ipsservices/ipssosaoplugin/src/IpsSosAOMboxLogic.cpp
changeset 56 15bc1d5d6267
parent 43 99bcbff212ad
child 57 ae34e1715e21
equal deleted inserted replaced
51:d845db10c0d4 56:15bc1d5d6267
   317     
   317     
   318     if ( event == EEventStart && iState == EStateError && 
   318     if ( event == EEventStart && iState == EStateError && 
   319           ( (iIsRoaming && CanConnectIfRoamingL())||
   319           ( (iIsRoaming && CanConnectIfRoamingL())||
   320              !iIsRoaming ) )
   320              !iIsRoaming ) )
   321         {
   321         {
       
   322         NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventStart");
   322         event = EEventNop;
   323         event = EEventNop;
   323         iAgent->LoadSettingsL();
   324         iAgent->LoadSettingsL();
   324         iTimer->Cancel();
   325         iTimer->Cancel();
       
   326         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", KIpsSosAOStartDelaySeconds);
   325         iTimer->After( KIpsSosAOStartDelaySeconds );
   327         iTimer->After( KIpsSosAOStartDelaySeconds );
   326         iState = EStateWaitSyncStart;
   328         iState = EStateWaitSyncStart;
       
   329         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   327         }
   330         }
   328     
   331     
   329     while ( event != EEventNop && iState != EStateError )
   332     while ( event != EEventNop && iState != EStateError )
   330         {
   333         {
   331         switch ( event )
   334         switch ( event )
   332             {
   335             {
   333             case EEventTimerFired:
   336             case EEventTimerFired:
       
   337                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventTimerFired");
   334                 event = HandleTimerFiredL();
   338                 event = HandleTimerFiredL();
   335               break;
   339               break;
   336             case EEventStartSync:
   340             case EEventStartSync:
       
   341                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventStartSync");
   337                 if ( iState == EStateWaitSyncStart )
   342                 if ( iState == EStateWaitSyncStart )
   338                     {         
   343                     {         
   339                     iError = KErrNone;
   344                     iError = KErrNone;
   340                     iAgent->StartSyncL();
   345                     iAgent->StartSyncL();
   341                     iState = EStateSyncOngoing;
   346                     iState = EStateSyncOngoing;
       
   347                     NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateSyncOngoing");
   342                     }
   348                     }
   343                 else if ( iState == EStateIdleAndWaitCommands )
   349                 else if ( iState == EStateIdleAndWaitCommands )
   344                     {
   350                     {
   345                     // start sync command in idle state is currently 
   351                     // start sync command in idle state is currently 
   346                     // received when emn arrives, checking scheduling 
   352                     // received when emn arrives, checking scheduling 
   358                             scheduler->SecondsToNextMark( seconds );
   364                             scheduler->SecondsToNextMark( seconds );
   359                     
   365                     
   360 					//</QMail>
   366 					//</QMail>
   361                     if ( type == EAOCConnectAfter )
   367                     if ( type == EAOCConnectAfter )
   362                         {
   368                         {
       
   369                         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   363                         iState = EStateWaitSyncStart;
   370                         iState = EStateWaitSyncStart;
       
   371                         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", seconds);
   364                         iTimer->After( seconds );
   372                         iTimer->After( seconds );
   365                         
   373                         
   366                         SetEmnReceivedFlagL( ETrue );
   374                         SetEmnReceivedFlagL( ETrue );
   367                         }
   375                         }
   368                     else
   376                     else
   369                         {
   377                         {
   370                         iError = KErrNone;
   378                         iError = KErrNone;
   371                         iAgent->StartSyncL();
   379                         iAgent->StartSyncL();
   372                         iState = EStateSyncOngoing;
   380                         iState = EStateSyncOngoing;
       
   381                         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateSyncOngoing");
   373                         }
   382                         }
   374 					//<QMail>
   383 					//<QMail>
   375                     CleanupStack::PopAndDestroy( 2, settings );
   384                     CleanupStack::PopAndDestroy( 2, settings );
   376 					//</QMail>
   385 					//</QMail>
   377                     }
   386                     }
   378                 // ignore in other states
   387                 // ignore in other states
   379                 event = EEventNop;
   388                 event = EEventNop;
   380                 break;
   389                 break;
   381             case EEventFetchMessages:
   390             case EEventFetchMessages:
       
   391                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventFetchMessages");
   382                 if ( ( iState == EStateWaitSyncStart || 
   392                 if ( ( iState == EStateWaitSyncStart || 
   383                        iState == EStateIdleAndWaitCommands ) &&
   393                        iState == EStateIdleAndWaitCommands ) &&
   384                         iFetchMsgArray.Count() > 0 )
   394                         iFetchMsgArray.Count() > 0 )
   385                     {
   395                     {
   386                     iError = KErrNone;
   396                     iError = KErrNone;
   387                     iAgent->StartFetchMessagesL( iFetchMsgArray );
   397                     iAgent->StartFetchMessagesL( iFetchMsgArray );
   388                     iFetchMsgArray.Reset();
   398                     iFetchMsgArray.Reset();
       
   399                     NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateFetchOngoing");
   389                     iState = EStateFetchOngoing;
   400                     iState = EStateFetchOngoing;
   390                     }
   401                     }
   391                 else 
   402                 else 
   392                     {
   403                     {
   393                     // ignore event in other states
   404                     // ignore event in other states
   394                     iFetchMsgArray.Reset();
   405                     iFetchMsgArray.Reset();
   395                     }
   406                     }
   396                 event = EEventNop;
   407                 event = EEventNop;
   397                 break;
   408                 break;
   398             case EEventOperationCompleted:
   409             case EEventOperationCompleted:
       
   410                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventOperationCompleted");
   399                 event = HandleOperationCompletionL();
   411                 event = HandleOperationCompletionL();
   400                 break;
   412                 break;
   401             case EEventSuspendOperations:
   413             case EEventSuspendOperations:
       
   414                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventSuspendOperations");
   402                 SuspendOperations();
   415                 SuspendOperations();
   403                 iState = EStateSuspended;
   416                 iState = EStateSuspended;
   404                 event = EEventNop;
   417                 event = EEventNop;
   405                 break;
   418                 break;
   406             case EEventContinueOperations:
   419             case EEventContinueOperations:
       
   420                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventContinueOperations");
   407                 if ( iState == EStateSuspended )
   421                 if ( iState == EStateSuspended )
   408                     {
   422                     {
       
   423                     INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", KIpsSosAOContinueWaitTime);
   409                     iTimer->After( KIpsSosAOContinueWaitTime );
   424                     iTimer->After( KIpsSosAOContinueWaitTime );
   410                     }
   425                     }
   411                 else
   426                 else
   412                     {
   427                     {
   413                     event = EEventNop;
   428                     event = EEventNop;
   414                     }
   429                     }
   415                 // ignore if in other states
   430                 // ignore if in other states
   416                 break;
   431                 break;
   417             case EEventStopAndRemoveOps:
   432             case EEventStopAndRemoveOps:
       
   433                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventStopAndRemoveOps");
   418                 // notify deletion
   434                 // notify deletion
   419                 iAgent->CancelAllAndDisconnectL();
   435                 iAgent->CancelAllAndDisconnectL();
   420                 iTimer->Cancel();
   436                 iTimer->Cancel();
       
   437                 NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateError");
   421                 iState = EStateError;
   438                 iState = EStateError;
   422                 event = EEventNop;
   439                 event = EEventNop;
   423                 break;
   440                 break;
   424             case EEventStart:
   441             case EEventStart:
   425             default:
   442             default:
   473     if ( iState == EStateSuspended &&
   490     if ( iState == EStateSuspended &&
   474         ( agentState == CIpsSosAOBaseAgent::EStateConnectAndSyncOnHold || 
   491         ( agentState == CIpsSosAOBaseAgent::EStateConnectAndSyncOnHold || 
   475           agentState == CIpsSosAOBaseAgent::EStatePopulateOnHold ) )
   492           agentState == CIpsSosAOBaseAgent::EStatePopulateOnHold ) )
   476         {
   493         {
   477         iAgent->ContinueHoldOperations();
   494         iAgent->ContinueHoldOperations();
       
   495         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateSyncOngoing");
   478         iState = EStateSyncOngoing;
   496         iState = EStateSyncOngoing;
   479         }
   497         }
   480     else if ( iState == EStateSuspended && 
   498     else if ( iState == EStateSuspended && 
   481             agentState == CIpsSosAOBaseAgent::EStateFetchOnHold )
   499             agentState == CIpsSosAOBaseAgent::EStateFetchOnHold )
   482         {
   500         {
   483         iAgent->ContinueHoldOperations();
   501         iAgent->ContinueHoldOperations();
       
   502         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateFetchOngoing");
   484         iState = EStateFetchOngoing;
   503         iState = EStateFetchOngoing;
   485         }
   504         }
   486     else
   505     else
   487         {
   506         {
   488         event = CheckSchedulingAndSwitchStateL();
   507         event = CheckSchedulingAndSwitchStateL();
   504              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
   523              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
   505     CleanupStack::PushL(settings);
   524     CleanupStack::PushL(settings);
   506 	//</Qmail>     
   525 	//</Qmail>     
   507     if ( iState == EStateSyncOngoing )
   526     if ( iState == EStateSyncOngoing )
   508         {
   527         {
       
   528         INFO_1("CIpsSosAOMBoxLogic: operation completed error: %d", iError);
       
   529         bool doSaveSyncTime = EFalse;
   509         if ( !( iError == KErrNone || iError == KErrCancel ) )
   530         if ( !( iError == KErrNone || iError == KErrCancel ) )
   510             {
   531             {
   511             ++iErrorCounter;
   532             ++iErrorCounter;
   512             }
   533             }
   513         else
   534         else
   514             {
   535             {
       
   536             if (iError == KErrNone)
       
   537                 {
       
   538                 doSaveSyncTime = ETrue;
       
   539                 }
   515             iError = KErrNone;
   540             iError = KErrNone;
   516             iErrorCounter = 0;
   541             iErrorCounter = 0;
   517             }
   542             }
   518         
   543         
   519         if ( iError != KErrNone && 
   544         if ( iError != KErrNone && 
   527             // emn not swithced of if its going to be "always on" in
   552             // emn not swithced of if its going to be "always on" in
   528             // future
   553             // future
   529             
   554             
   530             settings->SetEmnReceivedButNotSyncedFlag( EFalse );
   555             settings->SetEmnReceivedButNotSyncedFlag( EFalse );
   531             //</QMail>
   556             //</QMail>
       
   557             NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateError");
   532             iState = EStateError;
   558             iState = EStateError;
   533             iErrorCounter = 0;
   559             iErrorCounter = 0;
   534             }
   560             }
   535         else if ( iError != KErrNone && 
   561         else if ( iError != KErrNone && 
   536                 iErrorCounter < KIpsSosAOMaxReTryTimes )
   562                 iErrorCounter < KIpsSosAOMaxReTryTimes )
   540             IpsServices::TIpsSetDataAoStates state = 
   566             IpsServices::TIpsSetDataAoStates state = 
   541                     settings->AlwaysOnlineState();
   567                     settings->AlwaysOnlineState();
   542             
   568             
   543             if ( state == IpsServices::EMailAoOff )
   569             if ( state == IpsServices::EMailAoOff )
   544                 {
   570                 {
       
   571                 NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateIdleAndWaitCommands");
   545                 iState = EStateIdleAndWaitCommands;
   572                 iState = EStateIdleAndWaitCommands;
   546                 }
   573                 }
   547             else
   574             else
   548                 {
   575                 {
   549                 if( !iTimer->IsActive() )
   576                 if( !iTimer->IsActive() )
   550                     {
   577                     {
       
   578                     INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", KIpsSosAOReTryInterval);
   551                     iTimer->After( KIpsSosAOReTryInterval );
   579                     iTimer->After( KIpsSosAOReTryInterval );
   552                     }
   580                     }
       
   581                 NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   553                 iState = EStateWaitSyncStart;
   582                 iState = EStateWaitSyncStart;
   554                 }
   583                 }
   555 
   584 
   556 			//</QMail>
   585 			//</QMail>
   557             }
   586             }
   565             }
   594             }
   566         else
   595         else
   567             {
   596             {
   568             // no errors
   597             // no errors
   569             // update successfull sync time to settings
   598             // update successfull sync time to settings
   570             SaveSuccessfulSyncTimeL();
   599             if (doSaveSyncTime)
       
   600                 {
       
   601                 SaveSuccessfulSyncTimeL();
       
   602                 }
   571             // and adjust timer to sync interval
   603             // and adjust timer to sync interval
   572             CalculateToNextIntervalL();
   604             CalculateToNextIntervalL();
   573             }
   605             }
   574         }
   606         }
   575     else if ( iState == EStateFetchOngoing )
   607     else if ( iState == EStateFetchOngoing )
   576         {
   608         {
   577         iError = KErrNone;
   609         iError = KErrNone;
   578         if ( iTimer->IsActive() )
   610         if ( iTimer->IsActive() )
   579             {
   611             {
       
   612             NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   580             iState = EStateWaitSyncStart;
   613             iState = EStateWaitSyncStart;
   581             }
   614             }
   582         else
   615         else
   583             {
   616             {
   584             event = CheckSchedulingAndSwitchStateL();          
   617             event = CheckSchedulingAndSwitchStateL();          
   598     FUNC_LOG;
   631     FUNC_LOG;
   599     if ( iState == EStateSyncOngoing || iState == EStateFetchOngoing )
   632     if ( iState == EStateSyncOngoing || iState == EStateFetchOngoing )
   600         {
   633         {
   601         iAgent->HoldOperations();
   634         iAgent->HoldOperations();
   602         }
   635         }
       
   636     NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateSuspended");
   603     iState = EStateSuspended;
   637     iState = EStateSuspended;
   604     // set suspend watchdog, if clien not continue this
   638     // set suspend watchdog, if clien not continue this
   605     // ensure ao logic to continue
   639     // ensure ao logic to continue
   606     if ( !iTimer->IsActive() )
   640     if ( !iTimer->IsActive() )
   607         {
   641         {
       
   642         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", KIpsSosAOSuspendWatchdogTime);
   608         iTimer->After( KIpsSosAOSuspendWatchdogTime );
   643         iTimer->After( KIpsSosAOSuspendWatchdogTime );
   609         }
   644         }
   610     }
   645     }
   611 
   646 
   612 // ----------------------------------------------------------------------------
   647 // ----------------------------------------------------------------------------
   647 CIpsSosAOMBoxLogic::TMBoxLogicEvent 
   682 CIpsSosAOMBoxLogic::TMBoxLogicEvent 
   648     CIpsSosAOMBoxLogic::CheckSchedulingAndSwitchStateL()
   683     CIpsSosAOMBoxLogic::CheckSchedulingAndSwitchStateL()
   649     {
   684     {
   650 	//<Qmail>
   685 	//<Qmail>
   651     FUNC_LOG;
   686     FUNC_LOG;
   652      iTimer->Cancel();
   687     iTimer->Cancel();
   653     TMBoxLogicEvent event = EEventNop;
   688     TMBoxLogicEvent event = EEventNop;
   654     TTimeIntervalSeconds secondsToConnect = CalculateScheduledSyncTimeL();
   689     TTimeIntervalSeconds secondsToConnect = CalculateScheduledSyncTimeL();
   655     
   690     
   656     CIpsSosAOSettingsHandler* settings = 
   691     CIpsSosAOSettingsHandler* settings = 
   657              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
   692              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
   677             now.SecondsFrom( info.iLastSuccessfulUpdate, secsFromLastSync );
   712             now.SecondsFrom( info.iLastSuccessfulUpdate, secsFromLastSync );
   678             if ( (secsFromLastSync.Int() > 0) && ( 
   713             if ( (secsFromLastSync.Int() > 0) && ( 
   679                     secsFromLastSync.Int() < interval ) )
   714                     secsFromLastSync.Int() < interval ) )
   680                 {
   715                 {
   681                 // adjust timer to correct sync time
   716                 // adjust timer to correct sync time
   682                 iTimer->After(interval - secsFromLastSync.Int());        
   717                 TInt syncAfter = interval - secsFromLastSync.Int();
       
   718                 INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", syncAfter);
       
   719                 iTimer->After(syncAfter); 
       
   720                 NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   683                 iState = EStateWaitSyncStart;
   721                 iState = EStateWaitSyncStart;
   684                 }
   722                 }
   685             else
   723             else
   686                 {
   724                 {
   687                 event = EEventStartSync;
   725                 event = EEventStartSync;
   690         
   728         
   691         }
   729         }
   692     else if ( secondsToConnect.Int() == KErrNotFound )
   730     else if ( secondsToConnect.Int() == KErrNotFound )
   693         {
   731         {
   694         // means that ao is not on (but emn is)
   732         // means that ao is not on (but emn is)
       
   733         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateIdleAndWaitCommands");
   695         iState = EStateIdleAndWaitCommands;
   734         iState = EStateIdleAndWaitCommands;
   696       
   735       
   697         if ( settings->EmnReceivedButNotSyncedFlag() )
   736         if ( settings->EmnReceivedButNotSyncedFlag() )
   698             {
   737             {
   699             // got emn when logic was stopped
   738             // got emn when logic was stopped
   700             event = EEventStartSync;
   739             event = EEventStartSync;
   701             }
   740             }
   702         }
   741         }
   703     else
   742     else
   704         {
   743         {
       
   744         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", secondsToConnect);
   705         iTimer->After( secondsToConnect );
   745         iTimer->After( secondsToConnect );
       
   746         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   706         iState = EStateWaitSyncStart;
   747         iState = EStateWaitSyncStart;
   707         
   748         
   708 
   749 
   709         }
   750         }
   710     CleanupStack::PopAndDestroy(settings);
   751     CleanupStack::PopAndDestroy(settings);
   732 		
   773 		
   733 		//<QMail>
   774 		//<QMail>
   734         CIpsSosAOSettingsHandler* settings = 
   775         CIpsSosAOSettingsHandler* settings = 
   735                  CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
   776                  CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
   736         CleanupStack::PushL(settings);
   777         CleanupStack::PushL(settings);
   737         iTimer->After( 
   778         TInt secs = settings->InboxRefreshTime() * KAOSecondsInMinute;
   738                 settings->InboxRefreshTime() * KAOSecondsInMinute );
   779         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", secs);
       
   780         iTimer->After(secs);
   739         CleanupStack::PopAndDestroy(settings);
   781         CleanupStack::PopAndDestroy(settings);
   740 	   //</QMail>
   782 	   //</QMail>
       
   783         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   741         iState = EStateWaitSyncStart;
   784         iState = EStateWaitSyncStart;
   742         }
   785         }
   743     else if ( interval.Int() > 0 )
   786     else if ( interval.Int() > 0 )
   744         {
   787         {
       
   788         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", interval);
   745         iTimer->After( interval );
   789         iTimer->After( interval );
       
   790         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   746         iState = EStateWaitSyncStart;
   791         iState = EStateWaitSyncStart;
   747         }
   792         }
   748     else 
   793     else 
   749         {
   794         {
       
   795         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateIdleAndWaitCommands");
   750         iState = EStateIdleAndWaitCommands;
   796         iState = EStateIdleAndWaitCommands;
   751         }
   797         }
   752     
   798     
   753     }
   799     }
   754 
   800