dvrengine/CommonRecordingEngineClient/src/RCRClient.cpp
branchRCL_3
changeset 22 826cea16efd9
parent 21 798ee5f1972c
child 23 13a33d82ad98
equal deleted inserted replaced
21:798ee5f1972c 22:826cea16efd9
     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 the License "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:    Implementation of CR client's Server*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "RCRClient.h"
       
    22 #include <ipvideo/CRTypeDefs.h>
       
    23 #include <e32math.h>
       
    24 #include <f32file.h>
       
    25 
       
    26 // CONSTANTS
       
    27 const TUint KDefaultMessageSlots( 4 );
       
    28 const TUint KNumberOfServerStartupAttempts( 2 );
       
    29 
       
    30 // LOCAL FUNCTION PROTOTYPES
       
    31 static TInt StartServer();
       
    32 static TInt CreateServerProcess();
       
    33 
       
    34 // ============================= LOCAL FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // StartServer 
       
    38 // Returns: Error code
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 static TInt StartServer()
       
    42     {
       
    43     TFindServer findServer( KCRServerNameExe );
       
    44     TFullName name( KNullDesC );
       
    45     
       
    46     // Server already running?
       
    47     TInt result( findServer.Next( name ) );
       
    48     if ( !result )
       
    49         {
       
    50         return KErrNone;
       
    51         }    
       
    52    
       
    53     // Process
       
    54     result = CreateServerProcess();
       
    55     
       
    56     return result;    
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CreateServerProcess 
       
    61 //
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 static TInt CreateServerProcess()
       
    65     {
       
    66     RProcess server;
       
    67     TInt err( server.Create( KCRServerNameExe , _L( "" ) ) );
       
    68     if ( err )
       
    69         {
       
    70         return err;
       
    71         }
       
    72         
       
    73     // Makes the server eligible for execution.    
       
    74     TRequestStatus reqStatus;
       
    75     server.Rendezvous(reqStatus);
       
    76     
       
    77     server.Resume();
       
    78     
       
    79     User::WaitForRequest(reqStatus);
       
    80     
       
    81     if( reqStatus.Int() != KErrNone )
       
    82         {
       
    83         server.Close();
       
    84         }
       
    85         
       
    86     return reqStatus.Int();
       
    87     }
       
    88 
       
    89 // ============================ MEMBER FUNCTIONS ===============================
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // RCRClient::RCRClient
       
    93 //
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 RCRClient::RCRClient() : RSessionBase()
       
    97     {
       
    98     // None
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // RCRClient::Connect
       
   103 //
       
   104 // -----------------------------------------------------------------------------
       
   105 // 
       
   106 TInt RCRClient::Connect()
       
   107     {
       
   108     TInt ret( KErrNotFound );
       
   109     TInt retry( KNumberOfServerStartupAttempts );
       
   110     do
       
   111         {
       
   112         // Start
       
   113         ret = StartServer();
       
   114         if ( ret != KErrNone && ret != KErrAlreadyExists )
       
   115             {
       
   116             return ret;
       
   117             }
       
   118         
       
   119         // Subsession
       
   120         ret = CreateSession( KCRServerNameExe, Version(), KDefaultMessageSlots );
       
   121         if ( ret != KErrNotFound && ret != KErrServerTerminated )
       
   122             {
       
   123             return ret;
       
   124             }
       
   125 
       
   126         retry--;
       
   127         }
       
   128         while( retry >= 0 );
       
   129 
       
   130     return ret;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // RCRClient::Close
       
   135 // 
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void RCRClient::Close()
       
   139     {
       
   140     TIpcArgs args( TIpcArgs::ENothing );
       
   141     SendReceive( ECRServCloseSession, args );
       
   142     RHandleBase::Close();
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // RCRClient::Version
       
   147 // 
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 TVersion RCRClient::Version( void ) const
       
   151     {
       
   152     return( TVersion( KCRServMajorVersionNumber, 
       
   153                       KCRServMinorVersionNumber,
       
   154                       KCRServBuildVersionNumber ) );
       
   155     }
       
   156 
       
   157 // End of File