43 #include "xqservicemetadata/xqservicemetadata_p.h" |
44 #include "xqservicemetadata/xqservicemetadata_p.h" |
44 #include <xqservicemetadata/xqaiwinterfacedescriptor.h> |
45 #include <xqservicemetadata/xqaiwinterfacedescriptor.h> |
45 #include "xqconversions.h" |
46 #include "xqconversions.h" |
46 |
47 |
47 |
48 |
48 |
49 #define TIMER_DELAY 3000 |
|
50 |
|
51 class CProcessInfo : public CActive |
|
52 { |
|
53 public: |
|
54 static void AddProcessL(const TUid& appUid, RProcess& appProcess); |
|
55 static void EnsureProcessCanStartL(const TUid& appUid); |
|
56 |
|
57 protected: |
|
58 CProcessInfo(const TUid& appUid); |
|
59 ~CProcessInfo(); |
|
60 void ConstructL(RProcess& appProcess); |
|
61 void DoCancel(); |
|
62 void RunL(); |
|
63 |
|
64 protected: |
|
65 class ProcessInfoMap |
|
66 { |
|
67 public: |
|
68 ~ProcessInfoMap() |
|
69 { |
|
70 foreach (CProcessInfo* info, map.values()) |
|
71 delete info; |
|
72 } |
|
73 QHash<TInt32, CProcessInfo*> map; |
|
74 }; |
|
75 |
|
76 static ProcessInfoMap iProcessInfoMap; |
|
77 const TUid iAppUid; |
|
78 }; |
|
79 |
|
80 |
|
81 |
|
82 CProcessInfo::ProcessInfoMap CProcessInfo::iProcessInfoMap; |
|
83 |
|
84 CProcessInfo::CProcessInfo(const TUid& appUid): |
|
85 CActive(CActive::EPriorityStandard), |
|
86 iAppUid(appUid) |
|
87 { |
|
88 XQSERVICE_DEBUG_PRINT("CProcessInfo::CProcessInfo"); |
|
89 |
|
90 CActiveScheduler::Add(this); |
|
91 } |
|
92 |
|
93 CProcessInfo::~CProcessInfo() |
|
94 { |
|
95 XQSERVICE_DEBUG_PRINT("CProcessInfo::~CProcessInfo"); |
|
96 |
|
97 // Cancel asynch request, normally it should be done in DoCancel() |
|
98 // but we dont wont to cancel request when we cancel active object |
|
99 User::CancelMiscNotifier(iStatus); |
|
100 |
|
101 Cancel(); |
|
102 } |
|
103 |
|
104 void CProcessInfo::AddProcessL(const TUid& appUid, RProcess& appProcess) |
|
105 { |
|
106 XQSERVICE_DEBUG_PRINT("CProcessInfo::AddProcessL"); |
|
107 |
|
108 CProcessInfo* self = new(ELeave) CProcessInfo(appUid); |
|
109 CleanupStack::PushL(self); |
|
110 self->ConstructL(appProcess); |
|
111 CleanupStack::Pop(self); |
|
112 } |
|
113 |
|
114 void CProcessInfo::EnsureProcessCanStartL(const TUid& appUid) |
|
115 { |
|
116 XQSERVICE_DEBUG_PRINT("CProcessInfo::EnsureProcessCanStartL"); |
|
117 |
|
118 CProcessInfo* previousProcess = iProcessInfoMap.map[appUid.iUid]; |
|
119 if (previousProcess) { |
|
120 previousProcess->Cancel(); |
|
121 |
|
122 // Timer is for ensure that wait will end. |
|
123 // Maybe there is possibility that destroing process notification could be lost. |
|
124 RTimer securityTimer; |
|
125 securityTimer.CreateLocal(); |
|
126 CleanupClosePushL(securityTimer); |
|
127 |
|
128 TRequestStatus timerStatus; |
|
129 securityTimer.After(timerStatus, TIMER_DELAY); |
|
130 User::WaitForRequest(previousProcess->iStatus, timerStatus); |
|
131 |
|
132 CleanupStack::PopAndDestroy(); |
|
133 delete previousProcess; |
|
134 iProcessInfoMap.map.remove(appUid.iUid); |
|
135 } |
|
136 } |
|
137 |
|
138 void CProcessInfo::RunL() |
|
139 { |
|
140 XQSERVICE_DEBUG_PRINT("CProcessInfo::RunL"); |
|
141 |
|
142 iProcessInfoMap.map.remove(iAppUid.iUid); |
|
143 delete this; |
|
144 } |
|
145 |
|
146 void CProcessInfo::ConstructL(RProcess& appProcess) |
|
147 { |
|
148 XQSERVICE_DEBUG_PRINT("CProcessInfo::ConstructL"); |
|
149 |
|
150 SetActive(); |
|
151 |
|
152 EnsureProcessCanStartL(iAppUid); |
|
153 iProcessInfoMap.map.insert(iAppUid.iUid, this); |
|
154 appProcess.NotifyDestruction(iStatus); |
|
155 } |
|
156 |
|
157 void CProcessInfo::DoCancel() |
|
158 { |
|
159 XQSERVICE_DEBUG_PRINT("CProcessInfo::DoCancel"); |
|
160 |
|
161 // Cancel asynch request, normally it should be done in DoCancel() |
|
162 // but we dont wont to cancel request when we cancel active object. |
|
163 // Cancel asynch request is in ~CProcessInfo(). |
|
164 } |
|
165 |
|
166 /*! |
|
167 \class XQServiceManagerPrivate |
|
168 \brief Private implementation of the XQServiceManager. |
|
169 */ |
49 class XQServiceManagerPrivate |
170 class XQServiceManagerPrivate |
50 { |
171 { |
51 public: |
172 public: |
52 XQServiceManagerPrivate(); |
173 XQServiceManagerPrivate(); |
53 ~XQServiceManagerPrivate(); |
174 ~XQServiceManagerPrivate(); |
83 int iLatestError; |
204 int iLatestError; |
84 RApaLsSession iApaSession; |
205 RApaLsSession iApaSession; |
85 XQAiwInterfaceDescriptor iImplDescriptor; |
206 XQAiwInterfaceDescriptor iImplDescriptor; |
86 }; |
207 }; |
87 |
208 |
|
209 /*! |
|
210 \class XQServiceManager |
|
211 \brief Discovery and service startup. |
|
212 */ |
|
213 |
|
214 /*! |
|
215 Constructor. |
|
216 */ |
88 XQServiceManager::XQServiceManager() |
217 XQServiceManager::XQServiceManager() |
89 { |
218 { |
90 XQSERVICE_DEBUG_PRINT("XQServiceManager::XQServiceManager"); |
219 XQSERVICE_DEBUG_PRINT("XQServiceManager::XQServiceManager"); |
91 d = new XQServiceManagerPrivate(); |
220 d = new XQServiceManagerPrivate(); |
92 } |
221 } |
93 |
222 |
|
223 /*! |
|
224 Destructor. |
|
225 */ |
94 XQServiceManager::~XQServiceManager() |
226 XQServiceManager::~XQServiceManager() |
95 { |
227 { |
96 XQSERVICE_DEBUG_PRINT("XQServiceManager::~XQServiceManager"); |
228 XQSERVICE_DEBUG_PRINT("XQServiceManager::~XQServiceManager"); |
97 delete d; |
229 delete d; |
98 } |
230 } |
99 |
231 |
100 /*! |
232 /*! |
101 Starts service |
233 Starts service |
102 \param service The full name of service (servicename + interfacename) |
234 \param service The full name of service (servicename + interfacename). |
103 \param embedded Start in embedded mode |
235 \param embedded Start in embedded mode. |
104 \param applicationUid Returned applicatiion |
236 \param applicationUid Returned applicatiion. |
105 \return List of implementations |
237 \param threadId Returned process id of the application. |
|
238 \return Error code if error occured, 0 otherwise. |
106 */ |
239 */ |
107 int XQServiceManager::startServer(const QString& service, bool embedded, int& applicationUid, quint64& threadId) |
240 int XQServiceManager::startServer(const QString& service, bool embedded, int& applicationUid, quint64& threadId) |
108 { |
241 { |
109 XQSERVICE_DEBUG_PRINT("XQServiceManager::startServer(1)"); |
242 XQSERVICE_DEBUG_PRINT("XQServiceManager::startServer(1)"); |
110 return startServer(service,embedded,applicationUid,threadId,NULL); |
243 return startServer(service,embedded,applicationUid,threadId,NULL); |
111 } |
244 } |
112 |
245 |
|
246 /*! |
|
247 Starts service |
|
248 \param service The full name of service (servicename + interfacename). |
|
249 \param embedded Start in embedded mode. |
|
250 \param applicationUid Returned applicatiion. |
|
251 \param threadId Returned process id of the application. |
|
252 \param userData Additional user data. |
|
253 \return Error code if error occured, 0 otherwise. |
|
254 */ |
113 int XQServiceManager::startServer(const QString& service, bool embedded, int& applicationUid, quint64& threadId, |
255 int XQServiceManager::startServer(const QString& service, bool embedded, int& applicationUid, quint64& threadId, |
114 const void *userData) |
256 const void *userData) |
115 { |
257 { |
116 XQSERVICE_DEBUG_PRINT("XQServiceManager::startServer(2)"); |
258 XQSERVICE_DEBUG_PRINT("XQServiceManager::startServer(2)"); |
117 |
259 |
128 return d->StartServer(service,embedded,applicationUid,threadId, util); |
270 return d->StartServer(service,embedded,applicationUid,threadId, util); |
129 } |
271 } |
130 |
272 |
131 |
273 |
132 /*! |
274 /*! |
133 Finds implementations for the given interface |
275 Finds implementations for the given interface. |
134 \param interfaceName Interfacename to match |
276 \param interfaceName Interfacename to match. |
135 \return List of implementations |
277 \return List of implementations. |
136 */ |
278 */ |
137 QList<XQAiwInterfaceDescriptor> XQServiceManager::findInterfaces ( const QString &interfaceName ) const |
279 QList<XQAiwInterfaceDescriptor> XQServiceManager::findInterfaces ( const QString &interfaceName ) const |
138 { |
280 { |
139 XQSERVICE_DEBUG_PRINT("XQServiceManager::findInterfaces 1"); |
281 XQSERVICE_DEBUG_PRINT("XQServiceManager::findInterfaces 1"); |
140 QList<XQAiwInterfaceDescriptor> interfaces; |
282 QList<XQAiwInterfaceDescriptor> interfaces; |
143 TInt error=d->Discover(interfaceName, appUid, interfaces, XQServiceManagerPrivate::MatchInterfaceName); |
285 TInt error=d->Discover(interfaceName, appUid, interfaces, XQServiceManagerPrivate::MatchInterfaceName); |
144 return interfaces; |
286 return interfaces; |
145 } |
287 } |
146 |
288 |
147 /*! |
289 /*! |
148 Finds implementations for the given interface implemented by given service |
290 Finds implementations for the given interface implemented by given service. |
149 \param serviceName Service name |
291 \param serviceName Service name. |
150 \param interfaceName Interfacename to match |
292 \param interfaceName Interfacename to match. |
151 \return List of implementations |
293 \return List of implementations. |
152 */ |
294 */ |
153 QList<XQAiwInterfaceDescriptor> XQServiceManager::findInterfaces ( const QString &serviceName, const QString &interfaceName ) const |
295 QList<XQAiwInterfaceDescriptor> XQServiceManager::findInterfaces ( const QString &serviceName, const QString &interfaceName ) const |
154 { |
296 { |
155 XQSERVICE_DEBUG_PRINT("XQServiceManager::findInterfaces 2"); |
297 XQSERVICE_DEBUG_PRINT("XQServiceManager::findInterfaces 2"); |
156 QList<XQAiwInterfaceDescriptor> interfaces; |
298 QList<XQAiwInterfaceDescriptor> interfaces; |
176 TInt error=d->Discover(interfaceName, appUid, interfaces, XQServiceManagerPrivate::MatchInterfaceName, true); |
318 TInt error=d->Discover(interfaceName, appUid, interfaces, XQServiceManagerPrivate::MatchInterfaceName, true); |
177 return interfaces; |
319 return interfaces; |
178 } |
320 } |
179 |
321 |
180 /*! |
322 /*! |
181 Finds the first implementation for the given service + interface names |
323 Finds the first implementation for the given service + interface names. |
182 \param serviceName Service name |
324 \param serviceName Service name. |
183 \param interfaceName Interfacename to match |
325 \param interfaceName Interfacename to match. |
184 \return List of implementations |
326 \return List of implementations. |
185 */ |
327 */ |
186 QList<XQAiwInterfaceDescriptor> XQServiceManager::findFirstInterface ( const QString &serviceName, const QString &interfaceName ) const |
328 QList<XQAiwInterfaceDescriptor> XQServiceManager::findFirstInterface ( const QString &serviceName, const QString &interfaceName ) const |
187 { |
329 { |
188 XQSERVICE_DEBUG_PRINT("XQServiceManager::findFirstInterface 2"); |
330 XQSERVICE_DEBUG_PRINT("XQServiceManager::findFirstInterface 2"); |
189 QList<XQAiwInterfaceDescriptor> interfaces; |
331 QList<XQAiwInterfaceDescriptor> interfaces; |
195 return interfaces; |
337 return interfaces; |
196 } |
338 } |
197 |
339 |
198 |
340 |
199 /*! |
341 /*! |
200 Returns the latest error occured |
342 Gets the latest error occured. |
|
343 \return Latest error code as integer value. |
201 */ |
344 */ |
202 int XQServiceManager::latestError() const |
345 int XQServiceManager::latestError() const |
203 { |
346 { |
204 return d->LatestError(); |
347 return d->LatestError(); |
205 } |
348 } |
206 |
349 |
207 /*! |
350 /*! |
208 Returns the latest error occured |
351 Checks if the given \a implmentation is running. |
|
352 \param implementation Implementation to be checked. |
|
353 \return true if given \a implementation is running, false otherwise. |
209 */ |
354 */ |
210 bool XQServiceManager::isRunning(const XQAiwInterfaceDescriptor& implementation) const |
355 bool XQServiceManager::isRunning(const XQAiwInterfaceDescriptor& implementation) const |
211 { |
356 { |
212 XQSERVICE_DEBUG_PRINT("XQServiceManager::isRunning"); |
357 XQSERVICE_DEBUG_PRINT("XQServiceManager::isRunning"); |
213 return d->IsRunning(implementation); |
358 return d->IsRunning(implementation); |
387 newApp.Resume(); |
534 newApp.Resume(); |
388 |
535 |
389 User::WaitForRequest( requestStatusForRendezvous ); // Make the rendezvouz |
536 User::WaitForRequest( requestStatusForRendezvous ); // Make the rendezvouz |
390 XQSERVICE_DEBUG_PRINT("XQServiceManagerPrivate::Rendezvous done %d", requestStatusForRendezvous.Int()); |
537 XQSERVICE_DEBUG_PRINT("XQServiceManagerPrivate::Rendezvous done %d", requestStatusForRendezvous.Int()); |
391 |
538 |
|
539 if (!embed) { |
|
540 CProcessInfo::AddProcessL(uid, newApp); |
|
541 } |
|
542 |
392 User::LeaveIfError( requestStatusForRendezvous.Int()); |
543 User::LeaveIfError( requestStatusForRendezvous.Int()); |
393 CleanupStack::PopAndDestroy(2,cmdLine); // newApp, cmdLine |
544 CleanupStack::PopAndDestroy(2,cmdLine); // newApp, cmdLine |
394 |
545 |
395 XQSERVICE_DEBUG_PRINT("XQServiceManagerPrivate::Done"); |
546 XQSERVICE_DEBUG_PRINT("XQServiceManagerPrivate::Done"); |
396 } |
547 } |