calendarui/server/CalenSvr/inc/CalenSvrDBManager.h
branchRCL_3
changeset 66 bd7edf625bdd
child 67 1539a383d7b6
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
       
     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:   This class manages Calendar Server's connection to Agenda Server
       
    15 *                and Calendar database. 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CALENSVRDBMANAGER_H
       
    22 #define CALENSVRDBMANAGER_H
       
    23 
       
    24 // INCLUDES
       
    25 #include "PropertyObserver.h"
       
    26 #include <calprogresscallback.h>    // MCalProgressCallBack
       
    27 
       
    28 #include <e32base.h>
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CCalenGlobalData;
       
    32 
       
    33 /**
       
    34  * CCalenSvrDBManager manages Calendar Server's connection to Agenda Server
       
    35  * and Calendar database. It optimizes behavior so that Agenda Server
       
    36  * is not opened and closed unnecessarily often in short period of time, as
       
    37  * opening can be costly operation as it requires
       
    38  * 1) Starting Agenda Server process
       
    39  * 2) Opening database and creating indexes. Indexes are stored in
       
    40  *   Agenda Server, and reused by all clients of same database. 
       
    41  * 
       
    42  * It uses Calendar Engine to do actual opening. It owns Calendar Engine.
       
    43  */
       
    44 NONSHARABLE_CLASS( CCalenSvrDBManager ) : 
       
    45     public CBase, 
       
    46     public MPropertyChangeHandler,
       
    47     public MCalProgressCallBack
       
    48 
       
    49     {
       
    50 public:
       
    51     NONSHARABLE_CLASS( MCalenDBUser )
       
    52         {
       
    53     public:
       
    54         virtual void DatabaseOpened() = 0;
       
    55         virtual void DatabaseTemporarilyClosed() = 0;
       
    56     	virtual void HandleError() = 0;  
       
    57         };
       
    58 
       
    59 public: // Construction and destruction
       
    60     static CCalenSvrDBManager* NewL();
       
    61     virtual ~CCalenSvrDBManager();
       
    62 
       
    63 public: // New methods 
       
    64     /** Called by Calendar server, when booting is ready 
       
    65      */
       
    66     void BootReadyL();
       
    67 
       
    68     /** Register new user for Calendar database. Database is kept 
       
    69      * open as long as there are users. 
       
    70      */
       
    71     void RegisterUserL(MCalenDBUser& aUser); 
       
    72 
       
    73     /** Unregister user from Calendar database. When there are no more 
       
    74      * users, CCalenSvrDBManager sets small delay and closes database
       
    75      * session. 
       
    76      */
       
    77     void UnregisterUserL(MCalenDBUser& aUser);
       
    78 
       
    79 public: // From PropertyObserver
       
    80     void HandlePropertyChange(const TUid& aCategory, const TUint& aKey, const TInt& aValue);
       
    81    
       
    82 public: // from   MCalProgressCallBack
       
    83     void Completed(TInt aError);
       
    84     TBool NotifyProgress();
       
    85     void Progress(TInt aPercentageCompleted);
       
    86 
       
    87 private:
       
    88     void OpenDatabaseCompletedL(TInt aErrorVal = KErrNone);
       
    89 
       
    90 private: // Timer handling
       
    91     void StartClosingTimer();
       
    92     void ClosingTimeOut();
       
    93     static TInt ClosingTimeOutCallback(TAny* aAny);
       
    94 
       
    95 private: // Restore handling
       
    96     void RestoreStarted();
       
    97     void RestoreFinishedL();
       
    98 
       
    99 private: // construction 
       
   100     CCalenSvrDBManager();
       
   101     void ConstructL();
       
   102 
       
   103 private: // new functions
       
   104     /**
       
   105      *
       
   106      **/
       
   107     void NotifyUsersL(TInt aErrorVal = KErrNone);
       
   108 
       
   109 private:
       
   110     enum TState 
       
   111     {
       
   112         EStateBooting, // FIXME: if unregister works correctly this is not needed
       
   113         EStateOpeningDB,
       
   114         EStateDBOpen,
       
   115         EStateGoingToCloseDB, 
       
   116         EStateDBClosed,
       
   117         EStateRestoring
       
   118     };
       
   119 
       
   120     TState iState;
       
   121     RPointerArray<MCalenDBUser> iUsers;
       
   122     CPeriodic* iClosingTimer;
       
   123 
       
   124     CCalenGlobalData* iGlobalData;
       
   125 
       
   126     // ?one_line_short_description_of_data
       
   127     CPropertyObserver* iBackupObserver;
       
   128 
       
   129     };
       
   130 
       
   131 #endif // CALENSVRDBMANAGER_H
       
   132 
       
   133 
       
   134 // End of File