9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: This module contains the implementation of IAUpdateClient |
14 * Description: This module contains the implementation of RIAUpdateClient |
15 * class member functions. |
15 * class member functions. |
16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 |
19 |
20 |
20 |
21 //INCLUDES |
21 //INCLUDES |
22 #include <eikenv.h> |
22 #include <eikenv.h> |
23 #include <apgcli.h> |
23 #include <apgcli.h> |
24 #include <e32math.h> |
24 #include <e32math.h> |
25 #include <iaupdateparameters.h> |
|
26 #include <iaupdateresult.h> |
|
27 #include <xqservicerequest.h> |
|
28 #include <xqserviceutil.h> |
|
29 #include <xqrequestinfo.h> |
|
30 |
|
31 #include "iaupdateclient.h" |
25 #include "iaupdateclient.h" |
32 #include "iaupdateclientdefines.h" |
26 #include "iaupdateclientdefines.h" |
|
27 #include "iaupdatetools.h" |
33 #include "iaupdatedebug.h" |
28 #include "iaupdatedebug.h" |
34 |
29 |
35 |
30 |
36 // ----------------------------------------------------------------------------- |
31 // ----------------------------------------------------------------------------- |
37 // IAUpdateClient::IAUpdateClient |
32 // RIAUpdateClient::RIAUpdateClient |
38 // |
33 // |
39 // ----------------------------------------------------------------------------- |
34 // ----------------------------------------------------------------------------- |
40 // |
35 // |
41 IAUpdateClient::IAUpdateClient(MIAUpdateObserver& observer): |
36 RIAUpdateClient::RIAUpdateClient() |
42 mObserver(observer) |
37 : iPtr1( NULL, 0 ), |
43 { |
38 iPtr2( NULL, 0 ), |
44 mServiceRequest = NULL; |
39 iPtr3( NULL, 0 ) |
45 mCurrentRequestType = NoOperation; |
40 { |
46 } |
41 } |
47 |
42 |
48 // ----------------------------------------------------------------------------- |
43 |
49 // IAUpdateClient::~IAUpdateClient |
44 // ----------------------------------------------------------------------------- |
50 // |
45 // RIAUpdateClient::Open |
51 // ----------------------------------------------------------------------------- |
46 // |
52 // |
47 // ----------------------------------------------------------------------------- |
53 IAUpdateClient::~IAUpdateClient() |
48 // |
54 { |
49 TInt RIAUpdateClient::Open() |
55 if ( mServiceRequest) |
50 { |
56 { |
51 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::Open() begin"); |
57 delete mServiceRequest; |
52 TInt error( KErrNone ); |
58 } |
53 |
59 } |
54 if ( !iConnected ) |
60 |
55 { |
61 |
56 TRAP( error, ConnectNewAppL( ServiceUid() ) ); |
62 // ----------------------------------------------------------------------------- |
57 if ( error == KErrNone ) |
63 // IAUpdateClient::initRequest |
58 { |
64 // |
59 iConnected = ETrue; |
65 // ----------------------------------------------------------------------------- |
60 CEikonEnv* eikEnv = CEikonEnv::Static(); |
66 // |
61 if ( eikEnv ) |
67 int IAUpdateClient::initRequest(const CIAUpdateParameters* updateParameters, const QString& message, bool toBackground) |
62 { |
68 { |
63 RWindowGroup owngroup; |
69 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::initRequest() begin"); |
64 iOwnWgId = eikEnv->RootWin().Identifier(); |
70 int error(KErrNone); |
65 |
71 if (mCurrentRequestType != NoOperation) |
66 TPckg<TInt> wgId( iOwnWgId ); |
72 { |
67 delete iData; |
73 error = KErrServerBusy; |
68 iData = NULL; |
74 } |
69 TRAP_IGNORE( iData = wgId.AllocL() ); |
75 else if (!mServiceRequest) |
70 |
76 { |
71 TIpcArgs args; |
77 mServiceRequest = new XQServiceRequest("com.nokia.services.swupdate.swupdate_interface", message, false); |
72 args.Set( 0, iData ); |
78 if (mServiceRequest) |
73 SendReceive( IAUpdateClientDefines::EIAUpdateServerSendWgId, args ); |
79 { |
74 } |
80 connect(mServiceRequest, SIGNAL(requestCompleted(QVariant)), this, SLOT(requestCompleted(QVariant))); |
75 } |
81 connect(mServiceRequest, SIGNAL(requestError(int)), this, SLOT(requestError(int))); |
76 } |
82 } |
77 IAUPDATE_TRACE_1("[IAUPDATE] RIAUpdateClient::Open() end error code: %d", error ); |
83 else |
78 return error; |
84 { |
79 } |
85 error = KErrNoMemory; |
80 |
86 } |
81 // ----------------------------------------------------------------------------- |
87 } |
82 // RIAUpdateClient::OpenToBackroundAsync |
88 else |
83 // |
89 { |
84 // ----------------------------------------------------------------------------- |
90 mServiceRequest->setMessage(message); |
85 // |
91 } |
86 TInt RIAUpdateClient::OpenToBackroundAsync( TRequestStatus& aStatus ) |
92 |
87 { |
93 |
88 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::OpenToBackroundAsync() begin"); |
94 if (error == KErrNone) |
89 TInt error( KErrNone ); |
95 { |
90 if ( !iConnected ) |
96 XQRequestInfo requestInfo; |
91 { |
97 requestInfo.setBackground(toBackground); |
92 TRAP( error, StartNewAppToBackgroundL( ServiceUid(), aStatus ) ); |
98 mServiceRequest->setInfo(requestInfo); |
93 } |
99 int wgId = 0; |
94 IAUPDATE_TRACE_1("[IAUPDATE] RIAUpdateClient::OpenToBackroundAsync() end error code: %d", error ); |
|
95 return error; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // RIAUpdateClient::ConnectToApp |
|
100 // |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TInt RIAUpdateClient::ConnectToApp() |
|
104 { |
|
105 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::ConnectToApp() begin"); |
|
106 TInt error( KErrNone ); |
|
107 TName serverName; |
|
108 ServerName(serverName, ServiceUid(), iDifferentiator); |
|
109 TRAP( error,ConnectExistingByNameL( serverName ) ); |
|
110 |
|
111 if ( error == KErrNone ) |
|
112 { |
|
113 iConnected = ETrue; |
100 CEikonEnv* eikEnv = CEikonEnv::Static(); |
114 CEikonEnv* eikEnv = CEikonEnv::Static(); |
101 if ( eikEnv ) |
115 if ( eikEnv ) |
102 { |
116 { |
103 RWindowGroup owngroup; |
117 RWindowGroup owngroup; |
104 wgId = eikEnv->RootWin().Identifier(); |
118 iOwnWgId = eikEnv->RootWin().Identifier(); |
105 } |
119 |
106 IAUPDATE_TRACE_1("IAUpdateClient::initRequest() wgId: %d", wgId); |
120 TPckg<TInt> wgId( iOwnWgId ); |
107 QString stringWgid; |
121 delete iData; |
108 stringWgid.setNum(wgId); |
122 iData = NULL; |
109 *mServiceRequest << stringWgid; |
123 TRAP_IGNORE( iData = wgId.AllocL() ); |
110 if (updateParameters) |
124 |
111 { |
125 TIpcArgs args; |
112 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() UID: %d", updateParameters->Uid().iUid); |
126 args.Set( 0, iData ); |
113 QString stringUid; |
127 SendReceive( IAUpdateClientDefines::EIAUpdateServerSendWgId, args ); |
114 stringUid.setNum(updateParameters->Uid().iUid); |
128 } |
115 *mServiceRequest << stringUid; |
129 } |
116 |
130 IAUPDATE_TRACE_1("[IAUPDATE] RIAUpdateClient::ConnectToApp() end error code: %d", error ); |
117 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() searchcriteria: %S", &updateParameters->SearchCriteria()); |
131 return error; |
118 *mServiceRequest << qStringFromTDesC(updateParameters->SearchCriteria()); |
132 } |
119 |
133 |
120 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() executable: %S", &updateParameters->CommandLineExecutable()); |
134 |
121 *mServiceRequest << qStringFromTDesC(updateParameters->CommandLineExecutable()); |
135 |
122 |
136 |
123 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() arguments: %S8", &updateParameters->CommandLineArguments()); |
137 // ----------------------------------------------------------------------------- |
124 *mServiceRequest << qStringFromTDesC8(updateParameters->CommandLineArguments()); |
138 // RIAUpdateClient::Close |
125 |
139 // |
126 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() show progress: %d", updateParameters->ShowProgress()); |
140 // ----------------------------------------------------------------------------- |
127 QString stringShowProgress; |
141 // |
128 stringShowProgress.setNum(updateParameters->ShowProgress()); |
142 void RIAUpdateClient::Close() |
129 *mServiceRequest << stringShowProgress; |
143 { |
130 |
144 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::Close() begin"); |
131 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() importance: %d", updateParameters->Importance()); |
145 // Let the parent handle closing. |
132 QString stringImportance; |
146 RAknAppServiceBase::Close(); |
133 stringImportance.setNum(updateParameters->Importance()); |
147 iConnected = EFalse; |
134 *mServiceRequest << stringImportance; |
148 delete iData; |
135 |
149 iData = NULL; |
136 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() type: %d", updateParameters->Type()); |
150 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::Close() end"); |
137 QString stringType; |
151 } |
138 stringType.setNum(updateParameters->Type()); |
152 |
139 *mServiceRequest << stringType; |
153 // ----------------------------------------------------------------------------- |
140 |
154 // RIAUpdateClient::CheckUpdates |
141 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() refresh: %d", updateParameters->Refresh()); |
155 // |
142 QString stringRefresh; |
156 // ----------------------------------------------------------------------------- |
143 stringRefresh.setNum(updateParameters->Refresh()); |
157 // |
144 *mServiceRequest << stringRefresh; |
158 TInt RIAUpdateClient::CheckUpdates( const CIAUpdateParameters& aUpdateParameters, |
145 } |
159 TInt& aAvailableUpdates, |
146 } |
160 TRequestStatus& aStatus ) |
147 |
161 { |
148 |
162 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::CheckUpdates()"); |
149 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::initRequest() error code: %d", error ); |
163 // Inform the caller about the success of the request initializing. |
150 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::initRequest() end"); |
164 return SendCheckUpdatesRequest( IAUpdateClientDefines::EIAUpdateServerCheckUpdates, |
|
165 aUpdateParameters, |
|
166 aAvailableUpdates, |
|
167 aStatus ); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // RIAUpdateClient::ShowUpdates |
|
172 // |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 TInt RIAUpdateClient::ShowUpdates( const CIAUpdateParameters& aUpdateParameters, |
|
176 TInt& aNumberOfSuccessfullUpdates, |
|
177 TInt& aNumberOfFailedUpdates, |
|
178 TInt& aNumberOfCancelledUpdates, |
|
179 TRequestStatus& aStatus ) |
|
180 { |
|
181 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::ShowUpdates()"); |
|
182 // Inform the caller about the success of the request initializing. |
|
183 return SendUpdateRequest( IAUpdateClientDefines::EIAUpdateServerShowUpdates, |
|
184 aUpdateParameters, |
|
185 aNumberOfSuccessfullUpdates, |
|
186 aNumberOfFailedUpdates, |
|
187 aNumberOfCancelledUpdates, |
|
188 aStatus ); |
|
189 } |
|
190 |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // RIAUpdateClient::UpdateQuery |
|
194 // |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 TInt RIAUpdateClient::UpdateQuery( TBool& aUpdateNow, TRequestStatus& aStatus ) |
|
198 { |
|
199 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::UpdateQuery() begin"); |
|
200 TPckg<TBool> updateNow( aUpdateNow ); |
|
201 iPtr1.Set( updateNow ); |
|
202 |
|
203 TIpcArgs args; |
|
204 args.Set( 1, &iPtr1 ); |
|
205 |
|
206 SendReceive( IAUpdateClientDefines::EIAUpdateServerShowUpdateQuery, |
|
207 args, |
|
208 aStatus ); |
|
209 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::UpdateQuery() begin"); |
|
210 return KErrNone; |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // RIAUpdateClient::BroughtToForeground |
|
215 // |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void RIAUpdateClient::BroughtToForeground() |
|
219 { |
|
220 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::BroughtToForeground() begin"); |
|
221 if ( iConnected ) |
|
222 { |
|
223 SendReceive( IAUpdateClientDefines::EIAUpdateServerToForeground ); |
|
224 } |
|
225 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::BroughtToForeground() end"); |
|
226 } |
|
227 |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // RIAUpdateClient::CancelAsyncRequest |
|
231 // |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void RIAUpdateClient::CancelAsyncRequest() |
|
235 { |
|
236 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::CancelAsyncRequest() begin"); |
|
237 // We suppose that an active object will |
|
238 // wait for the cancellation to complete. |
|
239 // So, let the server know that operation is cancelled. |
|
240 // The server should set the correct status and complete |
|
241 // the request of the active object. So, the cancellation |
|
242 // can proceed to the end. |
|
243 if ( iConnected ) |
|
244 { |
|
245 SendReceive( IAUpdateClientDefines::EIAUpdateServerCancel ); |
|
246 } |
|
247 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::CancelAsyncRequest() end"); |
|
248 } |
|
249 |
|
250 |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // RIAUpdateClient::ServiceUid() |
|
254 // |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 TUid RIAUpdateClient::ServiceUid() const |
|
258 { |
|
259 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::ServiceUid()"); |
|
260 return IAUpdateClientDefines::KIAUpdateServiceUid; |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // RIAUpdateClient::SendCheckUpdatesRequest |
|
265 // |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 TInt RIAUpdateClient::SendCheckUpdatesRequest( TInt aUpdateFunction, |
|
269 const CIAUpdateParameters& aUpdateParameters, |
|
270 TInt& aCount, |
|
271 TRequestStatus& aStatus ) |
|
272 { |
|
273 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::SendCheckUpdatesRequest() begin"); |
|
274 |
|
275 aStatus = KRequestPending; |
|
276 |
|
277 delete iData; |
|
278 iData = NULL; |
|
279 |
|
280 TInt error( KErrNone ); |
|
281 TRAP( error, |
|
282 IAUpdateTools::ExternalizeParametersL( iData, |
|
283 aUpdateParameters ) ); |
|
284 IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", error ); |
|
285 |
|
286 // Because this function does not leave, |
|
287 // use error value to check if request can be done. |
|
288 if ( error == KErrNone ) |
|
289 { |
|
290 TPckg<TInt> count( aCount ); |
|
291 iPtr1.Set( count ); |
|
292 |
|
293 TIpcArgs args; |
|
294 args.Set( 0, iData ); |
|
295 args.Set( 1, &iPtr1 ); |
|
296 |
|
297 // Start the asynchronous operation in the server side. |
|
298 SendReceive( aUpdateFunction, args, aStatus ); |
|
299 } |
|
300 |
|
301 // Inform the caller about the success of the request initializing. |
|
302 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::SendCheckUpdatesRequest() begin"); |
151 return error; |
303 return error; |
152 } |
304 } |
153 |
305 |
154 // ----------------------------------------------------------------------------- |
306 // ----------------------------------------------------------------------------- |
155 // IAUpdateClient::checkUpdates |
307 // RIAUpdateClient::SendUpdateRequest |
156 // |
308 // |
157 // ----------------------------------------------------------------------------- |
309 // ----------------------------------------------------------------------------- |
158 // |
310 // |
159 void IAUpdateClient::checkUpdates(const CIAUpdateParameters& updateParameters) |
311 TInt RIAUpdateClient::SendUpdateRequest( TInt aUpdateFunction, |
160 { |
312 const CIAUpdateParameters& aUpdateParameters, |
161 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::checkUpdates()"); |
313 TInt& aNumberOfSuccessfullUpdates, |
162 QString message("checkUpdates(QString,QString,QString,QString,QString,QString,QString,QString,QString)"); |
314 TInt& aNumberOfFailedUpdates, |
163 //QString message("checkUpdates(int,int)"); |
315 TInt& aNumberOfCancelledUpdates, |
164 int ret = initRequest(&updateParameters,message,!updateParameters.ShowProgress()); |
316 TRequestStatus& aStatus ) |
165 if (ret == KErrNone) |
317 { |
166 { |
318 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::SendUpdateRequest() begin"); |
167 if (mServiceRequest->send()) |
319 aStatus = KRequestPending; |
168 { |
320 |
169 mCurrentRequestType = CheckUpdates; |
321 delete iData; |
170 } |
322 iData = NULL; |
171 else |
323 |
172 { |
324 TInt error( KErrNone ); |
173 mObserver.CheckUpdatesComplete(ret,0); |
325 TRAP( error, |
174 } |
326 IAUpdateTools::ExternalizeParametersL( iData, |
175 } |
327 aUpdateParameters ) ); |
176 } |
328 IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", error ); |
177 |
329 // Because this function does not leave, |
178 // ----------------------------------------------------------------------------- |
330 // use error value to check if request can be done. |
179 // IAUpdateClient::showUpdates |
331 if ( error == KErrNone ) |
180 // |
332 { |
181 // ----------------------------------------------------------------------------- |
333 TPckg<TInt> successCount( aNumberOfSuccessfullUpdates ); |
182 // |
334 iPtr1.Set( successCount ); |
183 void IAUpdateClient::showUpdates(const CIAUpdateParameters& updateParameters) |
335 |
184 { |
336 TPckg<TInt> failCount( aNumberOfFailedUpdates ); |
185 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::showUpdates()"); |
337 iPtr2.Set( failCount ); |
186 QString message("showUpdates(QString,QString,QString,QString,QString,QString,QString,QString,QString)"); |
338 |
187 int ret = initRequest(&updateParameters, message, false); |
339 TPckg<TInt> cancelCount( aNumberOfCancelledUpdates ); |
188 if (ret == KErrNone) |
340 iPtr3.Set( cancelCount ); |
189 { |
341 |
190 if (mServiceRequest->send()) |
342 TIpcArgs args; |
191 { |
343 args.Set( 0, iData ); |
192 mCurrentRequestType = ShowUpdates; |
344 args.Set( 1, &iPtr1 ); |
193 } |
345 args.Set( 2, &iPtr2 ); |
194 else |
346 args.Set( 3, &iPtr3 ); |
195 { |
347 |
196 mObserver.UpdateComplete(ret,NULL); |
348 // Start the asynchronous operation in the server side. |
197 } |
349 SendReceive( aUpdateFunction, args, aStatus ); |
198 } |
350 } |
199 } |
351 |
200 |
352 // Inform the caller about the success of the request initializing. |
201 |
353 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::SendUpdateRequest() end"); |
202 // ----------------------------------------------------------------------------- |
354 return error; |
203 // IAUpdateClient::updateQuery |
355 } |
204 // |
356 |
205 // ----------------------------------------------------------------------------- |
357 // ----------------------------------------------------------------------------- |
206 // |
358 // RIAUpdateClient::StartNewAppToBackgroundL |
207 void IAUpdateClient::updateQuery() |
359 // |
208 { |
360 // ----------------------------------------------------------------------------- |
209 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::updateQuery() begin"); |
361 // |
210 QString message("updateQuery(QString)"); |
362 void RIAUpdateClient::StartNewAppToBackgroundL( TUid aAppUid, TRequestStatus& aStatus ) |
211 CIAUpdateParameters* nullParameters = NULL; |
363 { |
212 int ret = initRequest(nullParameters, message, false); |
364 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::StartNewAppToBackgroundL() begin"); |
213 if (ret == KErrNone) |
365 TName notUsed; |
214 { |
366 iDifferentiator = GenerateServerDifferentiatorAndName(notUsed, aAppUid); |
215 if (mServiceRequest->send()) |
367 |
216 { |
368 RApaLsSession apa; |
217 mCurrentRequestType = UpdateQuery; |
369 User::LeaveIfError(apa.Connect()); |
218 } |
370 CleanupClosePushL(apa); |
219 else |
371 |
220 { |
372 TApaAppInfo info; |
221 mObserver.UpdateQueryComplete(ret,false); |
373 User::LeaveIfError(apa.GetAppInfo(info, aAppUid)); |
222 } |
374 |
223 } |
375 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
224 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::updateQuery() end"); |
376 cmdLine->SetExecutableNameL(info.iFullName); |
225 } |
377 cmdLine->SetServerRequiredL( iDifferentiator ); |
226 |
378 cmdLine->SetCommandL(EApaCommandBackground); |
227 // ----------------------------------------------------------------------------- |
379 |
228 // IAUpdateClient::update |
380 TThreadId notUsedId; |
229 // |
381 User::LeaveIfError(apa.StartApp(*cmdLine, notUsedId, &aStatus)); |
230 // ----------------------------------------------------------------------------- |
382 |
231 // |
383 CleanupStack::PopAndDestroy(2, &apa); // cmdLine and apa |
232 void IAUpdateClient::update() |
384 IAUPDATE_TRACE("[IAUPDATE] RIAUpdateClient::StartNewAppToBackgroundL() end"); |
233 { |
385 } |
234 mObserver.UpdateComplete(KErrNotSupported,NULL); |
386 |
235 } |
387 |
236 |
388 |
237 // ----------------------------------------------------------------------------- |
389 void RIAUpdateClient::ServerName(TName& aServerName, TUid aAppServerUid, TUint aServerDifferentiator) |
238 // IAUpdateClient::broughtToForeground |
390 { |
239 // |
391 _LIT(KServerNameFormat, "%08x_%08x_AppServer"); |
240 // ----------------------------------------------------------------------------- |
392 aServerName.Format(KServerNameFormat, aServerDifferentiator, aAppServerUid); |
241 // |
393 } |
242 void IAUpdateClient::broughtToForeground() |
394 |
243 { |
395 TUint RIAUpdateClient::GenerateServerDifferentiatorAndName(TName& aServerName, TUid aAppServerUid) |
244 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::broughtToForeground() begin"); |
396 { |
245 if (mServiceRequest) |
397 TUint r; |
246 { |
398 FOREVER |
247 QString message("broughtToForeground(int)"); |
399 { |
248 CIAUpdateParameters* nullParameters = NULL; |
400 r = Math::Random(); |
249 int ret = initRequest(nullParameters, message, false); |
401 if (r==0) |
250 if (ret == KErrNone) |
402 continue; |
251 { |
403 ServerName(aServerName, aAppServerUid, r); |
252 if (mServiceRequest->send()) |
404 TFindServer find(aServerName); |
253 { |
405 TFullName fullName; |
254 mCurrentRequestType = BroughtToForeground; |
406 if (find.Next(fullName) == KErrNone) |
255 } |
407 continue; |
256 } |
|
257 } |
|
258 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::broughtToForeground() end"); |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // IAUpdateClient::requestCompleted |
|
263 // |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void IAUpdateClient::requestCompleted(const QVariant& value) |
|
267 { |
|
268 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::requestCompleted() begin"); |
|
269 RequestType requestType = mCurrentRequestType; |
|
270 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::requestCompleted()request type: %d", requestType ); |
|
271 QList<QVariant> resultlist = value.toList(); |
|
272 int errorCode = resultlist.at(0).toInt(); |
|
273 CIAUpdateResult* updateResult(NULL); |
|
274 |
|
275 if ( requestType == ShowUpdates ) |
|
276 { |
|
277 // Update result object is required. |
|
278 // Notice that the ownership is transferred later. |
|
279 // So, this function does not need to delete updateResult object. |
|
280 TRAPD( trapError, updateResult = CIAUpdateResult::NewL() ); |
|
281 if ( updateResult ) |
|
282 { |
|
283 updateResult->SetSuccessCount(resultlist.at(1).toInt()); |
|
284 updateResult->SetFailCount(resultlist.at(2).toInt()); |
|
285 updateResult->SetCancelCount(resultlist.at(3).toInt()); |
|
286 } |
|
287 else |
|
288 { |
|
289 // Something went wrong when creating update result object. |
|
290 // Update the error code accordingly. |
|
291 errorCode = trapError; |
|
292 } |
|
293 // Let's assume that connection is not needed anymore |
|
294 if (mServiceRequest) |
|
295 { |
|
296 delete mServiceRequest; |
|
297 mServiceRequest= NULL; |
|
298 } |
|
299 } |
|
300 |
|
301 // Inform that no operation is going on anymore. |
|
302 // This is required for busy check. |
|
303 mCurrentRequestType = NoOperation; |
|
304 |
|
305 // Use the request type of the ongoing operation to check what callback |
|
306 // function to call. |
|
307 int countOfUpdates = 0; |
|
308 bool updateNow = false; |
|
309 switch (requestType) |
|
310 { |
|
311 case CheckUpdates: |
|
312 countOfUpdates = resultlist.at(1).toInt(); |
|
313 if (countOfUpdates == 0) |
|
314 { |
|
315 // Let's assume that connection is not needed anymore |
|
316 delete mServiceRequest; |
|
317 mServiceRequest= NULL; |
|
318 } |
|
319 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::requestCompleted() count of updates: %d", countOfUpdates ); |
|
320 mObserver.CheckUpdatesComplete(errorCode, countOfUpdates); |
|
321 break; |
408 break; |
322 |
409 } |
323 case ShowUpdates: |
410 return r; |
324 // Notice that ownership of result object is transferred here. |
411 } |
325 IAUPDATE_TRACE_3("[IAUPDATE] IAUpdateClient::requestCompleted() success count: %d failed count: %d cancelled count: %d", updateResult->SuccessCount(), updateResult->FailCount(), updateResult->CancelCount() ); |
|
326 mObserver.UpdateComplete(errorCode, updateResult); |
|
327 break; |
|
328 |
|
329 case UpdateQuery: |
|
330 updateNow = resultlist.at(1).toBool(); |
|
331 if ( !updateNow ) |
|
332 { |
|
333 // Let's assume that connection is not needed anymore |
|
334 delete mServiceRequest; |
|
335 mServiceRequest= NULL; |
|
336 } |
|
337 IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateClient::requestCompleted() update now: %d", updateNow ); |
|
338 mObserver.UpdateQueryComplete(errorCode, updateNow); |
|
339 break; |
|
340 |
|
341 default: |
|
342 // Should not ever come here. |
|
343 break; |
|
344 } |
|
345 |
|
346 // Do not anything else than return after callback function is called because |
|
347 // this instance can be deleted by a client in a callback function |
|
348 // |
|
349 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::requestCompleted() end"); |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // IAUpdateClient::requestError |
|
354 // |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 void IAUpdateClient::requestError(int /*err*/) |
|
358 { |
|
359 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::requestError() begin"); |
|
360 if ( mServiceRequest) |
|
361 { |
|
362 delete mServiceRequest; |
|
363 mServiceRequest= NULL; |
|
364 } |
|
365 RequestType requestType = mCurrentRequestType; |
|
366 mCurrentRequestType = NoOperation; |
|
367 // because this method is called also when iaupdate is closed normally, error code is not passed to a client |
|
368 CIAUpdateResult* updateResult(NULL); |
|
369 switch (requestType) |
|
370 { |
|
371 case CheckUpdates: |
|
372 mObserver.CheckUpdatesComplete(0, 0); |
|
373 break; |
|
374 |
|
375 case ShowUpdates: |
|
376 // Notice that ownership of result object is transferred here. |
|
377 TRAP_IGNORE( updateResult = CIAUpdateResult::NewL() ); |
|
378 mObserver.UpdateComplete(0, updateResult); |
|
379 break; |
|
380 |
|
381 case UpdateQuery: |
|
382 mObserver.UpdateQueryComplete(0, false); |
|
383 break; |
|
384 |
|
385 default: |
|
386 // Should not ever come here. |
|
387 break; |
|
388 } |
|
389 IAUPDATE_TRACE("[IAUPDATE] IAUpdateClient::requestError() end"); |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // IAUpdateClient::qStringFromTDesC16 |
|
394 // |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 QString IAUpdateClient::qStringFromTDesC16( const TDesC16& aDes16 ) |
|
398 { |
|
399 return QString::fromUtf16( aDes16.Ptr(), aDes16.Length() ); |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // IAUpdateClient::qStringFromTDesC8 |
|
404 // |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 QString IAUpdateClient::qStringFromTDesC8( const TDesC8& aDes8 ) |
|
408 { |
|
409 return QString::fromUtf8( reinterpret_cast<const char*>( aDes8.Ptr() ), aDes8.Length() ); |
|
410 } |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // IAUpdateClient::qStringFromTDesC |
|
414 // |
|
415 // ----------------------------------------------------------------------------- |
|
416 // |
|
417 QString IAUpdateClient::qStringFromTDesC( const TDesC& aDes ) |
|
418 { |
|
419 #if defined(_UNICODE) |
|
420 return qStringFromTDesC16( aDes ); |
|
421 #else |
|
422 return qStringFromTDesC8( aDes ); |
|
423 #endif |
|
424 } |
|
425 |
|
426 |
|
427 |
|