|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of the class Pbk2RemoteContactLookupFactory. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <cpbk2remotecontactlookupaccounts.h> |
|
20 |
|
21 #include "pbkxrclutils.h" |
|
22 #include "cpbkxrclprotocolenvimpl.h" |
|
23 #include "cpbkxremotecontactlookupprotocoladapter.h" |
|
24 |
|
25 void CleanupResetAndDestroyInfoArray(TAny* aObj) |
|
26 { |
|
27 if (aObj) |
|
28 { |
|
29 static_cast<RImplInfoPtrArray*>(aObj)->ResetAndDestroy(); |
|
30 } |
|
31 } |
|
32 |
|
33 void CleanupResetAndDestroyAccArray(TAny* aObj) |
|
34 { |
|
35 if (aObj) |
|
36 { |
|
37 static_cast<RPointerArray<CPbkxRemoteContactLookupProtocolAccount>*>(aObj)->ResetAndDestroy(); |
|
38 } |
|
39 } |
|
40 |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 |
|
45 EXPORT_C CPbk2RemoteContactLookupAccounts* CPbk2RemoteContactLookupAccounts::NewL() |
|
46 { |
|
47 CPbk2RemoteContactLookupAccounts* self = CPbk2RemoteContactLookupAccounts::NewLC(); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 |
|
53 |
|
54 EXPORT_C CPbk2RemoteContactLookupAccounts* CPbk2RemoteContactLookupAccounts::NewLC() |
|
55 { |
|
56 CPbk2RemoteContactLookupAccounts* self = new (ELeave) CPbk2RemoteContactLookupAccounts(); |
|
57 CleanupStack::PushL( self ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 |
|
62 |
|
63 CPbk2RemoteContactLookupAccounts::~CPbk2RemoteContactLookupAccounts() |
|
64 { |
|
65 iAdapters.ResetAndDestroy(); |
|
66 delete iProtocolEnv; |
|
67 } |
|
68 |
|
69 |
|
70 |
|
71 EXPORT_C TPbkxRemoteContactLookupProtocolAccountId CPbk2RemoteContactLookupAccounts::DefaultAccountIdL() |
|
72 { |
|
73 return PbkxRclUtils::DefaultProtocolAccountIdL(); |
|
74 } |
|
75 |
|
76 |
|
77 |
|
78 EXPORT_C CPbkxRemoteContactLookupProtocolAccount* CPbk2RemoteContactLookupAccounts::GetAccountL( |
|
79 const TPbkxRemoteContactLookupProtocolAccountId& aProtocolAccountId ) |
|
80 { |
|
81 CPbkxRclProtocolEnvImpl* protocolEnv = CPbkxRclProtocolEnvImpl::NewLC(); |
|
82 |
|
83 CPbkxRemoteContactLookupProtocolAccount* account = NULL; |
|
84 |
|
85 // Need load the plugin |
|
86 CPbkxRemoteContactLookupProtocolAdapter* adapter = NULL; |
|
87 TRAP_IGNORE( adapter = CPbkxRemoteContactLookupProtocolAdapter::NewL( |
|
88 aProtocolAccountId.iProtocolUid, |
|
89 *protocolEnv ) ); |
|
90 if ( adapter ) |
|
91 { |
|
92 CleanupStack::PushL( adapter ); |
|
93 |
|
94 // Delegate to the plugin |
|
95 account = adapter->NewProtocolAccountL( aProtocolAccountId ); |
|
96 CleanupStack::PopAndDestroy( adapter ); |
|
97 } |
|
98 CleanupStack::PopAndDestroy(); // protocolEnv |
|
99 return account; |
|
100 } |
|
101 |
|
102 |
|
103 |
|
104 EXPORT_C void CPbk2RemoteContactLookupAccounts::LoadProtocolPluginsL() |
|
105 { |
|
106 iAdapters.ResetAndDestroy(); |
|
107 if ( !iProtocolEnv ) |
|
108 { |
|
109 iProtocolEnv = CPbkxRclProtocolEnvImpl::NewL(); |
|
110 } |
|
111 |
|
112 RImplInfoPtrArray implArray; |
|
113 TCleanupItem cleanupItem(CleanupResetAndDestroyInfoArray, &implArray); |
|
114 CleanupStack::PushL( cleanupItem ); |
|
115 REComSession::ListImplementationsL( TUid::Uid(KPbkxRemoteContactLookupAdapterIfUid), implArray ); |
|
116 |
|
117 //TODO Need to also keep track of the plugin protocol UIDs. ??? |
|
118 // Also impl. UIDS to avoid unnecessary loading? |
|
119 // The plugin interface doesn't have a method for asking the protocol UID!! |
|
120 |
|
121 // Now create all the protocol adapters. |
|
122 // The actual ECom loading is implemented in CPbkxRemoteContactLookupProtocolAdapter. |
|
123 for ( TInt i = 0; i < implArray.Count(); i++ ) |
|
124 { |
|
125 CPbkxRemoteContactLookupProtocolAdapter* adapter = NULL; |
|
126 adapter = CPbkxRemoteContactLookupProtocolAdapter::NewL( |
|
127 implArray[i]->ImplementationUid(), *iProtocolEnv ); |
|
128 CleanupStack::PushL( adapter ); |
|
129 User::LeaveIfError( iAdapters.Append( adapter ) ); |
|
130 CleanupStack::Pop( adapter ); |
|
131 } |
|
132 CleanupStack::PopAndDestroy(); // cleanupItem |
|
133 } |
|
134 |
|
135 |
|
136 |
|
137 EXPORT_C void CPbk2RemoteContactLookupAccounts::GetAllAccountsL( |
|
138 RPointerArray<CPbkxRemoteContactLookupProtocolAccount>& aAccounts ) |
|
139 { |
|
140 if ( iAdapters.Count() == 0 ) |
|
141 { |
|
142 // No plugins were loaded. |
|
143 LoadProtocolPluginsL(); |
|
144 } |
|
145 |
|
146 // Loop through all the plugins and collect all the accounts |
|
147 const TInt protocolAdapterCount = iAdapters.Count(); |
|
148 for ( TInt n = 0; n < protocolAdapterCount; n++ ) |
|
149 { |
|
150 CPbkxRemoteContactLookupProtocolAdapter& adapter = *iAdapters[n]; |
|
151 // Using a temp array, just to avoid an adapter resetting the main array |
|
152 RPointerArray<CPbkxRemoteContactLookupProtocolAccount> protocolAccountsTmp; |
|
153 TCleanupItem cleanupItemAcc(CleanupResetAndDestroyAccArray, &protocolAccountsTmp); |
|
154 CleanupStack::PushL(cleanupItemAcc); |
|
155 adapter.GetAllProtocolAccountsL( protocolAccountsTmp ); |
|
156 |
|
157 // Move accounts from temp array to main array |
|
158 |
|
159 // First expand the main array so that we can move ownership in one go. |
|
160 // TODO OOPS, METHOD NOT AVAILABLE iAdapters.SetReserveL( iAdapters.Count() + protocolAccountsTmp.Count() ); |
|
161 |
|
162 |
|
163 // Don't need the cleanup item anymore since iAdapters will take ownership, |
|
164 // and the iAdapters has already been expanded. |
|
165 CleanupStack::Pop(); // cleanupItemAcc |
|
166 for ( TInt x = 0; x < protocolAccountsTmp.Count(); x++ ) |
|
167 { |
|
168 // Ownership is passed |
|
169 User::LeaveIfError( aAccounts.Append( protocolAccountsTmp[ x ] ) ); |
|
170 } |
|
171 // just let protocolAccountsTmp pass out of scope. It doesn't own anything now. |
|
172 } |
|
173 } |
|
174 |
|
175 |
|
176 |
|
177 EXPORT_C void CPbk2RemoteContactLookupAccounts::GetAccountsL( |
|
178 RPointerArray<CPbkxRemoteContactLookupProtocolAccount>& aAccounts, |
|
179 const TUid& aProtocol ) |
|
180 { |
|
181 //TODO Should optimise this. |
|
182 |
|
183 RPointerArray<CPbkxRemoteContactLookupProtocolAccount> protocolAccounts; |
|
184 TCleanupItem cleanupItemAcc(CleanupResetAndDestroyAccArray, &protocolAccounts); |
|
185 CleanupStack::PushL(cleanupItemAcc); |
|
186 |
|
187 GetAllAccountsL( protocolAccounts ); |
|
188 |
|
189 // Collect the accounts which have correct protocol |
|
190 for ( TInt j = protocolAccounts.Count() - 1; j >= 0; j-- ) |
|
191 { |
|
192 CPbkxRemoteContactLookupProtocolAccount* account = protocolAccounts[j]; |
|
193 if( account->Id().iProtocolUid == aProtocol ) |
|
194 { |
|
195 // Transfer ownership |
|
196 User::LeaveIfError( aAccounts.Append( account ) ); |
|
197 } |
|
198 else |
|
199 { |
|
200 // Wrong account. Don't need it. |
|
201 delete account; |
|
202 } |
|
203 protocolAccounts.Remove( j ); |
|
204 } |
|
205 CleanupStack::Pop(); // cleanupItemAcc |
|
206 } |
|
207 |
|
208 CPbk2RemoteContactLookupAccounts::CPbk2RemoteContactLookupAccounts() |
|
209 { |
|
210 } |
|
211 |
|
212 EXPORT_C void CPbk2RemoteContactLookupAccounts::SetDefaultAccountIdL( |
|
213 const TPbkxRemoteContactLookupProtocolAccountId& aAccountId ) |
|
214 { |
|
215 PbkxRclUtils::StoreDefaultProtocolAccountIdL( aAccountId ); |
|
216 } |
|
217 |
|
218 // end of file |