1 /* |
|
2 * Copyright (c) 2006 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: Resolves sending service information and stores it to |
|
15 * Central Repository. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <e32property.h> |
|
22 #include <e32cmn.h> |
|
23 #include <apgwgnam.h> |
|
24 #include <mtclreg.h> // CClientMtmRegistry |
|
25 #include <SendUiConsts.h> |
|
26 #include <CSendingService.h> |
|
27 #include <CSendingServiceInfo.h> |
|
28 #include <SendingServiceInterfaceUids.hrh> |
|
29 |
|
30 #include <CSendingServiceInfo.h> |
|
31 #include <TSendingCapabilities.h> |
|
32 #include "centralrepository.h" |
|
33 #include "senduisrappui.h" |
|
34 #include "SendUiPrivateCRKeys.h" |
|
35 #include "senduiproperty.h" |
|
36 #include "senduiserviceslog.h" // Logging |
|
37 #include <senduisingleton.h> |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Constructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CSendUiSrAppUi::CSendUiSrAppUi() : |
|
46 iCoeEnv( CCoeEnv::Static() ) |
|
47 { |
|
48 SetFullScreenApp(EFalse); // disable possible transition effects |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // ConstructL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 void CSendUiSrAppUi::ConstructL() |
|
56 { |
|
57 BaseConstructL(ENoAppResourceFile); |
|
58 |
|
59 HideApplicationFromFSW( ETrue ); // hide from Fast Swap Window |
|
60 |
|
61 TApaTask task(iEikonEnv->WsSession()); |
|
62 task.SetWgId(iEikonEnv->RootWin().Identifier()); |
|
63 task.SendToBackground(); |
|
64 |
|
65 iIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
66 iIdle->Start( TCallBack(UpdateTask, this )); |
|
67 } |
|
68 |
|
69 TInt CSendUiSrAppUi::UpdateTask( TAny* aThis ) |
|
70 { |
|
71 CSendUiSrAppUi* appUi = static_cast<CSendUiSrAppUi*>( aThis ); |
|
72 |
|
73 TRAPD( err, appUi->HandleUpdateSendListL() ); |
|
74 |
|
75 if ( err ) |
|
76 { |
|
77 #ifdef _DEBUG |
|
78 TBuf<256> buf; |
|
79 buf.Format(_L("SendUi err")); |
|
80 User::InfoPrint(buf); |
|
81 LOGTEXT2(_L("SendUiServiceResolver: Error %d while loading CenRep."), err ); |
|
82 #endif |
|
83 RProperty::Set( |
|
84 KPSUidSendUiProperty, |
|
85 KSendUiUpdateOperation, |
|
86 KSendUiUpdateOperationDone ); |
|
87 |
|
88 RProperty::Set( |
|
89 KPSUidSendUiProperty, |
|
90 KSendUiUpdateRequest, |
|
91 KSendUiNotInitialized ); |
|
92 } |
|
93 |
|
94 appUi->Exit(); |
|
95 return KErrNone; |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // Destructor |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 CSendUiSrAppUi::~CSendUiSrAppUi() |
|
104 { |
|
105 delete iIdle; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // HandleUpdateSendListL |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CSendUiSrAppUi::HandleUpdateSendListL() |
|
113 { |
|
114 RProperty::Set( |
|
115 KPSUidSendUiProperty, |
|
116 KSendUiUpdateOperation, |
|
117 KSendUiUpdateOperationRunning ); |
|
118 |
|
119 CRepository* myRep = CRepository::NewLC( KCRUidSendUi ); |
|
120 LOGTEXT(_L("SendUiSr: Repository created.")); |
|
121 |
|
122 // KErrNotFound indicates undefined repository state and services are re-read by Watcher |
|
123 // in boot, if this update fails. The correct language value is set when update completes |
|
124 // succesfully. |
|
125 TInt result = myRep->Set( KKeySendUiServiceLanguage, KErrNotFound ); |
|
126 |
|
127 LOGTEXT(_L("SendUiSr: Service Manager created.")); |
|
128 RPointerArray<CSendingServiceInfo> servicesArray; |
|
129 RPointerArray<CSendingService> serviceProviders; |
|
130 |
|
131 PopulateServicesListL( servicesArray, serviceProviders, iCoeEnv ); |
|
132 |
|
133 TSendingCapabilities serviceCapabilities; |
|
134 |
|
135 // cleaning old and storing new sending service values to Central Repository |
|
136 // is done in one transaction. |
|
137 result += myRep->StartTransaction( CRepository::EConcurrentReadWriteTransaction ); |
|
138 |
|
139 if ( result != KErrNone ) |
|
140 { |
|
141 servicesArray.Close(); |
|
142 CleanupStack::PopAndDestroy( myRep ); |
|
143 return; |
|
144 } |
|
145 else |
|
146 { |
|
147 ClearPluginListL( myRep ); |
|
148 } |
|
149 |
|
150 TInt i(0); |
|
151 TInt err(0); |
|
152 for ( i = 0; i < servicesArray.Count(); i++) |
|
153 { |
|
154 // Store to Central Repository: uid, providerId, name, menuname, capabilities, |
|
155 // technologytype, messagesize, flags and serviceFeatures |
|
156 err += AddSendingService( |
|
157 myRep, |
|
158 i, |
|
159 servicesArray[i]->ServiceId(), |
|
160 servicesArray[i]->ServiceProviderId(), |
|
161 servicesArray[i]->TechnologyTypeId(), |
|
162 servicesArray[i]->ServiceFeatures(), |
|
163 servicesArray[i]->ServiceCapabilities(), |
|
164 servicesArray[i]->ServiceName().Left( KSendUiServiceMaxNameLength ), |
|
165 servicesArray[i]->ServiceMenuName().Left( KSendUiServiceMaxNameLength ), |
|
166 servicesArray[i]->ServiceAddress().Left( KSendUiServiceMaxNameLength ) ); |
|
167 } |
|
168 |
|
169 err += myRep->Set( KKeySendUiServiceCount, servicesArray.Count() ); |
|
170 err += myRep->Set( KKeySendUiServiceLanguage, (TInt)User::Language() ); |
|
171 |
|
172 if ( err == KErrNone ) |
|
173 { |
|
174 TUint32 keyInfo; |
|
175 myRep->CommitTransaction( keyInfo ); |
|
176 } |
|
177 |
|
178 servicesArray.Close(); |
|
179 serviceProviders.ResetAndDestroy(); |
|
180 CleanupStack::PopAndDestroy( myRep ); // myRep |
|
181 |
|
182 RProperty::Set( |
|
183 KPSUidSendUiProperty, |
|
184 KSendUiUpdateOperation, |
|
185 KSendUiUpdateOperationDone ); |
|
186 |
|
187 RProperty::Set( |
|
188 KPSUidSendUiProperty, |
|
189 KSendUiUpdateRequest, |
|
190 KSendUiUpdated ); |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // AddSendingService |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 TInt CSendUiSrAppUi::AddSendingService( |
|
198 CRepository* aRep, |
|
199 TUint aIndex, |
|
200 TUid aMtmUid, |
|
201 TUid aServiceProviderId, |
|
202 TUid aTechnologyType, |
|
203 TInt aFeatures, |
|
204 TSendingCapabilities aCapabilities, |
|
205 TPtrC aServiceName, |
|
206 TPtrC aServiceMenuName, |
|
207 TPtrC aServiceAddress ) |
|
208 { |
|
209 // Cenrep stays in readble state during transaction |
|
210 |
|
211 aIndex = aIndex * KSendUiServiceIndex; |
|
212 // "collect" errors. Focus is in the existance of errors, not on any specific error. |
|
213 TInt err = aRep->Create( aIndex | KSendUiServiceId, (TInt)aMtmUid.iUid ); |
|
214 err += aRep->Create( aIndex | KSendUiServiceProviderId, (TInt)aServiceProviderId.iUid ); |
|
215 |
|
216 err += aRep->Create( aIndex | KSendUiServiceName, aServiceName ); |
|
217 err += aRep->Create( aIndex | KSendUiServiceMenuName, aServiceMenuName ); |
|
218 err += aRep->Create( aIndex | KSendUiServiceAddress, aServiceAddress ); |
|
219 |
|
220 err += aRep->Create( aIndex | KSendUiServiceFlags, aCapabilities.iFlags ); |
|
221 err += aRep->Create( aIndex | KSendUiServiceBodySize, aCapabilities.iBodySize ); |
|
222 err += aRep->Create( aIndex | KSendUiServiceMessageSize, aCapabilities.iMessageSize ); |
|
223 err += aRep->Create( aIndex | KSendUiServiceTechnologyType, (TInt)aTechnologyType.iUid ); |
|
224 err += aRep->Create( aIndex | KSendUiServiceFeatures, aFeatures ); |
|
225 LOGTEXT3(_L("SendUiServiceResolver: index %d, service %d"), aIndex, aMtmUid.iUid ); |
|
226 if ( err != KErrNone ) |
|
227 { |
|
228 LOGTEXT(_L("Error while creating Central Repository data.") ); |
|
229 } |
|
230 return ( err != KErrNone ); |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // ClearPluginListL |
|
235 // Deletes all service detail keys from the repository. |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 void CSendUiSrAppUi::ClearPluginListL( CRepository* aRep ) |
|
239 { |
|
240 TUint32 partialKey = 0x00000000; |
|
241 TUint32 keyMask = 0xFFFF0000; // 0, don't care mask |
|
242 RArray<TUint32> indexKeys; |
|
243 CleanupClosePushL( indexKeys ); |
|
244 |
|
245 aRep->FindL( partialKey, keyMask, indexKeys ); |
|
246 |
|
247 for (int i(0) ; i < indexKeys.Count(); i++) |
|
248 { |
|
249 aRep->Delete( indexKeys[ i ] ); |
|
250 } |
|
251 |
|
252 CleanupStack::PopAndDestroy( &indexKeys ); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // From class CAknAppUi. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void CSendUiSrAppUi::HandleCommandL(TInt /*aCommand*/) |
|
260 { |
|
261 // no implementation required |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 CSendingService* CSendUiSrAppUi::LoadServiceL( |
|
266 TUid aServiceProviderUid, |
|
267 CCoeEnv* aCoeEnv, |
|
268 CSendUiSingleton* aSingleton, |
|
269 RPointerArray<CSendingServiceInfo>& aServiceList ) |
|
270 { |
|
271 CSendingService* sendingService = CSendingService::NewL( |
|
272 aServiceProviderUid, |
|
273 *aCoeEnv, |
|
274 *aSingleton ); |
|
275 |
|
276 if( sendingService ) |
|
277 { |
|
278 CleanupStack::PushL( sendingService ); |
|
279 sendingService->PopulateServicesListL( aServiceList ); |
|
280 // if everything goes well, aServiceProviders will own this object soon enough |
|
281 CleanupStack::Pop( sendingService ); |
|
282 } |
|
283 return sendingService; |
|
284 } |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void CSendUiSrAppUi::PopulateServicesListL( |
|
290 RPointerArray<CSendingServiceInfo>& aServiceList, |
|
291 RPointerArray<CSendingService>& aServiceProviders, |
|
292 CCoeEnv* aCoeEnv ) |
|
293 { |
|
294 CSendUiSingleton* singleton = CSendUiSingleton::NewL(); |
|
295 CleanupStack::PushL( singleton ); |
|
296 aServiceList.Reset(); |
|
297 |
|
298 RImplInfoPtrArray implInfoArray; |
|
299 RPointerArray<CSendingServiceInfo> services; |
|
300 |
|
301 REComSession::ListImplementationsL( |
|
302 TUid::Uid( KSendUiSendingServiceInterface ),implInfoArray); |
|
303 |
|
304 TInt serviceIndex(0); |
|
305 CSendingService* sendingService; |
|
306 while ( serviceIndex < implInfoArray.Count() ) |
|
307 { |
|
308 sendingService = NULL; |
|
309 TUid serviceUid = (*implInfoArray[serviceIndex]).ImplementationUid(); |
|
310 // If Ecom service loading fails, then just move on |
|
311 TRAPD( error, sendingService = LoadServiceL( serviceUid, aCoeEnv, singleton, services ) ); |
|
312 |
|
313 if( sendingService && error == KErrNone ) |
|
314 { |
|
315 aServiceProviders.AppendL( sendingService ); |
|
316 |
|
317 for ( TInt index = 0; index < services.Count(); index++ ) |
|
318 { |
|
319 aServiceList.Append( services[ index ] ); |
|
320 } |
|
321 services.Reset(); |
|
322 |
|
323 LOGTEXT2( _L("Provider %d creation SUCCESS."), serviceUid ); |
|
324 } |
|
325 else |
|
326 { |
|
327 LOGTEXT3( _L("Provider %d creation FAILED. Error code: %d"), serviceUid, error ); |
|
328 } |
|
329 |
|
330 serviceIndex++; |
|
331 } |
|
332 services.Close(); |
|
333 implInfoArray.ResetAndDestroy(); |
|
334 REComSession::FinalClose(); |
|
335 CleanupStack::PopAndDestroy( singleton ); |
|
336 } |
|
337 |
|
338 // end of file |
|
339 |
|