wvuing/IMPSConnectionUI/NotifySrc/CIMPSConnUiConnectionSettingsNotifierImp.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 settings notifier implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32std.h>
       
    20 #include <impspresenceconnectionuiconstsng.h>
       
    21 #include <MIMPSConnUiConnectionSettingsObserver.h>
       
    22 #include "CIMPSConnUiConnectionSettingsNotifierImp.h"
       
    23 
       
    24 #include "CnUiPanics.h"
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CIMPSConnUiConnectionSettingsNotifierImp::NewL()
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CIMPSConnUiConnectionSettingsNotifierImp* CIMPSConnUiConnectionSettingsNotifierImp::NewL(
       
    33     CIMPSConnUiConnectionSettingsNotifier& aInterface,
       
    34     TIMPSConnectionClient aClient )
       
    35     {
       
    36     CIMPSConnUiConnectionSettingsNotifierImp* self =
       
    37         new ( ELeave ) CIMPSConnUiConnectionSettingsNotifierImp( aInterface,
       
    38                                                                  aClient );
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self ); //self
       
    42     return self;
       
    43     }
       
    44 
       
    45 
       
    46 // Destructor
       
    47 CIMPSConnUiConnectionSettingsNotifierImp::~CIMPSConnUiConnectionSettingsNotifierImp()
       
    48     {
       
    49     Dying();
       
    50     iObserverArray.Close();
       
    51     }
       
    52 
       
    53 
       
    54 // C++ default constructor can NOT contain any code, that
       
    55 // might leave.
       
    56 //
       
    57 CIMPSConnUiConnectionSettingsNotifierImp::CIMPSConnUiConnectionSettingsNotifierImp(
       
    58     CIMPSConnUiConnectionSettingsNotifier& aInterface,
       
    59     TIMPSConnectionClient aClient )
       
    60         : iInterface( aInterface ),
       
    61         iClient( aClient ),
       
    62         iStarted( EFalse ),
       
    63         iDying( EFalse )
       
    64     {
       
    65     }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CIMPSConnUiConnectionSettingsNotifierImp::ConstructL()
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CIMPSConnUiConnectionSettingsNotifierImp::ConstructL()
       
    73     {
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CIMPSConnUiConnectionSettingsNotifierImp::StartL()
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CIMPSConnUiConnectionSettingsNotifierImp::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 // CIMPSConnUiConnectionSettingsNotifierImp::Stop()
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CIMPSConnUiConnectionSettingsNotifierImp::Stop()
       
   118     {
       
   119     //notify observers from cancel
       
   120     StopAndNotifyObserversFromError( KErrCancel );
       
   121     }
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CIMPSConnUiConnectionSettingsNotifierImp::AddObserverL()
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CIMPSConnUiConnectionSettingsNotifierImp::AddObserverL(
       
   129     MIMPSConnUiConnectionSettingsObserver* aObserver )
       
   130     {
       
   131     __ASSERT_ALWAYS( aObserver,
       
   132                      CnUiPanicOrLeaveL( EIMPSConn_NULLPtr,
       
   133                                         KErrArgument ) );
       
   134 
       
   135     iObserverArray.AddObserverL( aObserver );
       
   136     }
       
   137 
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CIMPSConnUiConnectionSettingsNotifierImp::RemoveObserver()
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TInt CIMPSConnUiConnectionSettingsNotifierImp::RemoveObserver(
       
   144     MIMPSConnUiConnectionSettingsObserver* aObserver )
       
   145     {
       
   146     return iObserverArray.RemoveObserver( aObserver );
       
   147     }
       
   148 
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CIMPSConnUiConnectionSettingsNotifierImp::ConnectionSettingByCategoryL()
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TIMPSConnectionSettingsEvent
       
   155 CIMPSConnUiConnectionSettingsNotifierImp::ConnectionSettingByCategoryL(
       
   156     TIMPSConnectionSettingsEvent /*aSettingsEventCateqory*/ )
       
   157     {
       
   158     return EIMPSCSEUnknown;
       
   159     }
       
   160 
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CIMPSConnUiConnectionSettingsNotifierImp::DoStartL()
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CIMPSConnUiConnectionSettingsNotifierImp::DoStartL()
       
   167     {
       
   168     }
       
   169 
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CIMPSConnUiConnectionSettingsNotifierImp::DoStop()
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CIMPSConnUiConnectionSettingsNotifierImp::DoStop()
       
   176     {
       
   177     }
       
   178 
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CIMPSConnUiConnectionSettingsNotifierImp::Dying()
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CIMPSConnUiConnectionSettingsNotifierImp::Dying()
       
   185     {
       
   186     iDying = ETrue;
       
   187     if ( iStarted )
       
   188         {
       
   189         iStarted = EFalse;
       
   190         DoStop();
       
   191         }
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CIMPSConnUiConnectionSettingsNotifierImp::NotifyObserversFromEvent()
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CIMPSConnUiConnectionSettingsNotifierImp::NotifyObserversFromEvent(
       
   199     TIMPSConnectionSettingsEvent aEvent )
       
   200     {
       
   201     //if not running, don't notify the clients
       
   202     if ( !iStarted )
       
   203         {
       
   204         return;
       
   205         }
       
   206 
       
   207     iObserverArray.NotifyObservers( *this, aEvent );
       
   208     }
       
   209 
       
   210 
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CIMPSConnUiConnectionSettingsNotifierImp::StopAndNotifyObserversFromError()
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CIMPSConnUiConnectionSettingsNotifierImp::StopAndNotifyObserversFromError( TInt aError )
       
   217     {
       
   218     //if not running, don't notify the clients
       
   219     if ( !iStarted )
       
   220         {
       
   221         return;
       
   222         }
       
   223 
       
   224     //Error propagating from the underlying implementation
       
   225     //causes the notifier to stop. However, flag & actual
       
   226     //stopping must be done before notifying the clients
       
   227     //since some client may wan't to restart this notifier
       
   228     //in the notification callback...
       
   229 
       
   230     //Also the state must be set to "not started" before
       
   231     //actual stopping  since the stopping of some event
       
   232     //sources cause further KErrCancel events
       
   233     //(==>those will be filtered on !started check on above.)
       
   234     iStarted = EFalse;
       
   235     DoStop();
       
   236 
       
   237     //do the notify
       
   238     iObserverArray.NotifyObserversFromError( *this, aError );
       
   239     }
       
   240 
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CIMPSConnUiConnectionSettingsNotifierImp::MediateNotifyL()
       
   244 // From MGenObserverNotifyMediator
       
   245 // Forwards handling to pre-registered mediator function.
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CIMPSConnUiConnectionSettingsNotifierImp::MediateNotifyL(
       
   249     MIMPSConnUiConnectionSettingsObserver& aObserverToNotify,
       
   250     TIMPSConnectionSettingsEvent& aNotifyData )
       
   251     {
       
   252     aObserverToNotify.HandleConnectionSettingsEventL( &iInterface, aNotifyData );
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CIMPSConnUiConnectionSettingsNotifierImp::MediateNotifyError()
       
   257 // From MGenObserverNotifyMediator
       
   258 // Forwards any error propagated from MediateNotifyL() to
       
   259 // observer handle error.
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CIMPSConnUiConnectionSettingsNotifierImp::MediateNotifyError(
       
   263     MIMPSConnUiConnectionSettingsObserver& aObserverToNotify,
       
   264     TInt aLeaveError )
       
   265     {
       
   266     aObserverToNotify.HandleConnectionSettingsEventNotifyError( &iInterface, aLeaveError );
       
   267     }
       
   268 
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CIMPSConnUiConnectionSettingsNotifierImp::MediateError()
       
   272 // From MGenObserverNotifyMediator
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CIMPSConnUiConnectionSettingsNotifierImp::MediateError(
       
   276     MIMPSConnUiConnectionSettingsObserver& aObserverToNotify,
       
   277     TInt aError )
       
   278     {
       
   279     aObserverToNotify.HandleConnectionSettingsEventNotifyError( &iInterface, aError );
       
   280     }
       
   281 
       
   282 
       
   283 //  End of File
       
   284