qthighway/xqservice/src/xqserviceipcclient.h
branchRCL_3
changeset 9 5d007b20cfd0
equal deleted inserted replaced
8:885c2596c964 9:5d007b20cfd0
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:                                                         
       
    19 *
       
    20 */
       
    21 
       
    22 #ifndef XQSERVICECLIENT_H
       
    23 #define XQSERVICECLIENT_H
       
    24 
       
    25 #include <QtCore/qobject.h>
       
    26 
       
    27 #include <xqserviceipcobserver.h>
       
    28 #include <xqrequestinfo.h>
       
    29 
       
    30 namespace QtService {
       
    31 class MServiceIPCObserver;
       
    32 class ServiceIPCRequest;
       
    33 class ServiceFwIPCServer;
       
    34 class ServiceFwIPC;
       
    35 }
       
    36 using namespace QtService;
       
    37 
       
    38 #include <QtCore/qshareddata.h>
       
    39 #include <QtCore/qregexp.h>
       
    40 
       
    41 class QEventLoop;
       
    42 class XQServiceChannel;
       
    43 class XQServiceRequestCompletedAsync;
       
    44 class XQServiceProvider;
       
    45 
       
    46 #define	XQServiceCmd_Send		        	1
       
    47 #define XQServiceCmd_ReturnValueDelivered   2
       
    48 
       
    49 class XQServiceIpcClient : public QObject,
       
    50                            public MServiceIPCObserver
       
    51 {
       
    52     Q_OBJECT
       
    53 public:
       
    54     XQServiceIpcClient(const QString& ipcConName, bool isServer, 
       
    55                        bool isSync, XQServiceRequestCompletedAsync* rc,
       
    56                        const void *userData);
       
    57     ~XQServiceIpcClient();
       
    58 
       
    59     bool listen();
       
    60     bool connectToServer();
       
    61 
       
    62     bool sendChannelCommand(int cmd, const QString& ch);
       
    63     bool send(const QString& ch, const QString& msg, const QByteArray& data, QByteArray &retData,
       
    64               int cmd = XQServiceCmd_Send);
       
    65     bool cancelPendingSend(const QString& ch);
       
    66     
       
    67     bool isServer() const { return server; }
       
    68 
       
    69     int setCurrentRequest(ServiceIPCRequest* request);
       
    70     int setCurrentRequestAsync();
       
    71     bool completeRequest(int index, const QVariant& retValue);
       
    72     bool cancelRequest(ServiceIPCRequest* request);
       
    73     XQRequestInfo requestInfo() const;
       
    74     bool setRequestInfo(XQRequestInfo &info);
       
    75     
       
    76 signals:
       
    77 
       
    78 public slots:
       
    79     void disconnected();
       
    80     
       
    81 private slots:
       
    82     // ServiceFwIPC error
       
    83     void clientError(int);
       
    84     void readyRead();
       
    85     void readDone();
       
    86     
       
    87 private: // from MServiceIPCObserver
       
    88     bool handleRequest(ServiceIPCRequest *aRequest);
       
    89     void handleCancelRequest(ServiceIPCRequest* aRequest);
       
    90     void handleDeleteRequest(ServiceIPCRequest* aRequest);
       
    91     bool isEmbedded();
       
    92     
       
    93 private:    
       
    94     void wait(int msec);
       
    95     ServiceIPCRequest *requestPtr(int index) const; 
       
    96     
       
    97 private:
       
    98     bool server;
       
    99     bool synchronous;
       
   100     int retryCount;
       
   101     
       
   102     QEventLoop* sendSyncLoop;
       
   103 
       
   104     QString mIpcConName ;
       
   105 
       
   106     ServiceIPCRequest* cancelledRequest; 
       
   107     
       
   108     ServiceFwIPC* serviceIpc;
       
   109     ServiceFwIPCServer* serviceIpcServer;    
       
   110     
       
   111     static const int minPacketSize = 256;
       
   112     static const int retryToServerMax = 50;
       
   113     
       
   114     char outBuffer[minPacketSize];
       
   115     XQServiceRequestCompletedAsync* callBackRequestComplete;
       
   116     QObject* plugin;
       
   117     XQServiceProvider* localProvider;
       
   118 	
       
   119 	QByteArray iRetData;
       
   120     const void *mUserData;
       
   121     
       
   122     int lastId;
       
   123     QHash<int, ServiceIPCRequest*> requestsMap;
       
   124     
       
   125 };
       
   126 
       
   127 #endif