wvuing/IMPSConnectionUI/NotifySrc/CIMPSConnUiPresEventNotifierImpBase.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:  Event notifier implementation base
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32std.h>
       
    20 #include <mimpsconnuipresenceeventobserverng.h>
       
    21 #include <CPEngNWSessionSlotID2.h>
       
    22 #include "CIMPSConnUiPresEventNotifierImpBase.h"
       
    23 #include "CnUiEventMapper.h"
       
    24 #include "CnUiPanics.h"
       
    25 #include "IMPSCommonUiDebugPrint.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 // Destructor
       
    29 CIMPSConnUiPresEventNotifierImpBase::~CIMPSConnUiPresEventNotifierImpBase()
       
    30     {
       
    31     iObserverArray.Close();
       
    32     delete iSessionSlotID;
       
    33     }
       
    34 
       
    35 
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 //
       
    39 CIMPSConnUiPresEventNotifierImpBase::CIMPSConnUiPresEventNotifierImpBase(
       
    40     CIMPSConnUiPresEventNotifier& aInterface )
       
    41         : iInterface( aInterface ),
       
    42         iStarted( EFalse ),
       
    43         iDying( EFalse )
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CIMPSConnUiPresEventNotifierImpBase::StartL()
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CIMPSConnUiPresEventNotifierImpBase::StartL()
       
    53     {
       
    54     //make here sanity checks to encapsulate
       
    55     //real notifiers behaviour
       
    56     if ( iDying )
       
    57         {
       
    58         //if dying, the notifier restart is silently ignored
       
    59         //notifier is evidently going down anyway
       
    60         return;
       
    61         }
       
    62 
       
    63     if ( iStarted )
       
    64         {
       
    65         User::Leave( KErrInUse );
       
    66         }
       
    67 
       
    68     if ( iObserverArray.Count() == 0 )
       
    69         {
       
    70         User::Leave( KErrNotReady );
       
    71         }
       
    72 
       
    73     RArray< TPEngNWSessionSlotEvent > pecEvents;
       
    74     CleanupClosePushL( pecEvents );
       
    75     CnUiEventMapper::AddAllKnownPecEventsL( pecEvents );
       
    76     TRAPD( err, DoStartL( pecEvents.Array() ) );
       
    77     if ( err != KErrNone )
       
    78         {
       
    79         DoStop();
       
    80         User::Leave( err );
       
    81         }
       
    82 
       
    83     CleanupStack::PopAndDestroy(); //pecEvents
       
    84     iStarted = ETrue;
       
    85     }
       
    86 
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CIMPSConnUiPresEventNotifierImpBase::Stop()
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CIMPSConnUiPresEventNotifierImpBase::Stop()
       
    93     {
       
    94     StopAndNotifyObserversFromError( KErrCancel );
       
    95     }
       
    96 
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CIMPSConnUiPresEventNotifierImpBase::Dying()
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CIMPSConnUiPresEventNotifierImpBase::Dying()
       
   103     {
       
   104     iDying = ETrue;
       
   105     if ( iStarted )
       
   106         {
       
   107         iStarted = EFalse;
       
   108         DoStop();
       
   109         }
       
   110     }
       
   111 
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CIMPSConnUiPresEventNotifierImpBase::AddObserverL()
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CIMPSConnUiPresEventNotifierImpBase::AddObserverL(
       
   118     MIMPSConnUiPresenceEventObserver* aObserver )
       
   119     {
       
   120     __ASSERT_ALWAYS( aObserver,
       
   121                      CnUiPanicOrLeaveL( EIMPSConn_NULLPtr,
       
   122                                         KErrArgument ) );
       
   123 
       
   124     iObserverArray.AddObserverL( aObserver );
       
   125     }
       
   126 
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CIMPSConnUiPresEventNotifierImpBase::RemoveObserver()
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TInt CIMPSConnUiPresEventNotifierImpBase::RemoveObserver(
       
   133     MIMPSConnUiPresenceEventObserver* aObserver )
       
   134     {
       
   135     return iObserverArray.RemoveObserver( aObserver );
       
   136     }
       
   137 
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CIMPSConnUiPresEventNotifierImpBase::NotifyObserversFromEvent()
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CIMPSConnUiPresEventNotifierImpBase::NotifyObserversFromEvent(
       
   144     const CPEngNWSessionSlotID2& aSessionSlotID,
       
   145     TIMPSConnectionClient aClient,
       
   146     TIMPSPresenceServiceEvent aEvent )
       
   147     {
       
   148     //if not running, don't notify the clients
       
   149     if ( !iStarted )
       
   150         {
       
   151         return;
       
   152         }
       
   153 
       
   154     CPEngNWSessionSlotID2* tempSlot = NULL;
       
   155     if ( &aSessionSlotID )
       
   156         {
       
   157         TRAPD( err, tempSlot = aSessionSlotID.CloneL() );
       
   158         if ( err )
       
   159             {
       
   160             return;
       
   161             }
       
   162         delete iSessionSlotID;
       
   163         iSessionSlotID = tempSlot;
       
   164         iClient = aClient;
       
   165         }
       
   166 
       
   167     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSConnUiPresEventNotifierImpBase::NotifyObserversFromEvent() [%d]" ), aEvent );
       
   168     iObserverArray.NotifyObservers( *this, aEvent );
       
   169     }
       
   170 
       
   171 
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CIMPSConnUiPresEventNotifierImpBase::StopAndNotifyObserversFromError()
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CIMPSConnUiPresEventNotifierImpBase::StopAndNotifyObserversFromError( TInt aError )
       
   178     {
       
   179     //if not running, don't notify the clients
       
   180     if ( !iStarted )
       
   181         {
       
   182         return;
       
   183         }
       
   184 
       
   185     //Error propagating from the underlying implementation
       
   186     //causes the notifier to stop. However, flag & actual
       
   187     //stopping must be done before notifying the clients
       
   188     //since some client may wan't to restart this notifier
       
   189     //in the notification callback...
       
   190 
       
   191     //Also the state must be set to "not started" before
       
   192     //actual stopping  since the stopping of some event
       
   193     //sources cause further KErrCancel events
       
   194     //(==>those will be filtered on !started check on above.)
       
   195     iStarted = EFalse;
       
   196     DoStop();
       
   197 
       
   198     //do the notify
       
   199     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSConnUiPresEventNotifierImpBase::StopAndNotifyObserversFromError() [%d]" ), aError );
       
   200     iObserverArray.NotifyObserversFromError( *this, aError );
       
   201     }
       
   202 
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CIMPSConnUiPresEventNotifierImpBase::MediateNotifyL()
       
   206 // From MGenObserverNotifyMediator
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CIMPSConnUiPresEventNotifierImpBase::MediateNotifyL(
       
   210     MIMPSConnUiPresenceEventObserver& aObserverToNotify,
       
   211     TIMPSPresenceServiceEvent& aNotifyData )
       
   212 
       
   213     {
       
   214     aObserverToNotify.HandlePresenceEventL( &iInterface, *iSessionSlotID, iClient, aNotifyData );
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CIMPSConnUiPresEventNotifierImpBase::MediateNotifyError()
       
   219 // From MGenObserverNotifyMediator
       
   220 // Forwards any error propagated from MediateNotifyL() to
       
   221 // observer handle error.
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CIMPSConnUiPresEventNotifierImpBase::MediateNotifyError(
       
   225     MIMPSConnUiPresenceEventObserver& aObserverToNotify,
       
   226     TInt aLeaveError )
       
   227     {
       
   228     aObserverToNotify.HandlePresenceEventNotifyError( &iInterface, aLeaveError );
       
   229     }
       
   230 
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CIMPSConnUiPresEventNotifierImpBase::MediateError()
       
   234 // From MGenObserverNotifyMediator
       
   235 // Forwards error to observer.
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 void CIMPSConnUiPresEventNotifierImpBase::MediateError(
       
   239     MIMPSConnUiPresenceEventObserver& aObserverToNotify,
       
   240     TInt aError )
       
   241     {
       
   242     aObserverToNotify.HandlePresenceEventNotifyError( &iInterface, aError );
       
   243     }
       
   244 
       
   245 //  End of File
       
   246