musichomescreen_multiview/mcpmusicplayer/src/pnsmonitor.cpp
changeset 0 ff3acec5bc43
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/musichomescreen_multiview/mcpmusicplayer/src/pnsmonitor.cpp	Thu Dec 17 08:45:05 2009 +0200
@@ -0,0 +1,132 @@
+/*
+* Copyright (c) 2008-2008 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:  Monitors the file system for changes in a file.
+*
+*/
+
+
+#include <mpxlog.h>
+#include <mpxconstants.h>
+
+#include "pnsmonitor.h"
+#include "pnsmonitorobserver.h"
+
+// RProperty key to identify the case when Music Player launching
+// in the background
+const TInt KMPXLaunchingOnBackground( 100 );
+
+// ---------------------------------------------------------------------------
+// Constructor
+// ---------------------------------------------------------------------------
+//
+CPNSMonitor::CPNSMonitor( MPNSMonitorObserver& aObserver )
+        : CActive( CActive::EPriorityLow ),
+        iObserver( aObserver )
+    {
+    }
+
+// ---------------------------------------------------------------------------
+// Second Phase Constructor
+// ---------------------------------------------------------------------------
+//
+void CPNSMonitor::ConstructL()
+    {
+    User::LeaveIfError( iPropertyHandler.Attach( KAppUidMusicPlayerX,
+            KMPXLaunchingOnBackground ) );
+    CActiveScheduler::Add( this );
+    }
+
+// ---------------------------------------------------------------------------
+// Two-phased constructor
+// ---------------------------------------------------------------------------
+//
+CPNSMonitor* CPNSMonitor::NewL( MPNSMonitorObserver& aObserver )
+    {
+    CPNSMonitor* self = new( ELeave ) CPNSMonitor( aObserver );
+    CleanupStack::PushL( self );
+    self->ConstructL();
+    CleanupStack::Pop( self );
+    return self;
+    }
+
+// ---------------------------------------------------------------------------
+// Destructor
+// ---------------------------------------------------------------------------
+//
+CPNSMonitor::~CPNSMonitor()
+    {
+    Cancel();
+    iPropertyHandler.Close();
+    }
+
+// ---------------------------------------------------------------------------
+// Starts monitoring
+// ---------------------------------------------------------------------------
+//
+void CPNSMonitor::Start()
+    {
+    MPX_DEBUG1("CPNSMonitor::Start <---");
+    iPropertyHandler.Subscribe( iStatus );
+    SetActive();
+    MPX_DEBUG1("CPNSMonitor::Start --->");
+    }
+
+// ---------------------------------------------------------------------------
+// RunL callback
+// ---------------------------------------------------------------------------
+//
+void CPNSMonitor::RunL()
+    {
+    MPX_DEBUG1("CPNSMonitor::RunL <---");
+    TInt ret( 0 );
+    TInt err = RProperty::Get( KAppUidMusicPlayerX,
+                KMPXLaunchingOnBackground,
+                ret );
+
+    if ( ret )
+        {
+        iObserver.OpeningMusicPlayer();
+        MPX_DEBUG1("CPNSMonitor::RunL - Opening Music Player on the background");
+        }
+    
+	// Listen again
+    Start();
+    
+    MPX_DEBUG1("CPNSMonitor::RunL --->");
+    }
+
+// ---------------------------------------------------------------------------
+// Handle Cancelling
+// ---------------------------------------------------------------------------
+//
+void CPNSMonitor::DoCancel()
+    {
+    MPX_DEBUG1("CPNSMonitor::DoCancel <---");
+    // Stop monitoring
+    iPropertyHandler.Cancel();
+    MPX_DEBUG1("CPNSMonitor::DoCancel --->");
+    }
+
+// ----------------------------------------------------------------------------
+// Handles a leave occurring in the request completion event handler RunL()
+// ----------------------------------------------------------------------------
+//
+TInt CPNSMonitor::RunError( TInt aError )
+    {
+    MPX_DEBUG2("CPNSMonitor::RunError(%d)", aError );
+   
+    // Listen again
+    Start();
+    return KErrNone;
+    }