phonebookengines_old/contactsmodel/tsrc/CContactDbEventQueue.h
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // CContactDbEventQueue Test module
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __CContactDbEventQueue_H__
       
    19 #define __CContactDbEventQueue_H__
       
    20 
       
    21 // INCLUDES
       
    22 #include <cntdef.h>
       
    23 #include <cntdbobs.h>
       
    24 #include "cfixedqueue.h"
       
    25 
       
    26 
       
    27 // CLASS DECLARATION
       
    28 class CContactChangeNotifier;
       
    29 class CContactDatabase;
       
    30 
       
    31 
       
    32 /**
       
    33  * Contact Engine event queue class.
       
    34  */ 
       
    35 class CContactDbEventQueue : 
       
    36         public CTimer, public MContactDbObserver
       
    37     {
       
    38     public:
       
    39         /**
       
    40          * Creates a new event queue.
       
    41          * @param aDb   contact DB to listen for events.
       
    42          * @param aMaxQueueSize maximum size of event queue.
       
    43          * @return a new instance of this class.
       
    44          */
       
    45         static CContactDbEventQueue* NewL
       
    46             (CContactDatabase* aDb=NULL, TInt aMaxQueueSize=128);
       
    47         ~CContactDbEventQueue();
       
    48 
       
    49         /**
       
    50          * Waits for an event from the database.
       
    51          * @param aTimeOut  max time to wait for an event.
       
    52          * @param aEvent    the received event, undefined if this function returns false.
       
    53          * @return true if an event was received, false if timeout expired first.
       
    54          */
       
    55         TBool ListenForEvent
       
    56             (TTimeIntervalSeconds aTimeOut, 
       
    57             TContactDbObserverEvent& aEvent);
       
    58             
       
    59          /**
       
    60          * Pops Events from the event queue.  Required to avoid filling the queue.
       
    61          */    
       
    62         void PopEvent();           
       
    63 
       
    64          /**
       
    65          * Pops All Events from the event queue. Required to avoid queue overflow.
       
    66          */    
       
    67 		void Clear();
       
    68 
       
    69         /**
       
    70          * Removes all previously arrived events from the queue.
       
    71          */
       
    72         inline void Flush()
       
    73             {
       
    74             iQueue.Reset();
       
    75             }
       
    76 
       
    77     protected: // From MContactDbObserver.
       
    78 	    void HandleDatabaseEventL(TContactDbObserverEvent aEvent);
       
    79 
       
    80     private:  
       
    81         void RunL(); // from CTimer
       
    82         CContactDbEventQueue();
       
    83         void ConstructL(CContactDatabase* aDb, TInt aMaxQueueSize);
       
    84 
       
    85     private:  
       
    86         // Own: the notifier for attaching to CContactDatabase
       
    87         CContactChangeNotifier* iNotifier;
       
    88         // Own: event queue array
       
    89         CFixedQueue<TContactDbObserverEvent> iQueue;
       
    90     };
       
    91 
       
    92 #endif  // __CContactDbEventQueue_H__
       
    93 
       
    94 
       
    95 
       
    96 
       
    97