contextframework/cfw/src/cfclient/CFClientSession.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2002-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:  RCFClientSession class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CFClientSession.h"
       
    20 
       
    21 #include <e32svr.h>
       
    22 #include <e32math.h>
       
    23 #include <s32mem.h>
       
    24 #include <f32file.h>
       
    25 #include <centralrepository.h>
       
    26 #include <cfcontextdataobject.h>
       
    27 
       
    28 #include "cfcontextsubscriptionlistener.h"
       
    29 #include "CFContextSubscriptionImpl.h"
       
    30 #include "CFActionSubscriptionImpl.h"
       
    31 #include "CFContextQueryImpl.h"
       
    32 #include "cfcommon.h"
       
    33 #include "CFContextObjectImpl.h"
       
    34 #include "cftrace.h"
       
    35 #include "ContextFrameworkPrivateCRKeys.h"
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 //Fix for BHLS-7UPEA8
       
    40 static const TUint KDefaultMessageSlots = 5;
       
    41 static const TInt KCreateSessionRetryCount = 10;
       
    42 static const TInt KCreateSessionDelay = 100000; // 0.1 seconds
       
    43 
       
    44 RCFClientSession::RCFClientSession()
       
    45     {
       
    46     FUNC_LOG;
       
    47     }
       
    48 
       
    49 // METHODS
       
    50 
       
    51 //----------------------------------------------------------------------------
       
    52 // RCFClientSession::ConnectL
       
    53 //----------------------------------------------------------------------------
       
    54 //
       
    55 void RCFClientSession::ConnectL()
       
    56     {
       
    57     FUNC_LOG;
       
    58 
       
    59     TInt err = KErrNone;
       
    60     
       
    61 #ifdef CFW_SERVER_START_THROUGH_CLIENT
       
    62     err = StartServer();
       
    63     ERROR_1( err, "CF server start failed with code: %d", err );
       
    64     User::LeaveIfError( err );
       
    65 #endif
       
    66     
       
    67     RThread client;
       
    68     CleanupClosePushL( client );
       
    69     INFO_1( "Client [%x] session connecting to Context FW...",
       
    70         client.SecureId().iId );
       
    71     TInt retry = 0;
       
    72     do
       
    73         {
       
    74         err = CreateSession( KContextServerName,
       
    75             Version(),
       
    76             KDefaultMessageSlots );
       
    77         retry++;
       
    78 
       
    79         ERROR_2( err, "CF server session creation failed with code: %d. Retry count: %d", err, retry );
       
    80         if( err != KErrNone && retry < KCreateSessionRetryCount )
       
    81             {
       
    82             // Wait for a while so that CFW server is started
       
    83             User::After( KCreateSessionDelay );
       
    84             }
       
    85         }
       
    86     while( err != KErrNone && retry < KCreateSessionRetryCount );
       
    87 
       
    88     ERROR_1( err, "CF server session creation failed with code: %d", err );
       
    89     User::LeaveIfError( err );
       
    90     
       
    91     INFO_1( "Client [%x] session connecting to Context FW... OK",
       
    92         client.SecureId().iId );
       
    93     CleanupStack::PopAndDestroy( &client );
       
    94     }
       
    95 
       
    96 //----------------------------------------------------------------------------
       
    97 // RCFClientSession::Version
       
    98 //----------------------------------------------------------------------------
       
    99 //
       
   100 TVersion RCFClientSession::Version() const
       
   101     {
       
   102     FUNC_LOG;
       
   103     
       
   104     return( TVersion( KContextServMajorVersionNumber,
       
   105         KContextServMinorVersionNumber,
       
   106         KContextServBuildVersionNumber ) );
       
   107     }
       
   108 
       
   109 //----------------------------------------------------------------------------
       
   110 // RCFClientSession::SendSync
       
   111 //----------------------------------------------------------------------------
       
   112 //
       
   113 TInt RCFClientSession::SendSync( TInt aFunction ) const
       
   114     {
       
   115     FUNC_LOG;
       
   116     
       
   117     INFO_1( "SendSync: OpCode [%d]", aFunction );
       
   118     
       
   119     return SendReceive( aFunction );
       
   120     }
       
   121 
       
   122 //----------------------------------------------------------------------------
       
   123 // RCFClientSession::SendSync
       
   124 //----------------------------------------------------------------------------
       
   125 //
       
   126 TInt RCFClientSession::SendSync( TInt aFunction, const TIpcArgs& aArgs ) const
       
   127     {
       
   128     FUNC_LOG;
       
   129     
       
   130     INFO_1( "SendSync: OpCode [%d]", aFunction );
       
   131     
       
   132     return SendReceive( aFunction, aArgs );
       
   133     }
       
   134 
       
   135 //----------------------------------------------------------------------------
       
   136 // RCFClientSession::SendAsync
       
   137 //----------------------------------------------------------------------------
       
   138 //
       
   139 void RCFClientSession::SendAsync( TInt aFunction,
       
   140     const TIpcArgs& aArgs,
       
   141     TRequestStatus& aStatus ) const
       
   142     {
       
   143     FUNC_LOG;
       
   144     
       
   145     INFO_1( "SendAsync: OpCode [%d]", aFunction );
       
   146     
       
   147     SendReceive( aFunction, aArgs, aStatus );
       
   148     }
       
   149 
       
   150 //----------------------------------------------------------------------------
       
   151 // RCFClientSession::StartServer
       
   152 //----------------------------------------------------------------------------
       
   153 //
       
   154 TInt RCFClientSession::StartServer()
       
   155     {
       
   156     FUNC_LOG;
       
   157     
       
   158     TInt result;
       
   159     TFindServer findContextServer( KContextServerName );
       
   160     TFullName name;
       
   161     result = findContextServer.Next( name );
       
   162     if( result == KErrNone )
       
   163         {
       
   164         // Server already running
       
   165         INFO( "CF server already running" );
       
   166         return KErrNone;
       
   167         }
       
   168     
       
   169     // Create process for server and start the process
       
   170     RProcess server;
       
   171     result = server.Create( KContextServerName, KNullDesC );
       
   172     if( result != KErrNone )
       
   173         {
       
   174         return result;
       
   175         }
       
   176     INFO_1( "CF server process created with code: %d", result );
       
   177         
       
   178     TRequestStatus status;
       
   179     server.Rendezvous( status );
       
   180     server.Resume();
       
   181     
       
   182     // Wait for rendesvouz
       
   183     User::WaitForRequest( status );
       
   184     INFO_1( "CF server rendezvous: %d", status.Int() );
       
   185     
       
   186     // Close process handle since it is not needed anymore
       
   187     server.Close();
       
   188     
       
   189     return status.Int();
       
   190     }
       
   191 
       
   192 // End of file