emailservices/emailservermonitor/inc/emailshutter.h
branchRCL_3
changeset 64 3533d4323edc
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     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 EmailShutter
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef EMAILSHUTTER_H
       
    20 #define EMAILSHUTTER_H
       
    21 
       
    22 //  Include Files
       
    23 #include <e32base.h>        // CActive
       
    24 #include <e32cmn.h>         // TUid
       
    25 #include <e32property.h>    // RProperty
       
    26 
       
    27 /////////////////////////////////////////////////////////////////////////////
       
    28 //  FORWARD DECLARATIONS
       
    29 class CEmailServerMonitor;
       
    30 
       
    31 /////////////////////////////////////////////////////////////////////////////
       
    32 //  CONSTANT DEFINITIONS
       
    33 
       
    34 // Security policies used when defining P&S keys
       
    35 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
       
    36 static _LIT_SECURITY_POLICY_C1(KPowerMgmtPolicy,ECapabilityPowerMgmt);
       
    37 static _LIT_SECURITY_POLICY_C1(KWriteDeviceDataPolicy,ECapabilityWriteDeviceData);
       
    38 
       
    39 // Value to be set in shutdown P&S key.
       
    40 const TInt KEmailShutterPsValue = 1;
       
    41 
       
    42 // Maximum waiting times used to wait processes to close themselves gracefully
       
    43 const TInt KTimeToWaitApplicationsInSeconds = 2;
       
    44 const TInt KMaxTimeToWaitClientsInSeconds = 10;
       
    45 const TInt KMaxTimeToWaitPluginsInSeconds = 10;
       
    46 const TInt KMaxTimeToWaitMsgStoreInSeconds = 5;
       
    47 
       
    48 // Cycle length (in seconds) to check if some processes are still running
       
    49 const TInt KWaitTimeCycleInSeconds = 2;
       
    50 
       
    51 // Format string used with process finder to find processes by their UID
       
    52 _LIT( KFormatProcessFinderByUid, "*[%x]*" );
       
    53 // Length of the formatted process finder string, basically length of
       
    54 // KFormatProcessFinderByUid + length of 32 bit number in hexadecimal format
       
    55 const TInt KFormatProcessFinderByUidLength = 12;
       
    56 
       
    57 
       
    58 /////////////////////////////////////////////////////////////////////////////
       
    59 // CLASS DECLARATION
       
    60 
       
    61 /**
       
    62 *  Class CEmailShutter implements functionality that shuts down all email
       
    63 *  related services when IAD/sisx update starts. Shutdown is initiated by a
       
    64 *  Publish & Subscribe event sent by email installation initiator.
       
    65 */
       
    66 NONSHARABLE_CLASS( CEmailShutter ) : public CActive
       
    67     {
       
    68     
       
    69 public: // Public construcor and destructor
       
    70     /**
       
    71      * Two-phased class constructor.
       
    72      */
       
    73     static CEmailShutter* NewL();
       
    74 
       
    75     /**
       
    76      * Two-phased class constructor, leaves created object in cleanup stack.
       
    77      */
       
    78     static CEmailShutter* NewLC();
       
    79 
       
    80     /**
       
    81      * Destructor of CEmailShutter class.
       
    82      */
       
    83     ~CEmailShutter();
       
    84         
       
    85 public: // Public member functions
       
    86     
       
    87     /**
       
    88      * Start observing shutdown event.
       
    89      */
       
    90     void StartObservingShutdownEvent();
       
    91 
       
    92     /**
       
    93      * Set P&S key after installation is done
       
    94      */
       
    95     void SetPsKeyInstallationFinished();
       
    96 
       
    97     /**
       
    98      * Restart needed services after installation is finished
       
    99      */
       
   100     void RestartServicesAfterInstallation();
       
   101 
       
   102     /**
       
   103      * Set pointer to Email Server Monitor object
       
   104      */
       
   105     void SetMonitor( CEmailServerMonitor* aMonitor );
       
   106     
       
   107 private: // Private definitions
       
   108     
       
   109     /**
       
   110      * Definition of possible killing modes when killing processes gracelessly
       
   111      */
       
   112     enum TEmailShutterKillingMode
       
   113         {
       
   114         EKillingModeAll,
       
   115         EKillingModeClients,
       
   116         EKillingModePlugins,
       
   117         EKillingModeMsgStore
       
   118         };
       
   119 
       
   120 private: // Private constructors
       
   121     /**
       
   122      * Default class constructor.
       
   123      * Only NewL can be called
       
   124      */
       
   125     CEmailShutter();
       
   126         
       
   127     /**
       
   128      * Second phase class constructor.
       
   129      */
       
   130     void ConstructL();  
       
   131     
       
   132 private: // From base class CActive
       
   133     
       
   134     void RunL();
       
   135     void DoCancel();
       
   136 
       
   137 private: // Private member functions
       
   138 
       
   139     /**
       
   140      * Highest level function to close everything in right order
       
   141      */
       
   142     void StartShutdown();
       
   143     
       
   144     /**
       
   145      * End client applications gracefully
       
   146      */
       
   147     void EndClients();
       
   148     
       
   149     /**
       
   150      * End UI applications gracefully
       
   151      */
       
   152     void EndApplicationsL();
       
   153     
       
   154     /**
       
   155      * Define and publish the P&S key to inform all related services about the
       
   156      * installation, so that they can shutdown themselves gracefully
       
   157      */
       
   158     void PublishPsKey( TInt aKey );
       
   159     
       
   160     /**
       
   161      * Closes all non-email related plugins/services
       
   162      */
       
   163     void Close3rdPartyServices();
       
   164     
       
   165     /**
       
   166      * Sends command to Always Online server to stop fs email plugin
       
   167      */
       
   168     void CloseAOPluginL();
       
   169 
       
   170     /**
       
   171      * Sends command to Always Online server to start fs email plugin
       
   172      */
       
   173     void StartAoPluginL() const;
       
   174     
       
   175     /**
       
   176      * Closes PCS (Predictive Contact Search) server
       
   177      */
       
   178     void ClosePcsServerL();
       
   179     
       
   180     /**
       
   181      * Starts PCS (Predictive Contact Search) server
       
   182      */
       
   183     void StartPcsServerL() const;
       
   184 
       
   185     /**
       
   186      * Try to find the UID given as parameter from the array given as parameter.
       
   187      * 
       
   188      * @param aSid Process UID to be searched
       
   189      * @param aArray Array from where to search
       
   190      * @param aArrayCount Item count of the aArray
       
   191      * @return ETrue if the UID can be found from the array, otherwise EFalse.
       
   192      */
       
   193     TBool FindFromArray(
       
   194             const TUid aSid,
       
   195             const TUid aArray[],
       
   196             const TInt aArrayCount );
       
   197     
       
   198     /**
       
   199      * Checks does this UID belong to the list of the services that we need to
       
   200      * close down.
       
   201      * 
       
   202      * @param aSid Process UID to check
       
   203      * @param aMode Killing mode, are we now killing clients, plugins or msg store
       
   204      * @return ETrue if this is one of the services we need to close in specified
       
   205      *         mode, otherwise EFalse
       
   206      */
       
   207     TBool NeedToKillThisProcess(
       
   208             const TUid aSid,
       
   209             const TEmailShutterKillingMode aMode );
       
   210     
       
   211     /**
       
   212      * Kills all the related processes gracelessly. This is used as a backup for
       
   213      * those processes that didn't close themselves gracefully.
       
   214      * 
       
   215      * @param aMode Process killing mode as defined in TEmailShutterKillingMode
       
   216      * @param aOnlyCheckIfRunning If EFalse (default value) when calling this 
       
   217      *           function, it kills all the processes that match the mode and
       
   218      *           are running. If ETrue when calling this function, it only
       
   219      *           checks if at least one process needs to be killed (is running).
       
   220      * @return ETrue if at least one process was killed or need to be killed.
       
   221      */
       
   222     TBool KillEmAll( const TEmailShutterKillingMode aMode = EKillingModeAll,
       
   223                      const TBool aOnlyCheckIfRunning = EFalse );
       
   224 
       
   225     /**
       
   226      * Waits in cycles and checks between cycles have all relevant processes
       
   227      * closed or do we still need to wait. Returns when either aMaxWaitTime
       
   228      * has elapsed or when all relevant processes have been shutdown.
       
   229      * 
       
   230      * @param aMaxWaitTime Maximum time to wait in seconds
       
   231      * @param aMode Killing mode, are we now killing clients, plugins or msg
       
   232      *              store. Used to determine are there still some processes
       
   233      *              that have not closed themselves.
       
   234      */
       
   235     void WaitInCycles( const TInt aMaxWaitTime,
       
   236                        const TEmailShutterKillingMode aMode );
       
   237     
       
   238     /**
       
   239      * Reads platform API process UIDs from Publish and Subscribe key to
       
   240      * internal array
       
   241      */
       
   242     void ReadPlatformApiUidsL();
       
   243     
       
   244 private: // Member variables
       
   245 
       
   246     /**
       
   247      * Publish & Subscribe property to be observed.
       
   248      */
       
   249     RProperty iInstStatusProperty;
       
   250 
       
   251     /**
       
   252      * List of UIDs of the processes that are using platform API
       
   253      */
       
   254     RArray<TUid> iPlatformApiAppsToClose;
       
   255     
       
   256     /**
       
   257      * Pointer to Email Server Monitor
       
   258      * Not owned
       
   259      */
       
   260     CEmailServerMonitor* iMonitor;
       
   261     
       
   262     };
       
   263 
       
   264 
       
   265 #endif  // EMAILSHUTTER_H
       
   266