satengine/SatServer/Engine/src/CSatCommandHandler.cpp
changeset 0 ff3b6d0fd310
child 9 71e7b994dff4
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  Base class for handling SAT commands.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <ecom.h>
       
    22 #include    "MSatSystemState.h"
       
    23 #include    "CSatCommandHandler.h"
       
    24 #include    "MSatUtils.h"
       
    25 #include    "MSatApi.h"
       
    26 #include    "EnginePanic.h"
       
    27 #include    "MSatSUiClientHandler.h"
       
    28 #include    "SatLog.h"
       
    29 
       
    30 // Small delay for giving UI time to launch before starting to handle
       
    31 // pending command
       
    32 const TInt KTimerDelay =  100000;
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CSatCommandHandler::CSatCommandHandler
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C CSatCommandHandler::CSatCommandHandler() :
       
    43     CActive( EPriorityStandard )
       
    44     {
       
    45     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::CSatCommandHandler calling" )
       
    46 
       
    47     CActiveScheduler::Add( this );
       
    48 
       
    49     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::CSatCommandHandler exiting" )
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CSatCommandHandler::BaseConstructL
       
    54 // Symbian 2nd phase constructor can leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C void CSatCommandHandler::BaseConstructL( MSatUtils* aPtr )
       
    58     {
       
    59     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::BaseConstructL calling" )
       
    60 
       
    61     __ASSERT_ALWAYS( aPtr, PanicSatEngine( ESatEngineNullPointer ) );
       
    62     iUtils = aPtr;
       
    63 
       
    64     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::BaseConstructL exiting" )
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSatCommandHandler::NewL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CSatCommandHandler* CSatCommandHandler::NewL(
       
    73     const TUid& aImplUid,
       
    74     MSatUtils* aUtils )
       
    75     {
       
    76     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::NewL calling" )
       
    77 
       
    78     __ASSERT_ALWAYS( aUtils, PanicSatEngine( ESatEngineNullPointer ) );
       
    79 
       
    80     TAny* ptr = REComSession::CreateImplementationL( aImplUid,
       
    81         _FOFF( CSatCommandHandler, iDtorIDKey ), aUtils );
       
    82 
       
    83     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::NewL exiting" )
       
    84     return reinterpret_cast<CSatCommandHandler*>( ptr );
       
    85     }
       
    86 
       
    87 // Destructor
       
    88 EXPORT_C CSatCommandHandler::~CSatCommandHandler()
       
    89     {
       
    90     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::~CSatCommandHandler calling" )
       
    91 
       
    92     iUtils = NULL;
       
    93     REComSession::DestroyedImplementation( iDtorIDKey );
       
    94 
       
    95     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::~CSatCommandHandler exiting" )
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CSatCommandHandler::Start
       
   100 // Starts the waiting of SAT command, if not already active.
       
   101 // (other items were commented in a header).
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 EXPORT_C void CSatCommandHandler::Start()
       
   105     {
       
   106     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Start calling" )
       
   107 
       
   108     if ( !IsActive() )
       
   109         {
       
   110         LOG( DETAILED, "SATENGINE: CSatCommandHandler::Start set active" )
       
   111         // Child class issues the request.
       
   112         IssueUSATRequest( iStatus );
       
   113         SetActive();
       
   114 
       
   115         // Not executing
       
   116         iIsExecuting = EFalse;
       
   117         iWaitingUiLaunch = EFalse;
       
   118         }
       
   119 
       
   120     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Start exiting" )
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CSatCommandHandler::DoHandleCommand
       
   125 // Handles the SAT command, which has been notified from USAT api.
       
   126 // (other items were commented in a header).
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C void CSatCommandHandler::DoHandleCommand()
       
   130     {
       
   131     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::DoHandleCommand calling" )
       
   132 
       
   133     if ( CommandAllowed() )
       
   134         {
       
   135         iUtils->NotifyEvent( MSatUtils::EDestroySimSessionEndTimer );
       
   136         if ( NeedUiSession() )
       
   137             {
       
   138             // If ui session is not availabe, SATUI has to be
       
   139             // launched.
       
   140             if ( NULL == iUtils->SatUiHandler().UiSession() )
       
   141                 {
       
   142                 LOG( SIMPLE, "SATENGINE: CSatCommandHandler::DoHandleCommand \
       
   143                      uisession not available" )
       
   144                 TRAPD( err, iUtils->RegisterL(
       
   145                     this, MSatUtils::ESatUiLaunched );
       
   146 
       
   147                     // Try to launch the ui client.
       
   148                     iUtils->SatUiHandler().LaunchSatUiL();
       
   149                     ); // End of TRAPD
       
   150 
       
   151                 if ( KErrNone != err )
       
   152                     {
       
   153                     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::\
       
   154                     DoHandleCommand KErrNone != err" )
       
   155                     // Ui launch failed, unregister event
       
   156                     iUtils->UnregisterEvent( this, MSatUtils::ESatUiLaunched );
       
   157 
       
   158                     // Notify derived class that ui launch failed.
       
   159                     UiLaunchFailed();
       
   160                     }
       
   161                 }
       
   162             else
       
   163                 {
       
   164                 LOG( SIMPLE, "SATENGINE: CSatCommandHandler::DoHandleCommand \
       
   165                      uisession available" )
       
   166                 // client session is available handle the command.
       
   167                 HandleCommand();
       
   168                 }
       
   169             }
       
   170         else
       
   171             {
       
   172             LOG( SIMPLE, "SATENGINE: CSatCommandHandler::DoHandleCommand \
       
   173                  don't need uisession" )
       
   174             // Command does not need ui client, so handle the command.
       
   175             HandleCommand();
       
   176             }
       
   177         }
       
   178 
       
   179     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::DoHandleCommand exiting" )
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CSatCommandHandler::ClientResponse
       
   184 // (other items were commented in a header).
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 EXPORT_C void CSatCommandHandler::ClientResponse()
       
   188     {
       
   189     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::ClientResponse panic" )
       
   190     PanicSatEngine( ESatUnexpectedHandleUiResponseCall );
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CSatCommandHandler::Event
       
   195 // (other items were commented in a header).
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C void CSatCommandHandler::Event( TInt aEvent )
       
   199     {
       
   200     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Event calling" )
       
   201 
       
   202     if ( MSatUtils::ESatUiLaunched == aEvent )
       
   203         {
       
   204         iUtils->UnregisterEvent( this, MSatUtils::ESatUiLaunched );
       
   205         // Check is command still waiting UI to start
       
   206         if ( !IsActive() )
       
   207             {
       
   208             LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Event waiting UI" )
       
   209             // Start timer to give UI some time to execute
       
   210             iWaitingUiLaunch = ETrue;
       
   211             iDelayTimer.CreateLocal();
       
   212             iDelayTimer.After( iStatus, KTimerDelay );
       
   213             SetActive();
       
   214             }
       
   215         else
       
   216             {
       
   217             LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Event close UI" )
       
   218             // UI is launched but command is not executing. UI must be closed.
       
   219             iUtils->NotifyEvent( MSatUtils::ESessionTerminatedByUser );
       
   220             }
       
   221         }
       
   222 
       
   223     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Event exiting" )
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CSatCommandHandler::TerminalRsp
       
   228 // Sends the terminal response to the SIM and renews the sat request.
       
   229 // (other items were commented in a header).
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 EXPORT_C void CSatCommandHandler::TerminalRsp(
       
   233     RSat::TPCmd aPCmd, // Identifies the command sending terminal rsp.
       
   234     const TDesC8& aRsp ) // Data package of the response
       
   235     {
       
   236     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::TerminalRsp calling" )
       
   237 
       
   238     iUtils->NotifyEvent( MSatUtils::EDelaySimSessionEnd );
       
   239     iUtils->USatAPI().TerminalRsp( aPCmd, aRsp );
       
   240     Start();
       
   241 
       
   242     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::TerminalRsp exiting" )
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CSatCommandHandler::RunL
       
   247 // If request is completed without error, starts handling the command.
       
   248 // (other items were commented in a header).
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 EXPORT_C void CSatCommandHandler::RunL()
       
   252     {
       
   253     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::RunL calling" )
       
   254     LOG2( SIMPLE,
       
   255             "SATENGINE:   RunL status: %d", iStatus.Int() )
       
   256     if ( iWaitingUiLaunch )
       
   257         {
       
   258         LOG( NORMAL, "  UI is launched. Starting to handle command" )
       
   259         iWaitingUiLaunch = EFalse;
       
   260         iDelayTimer.Close();
       
   261         HandleCommand();
       
   262         }
       
   263     else if ( KErrNone == iStatus.Int() )
       
   264         {
       
   265         // Executing only, if really executing
       
   266         iIsExecuting = ETrue;
       
   267         DoHandleCommand();
       
   268         }
       
   269     else if ( KErrNotSupported != iStatus.Int() )
       
   270         {        
       
   271         Start();
       
   272         }
       
   273     else
       
   274         {
       
   275         LOG( SIMPLE, "SATENGINE:   Request was unsupported" )
       
   276         }
       
   277 
       
   278     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::RunL exiting" )
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CSatCommandHandler::IsPhoneInIdleState
       
   283 // Returns ETrue if using Dummy TSY
       
   284 // (other items were commented in a header).
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 EXPORT_C TBool CSatCommandHandler::IsPhoneInIdleState()
       
   288     {
       
   289     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::IsPhoneInIdleState calling" )
       
   290     TBool isIdle( EFalse );
       
   291 
       
   292     TRAPD( err, ( isIdle = iUtils->SystemState().IsPhoneInIdleStateL() ) );
       
   293 
       
   294     if ( KErrNone != err )
       
   295         {
       
   296         LOG( SIMPLE, 
       
   297         "SATENGINE: CSatCommandHandler::IsPhoneInIdleState KErrNone != err" )
       
   298         isIdle = EFalse;
       
   299         }
       
   300 
       
   301     LOG2( SIMPLE, "SATENGINE: CSatCommandHandler::IsPhoneInIdleState \
       
   302           exiting, isIdle: %d", isIdle )
       
   303     return isIdle;
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CSatCommandHandler::Panic
       
   308 // Gives a panic.
       
   309 // (other items were commented in a header).
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 EXPORT_C void CSatCommandHandler::Panic(
       
   313     const TDesC& aCategory, TInt aReason ) const
       
   314     {
       
   315     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Panic" )
       
   316     User::Panic( aCategory, aReason );
       
   317     }
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // CSatCommandHandler::IsCommandExecuting
       
   321 // (other items were commented in a header).
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 EXPORT_C TBool CSatCommandHandler::IsCommandExecuting() const
       
   325     {
       
   326     LOG( DETAILED, "SATENGINE: CSatCommandHandler::IsCommandExecuting" )
       
   327     return iIsExecuting;
       
   328     }
       
   329 
       
   330 //  End of File