homescreensrv_plat/sapi_backstepping/src/bsclient.cpp
branchv5backport
changeset 16 66e84aa0ed46
parent 12 2f40063dfb5c
child 17 c9bafd575d88
equal deleted inserted replaced
12:2f40063dfb5c 16:66e84aa0ed46
     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:  Client session for BS engine
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "bsclient.h"
       
    20 #include "bsengineglobals.h"
       
    21 
       
    22 // Number of message slots to reserve for this client server session.
       
    23 const TUint KDefaultMessageSlots( 5);
       
    24 
       
    25 // Function prototypes
       
    26 static TInt StartServer();
       
    27 static TInt CreateServerProcess();
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // C++ default constructor can NOT contain any code, that might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 RBSClient::RBSClient() :
       
    36     RSessionBase()
       
    37     {
       
    38     // No implementation required
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // Connect to Active Data Server session. 
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 TInt RBSClient::Connect()
       
    46     {
       
    47     TInt error =:: StartServer();
       
    48 
       
    49     if ( error == KErrNone )
       
    50         {
       
    51         error = CreateSession( KBSEngineName,
       
    52                 Version(),
       
    53                 KDefaultMessageSlots );
       
    54         }
       
    55     return error;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // 
       
    60 // -----------------------------------------------------------------------------
       
    61 
       
    62 TInt RBSClient::Initialize( TUid aApp )
       
    63     {
       
    64     return SendReceive( EBSEngineInitialize, TIpcArgs( aApp.iUid ) );
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // 
       
    69 // -----------------------------------------------------------------------------
       
    70 
       
    71 TInt RBSClient::ForwardActivationEvent( const TDesC8& aState, TBool aIsItem )
       
    72     {
       
    73     TPtr8 state( (TUint8*) aState.Ptr( ), aState.Size( ), aState.Size( ));
       
    74     return SendReceive( EBSEngineHandleActivationEvent, TIpcArgs( &state,
       
    75         aIsItem ) );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // 
       
    80 // -----------------------------------------------------------------------------
       
    81 
       
    82 TInt RBSClient::HandleBackCommand( const TDesC8& aState, TBool aCheckOnly )
       
    83     {
       
    84     TPtr8 state( (TUint8*) aState.Ptr( ), aState.Size( ), aState.Size( ));
       
    85     return SendReceive( EBSEngineHandleBackCommand, TIpcArgs( &state,
       
    86         aCheckOnly ) );
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // Version information.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 TVersion RBSClient::Version() const
       
    94     {
       
    95     return (TVersion( KBSEngineMajorVersionNumber,
       
    96         KBSEngineMinorVersionNumber, KBSEngineBuildVersionNumber ) );
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // Static method to start the server.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 static TInt StartServer()
       
   104     {
       
   105     TInt result;
       
   106 
       
   107     TFindServer findServer( KBSEngineName );
       
   108     TFullName name;
       
   109 
       
   110     result = findServer.Next( name );
       
   111     if ( result != KErrNone )
       
   112         {
       
   113         // Server not running
       
   114         result = CreateServerProcess( );
       
   115         }
       
   116     return result;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // Static method to create the server process.
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 static TInt CreateServerProcess()
       
   124     {
       
   125     const TUidType serverUid( KNullUid, KNullUid, KServerUid3);
       
   126     RProcess server;
       
   127     TInt result;
       
   128     result = server.Create( KBSEngineFilename, KNullDesC, serverUid );
       
   129     if ( result == KErrNone )
       
   130         {
       
   131         TRequestStatus stat = KRequestPending;
       
   132         server.Rendezvous( stat );
       
   133         if ( stat != KRequestPending )
       
   134             {
       
   135             server.Kill( 0 ); // abort startup
       
   136             }
       
   137         else
       
   138             {
       
   139             server.Resume( ); // logon OK - start the server
       
   140             }
       
   141 
       
   142         User::WaitForRequest( stat ); // wait for start or death
       
   143         // we can't use the 'exit reason' if the server panicked as this
       
   144         // is the panic 'reason' and may be '0' which cannot be distinguished
       
   145         // from KErrNone
       
   146         result = (server.ExitType( ) == EExitPanic ) ? KErrGeneral
       
   147             : stat.Int( );
       
   148         }
       
   149     server.Close( );
       
   150     return result;
       
   151     }