calendarui/server/CalenSvr/inc/CalenSvrDBManager.h
changeset 0 f979ecb2b13e
child 5 42814f902fe6
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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         };
       
    57 
       
    58 public: // Construction and destruction
       
    59     static CCalenSvrDBManager* NewL();
       
    60     virtual ~CCalenSvrDBManager();
       
    61 
       
    62 public: // New methods 
       
    63     /** Called by Calendar server, when booting is ready 
       
    64      */
       
    65     void BootReadyL();
       
    66 
       
    67     /** Register new user for Calendar database. Database is kept 
       
    68      * open as long as there are users. 
       
    69      */
       
    70     void RegisterUserL(MCalenDBUser& aUser); 
       
    71 
       
    72     /** Unregister user from Calendar database. When there are no more 
       
    73      * users, CCalenSvrDBManager sets small delay and closes database
       
    74      * session. 
       
    75      */
       
    76     void UnregisterUserL(MCalenDBUser& aUser);
       
    77 
       
    78 public: // From PropertyObserver
       
    79     void HandlePropertyChange(const TUid& aCategory, const TUint& aKey, const TInt& aValue);
       
    80    
       
    81 public: // from   MCalProgressCallBack
       
    82     void Completed(TInt aError);
       
    83     TBool NotifyProgress();
       
    84     void Progress(TInt aPercentageCompleted);
       
    85 
       
    86 private:
       
    87     void OpenDatabaseCompletedL();
       
    88 
       
    89 private: // Timer handling
       
    90     void StartClosingTimer();
       
    91     void ClosingTimeOut();
       
    92     static TInt ClosingTimeOutCallback(TAny* aAny);
       
    93 
       
    94 private: // Restore handling
       
    95     void RestoreStarted();
       
    96     void RestoreFinishedL();
       
    97 
       
    98 private: // construction 
       
    99     CCalenSvrDBManager();
       
   100     void ConstructL();
       
   101 
       
   102 private: // new functions
       
   103     /**
       
   104      *
       
   105      **/
       
   106     void NotifyUsersL();
       
   107 
       
   108 private:
       
   109     enum TState 
       
   110     {
       
   111         EStateBooting, // FIXME: if unregister works correctly this is not needed
       
   112         EStateOpeningDB,
       
   113         EStateDBOpen,
       
   114         EStateGoingToCloseDB, 
       
   115         EStateDBClosed,
       
   116         EStateRestoring
       
   117     };
       
   118 
       
   119     TState iState;
       
   120     RPointerArray<MCalenDBUser> iUsers;
       
   121     CPeriodic* iClosingTimer;
       
   122 
       
   123     CCalenGlobalData* iGlobalData;
       
   124 
       
   125     // ?one_line_short_description_of_data
       
   126     CPropertyObserver* iBackupObserver;
       
   127 
       
   128     };
       
   129 
       
   130 #endif // CALENSVRDBMANAGER_H
       
   131 
       
   132 
       
   133 // End of File