profilesservices/ProfileEngine/WrapperSrc/CProEngNotifyHandlerImpl.cpp
changeset 0 8c5d936e5675
child 8 f62c3a3d66b8
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Implementation of CProEngNotifyHandlerImpl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CProEngNotifyHandlerImpl.h"
       
    22 #include    <MProEngProfileActivationObserver.h>
       
    23 #include    <MProEngActiveProfileObserver.h>
       
    24 #include    <MProEngProfileObserver.h>
       
    25 #include    <MProEngProfileNameArrayObserver.h>
       
    26 #include    "ProfileEngineConstants.h"
       
    27 #include    "ProfileEnginePrivateCRKeys.h"
       
    28 #include    "ProfileEnginePrivatePSKeys.h"
       
    29 #include    "CProEngProfileActivationDelegate.h"
       
    30 #include    "CProEngActiveProfileDelegate.h"
       
    31 #include    "CProEngProfileNameArrayEventDelegate.h"
       
    32 #include    "CProEngProfileEventDelegate.h"
       
    33 
       
    34 
       
    35 // ============================= LOCAL FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CompareDelegates
       
    39 //
       
    40 // Comparison function to check that RPointerArray does not already
       
    41 // contain the given delegate for profile events
       
    42 // -----------------------------------------------------------------------------
       
    43 
       
    44 TBool CompareDelegates( const CProEngProfileEventDelegate& aDelegate1,
       
    45                         const CProEngProfileEventDelegate& aDelegate2 )
       
    46     {
       
    47     return ( aDelegate1.ProfileId() == aDelegate2.ProfileId() );
       
    48     }
       
    49  
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CProEngNotifyHandlerImpl::CProEngNotifyHandlerImpl
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CProEngNotifyHandlerImpl::CProEngNotifyHandlerImpl()
       
    57     {
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CProEngNotifyHandlerImpl::NewL
       
    62 // Two-phased constructor.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CProEngNotifyHandlerImpl* CProEngNotifyHandlerImpl::NewL()
       
    66     {
       
    67     return new ( ELeave ) CProEngNotifyHandlerImpl();
       
    68     }
       
    69 
       
    70 // Destructor
       
    71 CProEngNotifyHandlerImpl::~CProEngNotifyHandlerImpl()
       
    72     {
       
    73     CancelAll();
       
    74     //iProfileEventDelegates.ResetAndDestroy();
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CProEngNotifyHandlerImpl::RequestProfileActivationNotifications
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 TInt CProEngNotifyHandlerImpl::RequestProfileActivationNotificationsL(
       
    82         MProEngProfileActivationObserver& aObserver )
       
    83     {
       
    84     if( iActiveIdEventDelegate )
       
    85         {
       
    86         return KErrAlreadyExists;
       
    87         }
       
    88 
       
    89     iActiveIdEventDelegate =
       
    90             CProEngProfileActivationDelegate::NewL( aObserver );
       
    91 
       
    92     // make the actual request to the Publish & Subscribe:
       
    93     TInt result( iActiveIdEventDelegate->RequestNotification() );
       
    94     if( result != KErrNone )
       
    95         {
       
    96         delete iActiveIdEventDelegate;
       
    97         iActiveIdEventDelegate = NULL;
       
    98         }
       
    99 
       
   100     return result;
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CProEngNotifyHandlerImpl::RequestActiveProfileNotificationsL
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CProEngNotifyHandlerImpl::RequestActiveProfileNotificationsL(
       
   108         MProEngActiveProfileObserver& aObserver )
       
   109     {
       
   110     if( iActiveProfileEventDelegate )
       
   111         {
       
   112         return KErrAlreadyExists;
       
   113         }
       
   114 
       
   115     iActiveProfileEventDelegate = new ( ELeave ) CProEngActiveProfileDelegate(
       
   116             aObserver );
       
   117 
       
   118     // make the actual request to the Publish & Subscribe:
       
   119     TInt result( iActiveProfileEventDelegate->RequestNotification() );
       
   120     if( result != KErrNone )
       
   121         {
       
   122         delete iActiveProfileEventDelegate;
       
   123         iActiveProfileEventDelegate = NULL;
       
   124         }
       
   125 
       
   126     return result;
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CProEngNotifyHandlerImpl::RequestProfileNotificationsL
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 TInt CProEngNotifyHandlerImpl::RequestProfileNotificationsL(
       
   134         MProEngProfileObserver& aObserver,
       
   135         TInt aProfileId )
       
   136     {
       
   137     if( ( aProfileId < 0 ) || // profile id cannot be negative
       
   138         // or greater than the last dynamic profile id
       
   139         ( aProfileId > KProfileBaseDynamicProfileId +
       
   140                        KProfilesMaxNumberOfDynamicProfiles ) )
       
   141         {
       
   142         return KErrNotFound;
       
   143         }
       
   144 
       
   145     CProEngProfileEventDelegate* delegate = CProEngProfileEventDelegate::NewL(
       
   146             aProfileId, aObserver );
       
   147             
       
   148     TIdentityRelation<CProEngProfileEventDelegate> relation( CompareDelegates );
       
   149     if( iProfileEventDelegates.Find( delegate, relation ) != KErrNotFound )
       
   150         { // an observer has already been registered for the given profile id
       
   151         delete delegate;
       
   152         return KErrAlreadyExists;
       
   153         }
       
   154 
       
   155     TInt result( iProfileEventDelegates.Append( delegate ) );
       
   156     if( result == KErrNone )
       
   157         {
       
   158         // make the actual request to the Central Repository:
       
   159         result = delegate->RequestNotification();
       
   160         }
       
   161 
       
   162     if( result != KErrNone )
       
   163         {
       
   164         iProfileEventDelegates.Remove( iProfileEventDelegates.Count() - 1 );
       
   165         delete delegate;
       
   166         }
       
   167 
       
   168     return result;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CProEngNotifyHandlerImpl::RequestProfileNameArrayNotificationsL
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 TInt CProEngNotifyHandlerImpl::RequestProfileNameArrayNotificationsL(
       
   176         MProEngProfileNameArrayObserver& aObserver )
       
   177     {
       
   178     if( iNameArrayEventDelegate )
       
   179         {
       
   180         return KErrAlreadyExists;
       
   181         }
       
   182 
       
   183     iNameArrayEventDelegate = CProEngProfileNameArrayEventDelegate::NewL(
       
   184             aObserver );
       
   185             
       
   186     // make the actual request to the Central Repository:
       
   187     TInt result( iNameArrayEventDelegate->RequestNotification() );
       
   188     if( result != KErrNone )
       
   189         {
       
   190         delete iNameArrayEventDelegate;
       
   191         iNameArrayEventDelegate = NULL;
       
   192         }
       
   193 
       
   194     return result;
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CProEngNotifyHandlerImpl::CancelProfileActivationNotifications
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CProEngNotifyHandlerImpl::CancelProfileActivationNotifications()
       
   202     {
       
   203     if( iActiveIdEventDelegate )
       
   204         {
       
   205         iActiveIdEventDelegate->Cancel();
       
   206         delete iActiveIdEventDelegate;
       
   207         iActiveIdEventDelegate = NULL;
       
   208         }
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CProEngNotifyHandlerImpl::CancelActiveProfileNotifications
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CProEngNotifyHandlerImpl::CancelActiveProfileNotifications()
       
   216     {
       
   217     if( iActiveProfileEventDelegate )
       
   218         {
       
   219         iActiveProfileEventDelegate->Cancel();
       
   220         delete iActiveProfileEventDelegate;
       
   221         iActiveProfileEventDelegate = NULL;
       
   222         }
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CProEngNotifyHandlerImpl::CancelProfileNotifications
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CProEngNotifyHandlerImpl::CancelProfileNotifications( TInt aProfileId )
       
   230     {
       
   231     TInt count( iProfileEventDelegates.Count() );
       
   232     for( TInt i( 0 ); i<count; ++i )
       
   233         {
       
   234         if( iProfileEventDelegates[i]->ProfileId() == aProfileId )
       
   235             {
       
   236             CProEngProfileEventDelegate* delegate = iProfileEventDelegates[i];
       
   237             iProfileEventDelegates.Remove( i );
       
   238             delegate->Cancel();
       
   239             delete delegate;
       
   240             break;
       
   241             }
       
   242         }
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CProEngNotifyHandlerImpl::CancelProfileNameArrayNotifications
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 void CProEngNotifyHandlerImpl::CancelProfileNameArrayNotifications()
       
   250     {
       
   251     if( iNameArrayEventDelegate )
       
   252         {
       
   253         iNameArrayEventDelegate->Cancel();
       
   254         delete iNameArrayEventDelegate;
       
   255         iNameArrayEventDelegate = NULL;
       
   256         }
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CProEngNotifyHandlerImpl::CancelAll
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CProEngNotifyHandlerImpl::CancelAll()
       
   264     {
       
   265     CancelProfileActivationNotifications();
       
   266     CancelActiveProfileNotifications();
       
   267     CancelProfileNameArrayNotifications();
       
   268     TInt count = iProfileEventDelegates.Count();
       
   269     for( TInt i( 0 ); i<count; ++i )
       
   270         {
       
   271         iProfileEventDelegates[i]->Cancel();
       
   272         }
       
   273     iProfileEventDelegates.ResetAndDestroy();
       
   274     }
       
   275 
       
   276 //  End of File
       
   277