mmserv/radioutility/radio_utility/src/RadioMonitorBody.cpp
changeset 0 71ca22bcf22a
child 16 43d09473c595
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mmserv/radioutility/radio_utility/src/RadioMonitorBody.cpp	Tue Feb 02 01:08:46 2010 +0200
@@ -0,0 +1,131 @@
+/*
+* Copyright (c) 2007 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:  Radio Monitor body implementation
+*
+*/
+
+
+#include <RadioMonitor.h>
+#include "RadioMonitorBody.h"
+#include "RadioServerData.h"
+
+// ======== MEMBER FUNCTIONS ========
+
+// -----------------------------------------------------------------------------
+// CRadioMonitor::CBody::NewL
+// Two-phased constructor.
+// -----------------------------------------------------------------------------
+//
+CRadioMonitor::CBody* CRadioMonitor::CBody::NewL(
+    MRadioMonitorObserver& aObserver )
+    {
+    CRadioMonitor::CBody* s = new(ELeave) CRadioMonitor::CBody();
+    s->iRadioMonitorClient = &aObserver;
+    CleanupStack::PushL(s);
+    s->ConstructL();
+    CleanupStack::Pop();
+    return s;
+    }
+
+// -----------------------------------------------------------------------------
+// Destructor.
+// -----------------------------------------------------------------------------
+//
+CRadioMonitor::CBody::~CBody()
+    {
+    Cancel();
+    iProperty.Close();
+    }
+
+// -----------------------------------------------------------------------------
+// CRadioMonitor::CBody::CBody
+// Two-phased constructor.
+// -----------------------------------------------------------------------------
+//
+CRadioMonitor::CBody::CBody() :
+    CActive(EPriorityStandard)
+    {
+    }
+
+// -----------------------------------------------------------------------------
+// CRadioMonitor::ConstructL
+// Two-phased constructor.
+// -----------------------------------------------------------------------------
+//
+void CRadioMonitor::CBody::ConstructL()
+    {
+    CActiveScheduler::Add(this);
+
+    // Attach property
+    User::LeaveIfError(iProperty.Attach(KRadioServerPropertyCategory,
+                                        KRadioServPsMonitorState));
+
+    iProperty.Subscribe(iStatus);
+    SetActive();
+    }
+
+// -----------------------------------------------------------------------------
+// CRadioMonitor::IsRadioOn
+// (other items were commented in a header).
+// -----------------------------------------------------------------------------
+//
+TBool CRadioMonitor::CBody::IsRadioOn() const
+    {
+    TBool radioState = ERadioStateOff;
+    RProperty::Get(KRadioServerPropertyCategory,
+                   KRadioServPsMonitorState,
+                   radioState);
+
+    return radioState;
+    }
+
+// -----------------------------------------------------------------------------
+// CRadioMonitor::RunL
+// Called when property value changes
+// -----------------------------------------------------------------------------
+//
+void CRadioMonitor::CBody::RunL()
+    {
+    TBool radioState = ERadioStateOff;
+
+    // Resubscribe before processing new value to prevent missing updates
+    iProperty.Subscribe(iStatus);
+    SetActive();
+
+    TInt error = iProperty.Get(radioState);
+    if ( error == KErrNone )
+        {
+        iRadioMonitorClient->MrmEvent((TRadioMonitorEvent)radioState);
+        }
+    else if ( error == KErrNotFound )
+        {
+        iRadioMonitorClient->MrmEvent(ERadioStateOff);
+        }
+    else
+        {
+        // pass
+        }
+    }
+
+// -----------------------------------------------------------------------------
+// CRadioMonitor::DoCancel
+// Cancels event listening
+// -----------------------------------------------------------------------------
+//
+void CRadioMonitor::CBody::DoCancel()
+    {
+    iProperty.Cancel();
+    }
+
+// End of File