PECengine/PresenceManager2/SrcReactAuth/CPEngReactAuthNotifierImp.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:  Notifier API to listen presence reactive authorization changes.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngNWSessionSlotID2Imp.h"
       
    20 #include "CPEngReactAuthNotifierImp.h"
       
    21 #include "CPEngNWSessionSlotEventEntry.h"
       
    22 #include "GenObserverNotifyMediators.h"
       
    23 
       
    24 #include "CPEngNWSessionSlotStorageProxy.h"
       
    25 #include "PEngListLibraryFactory.h"
       
    26 #include "MPEngAuthorizationManager.h"
       
    27 #include "TPEngGenArrayAdapter.h"
       
    28 #include "MPEngAuthorizationRequest.h"
       
    29 #include <CPEngReactAuthNotifier.h>
       
    30 #include <MPEngReactAuthObserver.h>
       
    31 
       
    32 
       
    33 
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CPEngReactAuthNotifierImp::NewL()
       
    40 // Two-phased constructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CPEngReactAuthNotifierImp* CPEngReactAuthNotifierImp::NewL(
       
    44     CPEngReactAuthNotifier& aInterface,
       
    45     TInt aPriority,
       
    46     const CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    47     {
       
    48     CPEngReactAuthNotifierImp* self =
       
    49         new ( ELeave ) CPEngReactAuthNotifierImp( aInterface, aPriority );
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL( aNWSessionSlotID );
       
    52     CleanupStack::Pop( self );
       
    53     return self;
       
    54     }
       
    55 
       
    56 
       
    57 
       
    58 // Destructor
       
    59 CPEngReactAuthNotifierImp::~CPEngReactAuthNotifierImp()
       
    60     {
       
    61     iDying = ETrue;
       
    62     Stop();
       
    63     if ( iAuthManager )
       
    64         {
       
    65         iAuthManager->Close();
       
    66         }
       
    67 
       
    68     iObsArray.Close();
       
    69     delete iUsedSlot;
       
    70     }
       
    71 
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CPEngReactAuthNotifierImp::CPEngReactAuthNotifierImp
       
    76 // C++ default constructor can NOT contain any code, that
       
    77 // might leave.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CPEngReactAuthNotifierImp::CPEngReactAuthNotifierImp(
       
    81     CPEngReactAuthNotifier& aInterface,
       
    82     TInt aPriority )
       
    83         : iInterface( aInterface ),
       
    84         iCActivePriority( aPriority )
       
    85     {
       
    86     }
       
    87 
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CPEngReactAuthNotifierImp::ConstructL()
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CPEngReactAuthNotifierImp::ConstructL(
       
    95     const CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    96     {
       
    97     iUsedSlot = CPEngNWSessionSlotStorageProxy::NewL( aNWSessionSlotID );
       
    98     iAuthManager = PEngListLibraryFactory::AuthorizationManagerL( iUsedSlot->BaseId() );
       
    99     }
       
   100 
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CPEngReactAuthNotifierImp::Start()
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 TInt CPEngReactAuthNotifierImp::Start( TInt /*aOptions*/ )
       
   107     {
       
   108     //sanity checks to encapsulate notifier behaviour
       
   109     if ( iDying )
       
   110         {
       
   111         //if dying, the notifier restart is silently ignored
       
   112         //because notifier is evidently shutting down
       
   113         return KErrNone;
       
   114         }
       
   115 
       
   116     if ( iStarted )
       
   117         {
       
   118         return KErrInUse;
       
   119         }
       
   120 
       
   121 
       
   122     TRAPD( err,
       
   123         {
       
   124         //Register for reactive authorization events
       
   125         iAuthManager->RegisterAuthorizationObserverL( *this );
       
   126         } );
       
   127 
       
   128     if ( err == KErrNone )
       
   129         {
       
   130         iStarted = ETrue;
       
   131         }
       
   132 
       
   133     else
       
   134         {
       
   135         //Cancel the reactive authorization notification requests
       
   136         iAuthManager->UnRegisterAuthorizationObserver( *this );
       
   137         }
       
   138 
       
   139     return err;
       
   140     }
       
   141 
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CPEngReactAuthNotifierImp::Stop()
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CPEngReactAuthNotifierImp::Stop()
       
   148     {
       
   149     if ( !iStarted )
       
   150         {
       
   151         return;
       
   152         }
       
   153 
       
   154     iAuthManager->UnRegisterAuthorizationObserver( *this );
       
   155     iStarted = EFalse;
       
   156     }
       
   157 
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CPEngReactAuthNotifierImp::IsActive()
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 TBool CPEngReactAuthNotifierImp::IsActive() const
       
   164     {
       
   165     return iStarted;
       
   166     }
       
   167 
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CPEngReactAuthNotifierImp::AddObserver()
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TInt CPEngReactAuthNotifierImp::AddObserver(
       
   174     MPEngReactAuthObserver& aObserver )
       
   175 
       
   176     {
       
   177     return iObsArray.AddObserver( &aObserver );
       
   178     }
       
   179 
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CPEngReactAuthNotifierImp::RemoveObserver()
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 TInt CPEngReactAuthNotifierImp::RemoveObserver(
       
   186     MPEngReactAuthObserver& aObserver )
       
   187 
       
   188     {
       
   189     return iObsArray.RemoveObserver( &aObserver );
       
   190     }
       
   191 
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CPEngReactAuthNotifierImp::HandleNewPendingAuthorization()
       
   195 // From MPEngAuthorizationObserver
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CPEngReactAuthNotifierImp::HandleNewPendingAuthorization(
       
   199     MPEngAuthorizationRequest& aNewPendingAuthorization )
       
   200     {
       
   201     TPEngGenArrayAdapter< MPEngAuthorizationRequest* > adapter( &aNewPendingAuthorization );
       
   202     TArray< MPEngAuthorizationRequest* > array = adapter.Array();
       
   203 
       
   204     TGenNotifyMediator2 < MPEngReactAuthObserver,
       
   205     CPEngReactAuthNotifier&,
       
   206     TArray< MPEngAuthorizationRequest* >& >
       
   207     eventMediator( &MPEngReactAuthObserver::HandlePendingAuthorizationReqL,
       
   208                    &MPEngReactAuthObserver::HandleReactAuthError,
       
   209                    iInterface,
       
   210                    array );
       
   211 
       
   212     iObsArray.NotifyObservers( eventMediator );
       
   213     }
       
   214 
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CPEngReactAuthNotifierImp::HandlerNewAuthorizationStatus()
       
   218 // From MPEngAuthorizationObserver
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void CPEngReactAuthNotifierImp::HandlerNewAuthorizationStatus(
       
   222     const MPEngAuthorizationStatus& aNewAuthorizationStatus )
       
   223     {
       
   224     TPEngGenArrayAdapter< const MPEngAuthorizationStatus* > adapter( &aNewAuthorizationStatus );
       
   225     TArray< const MPEngAuthorizationStatus* > array = adapter.Array();
       
   226 
       
   227     TGenNotifyMediator2 < MPEngReactAuthObserver,
       
   228     CPEngReactAuthNotifier&,
       
   229     TArray< const MPEngAuthorizationStatus* > >
       
   230     eventMediator( &MPEngReactAuthObserver::HandlerAuthorizationStatusL,
       
   231                    &MPEngReactAuthObserver::HandleReactAuthError,
       
   232                    iInterface,
       
   233                    array );
       
   234 
       
   235     iObsArray.NotifyObservers( eventMediator );
       
   236     }
       
   237 
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CPEngReactAuthNotifierImp::HandleAuthorizationEngineUpdate()
       
   241 // From MPEngAuthorizationObserver
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CPEngReactAuthNotifierImp::HandleAuthorizationEngineUpdate()
       
   245     {
       
   246     //Nothing to do
       
   247     }
       
   248 
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CPEngReactAuthNotifierImp::HandleAuthorizationEngineError()
       
   252 // From MPEngAuthorizationObserver
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CPEngReactAuthNotifierImp::HandleAuthorizationEngineError( TInt aError )
       
   256     {
       
   257     TPEngGenArrayAdapter< MPEngAuthorizationRequest* > adapter( NULL );
       
   258     TArray< MPEngAuthorizationRequest* > array = adapter.Array();
       
   259 
       
   260     TGenNotifyMediator2 < MPEngReactAuthObserver,
       
   261     CPEngReactAuthNotifier&,
       
   262     TArray< MPEngAuthorizationRequest* >& >
       
   263     eventMediator( &MPEngReactAuthObserver::HandlePendingAuthorizationReqL,
       
   264                    &MPEngReactAuthObserver::HandleReactAuthError,
       
   265                    iInterface,
       
   266                    array );
       
   267 
       
   268     iObsArray.NotifyErrorObservers( eventMediator, aError );
       
   269     }
       
   270 
       
   271 
       
   272 // End of File
       
   273