uiacceltk/hitchcock/backgroundanim/src/bganimhost.cpp
branchRCL_3
changeset 22 7c5dd702d6d3
parent 17 3ac8bf5c5014
--- a/uiacceltk/hitchcock/backgroundanim/src/bganimhost.cpp	Tue Apr 27 17:34:42 2010 +0300
+++ b/uiacceltk/hitchcock/backgroundanim/src/bganimhost.cpp	Tue May 11 17:03:00 2010 +0300
@@ -41,21 +41,17 @@
     delete iCurrentPluginDllName;
     delete iCurrentPluginAssetDir;
     delete iTimer;
-    if (iPlugin)
-        {
-        iPlugin->destroy();
-        free(iPlugin);
-        }
-    iPluginLibrary.Close();
+    delete iTheReaper;
+    delete iDoomBringer;
+    
+    ReleasePlugin();
+
 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
     delete iSCPropertyListener;
 #endif
+    delete iHSFgStatusPropertyListener;
     delete iThemeRepositoryListener;
-    while (iSensorListeners.Count())
-        {
-        delete iSensorListeners[0];
-        iSensorListeners.Remove(0);
-        }
+
     iSensorListeners.Close();
     delete CActiveScheduler::Current();
     CActiveScheduler::Install(NULL);
@@ -82,11 +78,12 @@
     CActiveScheduler *ac = new (ELeave) CActiveScheduler;
     CActiveScheduler::Install(ac);
     iTimer = CHighResTimer::NewL(TCallBack(TimerFunc, this),CActive::EPriorityStandard);
+    iTheReaper = CHighResTimer::NewL(TCallBack(ReaperFunc, this),CActive::EPriorityStandard);
     iThemeRepositoryListener = CThemeRepositoryListener::NewL(&iRunning);
 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
     iSCPropertyListener = CScreenSaverPropertyListener::NewL(TCallBack(ScreenSaverCallback, this));
 #endif
-    
+    iHSFgStatusPropertyListener = CFGAppPropertyListener::NewL(TCallBack(FgAppCallback, this));
     CreateWindowL();
 
     User::LeaveIfError(iSkinSrv.Connect());
@@ -101,6 +98,7 @@
 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)    
     iSCPropertyListener->IssueRequest();
 #endif
+    iHSFgStatusPropertyListener->IssueRequest();
     }
     
 void CBgAnimHost::CreateWindowL()
@@ -507,11 +505,16 @@
     
 void CBgAnimHost::NewFrame()
     {
-    if (!iRunning)
+    if (!iRunning && !iDoomBringer)
         {
-        // Stop and exit
-        CActiveScheduler::Stop();
-        return;
+        iDoomBringer = CHighResTimer::NewL(TCallBack(DoomBringerFunc, this),CActive::EPriorityStandard);
+        iDoomBringer->CallBack(5000);
+        }
+		
+    if (iRunning && iDoomBringer)
+        {
+        delete iDoomBringer;
+        iDoomBringer = NULL;
         }
     if (!iSurfaceInitialized)
         {
@@ -545,7 +548,28 @@
     
     iTimer->CallBack(nextcallback);
     }
+
+void CBgAnimHost::Kill()
+    {
+    if (!iRunning)
+        {
+        CActiveScheduler::Stop();
+        }
+    else
+        {
+        delete iDoomBringer;
+        iDoomBringer = NULL;
+        }
     
+    return;
+    }
+    
+TInt CBgAnimHost::DoomBringerFunc(TAny* aPtr)
+    {
+    CBgAnimHost* me = (CBgAnimHost*)(aPtr);
+    me->Kill();
+    return ETrue;
+    }
     
 TInt CBgAnimHost::TimerFunc(TAny* aPtr)
     {
@@ -554,7 +578,14 @@
     return ETrue;
     }
 
-    
+TInt CBgAnimHost::ReaperFunc(TAny* aPtr)
+    {
+    CBgAnimHost* me = (CBgAnimHost*)(aPtr);
+    me->CompositionTargetHidden();
+    return ETrue;
+    }
+
+
 void CBgAnimHost::ExecuteL() 
     {
     // finally start our timer and scheduler...
@@ -606,7 +637,13 @@
 
 void CBgAnimHost::CompositionTargetVisible()
     {
-    if (iSurfaceInitialized || iHiddenDueSC)
+    if (!iRunning && !iDoomBringer)
+        {
+        iDoomBringer = CHighResTimer::NewL(TCallBack(DoomBringerFunc, this),CActive::EPriorityStandard);
+        iDoomBringer->CallBack(5000);
+        }
+
+    if (iSurfaceInitialized || iHiddenDueSC || iReaped)
         {
         // don't bother if we are already in
         // a correct state, or if we are hidden by
@@ -626,6 +663,7 @@
     if (!err)
         {
         iPlugin->gpuresourcesavailable(1);
+        iPlugin->setfaded(iHSFgStatusPropertyListener->GetHSFGStatus());
         iTimer->CallBack(1);
         iTimerRunning = ETrue;
         }
@@ -636,6 +674,7 @@
     {
 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
     TInt scStatus = iSCPropertyListener->GetScreenSaverStatus();
+    
     if (scStatus)
         {
         // screensaver is ON
@@ -666,6 +705,35 @@
         iSensorListeners[count]->StopListening();
         }
     }
+
+void CBgAnimHost::HandleFGAppEvent()
+    {
+    if (!iRunning && !iDoomBringer)
+        {
+        iDoomBringer = CHighResTimer::NewL(TCallBack(DoomBringerFunc, this),CActive::EPriorityStandard);
+        iDoomBringer->CallBack(5000);
+        }
+
+    if (iPlugin && iPlugin->setfaded)
+        {
+        iPlugin->setfaded(iHSFgStatusPropertyListener->GetHSFGStatus());
+        if (!iHSFgStatusPropertyListener->GetHSFGStatus())
+            {
+            // reap the anim in 5 seconds...
+            // 5 seconds is probably just allright
+            // to have enought time for the plugin to fade out...
+            iReaped = ETrue;
+            iTheReaper->CallBack(5000);
+            }
+        else
+            {
+            iReaped = EFalse;
+            iTheReaper->Cancel();
+            CompositionTargetVisible();
+            }
+        }
+    }
+
 TInt CBgAnimHost::ScreenSaverCallback(TAny* aPtr)
     {
     CBgAnimHost* me = (CBgAnimHost*) aPtr;
@@ -673,6 +741,13 @@
     return EFalse;
     }
 
+TInt CBgAnimHost::FgAppCallback(TAny* aPtr)
+    {
+    CBgAnimHost* me = (CBgAnimHost*) aPtr;
+    me->HandleFGAppEvent();
+    return EFalse;
+    }
+
 void CBgAnimHost::DataReceived( CSensrvChannel& aChannel, TInt aCount, TInt aDataLost )
     {
     if (iPlugin && iPlugin->receivesensordata)