2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Declaration of classes CActiveApDb
15 * and MActiveApDbObserver.
23 // Deprecation warning
24 #warning This header file has been deprecated. Will be removed in one of the next SDK releases.
29 #include <ApEngineVer.h>
32 // Enum for DATABASE_TYPE field
33 // Will be deprecated in 7.0
34 enum TCommDbDatabaseType
36 EUnspecified = 0, // not specifying which type it is - any type of
37 // database can be opened with this parameter
44 const TInt KErrActiveApDbObserverNotFound = -500;
46 // FORWARD DECLARATION
47 class CActiveApDbNotifier;
52 * Mixin protocol for handling events from a CCommsDatabase.
53 * Events are related to database changes and availability.
55 class MActiveApDbObserver
58 enum TEvent /// Events reported to the database observer.
60 EDbChanged, ///< Database has changed.
61 EDbClosing, ///< Database is about to close.
62 EDbAvailable ///< Database is available again.(E.g. after unlock)
65 public: // new methods
68 * Derived classes should implement this method, and act accordingly
70 * @param anEvent Database-related event.
74 IMPORT_C virtual void HandleApDbEventL( TEvent anEvent ) = 0;
79 * This class manages and guards database integrity
80 * by handling all events that are related to the database. These events
81 * may originate from the system (Shutdown, Backup/Restore) and from the
82 * database itself. The events are transformed into a simple protocol,
83 * defined by MActiveApDbObserver.
84 * Expects an active scheduler to be installed and running.
86 NONSHARABLE_CLASS( CActiveApDb ) : public CBase
89 public: // Constructors and destructor
91 * Two-phased constructor. Leaves on failure.
92 * @param aType The desired type of the CCommsDatabase object.
93 * Defaults to EDatabaseTypeIAP.
94 * @return The constructed CActiveApDb object.
98 IMPORT_C static CActiveApDb* NewL
99 ( TCommDbDatabaseType aType = EDatabaseTypeIAP );
108 IMPORT_C virtual ~CActiveApDb();
110 protected: // Constructors
113 * Second phase constructor. Leaves on failure.
114 * @param aType The desired type of the CCommsDatabase object.
119 public: // new methods
121 * Adds an observer to the list of observers to be notified
122 * about the DB events.
123 * Also automatically starts observation and notification.
124 * The order of notification will be exactly the order of registration.
125 * @param anObserver Observer to be notified about database-related
130 IMPORT_C void AddObserverL( MActiveApDbObserver* anObserver );
134 * Removes an observer. If not added, silently ignores.
135 * @param anObserver The observer.
139 IMPORT_C void RemoveObserver( MActiveApDbObserver* anObserver );
143 * Returns the CCommsDatabase.
144 * Required because we can not derive from CCommsDatabase...
148 IMPORT_C CCommsDatabase* Database();
152 * Handle events from the database (DBMS).
153 * The order of notification is the order of registration.
154 * @param anEvent Event generated by DBMS. Values from
155 * RDbNotifier::TEvent, or KErrCancel.
157 void HandleDbEventL( TInt anEvent );
161 * Notify all observers about an event.
162 * @param anEvent Event to be sent to observers.
164 void NotifyObserversL( MActiveApDbObserver::TEvent anEvent );
166 friend class CActiveApDbNotifier;
170 * Default constructor. Can not leave.
175 enum TState /// State of the finite state machine.
177 EClosed, ///< Closed and idle.
178 EReady, ///< Open and ready for use.
179 EWaitClose, ///< Closed, waiting for other users to close.
180 EWaitBackupRestore, ///< Closed, waiting Backup/Restore to finish.
181 EWaitShutdown ///< Closed, waiting to die.
185 CArrayPtrFlat<MActiveApDbObserver>* iObservers; ///< Observers.
187 CCommsDatabase* iDb; // Creates & owns it !
188 // CommsDb has its own RDbNotifier...
189 TState iState; ///< Current state of the database.
190 CActiveApDbNotifier* iDbNotifier;