52 }; |
52 }; |
53 |
53 |
54 XQServiceIpcClient::XQServiceIpcClient(const QString& ipcConName, bool isServer, |
54 XQServiceIpcClient::XQServiceIpcClient(const QString& ipcConName, bool isServer, |
55 bool isSync, XQServiceRequestCompletedAsync* rc, |
55 bool isSync, XQServiceRequestCompletedAsync* rc, |
56 const void *userData) |
56 const void *userData) |
57 : QObject(), serviceIpc(NULL), serviceIpcServer(NULL), callBackRequestComplete(rc), |
57 : QObject(), cancelledRequest(NULL), serviceIpc(NULL), serviceIpcServer(NULL), callBackRequestComplete(rc), |
58 mUserData(userData) // User data can be NULL ! |
58 mUserData(userData) // User data can be NULL ! |
59 { |
59 { |
60 XQSERVICE_DEBUG_PRINT("XQServiceIpcClient::XQServiceIpcClient"); |
60 XQSERVICE_DEBUG_PRINT("XQServiceIpcClient::XQServiceIpcClient"); |
61 XQSERVICE_DEBUG_PRINT("ipcConName: %s, isServer: %d, isSync: %d", qPrintable(ipcConName), isServer, isSync); |
61 XQSERVICE_DEBUG_PRINT("ipcConName: %s, isServer: %d, isSync: %d", qPrintable(ipcConName), isServer, isSync); |
62 XQSERVICE_DEBUG_PRINT("userData: %x, (int)userData)"); |
62 XQSERVICE_DEBUG_PRINT("userData: %x, (int)userData)"); |
145 |
145 |
146 connect(serviceIpc, SIGNAL(error(int)), this, SLOT(clientError(int))); |
146 connect(serviceIpc, SIGNAL(error(int)), this, SLOT(clientError(int))); |
147 connect(serviceIpc, SIGNAL(readyRead()), this, SLOT(readyRead())); |
147 connect(serviceIpc, SIGNAL(readyRead()), this, SLOT(readyRead())); |
148 XQSERVICE_DEBUG_PRINT("embedded: %d", embedded); |
148 XQSERVICE_DEBUG_PRINT("embedded: %d", embedded); |
149 if (embedded) { |
149 if (embedded) { |
|
150 // You can have only one embedded service in use at a time !!! |
150 // Start application in embedded mode (add process ID to connection name !) |
151 // Start application in embedded mode (add process ID to connection name !) |
151 quint64 processId=0; |
152 quint64 processId=0; |
152 bool ret = serviceIpc->startServer(mIpcConName,"", processId, ServiceFwIPC::EStartInEmbeddedMode); |
153 bool ret = serviceIpc->startServer(mIpcConName,"", processId, ServiceFwIPC::EStartInEmbeddedMode); |
153 XQSERVICE_DEBUG_PRINT("ret: %d", ret); |
154 XQSERVICE_DEBUG_PRINT("ret: %d", ret); |
154 if (ret && (processId > 0)) { |
155 if (ret && (processId > 0)) { |
248 } |
249 } |
249 XQSERVICE_DEBUG_PRINT("data: %s", data.constData()); |
250 XQSERVICE_DEBUG_PRINT("data: %s", data.constData()); |
250 QVariant ret; |
251 QVariant ret; |
251 // Processing command on server side. |
252 // Processing command on server side. |
252 if (command == XQServiceCmd_Send) { |
253 if (command == XQServiceCmd_Send) { |
253 //TODO: just a hack to be study how get foreground when need |
|
254 // maparnan: XQServiceUtil::toBackground(false); |
|
255 |
|
256 //Only support 1 sharable file, so index is 0 |
254 //Only support 1 sharable file, so index is 0 |
257 ret=XQServiceChannel::sendLocally(channel, msg, data, aRequest->sharableFile(0) ); |
255 ret=XQServiceChannel::sendLocally(channel, msg, data, aRequest->sharableFile(0) ); |
258 } |
256 } |
259 else if (command == XQServiceCmd_ReturnValueDelivered) { |
257 else if (command == XQServiceCmd_ReturnValueDelivered) { |
260 XQServiceChannel::sendCommand(channel,XQServiceChannel::ReturnValueDelivered); |
258 XQServiceChannel::sendCommand(channel,XQServiceChannel::ReturnValueDelivered); |
275 void XQServiceIpcClient::handleCancelRequest(ServiceIPCRequest* aRequest) |
273 void XQServiceIpcClient::handleCancelRequest(ServiceIPCRequest* aRequest) |
276 { |
274 { |
277 XQSERVICE_DEBUG_PRINT("XQServiceIpcClient::handleCancelRequest isServer?=%d", server); |
275 XQSERVICE_DEBUG_PRINT("XQServiceIpcClient::handleCancelRequest isServer?=%d", server); |
278 if (server) |
276 if (server) |
279 { |
277 { |
|
278 // Save the request to be cancelled if service provider wants to as |
|
279 // XQRequestInfo for details |
|
280 // Valid only upon sendCommand call |
|
281 cancelledRequest = aRequest; |
|
282 |
280 //Attention! At the moment channel name and connection name are the same |
283 //Attention! At the moment channel name and connection name are the same |
281 // it might be that in the future will be different then this is not valid anymore. |
284 // it might be that in the future will be different then this is not valid anymore. |
282 XQServiceChannel::sendCommand(mIpcConName,XQServiceChannel::ClientDisconnected); |
285 XQServiceChannel::sendCommand(mIpcConName,XQServiceChannel::ClientDisconnected); |
|
286 |
|
287 // Remember to reset immediatelly |
|
288 cancelledRequest = 0; |
|
289 |
283 cancelRequest(aRequest); |
290 cancelRequest(aRequest); |
284 } |
291 } |
285 } |
292 } |
286 |
293 |
287 /* |
294 /* |
760 // Returns the handle of the current request |
767 // Returns the handle of the current request |
761 // |
768 // |
762 ServiceIPCRequest *XQServiceIpcClient::requestPtr(int index) const |
769 ServiceIPCRequest *XQServiceIpcClient::requestPtr(int index) const |
763 { |
770 { |
764 ServiceIPCRequest* request = NULL; |
771 ServiceIPCRequest* request = NULL; |
|
772 |
|
773 // If request is being cancelled (saved by handleCancelRequest()) use it's id instead |
|
774 // By that way service provider can access the XQRequestInfo of the cancelled request |
|
775 // Upon handling clientDisconnected |
|
776 if (cancelledRequest) |
|
777 { |
|
778 index = cancelledRequest->id(); |
|
779 XQSERVICE_DEBUG_PRINT("\t Cancelled request id=%d", index); |
|
780 } |
765 |
781 |
766 if (requestsMap.contains(index)) { |
782 if (requestsMap.contains(index)) { |
767 XQSERVICE_DEBUG_PRINT("\t request having id=%d FOUND", index); |
783 XQSERVICE_DEBUG_PRINT("\t request having id=%d FOUND", index); |
768 request = requestsMap[index]; |
784 request = requestsMap[index]; |
769 } else { |
785 } else { |