cmmanager/cmmgr/cmmserver/src/cmmlistenermanager.cpp
changeset 20 9c97ad6591ae
child 44 a0c4ceac30d0
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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:
       
    15 * Manages all CommsDat table specific CenRep listeners.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "cmmcache.h"
       
    21 #include "cmmlistenermanager.h"
       
    22 
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "cmmlistenermanagerTraces.h"
       
    26 #endif
       
    27 
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Two phased construction.
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CCmmListenerManager* CCmmListenerManager::NewL( CCmmCache* aCache )
       
    34     {
       
    35     OstTraceFunctionEntry0( CCMMLISTENERMANAGER_NEWL_ENTRY );
       
    36 
       
    37     CCmmListenerManager* self = CCmmListenerManager::NewLC( aCache );
       
    38     CleanupStack::Pop( self );
       
    39 
       
    40     OstTraceFunctionExit0( CCMMLISTENERMANAGER_NEWL_EXIT );
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Two phased construction.
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CCmmListenerManager* CCmmListenerManager::NewLC( CCmmCache* aCache )
       
    49     {
       
    50     OstTraceFunctionEntry0( CCMMLISTENERMANAGER_NEWLC_ENTRY );
       
    51 
       
    52     CCmmListenerManager* self = new( ELeave ) CCmmListenerManager( aCache );
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55 
       
    56     OstTraceFunctionExit0( CCMMLISTENERMANAGER_NEWLC_EXIT );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // Destructor.
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CCmmListenerManager::~CCmmListenerManager()
       
    65     {
       
    66     OstTraceFunctionEntry0( CCMMLISTENERMANAGER_CCMMLISTENERMANAGER_ENTRY );
       
    67 
       
    68     // The destructor of each listener will cancel their own active request.
       
    69     iListeners.ResetAndDestroy();
       
    70 
       
    71     OstTraceFunctionExit0( CCMMLISTENERMANAGER_CCMMLISTENERMANAGER_EXIT );
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Constructor.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CCmmListenerManager::CCmmListenerManager( CCmmCache* aCache ) : iCache( aCache )
       
    79     {
       
    80     OstTraceFunctionEntry0( DUP1_CCMMLISTENERMANAGER_CCMMLISTENERMANAGER_ENTRY );
       
    81     OstTraceFunctionExit0( DUP1_CCMMLISTENERMANAGER_CCMMLISTENERMANAGER_EXIT );
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Second phase constructor.
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CCmmListenerManager::ConstructL()
       
    89     {
       
    90     OstTraceFunctionEntry0( CCMMLISTENERMANAGER_CONSTRUCTL_ENTRY );
       
    91 
       
    92     // Create the basic set of listeners, start them if necessary and store them in iListeners-array.
       
    93 
       
    94     OstTraceFunctionExit0( CCMMLISTENERMANAGER_CONSTRUCTL_EXIT );
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Adds a new listener to monitor for changes in the given database table.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CCmmListenerManager::AddListenerL( TUint32 aIdentifier )
       
   102     {
       
   103     OstTraceFunctionEntry0( CCMMLISTENERMANAGER_ADDLISTENERL_ENTRY );
       
   104 
       
   105     TBool duplicateFound( EFalse );
       
   106     for ( TInt i = 0; i < iListeners.Count(); i++ )
       
   107         {
       
   108         if ( iListeners[i]->GetTableId() == aIdentifier )
       
   109             {
       
   110             duplicateFound = ETrue;
       
   111             break;
       
   112             }
       
   113         }
       
   114 
       
   115     if ( !duplicateFound )
       
   116         {
       
   117         CCmmDbChangeListener* dbChangeListener = CCmmDbChangeListener::NewLC( this, aIdentifier );
       
   118         iListeners.AppendL( dbChangeListener );
       
   119         CleanupStack::Pop( dbChangeListener );
       
   120         TInt err = dbChangeListener->Start();
       
   121         if ( err )
       
   122             {
       
   123             iCache->DbChangeError( aIdentifier );
       
   124             }
       
   125         }
       
   126 
       
   127     OstTraceFunctionExit0( CCMMLISTENERMANAGER_ADDLISTENERL_EXIT );
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // Stops and deletes the listener monitoring the given database table.
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 TInt CCmmListenerManager::RemoveListener( TUint32 aIdentifier )
       
   135     {
       
   136     OstTraceFunctionEntry0( CCMMLISTENERMANAGER_REMOVELISTENER_ENTRY );
       
   137 
       
   138     TInt res( KErrNotFound );
       
   139     for ( TInt i = 0; i < iListeners.Count(); i++ )
       
   140         {
       
   141         if ( iListeners[i]->GetTableId() == aIdentifier )
       
   142             {
       
   143             delete iListeners[i];
       
   144             iListeners.Remove( i );
       
   145             res = KErrNone;
       
   146             break;
       
   147             }
       
   148         }
       
   149 
       
   150     OstTraceFunctionExit0( CCMMLISTENERMANAGER_REMOVELISTENER_EXIT );
       
   151     return res;
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // Tells the listener manager that a change has been detected in the given
       
   156 // database table.
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CCmmListenerManager::DbChangeDetected( TUint32 aIdentifier )
       
   160     {
       
   161     OstTraceFunctionEntry0( CCMMLISTENERMANAGER_DBCHANGEDETECTED_ENTRY );
       
   162 
       
   163     iCache->DbChangeDetected( aIdentifier );
       
   164 
       
   165     OstTraceFunctionExit0( CCMMLISTENERMANAGER_DBCHANGEDETECTED_EXIT );
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // Tells the listener manager that an error has been encountered while
       
   170 // listening the given database table. Change notifications will not be working
       
   171 // for this database table.
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CCmmListenerManager::DbChangeError( TUint32 aIdentifier )
       
   175     {
       
   176     OstTraceFunctionEntry0( CCMMLISTENERMANAGER_DBCHANGEERROR_ENTRY );
       
   177 
       
   178     iCache->DbChangeError( aIdentifier );
       
   179 
       
   180     OstTraceFunctionExit0( CCMMLISTENERMANAGER_DBCHANGEERROR_EXIT );
       
   181     }
       
   182 
       
   183 // End of file