satengine/SatServer/Engine/src/CSatCommandHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2010 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                 else 
       
   162                     { 
       
   163                     LOG( SIMPLE,  
       
   164                     "SATENGINE: CSatCommandHandler::DoHandleCommand iWaitingUiLaunch")
       
   165                     iWaitingUiLaunch = ETrue; 
       
   166                     }
       
   167                 }
       
   168             else
       
   169                 {
       
   170                 LOG( SIMPLE, "SATENGINE: CSatCommandHandler::DoHandleCommand \
       
   171                      uisession available" )
       
   172                 // client session is available handle the command.
       
   173                 HandleCommand();
       
   174                 }
       
   175             }
       
   176         else
       
   177             {
       
   178             LOG( SIMPLE, "SATENGINE: CSatCommandHandler::DoHandleCommand \
       
   179                  don't need uisession" )
       
   180             // Command does not need ui client, so handle the command.
       
   181             HandleCommand();
       
   182             }
       
   183         }
       
   184 
       
   185     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::DoHandleCommand exiting" )
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CSatCommandHandler::ClientResponse
       
   190 // (other items were commented in a header).
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 EXPORT_C void CSatCommandHandler::ClientResponse()
       
   194     {
       
   195     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::ClientResponse panic" )
       
   196     PanicSatEngine( ESatUnexpectedHandleUiResponseCall );
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CSatCommandHandler::Event
       
   201 // (other items were commented in a header).
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 EXPORT_C void CSatCommandHandler::Event( TInt aEvent )
       
   205     {
       
   206     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Event calling" )
       
   207 
       
   208     if ( MSatUtils::ESatUiLaunched == aEvent )
       
   209         {
       
   210         iUtils->UnregisterEvent( this, MSatUtils::ESatUiLaunched );
       
   211         // Check is command still waiting UI to start
       
   212         if ( !IsActive() )
       
   213             {
       
   214             LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Event waiting UI" )
       
   215             // Start timer to give UI some time to execute
       
   216             iWaitingUiLaunch = ETrue;
       
   217             iDelayTimer.CreateLocal();
       
   218             iDelayTimer.After( iStatus, KTimerDelay );
       
   219             SetActive();
       
   220             }
       
   221         else
       
   222             {
       
   223             LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Event close UI" )
       
   224             // UI is launched but command is not executing. UI must be closed.
       
   225             iUtils->NotifyEvent( MSatUtils::ESessionTerminatedByUser );
       
   226             }
       
   227         }
       
   228 
       
   229     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Event exiting" )
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CSatCommandHandler::TerminalRsp
       
   234 // Sends the terminal response to the SIM and renews the sat request.
       
   235 // (other items were commented in a header).
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C void CSatCommandHandler::TerminalRsp(
       
   239     RSat::TPCmd aPCmd, // Identifies the command sending terminal rsp.
       
   240     const TDesC8& aRsp ) // Data package of the response
       
   241     {
       
   242     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::TerminalRsp calling" )
       
   243 
       
   244     iUtils->NotifyEvent( MSatUtils::EDelaySimSessionEnd );
       
   245     iUtils->USatAPI().TerminalRsp( aPCmd, aRsp );
       
   246     Start();
       
   247 
       
   248     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::TerminalRsp exiting" )
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CSatCommandHandler::RunL
       
   253 // If request is completed without error, starts handling the command.
       
   254 // (other items were commented in a header).
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 EXPORT_C void CSatCommandHandler::RunL()
       
   258     {
       
   259     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::RunL calling" )
       
   260     LOG2( SIMPLE,
       
   261             "SATENGINE:   RunL status: %d", iStatus.Int() )
       
   262     if ( iWaitingUiLaunch )
       
   263         {
       
   264         LOG( NORMAL, "  UI is launched. Starting to handle command" )
       
   265         iWaitingUiLaunch = EFalse;
       
   266         iDelayTimer.Close();
       
   267         HandleCommand();
       
   268         }
       
   269     else if ( KErrNone == iStatus.Int() )
       
   270         {
       
   271         // Executing only, if really executing
       
   272         iIsExecuting = ETrue;
       
   273         DoHandleCommand();
       
   274         }
       
   275     else if ( KErrNotSupported != iStatus.Int() )
       
   276         {        
       
   277         Start();
       
   278         }
       
   279     else
       
   280         {
       
   281         LOG( SIMPLE, "SATENGINE:   Request was unsupported" )
       
   282         }
       
   283 
       
   284     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::RunL exiting" )
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CSatCommandHandler::IsPhoneInIdleState
       
   289 // Returns ETrue if using Dummy TSY
       
   290 // (other items were commented in a header).
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 EXPORT_C TBool CSatCommandHandler::IsPhoneInIdleState()
       
   294     {
       
   295     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::IsPhoneInIdleState calling" )
       
   296     TBool isIdle( EFalse );
       
   297 
       
   298     TRAPD( err, ( isIdle = iUtils->SystemState().IsPhoneInIdleStateL() ) );
       
   299 
       
   300     if ( KErrNone != err )
       
   301         {
       
   302         LOG( SIMPLE, 
       
   303         "SATENGINE: CSatCommandHandler::IsPhoneInIdleState KErrNone != err" )
       
   304         isIdle = EFalse;
       
   305         }
       
   306 
       
   307     LOG2( SIMPLE, "SATENGINE: CSatCommandHandler::IsPhoneInIdleState \
       
   308           exiting, isIdle: %d", isIdle )
       
   309     return isIdle;
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CSatCommandHandler::Panic
       
   314 // Gives a panic.
       
   315 // (other items were commented in a header).
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 EXPORT_C void CSatCommandHandler::Panic(
       
   319     const TDesC& aCategory, TInt aReason ) const
       
   320     {
       
   321     LOG( SIMPLE, "SATENGINE: CSatCommandHandler::Panic" )
       
   322     User::Panic( aCategory, aReason );
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CSatCommandHandler::IsCommandExecuting
       
   327 // (other items were commented in a header).
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 EXPORT_C TBool CSatCommandHandler::IsCommandExecuting() const
       
   331     {
       
   332     LOG( DETAILED, "SATENGINE: CSatCommandHandler::IsCommandExecuting" )
       
   333     return iIsExecuting;
       
   334     }
       
   335 
       
   336 //  End of File