homescreensrv_plat/sapi_contentpublishing/src/cpclientsession.cpp
changeset 0 79c6a41cd166
child 11 bd874ee5e5e2
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2007 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:  
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32mem.h>
       
    20 #include <liwcommon.h>
       
    21 
       
    22 #include "cpserverdef.h"
       
    23 #include "cpliwmap.h"
       
    24 #include "cpclientsession.h"
       
    25 #include "cpglobals.h"
       
    26 #include "cpdebug.h"
       
    27 #include "cpclientactivenotifier.h"
       
    28 
       
    29 // Number of message slots to reserve for this client server session.
       
    30 const TUint KDefaultMessageSlots( 1 );
       
    31 
       
    32 // Function prototypes
       
    33 static TInt StartServer();
       
    34 static TInt CreateServerProcess();
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // RCPServerClient::RCPServerClient
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 RCPServerClient::RCPServerClient() :
       
    45     RSessionBase()
       
    46     {
       
    47     // No implementation required
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // RCPServerClient::Connect
       
    52 // Connect to Content publisher server session. 
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 TInt RCPServerClient::Connect()
       
    56     {
       
    57     TInt error =:: StartServer();
       
    58 
       
    59     if ( error == KErrNone )
       
    60         {
       
    61         error = CreateSession( KCPServerName,
       
    62                 Version(),
       
    63                 KDefaultMessageSlots );
       
    64         }
       
    65     return error;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 //
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void RCPServerClient::Close()
       
    74     {
       
    75     RSessionBase::Close( );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void RCPServerClient::AddL( const CCPLiwMap& aMap,
       
    83                             CLiwGenericParamList& aOutParamList,
       
    84                             TUint aCmdOptions )
       
    85     {
       
    86     CP_DEBUG( _L8("RCPServerClient::AddL()") );
       
    87     HBufC8 *inbuf = aMap.PackForServerLC( );
       
    88     TInt32 id( 0);
       
    89     TPckg<TInt32> sizeDes(id);
       
    90     TIpcArgs args;
       
    91     args.Set( KDescriptorPosition, &*inbuf );
       
    92     args.Set( KReturnPosition, &sizeDes );
       
    93     if( aCmdOptions & KDisablePersist )
       
    94         {
       
    95         User::LeaveIfError( SendReceive( ECpServerAddDataNonPersistent, args ) );
       
    96         }
       
    97     else
       
    98         {
       
    99         User::LeaveIfError( SendReceive( ECpServerAddData, args ) );
       
   100         }
       
   101     TLiwGenericParam param( KItemId, id);
       
   102     aOutParamList.AppendL( param );
       
   103     CleanupStack::PopAndDestroy( inbuf );
       
   104     }
       
   105 
       
   106 
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void RCPServerClient::GetListL( const CCPLiwMap& aMap,
       
   113     CLiwGenericParamList& aOutParamList )
       
   114     {
       
   115     CP_DEBUG( _L8("RCPServerClient::GetListL()") );
       
   116     TIpcArgs args;
       
   117     HBufC8 *inbuf = aMap.PackForServerLC( );
       
   118     TInt error(KErrNone);
       
   119     TInt sizeList( 0);
       
   120     TPckg<TInt> sizeDes(sizeList);
       
   121     args.Set( KDescriptorPosition, &*inbuf );
       
   122     args.Set( KReturnPosition, &sizeDes );
       
   123     error = SendReceive( ECpServerGetListSize, args );
       
   124     if ( error == KErrNone )
       
   125         {
       
   126         TIpcArgs args;
       
   127         RBuf8 outbuf;
       
   128         outbuf.CleanupClosePushL( );
       
   129         outbuf.CreateL( sizeList );
       
   130         args.Set( KDescriptorPosition, &outbuf );
       
   131         error = SendReceive( ECpServerGetListData, args );
       
   132         if ( error == KErrNone )
       
   133             {
       
   134             RDesReadStream stream(outbuf);
       
   135             CleanupClosePushL( stream );
       
   136             aOutParamList.InternalizeL( stream ) ;
       
   137             CleanupStack::PopAndDestroy( &stream );
       
   138             }
       
   139         CleanupStack::PopAndDestroy( &outbuf );
       
   140         }
       
   141     User::LeaveIfError( error );
       
   142     CleanupStack::PopAndDestroy( inbuf );
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void RCPServerClient::ExecuteActionL( const CCPLiwMap& aMap )
       
   150     {
       
   151     CP_DEBUG( _L8("RCPServerClient::ExecuteActionL()") );
       
   152     HBufC8 *inbuf = aMap.PackForServerLC( );
       
   153     TIpcArgs args;
       
   154     args.Set( KDescriptorPosition, &*inbuf );
       
   155     User::LeaveIfError( SendReceive( ECpServerExecuteAction, args ) );
       
   156     CleanupStack::PopAndDestroy( inbuf );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void RCPServerClient::DeleteL( const CCPLiwMap& aMap )
       
   164     {
       
   165     CP_DEBUG( _L8("RCPServerClient::DeleteL()") );
       
   166     HBufC8 *inbuf = aMap.PackForServerLC( );
       
   167     TIpcArgs args;
       
   168     args.Set( KDescriptorPosition, &*inbuf );
       
   169     User::LeaveIfError( SendReceive( ECpServerRemoveData, args ) );
       
   170     CleanupStack::PopAndDestroy( inbuf );
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void RCPServerClient::RegisterObserverL( TRequestStatus& aStatus,
       
   178     TIpcArgs& aArgs )
       
   179     {
       
   180     CP_DEBUG( _L8("RCPServerClient::RegisterObserver()") );
       
   181     SendReceive( ECpServerRegisterObserver, aArgs, aStatus );
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void RCPServerClient::AddObserver( TIpcArgs& aArgs )
       
   189     {
       
   190     CP_DEBUG( _L8("RCPServerClient::AddObserver()") );
       
   191     SendReceive( ECpServerAddObserver, aArgs );
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void RCPServerClient::RemoveObserver( TIpcArgs& aArgs )
       
   199     {
       
   200     CP_DEBUG( _L8("RCPServerClient::AddObserver()") );
       
   201     SendReceive( ECpServerRemoveObserver, aArgs );
       
   202     }
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 TInt RCPServerClient::GetChangeInfoData( TDes8& aBuf )
       
   208     {
       
   209     CP_DEBUG( _L8("RCPServerClient::GetChangeInfoData()") );
       
   210     TIpcArgs args;
       
   211     args.Set( KDescriptorPosition, &aBuf );
       
   212     TInt error = SendReceive( ECpServerGetChangeInfoData, args );
       
   213     return error;
       
   214     }
       
   215  
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void RCPServerClient::UnregisterObserver()
       
   221     {
       
   222     CP_DEBUG( _L8("RCPServerClient::UnregisterObserver()") );
       
   223     SendReceive( ECpServerUnRegisterObserver );
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // RCPServerClient::Version
       
   228 // Version information.
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 TVersion RCPServerClient::Version() const
       
   232     {
       
   233     CP_DEBUG( _L8("RCPServerClient::Version()") );
       
   234     return (TVersion( KCPServerMajorVersionNumber,
       
   235         KCPServerMinorVersionNumber, KCPServerBuildVersionNumber ) );
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // StartServer
       
   240 // Static method to start the server.
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 static TInt StartServer()
       
   244     {
       
   245     TInt result;
       
   246 
       
   247     TFindServer findServer( KCPServerName );
       
   248     TFullName name;
       
   249 
       
   250     result = findServer.Next( name );
       
   251     if ( result != KErrNone )
       
   252         {
       
   253         // Server not running
       
   254         result = CreateServerProcess( );
       
   255         }
       
   256     return result;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CreateServerProcess
       
   261 // Static method to create the server process.
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 static TInt CreateServerProcess()
       
   265     {
       
   266     CP_DEBUG( _L8("RCPServerClient::CreateServerProcess()") );
       
   267     const TUidType serverUid( KNullUid, KNullUid, KServerUid3);
       
   268     RProcess server;
       
   269     TInt result;
       
   270     result = server.Create( KCPServerFilename, KNullDesC, serverUid );
       
   271     if ( result == KErrNone )
       
   272         {
       
   273         TRequestStatus stat = KRequestPending;
       
   274         server.Rendezvous( stat );
       
   275         if ( stat != KRequestPending )
       
   276             {
       
   277             server.Kill( 0 ); // abort startup
       
   278             }
       
   279         else
       
   280             {
       
   281             server.Resume( ); // logon OK - start the server
       
   282             }
       
   283 
       
   284         User::WaitForRequest( stat ); // wait for start or death
       
   285         // we can't use the 'exit reason' if the server panicked as this
       
   286         // is the panic 'reason' and may be '0' which cannot be distinguished
       
   287         // from KErrNone
       
   288         result = (server.ExitType( ) == EExitPanic ) ? KErrGeneral
       
   289             : stat.Int( );
       
   290         }
       
   291     server.Close( );
       
   292     return result;
       
   293     }