qthighway/xqserviceipc/xqserviceipc/xqserviceipc_apasymbian.cpp
changeset 24 9d760f716ca8
parent 4 90517678cc4f
equal deleted inserted replaced
19:46686fb6258c 24:9d760f716ca8
    41 const TInt KServerMinorVersionNumber = 0;
    41 const TInt KServerMinorVersionNumber = 0;
    42 const TInt KServerBuildVersionNumber = 0;
    42 const TInt KServerBuildVersionNumber = 0;
    43 
    43 
    44 
    44 
    45 /*!
    45 /*!
    46  \class CApaSymbianIPC
    46     \class CApaSymbianIPC
    47 
    47     \brief Symbian Client backend for the service IPC
    48  Symbian Client backend for the service IPC
    48 */
    49  */
    49 
    50 
    50 /*!
    51 /*!
    51     Constructor.
    52  Constructor
    52 */
    53  */
       
    54 CApaSymbianIPC::CApaSymbianIPC() :
    53 CApaSymbianIPC::CApaSymbianIPC() :
    55     CActive(CActive::EPriorityStandard), iDataSize(0)
    54     CActive(CActive::EPriorityStandard), iDataSize(0)
    56 {
    55 {
    57     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::CApaSymbianIPC");
    56     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::CApaSymbianIPC");
    58     CActiveScheduler::Add(this);
    57     CActiveScheduler::Add(this);
    59 }
    58 }
    60 
    59 
    61 /*!
    60 /*!
    62  Destructor 
    61     Destructor.
    63  */
    62 */
    64 CApaSymbianIPC::~CApaSymbianIPC()
    63 CApaSymbianIPC::~CApaSymbianIPC()
    65 {
    64 {
    66     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::~CApaSymbianIPC");
    65     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::~CApaSymbianIPC");
    67     Cancel();
    66     Cancel();
    68     delete iAsyncData;
    67     delete iAsyncData;
    69     delete iRequestData;
    68     delete iRequestData;
    70 }
    69 }
    71 
    70 
    72 /*!
    71 /*!
    73  2nd phased constructor
    72     2nd phased constructor.
    74  */
    73 */
    75 void CApaSymbianIPC::ConstructL()
    74 void CApaSymbianIPC::ConstructL()
    76 {
    75 {
    77     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::ConstructL");
    76     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::ConstructL");
    78 	iServerExitMonitor = NULL;
    77 	iServerExitMonitor = NULL;
    79 }
    78 }
    80 
    79 
    81 /*!
    80 /*!
    82  Two Phased Constructor
    81     Two Phased Constructor.
    83  */
    82 */
    84 CApaSymbianIPC* CApaSymbianIPC::NewL()
    83 CApaSymbianIPC* CApaSymbianIPC::NewL()
    85 {
    84 {
    86     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::NewL");
    85     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::NewL");
    87     CApaSymbianIPC* self = new(ELeave) CApaSymbianIPC();
    86     CApaSymbianIPC* self = new(ELeave) CApaSymbianIPC();
    88     CleanupStack::PushL(self);
    87     CleanupStack::PushL(self);
    90     CleanupStack::Pop(self);
    89     CleanupStack::Pop(self);
    91     return self;
    90     return self;
    92 }
    91 }
    93 
    92 
    94 /*!
    93 /*!
    95  Connect to the server
    94     Connect to the server.
    96  @param aServerName name of the server to connect to
    95     \param aServerName Name of the server to connect to.
    97  @return true if connected, false if not
    96     \return true if connected, false if not.
    98  */
    97 */
    99 bool CApaSymbianIPC::connect( const QString& aServerName )
    98 bool CApaSymbianIPC::connect( const QString& aServerName )
   100 {
    99 {
   101     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::connect");
   100     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::connect");
   102     // Version informaton
   101     // Version informaton
   103     TVersion version(KServerMajorVersionNumber, 
   102     TVersion version(KServerMajorVersionNumber, 
   112     
   111     
   113     return (err == KErrNone);
   112     return (err == KErrNone);
   114 }
   113 }
   115 
   114 
   116 /*!
   115 /*!
   117  Disconnect from the server
   116     Disconnect from the server.
   118  */
   117 */
   119 void CApaSymbianIPC::disconnect()
   118 void CApaSymbianIPC::disconnect()
   120 {
   119 {
   121     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::disconnect");
   120     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::disconnect");
   122     // Note !
   121     // Note !
   123     // iServerExitMonitor->Cancel will cause request cancellation 
   122     // iServerExitMonitor->Cancel will cause request cancellation 
   129     }
   128     }
   130     iSession.Close();
   129     iSession.Close();
   131 }
   130 }
   132 
   131 
   133 /*!
   132 /*!
   134  Starts the service
   133     Starts the service.
   135  @param aServerName server name
   134     \param aServerName Server name.
   136  @param aExeName server executable name
   135     \param aExeName Server executable name.
   137  */
   136     \return true if start was successful.
       
   137 */
   138 bool CApaSymbianIPC::startServer( const QString& aServerName, 
   138 bool CApaSymbianIPC::startServer( const QString& aServerName, 
   139                                   const QString& /*aExeName*/, 
   139                                   const QString& /*aExeName*/, 
   140                                   quint64& processId,
   140                                   quint64& processId,
   141                                   int options)
   141                                   int options)
   142 {
   142 {
   163     iSession.setServiceUid(appUid);
   163     iSession.setServiceUid(appUid);
   164     return (ret == KErrNone);
   164     return (ret == KErrNone);
   165 }
   165 }
   166 
   166 
   167 /*!
   167 /*!
   168  Send a request synchronously
   168     Send a request synchronously.
   169  @param aRequestType type of request to send to the server
   169     \param aRequestType Type of request to send to the server.
   170  @param aData data to send to the server
   170     \param aData Data to send to the server.
   171  */
   171     \return true if send was successful.
       
   172 */
   172 bool CApaSymbianIPC::sendSync( const QString& aRequestType, const QByteArray& aData )
   173 bool CApaSymbianIPC::sendSync( const QString& aRequestType, const QByteArray& aData )
   173 {
   174 {
   174     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::sendSync");
   175     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::sendSync");
   175     // Convert from QString to TPtr
   176     // Convert from QString to TPtr
   176     TPtrC request(reinterpret_cast<const TUint16*> (aRequestType.utf16()));
   177     TPtrC request(reinterpret_cast<const TUint16*> (aRequestType.utf16()));
   202     
   203     
   203     return (err == KErrNone);
   204     return (err == KErrNone);
   204 }
   205 }
   205 
   206 
   206 
   207 
   207 /*
   208 /*!
   208  * read sync
   209     Read sync.
   209  */
   210     \return Result of read as QByteArray.
       
   211 */
   210 QByteArray CApaSymbianIPC::readAll()
   212 QByteArray CApaSymbianIPC::readAll()
   211 {
   213 {
   212     // this is sync operation
   214     // this is sync operation
   213     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::readAll");
   215     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::readAll");
   214     QByteArray rtn;
   216     QByteArray rtn;
   246 }
   248 }
   247 
   249 
   248 
   250 
   249 
   251 
   250 /*!
   252 /*!
   251  Send a request asynchronously
   253     Send a request asynchronously.
   252  @param aRequestType type of request to send to the server
   254     \param aRequestType Type of request to send to the server.
   253  @param aData data to send to the server
   255     \param aData Data to send to the server.
   254  */
   256 */
   255 void CApaSymbianIPC::sendAsync(const QString& aRequestType,
   257 void CApaSymbianIPC::sendAsync(const QString& aRequestType,
   256 							   const QByteArray& aData )
   258 							   const QByteArray& aData )
   257 {
   259 {
   258     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::sendAsync");
   260     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::sendAsync");
   259     delete iRequestData;
   261     delete iRequestData;
   303         }
   305         }
   304     
   306     
   305 }
   307 }
   306 
   308 
   307 /*!
   309 /*!
   308  Reads all data pending in the buffer, leaves if an error occured
   310     Reads all data pending in the buffer, leaves if an error occured
   309  @return QByteArray containing the result data
   311     \return QByteArray Containing the result data.
   310  */
   312 */
   311 void CApaSymbianIPC::doReadAllL(QByteArray& aArray)
   313 void CApaSymbianIPC::doReadAllL(QByteArray& aArray)
   312 {
   314 {
   313     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::doReadAllL");
   315     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::doReadAllL");
   314     
   316     
   315 	//shouldn't be active when this is called
   317 	//shouldn't be active when this is called
   329     SetActive();
   331     SetActive();
   330 }
   332 }
   331 
   333 
   332 
   334 
   333 /*!
   335 /*!
   334  Maps error codes from Symbian error codes to Service IPC error codes
   336     Maps error codes from Symbian error codes to Service IPC error codes
   335  @param aError Symbian error code
   337     \param aError Symbian error code.
   336  @return mapped error code
   338     \return Mapped error code.
   337  */
   339 */
   338 int CApaSymbianIPC::doMapErrors(TInt aError)
   340 int CApaSymbianIPC::doMapErrors(TInt aError)
   339 {
   341 {
   340     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::doMapErrors");
   342     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::doMapErrors");
   341     int error(ERROR_NoError);
   343     int error(ERROR_NoError);
   342     switch (aError) {
   344     switch (aError) {
   376     }
   378     }
   377     }
   379     }
   378     return error;
   380     return error;
   379 }
   381 }
   380 /*!
   382 /*!
   381  Waits until data is available for reading 
   383     Waits until data is available for reading.
   382  @return bool always true, no need to wait
   384     \return bool always true, no need to wait.
   383  */
   385 */
   384 bool CApaSymbianIPC::waitForRead()
   386 bool CApaSymbianIPC::waitForRead()
   385 {
   387 {
   386     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::waitForRead");
   388     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::waitForRead");
   387     // Symbian Client-server is blocking, so no need to wait for read
   389     // Symbian Client-server is blocking, so no need to wait for read
   388     return true;
   390     return true;
   389 }
   391 }
   390 
   392 
   391 /*!
   393 /*!
   392  Active object callback
   394     Active object callback
   393  */
   395 */
   394 TInt CApaSymbianIPC::RunError(TInt err)
   396 TInt CApaSymbianIPC::RunError(TInt err)
   395 {
   397 {
   396     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::error %d", err);
   398     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::error %d", err);
   397     emitError(doMapErrors(err));
   399     emitError(doMapErrors(err));
   398     
   400     
   399     return KErrNone;
   401     return KErrNone;
   400 }
   402 }
   401 
   403 
       
   404 /*!
       
   405     Active object RunL function.
       
   406 */
   402 void CApaSymbianIPC::RunL()
   407 void CApaSymbianIPC::RunL()
   403 {
   408 {
   404     int err = iStatus.Int();
   409     int err = iStatus.Int();
   405     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::RunL %d", err);
   410     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::RunL %d", err);
   406     User::LeaveIfError( err );
   411     User::LeaveIfError( err );
   439             }
   444             }
   440         }
   445         }
   441 }
   446 }
   442 
   447 
   443 /*!
   448 /*!
   444  Active object cancel
   449     Active object cancel
   445  */
   450 */
   446 void CApaSymbianIPC::DoCancel()
   451 void CApaSymbianIPC::DoCancel()
   447 {
   452 {
   448     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::DoCancel");
   453     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::DoCancel");
   449     // We can't cancel in the IPC design.
   454     // We can't cancel in the IPC design.
   450  
   455  
   462         XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::StartExitMonitor status=%d",err);
   467         XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::StartExitMonitor status=%d",err);
   463         }
   468         }
   464 }
   469 }
   465 
   470 
   466 /*!
   471 /*!
   467  HandleServerAppExit
   472     HandleServerAppExit
   468  */
   473 */
   469 void CApaSymbianIPC::HandleServerAppExit(int aReason)
   474 void CApaSymbianIPC::HandleServerAppExit(int aReason)
   470 {
   475 {
   471     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::HandleServerAppExit");
   476     XQSERVICE_DEBUG_PRINT("CApaSymbianIPC::HandleServerAppExit");
   472     if (iServerExitMonitor) {
   477     if (iServerExitMonitor) {
   473         iServerExitMonitor->Cancel();
   478         iServerExitMonitor->Cancel();