|
1 /* |
|
2 * Copyright (c) 2007 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: Radio Monitor body implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <RadioMonitor.h> |
|
20 #include "RadioMonitorBody.h" |
|
21 #include "RadioServerData.h" |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CRadioMonitor::CBody::NewL |
|
27 // Two-phased constructor. |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CRadioMonitor::CBody* CRadioMonitor::CBody::NewL( |
|
31 MRadioMonitorObserver& aObserver ) |
|
32 { |
|
33 CRadioMonitor::CBody* s = new(ELeave) CRadioMonitor::CBody(); |
|
34 s->iRadioMonitorClient = &aObserver; |
|
35 CleanupStack::PushL(s); |
|
36 s->ConstructL(); |
|
37 CleanupStack::Pop(); |
|
38 return s; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // Destructor. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CRadioMonitor::CBody::~CBody() |
|
46 { |
|
47 Cancel(); |
|
48 iProperty.Close(); |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CRadioMonitor::CBody::CBody |
|
53 // Two-phased constructor. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CRadioMonitor::CBody::CBody() : |
|
57 CActive(EPriorityStandard) |
|
58 { |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CRadioMonitor::ConstructL |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CRadioMonitor::CBody::ConstructL() |
|
67 { |
|
68 CActiveScheduler::Add(this); |
|
69 |
|
70 // Attach property |
|
71 User::LeaveIfError(iProperty.Attach(KRadioServerPropertyCategory, |
|
72 KRadioServPsMonitorState)); |
|
73 |
|
74 iProperty.Subscribe(iStatus); |
|
75 SetActive(); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CRadioMonitor::IsRadioOn |
|
80 // (other items were commented in a header). |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 TBool CRadioMonitor::CBody::IsRadioOn() const |
|
84 { |
|
85 TBool radioState = ERadioStateOff; |
|
86 RProperty::Get(KRadioServerPropertyCategory, |
|
87 KRadioServPsMonitorState, |
|
88 radioState); |
|
89 |
|
90 return radioState; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CRadioMonitor::RunL |
|
95 // Called when property value changes |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CRadioMonitor::CBody::RunL() |
|
99 { |
|
100 TBool radioState = ERadioStateOff; |
|
101 |
|
102 // Resubscribe before processing new value to prevent missing updates |
|
103 iProperty.Subscribe(iStatus); |
|
104 SetActive(); |
|
105 |
|
106 TInt error = iProperty.Get(radioState); |
|
107 if ( error == KErrNone ) |
|
108 { |
|
109 iRadioMonitorClient->MrmEvent((TRadioMonitorEvent)radioState); |
|
110 } |
|
111 else if ( error == KErrNotFound ) |
|
112 { |
|
113 iRadioMonitorClient->MrmEvent(ERadioStateOff); |
|
114 } |
|
115 else |
|
116 { |
|
117 // pass |
|
118 } |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CRadioMonitor::DoCancel |
|
123 // Cancels event listening |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CRadioMonitor::CBody::DoCancel() |
|
127 { |
|
128 iProperty.Cancel(); |
|
129 } |
|
130 |
|
131 // End of File |