diff -r 79859ed3eea9 -r 919f36ff910f widgets/widgetapp/src/WidgetUiWindowManager.cpp --- a/widgets/widgetapp/src/WidgetUiWindowManager.cpp Tue Aug 31 16:17:46 2010 +0300 +++ b/widgets/widgetapp/src/WidgetUiWindowManager.cpp Wed Sep 01 12:28:30 2010 +0100 @@ -25,26 +25,35 @@ #include "WidgetInstallerInternalCRKeys.h" #include "SWInstWidgetUid.h" #include "widgetappdefs.rh" -#include "Browser_platform_variant.hrh" +#include "browser_platform_variant.hrh" +#include "WidgetUiPSNotifier.h" #ifdef BRDO_WRT_HS_FF #include "cpspublisher.h" #endif #include #include -#include +#include #include #include -#include -#include -#include +#include +#include #include #include "cpglobals.h" // CPS string definitions. -#include +#include #include #include -#include +#include + +#ifdef BRDO_MULTITOUCH_ENABLED_FF +#include +#include +#endif + +#ifdef BRDO_OCC_ENABLED_FF +#include +#endif // LOCAL FUNCTION PROTOTYPES TInt doDestructOOMNotifyTimer( TAny* ptr ); @@ -60,6 +69,10 @@ const TInt KOOMHarvesterNotificationTimeOut = 5000000; const TInt KOOMWidgetCloseTimeOut = 15;//Do not close the widget that was started after OOM within 15 sec +#ifdef BRDO_OCC_ENABLED_FF +const TInt KRetryConnectivityTimeout( 2*1000*1000 ); // 2 seconds +#endif + class CRequestRAM : public CActive { public: @@ -165,16 +178,34 @@ delete cenRep; } - iDialogsProvider = CBrowserDialogsProvider::NewL( NULL ); iHandler = CDocumentHandler::NewL(CEikonEnv::Static()->Process()); iDb = CActiveApDb::NewL( EDatabaseTypeIAP ); + #ifdef BRDO_OCC_ENABLED_FF + iConnection = CInternetConnectionManager::NewL( iDb->Database(), ETrue ); + #else iConnection = CInternetConnectionManager::NewL( iDb->Database(), EFalse ); + #endif + #ifdef BRDO_WRT_HS_FF iCpsPublisher = CCpsPublisher::NewL(); + iCenrepNotifyHandler = CCenrepNotifyHandler::NewL( *this ); + iNetworkListener = CWidgetUiNetworkListener::NewL( *this ); #endif - iNetworkListener = CWidgetUiNetworkListener::NewL( *this ); +#ifdef BRDO_OCC_ENABLED_FF + iConnStageNotifier = CConnectionStageNotifierWCB::NewL(); + iConnStageNotifier->SetPriority(CActive::EPriorityHigh); + iRetryConnectivity = CPeriodic::NewL(CActive::EPriorityStandard); +#endif + + //Creating observer WidgetWindowsObeserver + iWidgetNotifier = CWidgetUiPSNotifier::NewL(*this, EWidgetRegAltered); + +#ifdef BRDO_SAPINTFN_ENABLED_FF + iWidgetSapiNotifier = CWidgetUiPSNotifier::NewL(*this, ESapiPrompt); + iWidgetSapiClearNotifier = CWidgetUiPSNotifier::NewL(*this, ESapiPromptCleared); +#endif } // ----------------------------------------------------------------------------- @@ -202,9 +233,27 @@ // CWidgetUiWindowManager::~CWidgetUiWindowManager() { - iWindowList.ResetAndDestroy(); +#ifdef BRDO_WRT_HS_FF + iCenrepNotifyHandler->DoCancel(); + delete iCenrepNotifyHandler; +#endif + + iActiveFsWindow = NULL; +#ifdef BRDO_OCC_ENABLED_FF + if ( iRetryConnectivity) + { + iRetryConnectivity->Cancel(); + delete iRetryConnectivity; + iRetryConnectivity = NULL; + } +#endif + + iWindowList.ResetAndDestroy(); + +#ifdef BRDO_WRT_HS_FF delete iNetworkListener; +#endif // TODO Why there is a "Disconnect" method in the first place... // RHandleBase::Close() should be enough? @@ -216,8 +265,6 @@ iClientSession.Close(); delete iHandler; - delete iDialogsProvider; - if ( iConnection ) { TRAP_IGNORE( iConnection->StopConnectionL() ); @@ -228,6 +275,12 @@ delete iCpsPublisher; #endif delete iDb; + delete iWidgetNotifier; + +#ifdef BRDO_SAPINTFN_ENABLED_FF + delete iWidgetSapiNotifier; + delete iWidgetSapiClearNotifier; +#endif } // ----------------------------------------------------------------------------- @@ -245,12 +298,20 @@ wdgt_window->SetWindowStateMiniViewL( EMiniViewEnabled ); // TODO also other states are possible when we should react? - + // Removing . Miniview, shall remove full view as well. For blanket permissions // will be revoked for miniview - iClientSession.SetBlanketPermissionL( aUid, EBlanketUnknown ); + iClientSession.SetMiniViewL( aUid, EFalse ); +#ifdef BRDO_OCC_ENABLED_FF + wdgt_window->CancelAllDialogs(); + + if ( wdgt_window->IsDialogsLaunched() ) + { + return EFalse; + } +#endif return CloseWindow( wdgt_window ); } @@ -328,6 +389,9 @@ { // If we don't have window we know that WidgetUI has died // We must enable miniview state +#ifdef BRDO_MULTITOUCH_ENABLED_FF + GfxTransEffect::BeginFullScreen(AknTransEffect::EApplicationStart,TRect(0,0,0,0),AknTransEffect::EParameterType,AknTransEffect::GfxTransParam(TUid::Uid(KWidgetAppUid))); +#endif if( !GetWindow(aUid)) { needToNotify = EFalse; @@ -337,48 +401,106 @@ //WidgetLauncher modified to bring app to foreground GetWindow( aUid)->IncrementClickCount(); OpenOrCreateWindowL( aUid, LaunchFullscreen ); +#ifdef BRDO_MULTITOUCH_ENABLED_FF + GfxTransEffect::EndFullScreen(); +#endif } break; case WidgetOnline: { iNetworkMode = EOnlineMode; CWidgetUiWindow* wdgt_window( GetWindow( aUid ) ); -#ifdef BRDO_WRT_HS_FF - if ( wdgt_window->NetworkModeWait()->IsStarted() ) + if (wdgt_window) { - wdgt_window->NetworkModeWait()->AsyncStop(); +#ifdef BRDO_WRT_HS_FF + if ( wdgt_window->NetworkModeWait()->IsStarted() ) + { + wdgt_window->NetworkModeWait()->AsyncStop(); + } +#endif + if(wdgt_window->IsWidgetLoaded()) + wdgt_window->DetermineNetworkState(); + else + wdgt_window->NeedToNotifyNetworkState(ETrue); } -#endif - wdgt_window->DetermineNetworkState(); } break; case WidgetOffline: { iNetworkMode = EOfflineMode; CWidgetUiWindow* wdgt_window( GetWindow( aUid ) ); -#ifdef BRDO_WRT_HS_FF - if ( wdgt_window->NetworkModeWait()->IsStarted() ) + if (wdgt_window) { - wdgt_window->NetworkModeWait()->AsyncStop(); - } +#ifdef BRDO_WRT_HS_FF + if ( wdgt_window->NetworkModeWait()->IsStarted() ) + { + wdgt_window->NetworkModeWait()->AsyncStop(); + } #endif - // if no full view widgets open, then close the network connection - if ( ( !FullViewWidgetsOpen() ) && ( iConnection->Connected() ) ) - { - wdgt_window->Engine()->HandleCommandL( + if ( iConnection->Connected()) + { + for ( TInt i = 0; i < iWindowList.Count(); i++ ) + { + CWidgetUiWindow* window = iWindowList[i]; + if ( window && + (window->WidgetMiniViewState() == EPublishStart || + window->WidgetMiniViewState() == EPublishSuspend) + ) + //Send cancelFetch to all windows + TRAP_IGNORE( window->Engine()->HandleCommandL( + (TInt)TBrCtlDefs::ECommandIdBase + + (TInt)TBrCtlDefs::ECommandCancelFetch ) ); + } + TRAP_IGNORE( wdgt_window->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + - (TInt)TBrCtlDefs::ECommandDisconnect ); - iConnection->StopConnectionL(); + (TInt)TBrCtlDefs::ECommandDisconnect ) ); + } + // if no full view widgets open, then close the network connection + if ( !FullViewWidgetsOpen() && iConnection->Connected() ) + { + + iConnection->StopConnectionL(); +#ifdef BRDO_OCC_ENABLED_FF + StopConnectionObserving(); +#endif + } + if(wdgt_window->IsWidgetLoaded()) + wdgt_window->DetermineNetworkState(); + else + wdgt_window->NeedToNotifyNetworkState(ETrue); } - wdgt_window->DetermineNetworkState(); } - break; - case WidgetRestart: - { - OpenOrCreateWindowL( aUid, LaunchMiniview ); - ResumeWidgetL( aUid ); - } - break; + break; + case WidgetFullViewClose: + { + needToNotify = EFalse ; +#ifdef BRDO_OCC_ENABLED_FF + CWidgetUiWindow* window( GetWindow( aUid ) ); + if( !window ) + return; + else if ( window->IsDialogsLaunched() ) + { + iActiveFsWindow = window; + // Bring app to foreground + iAppUi.SendAppToForeground(); + if ( iActiveFsWindow->Engine()->Rect() != View()->ClientRect()) + { + iActiveFsWindow->Engine()->SetRect( View()->ClientRect() ); + } + iActiveFsWindow->SetCurrentWindow( ETrue ); + + } + else if (window->getSapiPromptCleared()) + { + Exit( EEikCmdExit, aUid ); + } + + +#else + Exit( EEikCmdExit, aUid ); +#endif + } + break; } if(needToNotify) // Widget is up and running, notify that next one can be launched @@ -606,13 +728,13 @@ TBool CWidgetUiWindowManager::RemoveFromWindowList( CWidgetUiWindow* aWidgetWindow ) { __ASSERT_DEBUG( aWidgetWindow, User::Invariant() ); - if ( iDialogsProvider->IsDialogLaunched() ) - { - return EFalse; - } - + TBool count(EFalse); + if ( iClientSession.IsWidgetInFullView ( aWidgetWindow->Uid())) { +#ifdef BRDO_WRT_HS_FF + iCpsPublisher->ClearScreenshotL(*(aWidgetWindow->WidgetBundleId()), aWidgetWindow->Uid().iUid); +#endif HideWindow( aWidgetWindow ); if (aWidgetWindow == iActiveFsWindow) iActiveFsWindow = NULL; @@ -633,16 +755,43 @@ (TInt)TBrCtlDefs::ECommandCancelFetch ) ); if ( lastOne ) { - TRAP_IGNORE( aWidgetWindow->Engine()->HandleCommandL( - (TInt)TBrCtlDefs::ECommandIdBase + - (TInt)TBrCtlDefs::ECommandDisconnect ) ); - - delete aWidgetWindow; - return ETrue; + if(aWidgetWindow->CanBeDeleted()) + { +#ifdef BRDO_OCC_ENABLED_FF + StopConnectionObserving(); +#endif + iConnection->StopConnectionL(); + delete aWidgetWindow; + return ETrue; + } } else { - delete aWidgetWindow; + if(aWidgetWindow->CanBeDeleted()) + { + for ( TInt i = 0; i < iWindowList.Count(); ++i ) + { + CWidgetUiWindow* window( iWindowList[i] ); + if(window->WidgetMiniViewState() == EMiniViewEnabled || window->WidgetMiniViewState() == EMiniViewNotEnabled) + { + count = ETrue; + break; + } + } + if(!count && iNetworkMode == EOfflineMode){ +#ifdef BRDO_OCC_ENABLED_FF + StopConnectionObserving(); +#endif + iConnection->StopConnectionL(); + } + if(!aWidgetWindow->Engine()->IsSynchRequestPending()) + delete aWidgetWindow; + else + { + //Let sync request complete and then delete + aWidgetWindow->DeleteItself(); + } + } } return EFalse; } @@ -735,13 +884,20 @@ CWidgetUiWindow* window( GetWindow( aUid ) ); if( !window ) return; - + +#ifdef BRDO_WRT_HS_FF + iCpsPublisher->ClearScreenshotL(*(GetWindow(aUid )->WidgetBundleId()), aUid.iUid); +#endif +#ifdef BRDO_MULTITOUCH_ENABLED_FF + GfxTransEffect::BeginFullScreen(AknTransEffect::EApplicationExit,TRect(0,0,0,0),AknTransEffect::EParameterType,AknTransEffect::GfxTransParam(TUid::Uid(KWidgetAppUid))); +#endif // make widgets act like separate applications by pushing to background // this way user is sent back to app shell or idle to run another widget iAppUi.SendAppToBackground(); if ( window == iActiveFsWindow ) { //make the active window NULL and also CurrentWindow as False + iActiveFsWindow->SetCurrentWindow(EFalse); iActiveFsWindow->SetIsCurrentWindow(EFalse); iActiveFsWindow = NULL; } @@ -856,6 +1012,22 @@ } else { +#ifdef BRDO_OCC_ENABLED_FF + if(iActiveFsWindow) + iActiveFsWindow->CancelAllDialogs(); +#endif + +#ifdef BRDO_WRT_HS_FF + CFbsBitmap* bitmap( new CFbsBitmap() ); + if ( bitmap && iCpsPublisher) + { + if(iActiveFsWindow) + { + TRAP_IGNORE(iActiveFsWindow->Engine()->TakeSnapshotL( *bitmap )); + TRAP_IGNORE(iCpsPublisher->PublishScreenshotL(*iActiveFsWindow->WidgetBundleId(),iActiveFsWindow->Uid().iUid, bitmap)); + } + } +#endif HideWindow( iActiveFsWindow ); } } @@ -983,6 +1155,12 @@ (wdgt_window->WidgetMiniViewState() == EPublishSuspend) ) { //Widgets on HS cannnot be active + if (iActiveFsWindow ) + { + iActiveFsWindow->Engine()->MakeVisible( EFalse ); + iActiveFsWindow->SetIsCurrentWindow( EFalse ); + iActiveFsWindow->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandAppBackground + (TInt)TBrCtlDefs::ECommandIdBase); + } iActiveFsWindow = NULL; // Publish should start only after widget is resumed. wdgt_window->SetWindowStateMiniViewL(EPublishStart); @@ -996,7 +1174,11 @@ (TInt)TBrCtlDefs::ECommandIdBase); #ifdef BRDO_WRT_HS_FF wdgt_window->Engine()->MakeVisible( EFalse ); + wdgt_window->SetIsCurrentWindow( EFalse ); wdgt_window->Engine()->SetRect( iCpsPublisher->BitmapSize()); + //When HS comes to foreground show the latest updatd content on HS. + //Relayout can sometimes happen only when widget in FullView. + wdgt_window->PublishSnapShot(); #endif } } @@ -1258,7 +1440,6 @@ // ------------------------------------------------------------------------ TBool CWidgetUiWindowManager::CloseAllWidgetsUnderOOM() { - TInt temp(0); TInt err(KErrNone); CWidgetUiWindow* windowToBeClosed(NULL); TTime currentTime; @@ -1268,6 +1449,13 @@ TBool bAllWindowsClosed = ETrue; TInt nWidgetsCount = iWindowList.Count(); + if(nWidgetsCount > 0) + { + CWidgetUiWindow* window = iWindowList[0]; + TRAP_IGNORE( window->Engine()->HandleCommandL( + (TInt)TBrCtlDefs::ECommandIdBase + + (TInt)TBrCtlDefs::ECommandOOMExit ) ); + } for ( TInt i = (nWidgetsCount-1); i >= 0; i-- ) { CWidgetUiWindow* window = iWindowList[i]; @@ -1299,7 +1487,17 @@ TInt nWidgetsCount = iWindowList.Count(); for ( TInt i = (nWidgetsCount-1); i >= 0; i-- ) { - CWidgetUiWindow* window = iWindowList[i]; + CWidgetUiWindow* window = iWindowList[i]; + TRAP_IGNORE( window->Engine()->HandleCommandL( + (TInt)TBrCtlDefs::ECommandIdBase + + (TInt)TBrCtlDefs::ECommandCancelFetch ) ); + if(i == 0) + { +#ifdef BRDO_OCC_ENABLED_FF + StopConnectionObserving(); +#endif + iConnection->StopConnectionL(); + } delete window; } iWindowList.Reset(); @@ -1332,11 +1530,135 @@ return EFalse; } + +void CWidgetUiWindowManager::ExitNow() + { + iAppUi.Exit(); + } +#ifdef BRDO_OCC_ENABLED_FF +// ----------------------------------------------------------------------------- +// CWidgetUiWindowManager::ConnectionStageAchievedL() +// ----------------------------------------------------------------------------- +// +void CWidgetUiWindowManager::ConnectionStageAchievedL() + { + iConnection->Disconnect(); + + TNifProgressBuf buf = iConnStageNotifier->GetProgressBuffer(); + CWidgetUiWindow* window( iWindowList[0] ); + if( buf().iError == KErrDisconnected ) + { + TRAP_IGNORE( window->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandSetRetryConnectivityFlag + (TInt)TBrCtlDefs::ECommandIdBase ) ); + SetRetryFlag(ETrue); + + TRAP_IGNORE( window->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelQueuedTransactions + (TInt)TBrCtlDefs::ECommandIdBase ) ); + + if( iRetryConnectivity && iRetryConnectivity->IsActive()) + { + iRetryConnectivity->Cancel(); + } + iRetryConnectivity->Start(KRetryConnectivityTimeout, 0,TCallBack(RetryConnectivity,this)); + } + else + { + TRAP_IGNORE( window->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelFetch + (TInt)TBrCtlDefs::ECommandIdBase ) ); + } + } + +void CWidgetUiWindowManager::ConnNeededStatusL( TInt aErr ) + { + StopConnectionObserving(); //Need to stop the connection observer first + + + if ( !iConnStageNotifier->IsActive() ) + { + TName* connectionName = iConnection->ConnectionNameL(); + CleanupStack::PushL( connectionName ); + + iConnStageNotifier->StartNotificationL(connectionName, KLinkLayerClosed, this); + + CleanupStack::PopAndDestroy(); //connectionName + } + } +void CWidgetUiWindowManager::StopConnectionObserving() + { + + if ( iConnStageNotifier ) + { + iConnStageNotifier->Cancel(); + } + } + +// ----------------------------------------------------------------------------- +// CWidgetUiWindow::SetRetryFlag +// ----------------------------------------------------------------------------- +// +void CWidgetUiWindowManager::SetRetryFlag(TBool flag) + { + reConnectivityFlag = flag; + } +// ----------------------------------------------------------------------------- +// CWidgetUiWindow::RetryConnectivity +// ----------------------------------------------------------------------------- +// +TInt CWidgetUiWindowManager::RetryConnectivity(TAny* aWindowManager) + { + + TInt err = ((CWidgetUiWindowManager*)aWindowManager)->RetryInternetConnection(); + return err; + } +TInt CWidgetUiWindowManager::RetryInternetConnection() + { + //First cancel the timer + if ( iRetryConnectivity && iRetryConnectivity->IsActive() ) + { + iRetryConnectivity->Cancel(); + } + TInt err = KErrNone; + if ( !iConnection->Connected() ) + { + TRAP_IGNORE( err = iConnection->StartConnectionL( ETrue ) ); + } + + //Root cause needs to be identified.. + //Fix for Array out of bound crash.. + if(!iWindowList.Count()) + return err; + + CWidgetUiWindow* window( iWindowList[0] ); + if( err == KErrNone ) + { + + TRAP_IGNORE( window->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandUnSetRetryConnectivityFlag + (TInt)TBrCtlDefs::ECommandIdBase ) ); + SetRetryFlag(EFalse); + + TRAP_IGNORE(ConnNeededStatusL(err)); //Start the observer again + TRAP_IGNORE( window->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandRetryTransactions + (TInt)TBrCtlDefs::ECommandIdBase ) ); + } + else + { + TRAP_IGNORE( window->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandUnSetRetryConnectivityFlag + (TInt)TBrCtlDefs::ECommandIdBase ) ); + SetRetryFlag(EFalse); + TRAP_IGNORE(window->Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandClearQuedTransactions + (TInt)TBrCtlDefs::ECommandIdBase ) ); + } + + return err; + } +// ----------------------------------------------------------------------------- +// CWidgetUiWindowManager::GetRetryFlag +// ----------------------------------------------------------------------------- +// + TBool CWidgetUiWindowManager::GetRetryFlag() + { + return reConnectivityFlag; + } +#endif // BRDO_OCC_ENABLED_FF + CRequestRAM::CRequestRAM(CWidgetUiWindowManager* aWidgetUiWindowManager, const TUid& aUid, TUint32 aOperation): CActive( EPriorityStandard ), - iOperation(aOperation), + iWidgetUiWindowManager(aWidgetUiWindowManager), iUid(aUid), - iWidgetUiWindowManager(aWidgetUiWindowManager) + iOperation(aOperation) { } @@ -1353,7 +1675,7 @@ { User::LeaveIfError(iOomSession.Connect()); CActiveScheduler::Add( this ); -#ifdef FF_OOM_MONITOR2_COMPONENT +#ifdef BRDO_OOM_MONITOR2_COMPONENT_FF iOomSession.RequestOptionalRam(KMemoryToCreateWidgetWindow, KMemoryToCreateWidgetWindow, KUidWidgetOOMPlugin, iStatus); SetActive(); #else @@ -1371,6 +1693,7 @@ if(iStatus >= 0) { iWidgetUiWindowManager->OpenOrCreateWindowL( iUid, LaunchMiniview ); + iWidgetUiWindowManager->GetWindow(iUid)->NeedToNotifyNetworkState(ETrue); iWidgetUiWindowManager->ResumeWidgetL( iUid ); iWidgetUiWindowManager->GetWindow(iUid)->SetTime(); #ifdef OOM_WIDGET_CLOSEALL @@ -1397,6 +1720,11 @@ else { NotifyCommandHandled(); + TBool lastOne( iWidgetUiWindowManager->WindowListCount() == 0 ); + if( lastOne ) + { + iWidgetUiWindowManager->AppUi().Exit(); + } iWidgetUiWindowManager->SendAppToBackground(); iWidgetUiWindowManager->WidgetUIClientSession().SetActive( iUid, EFalse ); } @@ -1413,5 +1741,131 @@ { iOomSession.CancelRequestFreeMemory(); } +void CWidgetUiWindowManager::CenrepChanged(TInt aHSModeOnline) + { + if(iWindowList.Count()) + { + CWidgetUiWindow* window = iWindowList[0]; + if( window && + (window->WidgetMiniViewState() == EPublishStart || + window->WidgetMiniViewState() == EPublishSuspend) ) + { + if ( window->NetworkModeWait()->IsStarted() && window->WidgetMiniViewState() == EPublishSuspend) + { + window->NetworkModeWait()->AsyncStop(); + } + if(aHSModeOnline) + { + iNetworkMode = EOnlineMode; + } + else + { + iNetworkMode = EOfflineMode; + + if ( iConnection->Connected() ) + { + for ( TInt i = 0; i < iWindowList.Count(); i++ ) + { + CWidgetUiWindow* wdg_window = iWindowList[i]; + //send CancelFetch to all windows + TRAP_IGNORE( window->Engine()->HandleCommandL( + (TInt)TBrCtlDefs::ECommandIdBase + + (TInt)TBrCtlDefs::ECommandCancelFetch ) ); + } + TRAP_IGNORE( window->Engine()->HandleCommandL( + (TInt)TBrCtlDefs::ECommandIdBase + + (TInt)TBrCtlDefs::ECommandDisconnect ) ); + } + } + if(window->IsWidgetLoaded()) + window->DetermineNetworkState(); + else + window->NeedToNotifyNetworkState(ETrue); + + } + } + if ( ( !FullViewWidgetsOpen() ) && iConnection->Connected() && iNetworkMode == EOfflineMode) + { +#ifdef BRDO_OCC_ENABLED_FF + StopConnectionObserving(); +#endif + iConnection->StopConnectionL(); + } + } + +//cenrep notification handling + +CCenrepNotifyHandler * CCenrepNotifyHandler::NewL( + MCenrepWatcher& aObserver) + { + CCenrepNotifyHandler* o = CCenrepNotifyHandler::NewLC(aObserver); + CleanupStack:: Pop(o); + return o; + } +CCenrepNotifyHandler* CCenrepNotifyHandler::NewLC( + MCenrepWatcher& aObserver) + { + CCenrepNotifyHandler* self( new( ELeave ) CCenrepNotifyHandler( aObserver) ); + CleanupStack:: PushL(self); + self->ConstructL(); + return self; + } +void CCenrepNotifyHandler::ConstructL() + { + iUid = TUid::Uid( KCRUidActiveIdleLV ); + iKey = KAIWebStatus; + iRepository = CRepository::NewL( iUid ); + CActiveScheduler::Add(this); + StartObservingL(); + } + +CCenrepNotifyHandler::CCenrepNotifyHandler(MCenrepWatcher& aObserver) : CActive (EPriorityLow),iObserver(aObserver) + { + + } + +CCenrepNotifyHandler::~CCenrepNotifyHandler() + { + Cancel(); //first cancel because iRepository is used there + delete iRepository; + iRepository=NULL; + } + +void CCenrepNotifyHandler::StartObservingL() + { + if( IsActive() ) + { + return; //do nothing if allready observing + } + User::LeaveIfError( + iRepository->NotifyRequest( iKey, iStatus ) ); + SetActive(); + } + +void CCenrepNotifyHandler::StopObserving() + { + Cancel(); + } + +void CCenrepNotifyHandler::DoCancel() + { + iRepository->NotifyCancel(iKey); + } + +void CCenrepNotifyHandler::RunL() + { + TInt value = 0; + TInt error = iRepository->Get( iKey, value); + if( error == KErrNone ) + { + iObserver.CenrepChanged(value); + } + // Re-subscribe + error = iRepository->NotifyRequest( iKey, iStatus ); + if( error == KErrNone ) + { + SetActive(); + } + } // End of file