satengine/SatServer/Engine/src/CSatClientServiceReq.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     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:  Handles client requests.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CSatClientServiceReq.h"
       
    22 #include    "MSatUtils.h"
       
    23 #include    "MSatSUiClientHandler.h"
       
    24 #include    "EnginePanic.h"
       
    25 #include    "SatLog.h"
       
    26 
       
    27 _LIT( KTxtServer, "SatServer" );
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CSatClientServiceReq::CSatClientServiceReq
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CSatClientServiceReq::CSatClientServiceReq(
       
    38     TSatServerRequest aRequest,
       
    39     TSatServerRequest aResponse,
       
    40     MSatCommand* aCommand,
       
    41     MSatUtils& aUtils ) :
       
    42     iHandledRequest( aRequest ),
       
    43     iHandledResponse( aResponse ),
       
    44     iResponseObserver( aCommand ),
       
    45     iUtils( aUtils )
       
    46     {
       
    47     LOG( SIMPLE, "SATENGINE: \
       
    48         CSatClientServiceReq::CSatClientServiceReq calling-exiting" )
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CSatClientServiceReq::NewL
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CSatClientServiceReq* CSatClientServiceReq::NewL(
       
    57     TSatServerRequest aRequest,
       
    58     TSatServerRequest aResponse,
       
    59     MSatCommand* aCommand,
       
    60     MSatUtils& aUtils )
       
    61     {
       
    62     LOG( SIMPLE, "SATENGINE: CSatClientServiceReq::NewL calling-exiting" )
       
    63     return new ( ELeave ) CSatClientServiceReq(
       
    64         aRequest, aResponse, aCommand, aUtils );
       
    65     }
       
    66 
       
    67 
       
    68 // Destructor
       
    69 CSatClientServiceReq::~CSatClientServiceReq()
       
    70     {
       
    71     LOG( SIMPLE,
       
    72         "SATENGINE: CSatClientServiceReq::~CSatClientServiceReq calling" )
       
    73 
       
    74     iResponseObserver = NULL;
       
    75     iCmdData = 0;
       
    76     iCmdRsp = 0;
       
    77 
       
    78     LOG( SIMPLE,
       
    79         "SATENGINE: CSatClientServiceReq::~CSatClientServiceReq exiting" )
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CSatClientServiceReq::HandleCommand
       
    84 // Handles the SIM command. If client has not yet requested service for this
       
    85 // SIM command, command is stored for later use.
       
    86 // (other items were commented in a header).
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TBool CSatClientServiceReq::HandleCommand(
       
    90     TDesC8* aCmdData, // Data to be sent to client.
       
    91     TDes8* aCmdRsp, // Client is response is written to this.h
       
    92     TSatServerRequest aRequest ) // Command from SIM
       
    93     {
       
    94     LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleCommand calling" )
       
    95 
       
    96     __ASSERT_ALWAYS( iResponseObserver,
       
    97         PanicSatEngine( ESatEngineNullPointer ) );
       
    98 
       
    99     TBool handled( EFalse );
       
   100     // Handle the command here if the request op codes match.
       
   101     if ( iHandledRequest == aRequest )
       
   102         {
       
   103         LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleCommand \
       
   104              request op codes match" )
       
   105         // Store the descriptors
       
   106         iCmdData = aCmdData;
       
   107         iCmdRsp = aCmdRsp;
       
   108 
       
   109         handled = ETrue;
       
   110 
       
   111         // Is the client already waiting for the command
       
   112         if ( iRequestPending )
       
   113             {
       
   114             LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleCommand \
       
   115                  RequestPending" )
       
   116             // Request is served.
       
   117             iRequestPending = EFalse;
       
   118             SendDataToClient();
       
   119             }
       
   120         else
       
   121             {
       
   122             LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleCommand \
       
   123                  no RequestPending" )
       
   124             // Client request was not available, so command is waiting for
       
   125             // client request.
       
   126             iCmdPending = ETrue;
       
   127             }
       
   128         }
       
   129 
       
   130     LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleCommand exiting" )
       
   131     return handled;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CSatClientServiceReq::HandleRequest
       
   136 // Handles the client's request.
       
   137 // (other items were commented in a header).
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 TBool CSatClientServiceReq::HandleRequest(
       
   141     const RMessage2& aRequest ) // Request from client.
       
   142     {
       
   143     LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleRequest calling" )
       
   144 
       
   145     TBool handled( EFalse );
       
   146 
       
   147     // Is the request handled here.
       
   148     const TInt request( aRequest.Function() );
       
   149     if ( request == iHandledRequest )
       
   150         {
       
   151         LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleRequest \
       
   152              handle request" )
       
   153         handled = ETrue;
       
   154         iRequest = aRequest;
       
   155 
       
   156         // Is the command waiting for client.
       
   157         if ( iCmdPending )
       
   158             {
       
   159             LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleRequest \
       
   160             iCmdPending" )
       
   161             iCmdPending = EFalse;
       
   162             SendDataToClient();
       
   163             }
       
   164         else
       
   165             {
       
   166             // Command has not yet arrived from SIM, so
       
   167             // wait for the command.
       
   168             iRequestPending = ETrue;
       
   169             }
       
   170         }
       
   171     // Is the response handled here.
       
   172     else if ( request == iHandledResponse )
       
   173         {
       
   174         LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleRequest \
       
   175              handle response" )
       
   176         handled = ETrue;
       
   177 
       
   178         TRAPD( res, aRequest.ReadL( 0, *iCmdRsp ) );
       
   179 
       
   180         // Send the response further only if IPC succeeded.
       
   181         if ( KErrNone != res )
       
   182             {
       
   183             LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleRequest \
       
   184             KErrNone != res" )
       
   185             iRequest.Panic( KTxtServer, ESatSBadDescriptor );
       
   186             }
       
   187 
       
   188         // Release client first, then handle the response
       
   189         aRequest.Complete( KErrNone );
       
   190         // Notify command that response is available.
       
   191         iResponseObserver->ClientResponse();
       
   192         }
       
   193     else
       
   194         {
       
   195         }
       
   196 
       
   197     LOG( DETAILED, "SATENGINE: CSatClientServiceReq::HandleRequest exiting" )
       
   198     return handled;
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CSatClientServiceReq::SendDataToClient
       
   203 // Writes the data to client address space and completes the iRequest.
       
   204 // (other items were commented in a header).
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void CSatClientServiceReq::SendDataToClient()
       
   208     {
       
   209     LOG( SIMPLE, "SATENGINE: CSatClientServiceReq::SendDataToClient calling" )
       
   210 
       
   211     TRAPD( res,iRequest.WriteL( 0, *iCmdData ) );
       
   212     LOG2( SIMPLE, "SATENGINE: CSatClientServiceReq::SendDataToClient res: %d",
       
   213           res )
       
   214     if ( KErrNone != res )
       
   215         {
       
   216         iRequest.Panic( KTxtServer, ESatSBadDescriptor );
       
   217         }
       
   218 
       
   219     iRequest.Complete( KErrNone );
       
   220 
       
   221     // If UI is not launched by user, make sure UI is in foreground
       
   222     if ( !iUtils.SatUiHandler().UiLaunchedByUser() )
       
   223         {
       
   224         LOG( SIMPLE, 
       
   225         "SATENGINE: CSatClientServiceReq::SendDataToClient \
       
   226         EBringSatUiToForeGround" )
       
   227         iUtils.NotifyEvent( MSatUtils::EBringSatUiToForeGround );
       
   228         }
       
   229 
       
   230     LOG( SIMPLE, "SATENGINE: CSatClientServiceReq::SendDataToClient exiting" )
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CSatClientServiceReq::IsMyRequest
       
   235 // (other items were commented in a header).
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 TBool CSatClientServiceReq::IsMyRequest( const TSatServerRequest aRequest )
       
   239     {
       
   240     LOG( SIMPLE, "SATENGINE: CSatClientServiceReq::IsMyRequest calling" )
       
   241     TBool myRequest( EFalse );
       
   242 
       
   243     if ( iHandledRequest == aRequest )
       
   244         {
       
   245         LOG( SIMPLE,
       
   246             "SATENGINE: CSatClientServiceReq::IsMyRequest" )
       
   247 
       
   248         myRequest = ETrue;
       
   249         }
       
   250     LOG2( SIMPLE, "SATENGINE: CSatClientServiceReq::IsMyRequest exiting, \
       
   251           return: %d", myRequest )
       
   252     return myRequest;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CSatClientServiceReq::SetCommandHandler
       
   257 // (other items were commented in a header).
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CSatClientServiceReq::SetCommandHandler( MSatCommand* aCommand )
       
   261     {
       
   262     LOG( SIMPLE, "SATENGINE: CSatClientServiceReq::SetCommandHandler calling" )
       
   263 
       
   264     iResponseObserver = aCommand;
       
   265 
       
   266     LOG( SIMPLE, "SATENGINE: CSatClientServiceReq::SetCommandHandler exiting" )
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CSatClientServiceReq::Reset
       
   271 // Resets member data
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void CSatClientServiceReq::Reset()
       
   275     {
       
   276     LOG( SIMPLE, "SATENGINE: CSatClientServiceReq::Reset calling" )
       
   277 
       
   278     // Check is request pending
       
   279     if ( !iRequestPending )
       
   280         {
       
   281         // Request not pending meaning that command is executing.
       
   282         // Send client response to prevent SIM to lock
       
   283         LOG( NORMAL, " Request is not pending" )
       
   284         // Notify command that response is available.
       
   285         iResponseObserver->ClientResponse();
       
   286         }
       
   287 
       
   288     // Clean data
       
   289     iCmdData = NULL;
       
   290     iCmdRsp = NULL;
       
   291     iCmdPending = EFalse;
       
   292     iRequestPending = EFalse;
       
   293     // We don't reset iResponseObserver
       
   294 
       
   295     LOG( SIMPLE, "SATENGINE: CSatClientServiceReq::Reset exiting" )
       
   296     }
       
   297 
       
   298 //  End of File