|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <ssm/ssmsystemwideproperty.h> |
|
17 #include "ssmpropertymonitor.h" |
|
18 #include "ssmdebug.h" |
|
19 #include "cmnpanic.h" |
|
20 |
|
21 const TUid KSsmServerSid = {0x2000D75B}; //UID3 of sysstatemgr.exe |
|
22 |
|
23 // |
|
24 //---------------- class RSsmSystemWideProperty ------------------ |
|
25 // |
|
26 |
|
27 /** |
|
28 Connect to the specified System-Wide-Property. |
|
29 If the specified property does not yet exist, then this operation will still succeed. |
|
30 @param aSwpKey the key(a TUint value) of the System-Wide-Property to connect |
|
31 @return KErrNone if successful, otherwise one of the system wide error codes. |
|
32 */ |
|
33 EXPORT_C TInt RSsmSystemWideProperty::Connect(TUint aSwpKey) |
|
34 { |
|
35 return RSsmSystemWideProperty::Connect(aSwpKey, KSsmServerSid); |
|
36 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
37 |
|
38 /** |
|
39 @internalComponent |
|
40 */ |
|
41 TInt RSsmSystemWideProperty::Connect(TUint aSwpKey, TUid aProcessSid) |
|
42 { |
|
43 iKey = aSwpKey; |
|
44 return iProperty.Attach(aProcessSid, iKey, EOwnerThread); |
|
45 } //lint !e1746 Suppress parameter 'aProcessSid' could be made const reference |
|
46 |
|
47 /** |
|
48 Close this handle |
|
49 */ |
|
50 EXPORT_C void RSsmSystemWideProperty::Close() |
|
51 { |
|
52 if(KNullHandle != iProperty.Handle()) |
|
53 { |
|
54 iProperty.Cancel(); |
|
55 iProperty.Close(); |
|
56 } |
|
57 } |
|
58 |
|
59 /** |
|
60 Reads the value of the connected System-Wide-Property. |
|
61 @param aValue A reference to the variable to store the read value into. |
|
62 @return KErrNone if successful, KErrBadHandle if not connected, otherwise one of the system wide error codes. |
|
63 */ |
|
64 EXPORT_C TInt RSsmSystemWideProperty::GetValue(TInt& aValue) const |
|
65 { |
|
66 //This function is implemented as "return by reference" because it can't handle |
|
67 //any error returned from RProperty in a sensible way. |
|
68 TInt err = KErrBadHandle; |
|
69 if(iProperty.Handle()) |
|
70 { |
|
71 err = const_cast<RProperty&>(iProperty).Get(aValue); |
|
72 #ifdef _DEBUG |
|
73 if(KErrNone != err) |
|
74 { |
|
75 DEBUGPRINT3A("RSsmSystemWideProperty::Value read property %d returned error %d", iKey, err); |
|
76 } |
|
77 #endif |
|
78 } |
|
79 return err; |
|
80 } |
|
81 |
|
82 /** |
|
83 Use to get a notification when the value of the connected System-Wide-Property changes |
|
84 @param aStatus The TRequestStatus to be completed when the value gets changed. Will complete |
|
85 immediately with KErrBadHandle if no System-Wide-Property is connected. |
|
86 */ |
|
87 EXPORT_C void RSsmSystemWideProperty::Subscribe(TRequestStatus& aStatus) |
|
88 { |
|
89 if(iProperty.Handle()) |
|
90 { |
|
91 iProperty.Subscribe(aStatus); |
|
92 } |
|
93 else |
|
94 { |
|
95 TRequestStatus* status = &aStatus; |
|
96 User::RequestComplete(status, KErrBadHandle); |
|
97 } |
|
98 } |
|
99 |
|
100 /** |
|
101 Cancel an outstanding @c Subscribe operation. |
|
102 */ |
|
103 EXPORT_C void RSsmSystemWideProperty::SubscribeCancel() |
|
104 { |
|
105 if(KNullHandle != iProperty.Handle()) |
|
106 { |
|
107 iProperty.Cancel(); |
|
108 } |
|
109 } |
|
110 |
|
111 // |
|
112 //---------------- class CSsmSystemWideProperty ------------------ |
|
113 // |
|
114 |
|
115 /** |
|
116 Factory method that returns an instance of this object setup to subscribe |
|
117 on changes of the specifed System-Wide-Property. If the specified property |
|
118 does not yet exist, then this operation will still succeed. |
|
119 |
|
120 @param aSwpKey the key(a TUint value) of the System-Wide-Property to subscribe to |
|
121 @return KErrNone if successful, otherwise one of the system wide error codes. |
|
122 */ |
|
123 EXPORT_C CSsmSystemWideProperty* CSsmSystemWideProperty::NewLC(TUint aSwpKey) |
|
124 { |
|
125 CSsmSystemWideProperty* self = new (ELeave) CSsmSystemWideProperty; |
|
126 CleanupStack::PushL(self); |
|
127 self->ConstructL(aSwpKey, KSsmServerSid); |
|
128 return self; |
|
129 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
130 |
|
131 /** |
|
132 Factory method that returns an instance of this object setup to subscribe |
|
133 on changes of the specifed System-Wide-Property. If the specified property |
|
134 does not yet exist, then this operation will still succeed. |
|
135 |
|
136 @param aSwpKey the key(a TUint value) of the System-Wide-Property to subscribe to |
|
137 @return KErrNone if successful, otherwise one of the system wide error codes. |
|
138 */ |
|
139 EXPORT_C CSsmSystemWideProperty* CSsmSystemWideProperty::NewL(TUint aSwpKey) |
|
140 { |
|
141 CSsmSystemWideProperty* self = CSsmSystemWideProperty::NewLC(aSwpKey); |
|
142 CleanupStack::Pop(self); |
|
143 return self; |
|
144 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
145 |
|
146 /** |
|
147 @internalComponent |
|
148 */ |
|
149 CSsmSystemWideProperty* CSsmSystemWideProperty::NewLC(TUint aSwpKey, TUid aProcessSid) |
|
150 { |
|
151 CSsmSystemWideProperty* self = new (ELeave) CSsmSystemWideProperty; |
|
152 CleanupStack::PushL(self); |
|
153 self->ConstructL(aSwpKey, aProcessSid); |
|
154 return self; |
|
155 } //lint !e1746 Suppress parameter 'aProcessSid' could be made const reference |
|
156 |
|
157 /** |
|
158 @internalComponent |
|
159 */ |
|
160 void CSsmSystemWideProperty::ConstructL(TUint aSwpKey, TUid aProcessSid) |
|
161 { |
|
162 iMonitor = CSsmPropertyMonitor::NewL(*this, aSwpKey, aProcessSid); |
|
163 } //lint !e1746 Suppress parameter 'aProcessSid' could be made const reference |
|
164 |
|
165 /** |
|
166 @internalComponent |
|
167 */ |
|
168 CSsmSystemWideProperty::CSsmSystemWideProperty() |
|
169 { |
|
170 } |
|
171 |
|
172 /** |
|
173 Destructor |
|
174 */ |
|
175 EXPORT_C CSsmSystemWideProperty::~CSsmSystemWideProperty() |
|
176 { |
|
177 iSubscribers.Close(); |
|
178 delete iMonitor; |
|
179 } |
|
180 |
|
181 /** |
|
182 Reads the value held by the connected System-Wide-Property. |
|
183 @param aSwp A reference to the variable where the read data will be written. |
|
184 @panic ECmnSwpSession1 if an error occurs in RunL |
|
185 @return KErrNone if successful, otherwise one of the system wide error codes. |
|
186 */ |
|
187 EXPORT_C TInt CSsmSystemWideProperty::GetValue(TSsmSwp& aSwp) const |
|
188 { |
|
189 __ASSERT_DEBUG(iMonitor, User::Panic(KPanicSsmCmn, ECmnSwpSession1)); |
|
190 if(iMonitor) |
|
191 { |
|
192 return iMonitor->GetValue(aSwp); |
|
193 } |
|
194 else |
|
195 { |
|
196 return KErrGeneral; |
|
197 } |
|
198 } |
|
199 |
|
200 /** |
|
201 Register for a callback when the monitored System-Wide-Property changes. |
|
202 @param aSubscriber The object to receive the callback |
|
203 */ |
|
204 EXPORT_C void CSsmSystemWideProperty::AddSubscriberL(MSwpChangeNotificationSubscriber& aSubscriber) |
|
205 { |
|
206 iSubscribers.AppendL(&aSubscriber); |
|
207 } |
|
208 |
|
209 /** |
|
210 Cancel callback subscription from the monitored System-Wide-Property. |
|
211 @param aSubscriber The object for which to cancel subsription. |
|
212 */ |
|
213 EXPORT_C void CSsmSystemWideProperty::RemoveSubscriber(const MSwpChangeNotificationSubscriber& aSubscriber) |
|
214 { |
|
215 const TInt index = iSubscribers.Find(&aSubscriber); |
|
216 if(index > KErrNotFound) |
|
217 { |
|
218 iSubscribers.Remove(index); |
|
219 |
|
220 const TInt KDefaultPtrArrayGranularity = 8; // from /cedar/generic/base/e32/common/array.cpp |
|
221 const TInt count = iSubscribers.Count(); |
|
222 if((count % KDefaultPtrArrayGranularity) == 0) |
|
223 { |
|
224 iSubscribers.Compress(); |
|
225 } |
|
226 } |
|
227 } |
|
228 |
|
229 /** |
|
230 Called from CSsmPropertyMonitor when the subsribed System-Wide-Property have changed. |
|
231 @internalComponent |
|
232 */ |
|
233 void CSsmSystemWideProperty::NotifySubscribers(TSsmSwp aSwp) |
|
234 { |
|
235 TInt count = iSubscribers.Count(); |
|
236 while (count--) |
|
237 { |
|
238 #ifdef _DEBUG |
|
239 TRAPD(err, iSubscribers[count]->SwpChanged(aSwp)); |
|
240 if(KErrNone != err) |
|
241 { |
|
242 DEBUGPRINT2A("Illegal leave (leavecode: %d) detected. Will be ignored", err); |
|
243 } |
|
244 #else |
|
245 TRAP_IGNORE(iSubscribers[count]->SwpChanged(aSwp)); |
|
246 #endif |
|
247 } |
|
248 } //lint !e1746 Suppress parameter 'aSwp' could be made const reference |
|
249 |