PECengine/StorageManager2/ClientSrc/RPEngStorageClient.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Storage main client
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "RPEngStorageClient.h"
       
    21 #include <eikdll.h>
       
    22 #include <f32file.h>
       
    23 
       
    24 #include "PEngServerStarter.h"
       
    25 #include "PEngStorageServerCommon.h"
       
    26 #include "TPEngStorageServerMessages.h"
       
    27 
       
    28 // PEC Engine internal constants
       
    29 #include "PEngPresenceEngineConsts2.h"
       
    30 #include "PEngInternalGlobalConsts.h"
       
    31 
       
    32 #include "PresenceDebugPrint.h"
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 // each session can have several sub-session, while only one sub-session
       
    37 // is using asynchronous requests, 20 slots shall be enough to cover
       
    38 const TUint KMessageSlotCount = 20;
       
    39 
       
    40 
       
    41 // MACROS
       
    42 #define RETURN_IF_NOT_CONNECTED()\
       
    43     if(!iConnected)\
       
    44         {\
       
    45         return KErrDisconnected;\
       
    46         }
       
    47 
       
    48 #define RETURN_IF_NULL( desBuff )\
       
    49     if ( !desBuff )\
       
    50         {\
       
    51         return KErrNoMemory;\
       
    52         }
       
    53 
       
    54 // ============================ MEMBER FUNCTIONS ===============================
       
    55 // -----------------------------------------------------------------------------
       
    56 // RPEngStorageClient::RPEngStorageClient
       
    57 // C++ default constructor can NOT contain any code, that might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 RPEngStorageClient::RPEngStorageClient()
       
    61     {
       
    62     }
       
    63 
       
    64 // Destructor
       
    65 RPEngStorageClient::~RPEngStorageClient()
       
    66     {
       
    67     }
       
    68 
       
    69 // =============================================================================
       
    70 // =============Function of the client for Connection managing =================
       
    71 // =============================================================================
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // RPEngStorageClient::Connect
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 TInt RPEngStorageClient::Connect()
       
    78     {
       
    79     PENG_DP_TXT( "RPEngStorageClient::Connect()" );
       
    80 
       
    81     //Connects this client to the server.
       
    82     //Launches new server process if one not yet running.
       
    83     TInt err = PEngServerStarter::ConnectServer( *this,
       
    84                                                  KStorageServerName,
       
    85                                                  Version(),
       
    86                                                  KMessageSlotCount,
       
    87                                                  KStorageServerExe );
       
    88 
       
    89     iConnected = ( err == KErrNone );
       
    90     return err;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // RPEngStorageClient::Close
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void RPEngStorageClient::Close()
       
    98     {
       
    99     PENG_DP_TXT( "RPEngStorageClient::Close()" );
       
   100 
       
   101     // all requests from this session are canceled on the server side
       
   102     RSessionBase::Close();
       
   103     iConnected = EFalse;
       
   104     }
       
   105 
       
   106 // =============================================================================
       
   107 // ============= New Function of the client  ===================================
       
   108 // =============================================================================
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // RPEngStorageClient::SessionSlotState()
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TInt RPEngStorageClient::SessionSlotState(
       
   115     const TDesC8& aSessionName,
       
   116     HBufC8*& aSessionState,
       
   117     TInt aInitSize )
       
   118     {
       
   119     RETURN_IF_NOT_CONNECTED();
       
   120     TIpcArgs messArgs;
       
   121     messArgs.Set( KMessageSlot0, &aSessionName );
       
   122     aSessionState = HBufC8::New( aInitSize );
       
   123     RETURN_IF_NULL( aSessionState );
       
   124     TPtr8 sessState ( aSessionState->Des() );
       
   125     messArgs.Set( KMessageSlot1, &sessState );
       
   126     TInt err( SendReceive( EMainSessGetSessionState, messArgs ) );
       
   127     // if error is positive, then buffer was not big enough
       
   128     if ( err > KErrNone )
       
   129         {
       
   130         // realloc buffer, looks complicated, but safe, avoiding realloc
       
   131         delete aSessionState;
       
   132         aSessionState = NULL;
       
   133         aSessionState = HBufC8::New( err );
       
   134         RETURN_IF_NULL( aSessionState );
       
   135         sessState.Set( aSessionState->Des() );
       
   136         messArgs.Set( KMessageSlot1, &sessState );
       
   137         err = SendReceive( EMainSessGetSessionState, messArgs );
       
   138         }
       
   139     // if there was error erase buffer
       
   140     if ( err < KErrNone )
       
   141         {
       
   142         delete aSessionState;
       
   143         aSessionState = NULL;
       
   144         }
       
   145     return err;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // RPEngStorageClient::AllSessionSlotsStates()
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TInt RPEngStorageClient::AllSessionSlotsStates(
       
   153     HBufC8*& aSessionSlotsBuffer,
       
   154     TInt aInitSize )
       
   155     {
       
   156     RETURN_IF_NOT_CONNECTED();
       
   157     TIpcArgs messArgs;
       
   158     aSessionSlotsBuffer = HBufC8::New( aInitSize );
       
   159     RETURN_IF_NULL( aSessionSlotsBuffer );
       
   160     TPtr8 sessStates ( aSessionSlotsBuffer->Des() );
       
   161     messArgs.Set( KMessageSlot0, &sessStates );
       
   162     TInt err( SendReceive( EMainSessGetAllSessionStates, messArgs ) );
       
   163     // if error is positive, then buffer was not big enough
       
   164     if ( err > KErrNone )
       
   165         {
       
   166         // realloc buffer, looks complicated, but safe, avoiding realloc
       
   167         delete aSessionSlotsBuffer;
       
   168         aSessionSlotsBuffer = NULL;
       
   169         aSessionSlotsBuffer = HBufC8::New( err );
       
   170         RETURN_IF_NULL( aSessionSlotsBuffer );
       
   171         sessStates.Set( aSessionSlotsBuffer->Des() );
       
   172         messArgs.Set( KMessageSlot1, &sessStates );
       
   173         err = SendReceive( EMainSessGetAllSessionStates, messArgs );
       
   174         }
       
   175     // if there was error erase buffer
       
   176     if ( err < KErrNone )
       
   177         {
       
   178         delete aSessionSlotsBuffer;
       
   179         aSessionSlotsBuffer = NULL;
       
   180         }
       
   181     return err;
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // RPEngStorageClient::ListenGlobalEvents()
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 TInt RPEngStorageClient::ListenGlobalEvents()
       
   189     {
       
   190     RETURN_IF_NOT_CONNECTED();
       
   191     return SendReceive( EMainSessListenGlobalEvents );
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // RPEngStorageClient::ReloadGlobalEventListener()
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TInt RPEngStorageClient::ReloadGlobalEventListener(
       
   199     TDes8& aGlobalEventBuffer,
       
   200     TRequestStatus& aStatus )
       
   201     {
       
   202     RETURN_IF_NOT_CONNECTED();
       
   203     TIpcArgs messArgs;
       
   204     messArgs.Set( KMessageSlot0, EMainSessListenGlobalEvents );
       
   205     messArgs.Set( KMessageSlot1, &aGlobalEventBuffer );
       
   206     SendReceive( EMainSessReloadAsynchronousScout, messArgs, aStatus );
       
   207     return KErrNone;
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // RPEngStorageClient::StopEventListening()
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TInt RPEngStorageClient::StopEventListening()
       
   215     {
       
   216     RETURN_IF_NOT_CONNECTED();
       
   217     TIpcArgs messArgs;
       
   218     messArgs.Set( KMessageSlot0, EMainSessListenGlobalEvents );
       
   219     return SendReceive( EMainSessCancelRequest, messArgs );
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // RPEngStorageClient::CreateSessionFolder()
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 TInt RPEngStorageClient::CreateSessionFolder(
       
   227     const TDesC8& aSessionSlot,
       
   228     const TDesC16& aApplicationId )
       
   229     {
       
   230     RETURN_IF_NOT_CONNECTED();
       
   231     TIpcArgs messArgs;
       
   232     messArgs.Set( KMessageSlot0, &aSessionSlot );
       
   233     messArgs.Set( KMessageSlot1, &aApplicationId );
       
   234 
       
   235     return SendReceive( EMainSessCreateSessionFolder, messArgs );
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // RPEngStorageClient::RemoveSessionFolder()
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 TInt RPEngStorageClient::RemoveSessionFolder(
       
   243     const TDesC8& aSessionSlot,
       
   244     const TDesC16& aApplicationId )
       
   245     {
       
   246     RETURN_IF_NOT_CONNECTED();
       
   247     TIpcArgs messArgs;
       
   248     messArgs.Set( KMessageSlot0, &aSessionSlot );
       
   249     messArgs.Set( KMessageSlot1, &aApplicationId );
       
   250     return SendReceive( EMainSessRemoveSessionFolder, messArgs );
       
   251     }
       
   252 
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // RPEngStorageClient::Version()
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 TVersion RPEngStorageClient::Version() const
       
   259     {
       
   260     return( TVersion( KClientVersionMajor,
       
   261                       KClientVersionMinor,
       
   262                       KClientVersionBuild ) );
       
   263     }
       
   264 
       
   265 //  End of File
       
   266