emailservices/emailserver/src/fsnotificationhandlermgrimpl.cpp
branchRCL_3
changeset 80 726fba06891a
parent 64 3533d4323edc
equal deleted inserted replaced
73:c8382f7b54ef 80:726fba06891a
    36 //</cmail>
    36 //</cmail>
    37 
    37 
    38 
    38 
    39 static const TInt64 KMegaByte = 1048576;
    39 static const TInt64 KMegaByte = 1048576;
    40 
    40 
       
    41 _LIT( KFSMailServerPanic, "FS mail server" );
       
    42 const TInt KUndefinedState = 1;
       
    43 const TTimeIntervalMicroSeconds32 KDelay = 5000000; // 5 seconds 
       
    44 
    41 // ======== MEMBER FUNCTIONS ========
    45 // ======== MEMBER FUNCTIONS ========
    42 
    46 
    43 
    47 
    44 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    45 //
    49 //
    62 void CFSNotificationHandlerMgr::ConstructL()
    66 void CFSNotificationHandlerMgr::ConstructL()
    63     {
    67     {
    64     FUNC_LOG;
    68     FUNC_LOG;
    65     // Performs the time consuming initialization asynchronously in RunL, in order
    69     // Performs the time consuming initialization asynchronously in RunL, in order
    66     // to let the process startup finish quicker
    70     // to let the process startup finish quicker
       
    71     iTimer.CreateLocal();
       
    72     SetActive();
       
    73     iState = EPrepareInitialization;
    67     TRequestStatus* status = &iStatus;
    74     TRequestStatus* status = &iStatus;
    68     User::RequestComplete(status, KErrNone);
    75     User::RequestComplete( status, KErrNone );
    69     SetActive();
       
    70     }
    76     }
    71 
    77 
    72 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
    73 // Finishes the initialization
    79 // Finishes the initialization
    74 // ---------------------------------------------------------------------------
    80 // ---------------------------------------------------------------------------
    75 //
    81 //
    76 void CFSNotificationHandlerMgr::RunL()
    82 void CFSNotificationHandlerMgr::RunL()
    77     {
    83     {
    78     FUNC_LOG;
    84     FUNC_LOG;
    79     // Create mail client
    85     
    80     iMailClient = CFSMailClient::NewL();
    86     TBool goToNextState = ETrue;
    81     if ( iMailClient == NULL )
    87     
    82         {
    88     switch( iState )
    83         User::Leave( KErrNoMemory );
    89         {
    84         }
    90         case EPrepareInitialization:
    85 
    91             {
    86     // Once mail client is created ok, disk space needs to be checked
    92             // Create mail client
    87     // and cleaned if necessary
    93             iMailClient = CFSMailClient::NewL();
    88     CleanTempFilesIfNeededL();
    94             if ( iMailClient == NULL )
    89 
    95                 {
    90     //<cmail>
    96                 User::Leave( KErrNoMemory );
    91     // Notification handlers are created next.
    97                 }
    92     // Notice that if a handler cannot be created it does not mean
    98             // Once mail client is created ok, disk space needs to be checked
    93     // that the construction of the manager would be stopped. This
    99             // and cleaned if necessary
    94     // approach is chosen so that if something goes wrong with
   100             CleanTempFilesIfNeededL();
    95     // construction of a handler it can safely leave and get
   101             break;
    96     // destroyed but does not interfere other handlers.
   102             }
    97 
   103         case EInitializeMailIconHandler:
    98     CreateAndStoreHandlerL( KMailIconHandlerUid );
   104             {
    99 
   105             CreateAndStoreHandlerL( KMailIconHandlerUid );
   100     CreateAndStoreHandlerL( KLedHandlerUid );
   106             break;
   101 
   107             }
       
   108         case EInitializeLedHandler:
       
   109             {
       
   110             CreateAndStoreHandlerL( KLedHandlerUid );
       
   111             break;
       
   112             }
   102 #ifndef __WINS__
   113 #ifndef __WINS__
   103     CreateAndStoreHandlerL( KSoundHandlerUid );
   114         case ESoundHandler:
   104     // Earlier RefreshData() was called for the soundhandler
   115             {
   105     // object after creation, but as it does not do anything
   116             // Earlier RefreshData() was called for the soundhandler
   106     // it is not called anymore.
   117             // object after creation, but as it does not do anything
       
   118             // it is not called anymore.
       
   119             CreateAndStoreHandlerL( KSoundHandlerUid );
       
   120             break;
       
   121             }
   107 #endif
   122 #endif
   108 
   123         case EInitializeMtmHandler:
   109     CreateAndStoreHandlerL( KMtmHandlerUid );
   124             {
   110 
   125             CreateAndStoreHandlerL( KMtmHandlerUid );
   111     CreateAndStoreHandlerL( KOutofMemoryHandlerUid );
   126             break;
   112 
   127             }      
   113     CreateAndStoreHandlerL( KAuthenticationHandlerUid );
   128         case EInitializeOutofMemoryHandler:
   114 
   129             {
   115     CreateAndStoreHandlerL( KMessageQueryHandlerUid );
   130             CreateAndStoreHandlerL( KOutofMemoryHandlerUid );
   116 
   131             break;
   117     CreateAndStoreHandlerL( KCMailCpsHandlerUid );
   132             }
   118     //</cmail>
   133         case EInitializeAuthenticationHandler:
   119 
   134             {
   120     StartObservingL();
   135             CreateAndStoreHandlerL( KAuthenticationHandlerUid );
       
   136             break;
       
   137             }
       
   138         case EInitializeMessageQueryHandlerUid:
       
   139             {
       
   140             CreateAndStoreHandlerL( KMessageQueryHandlerUid );
       
   141             break;
       
   142             }
       
   143         case EWaitForPluginsReady:
       
   144             {
       
   145             if ( !iMailClient->AreAllPluginsLoaded() )
       
   146                 {
       
   147                 goToNextState = EFalse;
       
   148                 SetActive();
       
   149                 iTimer.After( iStatus, KDelay );
       
   150                 }
       
   151             break;
       
   152             }
       
   153         case EInitializeCMailCpsHandlerUid:
       
   154             {
       
   155             CreateAndStoreHandlerL( KCMailCpsHandlerUid );
       
   156             break;
       
   157             }
       
   158         case EFinish:
       
   159             {
       
   160             StartObservingL();
       
   161             goToNextState = EFalse;
       
   162             break;
       
   163             }
       
   164         default:
       
   165             {
       
   166             User::Panic( KFSMailServerPanic, KUndefinedState );
       
   167             break;
       
   168             }
       
   169         }
       
   170     if ( goToNextState )
       
   171         {
       
   172         iState = TState( iState + 1 );
       
   173         SetActive();
       
   174         TRequestStatus* status = &iStatus; 
       
   175         User::RequestComplete( status, KErrNone );
       
   176         }
   121     }
   177     }
   122 
   178 
   123 // ---------------------------------------------------------------------------
   179 // ---------------------------------------------------------------------------
   124 //
   180 //
   125 // ---------------------------------------------------------------------------
   181 // ---------------------------------------------------------------------------
   194         iMailClient->Close();
   250         iMailClient->Close();
   195         iMailClient = NULL;
   251         iMailClient = NULL;
   196         }
   252         }
   197 
   253 
   198     iAppUi = NULL;
   254     iAppUi = NULL;
       
   255     
       
   256     iTimer.Close();
   199 
   257 
   200     // Finished using ECom
   258     // Finished using ECom
   201     // ECom used at least in CFSMailHSUpdateHandler
   259     // ECom used at least in CFSMailHSUpdateHandler
   202     REComSession::FinalClose();
   260     REComSession::FinalClose();
   203     }
   261     }