|
1 /* |
|
2 * Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Monitors the file system for changes in a file. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mpxlog.h> |
|
20 #include <mpxconstants.h> |
|
21 |
|
22 #include "pnsmonitor.h" |
|
23 #include "pnsmonitorobserver.h" |
|
24 |
|
25 // RProperty key to identify the case when Music Player launching |
|
26 // in the background |
|
27 const TInt KMPXLaunchingOnBackground( 100 ); |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CPNSMonitor::CPNSMonitor( MPNSMonitorObserver& aObserver ) |
|
34 : CActive( CActive::EPriorityLow ), |
|
35 iObserver( aObserver ) |
|
36 { |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Second Phase Constructor |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 void CPNSMonitor::ConstructL() |
|
44 { |
|
45 User::LeaveIfError( iPropertyHandler.Attach( KAppUidMusicPlayerX, |
|
46 KMPXLaunchingOnBackground ) ); |
|
47 CActiveScheduler::Add( this ); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Two-phased constructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CPNSMonitor* CPNSMonitor::NewL( MPNSMonitorObserver& aObserver ) |
|
55 { |
|
56 CPNSMonitor* self = new( ELeave ) CPNSMonitor( aObserver ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop( self ); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // Destructor |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CPNSMonitor::~CPNSMonitor() |
|
68 { |
|
69 Cancel(); |
|
70 iPropertyHandler.Close(); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Starts monitoring |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CPNSMonitor::Start() |
|
78 { |
|
79 MPX_DEBUG1("CPNSMonitor::Start <---"); |
|
80 iPropertyHandler.Subscribe( iStatus ); |
|
81 SetActive(); |
|
82 MPX_DEBUG1("CPNSMonitor::Start --->"); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // RunL callback |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CPNSMonitor::RunL() |
|
90 { |
|
91 MPX_DEBUG1("CPNSMonitor::RunL <---"); |
|
92 TInt ret( 0 ); |
|
93 TInt err = RProperty::Get( KAppUidMusicPlayerX, |
|
94 KMPXLaunchingOnBackground, |
|
95 ret ); |
|
96 |
|
97 if ( ret ) |
|
98 { |
|
99 iObserver.OpeningMusicPlayer(); |
|
100 MPX_DEBUG1("CPNSMonitor::RunL - Opening Music Player on the background"); |
|
101 } |
|
102 |
|
103 // Listen again |
|
104 Start(); |
|
105 |
|
106 MPX_DEBUG1("CPNSMonitor::RunL --->"); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // Handle Cancelling |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CPNSMonitor::DoCancel() |
|
114 { |
|
115 MPX_DEBUG1("CPNSMonitor::DoCancel <---"); |
|
116 // Stop monitoring |
|
117 iPropertyHandler.Cancel(); |
|
118 MPX_DEBUG1("CPNSMonitor::DoCancel --->"); |
|
119 } |
|
120 |
|
121 // ---------------------------------------------------------------------------- |
|
122 // Handles a leave occurring in the request completion event handler RunL() |
|
123 // ---------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CPNSMonitor::RunError( TInt aError ) |
|
126 { |
|
127 MPX_DEBUG2("CPNSMonitor::RunError(%d)", aError ); |
|
128 |
|
129 // Listen again |
|
130 Start(); |
|
131 return KErrNone; |
|
132 } |