author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 19 Aug 2010 11:14:22 +0300 | |
branch | RCL_3 |
changeset 42 | a179b74831c9 |
parent 0 | a41df078684a |
permissions | -rw-r--r-- |
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 2 |
// All rights reserved. |
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "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 |
// domain\src\domaincli.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <e32base.h> |
|
19 |
#include <e32base_private.h> |
|
20 |
#include <e32property.h> |
|
21 |
||
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
22 |
|
0 | 23 |
#include <domainmember.h> |
24 |
#include <domainmanager.h> |
|
25 |
#include "domainobserver.h" |
|
26 |
#include "domainsrv.h" |
|
27 |
||
28 |
#define __DM_PANIC(aError) User::Panic(_L("domainCli.cpp"), (-(aError)) | (__LINE__ << 16)) |
|
29 |
#define __DM_ASSERT(aCond) __ASSERT_DEBUG(aCond,User::Panic(_L("domainCli.cpp; assertion failed"), __LINE__)) |
|
30 |
||
31 |
TInt RDmDomainSession::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId, TUint* aKey) |
|
32 |
{ |
|
33 |
TInt r = RSessionBase::CreateSession(KDmDomainServerNameLit, KDmDomainServerVersion, 1); |
|
34 |
if (r != KErrNone) |
|
35 |
return r; |
|
36 |
TIpcArgs a( (TInt)aHierarchyId, (TInt)aDomainId ); |
|
37 |
r = RSessionBase::SendReceive(EDmDomainJoin, a); |
|
38 |
if (r != KErrNone) |
|
39 |
{ |
|
40 |
RSessionBase::Close(); |
|
41 |
return r; |
|
42 |
} |
|
43 |
*aKey = DmStatePropertyKey( |
|
44 |
aHierarchyId, |
|
45 |
aDomainId); |
|
46 |
||
47 |
return KErrNone; |
|
48 |
} |
|
49 |
||
50 |
void RDmDomainSession::Acknowledge(TInt aValue, TInt aError) |
|
51 |
{ |
|
52 |
__DM_ASSERT(Handle() != KNullHandle); |
|
53 |
||
54 |
TIpcArgs a(aValue, aError); |
|
55 |
TInt r = RSessionBase::SendReceive(EDmStateAcknowledge, a); |
|
56 |
if (r != KErrNone) |
|
57 |
__DM_PANIC(r); |
|
58 |
} |
|
59 |
||
60 |
void RDmDomainSession::RequestTransitionNotification() |
|
61 |
{ |
|
62 |
__DM_ASSERT(Handle() != KNullHandle); |
|
63 |
TInt r = RSessionBase::SendReceive(EDmStateRequestTransitionNotification); |
|
64 |
if (r != KErrNone) |
|
65 |
__DM_PANIC(r); |
|
66 |
} |
|
67 |
||
68 |
void RDmDomainSession::CancelTransitionNotification() |
|
69 |
{ |
|
70 |
if (Handle() != KNullHandle) |
|
71 |
{ |
|
72 |
TInt r = RSessionBase::SendReceive(EDmStateCancelTransitionNotification); |
|
73 |
if (r != KErrNone) |
|
74 |
__DM_PANIC(r); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
||
79 |
||
80 |
/** |
|
81 |
Connects to the domain identified by the specified domain Id. |
|
82 |
||
83 |
To connect to the root domain, which has the Id KDmIdRoot, |
|
84 |
the capability WriteDeviceData is required. |
|
85 |
||
86 |
Once connected, an application can use this RDmDomain object to read |
|
87 |
the domain's power state and to request notification |
|
88 |
when the power state changes. |
|
89 |
||
90 |
@param aDomainId The identifier of the domain to be connected to. |
|
91 |
||
92 |
@return KErrNone, if successful; otherwise one of the other system-wide |
|
93 |
or domain manager specific error codes. |
|
94 |
||
95 |
@capability WriteDeviceData If aDomainId==KDmIdRoot |
|
96 |
*/ |
|
97 |
EXPORT_C TInt RDmDomain::Connect(TDmDomainId aDomainId) |
|
98 |
{ |
|
99 |
TUint key; |
|
100 |
TInt r = iSession.Connect(KDmHierarchyIdPower, aDomainId, &key); |
|
101 |
if (r != KErrNone) |
|
102 |
return r; |
|
103 |
r = iStateProperty.Attach(KUidDmPropertyCategory, key); |
|
104 |
if (r != KErrNone) |
|
105 |
{ |
|
106 |
iSession.Close(); |
|
107 |
return r; |
|
108 |
} |
|
109 |
return KErrNone; |
|
110 |
} |
|
111 |
||
112 |
||
113 |
||
114 |
||
115 |
/** |
|
116 |
Connects to the domain identified by the specified domain Id. |
|
117 |
||
118 |
To connect to the root domain, which has the Id KDmIdRoot, |
|
119 |
the capability WriteDeviceData is required. |
|
120 |
||
121 |
Once connected, an application can use this RDmDomain object to read |
|
122 |
the domain's state and to request notification |
|
123 |
when the state changes. |
|
124 |
||
125 |
@param aHierarchyId The Id of the domain hierarchy to connect to. |
|
126 |
@param aDomainId The identifier of the domain to be connected to. |
|
127 |
||
128 |
@return KErrNone, if successful; otherwise one of the other system-wide |
|
129 |
or domain manager specific error codes. |
|
130 |
||
131 |
@capability WriteDeviceData If aDomainId==KDmIdRoot |
|
132 |
*/ |
|
133 |
EXPORT_C TInt RDmDomain::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId) |
|
134 |
{ |
|
135 |
TUint key; |
|
136 |
TInt r = iSession.Connect(aHierarchyId, aDomainId, &key); |
|
137 |
if (r != KErrNone) |
|
138 |
return r; |
|
139 |
r = iStateProperty.Attach(KUidDmPropertyCategory, key); |
|
140 |
if (r != KErrNone) |
|
141 |
{ |
|
142 |
iSession.Close(); |
|
143 |
return r; |
|
144 |
} |
|
145 |
return KErrNone; |
|
146 |
} |
|
147 |
||
148 |
||
149 |
||
150 |
||
151 |
/** |
|
152 |
Disconnects from the associated domain. |
|
153 |
||
154 |
If this object is not connected to any domain, then it returns silently. |
|
155 |
*/ |
|
156 |
EXPORT_C void RDmDomain::Close() |
|
157 |
{ |
|
158 |
iSession.Close(); |
|
159 |
iStateProperty.Close(); |
|
160 |
} |
|
161 |
||
162 |
||
163 |
||
164 |
||
165 |
/** |
|
166 |
Requests notification when the domain's state changes. |
|
167 |
||
168 |
This is an asynchronous request that completes when |
|
169 |
the domain's state changes. |
|
170 |
||
171 |
@param aStatus The request status object for this asynchronous request. |
|
172 |
||
173 |
@see RDmDomain::CancelTransitionNotification() |
|
174 |
*/ |
|
175 |
EXPORT_C void RDmDomain::RequestTransitionNotification(TRequestStatus& aStatus) |
|
176 |
{ |
|
177 |
iStateProperty.Subscribe(aStatus); |
|
178 |
iSession.RequestTransitionNotification(); |
|
179 |
} |
|
180 |
||
181 |
||
182 |
||
183 |
||
184 |
/** |
|
185 |
Cancels an outstanding notification request. |
|
186 |
||
187 |
Any outstanding notification request completes with KErrCancel. |
|
188 |
*/ |
|
189 |
EXPORT_C void RDmDomain::CancelTransitionNotification() |
|
190 |
{ |
|
191 |
iSession.CancelTransitionNotification(); |
|
192 |
iStateProperty.Cancel(); |
|
193 |
} |
|
194 |
||
195 |
||
196 |
||
197 |
||
198 |
/** |
|
199 |
Gets the domain's power state. |
|
200 |
||
201 |
An application normally calls this function after a notification request |
|
202 |
has completed. It then performs any application-dependent action demanded by |
|
203 |
the power state, and then acknowledges the state transition. |
|
204 |
||
205 |
Note that the domain manager requires any domain power state change to be |
|
206 |
acknowledged by all applications connected to the domain. |
|
207 |
||
208 |
@return The connected domain's power state. |
|
209 |
||
210 |
@see RDmDomain::AcknowledgeLastState() |
|
211 |
*/ |
|
212 |
EXPORT_C TPowerState RDmDomain::GetPowerState() |
|
213 |
{ |
|
214 |
TInt value; |
|
215 |
TInt r = iStateProperty.Get(value); |
|
216 |
if (r != KErrNone) |
|
217 |
__DM_PANIC(r); |
|
218 |
iLastStatePropertyValue = value; |
|
219 |
return (TPowerState) DmStateFromPropertyValue(value); |
|
220 |
} |
|
221 |
||
222 |
||
223 |
||
224 |
||
225 |
/** |
|
226 |
Acknowledges the state change. |
|
227 |
||
228 |
An application must acknowledge that it has performed all actions required |
|
229 |
by the last known state of the domain. |
|
230 |
*/ |
|
231 |
EXPORT_C void RDmDomain::AcknowledgeLastState() |
|
232 |
{ |
|
233 |
iSession.Acknowledge(iLastStatePropertyValue, KErrNone); |
|
234 |
} |
|
235 |
||
236 |
||
237 |
/** |
|
238 |
Acknowledges the state change with the specified error |
|
239 |
||
240 |
An application must acknowledge that it has performed all actions required |
|
241 |
by the last known state of the domain. |
|
242 |
||
243 |
@param aError KDmErrNotJoin if domain is not part of the hierarhcy or a |
|
244 |
system wide error value associated with the state change. |
|
245 |
*/ |
|
246 |
EXPORT_C void RDmDomain::AcknowledgeLastState(TInt aError) |
|
247 |
{ |
|
248 |
iSession.Acknowledge(iLastStatePropertyValue, aError); |
|
249 |
} |
|
250 |
||
251 |
||
252 |
||
253 |
/** |
|
254 |
Gets the domain's state. |
|
255 |
||
256 |
An application normally calls this function after a notification request |
|
257 |
has completed. It then performs any application-dependent action demanded by |
|
258 |
the state, and then acknowledges the state transition. |
|
259 |
||
260 |
Note, that the domain manager requires any domain state change to be |
|
261 |
acknowledged by all applications connected to the domain. |
|
262 |
||
263 |
@return The connected domain's state. |
|
264 |
*/ |
|
265 |
EXPORT_C TDmDomainState RDmDomain::GetState() |
|
266 |
{ |
|
267 |
TInt value; |
|
268 |
TInt r = iStateProperty.Get(value); |
|
269 |
if (r != KErrNone) |
|
270 |
__DM_PANIC(r); |
|
271 |
iLastStatePropertyValue = value; |
|
272 |
return DmStateFromPropertyValue(value); |
|
273 |
} |
|
274 |
||
275 |
TInt RDmManagerSession::Connect() |
|
276 |
{ |
|
277 |
__DM_ASSERT(Handle() == KNullHandle); |
|
278 |
||
279 |
return RSessionBase::CreateSession( |
|
280 |
KDmManagerServerNameLit, |
|
281 |
KDmManagerServerVersion, |
|
282 |
2); |
|
283 |
} |
|
284 |
||
285 |
TInt RDmManagerSession::ConnectObserver(TDmHierarchyId aHierarchyId) |
|
286 |
{ |
|
287 |
TInt r = Connect(); |
|
288 |
if (r != KErrNone) |
|
289 |
return r; |
|
290 |
||
291 |
TIpcArgs a( (TInt)aHierarchyId); |
|
292 |
r = RSessionBase::SendReceive(EDmObserverJoin, a); |
|
293 |
if (r != KErrNone) |
|
294 |
{ |
|
295 |
RSessionBase::Close(); |
|
296 |
return r; |
|
297 |
} |
|
298 |
return KErrNone; |
|
299 |
} |
|
300 |
||
301 |
TInt RDmManagerSession::Connect(TDmHierarchyId aHierarchyId) |
|
302 |
{ |
|
303 |
TInt r = Connect(); |
|
304 |
if (r != KErrNone) |
|
305 |
return r; |
|
306 |
||
307 |
TIpcArgs a( (TInt)aHierarchyId); |
|
308 |
r = RSessionBase::SendReceive(EDmHierarchyJoin, a); |
|
309 |
if (r != KErrNone) |
|
310 |
{ |
|
311 |
RSessionBase::Close(); |
|
312 |
return r; |
|
313 |
} |
|
314 |
return KErrNone; |
|
315 |
} |
|
316 |
||
317 |
void RDmManagerSession::RequestDomainTransition( |
|
318 |
TDmDomainId aDomainId, |
|
319 |
TDmDomainState aState, |
|
320 |
TDmTraverseDirection aDirection, |
|
321 |
TRequestStatus& aStatus) |
|
322 |
{ |
|
323 |
__DM_ASSERT(Handle() != KNullHandle); |
|
324 |
||
325 |
if(aDirection < 0 || aDirection > ETraverseMax) |
|
326 |
__DM_PANIC(KErrArgument); |
|
327 |
||
328 |
TIpcArgs a(aDomainId, aState, aDirection); |
|
329 |
RSessionBase::SendReceive(EDmRequestDomainTransition, a, aStatus); |
|
330 |
} |
|
331 |
||
332 |
void RDmManagerSession::CancelTransition() |
|
333 |
{ |
|
334 |
if (Handle() != KNullHandle) |
|
335 |
{ |
|
336 |
TInt r = RSessionBase::SendReceive(EDmCancelTransition); |
|
337 |
if (r != KErrNone) |
|
338 |
__DM_PANIC(r); |
|
339 |
} |
|
340 |
} |
|
341 |
||
342 |
void RDmManagerSession::CancelObserver() |
|
343 |
{ |
|
344 |
if (Handle() != KNullHandle) |
|
345 |
{ |
|
346 |
TInt r = RSessionBase::SendReceive(EDmObserverCancel); |
|
347 |
if (r != KErrNone) |
|
348 |
__DM_PANIC(r); |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
void RDmManagerSession::RequestSystemTransition( |
|
353 |
TDmDomainState aState, |
|
354 |
TDmTraverseDirection aDirection, |
|
355 |
TRequestStatus& aStatus) |
|
356 |
{ |
|
357 |
__DM_ASSERT(Handle() != KNullHandle); |
|
358 |
||
359 |
TIpcArgs a(aState, aDirection); |
|
360 |
RSessionBase::SendReceive(EDmRequestSystemTransition, a, aStatus); |
|
361 |
} |
|
362 |
||
363 |
TInt RDmManagerSession::AddDomainHierarchy(TDmHierarchyId aHierarchyId) |
|
364 |
{ |
|
365 |
__DM_ASSERT(Handle() != KNullHandle); |
|
366 |
||
367 |
TIpcArgs a( (TInt)aHierarchyId); |
|
368 |
TInt r = RSessionBase::SendReceive(EDmHierarchyAdd, a); |
|
369 |
||
370 |
return r; |
|
371 |
} |
|
372 |
||
373 |
TInt RDmManagerSession::GetTransitionFailureCount() |
|
374 |
{ |
|
375 |
__DM_ASSERT(Handle() != KNullHandle); |
|
376 |
||
377 |
return RSessionBase::SendReceive(EDmGetTransitionFailureCount); |
|
378 |
} |
|
379 |
||
380 |
TInt RDmManagerSession::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures) |
|
381 |
{ |
|
382 |
__DM_ASSERT(Handle() != KNullHandle); |
|
383 |
||
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
|
0 | 385 |
aTransitionFailures.Reset(); |
386 |
||
387 |
TInt err = KErrNone; |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
|
0 | 389 |
TInt failureCount = GetTransitionFailureCount(); |
390 |
if (failureCount <= 0) |
|
391 |
return failureCount; |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
|
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
// Pre-allocate array with a known size which for this case is the value in failureCount |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
// in order to guarantee that future append operations to the array aTransitionFailures would |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
// not fail. This is assuming that the pre-allocated size is not exceeded. |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
err=aTransitionFailures.Reserve(failureCount); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
if (err != KErrNone) |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
return err; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
|
0 | 400 |
TTransitionFailure* failures = new TTransitionFailure[failureCount]; |
401 |
if(failures == NULL) |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
{ |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
aTransitionFailures.Reset(); |
0 | 404 |
return(KErrNoMemory); |
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
} |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
|
0 | 407 |
TPtr8 dataPtr(reinterpret_cast<TUint8*>(failures), failureCount * sizeof(TTransitionFailure)); |
408 |
||
409 |
TIpcArgs a(&dataPtr); |
|
410 |
err = RSessionBase::SendReceive(EDmGetTransitionFailures, a); |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
|
0 | 412 |
if (err == KErrNone) |
413 |
{ |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
for (TInt i=0; i<failureCount; i++) |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
{ |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
err = aTransitionFailures.Append(failures[i]); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
//The pre-allocation made above for the array aTransitionFailures should guarantee |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
//that append operations complete succesfully. |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
__DM_ASSERT(err == KErrNone); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
} |
0 | 421 |
} |
422 |
||
423 |
delete [] failures; |
|
424 |
||
425 |
return err; |
|
426 |
} |
|
427 |
||
428 |
TInt RDmManagerSession::StartObserver(TDmDomainId aDomainId, TDmNotifyType aNotifyType) |
|
429 |
{ |
|
430 |
__DM_ASSERT(Handle() != KNullHandle); |
|
431 |
||
432 |
TIpcArgs a(aDomainId,aNotifyType); |
|
433 |
return(RSessionBase::SendReceive(EDmObserverStart,a)); |
|
434 |
} |
|
435 |
||
436 |
void RDmManagerSession::GetNotification(TRequestStatus& aStatus) |
|
437 |
{ |
|
438 |
__DM_ASSERT(Handle() != KNullHandle); |
|
439 |
RSessionBase::SendReceive(EDmObserverNotify,aStatus); |
|
440 |
} |
|
441 |
||
442 |
TInt RDmManagerSession::GetEventCount() |
|
443 |
{ |
|
444 |
__DM_ASSERT(Handle() != KNullHandle); |
|
445 |
return(RSessionBase::SendReceive(EDmObserverEventCount)); |
|
446 |
} |
|
447 |
||
448 |
TInt RDmManagerSession::GetEvents(RArray<const TTransInfo>& aTransitions) |
|
449 |
{ |
|
450 |
__DM_ASSERT(Handle() != KNullHandle); |
|
451 |
||
452 |
aTransitions.Reset(); |
|
453 |
||
454 |
||
455 |
TInt count = GetEventCount(); |
|
456 |
// This shouldn't happen unless something gone terribly wrong |
|
457 |
if (count <= 0) |
|
458 |
return KErrGeneral; |
|
459 |
||
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
460 |
// Pre-allocate array with a known size which for this case is the value in count |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
461 |
// in order to guarantee that future append operations to the array aTransitionFailures |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
462 |
// would not fail. This is assuming that the pre-allocated size is not exceeded. |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
463 |
TInt ret=aTransitions.Reserve(count); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
464 |
if (ret != KErrNone) |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
return ret; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
466 |
|
0 | 467 |
TTransInfo* trans = new TTransInfo[count]; |
468 |
if(trans == NULL) |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
{ |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
aTransitions.Reset(); |
0 | 471 |
return(KErrNoMemory); |
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
472 |
} |
0 | 473 |
|
474 |
TPtr8 dataPtr(reinterpret_cast<TUint8*>(trans), count * sizeof(TTransInfo)); |
|
475 |
||
476 |
TIpcArgs a(&dataPtr); |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
ret=RSessionBase::SendReceive(EDmObserverGetEvent, a); |
0 | 478 |
|
479 |
if(ret==KErrNone) |
|
480 |
{ |
|
481 |
for (TInt i=0; i<count; i++) |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
{ |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
ret = aTransitions.Append(trans[i]); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
//The pre-allocation made above for the array aTransitions should guarantee |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
//that append operations complete succesfully. |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
__DM_ASSERT(ret == KErrNone); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
487 |
} |
0 | 488 |
} |
489 |
||
490 |
delete [] trans; |
|
491 |
return ret; |
|
492 |
||
493 |
} |
|
494 |
||
495 |
TInt RDmManagerSession::ObserverDomainCount() |
|
496 |
{ |
|
497 |
__DM_ASSERT(Handle() != KNullHandle); |
|
498 |
return(RSessionBase::SendReceive(EDmObserveredCount)); |
|
499 |
} |
|
500 |
||
501 |
/** |
|
502 |
@internalAll |
|
503 |
@released |
|
504 |
*/ |
|
505 |
EXPORT_C TInt RDmDomainManager::WaitForInitialization() |
|
506 |
{ |
|
507 |
RProperty prop; |
|
508 |
TInt r = prop.Attach(KUidDmPropertyCategory, KDmPropertyKeyInit); |
|
509 |
if (r != KErrNone) |
|
510 |
return r; |
|
511 |
||
512 |
#ifdef _DEBUG |
|
513 |
TInt count = RThread().RequestCount(); |
|
514 |
#endif |
|
515 |
||
516 |
TRequestStatus status; |
|
517 |
for (;;) |
|
518 |
{ |
|
519 |
prop.Subscribe(status); |
|
520 |
TInt value; |
|
521 |
r = prop.Get(value); |
|
522 |
if (r == KErrNone) |
|
523 |
{ |
|
524 |
if (value) break; // initialized |
|
525 |
// property exists but the server is not intialized yet |
|
526 |
} |
|
527 |
else |
|
528 |
{ |
|
529 |
if (r != KErrNotFound) break; // error |
|
530 |
// property doesn't exist yet |
|
531 |
} |
|
532 |
User::WaitForRequest(status); |
|
533 |
if (status.Int() != KErrNone) |
|
534 |
break; // error |
|
535 |
} |
|
536 |
||
537 |
if (status.Int() == KRequestPending) |
|
538 |
{ |
|
539 |
prop.Cancel(); |
|
540 |
User::WaitForRequest(status); |
|
541 |
} |
|
542 |
prop.Close(); |
|
543 |
||
544 |
__DM_ASSERT(RThread().RequestCount() == count); |
|
545 |
||
546 |
return r; |
|
547 |
} |
|
548 |
||
549 |
||
550 |
||
551 |
||
552 |
/** |
|
553 |
Opens a controlling connection to the standard power domain hierarchy |
|
554 |
in the domain manager. |
|
555 |
||
556 |
The domain manger allows only one open connection at any one time to the |
|
557 |
power domain hierarchy. |
|
558 |
Connection is usually made by the power policy entity. |
|
559 |
||
560 |
@return KErrNone, if successful; otherwise one of the other system-wide |
|
561 |
or the domain manager specific error codes. |
|
562 |
||
563 |
@see KDmErrAlreadyJoin |
|
564 |
*/ |
|
565 |
EXPORT_C TInt RDmDomainManager::Connect() |
|
566 |
{ |
|
567 |
return iSession.Connect(KDmHierarchyIdPower); |
|
568 |
} |
|
569 |
||
570 |
||
571 |
||
572 |
||
573 |
/** |
|
574 |
Opens a controlling connection to a specific domain hieararchy owned |
|
575 |
by the domain manager. |
|
576 |
||
577 |
The domain manger allows only one open connection at any one time to a |
|
578 |
particular hierarchy. |
|
579 |
||
580 |
@param aHierarchyId The Id of the domain hierarchy to connect to. |
|
581 |
||
582 |
@return KErrNone, if successful; otherwise one of the other system-wide |
|
583 |
or domain manager specific error codes. |
|
584 |
||
585 |
@see KDmErrAlreadyJoin |
|
586 |
@see KErrBadHierarchyId |
|
587 |
*/ |
|
588 |
EXPORT_C TInt RDmDomainManager::Connect(TDmHierarchyId aHierarchyId) |
|
589 |
||
590 |
{ |
|
591 |
return iSession.Connect(aHierarchyId); |
|
592 |
} |
|
593 |
||
594 |
||
595 |
||
596 |
||
597 |
/** |
|
598 |
Closes this connection to the domain manager. |
|
599 |
||
600 |
If there is no existing connection, then it returns silently. |
|
601 |
*/ |
|
602 |
EXPORT_C void RDmDomainManager::Close() |
|
603 |
{ |
|
604 |
iSession.Close(); |
|
605 |
} |
|
606 |
||
607 |
||
608 |
||
609 |
||
610 |
/** |
|
611 |
Requests a system-wide power state transition. |
|
612 |
||
613 |
The domain hierarchy is traversed in the default direction |
|
614 |
||
615 |
@param aState The target power state. |
|
616 |
@param aStatus The request status object for this asynchronous request. |
|
617 |
||
618 |
@see RDmDomainManager::CancelTransition() |
|
619 |
*/ |
|
620 |
EXPORT_C void RDmDomainManager::RequestSystemTransition(TPowerState aState, TRequestStatus& aStatus) |
|
621 |
{ |
|
622 |
if (aState == EPwActive) |
|
623 |
{ |
|
624 |
TRequestStatus* status = &aStatus; |
|
625 |
User::RequestComplete(status, KErrArgument); |
|
626 |
return; |
|
627 |
} |
|
628 |
RequestSystemTransition((TDmDomainState) aState, ETraverseDefault, aStatus); |
|
629 |
} |
|
630 |
||
631 |
||
632 |
||
633 |
||
634 |
/** |
|
635 |
Requests a system-wide power shutdown. |
|
636 |
||
637 |
This is a request to change the system's power state to EPwOff. |
|
638 |
This call does not return; the system can only return by rebooting. |
|
639 |
*/ |
|
640 |
EXPORT_C void RDmDomainManager::SystemShutdown() |
|
641 |
{ |
|
642 |
TRequestStatus status; |
|
643 |
RequestSystemTransition((TDmDomainState) EPwOff, ETraverseDefault, status); |
|
644 |
User::WaitForRequest(status); |
|
645 |
__DM_ASSERT(0); |
|
646 |
} |
|
647 |
||
648 |
||
649 |
||
650 |
||
651 |
/** |
|
652 |
Requests a domain state transition. |
|
653 |
||
654 |
The domain hierarchy is traversed in the default direction. |
|
655 |
||
656 |
@param aDomainId The Id of the domain for which the state transition |
|
657 |
is being requested. |
|
658 |
@param aState The target state. |
|
659 |
@param aStatus The request status object for this asynchronous request. |
|
660 |
||
661 |
@see RDmDomainManager::CancelTransition() |
|
662 |
*/ |
|
663 |
EXPORT_C void RDmDomainManager::RequestDomainTransition( |
|
664 |
TDmDomainId aDomainId, |
|
665 |
TPowerState aState, |
|
666 |
TRequestStatus& aStatus) |
|
667 |
{ |
|
668 |
RequestDomainTransition(aDomainId,(TDmDomainState) aState, ETraverseDefault, aStatus); |
|
669 |
} |
|
670 |
||
671 |
||
672 |
||
673 |
||
674 |
/** |
|
675 |
Cancels a state transition, whether initiated by a call |
|
676 |
to RequestSystemTransition() or RequestDomainTransition(). |
|
677 |
||
678 |
An outstanding state transition request completes with KErrCancel. |
|
679 |
*/ |
|
680 |
EXPORT_C void RDmDomainManager::CancelTransition() |
|
681 |
{ |
|
682 |
iSession.CancelTransition(); |
|
683 |
} |
|
684 |
||
685 |
||
686 |
||
687 |
||
688 |
/** |
|
689 |
Requests a system-wide state transition. |
|
690 |
||
691 |
The domain hierarchy is traversed in the specified direction. |
|
692 |
||
693 |
@param aState The target state. |
|
694 |
@param aDirection The direction in which to traverse the hierarchy |
|
695 |
@param aStatus The request status object for this asynchronous request. |
|
696 |
||
697 |
@see RDmDomainManager::CancelTransition() |
|
698 |
||
699 |
@panic domainCli.cpp; assertion failed VARNUM if the numerical value of aDirection |
|
700 |
is greater than the value of ETraverseMax. NOTE: VARNUM is the line number |
|
701 |
in the source code and may change if the implementation changes. |
|
702 |
*/ |
|
703 |
EXPORT_C void RDmDomainManager::RequestSystemTransition( |
|
704 |
TDmDomainState aState, |
|
705 |
TDmTraverseDirection aDirection, |
|
706 |
TRequestStatus& aStatus) |
|
707 |
{ |
|
708 |
__DM_ASSERT(aDirection <= ETraverseMax); |
|
709 |
iSession.RequestSystemTransition(aState, aDirection, aStatus); |
|
710 |
} |
|
711 |
||
712 |
||
713 |
||
714 |
||
715 |
/** |
|
716 |
Requests a domain state transition. |
|
717 |
||
718 |
The domain hierarchy is traversed in the specified direction |
|
719 |
||
720 |
@param aDomainId The Id of the domain for which the state transition |
|
721 |
is being requested. |
|
722 |
@param aState The target state. |
|
723 |
@param aDirection The direction in which to traverse the hierarchy. |
|
724 |
@param aStatus The request status object for this asynchronous request. |
|
725 |
||
726 |
@see RDmDomainManager::CancelTransition() |
|
727 |
||
728 |
@panic domainCli.cpp; assertion failed VARNUM if the numerical value of aDirection |
|
729 |
is greater than the value of ETraverseMax. NOTE: VARNUM is the line number |
|
730 |
in the source code and may change if the implementation changes. |
|
731 |
*/ |
|
732 |
EXPORT_C void RDmDomainManager::RequestDomainTransition( |
|
733 |
TDmDomainId aDomainId, |
|
734 |
TDmDomainState aState, |
|
735 |
TDmTraverseDirection aDirection, |
|
736 |
TRequestStatus& aStatus) |
|
737 |
{ |
|
738 |
__DM_ASSERT(aDirection <= ETraverseMax); |
|
739 |
iSession.RequestDomainTransition(aDomainId, aState, aDirection, aStatus); |
|
740 |
} |
|
741 |
||
742 |
||
743 |
||
744 |
||
745 |
/** |
|
746 |
Adds a domain hierarchy to the domain manager. |
|
747 |
||
748 |
@param aHierarchyId The Id of the domain hierarchy to be added. |
|
749 |
||
750 |
@return KErrNone if successful; otherwise one of the other system-wide |
|
751 |
or domain manager specific error codes. |
|
752 |
*/ |
|
753 |
EXPORT_C TInt RDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId) |
|
754 |
{ |
|
755 |
RDmManagerSession session; |
|
756 |
TInt r = session.Connect(); |
|
757 |
if (r != KErrNone) |
|
758 |
return r; |
|
759 |
r = session.AddDomainHierarchy(aHierarchyId); |
|
760 |
session.Close(); |
|
761 |
return r; |
|
762 |
} |
|
763 |
||
764 |
||
765 |
||
766 |
/** |
|
767 |
Requests a list of transition failures since the last transition request. |
|
768 |
||
769 |
@param aTransitionFailures A client-supplied array of TTransitionFailure objects which |
|
770 |
on exit will contain the failures that have occurred since the last transition |
|
771 |
request. |
|
772 |
@pre The session must be connected. |
|
773 |
||
774 |
@return KErrNone, if successful; otherwise one of the other system-wide |
|
775 |
or domain manager specific error codes. |
|
776 |
*/ |
|
777 |
EXPORT_C TInt RDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures) |
|
778 |
{ |
|
779 |
return iSession.GetTransitionFailures(aTransitionFailures); |
|
780 |
} |
|
781 |
||
782 |
||
783 |
||
784 |
/** |
|
785 |
Gets the number of transition failures since the last transition request. |
|
786 |
||
787 |
@return The number of failures, if successful; otherwise one of the other system-wide |
|
788 |
or domain manager specific error codes. |
|
789 |
*/ |
|
790 |
EXPORT_C TInt RDmDomainManager::GetTransitionFailureCount() |
|
791 |
{ |
|
792 |
return iSession.GetTransitionFailureCount(); |
|
793 |
} |
|
794 |
||
795 |
||
796 |
||
797 |
// CDmDomain |
|
798 |
||
799 |
/** |
|
800 |
Constructor. |
|
801 |
||
802 |
Adds this active object to the active scheduler. The priority of the active object |
|
803 |
is the standard value, i.e. CActive::EPriorityStandard. |
|
804 |
||
805 |
@param aHierarchyId The Id of the domain hierarchy to connect to. |
|
806 |
@param aDomainId The Id of the domain to connect to. |
|
807 |
||
808 |
@see CActive |
|
809 |
@see CActive::TPriority |
|
810 |
*/ |
|
811 |
EXPORT_C CDmDomain::CDmDomain(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId) : |
|
812 |
CActive(CActive::EPriorityStandard), |
|
813 |
iHierarchyId(aHierarchyId), |
|
814 |
iDomainId(aDomainId) |
|
815 |
{ |
|
816 |
CActiveScheduler::Add(this); |
|
817 |
} |
|
818 |
||
819 |
||
820 |
||
821 |
||
822 |
/** |
|
823 |
Destructor. |
|
824 |
||
825 |
Closes the session to the domain manager. |
|
826 |
*/ |
|
827 |
EXPORT_C CDmDomain::~CDmDomain() |
|
828 |
{ |
|
829 |
Cancel(); |
|
830 |
iDomain.Close(); |
|
831 |
} |
|
832 |
||
833 |
||
834 |
||
835 |
||
836 |
/** |
|
837 |
Second-phase constructor. |
|
838 |
||
839 |
The function attempts to connect to the domain specified in the constructor. |
|
840 |
||
841 |
@leave One of the system-wide error codes |
|
842 |
*/ |
|
843 |
EXPORT_C void CDmDomain::ConstructL() |
|
844 |
{ |
|
845 |
User::LeaveIfError(iDomain.Connect(iHierarchyId, iDomainId)); |
|
846 |
} |
|
847 |
||
848 |
||
849 |
||
850 |
||
851 |
/** |
|
852 |
Requests notification when the domain's state changes. |
|
853 |
||
854 |
RunL() will be called when this happens. |
|
855 |
*/ |
|
856 |
EXPORT_C void CDmDomain::RequestTransitionNotification() |
|
857 |
{ |
|
858 |
__DM_ASSERT(!IsActive()); |
|
859 |
iDomain.RequestTransitionNotification(iStatus); |
|
860 |
SetActive(); |
|
861 |
} |
|
862 |
||
863 |
||
864 |
||
865 |
||
866 |
/** |
|
867 |
Cancels an outstanding notification request. |
|
868 |
||
869 |
Any outstanding notification request completes with KErrCancel. |
|
870 |
*/ |
|
871 |
EXPORT_C void CDmDomain::DoCancel() |
|
872 |
{ |
|
873 |
iDomain.CancelTransitionNotification(); |
|
874 |
} |
|
875 |
||
876 |
||
877 |
||
878 |
||
879 |
/** |
|
880 |
Acknowledges the last state change. |
|
881 |
||
882 |
An application must acknowledge that it has performed all actions required |
|
883 |
by the last known state of the domain. |
|
884 |
||
885 |
@param aError The error to return to the domain manager. The client should |
|
886 |
set this to KErrNone if it successfully transitioned to the |
|
887 |
new state or to one of the system-wide error codes. |
|
888 |
*/ |
|
889 |
EXPORT_C void CDmDomain::AcknowledgeLastState(TInt aError) |
|
890 |
{ |
|
891 |
iDomain.AcknowledgeLastState(aError); |
|
892 |
} |
|
893 |
||
894 |
||
895 |
||
896 |
||
897 |
/** |
|
898 |
Gets the domain's state. |
|
899 |
||
900 |
An application normally calls this function after a notification request |
|
901 |
has completed. It then performs any application-dependent action demanded by |
|
902 |
the state, and then acknowledges the state transition. |
|
903 |
||
904 |
@return The connected domain's state. |
|
905 |
*/ |
|
906 |
EXPORT_C TDmDomainState CDmDomain::GetState() |
|
907 |
{ |
|
908 |
return iDomain.GetState(); |
|
909 |
} |
|
910 |
||
911 |
// CDmDomainManager |
|
912 |
||
913 |
/** |
|
914 |
Constructor. |
|
915 |
||
916 |
Adds this active object to the active scheduler. |
|
917 |
||
918 |
@param aHierarchyId The Id of the domain hierarchy to connect to |
|
919 |
*/ |
|
920 |
EXPORT_C CDmDomainManager::CDmDomainManager(TDmHierarchyId aHierarchyId) : |
|
921 |
CActive(CActive::EPriorityStandard), |
|
922 |
iHierarchyId(aHierarchyId) |
|
923 |
{ |
|
924 |
CActiveScheduler::Add(this); |
|
925 |
} |
|
926 |
||
927 |
||
928 |
||
929 |
||
930 |
/** |
|
931 |
Destructor. |
|
932 |
||
933 |
Closes the session to the domain manager. |
|
934 |
*/ |
|
935 |
EXPORT_C CDmDomainManager::~CDmDomainManager() |
|
936 |
{ |
|
937 |
Cancel(); |
|
938 |
iManager.Close(); |
|
939 |
} |
|
940 |
||
941 |
||
942 |
||
943 |
||
944 |
/** |
|
945 |
The second-phase constructor. |
|
946 |
||
947 |
This function attempts to connect to the hierarchy |
|
948 |
specified in the constructor. |
|
949 |
||
950 |
@leave One of the system-wide error codes. |
|
951 |
*/ |
|
952 |
EXPORT_C void CDmDomainManager::ConstructL() |
|
953 |
{ |
|
954 |
User::LeaveIfError(iManager.Connect(iHierarchyId)); |
|
955 |
} |
|
956 |
||
957 |
||
958 |
||
959 |
||
960 |
/** |
|
961 |
Requests a system-wide state transition. |
|
962 |
||
963 |
The domain hierarchy is traversed in the specified direction |
|
964 |
||
965 |
@param aState The target state. |
|
966 |
@param aDirection The direction in which to traverse the hierarchy. |
|
967 |
*/ |
|
968 |
EXPORT_C void CDmDomainManager::RequestSystemTransition(TDmDomainState aState, TDmTraverseDirection aDirection) |
|
969 |
{ |
|
970 |
__DM_ASSERT(!IsActive()); |
|
971 |
iStatus = KRequestPending; |
|
972 |
iManager.RequestSystemTransition(aState, aDirection, iStatus); |
|
973 |
SetActive(); |
|
974 |
} |
|
975 |
||
976 |
||
977 |
||
978 |
||
979 |
/** |
|
980 |
Requests a domain state transition. |
|
981 |
||
982 |
The domain hierarchy is traversed in the specified direction. |
|
983 |
||
984 |
@param aDomain The Id of the domain for which the state transition |
|
985 |
is being requested. |
|
986 |
@param aState The target state. |
|
987 |
@param aDirection The direction in which to traverse the hierarchy. |
|
988 |
*/ |
|
989 |
EXPORT_C void CDmDomainManager::RequestDomainTransition(TDmDomainId aDomain, TDmDomainState aState, TDmTraverseDirection aDirection) |
|
990 |
{ |
|
991 |
__DM_ASSERT(!IsActive()); |
|
992 |
iStatus = KRequestPending; |
|
993 |
iManager.RequestDomainTransition(aDomain, aState, aDirection, iStatus); |
|
994 |
SetActive(); |
|
995 |
} |
|
996 |
||
997 |
||
998 |
||
999 |
||
1000 |
/** |
|
1001 |
Adds a domain hierarchy to the domain manager. |
|
1002 |
||
1003 |
@param aHierarchyId The Id of the domain hierarchy to add |
|
1004 |
||
1005 |
@return KErrNone if successful; otherwise one of the other system-wide |
|
1006 |
or domain manager specific error codes. |
|
1007 |
*/ |
|
1008 |
EXPORT_C TInt CDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId) |
|
1009 |
{ |
|
1010 |
RDmManagerSession session; |
|
1011 |
TInt r = session.Connect(); |
|
1012 |
if (r != KErrNone) |
|
1013 |
return r; |
|
1014 |
r = session.AddDomainHierarchy(aHierarchyId); |
|
1015 |
session.Close(); |
|
1016 |
return r; |
|
1017 |
||
1018 |
} |
|
1019 |
||
1020 |
||
1021 |
||
1022 |
||
1023 |
/** |
|
1024 |
Cancels a pending event. |
|
1025 |
*/ |
|
1026 |
EXPORT_C void CDmDomainManager::DoCancel() |
|
1027 |
{ |
|
1028 |
iManager.CancelTransition(); |
|
1029 |
} |
|
1030 |
||
1031 |
||
1032 |
||
1033 |
||
1034 |
/** |
|
1035 |
Requests a list of transition failures since the last transition request. |
|
1036 |
||
1037 |
@param aTransitionFailures A client-supplied array of TTransitionFailure objects which |
|
1038 |
on exit will contain the failures that have occurred since the last transition |
|
1039 |
request. |
|
1040 |
@pre The session must be connected. |
|
1041 |
||
1042 |
@return KErrNone, if successful; otherwise one of the other system-wide |
|
1043 |
or domain manager specific error codes. |
|
1044 |
*/ |
|
1045 |
EXPORT_C TInt CDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures) |
|
1046 |
{ |
|
1047 |
return iManager.GetTransitionFailures(aTransitionFailures); |
|
1048 |
} |
|
1049 |
||
1050 |
||
1051 |
||
1052 |
||
1053 |
/** |
|
1054 |
Gets the number of transition failures since the last transition request. |
|
1055 |
||
1056 |
@return The number of failures if successful, otherwise one of the other system-wide |
|
1057 |
or domain manager specific error codes. |
|
1058 |
*/ |
|
1059 |
EXPORT_C TInt CDmDomainManager::GetTransitionFailureCount() |
|
1060 |
{ |
|
1061 |
return iManager.GetTransitionFailureCount(); |
|
1062 |
} |
|
1063 |
||
1064 |
||
1065 |
||
1066 |
||
1067 |
CHierarchyObserver::CHierarchyObserver(MHierarchyObserver& aHierarchyObserver, TDmHierarchyId aHierarchyId): |
|
1068 |
CActive(CActive::EPriorityStandard), |
|
1069 |
iHierarchyId(aHierarchyId), |
|
1070 |
iObserver(aHierarchyObserver) |
|
1071 |
{ |
|
1072 |
iTransitionEvents.Reset(); |
|
1073 |
CActiveScheduler::Add(this); |
|
1074 |
} |
|
1075 |
||
1076 |
||
1077 |
||
1078 |
||
1079 |
/** |
|
1080 |
Constructs a new observer on the domain hierarchy. |
|
1081 |
||
1082 |
Note that only one observer per domain hierarchy is allowed. |
|
1083 |
||
1084 |
@param aHierarchyObserver The implementation of the interface to the domain manager. |
|
1085 |
@param aHierarchyId The Id of the domain hierarchy. |
|
1086 |
||
1087 |
@return The newly created CHierarchyObserver object. |
|
1088 |
*/ |
|
1089 |
EXPORT_C CHierarchyObserver* CHierarchyObserver::NewL(MHierarchyObserver& aHierarchyObserver,TDmHierarchyId aHierarchyId) |
|
1090 |
{ |
|
1091 |
CHierarchyObserver* observer=new(ELeave)CHierarchyObserver(aHierarchyObserver,aHierarchyId); |
|
1092 |
||
1093 |
CleanupStack::PushL(observer); |
|
1094 |
User::LeaveIfError(observer->iSession.ConnectObserver(aHierarchyId)); |
|
1095 |
CleanupStack::Pop(); |
|
1096 |
||
1097 |
return(observer); |
|
1098 |
} |
|
1099 |
||
1100 |
||
1101 |
||
1102 |
||
1103 |
/** |
|
1104 |
Destructor. |
|
1105 |
||
1106 |
Frees resources prior to destruction of the object. |
|
1107 |
*/ |
|
1108 |
EXPORT_C CHierarchyObserver::~CHierarchyObserver() |
|
1109 |
{ |
|
1110 |
Cancel(); |
|
1111 |
iSession.Close(); |
|
1112 |
iTransitionEvents.Reset(); |
|
1113 |
} |
|
1114 |
||
1115 |
void CHierarchyObserver::DoCancel() |
|
1116 |
{ |
|
1117 |
iObserverStarted=EFalse; |
|
1118 |
iSession.CancelObserver(); |
|
1119 |
} |
|
1120 |
||
1121 |
void CHierarchyObserver::RunL() |
|
1122 |
// |
|
1123 |
// Process the reply to client's request for domain transition/failure |
|
1124 |
// |
|
1125 |
{ |
|
1126 |
||
1127 |
TInt ret= iSession.GetEvents(iTransitionEvents); |
|
1128 |
||
1129 |
User::LeaveIfError(ret); |
|
1130 |
||
1131 |
TInt count = iTransitionEvents.Count(); |
|
1132 |
||
1133 |
for(TInt i=0;i<count;i++) |
|
1134 |
{ |
|
1135 |
if(iTransitionEvents[i].iError==KErrNone) |
|
1136 |
iObserver.TransProgEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState); |
|
1137 |
else if(iTransitionEvents[i].iError==KDmErrOutstanding) |
|
1138 |
iObserver.TransReqEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState); |
|
1139 |
else |
|
1140 |
iObserver.TransFailEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState,iTransitionEvents[i].iError); |
|
1141 |
} |
|
1142 |
||
1143 |
GetNotification(); |
|
1144 |
} |
|
1145 |
||
1146 |
||
1147 |
||
1148 |
||
1149 |
/** |
|
1150 |
Starts the observer. |
|
1151 |
||
1152 |
@param aDomainId The Id of the domain to which the obsever is attached. |
|
1153 |
@param aNotifyType The type of notifications of interest to the observer. |
|
1154 |
||
1155 |
@return KErrNone on successful start, otherwise one of the other system wide error codes. |
|
1156 |
*/ |
|
1157 |
EXPORT_C TInt CHierarchyObserver::StartObserver(TDmDomainId aDomainId, TDmNotifyType aNotifyType) |
|
1158 |
{ |
|
1159 |
iNotifyType=aNotifyType; |
|
1160 |
iDomainId=aDomainId; |
|
1161 |
||
1162 |
TInt ret=iSession.StartObserver(iDomainId, iNotifyType); |
|
1163 |
if(ret!=KErrNone) |
|
1164 |
return ret; |
|
1165 |
iObserverStarted=ETrue; |
|
1166 |
GetNotification(); |
|
1167 |
return KErrNone; |
|
1168 |
} |
|
1169 |
||
1170 |
||
1171 |
||
1172 |
||
1173 |
/** |
|
1174 |
Stops the observer. |
|
1175 |
||
1176 |
@return KErrNone if successful; KDmErrBadSequence, if the observer |
|
1177 |
has not already started. |
|
1178 |
*/ |
|
1179 |
EXPORT_C TInt CHierarchyObserver::StopObserver() |
|
1180 |
{ |
|
1181 |
if(!iObserverStarted) |
|
1182 |
return(KDmErrBadSequence); |
|
1183 |
Cancel(); |
|
1184 |
return(KErrNone); |
|
1185 |
} |
|
1186 |
||
1187 |
void CHierarchyObserver::GetNotification() |
|
1188 |
{ |
|
1189 |
iSession.GetNotification(iStatus); |
|
1190 |
SetActive(); |
|
1191 |
} |
|
1192 |
||
1193 |
/** |
|
1194 |
Gets the number of domains that are being observed. |
|
1195 |
||
1196 |
This value is the number of children of the domain member to which the observer |
|
1197 |
is attached, including itself. |
|
1198 |
||
1199 |
@return The number of observed domain members. |
|
1200 |
One of the other system wide error codes may be returned on failure; |
|
1201 |
specifically KErrNotFound if the observer is not already started. |
|
1202 |
*/ |
|
1203 |
EXPORT_C TInt CHierarchyObserver::ObserverDomainCount() |
|
1204 |
{ |
|
1205 |
if(!iObserverStarted) |
|
1206 |
return KErrNotFound; |
|
1207 |
return(iSession.ObserverDomainCount()); |
|
1208 |
} |