wim/WimClient/src/WimClient.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     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:  Startup place for client & server, message handling.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //INCLUDES
       
    20 #include "WimClient.h"
       
    21 #include "WimSig.h"
       
    22 #include "WimTrace.h"
       
    23 
       
    24 #ifdef __WINS__
       
    25 #include <c32comm.h>
       
    26 
       
    27 #endif // WINS
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // FindServerFileName()
       
    32 // Return the name of the WIM server file
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 TInt RWimClient::FindServerFileName( TFileName& aServer )
       
    36     {
       
    37     // just return .EXE name, it's loaded from /sys/bin
       
    38     aServer = KWimServerFile;
       
    39     return ( KErrNone );
       
    40     }
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // StartWim()
       
    45 // Start the WIM server
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 TInt RWimClient::StartWim()
       
    49     {
       
    50     _WIMTRACE( _L( "StartWim() ") );
       
    51     // just get .EXE name, it's loaded from /sys/bin
       
    52     TFileName serverFileName( KWimServerFile ); 
       
    53     TRequestStatus stat;
       
    54 
       
    55     RProcess server;
       
    56     _WIMTRACE( _L( "StartWim Process() start" ) );
       
    57     TInt r = server.Create( serverFileName, 
       
    58                             KNullDesC,
       
    59                             TUidType( KNullUid, 
       
    60                                       KNullUid, 
       
    61                                       KWimServerUid ) );
       
    62     if ( r != KErrNone )
       
    63         {
       
    64         return r;
       
    65         }
       
    66 
       
    67     _WIMTRACE( _L( "StartWim Process() started" ) );
       
    68 
       
    69 
       
    70     _WIMTRACE( _L( "wait util server release mutex..." ) );
       
    71 
       
    72     server.Rendezvous( stat );
       
    73     
       
    74     _WIMTRACE( _L( "mutex is released" ) );
       
    75   
       
    76 
       
    77     
       
    78     if ( stat != KRequestPending )
       
    79         {
       
    80         // logon failed - server is not yet running, so cannot have terminated
       
    81         server.Kill(0);       // Abort startup
       
    82         }
       
    83     else
       
    84         {
       
    85         // logon OK - start the server
       
    86         server.Resume();
       
    87         }
       
    88 
       
    89     _WIMTRACE( _L( "RWimClient::StartWim() | Wait status to complete" ) );
       
    90 
       
    91     User::WaitForRequest( stat ); // Wait server to signal is has started
       
    92     
       
    93     _WIMTRACE2( _L( "RWimClient::StartWim() | complete with error %d" ), stat.Int() );
       
    94  
       
    95     if ( stat.Int() == KErrAlreadyExists )
       
    96         {
       
    97         r = KErrNone;
       
    98         }
       
    99     else
       
   100         {
       
   101         r = stat.Int();
       
   102         }
       
   103 
       
   104     server.Close();
       
   105     _WIMTRACE( _L( "RWimClient::StartWim() | End" ) );
       
   106     
       
   107     
       
   108     return r;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // RWimClient::RWimClient()
       
   113 // Default constructor
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 RWimClient::RWimClient()
       
   117     {
       
   118     _WIMTRACE ( _L( "RWimClient::RWimClient()" ) );
       
   119     }
       
   120 
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // RWimClient::~RWimClient()
       
   124 // Destructor
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 RWimClient::~RWimClient()
       
   128     {
       
   129     _WIMTRACE ( _L( "RWimClient::~RWimClient()" ) );
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // RWimClient::Connect()
       
   134 // Connect to WIMI server
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 TInt RWimClient::Connect()
       
   138     {
       
   139     _WIMTRACE ( _L( "RWimClient::Connect()" ) );
       
   140 #ifdef __WINS__
       
   141     StartC32();
       
   142 #endif
       
   143     TInt retryCount = 0;
       
   144     TInt retval = 0;
       
   145     retval = CreateSession( KWIMServerName, 
       
   146         Version(), 
       
   147         KMessageSlotsNum );
       
   148     if ( retval == KErrServerTerminated )
       
   149         {
       
   150         while ( (retval == KErrServerTerminated ) 
       
   151             && ( retryCount++ < KWimServerTerminatingMaxRetryCount) )
       
   152             {   
       
   153             /* Server can take some time to shutdown, retry in a moment */
       
   154             User::After( KWimServerTerminatingRetryTimeout );
       
   155             retval = CreateSession( KWIMServerName, 
       
   156                 Version(), 
       
   157                 KMessageSlotsNum );
       
   158             }
       
   159         }
       
   160     return retval; 
       
   161     }
       
   162 
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // RWimClient::Version() const
       
   166 // Return version
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 TVersion RWimClient::Version( void ) const
       
   170     {
       
   171     _WIMTRACE ( _L( "RWimClient::Version()" ) );
       
   172     return( TVersion( KWIMServMajorVersionNumber, 
       
   173                       KWIMServMinorVersionNumber, 
       
   174                       KWIMServBuildVersionNumber ) );
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // RWimClient::SendReceiveData()
       
   179 // Send message synchronously to server
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 TInt  RWimClient::SendReceiveData( TWimServRqst aFn, TIpcArgs& aIpcArgs )
       
   183     {
       
   184     _WIMTRACE ( _L( "RWimClient::SendReceiveData()" ) );
       
   185     return SendReceive( aFn, aIpcArgs ); 
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // RWimClient::SendReceiveData()
       
   190 // Send message asyncronously to server
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void RWimClient::SendReceiveData( TWimServRqst aFn, 
       
   194                                   TIpcArgs& aIpcArgs, 
       
   195                                   TRequestStatus& aStatus )
       
   196     {
       
   197     _WIMTRACE ( _L( "RWimClient::SendReceiveData()" ) );
       
   198     SendReceive( aFn, aIpcArgs, aStatus );
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // RWimClient::FreeAddrLst()
       
   203 // Free the address list
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void RWimClient::FreeAddrLst( const TUint32 addrLst )
       
   207     {
       
   208     _WIMTRACE ( _L( "RWimClient::FreeAddrLst()" ) );
       
   209 
       
   210     TIpcArgs args;
       
   211     args.Set( 0, addrLst );
       
   212     SendReceiveData( EFreeMemoryLst, args );
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // RWimClient::FreeWIMAddrLst()
       
   217 // Free the address list
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void RWimClient::FreeWIMAddrLst( const TWimAddressList addrLst, 
       
   221                                  const TUint aSize )
       
   222     {
       
   223     _WIMTRACE ( _L( "RWimClient::FreeWIMAddrLst()" ) );
       
   224 
       
   225     TIpcArgs args;
       
   226     args.Set( 0, addrLst[0] );
       
   227     args.Set( 1, aSize );
       
   228     
       
   229     SendReceiveData( EFreeWIMMemoryLst, args );
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // RWimClient::FreeWIMAddr()
       
   234 // Free the address
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void RWimClient::FreeWIMAddr( const TWimAddress aAddr )
       
   238     {
       
   239     _WIMTRACE ( _L( "RWimClient::FreeWIMAddr()" ) );
       
   240     TIpcArgs args;
       
   241     args.Set( 0, aAddr );
       
   242     SendReceiveData( EFreeMemory, args );
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // RWimClient::Initialize()
       
   247 // Sends initialization command to Server.
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void RWimClient::Initialize( TRequestStatus& aStatus )
       
   251     {
       
   252     aStatus = KRequestPending;
       
   253     _WIMTRACE ( _L( "RWimClient::Initialize( TRequestStatus& aStatus )" ) );
       
   254     TIpcArgs args;
       
   255     SendReceiveData( EWimInitialize, args, aStatus );
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // RWimClient::CancelInitialize()
       
   260 // Cancel initialization command to Server.
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void RWimClient::CancelInitialize()
       
   264     {
       
   265     _WIMTRACE ( _L( "RWimClient::CancelInitialize()" ) );
       
   266 	TIpcArgs args;
       
   267     SendReceiveData( ECancelWimInitialize, args );
       
   268     }
       
   269 // End of File
       
   270 
       
   271 
       
   272