emailservices/emailservermonitor/inc/emailservermonitor.h
changeset 0 8466d47a6819
child 12 f5907b1a1053
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2009 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 * Header definition for EmailServerMonitor
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef EMAILSERVERMONITOR_H
       
    20 #define EMAILSERVERMONITOR_H
       
    21 
       
    22 //  Include Files
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <e32cmn.h>						// TUid
       
    26 #include <apgcli.h>                     // RApaLsSession
       
    27 
       
    28 #include "emailservermonitorconst.h"
       
    29 
       
    30 /**
       
    31 *  Class CEmailServerMonitor implements functionality that starts up
       
    32 *  EmailServer and monitors it. If EmailServer crashes, then
       
    33 *  CEmailServerMonitor restarts it. CEmailServerMonitor also starts up needed
       
    34 *  email related 3rd party services after IAD update.
       
    35 */
       
    36 NONSHARABLE_CLASS( CEmailServerMonitor ) : public CActive
       
    37     {
       
    38     
       
    39 public: // Public construcor and destructor
       
    40     /**
       
    41      * Two-phased class constructor.
       
    42      */
       
    43     static CEmailServerMonitor* NewL();
       
    44 
       
    45     /**
       
    46      * Two-phased class constructor.
       
    47      */
       
    48     static CEmailServerMonitor* NewLC();
       
    49 
       
    50     /**
       
    51      * Destructor of CEmailServerMonitor class.
       
    52      */
       
    53     ~CEmailServerMonitor();
       
    54         
       
    55 public: // Public member functions
       
    56     
       
    57     /**
       
    58      * Start email server monitoring.
       
    59      */
       
    60     void Start();
       
    61 
       
    62 private: // Private constructors
       
    63     /**
       
    64      * Default class constructor.
       
    65      * Only NewL can be called
       
    66      */
       
    67     CEmailServerMonitor();
       
    68         
       
    69     /**
       
    70      * Second phase class constructor.
       
    71      */
       
    72     void ConstructL();      
       
    73 
       
    74     /**
       
    75      * Start Email Server and its monitoring
       
    76      * 
       
    77      * @return ETrue if Email Server and its monitoring started succesfully,
       
    78      *         otherwise EFalse
       
    79      */
       
    80     TBool StartEmailServerMonitoring();
       
    81     
       
    82     /**
       
    83      * Starts the actual monitoring. Assumes that Email Server is running
       
    84      * and Monitor's internal variables are set accordingly.
       
    85      */
       
    86     void DoStartMonitoring();
       
    87     
       
    88     /**
       
    89      * Start specified application, leaves if failed to start the application
       
    90      * 
       
    91      * @param aAppName Name of the application to be started
       
    92      * @param aThreadId On return, the id of the main thread started
       
    93      * @param aReqStatusForRendezvous Asynchronous status request passed to
       
    94      *                                RProcess::Rendezvous() when starting app
       
    95      */
       
    96     void StartApplicationL(
       
    97             const TDesC& aAppName,
       
    98             TThreadId& aThreadId,
       
    99             TRequestStatus& aReqStatusForRendezvous );
       
   100     
       
   101     /**
       
   102      * Handles monitoring event
       
   103      */
       
   104     void HandleMonitorEvent();
       
   105     
       
   106     /**
       
   107      * Initiates an asynchronous delayed restart
       
   108      */
       
   109     void InitiateDelayedRestart();
       
   110 
       
   111 private: // From base class CActive
       
   112     
       
   113     void RunL();
       
   114     void DoCancel();
       
   115 
       
   116 private: // Private types
       
   117     
       
   118     enum TEmailServerMonitorState
       
   119         {
       
   120         EEsmStateIdle,
       
   121         EEsmStateInitializing,
       
   122         EEsmStateMonitoring,
       
   123         EEsmStateRestarting
       
   124         };
       
   125 
       
   126 private: // Member variables
       
   127 
       
   128     // A session with the application architecture server
       
   129     RApaLsSession iApaLsSession;
       
   130     
       
   131     // A handle to email server process
       
   132     RProcess iProcess;
       
   133     
       
   134     // A timer object used to make delayed restarts
       
   135     RTimer iDelayTimer;
       
   136     
       
   137     // Internal state
       
   138     TEmailServerMonitorState iState;
       
   139     
       
   140     // Number of server restarts
       
   141     TInt iRestarts;
       
   142     
       
   143     // Time of the previous restart, used to reset restart counter if
       
   144     // server has been running succesfully long enough
       
   145     TTime iLastRestartTime;
       
   146 
       
   147     };
       
   148 
       
   149 
       
   150 #endif  // EMAILSERVERMONITOR_H