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: Observes the state of P&S property |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32cmn.h> |
|
21 #include <vccsubscribekeys.h> |
|
22 |
|
23 #include "vccengpspropertylistener.h" |
|
24 #include "rubydebug.h" |
|
25 |
|
26 //#include "vccuipropertyhandler.pan" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 // ----------------------------------------------------------------------------- |
|
30 // C++ constructor |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CVccEngPsPropertyListener::CVccEngPsPropertyListener( |
|
34 const TUid aCategoryUid, |
|
35 const TUint aKeyId ): |
|
36 CActive( EPriorityStandard ), |
|
37 iCategoryId( aCategoryUid ), |
|
38 iKeyId( aKeyId ) |
|
39 { |
|
40 RUBY_DEBUG_BLOCK( "VccEngPsPropertyListener::CVccEngPsPropertyListener" ); |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // 2nd phase constructor |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CVccEngPsPropertyListener::ConstructL() |
|
48 { |
|
49 RUBY_DEBUG_BLOCKL( "CVccEngPsPropertyListener::ConstructL" ); |
|
50 // Attach to categroy and key. |
|
51 User::LeaveIfError( iProperty.Attach( iCategoryId, iKeyId )); |
|
52 // Add to active scheduler |
|
53 CActiveScheduler::Add( this ); |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // Constructor |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CVccEngPsPropertyListener* CVccEngPsPropertyListener::NewL( |
|
61 const TUid aCategoryId, |
|
62 const TUint aKeyId) |
|
63 { |
|
64 RUBY_DEBUG_BLOCKL("CVccEngPsPropertyListener::NewL"); |
|
65 |
|
66 CVccEngPsPropertyListener* self = new (ELeave) CVccEngPsPropertyListener( |
|
67 aCategoryId, aKeyId ); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop( self ); |
|
71 |
|
72 return self; |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // Destructor |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CVccEngPsPropertyListener::~CVccEngPsPropertyListener() |
|
80 { |
|
81 RUBY_DEBUG0( "CVccEngPsPropertyListener::~CVccEngPsPropertyListener() - ENTER" ); |
|
82 Cancel(); |
|
83 iProperty.Close(); |
|
84 iObservers.Close(); |
|
85 RUBY_DEBUG0( "CVccEngPsPropertyListener::~CVccEngPsPropertyListener() - EXIT" ); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // Add Vcc property observer |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CVccEngPsPropertyListener::AddObserverL( |
|
93 MVccEngPsPropertyListenerObserver& aObserver ) |
|
94 { |
|
95 RUBY_DEBUG_BLOCKL( "CVccEngPsPropertyListener::AddObserverL" ); |
|
96 |
|
97 if ( iObservers.Find( &aObserver ) == KErrNotFound ) |
|
98 { |
|
99 User::LeaveIfError( iObservers.Append( &aObserver ) ); |
|
100 } |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // Removes observer |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CVccEngPsPropertyListener::RemoveObserver( |
|
108 MVccEngPsPropertyListenerObserver& aObserver ) |
|
109 { |
|
110 RUBY_DEBUG_BLOCK( "CVccEngPsPropertyListener::RemoveObserver" ); |
|
111 |
|
112 TInt index = iObservers.Find( &aObserver ); |
|
113 |
|
114 if ( index != KErrNotFound ) |
|
115 { |
|
116 iObservers.Remove( index ); |
|
117 } |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // Fetches the current value of the key |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 TInt CVccEngPsPropertyListener::CurrentValue() |
|
125 { |
|
126 RUBY_DEBUG_BLOCK( "CVccEngPsPropertyListener::CurrentValue" ); |
|
127 |
|
128 TInt value( KErrNotFound ); |
|
129 iProperty.Get( iCategoryId, iKeyId, value ); |
|
130 return value; |
|
131 } |
|
132 |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // Cancels the outstanding subsription request |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CVccEngPsPropertyListener::DoCancel() |
|
139 { |
|
140 RUBY_DEBUG0( "CVccEngPsPropertyListener::DoCancel - ENTER" ); |
|
141 iProperty.Cancel(); |
|
142 RUBY_DEBUG0( "CVccEngPsPropertyListener::DoCancel - EXIT" ); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // Subsribes to property |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CVccEngPsPropertyListener::Start() |
|
150 { |
|
151 RUBY_DEBUG_BLOCK( "CVccEngPsPropertyListener::Start" ); |
|
152 |
|
153 // Subscribe to get updates. |
|
154 iProperty.Subscribe( iStatus ); |
|
155 SetActive(); |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // RunL |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CVccEngPsPropertyListener::RunL() |
|
163 { |
|
164 TInt err = iStatus.Int(); |
|
165 Start(); |
|
166 RUBY_DEBUG_BLOCK( "CVccEngPsPropertyListener::RunL" ); |
|
167 RUBY_DEBUG1( " - Status: %d", iStatus.Int() ); |
|
168 if ( KErrNone == err ) |
|
169 { |
|
170 RUBY_DEBUG0( " - CVccEngPsPropertyListener::RunL - \ |
|
171 if ( KErrNone == err )" ); |
|
172 // Notify property changes to observers. |
|
173 NotifyObserversL(); |
|
174 } |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // Notify all observers about the changed value |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CVccEngPsPropertyListener::NotifyObserversL() |
|
182 { |
|
183 RUBY_DEBUG_BLOCKL( "CVccEngPsPropertyListener::NotifyObserversL" ); |
|
184 |
|
185 TInt value = CurrentValue(); |
|
186 RUBY_DEBUG1( " - value [%d]", value ); |
|
187 |
|
188 for ( TInt i(0) ; i < iObservers.Count() ; i++ ) |
|
189 { |
|
190 MVccEngPsPropertyListenerObserver* observer = iObservers[i]; |
|
191 |
|
192 if ( observer ) |
|
193 { |
|
194 observer->PropertyChangedL( iCategoryId, iKeyId, value ); |
|
195 } |
|
196 } |
|
197 } |
|