ximpfw/core/srcclient/ximpsrvcontextclient.cpp
changeset 51 61fad867f68e
equal deleted inserted replaced
-1:000000000000 51:61fad867f68e
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  XIMP Framework PSC Server context session.
       
    15  *
       
    16 */
       
    17 
       
    18 #include "ximpsrvcontextclient.h"
       
    19 #include "ximpprocessstarter.h"
       
    20 #include "ximpserverdefs.h"
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 //Import NXIMPSrv
       
    25 using namespace NXIMPSrv;
       
    26 
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // RXIMPSrvContextClient::RXIMPSrvContextClient()
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 EXPORT_C RXIMPSrvContextClient::RXIMPSrvContextClient()
       
    35     {
       
    36     }
       
    37 
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // RXIMPSrvContextClient::Connect()
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C void RXIMPSrvContextClient::ConnectL( TUid aProtocolImpUid )
       
    44     {
       
    45     iMyUid = aProtocolImpUid;
       
    46 
       
    47     // create the server name: "!XIMPCtxSrv9bde667a" 
       
    48     HBufC* serverName = HBufC::NewLC( NName::KSymbianServer().Length() + 
       
    49             NStartupParam::KProtocolUidMaxLen + 
       
    50             1 );
       
    51 
       
    52     serverName->Des().Copy( NName::KSymbianServer );
       
    53     serverName->Des().AppendNumFixedWidth( iMyUid.iUid, 
       
    54             EHex, 
       
    55             NStartupParam::KProtocolUidMaxLen );
       
    56 
       
    57     // Pass the UID to server side.
       
    58     // For security reasons it was not allowed to pass the complete 
       
    59     // server name descriptor but just the UID part
       
    60     RArray< TXIMPProcessStartupParam > params;
       
    61     CleanupClosePushL( params );
       
    62 
       
    63     TXIMPProcessStartupParam paramUid;
       
    64     paramUid.Set( NStartupParam::KProtocolUidIndex, 
       
    65             iMyUid.iUid );
       
    66 
       
    67     User::LeaveIfError( params.Append( paramUid ) );
       
    68     TArray< TXIMPProcessStartupParam > array = params.Array();
       
    69 
       
    70 
       
    71     //Get path to correct exe to launch
       
    72     TFileName fullExePath;
       
    73     XIMPProcessStarter::FullExePathForClienLocation( NName::KExecutable,
       
    74             fullExePath );
       
    75 
       
    76     //Create a connection
       
    77     TInt ret = XIMPProcessStarter::ConnectToServer( fullExePath,
       
    78             KNullDesC,
       
    79             &array,
       
    80             *this,
       
    81             *serverName,
       
    82             TVersion( NVersion::KMajor,
       
    83                       NVersion::KMinor,
       
    84                       NVersion::KBuild ),
       
    85                       NRequest::KMsgSlotCount );
       
    86     User::LeaveIfError( ret );
       
    87     CleanupStack::PopAndDestroy( 2, serverName ); // params, serverName
       
    88 
       
    89     //Mutate the server side session to correct type
       
    90     User::LeaveIfError( SendReceive( NRequest::EBecomeCtxSession ) );
       
    91     }
       
    92 
       
    93 
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // RXIMPSrvContextClient::Close()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C void RXIMPSrvContextClient::Close()
       
   100     {
       
   101     RSessionBase::Close();
       
   102     #if _BullseyeCoverage
       
   103     cov_write();
       
   104     #endif
       
   105     }
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // RXIMPSrvContextClient::DoQueueOperation()
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C TInt RXIMPSrvContextClient::DoQueueOperation(
       
   113     TInt aOperationType, 
       
   114     const TDesC8& aOperationParams,
       
   115     TXIMPRequestId& aReqId )
       
   116     {
       
   117     TPckgBuf< TXIMPRequestId > reqIdPck;
       
   118 
       
   119     TIpcArgs msgArgs;
       
   120     msgArgs.Set( 0, aOperationType );
       
   121     msgArgs.Set( 1, &aOperationParams );
       
   122     msgArgs.Set( 2, &reqIdPck );
       
   123 
       
   124     TInt err = SendReceive( NRequest::ECtxSsQueueOperation, msgArgs );
       
   125 
       
   126     aReqId = reqIdPck();
       
   127     return err;
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // RXIMPSrvContextClient::DoQueueOperation2()
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 EXPORT_C TInt RXIMPSrvContextClient::DoQueueOperation2(
       
   135     TInt aOperationType, 
       
   136     const TDesC8& aOperationParams,
       
   137     TXIMPRequestId& aReqId )
       
   138     {
       
   139     TPckgBuf< TXIMPRequestId > reqIdPck;
       
   140 
       
   141     TIpcArgs msgArgs;
       
   142     msgArgs.Set( 0, aOperationType );
       
   143     msgArgs.Set( 1, &aOperationParams );
       
   144     msgArgs.Set( 2, &reqIdPck );
       
   145 
       
   146     TInt err = SendReceive( NRequest::ECtxSsQueueBindOperation, msgArgs );
       
   147     aReqId = reqIdPck();
       
   148     return err;
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // RXIMPSrvContextClient::GetContextCapabilitiesL()
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C HBufC8* RXIMPSrvContextClient::GetContextFeaturesL() const
       
   156     {
       
   157     return PrepareAndGetDataL( NRequest::ECtxSsPrepareContextFeatures );
       
   158     }
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // RXIMPSrvContextClient::ListenEvent()
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C void RXIMPSrvContextClient::ListenEvent( TRequestStatus& aStatus )
       
   166     {
       
   167     SendReceive( NRequest::ECtxSsSetEventListenScout, aStatus );
       
   168     }
       
   169 
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // RXIMPSrvContextClient::CancelListening()
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void RXIMPSrvContextClient::CancelListening()
       
   176     {
       
   177     SendReceive( NRequest::ECtxSsCancelEventListenScout );
       
   178     }
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // RXIMPSrvContextClient::InstallEventFilterL()
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C void RXIMPSrvContextClient::InstallEventFilterL(
       
   186         const TDesC8& aFilterData )
       
   187     {
       
   188     TIpcArgs msgArgs;
       
   189     msgArgs.Set( 0, &aFilterData );
       
   190     User::LeaveIfError( SendReceive( NRequest::ECtxSsInstallEventFilter, 
       
   191                                      msgArgs ) );
       
   192     }
       
   193 
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // RXIMPSrvContextClient::FetchTopEventDataLC()
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C HBufC8* RXIMPSrvContextClient::FetchTopEventDataLC()
       
   200     {
       
   201     TInt bufSize = SendReceive( NRequest::ECtxSsFetchTopEventDataSize );
       
   202     User::LeaveIfError( bufSize );
       
   203 
       
   204     HBufC8* eventBuf = HBufC8::NewLC( bufSize );
       
   205     TPtr8 ptrBuf( eventBuf->Des() );
       
   206 
       
   207     TIpcArgs msgArgs;
       
   208     msgArgs.Set( 0, &ptrBuf );
       
   209 
       
   210     User::LeaveIfError( SendReceive( NRequest::ECtxSsFetchTopEventData, 
       
   211                                      msgArgs ) );
       
   212     return eventBuf;
       
   213     }
       
   214 
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // RXIMPSrvContextClient::FetchTopEventReqId()
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C TInt RXIMPSrvContextClient::FetchTopEventReqId( 
       
   221     TXIMPRequestId& aReqId )
       
   222     {
       
   223     TPckgBuf< TXIMPRequestId > reqIdPck;
       
   224 
       
   225     TIpcArgs msgArgs;
       
   226     msgArgs.Set( 0, &reqIdPck );
       
   227 
       
   228     TInt err = SendReceive( NRequest::ECtxSsFetchTopEventReqId, msgArgs );
       
   229 
       
   230     aReqId = reqIdPck();
       
   231     return err;
       
   232     }
       
   233 
       
   234 
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // RXIMPSrvContextClient::DropTopEvent()
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 EXPORT_C TInt RXIMPSrvContextClient::DropTopEvent()
       
   241     {
       
   242     TInt err = SendReceive( NRequest::ECtxSsDropTopEvent );
       
   243     return err;
       
   244     }
       
   245 
       
   246 
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // RXIMPSrvContextClient::PrepareAndGetDataL()
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 HBufC8* RXIMPSrvContextClient::PrepareAndGetDataL( TInt aMsg ) const
       
   253     {
       
   254     TInt bufSize = SendReceive( aMsg );
       
   255     User::LeaveIfError( bufSize );
       
   256 
       
   257     HBufC8* buf = HBufC8::NewLC( bufSize );
       
   258     TPtr8 ptrBuf( buf->Des() );
       
   259 
       
   260     TIpcArgs msgArgs;
       
   261     msgArgs.Set( 0, &ptrBuf );
       
   262 
       
   263     User::LeaveIfError( SendReceive( NRequest::ECtxSsGetPreparedData, 
       
   264                                      msgArgs ) );
       
   265 
       
   266     CleanupStack::Pop( buf );
       
   267     return buf;
       
   268     }
       
   269 
       
   270 
       
   271 // End of file
       
   272 
       
   273