wvuing/IMPSConnectionUI/ConnectionSrc/CIMPSConnectionUiAgentImp.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 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:  IMPS Connection UI Agent implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32std.h>
       
    20 #include <cimpsconnuiclntfilteredpreseventnotifierng.h>
       
    21 
       
    22 #include "CIMPSConnectionUiAgentImp.h"
       
    23 #include "MCnUiUiFacade.h"
       
    24 
       
    25 #include "CnUiCommon.hrh"
       
    26 #include "CCnUiClientGroupUiNotifyHandler.h"
       
    27 #include "CCnUiClientGroupUiConnectionLostHandler.h"
       
    28 #include "MCnUiConnModeHandler.h"
       
    29 
       
    30 
       
    31 
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 // Two-phased constructor.
       
    35 CIMPSConnectionUiAgentImp* CIMPSConnectionUiAgentImp::NewL( TIMPSConnectionClient aClient )
       
    36     {
       
    37     CIMPSConnectionUiAgentImp* self = new ( ELeave ) CIMPSConnectionUiAgentImp( aClient );
       
    38 
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self ); //self
       
    42 
       
    43     return self;
       
    44     }
       
    45 
       
    46 
       
    47 // Destructor
       
    48 CIMPSConnectionUiAgentImp::~CIMPSConnectionUiAgentImp()
       
    49     {
       
    50     delete iClientGroupRemoteNotifyHandler;
       
    51     delete iClientGroupConnectionLostHandler;
       
    52     delete iClientConnModeHandler;
       
    53 
       
    54     delete iUi;
       
    55     delete iClntNotifier;
       
    56     delete iBrandedResourceFileName;
       
    57     }
       
    58 
       
    59 
       
    60 // C++ default constructor can NOT contain any code, that
       
    61 // might leave.
       
    62 //
       
    63 CIMPSConnectionUiAgentImp::CIMPSConnectionUiAgentImp( TIMPSConnectionClient aClient )
       
    64         : iClient( aClient )
       
    65     {
       
    66     }
       
    67 
       
    68 
       
    69 // Symbian OS default constructor can leave.
       
    70 void CIMPSConnectionUiAgentImp::ConstructL()
       
    71     {
       
    72     //agent services
       
    73     iClntNotifier = CIMPSConnUiClntFilteredPresEventNotifier::NewL( iClient );
       
    74     iClntNotifier->AddObserverL( this );
       
    75     iClntNotifier->StartL();
       
    76 
       
    77     //agent service handlers
       
    78     iClientGroupRemoteNotifyHandler = CCnUiClientGroupUiNotifyHandler::NewL( iClient );
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CIMPSConnectionUiAgentImp::StartServiceL()
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 TInt CIMPSConnectionUiAgentImp::StartServiceL( TIMPSConnectionUiAgentService aService )
       
    86     {
       
    87     switch ( aService )
       
    88         {
       
    89         case EIMPSNotifyActiveConnectionLostReasons:
       
    90             {
       
    91             if ( !iClientGroupConnectionLostHandler )
       
    92                 {
       
    93                 iClientGroupConnectionLostHandler =
       
    94                     CCnUiClientGroupUiConnectionLostHandler::NewL( iClient );
       
    95                 }
       
    96 
       
    97             break;
       
    98             }
       
    99 
       
   100         case EIMPSQueryActiveConnectionScheduledClose:
       
   101             {
       
   102             if ( iBrandedResourceFileName )
       
   103                 {
       
   104                 iClientGroupRemoteNotifyHandler->UseResourceFileL( *iBrandedResourceFileName );
       
   105                 }
       
   106             else
       
   107                 {
       
   108                 iClientGroupRemoteNotifyHandler->UseResourceFileL( KNullDesC() );
       
   109                 }
       
   110 
       
   111             iClientGroupRemoteNotifyHandler->SetHandled(
       
   112                 ECGQActiveConnectionScheduledClose,
       
   113                 ETrue );
       
   114             break;
       
   115             }
       
   116 
       
   117 
       
   118         case EIMPSQueryActiveConnectionSuppressForScheduledConnection:
       
   119             {
       
   120             if ( iBrandedResourceFileName )
       
   121                 {
       
   122                 iClientGroupRemoteNotifyHandler->UseResourceFileL( *iBrandedResourceFileName );
       
   123                 }
       
   124             else
       
   125                 {
       
   126                 iClientGroupRemoteNotifyHandler->UseResourceFileL( KNullDesC() );
       
   127                 }
       
   128             iClientGroupRemoteNotifyHandler->SetHandled(
       
   129                 ECGQActiveConnectionSuppressForScheduledConnection,
       
   130                 ETrue );
       
   131             break;
       
   132             }
       
   133 
       
   134 
       
   135         case EIMPSReqisterAsSignificantConnectionClientInScheduling :
       
   136             {
       
   137             if ( !iClientConnModeHandler )
       
   138                 {
       
   139                 iClientConnModeHandler = CreateConnModeHandlerL();
       
   140                 iClientConnModeHandler->CancelRegisteringAsSSClient();
       
   141                 }
       
   142             break;
       
   143             }
       
   144 
       
   145         default:
       
   146             {
       
   147             break; //unknown service
       
   148             }
       
   149         }
       
   150 
       
   151     return KErrNone;
       
   152     }
       
   153 
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CIMPSConnectionUiAgentImp::StopService()
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TInt CIMPSConnectionUiAgentImp::StopService( TIMPSConnectionUiAgentService aService )
       
   160     {
       
   161     switch ( aService )
       
   162         {
       
   163         case EIMPSNotifyActiveConnectionLostReasons:
       
   164             {
       
   165             if ( iClientGroupConnectionLostHandler )
       
   166                 {
       
   167                 delete iClientGroupConnectionLostHandler;
       
   168                 iClientGroupConnectionLostHandler = NULL;
       
   169                 }
       
   170             break;
       
   171             }
       
   172 
       
   173         case EIMPSQueryActiveConnectionScheduledClose:
       
   174             {
       
   175             iClientGroupRemoteNotifyHandler->SetHandled( ECGQActiveConnectionScheduledClose,
       
   176                                                          EFalse );
       
   177             break;
       
   178             }
       
   179 
       
   180 
       
   181         case EIMPSQueryActiveConnectionSuppressForScheduledConnection:
       
   182             {
       
   183             iClientGroupRemoteNotifyHandler->SetHandled( ECGQActiveConnectionSuppressForScheduledConnection,
       
   184                                                          EFalse );
       
   185             break;
       
   186             }
       
   187 
       
   188 
       
   189         case EIMPSReqisterAsSignificantConnectionClientInScheduling :
       
   190             {
       
   191             if ( iClientConnModeHandler )
       
   192                 {
       
   193                 iClientConnModeHandler->CancelRegisteringAsSSClient();
       
   194                 delete iClientConnModeHandler;
       
   195                 iClientConnModeHandler = NULL;
       
   196                 }
       
   197 
       
   198             break;
       
   199             }
       
   200 
       
   201         default:
       
   202             {
       
   203             break; //unknown service
       
   204             }
       
   205         }
       
   206 
       
   207     return KErrNone;
       
   208     }
       
   209 
       
   210 
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CIMPSConnectionUiAgentImp::StopAllServices()
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CIMPSConnectionUiAgentImp::StopAllServices()
       
   217     {
       
   218     //NOTE!! When adding new services, remember add those also here
       
   219 
       
   220     StopService( EIMPSNotifyActiveConnectionLostReasons );
       
   221     StopService( EIMPSQueryActiveConnectionScheduledClose );
       
   222     StopService( EIMPSQueryActiveConnectionSuppressForScheduledConnection );
       
   223     StopService( EIMPSReqisterAsSignificantConnectionClientInScheduling );
       
   224     }
       
   225 
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CIMPSConnectionUiAgentImp::HandlePresenceEventL()
       
   229 // From MIMPSConnUiPresenceEventObserver
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CIMPSConnectionUiAgentImp::HandlePresenceEventL( CIMPSConnUiPresEventNotifier* /*aNotifier*/,
       
   233                                                       const CPEngNWSessionSlotID2& /*aSessionSlotID*/,
       
   234                                                       TIMPSConnectionClient /*aClient*/,
       
   235                                                       TIMPSPresenceServiceEvent aEvent )
       
   236     {
       
   237     MCnUiUiFacade* tempUi = CreateUiFacadeL();
       
   238     if ( iUi )
       
   239         {
       
   240         delete iUi;
       
   241         }
       
   242     iUi = tempUi;
       
   243 
       
   244     if ( iBrandedResourceFileName )
       
   245         {
       
   246 
       
   247         if ( iUi )
       
   248             {
       
   249             iUi->SwitchResourceFileL( *iBrandedResourceFileName );
       
   250             }
       
   251         }
       
   252 
       
   253     if ( iClientGroupConnectionLostHandler )
       
   254         {
       
   255         if ( iBrandedResourceFileName )
       
   256             {
       
   257             iClientGroupConnectionLostHandler->UseResourceFileL( *iBrandedResourceFileName );
       
   258             }
       
   259         else
       
   260             {
       
   261             iClientGroupConnectionLostHandler->UseResourceFileL( KNullDesC() );
       
   262             }
       
   263         TRAPD( err, iClientGroupConnectionLostHandler->HandlePresenceEventL( aEvent ) );
       
   264 
       
   265 
       
   266         //When userA logs in with some user id. Now userB logs in with same user id.
       
   267         //Before UserA gets the notification from network of the server disconnection, userA
       
   268         //tries to exit the application. The Application crashes.
       
   269 
       
   270         //Reason:
       
   271         //*******
       
   272         //The UiSessionHandler calls for a HandlePresenceEventL(..) when UserA exits the application.
       
   273         //Before the completion of this handler, the netwrok sends the notification, the current active
       
   274         //object is put on a hold and the network disconnection active object takes the control.
       
   275         //This results in calling the same HandlePresenceEventL(..), wherein the iUi is deleted.
       
   276         //After completion the other thread which was interrupted resumes, and since the iUi was deleted
       
   277         //this thread crashes.
       
   278 
       
   279         //Solution:
       
   280         //*********
       
   281         //1: Remove delete which is below. So that some iUi is available for the other
       
   282         //thread to complete. This soln was not followed as this commonUi has to be revamped
       
   283         //take care of the same while revamping this component.
       
   284         //2: better check for iUi before performing any action on the same. This is
       
   285         //now followed as it is simpler solution.
       
   286 
       
   287         if ( iUi )
       
   288             {
       
   289             iUi->HandleIfError( err );
       
   290             }
       
   291         }
       
   292 
       
   293     if ( iClientGroupRemoteNotifyHandler )
       
   294         {
       
   295         if ( iBrandedResourceFileName )
       
   296             {
       
   297             iClientGroupConnectionLostHandler->UseResourceFileL( *iBrandedResourceFileName );
       
   298             }
       
   299         else
       
   300             {
       
   301             iClientGroupConnectionLostHandler->UseResourceFileL( KNullDesC() );
       
   302             }
       
   303         TRAPD( err, iClientGroupRemoteNotifyHandler->HandlePresenceEventL( aEvent ) );
       
   304 
       
   305         if ( iUi )
       
   306             {
       
   307             iUi->HandleIfError( err );
       
   308             }
       
   309         }
       
   310 
       
   311     delete iUi;
       
   312     iUi = NULL;
       
   313     }
       
   314 
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CIMPSConnectionUiAgentImp::HandlePresenceEventNotifyError()
       
   318 // From MIMPSConnUiPresenceEventObserver
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 void CIMPSConnectionUiAgentImp::HandlePresenceEventNotifyError( CIMPSConnUiPresEventNotifier* /*aNotifier*/,
       
   322                                                                 TInt aError )
       
   323     {
       
   324     MCnUiUiFacade* tempUi = NULL;
       
   325     // if we don't get facade we just don't show anything
       
   326     TRAPD( err, tempUi = CreateUiFacadeL() );
       
   327     if ( err )
       
   328         {
       
   329         return;
       
   330         }
       
   331 
       
   332     if ( iUi )
       
   333         {
       
   334         delete iUi;
       
   335         }
       
   336     iUi = tempUi;
       
   337 
       
   338     if ( iBrandedResourceFileName )
       
   339         {
       
   340 
       
   341         if ( iUi )
       
   342             {
       
   343             TRAP( err, iUi->SwitchResourceFileL( *iBrandedResourceFileName ) );
       
   344             if ( err != KErrNone )
       
   345                 {
       
   346                 CActiveScheduler::Current()->Error( err );
       
   347                 }
       
   348             }
       
   349         }
       
   350 
       
   351 
       
   352     if ( iUi )
       
   353         {
       
   354         iUi->HandleIfError( aError );
       
   355         }
       
   356 
       
   357     delete iUi;
       
   358     iUi = NULL;
       
   359     }
       
   360 
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CIMPSConnectionUiAgentImp::UseResourceFileL()
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CIMPSConnectionUiAgentImp::UseResourceFileL( const TDesC& aNewResourceFile )
       
   367     {
       
   368     if ( aNewResourceFile.Length() == 0 )
       
   369         {
       
   370         //empty resource file name ==> use the default resource
       
   371         delete iBrandedResourceFileName;
       
   372         iBrandedResourceFileName = NULL;
       
   373         }
       
   374     else
       
   375         {
       
   376         // use this resourcefile
       
   377         HBufC* tempFile = aNewResourceFile.AllocL();
       
   378         delete iBrandedResourceFileName;
       
   379         iBrandedResourceFileName = tempFile;
       
   380         }
       
   381     }
       
   382 
       
   383 
       
   384 //  End of File
       
   385 
       
   386 
       
   387 
       
   388 
       
   389