satengine/SatServer/Engine/src/CSatSUiClientHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2009 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 some UI Client activity
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CSatSUiClientHandler.h"
       
    22 //lint -e766 Used inside TRAP macro, lint misfunction.
       
    23 #include    "EnginePanic.h"
       
    24 #include    "MSatSSessions.h"
       
    25 #include    "MSatShellController.h"
       
    26 #include    "CSatThreadDeathMonitor.h"
       
    27 #include    "SatLog.h"
       
    28 #include    "MSatUtils.h"
       
    29 #include    "TSatEventMediator.h"
       
    30 
       
    31 // CONSTANTS
       
    32 _LIT( KShellControllerDll, "SatShellCntrl.dll" ); // ShellController dll
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CSatSUiClientHandler::CSatSUiClientHandler
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CSatSUiClientHandler::CSatSUiClientHandler(
       
    43     MSatSSessions& aSessions,
       
    44     TSatEventMediator& aEventMediator ) :
       
    45     iSessions( aSessions ),
       
    46     iEventMediator( aEventMediator ),
       
    47     iUiLaunchedByUser( EFalse ),
       
    48     iSatUiClosing( EFalse ),
       
    49     iLaunchSatUiAfterClose( EFalse ),
       
    50     iSatUiPanicked( EFalse )
       
    51     {
       
    52     LOG( SIMPLE, "SATENGINE: \
       
    53         CSatSUiClientHandler::CSatSUiClientHandler calling - exiting" )
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSatSUiClientHandler::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CSatSUiClientHandler::ConstructL()
       
    62     {
       
    63     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ConstructL calling" )
       
    64 
       
    65     // Create thread death monitor
       
    66     iThreadDeathMonitor = CSatThreadDeathMonitor::NewL();
       
    67 
       
    68     iEventMediator.RegisterL( this, MSatUtils::ESatUiLaunched );
       
    69     iEventMediator.RegisterL( this, MSatUtils::EBringSatUiToForeGround );
       
    70 
       
    71     // Load SatShellController
       
    72     // Create the UI handler instance
       
    73     User::LeaveIfError( iSatShellCntrlLibrary.Load( KShellControllerDll ) );
       
    74 
       
    75     // creating the class...
       
    76     TLibraryFunction uiControllerFactory = iSatShellCntrlLibrary.Lookup( 1 );
       
    77 
       
    78     iSatShellCntrl =
       
    79         reinterpret_cast<MSatShellController*>( uiControllerFactory() );
       
    80 
       
    81     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ConstructL exiting" )
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSatSUiClientHandler::NewL
       
    86 // Two-phased constructor.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CSatSUiClientHandler* CSatSUiClientHandler::NewL(
       
    90     MSatSSessions& aSessions,
       
    91     TSatEventMediator& aEventMediator )
       
    92     {
       
    93     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::NewL calling" )
       
    94 
       
    95     CSatSUiClientHandler* self =
       
    96         new( ELeave ) CSatSUiClientHandler( aSessions, aEventMediator );
       
    97 
       
    98     CleanupStack::PushL( self );
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop( self );
       
   101 
       
   102     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::NewL exiting" )
       
   103     return self;
       
   104     }
       
   105 
       
   106 
       
   107 // Destructor
       
   108 CSatSUiClientHandler::~CSatSUiClientHandler()
       
   109     {
       
   110     LOG( SIMPLE,
       
   111          "SATENGINE: CSatSUiClientHandler::~CSatSUiClientHandler calling" )
       
   112 
       
   113     iUtils = NULL;
       
   114     delete iSatShellCntrl;
       
   115     delete iThreadDeathMonitor;
       
   116     iSatShellCntrlLibrary.Close();
       
   117 
       
   118     LOG( SIMPLE,
       
   119          "SATENGINE: CSatSUiClientHandler::~CSatSUiClientHandler exiting" )
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CSatSUiClientHandler::SetUtils
       
   124 // Sets Sat Utils interface
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CSatSUiClientHandler::SetUtils( MSatUtils* aUtils )
       
   128     {
       
   129     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::SetUtils calling" )
       
   130 
       
   131     iUtils = aUtils;
       
   132 
       
   133     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::SetUtils exiting" )
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CSatSUiClientHandler::ThreadDiedL
       
   138 // Notification from Thread death monitor
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CSatSUiClientHandler::ThreadDiedL()
       
   142     {
       
   143     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ThreadDiedL calling" )
       
   144 
       
   145     // Sat UI Thread has died.
       
   146     iSatUiClosing = EFalse;
       
   147     iUiLaunchedByUser = EFalse;
       
   148 
       
   149     // Check is there LaunchUi request active.
       
   150     if ( iLaunchSatUiAfterClose )
       
   151         {
       
   152         LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ThreadDiedL \
       
   153         iLaunchSatUiAfterClose true" )
       
   154         iLaunchSatUiAfterClose = EFalse;
       
   155         LaunchSatUiL();
       
   156         }
       
   157 
       
   158     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ThreadDiedL exiting" )
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CSatSUiClientHandler::ThreadPanicedL
       
   163 // Notification from Thread death monitor
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CSatSUiClientHandler::ThreadPanicedL()
       
   167     {
       
   168     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ThreadDiedL calling" )
       
   169 
       
   170     iSatUiPanicked = ETrue;
       
   171     ThreadDiedL();
       
   172 
       
   173     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ThreadDiedL exiting" )
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CSatSUiClientHandler::Event
       
   178 // Event notified
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CSatSUiClientHandler::Event( TInt aEvent )
       
   182     {
       
   183     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::Event calling" )
       
   184 
       
   185     //lint -e{961} Other events do not need to be handled here
       
   186     if ( MSatUtils::ESatUiLaunched == aEvent )
       
   187         {
       
   188         iSatUiPanicked = EFalse;
       
   189         // Ui is not launced by user, if there are executing commands when
       
   190         // ui launch event has arrived.
       
   191         const TInt activeCommands( iUtils->NumberOfExecutingCommandHandlers() );
       
   192         LOG2( SIMPLE, "SATENGINE: CSatSUiClientHandler::Event \
       
   193               activeCommands: %i", activeCommands )
       
   194         if ( activeCommands > 0 )
       
   195             {
       
   196             iUiLaunchedByUser = EFalse;
       
   197             // Bring to foreground. This will complete the SAT UI cosntruction.
       
   198             ShellController().BringSatUiToForeground();
       
   199             }
       
   200         else
       
   201             {
       
   202             iUiLaunchedByUser = ETrue;
       
   203             }
       
   204         }
       
   205     else if ( MSatUtils::EBringSatUiToForeGround == aEvent )
       
   206         {
       
   207         LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::Event bring SAT UI \
       
   208              to foreground" )
       
   209         // If UI is not launched by user, bring SAT UI to foreground when 
       
   210         // needed.
       
   211         if ( !iUiLaunchedByUser )
       
   212             {
       
   213             LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::Event \
       
   214             iUiLaunchedByUser false" )
       
   215             ShellController().BringSatUiToForeground();
       
   216             }
       
   217         }
       
   218 
       
   219     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::Event exiting" )
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CSatSUiClientHandler::NotifyThreadDeath
       
   224 // Notifies Thread death monitor
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CSatSUiClientHandler::NotifyThreadDeath()
       
   228     {
       
   229     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::NotifyThreadDeath calling" )
       
   230 
       
   231     iSatUiClosing = ETrue;
       
   232     iUiLaunchedByUser = EFalse;
       
   233 
       
   234     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::NotifyThreadDeath exiting" )
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CSatSUiClientHandler::StartObservingThread
       
   239 // Notifies Thread death monitor
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 void CSatSUiClientHandler::StartObservingThread()
       
   243     {
       
   244     LOG( SIMPLE,
       
   245         "SATENGINE: CSatSUiClientHandler::StartObservingThread calling" )
       
   246 
       
   247     TInt err( KErrNone );
       
   248     TRAP( err, iThreadDeathMonitor->NotifyThreadDeathL( iThread, *this ) );
       
   249     if ( KErrNone != err )
       
   250         {
       
   251         LOG2( NORMAL, "SATENGINE: \
       
   252             CSatSUiClientHandler::NotifyThreadDeath error: %i", err )
       
   253         iThreadDeathMonitor->Cancel();
       
   254         }
       
   255 
       
   256     LOG( SIMPLE,
       
   257         "SATENGINE: CSatSUiClientHandler::StartObservingThread exiting" )
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CSatSUiClientHandler::SetObserveredThread
       
   262 // Notifies Thread death monitor
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CSatSUiClientHandler::SetObserveredThread( TThreadId& aThreadId )
       
   266     {
       
   267     LOG( SIMPLE,
       
   268          "SATENGINE: CSatSUiClientHandler::SetObserveredThread calling" )
       
   269 
       
   270     iThread = aThreadId;
       
   271 
       
   272     LOG( SIMPLE,
       
   273          "SATENGINE: CSatSUiClientHandler::SetObserveredThread exiting" )
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CSatSUiClientHandler::UiSession
       
   278 // Returns UI session
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 MSatUiSession* CSatSUiClientHandler::UiSession()
       
   282     {
       
   283     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::UiSession calling" )
       
   284 
       
   285     MSatUiSession* session = NULL;
       
   286 
       
   287     // If SAT UI is closing, return null, even if session is not null
       
   288     if ( !iSatUiClosing && !iSatUiPanicked )
       
   289         {
       
   290         LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::UiSession session \
       
   291         not null" )
       
   292         session = iSessions.UiSession();
       
   293         }
       
   294 
       
   295     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::UiSession exiting" )
       
   296     return session;
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CSatSUiClientHandler::LaunchSatUiL
       
   301 // Launches Sat UI
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CSatSUiClientHandler::LaunchSatUiL()
       
   305     {
       
   306     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::LaunchSatUiL calling" )
       
   307 
       
   308     // If ui client application is closing, we have to wait for the
       
   309     // closing and launch ui client after it.
       
   310     if ( iSatUiClosing )
       
   311         {
       
   312         LOG( NORMAL, "SATENGINE: CSatSUiClientHandler::LaunchSatUiL \
       
   313              UI IS CLOSING DOWN -> WAIT UI THREAD DEATH" )
       
   314         iLaunchSatUiAfterClose = ETrue;
       
   315         }
       
   316     else
       
   317         {
       
   318         LOG( NORMAL, "SATENGINE: CSatSUiClientHandler::LaunchSatUiL \
       
   319              LAUNCHING SAT UI" )
       
   320         ShellController().LaunchSatUiL();
       
   321         }
       
   322 
       
   323     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::LaunchSatUiL exiting" )
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CSatSUiClientHandler::UiLaunchedByUser
       
   328 // Is UI Launched by user
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 TBool CSatSUiClientHandler::UiLaunchedByUser()
       
   332     {
       
   333     LOG( SIMPLE,
       
   334         "SATENGINE: CSatSUiClientHandler::UiLaunchedByUser calling - exiting" )
       
   335     return iUiLaunchedByUser;
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CSatSUiClientHandler::ShellController
       
   340 // Returns SatShellController from UI side
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 MSatShellController& CSatSUiClientHandler::ShellController()
       
   344     {
       
   345     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ShellController calling" )
       
   346 
       
   347     __ASSERT_ALWAYS( iSatShellCntrl, PanicSatEngine( ESatEngineNullPointer ) );
       
   348 
       
   349     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::ShellController exiting" )
       
   350     return *iSatShellCntrl;
       
   351     }
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CSatSUiClientHandler::ShellController
       
   355 // Returns SatShellController from UI side
       
   356 // -----------------------------------------------------------------------------
       
   357 //
       
   358 TBool CSatSUiClientHandler::IsUiClosing() const
       
   359     {
       
   360     LOG( SIMPLE, "SATENGINE: CSatSUiClientHandler::IsUiClosing call - exit" )
       
   361     return iSatUiClosing;
       
   362     }
       
   363 
       
   364 //  End of File