satengine/SatServer/Commands/SimSessionEndCmd/src/CSimSessionEndHandler.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 SimSessionEnd command
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "MSatApi.h"
       
    22 #include    "MSatUiSession.h"
       
    23 #include    "MSatSUiClientHandler.h"
       
    24 #include    "CSimSessionEndHandler.h"
       
    25 #include    "SatLog.h"
       
    26 
       
    27 // CONSTANTS
       
    28 const TInt KSimSessionEndDelay = 60000000;
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CSimSessionEndHandler::CSimSessionEndHandler
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CSimSessionEndHandler::CSimSessionEndHandler() :
       
    39     CSatCommandHandler()
       
    40     {
       
    41     LOG( SIMPLE, "SIMSESSIONEND: \
       
    42         CSimSessionEndHandler::CSimSessionEndHandler calling - exiting" )
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CSimSessionEndHandler::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CSimSessionEndHandler::ConstructL()
       
    51     {
       
    52     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::ConstructL calling" )
       
    53 
       
    54     iTimer = CPeriodic::NewL( EPriorityStandard );
       
    55 
       
    56     iUtils->RegisterL( this, MSatUtils::EDelaySimSessionEnd );
       
    57     iUtils->RegisterL( this, MSatUtils::EDestroySimSessionEndTimer );
       
    58     iUtils->RegisterL( this, MSatUtils::ESessionTerminatedByUser );
       
    59     iUtils->RegisterL( this, MSatUtils::ESimSessionEndCallBack );
       
    60     iUtils->RegisterL( this, MSatUtils::ESustainedTextInDisplay );
       
    61     iUtils->RegisterL( this, MSatUtils::ESustainedTextRemoved );
       
    62     iUtils->RegisterL( this, MSatUtils::ESatUiLaunched );
       
    63 
       
    64     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::ConstructL exiting" )
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSimSessionEndHandler::NewL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CSimSessionEndHandler* CSimSessionEndHandler::NewL( MSatUtils* aUtils )
       
    73     {
       
    74     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::NewL calling" )
       
    75 
       
    76     CSimSessionEndHandler* self = new( ELeave ) CSimSessionEndHandler;
       
    77 
       
    78     CleanupStack::PushL( self );
       
    79     self->BaseConstructL( aUtils );
       
    80     self->ConstructL();
       
    81     CleanupStack::Pop( self );
       
    82 
       
    83     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::NewL exiting" )
       
    84     return self;
       
    85     }
       
    86 
       
    87 
       
    88 // Destructor
       
    89 CSimSessionEndHandler::~CSimSessionEndHandler()
       
    90     {
       
    91     LOG( SIMPLE,
       
    92         "SIMSESSIONEND: CSimSessionEndHandler::~CSimSessionEndHandler calling" )
       
    93 
       
    94     Cancel();
       
    95 
       
    96     if ( iTimer )
       
    97         {
       
    98         iTimer->Cancel();
       
    99         }
       
   100     delete iTimer;
       
   101 
       
   102     LOG( SIMPLE,
       
   103         "SIMSESSIONEND: CSimSessionEndHandler::~CSimSessionEndHandler exiting" )
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CSimSessionEndHandler::TimerCallback
       
   108 // (other items were commented in a header).
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TInt CSimSessionEndHandler::TimerCallback( TAny* aSimSessionEndHandler )
       
   112     {
       
   113     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::TimerCallback calling" )
       
   114 
       
   115     CSimSessionEndHandler* handler =
       
   116         static_cast<CSimSessionEndHandler*>( aSimSessionEndHandler );
       
   117         
       
   118     if ( handler )
       
   119         {
       
   120         LOG( SIMPLE, 
       
   121         "SIMSESSIONEND: CSimSessionEndHandler::TimerCallback handler true" )
       
   122         handler->iTimer->Cancel();
       
   123         handler->HandleCommand();
       
   124         }
       
   125 
       
   126     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::TimerCallback exiting" )
       
   127     return KErrNone;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSimSessionEndHandler::Event
       
   132 // Waits for indication of user wanting to close the sim session.
       
   133 // (other items were commented in a header).
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CSimSessionEndHandler::Event( TInt aEvent )
       
   137     {
       
   138     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::Event calling" )
       
   139 
       
   140     switch ( aEvent )
       
   141         {
       
   142         case MSatUtils::ESatUiLaunched:
       
   143             {
       
   144             LOG( NORMAL, 
       
   145             "SIMSESSIONEND: CSimSessionEndHandler::Event UI is launched" )
       
   146             // New UI session, reset flag
       
   147             iSimSessionTerminatedByUser = EFalse;
       
   148             break;
       
   149             }
       
   150 
       
   151         case MSatUtils::ESessionTerminatedByUser:
       
   152             {
       
   153             LOG( NORMAL, 
       
   154             "SIMSESSIONEND: CSimSessionEndHandler::Event \
       
   155             ESessionTerminatedByUser" )
       
   156             // Next SimSessionEnd will close the ui session.
       
   157             iSimSessionTerminatedByUser = ETrue;
       
   158             break;
       
   159             }
       
   160 
       
   161         case MSatUtils::EDelaySimSessionEnd:
       
   162             {
       
   163             LOG( NORMAL, 
       
   164             "SIMSESSIONEND: CSimSessionEndHandler::Event \
       
   165             EDelaySimSessionEnd" )
       
   166             iTimer->Cancel();
       
   167             TCallBack callback( TimerCallback, this );
       
   168             iTimer->Start( KSimSessionEndDelay, KSimSessionEndDelay, callback );
       
   169             break;
       
   170             }
       
   171 
       
   172         case MSatUtils::EDestroySimSessionEndTimer:
       
   173             {
       
   174             LOG( NORMAL, 
       
   175             "SIMSESSIONEND: CSimSessionEndHandler::Event \
       
   176             EDestroySimSessionEndTimer" )
       
   177             iTimer->Cancel();
       
   178             break;
       
   179             }
       
   180 
       
   181         case MSatUtils::ESimSessionEndCallBack:
       
   182             {
       
   183             LOG( NORMAL, 
       
   184             "SIMSESSIONEND: CSimSessionEndHandler::Event \
       
   185             ESimSessionEndCallBack" )
       
   186             // Forced Sim session end.
       
   187             iTimer->Cancel();
       
   188             HandleCommand();
       
   189             break;
       
   190             }
       
   191 
       
   192         case MSatUtils::ESustainedTextInDisplay:
       
   193             {
       
   194             LOG( NORMAL, "SIMSESSIONEND: CSimSessionEndHandler::Event \
       
   195             ESustainedTextInDisplay" )
       
   196             // Indication of sustained text
       
   197             iSustainedTextActive = ETrue;
       
   198             break;
       
   199             }
       
   200 
       
   201         case MSatUtils::ESustainedTextRemoved:
       
   202             {
       
   203             LOG( NORMAL, "SIMSESSIONEND: CSimSessionEndHandler::Event \
       
   204             ESustainedTextRemoved" )
       
   205             // Indication of sustained text cleared
       
   206             iSustainedTextActive = EFalse;
       
   207             // If last sim session end is pending because of sustained text, 
       
   208             // execute it now
       
   209             if ( iSimSessionEndPending )
       
   210                 {
       
   211                 LOG( NORMAL, 
       
   212                 "SIMSESSIONEND: CSimSessionEndHandler::Event \
       
   213                 iSimSessionEndPending" )
       
   214                 HandleCommand();
       
   215                 }
       
   216 
       
   217             break;
       
   218             }
       
   219 
       
   220         default:
       
   221             {
       
   222             LOG2( NORMAL, 
       
   223             "SIMSESSIONEND: CSimSessionEndHandler::Event \
       
   224             Unexpected event: %i", aEvent )
       
   225             CSatCommandHandler::Event( aEvent );
       
   226             break;
       
   227             }
       
   228         }
       
   229 
       
   230     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::Event exiting" )
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CSimSessionEndHandler::DoCancel
       
   235 // Cancels the sat request.
       
   236 // (other items were commented in a header).
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CSimSessionEndHandler::DoCancel()
       
   240     {
       
   241     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::DoCancel calling" )
       
   242 
       
   243     iUtils->USatAPI().NotifySimSessionEndCancel();
       
   244 
       
   245     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::DoCancel exiting" )
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CSimSessionEndHandler::IssueUSATRequest
       
   250 // (other items were commented in a header).
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CSimSessionEndHandler::IssueUSATRequest( TRequestStatus& aStatus )
       
   254     {
       
   255     LOG( SIMPLE,
       
   256         "SIMSESSIONEND: CSimSessionEndHandler::IssueUSATRequest calling" )
       
   257 
       
   258     iUtils->USatAPI().NotifySimSessionEnd( aStatus );
       
   259 
       
   260     LOG( SIMPLE,
       
   261         "SIMSESSIONEND: CSimSessionEndHandler::IssueUSATRequest exiting" )
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CSimSessionEndHandler::CommandAllowed
       
   266 // (other items were commented in a header).
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 TBool CSimSessionEndHandler::CommandAllowed()
       
   270     {
       
   271     LOG( SIMPLE, "SIMSESSIONEND: \
       
   272         CSimSessionEndHandler::CommandAllowed calling - exiting" )
       
   273     return ETrue;
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CSimSessionEndHandler::NeedUiSession
       
   278 // (other items were commented in a header).
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 TBool CSimSessionEndHandler::NeedUiSession()
       
   282     {
       
   283     LOG( SIMPLE, "SIMSESSIONEND: \
       
   284         CSimSessionEndHandler::NeedUiSession calling - exiting" )
       
   285     return EFalse;
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CSimSessionEndHandler::HandleCommand
       
   290 // (other items were commented in a header).
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CSimSessionEndHandler::HandleCommand()
       
   294     {
       
   295     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::HandleCommand calling" )
       
   296 
       
   297     // Note that the framework has destroyed the simsession
       
   298     // end timer, when HandleCommand is called.
       
   299     if ( !iSimSessionTerminatedByUser && !iSustainedTextActive )
       
   300         {
       
   301         LOG( SIMPLE, 
       
   302         "SIMSESSIONEND: CSimSessionEndHandler::HandleCommand \
       
   303         ESimSessionEndExecuting" )
       
   304         iUtils->NotifyEvent( MSatUtils::ESimSessionEndExecuting );
       
   305         }
       
   306 
       
   307     MSatUiSession* uiSession = iUtils->SatUiHandler().UiSession();
       
   308     if ( uiSession )
       
   309         {
       
   310         // If sustained Display text is on screen, cannot close UI
       
   311         if ( !iSustainedTextActive && ( iSimSessionTerminatedByUser ||
       
   312             !iUtils->SatUiHandler().UiLaunchedByUser() ) )
       
   313             {
       
   314             iSimSessionTerminatedByUser = EFalse;
       
   315             iSimSessionEndPending = EFalse;
       
   316             // Number of executing command handlers should be 0.
       
   317             TInt expectedCommCount = 0;
       
   318 
       
   319             // If SimSessionEnd is executing ie. not active, it has to take
       
   320             // into account when checking executing command handlers.
       
   321             if ( !IsActive() )
       
   322                 {
       
   323                 LOG( SIMPLE, 
       
   324                 "SIMSESSIONEND: CSimSessionEndHandler::HandleCommand \
       
   325                 isn't Active" )
       
   326                 expectedCommCount = 1;
       
   327                 }
       
   328 
       
   329             LOG2( NORMAL, "SIMSESSIONEND: Expected commands: %i",
       
   330                 expectedCommCount )
       
   331             // SimSession end is currently executing, therefore there is one
       
   332             // executing command.
       
   333             if ( expectedCommCount ==
       
   334                  iUtils->NumberOfExecutingCommandHandlers() )
       
   335                 {
       
   336                 LOG( SIMPLE, 
       
   337                 "SIMSESSIONEND: CSimSessionEndHandler::HandleCommand \
       
   338                 expectedCommCount==iUtils->NumberOfExecutingCommandHandlers()" )
       
   339                 // Close the ui session only if there are no
       
   340                 // executing commands.
       
   341                 uiSession->CloseUiSession();
       
   342                 }
       
   343             }
       
   344         else
       
   345             {
       
   346             if ( iSustainedTextActive )
       
   347                 {
       
   348                 LOG( SIMPLE, 
       
   349                 "SIMSESSIONEND: CSimSessionEndHandler::HandleCommand \
       
   350                 iSustainedTextActive true" )
       
   351                 iSimSessionEndPending = ETrue;
       
   352                 }
       
   353             }
       
   354         }
       
   355 
       
   356     // Renew the request, because the sim session end does not send
       
   357     // terminal response, which would renew the request automatically.
       
   358     Start();
       
   359 
       
   360     LOG( SIMPLE, "SIMSESSIONEND: CSimSessionEndHandler::HandleCommand exiting" )
       
   361     }
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // CSimSessionEndHandler::UiLaunchFailed
       
   365 // (other items were commented in a header).
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 void CSimSessionEndHandler::UiLaunchFailed()
       
   369     {
       
   370     // This command does not launch ui client.
       
   371     LOG( SIMPLE,
       
   372         "SIMSESSIONEND: CSimSessionEndHandler::UiLaunchFailed calling-exiting" )
       
   373     }
       
   374 
       
   375 //  End of File