wvuing/IMPSConnectionUI/NotifySrc/CIMPSConnUiConnectionModeNotifierImp.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Connection mode notifier implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32std.h>
       
    20 #include <mimpsconnuiconnectionmodeobserverng.h>
       
    21 #include "CIMPSConnUiConnectionModeNotifierImp.h"
       
    22 #include "CnUiPanics.h"
       
    23 
       
    24 // ================= MEMBER FUNCTIONS =======================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CIMPSConnUiConnectionModeNotifierImp::NewL()
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CIMPSConnUiConnectionModeNotifierImp* CIMPSConnUiConnectionModeNotifierImp::NewL(
       
    31     CIMPSConnUiConnectionModeNotifier& aInterface,
       
    32     TIMPSConnectionClient aClient )
       
    33     {
       
    34     CIMPSConnUiConnectionModeNotifierImp* self =
       
    35         new ( ELeave ) CIMPSConnUiConnectionModeNotifierImp( aInterface,
       
    36                                                              aClient );
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self ); //self
       
    40     return self;
       
    41     }
       
    42 
       
    43 
       
    44 // Destructor
       
    45 CIMPSConnUiConnectionModeNotifierImp::~CIMPSConnUiConnectionModeNotifierImp()
       
    46     {
       
    47     Dying();
       
    48     delete iConnModeHandler;
       
    49     iObserverArray.Close();
       
    50     }
       
    51 
       
    52 
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 //
       
    56 CIMPSConnUiConnectionModeNotifierImp::CIMPSConnUiConnectionModeNotifierImp(
       
    57     CIMPSConnUiConnectionModeNotifier& aInterface,
       
    58     TIMPSConnectionClient aClient )
       
    59         : iInterface( aInterface ),
       
    60         iClient( aClient ),
       
    61         iStarted( EFalse ),
       
    62         iDying( EFalse )
       
    63     {
       
    64     }
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CIMPSConnUiConnectionModeNotifierImp::ConstructL()
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CIMPSConnUiConnectionModeNotifierImp::ConstructL()
       
    72     {
       
    73     iConnModeHandler = CreateConnModeHandlerL();
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CIMPSConnUiConnectionModeNotifierImp::StartL()
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CIMPSConnUiConnectionModeNotifierImp::StartL()
       
    82     {
       
    83     //make here sanity checks to encapsulate
       
    84     //notifier behaviour
       
    85     if ( iDying )
       
    86         {
       
    87         //if dying, the notifier restart is silently ignored
       
    88         //notifier is evidently going down anyway
       
    89         return;
       
    90         }
       
    91 
       
    92     if ( iStarted )
       
    93         {
       
    94         User::Leave( KErrInUse );
       
    95         }
       
    96 
       
    97     if ( iObserverArray.Count() == 0 )
       
    98         {
       
    99         User::Leave( KErrNotReady );
       
   100         }
       
   101 
       
   102     TRAPD( err, DoStartL() );
       
   103     if ( err != KErrNone )
       
   104         {
       
   105         DoStop();
       
   106         User::Leave( err );
       
   107         }
       
   108 
       
   109     iStarted = ETrue;
       
   110     }
       
   111 
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CIMPSConnUiConnectionModeNotifierImp::Stop()
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CIMPSConnUiConnectionModeNotifierImp::Stop()
       
   118     {
       
   119     //notify observers from cancel
       
   120     StopAndNotifyObserversFromError( KErrCancel );
       
   121     }
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CIMPSConnUiConnectionModeNotifierImp::AddObserverL()
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CIMPSConnUiConnectionModeNotifierImp::AddObserverL(
       
   129     MIMPSConnUiConnectionModeObserver* aObserver )
       
   130     {
       
   131     __ASSERT_ALWAYS( aObserver,
       
   132                      CnUiPanicOrLeaveL( EIMPSConn_NULLPtr,
       
   133                                         KErrArgument ) );
       
   134 
       
   135     iObserverArray.AddObserverL( aObserver );
       
   136     }
       
   137 
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CIMPSConnUiConnectionModeNotifierImp::RemoveObserver()
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TInt CIMPSConnUiConnectionModeNotifierImp::RemoveObserver(
       
   144     MIMPSConnUiConnectionModeObserver* aObserver )
       
   145     {
       
   146     return iObserverArray.RemoveObserver( aObserver );
       
   147     }
       
   148 
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CIMPSConnUiConnectionModeNotifierImp::ConnectionModeByCategoryL()
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TIMPSConnectionModeEvent CIMPSConnUiConnectionModeNotifierImp::ConnectionModeByCategoryL(
       
   155     TIMPSConnectionModeEvent aModeEventCateqory )
       
   156     {
       
   157     return iConnModeHandler->ConnectionModeL( iClient, aModeEventCateqory );
       
   158     }
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CIMPSConnUiConnectionModeNotifierImp::StopAndNotifyObserversFromError()
       
   163 // from MCnUiConnModeObserver
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CIMPSConnUiConnectionModeNotifierImp::HandleConnModeChange(
       
   167     TIMPSConnectionClient /*aRequestedClient*/,
       
   168     TIMPSConnectionModeEvent aConnMode )
       
   169     {
       
   170     NotifyObserversFromEvent( aConnMode );
       
   171     }
       
   172 
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CIMPSConnUiConnectionModeNotifierImp::DoStartL()
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CIMPSConnUiConnectionModeNotifierImp::DoStartL()
       
   179     {
       
   180     iConnModeHandler->NotifyConnectionModeChangesL( this, iClient );
       
   181     }
       
   182 
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CIMPSConnUiConnectionModeNotifierImp::DoStop()
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CIMPSConnUiConnectionModeNotifierImp::DoStop()
       
   189     {
       
   190     iConnModeHandler->CancelConnectionModeNotify();
       
   191     }
       
   192 
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CIMPSConnUiConnectionModeNotifierImp::Dying()
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CIMPSConnUiConnectionModeNotifierImp::Dying()
       
   199     {
       
   200     iDying = ETrue;
       
   201     if ( iStarted )
       
   202         {
       
   203         iStarted = EFalse;
       
   204         DoStop();
       
   205         }
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CIMPSConnUiConnectionModeNotifierImp::NotifyObserversFromEvent()
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CIMPSConnUiConnectionModeNotifierImp::NotifyObserversFromEvent(
       
   213     TIMPSConnectionModeEvent aEvent )
       
   214     {
       
   215     //if not running, don't notify the clients
       
   216     if ( !iStarted )
       
   217         {
       
   218         return;
       
   219         }
       
   220 
       
   221     iObserverArray.NotifyObservers( *this, aEvent );
       
   222     }
       
   223 
       
   224 
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CIMPSConnUiConnectionModeNotifierImp::StopAndNotifyObserversFromError()
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CIMPSConnUiConnectionModeNotifierImp::StopAndNotifyObserversFromError( TInt aError )
       
   231     {
       
   232     //if not running, don't notify the clients
       
   233     if ( !iStarted )
       
   234         {
       
   235         return;
       
   236         }
       
   237 
       
   238     //Error propagating from the underlying implementation
       
   239     //causes the notifier to stop. However, flag & actual
       
   240     //stopping must be done before notifying the clients
       
   241     //since some client may wan't to restart this notifier
       
   242     //in the notification callback...
       
   243 
       
   244     //Also the state must be set to "not started" before
       
   245     //actual stopping  since the stopping of some event
       
   246     //sources cause further KErrCancel events
       
   247     //(==>those will be filtered on !started check on above.)
       
   248     iStarted = EFalse;
       
   249     DoStop();
       
   250 
       
   251     //do the notify
       
   252     iObserverArray.NotifyObserversFromError( *this, aError );
       
   253     }
       
   254 
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CIMPSConnUiConnectionModeNotifierImp::MediateNotifyL()
       
   258 // From MGenObserverNotifyMediator
       
   259 // Forwards handling to pre-registered mediator function.
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CIMPSConnUiConnectionModeNotifierImp::MediateNotifyL(
       
   263     MIMPSConnUiConnectionModeObserver& aObserverToNotify,
       
   264     TIMPSConnectionModeEvent& aNotifyData )
       
   265     {
       
   266     aObserverToNotify.HandleConnectionModeEventL( &iInterface, aNotifyData );
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CIMPSConnUiConnectionModeNotifierImp::MediateNotifyError()
       
   271 // From MGenObserverNotifyMediator
       
   272 // Forwards any error propagated from MediateNotifyL() to
       
   273 // observer handle error.
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CIMPSConnUiConnectionModeNotifierImp::MediateNotifyError(
       
   277     MIMPSConnUiConnectionModeObserver& aObserverToNotify,
       
   278     TInt aLeaveError )
       
   279     {
       
   280     aObserverToNotify.HandleConnectionModeEventNotifyError( &iInterface, aLeaveError );
       
   281     }
       
   282 
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CIMPSConnUiConnectionModeNotifierImp::MediateError()
       
   286 // From MGenObserverNotifyMediator
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CIMPSConnUiConnectionModeNotifierImp::MediateError(
       
   290     MIMPSConnUiConnectionModeObserver& aObserverToNotify,
       
   291     TInt aError )
       
   292     {
       
   293     aObserverToNotify.HandleConnectionModeEventNotifyError( &iInterface, aError );
       
   294     }
       
   295 
       
   296 
       
   297 //  End of File
       
   298