qthighway/xqservice/src/xqaiwrequest.cpp
changeset 24 9d760f716ca8
parent 14 6fbed849b4f4
child 26 3d09643def13
equal deleted inserted replaced
19:46686fb6258c 24:9d760f716ca8
    26 #include "xqaiwservicedriver.h"
    26 #include "xqaiwservicedriver.h"
    27 #include "xqaiwfiledriver.h"
    27 #include "xqaiwfiledriver.h"
    28 #include "xqaiwuridriver.h"
    28 #include "xqaiwuridriver.h"
    29 #include "xqaiwrequest.h"
    29 #include "xqaiwrequest.h"
    30 
    30 
       
    31 /*!
       
    32     \class XQAiwRequest
       
    33     \inpublicgroup QtBaseModule
       
    34 
       
    35     \ingroup ipc
       
    36     \brief Encapsulates the core functionality of the interworking requests
       
    37     
       
    38     The XQAiwRequest class encapsulates the core functionality of the interworking requests and hides the implementation details. 
       
    39     This object is created by the XQApplicationManager::create factory method.
       
    40     
       
    41     This class is a part of API to be used by the applications instead of using XQServiceRequest directly.
       
    42     
       
    43     The Application Manager API offers centric place for applications UIs to handle application to application interworking use cases, like:
       
    44     - Synchronous out-of-process service call from client to service provider, where service provider needs to complete the request before
       
    45       control comes back to requesting client.
       
    46     - Asynchronous out-of-process service call from client to service provider, where Service provider completes the request whenever suitable.
       
    47       The control returns back requesting as soon the service provider has received the asynchronous call (can be applied to notifications as well).
       
    48     - Embedded out-of-process service call. In this case window groups are chained and "Back" returns to client window.
       
    49     - Any named Qt type in the Qt meta-object system can be used as a service call parameter or return value. Also own, custom meta-types are supported.
       
    50     - Launched service provider application (.exe) if not already running when client makes service call to it.
       
    51     - List and discover services dynamically.
       
    52     - Apply UI related options upon service launch, like "launch as embedded", "launch to foreground" and "launch to backround".
       
    53     - Opening files to be viewed by a file viewing interface.
       
    54     - Opening URI to be viewed by a URI viewing interface. Includes also launching activity URIs (appto) as fire-and-forget manner.
       
    55     - Miscellanous AIW support, like get service stasus or get DRM attributes.
       
    56     
       
    57     See the "examples/appmgrclient" included in the QtHighway release for usage examples.
       
    58     
       
    59     <b>Example usage:</b> \n
       
    60     The usage pattern for all the XQAiwRequest variants implemented as service providers , interface, QUrl, QFile, is similar both embedded
       
    61     and non-embedded usage.
       
    62     \code
       
    63         // Recommended way is to add XQApplicationManager as member variable to class
       
    64         // Later on when caching of services
       
    65         // You can use the class also as local variable.
       
    66         class Client
       
    67         {
       
    68 
       
    69         public:
       
    70              // Service access
       
    71             bool accessService(void);
       
    72 
       
    73         private slots:
       
    74                 void handleOk(const QVariant &result);
       
    75                 void handleError(int errorCode, const QString& errorMessage);
       
    76         private:
       
    77               XQApplicationManager mAiwMgr;
       
    78         };
       
    79 
       
    80 
       
    81         //  In client.cpp
       
    82         bool Client::accessService(void)
       
    83         {
       
    84             QString parameter1("+3581234567890");
       
    85             int parameter2 = 3;
       
    86 
       
    87             bool embedded=true;  // or false
       
    88 
       
    89             XQAiwRequest *request;
       
    90             // Create request by interface name, the very first service implementation
       
    91             // applied.
       
    92             request = mAiwMgr.create("Interface", "functionName2(QString, int)", embedded);
       
    93 
       
    94             // If dedicated service is wanted, apply this 
       
    95             // request = mAiwMgr.create("Service", "Interface", 
       
    96             //                          "functionName2(QString, int)", embedded);
       
    97 
       
    98             if (request == NULL)
       
    99             {
       
   100                 // Service not found 
       
   101                 return false;
       
   102             }
       
   103 
       
   104             // Connect result handling signal
       
   105             connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
       
   106             // Connect error handling signal or apply lastError function instead.
       
   107             connect(request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
       
   108 
       
   109             // Set function parameters
       
   110            QList<QVariant> args;
       
   111            args << parameter1;
       
   112            args << parameter2;
       
   113            request->setArguments(args);
       
   114 
       
   115            // In this example, request embedded launch (window groups chained)
       
   116            request->setEmbedded(true);
       
   117 
       
   118            // Send the request
       
   119            bool res = request.send();
       
   120            if  (!res) 
       
   121            {
       
   122                // Request failed. 
       
   123               return false;
       
   124            }
       
   125          
       
   126            // If making multiple requests to same service, you can save the request as member variable
       
   127            // In this example all done.
       
   128            delete request;
       
   129            return true;
       
   130         }
       
   131 
       
   132         void Client::handleOk(const QVariant& result)
       
   133         {
       
   134            // Handle result here or just save them.
       
   135            // Result could be a service specific error code also.
       
   136            // 
       
   137         }
       
   138 
       
   139         void Client::handleError(int errorCode, const QString& errorMessage)
       
   140         {
       
   141            // Handle error
       
   142         }
       
   143     \endcode
       
   144     
       
   145     \sa XQApplicationManager
       
   146 */
       
   147 
       
   148 /*!
       
   149     Constructs interworking request to service application by the given interface \a descriptor
       
   150     which points to the dedicated implementation. The service application is not started during
       
   151     creation of the request.
       
   152     \param descriptor Points to the dedicated service implementation. Obtained via the XQApplicationManager::list function.
       
   153     \param operation Service function to be called, equals \a message parameter in XQServiceRequest.
       
   154     \param embedded True if window groups should be chained, false otherwise
       
   155     \return Constructed interworking request to service application object.
       
   156 */
    31 XQAiwRequest::XQAiwRequest(const XQAiwInterfaceDescriptor& descriptor, const QString &operation, bool embedded)
   157 XQAiwRequest::XQAiwRequest(const XQAiwInterfaceDescriptor& descriptor, const QString &operation, bool embedded)
    32     : QObject(),
   158     : QObject(),
    33       currentRequest(NULL),
   159       currentRequest(NULL),
    34       errorMsg(),
   160       errorMsg(),
    35       errorCode(0),
   161       errorCode(0),
    50     {
   176     {
    51         currentRequest->setEmbedded(embedded);
   177         currentRequest->setEmbedded(embedded);
    52     }
   178     }
    53 }
   179 }
    54 
   180 
       
   181 /*!
       
   182     Constructs interworking request to service application by the given uri and the interface \a descriptor
       
   183     which points to the dedicated implementation. The service application is not started during
       
   184     creation of the request.
       
   185     \param uri Uri for the given interworking request to service application.
       
   186     \param descriptor Points to the dedicated service implementation. Obtained via the XQApplicationManager::list function.
       
   187     \param operation Service function to be called, equals \a message parameter in XQServiceRequest.
       
   188     \return Constructed interworking request to service application object.
       
   189 */
    55 XQAiwRequest::XQAiwRequest(
   190 XQAiwRequest::XQAiwRequest(
    56     const QUrl &uri, const XQAiwInterfaceDescriptor& descriptor, const QString &operation)
   191     const QUrl &uri, const XQAiwInterfaceDescriptor& descriptor, const QString &operation)
    57     : QObject(),
   192     : QObject(),
    58       currentRequest(NULL),
   193       currentRequest(NULL),
    59       errorMsg(),
   194       errorMsg(),
    78     }
   213     }
    79     
   214     
    80 }
   215 }
    81 
   216 
    82 
   217 
    83 
   218 /*!
       
   219     Constructs interworking request to service application by the file and the interface \a descriptor
       
   220     which points to the dedicated implementation. The service application is not started during
       
   221     creation of the request.
       
   222     \param file File for the given interworking request to service application.
       
   223     \param descriptor Points to the dedicated service implementation. Obtained via the XQApplicationManager::list function.
       
   224     \param operation Service function to be called, equals \a message parameter in XQServiceRequest.
       
   225     \return Constructed interworking request to service application object.
       
   226 */
    84 XQAiwRequest::XQAiwRequest(
   227 XQAiwRequest::XQAiwRequest(
    85     const QFile &file, const XQAiwInterfaceDescriptor& descriptor, const QString &operation)
   228     const QFile &file, const XQAiwInterfaceDescriptor& descriptor, const QString &operation)
    86     : QObject(),
   229     : QObject(),
    87      currentRequest(NULL),
   230      currentRequest(NULL),
    88       errorMsg(),
   231       errorMsg(),
   110        currentRequest = new XQAiwFileDriver(file, descriptor, operation);
   253        currentRequest = new XQAiwFileDriver(file, descriptor, operation);
   111    }
   254    }
   112        
   255        
   113 }
   256 }
   114 
   257 
   115 
   258 /*!
       
   259     Constructs interworking request to service application by the sharable file and the interface \a descriptor
       
   260     which points to the dedicated implementation. The service application is not started during
       
   261     creation of the request.
       
   262     \param file Sharable file for the given interworking request to service application.
       
   263     \param descriptor Points to the dedicated service implementation. Obtained via the XQApplicationManager::list function.
       
   264     \param operation Service function to be called, equals \a message parameter in XQServiceRequest.
       
   265     \return Constructed interworking request to service application object.
       
   266 */
   116 XQAiwRequest::XQAiwRequest(
   267 XQAiwRequest::XQAiwRequest(
   117      const XQSharableFile &file, const XQAiwInterfaceDescriptor& descriptor, const QString &operation)
   268      const XQSharableFile &file, const XQAiwInterfaceDescriptor& descriptor, const QString &operation)
   118     : QObject(),
   269     : QObject(),
   119       currentRequest(NULL),
   270       currentRequest(NULL),
   120       errorMsg(),
   271       errorMsg(),
   141         currentRequest = new XQAiwFileDriver(file, descriptor, operation);
   292         currentRequest = new XQAiwFileDriver(file, descriptor, operation);
   142     }
   293     }
   143 
   294 
   144 }
   295 }
   145 
   296 
   146             
   297 
   147 XQAiwRequest::~XQAiwRequest()
   298 XQAiwRequest::~XQAiwRequest()
   148 {
   299 {
   149     XQSERVICE_DEBUG_PRINT("~XQAiwRequest::XQAiwRequest");
   300     XQSERVICE_DEBUG_PRINT("~XQAiwRequest::XQAiwRequest");
   150 
   301 
   151     // Disconnect signals
   302     // Disconnect signals
   167 }
   318 }
   168 
   319 
   169 /*!
   320 /*!
   170     Create a QAction related to request from the registration data. Caller can
   321     Create a QAction related to request from the registration data. Caller can
   171     add the action to wanted UI widget. When the action  is triggered the XQAiwRequest
   322     add the action to wanted UI widget. When the action  is triggered the XQAiwRequest
   172     emits "triggered" signal for caller.
   323     emits triggered() signal for caller.
   173     The XQAiwRequest owns the action (caller shall not delete the action object).
   324     The XQAiwRequest owns the action (caller shall not delete the action object).
   174     \return QAction object, if there was action attached to request. Otherwise 0.
   325     \return QAction object, if there was action attached to request. Otherwise 0.
   175 */
   326 */
   176 QAction *XQAiwRequest::createAction()
   327 QAction *XQAiwRequest::createAction()
   177 {
   328 {
   191 }
   342 }
   192 
   343 
   193 /*!
   344 /*!
   194     Set arguments for the request. This shall be called before sending
   345     Set arguments for the request. This shall be called before sending
   195     add the action to wanted UI widget. For the attached action, the
   346     add the action to wanted UI widget. For the attached action, the
   196     "triggered" signal emitted by the request is the last chance to
   347     triggered() signal emitted by the request is the last chance to
   197     add aguments.
   348     add aguments.
       
   349     \param arguments List of arguments that will be transferred to service provider function
       
   350                      to be called
   198 */
   351 */
   199 void XQAiwRequest::setArguments(const QList<QVariant> &arguments)
   352 void XQAiwRequest::setArguments(const QList<QVariant> &arguments)
   200 {
   353 {
   201     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setArguments");
   354     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setArguments");
   202     currentRequest->setArguments(arguments);
   355     currentRequest->setArguments(arguments);
   204 
   357 
   205 
   358 
   206 /*!
   359 /*!
   207     Returns the last error code occured.
   360     Returns the last error code occured.
   208     IPC errors:
   361     IPC errors:
   209         EConnectionError  = -5000,  (Server might be busy)
   362         - ENoError          = 0
   210         EConnectionClosed = -4999,  
   363         - EConnectionError  = -5000,  (Server might be busy)
   211         EServerNotFound   = -4998,
   364         - EConnectionClosed = -4999,  
   212         EIPCError         = -4997,
   365         - EServerNotFound   = -4998,
   213         EUnknownError     = -4996,
   366         - EIPCError         = -4997,
   214         ERequestPending   = -4995   (already pending request exists)
   367         - EUnknownError     = -4996,
   215         EM   = -4995   (already pending request exists)
   368         - ERequestPending   = -4995,  (already pending request exists)
       
   369         - EMessageNotFound  = -4994,
       
   370         - EArgumentError    = -4993
       
   371     \return Error code as integer value.
       
   372     \sa xqserviceglobal.h for error codes
   216 
   373 
   217 */
   374 */
   218 int XQAiwRequest::lastError() const
   375 int XQAiwRequest::lastError() const
   219 {
   376 {
   220     int err = currentRequest->lastError();
   377     int err = currentRequest->lastError();
   224 
   381 
   225 /*!
   382 /*!
   226     Returns the last error as text for debugging purposes.
   383     Returns the last error as text for debugging purposes.
   227     The content and details of the text may vary over API
   384     The content and details of the text may vary over API
   228     development time evolution.
   385     development time evolution.
       
   386     \return Error code as QString value.
   229 */
   387 */
   230 const QString& XQAiwRequest::lastErrorMessage() const
   388 const QString& XQAiwRequest::lastErrorMessage() const
   231 {
   389 {
   232     XQSERVICE_DEBUG_PRINT("XQAiwRequest::lastErrorMessage");
   390     XQSERVICE_DEBUG_PRINT("XQAiwRequest::lastErrorMessage");
   233     return currentRequest->lastErrorMessage();
   391     return currentRequest->lastErrorMessage();
   235 
   393 
   236 
   394 
   237 /*!
   395 /*!
   238     Returns the implementation descriptor of a service attached to request.
   396     Returns the implementation descriptor of a service attached to request.
   239     Caller can check meta-data information of the request.
   397     Caller can check meta-data information of the request.
       
   398     \return Implementation descriptor attached to the request.
   240 */
   399 */
   241 const XQAiwInterfaceDescriptor &XQAiwRequest::descriptor() const 
   400 const XQAiwInterfaceDescriptor &XQAiwRequest::descriptor() const 
   242 {
   401 {
   243     XQSERVICE_DEBUG_PRINT("XQAiwRequest::descriptor");
   402     XQSERVICE_DEBUG_PRINT("XQAiwRequest::descriptor");
   244     return currentRequest->descriptor();
   403     return currentRequest->descriptor();
   245 }
   404 }
   246 
   405 
   247 /*!
   406 /*!
   248     Send request on-ward.
   407     Starts the service application if necessary and sends request on-ward.
   249     The results are delivered via "requestOk" and "requestError" signals.
   408     The results are delivered via requestOk() and requestError() signals.
   250     \return true on success, false otherwise
   409     If the request is synchronous, the client application is blocked until
       
   410     service provider completes the request.
       
   411     \return True on success, false otherwise
   251 */
   412 */
   252 bool XQAiwRequest::send()
   413 bool XQAiwRequest::send()
   253 {
   414 {
   254     XQSERVICE_DEBUG_PRINT("XQAiwRequest::send");
   415     XQSERVICE_DEBUG_PRINT("XQAiwRequest::send");
   255 
   416 
   273 
   434 
   274 
   435 
   275 /*!
   436 /*!
   276     Convinience method for sending a synchronous request on-ward.
   437     Convinience method for sending a synchronous request on-ward.
   277     The returnValue delivered via the output parameter.
   438     The returnValue delivered via the output parameter.
   278     \return true on success, false otherwise
   439     \return True on success, false otherwise
   279 */
   440 */
   280 bool XQAiwRequest::send(QVariant &returnValue)
   441 bool XQAiwRequest::send(QVariant &returnValue)
   281 {
   442 {
   282 
   443 
   283     XQSERVICE_DEBUG_PRINT("XQAiwRequest::send(retValue)");
   444     XQSERVICE_DEBUG_PRINT("XQAiwRequest::send(retValue)");
   300         return false;
   461         return false;
   301     }
   462     }
   302    
   463    
   303 }
   464 }
   304 
   465 
   305 
   466 /*!
       
   467     Request service application to be launched in embedded mode.
       
   468     \param embedded If set to true, service application will be launched
       
   469                     in embedded mode
       
   470 */
   306 void XQAiwRequest::setEmbedded(bool embedded)
   471 void XQAiwRequest::setEmbedded(bool embedded)
   307 {
   472 {
   308     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setEmbedded=%d",embedded);
   473     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setEmbedded=%d",embedded);
   309     currentRequest->setEmbedded(embedded);
   474     currentRequest->setEmbedded(embedded);
   310 }
   475 }
       
   476 
       
   477 /*!
       
   478     Get the value of embedded option of the request.
       
   479     \return True if request is set to launch service application in embedded
       
   480             mode, false otherwise
       
   481 */
   311 bool XQAiwRequest::isEmbedded() const
   482 bool XQAiwRequest::isEmbedded() const
   312 {
   483 {
   313     XQSERVICE_DEBUG_PRINT("XQAiwRequest::isEmbedded");
   484     XQSERVICE_DEBUG_PRINT("XQAiwRequest::isEmbedded");
   314     return currentRequest->isEmbedded();
   485     return currentRequest->isEmbedded();
   315 }
   486 }
   316 
   487 
       
   488 /*!
       
   489     Sets service operation. The XQApplicationManager::create() functions for
       
   490     files and URLs set the default operation, but it can be overriden using
       
   491     this function.
       
   492     \param operation Operation to be set to the request.
       
   493 */
   317 void XQAiwRequest::setOperation(const QString &operation)
   494 void XQAiwRequest::setOperation(const QString &operation)
   318 {
   495 {
   319     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setOperation");
   496     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setOperation");
   320     currentRequest->setOperation(operation);
   497     currentRequest->setOperation(operation);
   321 }
   498 }
   322 
   499 
       
   500 /*!
       
   501     Returns operation attached to the request.
       
   502     \return Operation attached to the request
       
   503 */
   323 const QString &XQAiwRequest::operation() const
   504 const QString &XQAiwRequest::operation() const
   324 {
   505 {
   325     XQSERVICE_DEBUG_PRINT("XQAiwRequest::operation");
   506     XQSERVICE_DEBUG_PRINT("XQAiwRequest::operation");
   326     return currentRequest->operation();
   507     return currentRequest->operation();
   327 }
   508 }
   328 
   509 
   329 
   510 /*!
       
   511     Sets request as synchronous or asynchronous, based on the \a synchronous value.
       
   512     \param synchronous If set to true, request will be synchronous.
       
   513                        If set to false, request will be asynchronous
       
   514 */
   330 void XQAiwRequest::setSynchronous(bool synchronous)
   515 void XQAiwRequest::setSynchronous(bool synchronous)
   331 {
   516 {
   332     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setSynchronous=%d", synchronous);
   517     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setSynchronous=%d", synchronous);
   333     currentRequest->setSynchronous(synchronous);
   518     currentRequest->setSynchronous(synchronous);
   334 }
   519 }
       
   520 
       
   521 /*!
       
   522     Returns the value of the synchronous option.
       
   523     \return True if request is synchronous, false otherwise
       
   524 */
   335 bool XQAiwRequest::isSynchronous() const
   525 bool XQAiwRequest::isSynchronous() const
   336 {
   526 {
   337     XQSERVICE_DEBUG_PRINT("XQAiwRequest::isSynchronous");
   527     XQSERVICE_DEBUG_PRINT("XQAiwRequest::isSynchronous");
   338     return currentRequest->isSynchronous();
   528     return currentRequest->isSynchronous();
   339 }
   529 }
   340 
   530 
       
   531 /*!
       
   532     Requests service application to be launched to background initially,
       
   533     or if already running, to go to background.
       
   534     \param background If set to true, service application will be launched
       
   535                       to background
       
   536 */
   341 void XQAiwRequest::setBackground(bool background )
   537 void XQAiwRequest::setBackground(bool background )
   342 {
   538 {
   343     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setbackground=%d", background);
   539     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setbackground=%d", background);
   344     currentRequest->setBackground(background);
   540     currentRequest->setBackground(background);
   345 }
   541 }
   346 
   542 
       
   543 /*!
       
   544     Returns the value of the background option.
       
   545     \return True if request is set to launch service
       
   546                  application to background
       
   547 */
   347 bool XQAiwRequest::isBackground() const
   548 bool XQAiwRequest::isBackground() const
   348 {
   549 {
   349     XQSERVICE_DEBUG_PRINT("XQAiwRequest::isBackground");
   550     XQSERVICE_DEBUG_PRINT("XQAiwRequest::isBackground");
   350     return currentRequest->isBackground();
   551     return currentRequest->isBackground();
   351 }
   552 }
   352 
   553 
       
   554 /*!
       
   555     Used to set additional UI behavior type options to the request.
       
   556     Embedded and background options are handled by their own functions.
       
   557     This function should not be used to implement additional data
       
   558     parameters for operations!
       
   559     \param info UI bahavior type option to be set to the request.
       
   560 */
   353 void XQAiwRequest::setInfo(const XQRequestInfo &info)
   561 void XQAiwRequest::setInfo(const XQRequestInfo &info)
   354 {
   562 {
   355     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setInfo");
   563     XQSERVICE_DEBUG_PRINT("XQAiwRequest::setInfo");
   356     return currentRequest->setInfo(info);
   564     return currentRequest->setInfo(info);
   357 }
   565 }
   358 
   566 
       
   567 /*!
       
   568     Returns additional options attached to the request.
       
   569     \return Additional options attached to the request.
       
   570 */
   359 XQRequestInfo XQAiwRequest::info() const
   571 XQRequestInfo XQAiwRequest::info() const
   360 {
   572 {
   361     XQSERVICE_DEBUG_PRINT("XQAiwRequest::info");
   573     XQSERVICE_DEBUG_PRINT("XQAiwRequest::info");
   362     return currentRequest->info();
   574     return currentRequest->info();
   363 }
   575 }