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