apengine/apeng/src/ActiveApDbNotifier.cpp
changeset 0 5a93021fdf25
child 66 ed07dcc72692
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apengine/apeng/src/ActiveApDbNotifier.cpp	Thu Dec 17 08:55:21 2009 +0200
@@ -0,0 +1,121 @@
+/*
+* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Implementation of CActiveApDbNotifier.
+*
+*/
+
+
+// INCLUDE FILES
+
+#include "ActiveApDb.h"
+#include "ActiveApDbNotifier.h"
+
+// ================= MEMBER FUNCTIONS =======================
+
+// ---------------------------------------------------------
+// CActiveApDbNotifier::CActiveApDbNotifier
+// ---------------------------------------------------------
+//
+CActiveApDbNotifier::CActiveApDbNotifier( CActiveApDb& aDb )
+: CActive( EPriorityStandard )
+    {
+    iActiveDb = &aDb;
+    CActiveScheduler::Add( this );
+    }
+
+// ---------------------------------------------------------
+// CActiveApDbNotifier::~CActiveApDbNotifier
+// ---------------------------------------------------------
+//
+CActiveApDbNotifier::~CActiveApDbNotifier()
+    {
+    Cancel();
+    }
+
+// ---------------------------------------------------------
+// CActiveApDbNotifier::RunL
+// ---------------------------------------------------------
+//
+void CActiveApDbNotifier::RunL()
+    {
+    if ( iStatus == KErrCancel )
+        {
+        // Do nothing.
+        }
+    else
+        {
+        // first store status, because re-schedule will be earlier 
+        // than notifying clients. Reason:
+        // clients can leave but re-schedule MUST happen anyway,
+        // to keep the notifier alive even if any client leaves
+        TRequestStatus tempstatus( iStatus );
+
+        if ( iStatus == RDbNotifier::EClose )
+            {
+            // Finish if the database is closed.
+            NotifyChange();
+            }
+        else
+            {
+            // Reschedule automatically (as long as the database is open).
+            NotifyChange();
+            }
+        // and now let clients handle their stuff...
+        TRAP_IGNORE( iActiveDb->HandleDbEventL( tempstatus.Int() ) );
+        }
+    }
+
+
+// ---------------------------------------------------------
+// CActiveApDbNotifier::DoCancel
+// ---------------------------------------------------------
+//
+void CActiveApDbNotifier::DoCancel()
+    {
+    Stop();
+    }
+
+
+// ---------------------------------------------------------
+// CActiveApDbNotifier::Stop
+// ---------------------------------------------------------
+//
+void CActiveApDbNotifier::Stop()
+    {
+    iActiveDb->Database()->CancelRequestNotification();
+    }
+
+// ---------------------------------------------------------
+// CActiveApDbNotifier::Start
+// ---------------------------------------------------------
+//
+void CActiveApDbNotifier::Start()
+    {
+    NotifyChange();
+    }
+
+// ---------------------------------------------------------
+// CActiveApDbNotifier::NotifyChange
+// ---------------------------------------------------------
+//
+void CActiveApDbNotifier::NotifyChange()
+    {
+    if ( !IsActive() )
+        {
+        iActiveDb->Database()->RequestNotification( iStatus );
+        SetActive();
+        }
+    }
+
+// End of File