243
|
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 |
|
243
|
22 |
|
0
|
23 |
#include <domainmember.h>
|
|
24 |
#include <domainmanager.h>
|
279
|
25 |
#include "domainmanager_private.h"
|
0
|
26 |
#include "domainobserver.h"
|
|
27 |
#include "domainsrv.h"
|
279
|
28 |
#include "domainmember_private.h"
|
0
|
29 |
|
|
30 |
#define __DM_PANIC(aError) User::Panic(_L("domainCli.cpp"), (-(aError)) | (__LINE__ << 16))
|
|
31 |
#define __DM_ASSERT(aCond) __ASSERT_DEBUG(aCond,User::Panic(_L("domainCli.cpp; assertion failed"), __LINE__))
|
|
32 |
|
|
33 |
TInt RDmDomainSession::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId, TUint* aKey)
|
|
34 |
{
|
|
35 |
TInt r = RSessionBase::CreateSession(KDmDomainServerNameLit, KDmDomainServerVersion, 1);
|
|
36 |
if (r != KErrNone)
|
|
37 |
return r;
|
|
38 |
TIpcArgs a( (TInt)aHierarchyId, (TInt)aDomainId );
|
|
39 |
r = RSessionBase::SendReceive(EDmDomainJoin, a);
|
|
40 |
if (r != KErrNone)
|
|
41 |
{
|
|
42 |
RSessionBase::Close();
|
|
43 |
return r;
|
|
44 |
}
|
|
45 |
*aKey = DmStatePropertyKey(
|
|
46 |
aHierarchyId,
|
|
47 |
aDomainId);
|
|
48 |
|
|
49 |
return KErrNone;
|
|
50 |
}
|
|
51 |
|
279
|
52 |
TInt RDmDomainSession::Acknowledge(TInt aValue, TInt aError)
|
0
|
53 |
{
|
|
54 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
55 |
|
|
56 |
TIpcArgs a(aValue, aError);
|
279
|
57 |
return RSessionBase::SendReceive(EDmStateAcknowledge, a);
|
0
|
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 |
|
279
|
79 |
void RDmDomainSession::DeferAcknowledgement(TRequestStatus& aStatus)
|
|
80 |
{
|
|
81 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
82 |
RSessionBase::SendReceive(EDmStateDeferAcknowledgement, aStatus);
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
void RDmDomainSession::CancelDeferral()
|
|
87 |
{
|
|
88 |
if (Handle() != KNullHandle)
|
|
89 |
{
|
|
90 |
TInt r = RSessionBase::SendReceive(EDmStateCancelDeferral);
|
|
91 |
if (r != KErrNone)
|
|
92 |
__DM_PANIC(r);
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
0
|
96 |
|
|
97 |
/**
|
|
98 |
Connects to the domain identified by the specified domain Id.
|
|
99 |
|
|
100 |
To connect to the root domain, which has the Id KDmIdRoot,
|
|
101 |
the capability WriteDeviceData is required.
|
|
102 |
|
|
103 |
Once connected, an application can use this RDmDomain object to read
|
|
104 |
the domain's power state and to request notification
|
|
105 |
when the power state changes.
|
|
106 |
|
|
107 |
@param aDomainId The identifier of the domain to be connected to.
|
|
108 |
|
|
109 |
@return KErrNone, if successful; otherwise one of the other system-wide
|
279
|
110 |
or Domain Manager specific error codes.
|
0
|
111 |
|
|
112 |
@capability WriteDeviceData If aDomainId==KDmIdRoot
|
|
113 |
*/
|
|
114 |
EXPORT_C TInt RDmDomain::Connect(TDmDomainId aDomainId)
|
|
115 |
{
|
|
116 |
TUint key;
|
|
117 |
TInt r = iSession.Connect(KDmHierarchyIdPower, aDomainId, &key);
|
|
118 |
if (r != KErrNone)
|
|
119 |
return r;
|
|
120 |
r = iStateProperty.Attach(KUidDmPropertyCategory, key);
|
|
121 |
if (r != KErrNone)
|
|
122 |
{
|
|
123 |
iSession.Close();
|
|
124 |
return r;
|
|
125 |
}
|
|
126 |
return KErrNone;
|
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
/**
|
|
133 |
Connects to the domain identified by the specified domain Id.
|
|
134 |
|
|
135 |
To connect to the root domain, which has the Id KDmIdRoot,
|
|
136 |
the capability WriteDeviceData is required.
|
|
137 |
|
|
138 |
Once connected, an application can use this RDmDomain object to read
|
|
139 |
the domain's state and to request notification
|
|
140 |
when the state changes.
|
|
141 |
|
|
142 |
@param aHierarchyId The Id of the domain hierarchy to connect to.
|
|
143 |
@param aDomainId The identifier of the domain to be connected to.
|
|
144 |
|
|
145 |
@return KErrNone, if successful; otherwise one of the other system-wide
|
279
|
146 |
or Domain Manager specific error codes.
|
0
|
147 |
|
|
148 |
@capability WriteDeviceData If aDomainId==KDmIdRoot
|
|
149 |
*/
|
|
150 |
EXPORT_C TInt RDmDomain::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId)
|
|
151 |
{
|
|
152 |
TUint key;
|
|
153 |
TInt r = iSession.Connect(aHierarchyId, aDomainId, &key);
|
|
154 |
if (r != KErrNone)
|
|
155 |
return r;
|
|
156 |
r = iStateProperty.Attach(KUidDmPropertyCategory, key);
|
|
157 |
if (r != KErrNone)
|
|
158 |
{
|
|
159 |
iSession.Close();
|
|
160 |
return r;
|
|
161 |
}
|
|
162 |
return KErrNone;
|
|
163 |
}
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
/**
|
|
169 |
Disconnects from the associated domain.
|
|
170 |
|
|
171 |
If this object is not connected to any domain, then it returns silently.
|
|
172 |
*/
|
|
173 |
EXPORT_C void RDmDomain::Close()
|
|
174 |
{
|
|
175 |
iSession.Close();
|
|
176 |
iStateProperty.Close();
|
|
177 |
}
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
/**
|
|
183 |
Requests notification when the domain's state changes.
|
|
184 |
|
|
185 |
This is an asynchronous request that completes when
|
|
186 |
the domain's state changes.
|
|
187 |
|
|
188 |
@param aStatus The request status object for this asynchronous request.
|
|
189 |
|
|
190 |
@see RDmDomain::CancelTransitionNotification()
|
|
191 |
*/
|
|
192 |
EXPORT_C void RDmDomain::RequestTransitionNotification(TRequestStatus& aStatus)
|
|
193 |
{
|
|
194 |
iStateProperty.Subscribe(aStatus);
|
|
195 |
iSession.RequestTransitionNotification();
|
|
196 |
}
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
/**
|
|
202 |
Cancels an outstanding notification request.
|
|
203 |
|
|
204 |
Any outstanding notification request completes with KErrCancel.
|
|
205 |
*/
|
|
206 |
EXPORT_C void RDmDomain::CancelTransitionNotification()
|
|
207 |
{
|
|
208 |
iSession.CancelTransitionNotification();
|
|
209 |
iStateProperty.Cancel();
|
|
210 |
}
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
/**
|
|
215 |
Gets the domain's power state.
|
279
|
216 |
|
0
|
217 |
An application normally calls this function after a notification request
|
|
218 |
has completed. It then performs any application-dependent action demanded by
|
|
219 |
the power state, and then acknowledges the state transition.
|
|
220 |
|
279
|
221 |
Note that the Domain Manager requires any domain power state change to be
|
0
|
222 |
acknowledged by all applications connected to the domain.
|
|
223 |
|
|
224 |
@return The connected domain's power state.
|
|
225 |
|
|
226 |
@see RDmDomain::AcknowledgeLastState()
|
|
227 |
*/
|
|
228 |
EXPORT_C TPowerState RDmDomain::GetPowerState()
|
|
229 |
{
|
|
230 |
TInt value;
|
|
231 |
TInt r = iStateProperty.Get(value);
|
|
232 |
if (r != KErrNone)
|
|
233 |
__DM_PANIC(r);
|
|
234 |
iLastStatePropertyValue = value;
|
|
235 |
return (TPowerState) DmStateFromPropertyValue(value);
|
|
236 |
}
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
/**
|
|
242 |
Acknowledges the state change.
|
279
|
243 |
|
0
|
244 |
An application must acknowledge that it has performed all actions required
|
|
245 |
by the last known state of the domain.
|
|
246 |
*/
|
|
247 |
EXPORT_C void RDmDomain::AcknowledgeLastState()
|
|
248 |
{
|
279
|
249 |
TInt r = iSession.Acknowledge(iLastStatePropertyValue, KErrNone);
|
|
250 |
|
|
251 |
if (r != KErrNone && r != KErrNotFound)
|
|
252 |
__DM_PANIC(r);
|
0
|
253 |
}
|
|
254 |
|
|
255 |
/**
|
|
256 |
Acknowledges the state change with the specified error
|
|
257 |
|
|
258 |
An application must acknowledge that it has performed all actions required
|
|
259 |
by the last known state of the domain.
|
|
260 |
|
279
|
261 |
@param aError KDmErrNotJoin if domain is not part of the hierarchy or a
|
0
|
262 |
system wide error value associated with the state change.
|
|
263 |
*/
|
|
264 |
EXPORT_C void RDmDomain::AcknowledgeLastState(TInt aError)
|
|
265 |
{
|
279
|
266 |
TInt r = iSession.Acknowledge(iLastStatePropertyValue, aError);
|
|
267 |
|
|
268 |
if (r != KErrNone && r != KErrNotFound)
|
|
269 |
__DM_PANIC(r);
|
|
270 |
}
|
|
271 |
|
|
272 |
/**
|
|
273 |
Acknowledges the state change with the specified error
|
|
274 |
|
|
275 |
@param aError KDmErrNotJoin if domain is not part of the hierarchy or a
|
|
276 |
system wide error value associated with the state change.
|
|
277 |
|
|
278 |
@return KErrNone If the acknowledgment was valid, KErrNotFound if it was spurious
|
|
279 |
*/
|
|
280 |
TInt RDmDomain::AcknowledgeLastStatePriv(TInt aError)
|
|
281 |
{
|
|
282 |
return iSession.Acknowledge(iLastStatePropertyValue, aError);
|
0
|
283 |
}
|
|
284 |
|
279
|
285 |
/**
|
|
286 |
Having received a state transition notification, instead of acknowledging,
|
|
287 |
request more time. To be sure of deferring in time a client should call this immediately
|
|
288 |
after receiving notification. This asynchronous call will complete once the original deadline
|
|
289 |
is reached (ie. one period earlier than the final deadline), at which point the member must either
|
|
290 |
defer again or acknowledge the transition. In the meantime, the member should perform
|
|
291 |
its transition actions, whilst remaining responsive to new completion events.
|
|
292 |
|
|
293 |
For example, if after receiving a transition notification, the client calls DeferAcknowledgement
|
|
294 |
once, but fails to acknowledge or renew its deferral, it would be timed out after two time periods.
|
|
295 |
|
|
296 |
Once the member has completed all necessary actions it should call AcknowledgeLastState
|
|
297 |
to indicate a successful transition (it need not wait for the completion of DeferAcknowledgement).
|
|
298 |
|
|
299 |
@note Deferrals are not always possible,
|
|
300 |
whether the member will actually be given more time depends on if
|
|
301 |
- The current transition allows deferrals at all.
|
|
302 |
- The member still has deferrals left - there may be a maximum number
|
|
303 |
allowed.
|
|
304 |
- The deferral request was received in time.
|
|
305 |
|
|
306 |
@param aStatus Status of request
|
|
307 |
- KErrNone Request has completed i.e. The member must either defer again or acknowledge.
|
|
308 |
- KErrCompletion The deferral was obsoleted by a subsequent call to AcknowledgeLastState.
|
|
309 |
- KErrNotSupported The current transition may not be deferred, or maximum deferral count reached.
|
|
310 |
- KErrCancel The deferral was cancelled.
|
|
311 |
- KErrNotReady Deferral attempted before a transition notification was received
|
|
312 |
or after the deadline for the previous one.
|
|
313 |
- KErrPermissionDenied The member lacked the necessary capabilities.
|
|
314 |
- KErrServerBusy A deferral was already outstanding.
|
|
315 |
|
|
316 |
This function is provided for members to inform the Domain Manager that they
|
|
317 |
are still active and are responding to a transition notification.
|
|
318 |
For example, a server may have to persist data using
|
|
319 |
the file server before shut down. Since this task should be allowed to complete
|
|
320 |
before shutdown continues, the member should defer the transition, and then persist
|
|
321 |
the data, using asynchronous calls.
|
|
322 |
|
|
323 |
At least one of the below capabilities is required in order to defer a
|
|
324 |
domain transition. Without them, the client will get KErrPermissionDenied.
|
|
325 |
|
|
326 |
@capability WriteDeviceData
|
|
327 |
@capability ProtServ
|
|
328 |
|
|
329 |
@pre The member has been notified of a transition which it has not yet acknowledged
|
|
330 |
*/
|
|
331 |
EXPORT_C void RDmDomain::DeferAcknowledgement(TRequestStatus& aStatus)
|
|
332 |
{
|
|
333 |
iSession.DeferAcknowledgement(aStatus);
|
|
334 |
}
|
|
335 |
|
|
336 |
|
|
337 |
/**
|
|
338 |
Will cancel a call of DeferAcknowledgement(), if one was pending.
|
|
339 |
|
|
340 |
If none was pending, it does nothing.
|
|
341 |
*/
|
|
342 |
EXPORT_C void RDmDomain::CancelDeferral()
|
|
343 |
{
|
|
344 |
iSession.CancelDeferral();
|
|
345 |
}
|
0
|
346 |
|
|
347 |
|
|
348 |
/**
|
|
349 |
Gets the domain's state.
|
279
|
350 |
|
0
|
351 |
An application normally calls this function after a notification request
|
|
352 |
has completed. It then performs any application-dependent action demanded by
|
|
353 |
the state, and then acknowledges the state transition.
|
|
354 |
|
279
|
355 |
Note, that the Domain Manager requires any domain state change to be
|
0
|
356 |
acknowledged by all applications connected to the domain.
|
|
357 |
|
|
358 |
@return The connected domain's state.
|
|
359 |
*/
|
|
360 |
EXPORT_C TDmDomainState RDmDomain::GetState()
|
|
361 |
{
|
|
362 |
TInt value;
|
|
363 |
TInt r = iStateProperty.Get(value);
|
|
364 |
if (r != KErrNone)
|
|
365 |
__DM_PANIC(r);
|
|
366 |
iLastStatePropertyValue = value;
|
|
367 |
return DmStateFromPropertyValue(value);
|
|
368 |
}
|
|
369 |
|
|
370 |
TInt RDmManagerSession::Connect()
|
|
371 |
{
|
|
372 |
__DM_ASSERT(Handle() == KNullHandle);
|
|
373 |
|
|
374 |
return RSessionBase::CreateSession(
|
|
375 |
KDmManagerServerNameLit,
|
|
376 |
KDmManagerServerVersion,
|
|
377 |
2);
|
|
378 |
}
|
|
379 |
|
|
380 |
TInt RDmManagerSession::ConnectObserver(TDmHierarchyId aHierarchyId)
|
|
381 |
{
|
|
382 |
TInt r = Connect();
|
|
383 |
if (r != KErrNone)
|
|
384 |
return r;
|
|
385 |
|
|
386 |
TIpcArgs a( (TInt)aHierarchyId);
|
|
387 |
r = RSessionBase::SendReceive(EDmObserverJoin, a);
|
|
388 |
if (r != KErrNone)
|
|
389 |
{
|
|
390 |
RSessionBase::Close();
|
|
391 |
return r;
|
|
392 |
}
|
|
393 |
return KErrNone;
|
|
394 |
}
|
|
395 |
|
|
396 |
TInt RDmManagerSession::Connect(TDmHierarchyId aHierarchyId)
|
|
397 |
{
|
|
398 |
TInt r = Connect();
|
|
399 |
if (r != KErrNone)
|
|
400 |
return r;
|
|
401 |
|
|
402 |
TIpcArgs a( (TInt)aHierarchyId);
|
|
403 |
r = RSessionBase::SendReceive(EDmHierarchyJoin, a);
|
|
404 |
if (r != KErrNone)
|
|
405 |
{
|
|
406 |
RSessionBase::Close();
|
|
407 |
return r;
|
|
408 |
}
|
|
409 |
return KErrNone;
|
|
410 |
}
|
|
411 |
|
|
412 |
void RDmManagerSession::RequestDomainTransition(
|
|
413 |
TDmDomainId aDomainId,
|
|
414 |
TDmDomainState aState,
|
|
415 |
TDmTraverseDirection aDirection,
|
|
416 |
TRequestStatus& aStatus)
|
|
417 |
{
|
|
418 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
419 |
|
|
420 |
if(aDirection < 0 || aDirection > ETraverseMax)
|
|
421 |
__DM_PANIC(KErrArgument);
|
|
422 |
|
|
423 |
TIpcArgs a(aDomainId, aState, aDirection);
|
|
424 |
RSessionBase::SendReceive(EDmRequestDomainTransition, a, aStatus);
|
|
425 |
}
|
|
426 |
|
|
427 |
void RDmManagerSession::CancelTransition()
|
|
428 |
{
|
|
429 |
if (Handle() != KNullHandle)
|
|
430 |
{
|
|
431 |
TInt r = RSessionBase::SendReceive(EDmCancelTransition);
|
|
432 |
if (r != KErrNone)
|
|
433 |
__DM_PANIC(r);
|
|
434 |
}
|
|
435 |
}
|
|
436 |
|
|
437 |
void RDmManagerSession::CancelObserver()
|
|
438 |
{
|
|
439 |
if (Handle() != KNullHandle)
|
|
440 |
{
|
|
441 |
TInt r = RSessionBase::SendReceive(EDmObserverCancel);
|
|
442 |
if (r != KErrNone)
|
|
443 |
__DM_PANIC(r);
|
|
444 |
}
|
|
445 |
}
|
|
446 |
|
|
447 |
void RDmManagerSession::RequestSystemTransition(
|
|
448 |
TDmDomainState aState,
|
|
449 |
TDmTraverseDirection aDirection,
|
|
450 |
TRequestStatus& aStatus)
|
|
451 |
{
|
|
452 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
453 |
|
|
454 |
TIpcArgs a(aState, aDirection);
|
|
455 |
RSessionBase::SendReceive(EDmRequestSystemTransition, a, aStatus);
|
|
456 |
}
|
|
457 |
|
|
458 |
TInt RDmManagerSession::AddDomainHierarchy(TDmHierarchyId aHierarchyId)
|
|
459 |
{
|
|
460 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
461 |
|
|
462 |
TIpcArgs a( (TInt)aHierarchyId);
|
|
463 |
TInt r = RSessionBase::SendReceive(EDmHierarchyAdd, a);
|
|
464 |
|
|
465 |
return r;
|
|
466 |
}
|
|
467 |
|
|
468 |
TInt RDmManagerSession::GetTransitionFailureCount()
|
|
469 |
{
|
|
470 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
471 |
|
|
472 |
return RSessionBase::SendReceive(EDmGetTransitionFailureCount);
|
|
473 |
}
|
|
474 |
|
|
475 |
TInt RDmManagerSession::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
|
|
476 |
{
|
|
477 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
478 |
|
243
|
479 |
|
0
|
480 |
aTransitionFailures.Reset();
|
|
481 |
|
|
482 |
TInt err = KErrNone;
|
243
|
483 |
|
0
|
484 |
TInt failureCount = GetTransitionFailureCount();
|
|
485 |
if (failureCount <= 0)
|
|
486 |
return failureCount;
|
243
|
487 |
|
|
488 |
// Pre-allocate array with a known size which for this case is the value in failureCount
|
|
489 |
// in order to guarantee that future append operations to the array aTransitionFailures would
|
|
490 |
// not fail. This is assuming that the pre-allocated size is not exceeded.
|
|
491 |
err=aTransitionFailures.Reserve(failureCount);
|
|
492 |
if (err != KErrNone)
|
|
493 |
return err;
|
|
494 |
|
0
|
495 |
TTransitionFailure* failures = new TTransitionFailure[failureCount];
|
|
496 |
if(failures == NULL)
|
243
|
497 |
{
|
|
498 |
aTransitionFailures.Reset();
|
0
|
499 |
return(KErrNoMemory);
|
243
|
500 |
}
|
|
501 |
|
0
|
502 |
TPtr8 dataPtr(reinterpret_cast<TUint8*>(failures), failureCount * sizeof(TTransitionFailure));
|
|
503 |
|
|
504 |
TIpcArgs a(&dataPtr);
|
|
505 |
err = RSessionBase::SendReceive(EDmGetTransitionFailures, a);
|
243
|
506 |
|
0
|
507 |
if (err == KErrNone)
|
|
508 |
{
|
243
|
509 |
for (TInt i=0; i<failureCount; i++)
|
|
510 |
{
|
|
511 |
err = aTransitionFailures.Append(failures[i]);
|
|
512 |
//The pre-allocation made above for the array aTransitionFailures should guarantee
|
|
513 |
//that append operations complete succesfully.
|
|
514 |
__DM_ASSERT(err == KErrNone);
|
|
515 |
}
|
0
|
516 |
}
|
|
517 |
|
|
518 |
delete [] failures;
|
|
519 |
|
|
520 |
return err;
|
|
521 |
}
|
|
522 |
|
|
523 |
TInt RDmManagerSession::StartObserver(TDmDomainId aDomainId, TDmNotifyType aNotifyType)
|
|
524 |
{
|
|
525 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
526 |
|
|
527 |
TIpcArgs a(aDomainId,aNotifyType);
|
|
528 |
return(RSessionBase::SendReceive(EDmObserverStart,a));
|
|
529 |
}
|
|
530 |
|
|
531 |
void RDmManagerSession::GetNotification(TRequestStatus& aStatus)
|
|
532 |
{
|
|
533 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
534 |
RSessionBase::SendReceive(EDmObserverNotify,aStatus);
|
|
535 |
}
|
|
536 |
|
|
537 |
TInt RDmManagerSession::GetEventCount()
|
|
538 |
{
|
|
539 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
540 |
return(RSessionBase::SendReceive(EDmObserverEventCount));
|
|
541 |
}
|
|
542 |
|
|
543 |
TInt RDmManagerSession::GetEvents(RArray<const TTransInfo>& aTransitions)
|
|
544 |
{
|
|
545 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
546 |
|
|
547 |
aTransitions.Reset();
|
|
548 |
|
|
549 |
|
|
550 |
TInt count = GetEventCount();
|
|
551 |
// This shouldn't happen unless something gone terribly wrong
|
|
552 |
if (count <= 0)
|
|
553 |
return KErrGeneral;
|
|
554 |
|
243
|
555 |
// Pre-allocate array with a known size which for this case is the value in count
|
|
556 |
// in order to guarantee that future append operations to the array aTransitionFailures
|
|
557 |
// would not fail. This is assuming that the pre-allocated size is not exceeded.
|
|
558 |
TInt ret=aTransitions.Reserve(count);
|
|
559 |
if (ret != KErrNone)
|
|
560 |
return ret;
|
|
561 |
|
0
|
562 |
TTransInfo* trans = new TTransInfo[count];
|
|
563 |
if(trans == NULL)
|
243
|
564 |
{
|
|
565 |
aTransitions.Reset();
|
0
|
566 |
return(KErrNoMemory);
|
243
|
567 |
}
|
0
|
568 |
|
|
569 |
TPtr8 dataPtr(reinterpret_cast<TUint8*>(trans), count * sizeof(TTransInfo));
|
|
570 |
|
|
571 |
TIpcArgs a(&dataPtr);
|
243
|
572 |
ret=RSessionBase::SendReceive(EDmObserverGetEvent, a);
|
0
|
573 |
|
|
574 |
if(ret==KErrNone)
|
|
575 |
{
|
|
576 |
for (TInt i=0; i<count; i++)
|
243
|
577 |
{
|
|
578 |
ret = aTransitions.Append(trans[i]);
|
|
579 |
//The pre-allocation made above for the array aTransitions should guarantee
|
|
580 |
//that append operations complete succesfully.
|
|
581 |
__DM_ASSERT(ret == KErrNone);
|
|
582 |
}
|
0
|
583 |
}
|
|
584 |
|
|
585 |
delete [] trans;
|
|
586 |
return ret;
|
|
587 |
|
|
588 |
}
|
|
589 |
|
|
590 |
TInt RDmManagerSession::ObserverDomainCount()
|
|
591 |
{
|
|
592 |
__DM_ASSERT(Handle() != KNullHandle);
|
|
593 |
return(RSessionBase::SendReceive(EDmObserveredCount));
|
|
594 |
}
|
|
595 |
|
279
|
596 |
|
|
597 |
|
|
598 |
//-- RDmDomainManager ---------------------------------------------------------
|
|
599 |
|
|
600 |
|
|
601 |
|
0
|
602 |
/**
|
279
|
603 |
Caller blocked until the Domain Manager server has started up and is ready
|
|
604 |
for requests.
|
|
605 |
|
|
606 |
@return KErrNone once the Domain Manager server is ready, otherwise one of the
|
|
607 |
other system wide or the Domain Manager specific error codes.
|
0
|
608 |
*/
|
|
609 |
EXPORT_C TInt RDmDomainManager::WaitForInitialization()
|
|
610 |
{
|
|
611 |
RProperty prop;
|
|
612 |
TInt r = prop.Attach(KUidDmPropertyCategory, KDmPropertyKeyInit);
|
|
613 |
if (r != KErrNone)
|
|
614 |
return r;
|
|
615 |
|
|
616 |
#ifdef _DEBUG
|
|
617 |
TInt count = RThread().RequestCount();
|
|
618 |
#endif
|
|
619 |
|
|
620 |
TRequestStatus status;
|
|
621 |
for (;;)
|
|
622 |
{
|
|
623 |
prop.Subscribe(status);
|
|
624 |
TInt value;
|
|
625 |
r = prop.Get(value);
|
|
626 |
if (r == KErrNone)
|
|
627 |
{
|
|
628 |
if (value) break; // initialized
|
279
|
629 |
// property exists but the server is not initialised yet
|
0
|
630 |
}
|
|
631 |
else
|
|
632 |
{
|
|
633 |
if (r != KErrNotFound) break; // error
|
|
634 |
// property doesn't exist yet
|
|
635 |
}
|
|
636 |
User::WaitForRequest(status);
|
|
637 |
if (status.Int() != KErrNone)
|
|
638 |
break; // error
|
|
639 |
}
|
|
640 |
|
|
641 |
if (status.Int() == KRequestPending)
|
|
642 |
{
|
|
643 |
prop.Cancel();
|
|
644 |
User::WaitForRequest(status);
|
|
645 |
}
|
|
646 |
prop.Close();
|
|
647 |
|
|
648 |
__DM_ASSERT(RThread().RequestCount() == count);
|
|
649 |
|
|
650 |
return r;
|
|
651 |
}
|
|
652 |
|
|
653 |
|
|
654 |
/**
|
|
655 |
Opens a controlling connection to the standard power domain hierarchy
|
279
|
656 |
in the Domain Manager.
|
0
|
657 |
|
279
|
658 |
The Domain Manager allows only one open connection at any one time to the
|
0
|
659 |
power domain hierarchy.
|
|
660 |
|
279
|
661 |
@return KErrNone if successful, otherwise one of the other system-wide
|
|
662 |
or the Domain Manager specific error codes.
|
|
663 |
@return KErrInUse when the power hierarchy already has a controller connected.
|
|
664 |
@return KErrBadHierarchyId when the server has failed to load the power hierarchy.
|
|
665 |
@return KErrPermissionDenied when the client has insufficient capabilities
|
|
666 |
|
|
667 |
@capability PowerMgmt Required to create a connection to the Domain Manager.
|
|
668 |
@see KDmHierarchyIdPower
|
0
|
669 |
*/
|
|
670 |
EXPORT_C TInt RDmDomainManager::Connect()
|
|
671 |
{
|
|
672 |
return iSession.Connect(KDmHierarchyIdPower);
|
|
673 |
}
|
|
674 |
|
|
675 |
|
279
|
676 |
/**
|
|
677 |
Opens a controlling connection to a specific domain hierarchy previously
|
|
678 |
loaded into the Domain Manager by the controller. The Domain Manager allows only
|
|
679 |
one open connection at any one time to a particular hierarchy.
|
0
|
680 |
|
279
|
681 |
@param aHierarchyId The Id of the domain hierarchy to connect to.
|
0
|
682 |
|
279
|
683 |
@return KErrNone if successful, otherwise one of the other system-wide
|
|
684 |
or the Domain Manager specific error codes.
|
|
685 |
@return KErrInUse when the power hierarchy already has a controller connected.
|
|
686 |
@return KErrBadHierarchyId when the server has failed to load the power hierarchy.
|
|
687 |
@return KErrPermissionDenied when the client has insufficient capabilities
|
|
688 |
|
|
689 |
@capability PowerMgmt Required to create a connection to the Domain Manager.
|
0
|
690 |
*/
|
|
691 |
EXPORT_C TInt RDmDomainManager::Connect(TDmHierarchyId aHierarchyId)
|
|
692 |
{
|
|
693 |
return iSession.Connect(aHierarchyId);
|
|
694 |
}
|
|
695 |
|
|
696 |
|
|
697 |
/**
|
279
|
698 |
Closes this connection to the Domain Manager.
|
0
|
699 |
|
|
700 |
If there is no existing connection, then it returns silently.
|
|
701 |
*/
|
|
702 |
EXPORT_C void RDmDomainManager::Close()
|
|
703 |
{
|
|
704 |
iSession.Close();
|
|
705 |
}
|
|
706 |
|
|
707 |
|
|
708 |
/**
|
279
|
709 |
Requests a system-wide power state transition and is used with the
|
|
710 |
KDmHierarchyIdPower hierarchy. The domain hierarchy is traversed in the
|
|
711 |
default direction.
|
0
|
712 |
|
279
|
713 |
A transition to the power state EPwActive is an error and result in
|
|
714 |
async completion with KErrArgument.
|
|
715 |
|
|
716 |
@param aState The target power state, not EPwActive or >=EPwLimit.
|
|
717 |
@param aStatus The request status object for this asynchronous request.
|
0
|
718 |
|
|
719 |
@see RDmDomainManager::CancelTransition()
|
279
|
720 |
@see KDmHierarchyIdPower
|
0
|
721 |
*/
|
|
722 |
EXPORT_C void RDmDomainManager::RequestSystemTransition(TPowerState aState, TRequestStatus& aStatus)
|
|
723 |
{
|
279
|
724 |
if ((aState == EPwActive) || (aState >= EPwLimit))
|
0
|
725 |
{
|
|
726 |
TRequestStatus* status = &aStatus;
|
|
727 |
User::RequestComplete(status, KErrArgument);
|
|
728 |
return;
|
|
729 |
}
|
|
730 |
RequestSystemTransition((TDmDomainState) aState, ETraverseDefault, aStatus);
|
|
731 |
}
|
|
732 |
|
|
733 |
|
279
|
734 |
/**
|
|
735 |
Requests a system-wide power off (EPwOff) state transition to shutdown the
|
|
736 |
platform. Applicable to the KDmHierarchyIdPower hierarchy.
|
0
|
737 |
|
279
|
738 |
This call does not return; the system can only return by physical button restart.
|
0
|
739 |
|
279
|
740 |
@see KDmHierarchyIdPower
|
0
|
741 |
*/
|
|
742 |
EXPORT_C void RDmDomainManager::SystemShutdown()
|
|
743 |
{
|
|
744 |
TRequestStatus status;
|
|
745 |
RequestSystemTransition((TDmDomainState) EPwOff, ETraverseDefault, status);
|
|
746 |
User::WaitForRequest(status);
|
|
747 |
__DM_ASSERT(0);
|
|
748 |
}
|
|
749 |
|
|
750 |
|
|
751 |
/**
|
279
|
752 |
Requests a domain power state transition and is used with the
|
|
753 |
KDmHierarchyIdPower hierarchy. The domain hierarchy is traversed in the
|
|
754 |
default direction.
|
0
|
755 |
|
|
756 |
@param aDomainId The Id of the domain for which the state transition
|
|
757 |
is being requested.
|
279
|
758 |
@param aState The target power state.
|
|
759 |
@param aStatus The request status object to receive the asynchronous result.
|
|
760 |
KErrNone if successful, otherwise one of the other system-wide
|
|
761 |
or the Domain Manager specific error codes.
|
|
762 |
|
|
763 |
@see KDmHierarchyIdPower
|
0
|
764 |
@see RDmDomainManager::CancelTransition()
|
|
765 |
*/
|
|
766 |
EXPORT_C void RDmDomainManager::RequestDomainTransition(
|
|
767 |
TDmDomainId aDomainId,
|
|
768 |
TPowerState aState,
|
|
769 |
TRequestStatus& aStatus)
|
|
770 |
{
|
|
771 |
RequestDomainTransition(aDomainId,(TDmDomainState) aState, ETraverseDefault, aStatus);
|
|
772 |
}
|
|
773 |
|
|
774 |
|
|
775 |
/**
|
279
|
776 |
Cancels an outstanding state transition, whether initiated by a call
|
0
|
777 |
to RequestSystemTransition() or RequestDomainTransition().
|
|
778 |
|
279
|
779 |
The outstanding state transition request completes with KErrCancel.
|
0
|
780 |
*/
|
|
781 |
EXPORT_C void RDmDomainManager::CancelTransition()
|
|
782 |
{
|
|
783 |
iSession.CancelTransition();
|
|
784 |
}
|
|
785 |
|
|
786 |
|
|
787 |
/**
|
279
|
788 |
Requests a state transition across the whole domain hierarchy that
|
|
789 |
this connection is controlling. The domain hierarchy is traversed in the
|
|
790 |
specified direction.
|
|
791 |
|
|
792 |
@param aState The target state, hierarchy specific state value.
|
|
793 |
@param aDirection The direction in which to traverse the hierarchy
|
|
794 |
@param aStatus The request status object to receive the asynchronous result.
|
|
795 |
KErrNone if successful, otherwise one of the other system-wide
|
|
796 |
or the Domain Manager specific error codes.
|
0
|
797 |
|
279
|
798 |
@panic domainCli.cpp; assertion failed line - if the numerical value of
|
|
799 |
aDirection is greater than the value of ETraverseMax.
|
0
|
800 |
|
|
801 |
@see RDmDomainManager::CancelTransition()
|
|
802 |
*/
|
|
803 |
EXPORT_C void RDmDomainManager::RequestSystemTransition(
|
|
804 |
TDmDomainState aState,
|
|
805 |
TDmTraverseDirection aDirection,
|
|
806 |
TRequestStatus& aStatus)
|
|
807 |
{
|
|
808 |
__DM_ASSERT(aDirection <= ETraverseMax);
|
|
809 |
iSession.RequestSystemTransition(aState, aDirection, aStatus);
|
|
810 |
}
|
|
811 |
|
|
812 |
|
|
813 |
|
|
814 |
/**
|
279
|
815 |
Requests a domain state transition for the hierarchy that this connection is
|
|
816 |
controlling. The domain hierarchy is traversed in the specified direction.
|
0
|
817 |
|
|
818 |
@param aDomainId The Id of the domain for which the state transition
|
|
819 |
is being requested.
|
|
820 |
@param aState The target state.
|
|
821 |
@param aDirection The direction in which to traverse the hierarchy.
|
279
|
822 |
@param aStatus The request status object to receive the asynchronous result.
|
|
823 |
KErrNone if successful, otherwise one of the other system-wide
|
|
824 |
or the Domain Manager specific error codes.
|
0
|
825 |
|
|
826 |
@panic domainCli.cpp; assertion failed VARNUM if the numerical value of aDirection
|
|
827 |
is greater than the value of ETraverseMax. NOTE: VARNUM is the line number
|
|
828 |
in the source code and may change if the implementation changes.
|
279
|
829 |
|
|
830 |
@see RDmDomainManager::CancelTransition()
|
0
|
831 |
*/
|
|
832 |
EXPORT_C void RDmDomainManager::RequestDomainTransition(
|
|
833 |
TDmDomainId aDomainId,
|
|
834 |
TDmDomainState aState,
|
|
835 |
TDmTraverseDirection aDirection,
|
|
836 |
TRequestStatus& aStatus)
|
|
837 |
{
|
|
838 |
__DM_ASSERT(aDirection <= ETraverseMax);
|
|
839 |
iSession.RequestDomainTransition(aDomainId, aState, aDirection, aStatus);
|
|
840 |
}
|
|
841 |
|
|
842 |
|
|
843 |
|
|
844 |
/**
|
279
|
845 |
Instructs the Domain Manager to load the domain hierarchy library for
|
|
846 |
aHierarchyId. The library takes the name "domainpolicyNN.dll" where NN is
|
|
847 |
the hierarchy number as supplied.
|
0
|
848 |
|
|
849 |
@param aHierarchyId The Id of the domain hierarchy to be added.
|
|
850 |
|
279
|
851 |
@return KErrNone if successful, otherwise one of the other system-wide
|
|
852 |
or the Domain Manager specific error codes.
|
|
853 |
@return KErrBadHierarchyId If the library is not found or contains invalid data
|
|
854 |
@return KErrPermissionDenied when the client has insufficient capabilities
|
|
855 |
|
|
856 |
@capability PowerMgmt Required to create a connection to the Domain Manager.
|
0
|
857 |
*/
|
|
858 |
EXPORT_C TInt RDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId)
|
|
859 |
{
|
|
860 |
RDmManagerSession session;
|
|
861 |
TInt r = session.Connect();
|
|
862 |
if (r != KErrNone)
|
|
863 |
return r;
|
|
864 |
r = session.AddDomainHierarchy(aHierarchyId);
|
|
865 |
session.Close();
|
|
866 |
return r;
|
|
867 |
}
|
|
868 |
|
|
869 |
|
|
870 |
/**
|
|
871 |
Requests a list of transition failures since the last transition request.
|
|
872 |
|
279
|
873 |
@param aTransitionFailures A client supplied array of TTransitionFailure objects
|
|
874 |
which on exit will contain the failures that have occurred since the
|
|
875 |
last transition request.
|
0
|
876 |
|
279
|
877 |
@return KErrNone if successful, otherwise one of the other system-wide
|
|
878 |
or the Domain Manager specific error codes.
|
0
|
879 |
*/
|
|
880 |
EXPORT_C TInt RDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
|
|
881 |
{
|
|
882 |
return iSession.GetTransitionFailures(aTransitionFailures);
|
|
883 |
}
|
|
884 |
|
|
885 |
|
|
886 |
/**
|
|
887 |
Gets the number of transition failures since the last transition request.
|
|
888 |
|
279
|
889 |
@return KErrNone if successful, otherwise one of the other system-wide
|
|
890 |
or the Domain Manager specific error codes.
|
0
|
891 |
*/
|
|
892 |
EXPORT_C TInt RDmDomainManager::GetTransitionFailureCount()
|
|
893 |
{
|
|
894 |
return iSession.GetTransitionFailureCount();
|
|
895 |
}
|
|
896 |
|
|
897 |
|
|
898 |
|
279
|
899 |
//-- CDmDomain ----------------------------------------------------------------
|
|
900 |
|
|
901 |
|
0
|
902 |
|
|
903 |
/**
|
|
904 |
Constructor.
|
|
905 |
|
|
906 |
Adds this active object to the active scheduler. The priority of the active object
|
|
907 |
is the standard value, i.e. CActive::EPriorityStandard.
|
|
908 |
|
|
909 |
@param aHierarchyId The Id of the domain hierarchy to connect to.
|
|
910 |
@param aDomainId The Id of the domain to connect to.
|
|
911 |
|
|
912 |
@see CActive
|
|
913 |
@see CActive::TPriority
|
|
914 |
*/
|
|
915 |
EXPORT_C CDmDomain::CDmDomain(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId) :
|
|
916 |
CActive(CActive::EPriorityStandard),
|
|
917 |
iHierarchyId(aHierarchyId),
|
|
918 |
iDomainId(aDomainId)
|
|
919 |
{
|
|
920 |
CActiveScheduler::Add(this);
|
|
921 |
}
|
|
922 |
|
|
923 |
|
|
924 |
|
|
925 |
|
|
926 |
/**
|
|
927 |
Destructor.
|
|
928 |
|
279
|
929 |
Closes the session to the Domain Manager.
|
0
|
930 |
*/
|
|
931 |
EXPORT_C CDmDomain::~CDmDomain()
|
|
932 |
{
|
|
933 |
Cancel();
|
|
934 |
iDomain.Close();
|
|
935 |
}
|
|
936 |
|
|
937 |
|
|
938 |
|
|
939 |
|
|
940 |
/**
|
|
941 |
Second-phase constructor.
|
|
942 |
|
|
943 |
The function attempts to connect to the domain specified in the constructor.
|
|
944 |
|
|
945 |
@leave One of the system-wide error codes
|
|
946 |
*/
|
|
947 |
EXPORT_C void CDmDomain::ConstructL()
|
|
948 |
{
|
|
949 |
User::LeaveIfError(iDomain.Connect(iHierarchyId, iDomainId));
|
|
950 |
}
|
|
951 |
|
|
952 |
|
|
953 |
|
|
954 |
|
|
955 |
/**
|
|
956 |
Requests notification when the domain's state changes.
|
|
957 |
|
|
958 |
RunL() will be called when this happens.
|
279
|
959 |
|
|
960 |
@note
|
|
961 |
If the client is ready to acknowledge the last transition, but
|
|
962 |
would like to register for notification of the next one, it
|
|
963 |
should call this function and then call AcknowledgeLastState,
|
|
964 |
immediately afterwards.
|
|
965 |
This eliminates the possibility of a transition occurring
|
|
966 |
between acknowledging and registering for notification.
|
0
|
967 |
*/
|
|
968 |
EXPORT_C void CDmDomain::RequestTransitionNotification()
|
|
969 |
{
|
|
970 |
__DM_ASSERT(!IsActive());
|
|
971 |
iDomain.RequestTransitionNotification(iStatus);
|
|
972 |
SetActive();
|
|
973 |
}
|
|
974 |
|
|
975 |
|
|
976 |
|
|
977 |
|
|
978 |
/**
|
|
979 |
Cancels an outstanding notification request.
|
|
980 |
|
|
981 |
Any outstanding notification request completes with KErrCancel.
|
|
982 |
*/
|
|
983 |
EXPORT_C void CDmDomain::DoCancel()
|
|
984 |
{
|
|
985 |
iDomain.CancelTransitionNotification();
|
|
986 |
}
|
|
987 |
|
|
988 |
|
|
989 |
|
|
990 |
|
|
991 |
/**
|
|
992 |
Acknowledges the last state change.
|
|
993 |
|
|
994 |
An application must acknowledge that it has performed all actions required
|
|
995 |
by the last known state of the domain.
|
|
996 |
|
279
|
997 |
@param aError The error to return to the Domain Manager. The client should
|
0
|
998 |
set this to KErrNone if it successfully transitioned to the
|
|
999 |
new state or to one of the system-wide error codes.
|
|
1000 |
*/
|
|
1001 |
EXPORT_C void CDmDomain::AcknowledgeLastState(TInt aError)
|
|
1002 |
{
|
|
1003 |
iDomain.AcknowledgeLastState(aError);
|
|
1004 |
}
|
|
1005 |
|
|
1006 |
|
|
1007 |
|
|
1008 |
|
|
1009 |
/**
|
|
1010 |
Gets the domain's state.
|
|
1011 |
|
|
1012 |
An application normally calls this function after a notification request
|
|
1013 |
has completed. It then performs any application-dependent action demanded by
|
|
1014 |
the state, and then acknowledges the state transition.
|
|
1015 |
|
|
1016 |
@return The connected domain's state.
|
|
1017 |
*/
|
|
1018 |
EXPORT_C TDmDomainState CDmDomain::GetState()
|
|
1019 |
{
|
|
1020 |
return iDomain.GetState();
|
|
1021 |
}
|
|
1022 |
|
279
|
1023 |
//-- CDmDomainKeepAlive ----------------------------------------------------------------
|
|
1024 |
|
|
1025 |
|
|
1026 |
/**
|
|
1027 |
Constructor.
|
|
1028 |
|
|
1029 |
Adds this active object to the active scheduler.
|
|
1030 |
|
|
1031 |
@param aHierarchyId The Id of the domain hierarchy to connect to.
|
|
1032 |
@param aDomainId The Id of the domain to connect to.
|
|
1033 |
|
|
1034 |
@see CActive
|
|
1035 |
*/
|
|
1036 |
EXPORT_C CDmDomainKeepAlive::CDmDomainKeepAlive(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId)
|
|
1037 |
: CDmDomain(aHierarchyId, aDomainId), iKeepAlive(NULL)
|
|
1038 |
{
|
|
1039 |
}
|
|
1040 |
|
|
1041 |
/**
|
|
1042 |
Destructor.
|
|
1043 |
|
|
1044 |
Cleanup the internal CDmKeepAlive active object.
|
|
1045 |
*/
|
|
1046 |
EXPORT_C CDmDomainKeepAlive::~CDmDomainKeepAlive()
|
|
1047 |
{
|
|
1048 |
delete iKeepAlive;
|
|
1049 |
}
|
|
1050 |
|
|
1051 |
/**
|
|
1052 |
Complete construction of this object. Classes derived from this one
|
|
1053 |
should call this as part of their ConstructL or NewL functions.
|
|
1054 |
*/
|
|
1055 |
EXPORT_C void CDmDomainKeepAlive::ConstructL()
|
|
1056 |
{
|
|
1057 |
CDmDomain::ConstructL();
|
|
1058 |
iKeepAlive = new (ELeave) CDmKeepAlive(iDomain, *this);
|
|
1059 |
}
|
|
1060 |
|
|
1061 |
/**
|
|
1062 |
Acknowledges the last state change.
|
|
1063 |
|
|
1064 |
An application must acknowledge that it has performed all actions required
|
|
1065 |
by the last known state of the domain.
|
|
1066 |
|
|
1067 |
Once this is done the AO will no longer attempt to defer deadlines.
|
|
1068 |
|
|
1069 |
@param aError The error to return to the Domain Manager. The client should
|
|
1070 |
set this to KErrNone if it successfully transitioned to the
|
|
1071 |
new state or to one of the system-wide error codes.
|
|
1072 |
*/
|
|
1073 |
EXPORT_C void CDmDomainKeepAlive::AcknowledgeLastState(TInt aError)
|
|
1074 |
{
|
|
1075 |
TInt r = iDomain.AcknowledgeLastStatePriv(aError);
|
|
1076 |
if (r != KErrNone && r != KErrNotFound)
|
|
1077 |
__DM_PANIC(r);
|
|
1078 |
|
|
1079 |
if (r == KErrNone)
|
|
1080 |
{
|
|
1081 |
// KErrNone indicates that an acknowledgment was accepted
|
|
1082 |
// (as opposed to being spurious or late)
|
|
1083 |
|
|
1084 |
iKeepAlive->NotifyOfAcknowledgment();
|
|
1085 |
}
|
|
1086 |
}
|
|
1087 |
|
|
1088 |
/**
|
|
1089 |
Handle completion of request notifications, begins deferrals.
|
|
1090 |
|
|
1091 |
@note Clients should not need to override this, they
|
|
1092 |
will be notified of events via calls to HandleTransitionL.
|
|
1093 |
*/
|
|
1094 |
EXPORT_C void CDmDomainKeepAlive::RunL()
|
|
1095 |
{
|
|
1096 |
iKeepAlive->DeferNotification();
|
|
1097 |
HandleTransitionL();
|
|
1098 |
}
|
|
1099 |
|
|
1100 |
/**
|
|
1101 |
This object will internally, use RDmDomain::DeferAcknowledgement.
|
|
1102 |
|
|
1103 |
The default implementation of this function will simply ignore errors
|
|
1104 |
from RDmDomain::DeferAcknowledgement that
|
|
1105 |
it presumes the client can not or need not handle.
|
|
1106 |
|
|
1107 |
ie.
|
|
1108 |
KErrCompletion - Client has now acknowledged notification - not an error.
|
|
1109 |
KErrCancel - Server cancelled request - client can do nothing.
|
|
1110 |
KErrNotSupported - Deferral not possible - client can do nothing.
|
|
1111 |
KErrNotReady - Deferral too late or too early - client can do nothing.
|
|
1112 |
|
|
1113 |
All other error codes will be returned unhandled to the active scheduler,
|
|
1114 |
leading to a panic.
|
|
1115 |
|
|
1116 |
If the client does want to handle or inspect these errors e.g. for diagnostic
|
|
1117 |
purposes, they can override this method. KErrNone should be returned
|
|
1118 |
for errors that should not be passed to the active scheduler.
|
|
1119 |
|
|
1120 |
@param aError Error code to handle
|
|
1121 |
*/
|
|
1122 |
EXPORT_C TInt CDmDomainKeepAlive::HandleDeferralError(TInt aError)
|
|
1123 |
{
|
|
1124 |
switch (aError)
|
|
1125 |
{
|
|
1126 |
case KErrCompletion:
|
|
1127 |
case KErrCancel:
|
|
1128 |
case KErrNotSupported:
|
|
1129 |
case KErrNotReady:
|
|
1130 |
{
|
|
1131 |
// All the above error codes may occur but signal only
|
|
1132 |
// that Deferrals should not continue for the current
|
|
1133 |
// transition.
|
|
1134 |
return KErrNone;
|
|
1135 |
}
|
|
1136 |
case KErrPermissionDenied:
|
|
1137 |
case KErrServerBusy:
|
|
1138 |
default:
|
|
1139 |
{
|
|
1140 |
return aError;
|
|
1141 |
}
|
|
1142 |
}
|
|
1143 |
}
|
|
1144 |
|
|
1145 |
//-- CDmKeepAlive ----------------------------------------------------------------
|
|
1146 |
|
|
1147 |
CDmKeepAlive::CDmKeepAlive(RDmDomain& aDomain, CDmDomainKeepAlive& aOwnerActiveObject)
|
|
1148 |
: CActive(CActive::EPriorityHigh), iDomain(aDomain), iOwnerActiveObject(aOwnerActiveObject), iCeaseDeferral(EFalse)
|
|
1149 |
{
|
|
1150 |
CActiveScheduler::Add(this);
|
|
1151 |
}
|
|
1152 |
|
|
1153 |
CDmKeepAlive::~CDmKeepAlive()
|
|
1154 |
{
|
|
1155 |
Cancel();
|
|
1156 |
}
|
|
1157 |
|
|
1158 |
void CDmKeepAlive::DeferNotification()
|
|
1159 |
{
|
|
1160 |
__DM_ASSERT(!IsActive());
|
|
1161 |
iStatus = KRequestPending;
|
|
1162 |
iDomain.DeferAcknowledgement(iStatus);
|
|
1163 |
SetActive();
|
|
1164 |
}
|
|
1165 |
|
|
1166 |
/**
|
|
1167 |
Informs the object that the state transition has
|
|
1168 |
been _successfully_ acknowledged
|
|
1169 |
*/
|
|
1170 |
void CDmKeepAlive::NotifyOfAcknowledgment()
|
|
1171 |
{
|
|
1172 |
if (IsActive())
|
|
1173 |
{
|
|
1174 |
iCeaseDeferral = ETrue;
|
|
1175 |
}
|
|
1176 |
}
|
|
1177 |
|
|
1178 |
void CDmKeepAlive::RunL()
|
|
1179 |
{
|
|
1180 |
const TInt error = iStatus.Int();
|
|
1181 |
|
|
1182 |
TBool ceaseDeferral = iCeaseDeferral;
|
|
1183 |
iCeaseDeferral = EFalse;
|
|
1184 |
|
|
1185 |
User::LeaveIfError(error);
|
|
1186 |
|
|
1187 |
// If a valid acknowledgment
|
|
1188 |
// has occured since the last deferral
|
|
1189 |
// then avoid deferring again since
|
|
1190 |
// this would only lead to KErrNotReady
|
|
1191 |
if(!ceaseDeferral)
|
|
1192 |
{
|
|
1193 |
DeferNotification();
|
|
1194 |
}
|
|
1195 |
else
|
|
1196 |
{
|
|
1197 |
// At this point we know error == KErrNone
|
|
1198 |
// However, we return the error code KErrCompletion, as this
|
|
1199 |
// is what would have happened, had the acknowledgment come in
|
|
1200 |
// a little earlier,
|
|
1201 |
// whilst the deferral was still outstanding on the server.
|
|
1202 |
User::Leave(KErrCompletion);
|
|
1203 |
}
|
|
1204 |
}
|
|
1205 |
|
|
1206 |
TInt CDmKeepAlive::RunError(TInt aError)
|
|
1207 |
{
|
|
1208 |
return iOwnerActiveObject.HandleDeferralError(aError);
|
|
1209 |
}
|
|
1210 |
|
|
1211 |
void CDmKeepAlive::DoCancel()
|
|
1212 |
{
|
|
1213 |
iDomain.CancelDeferral();
|
|
1214 |
}
|
|
1215 |
|
0
|
1216 |
// CDmDomainManager
|
|
1217 |
|
|
1218 |
/**
|
|
1219 |
Constructor.
|
|
1220 |
|
|
1221 |
Adds this active object to the active scheduler.
|
|
1222 |
|
|
1223 |
@param aHierarchyId The Id of the domain hierarchy to connect to
|
|
1224 |
*/
|
|
1225 |
EXPORT_C CDmDomainManager::CDmDomainManager(TDmHierarchyId aHierarchyId) :
|
|
1226 |
CActive(CActive::EPriorityStandard),
|
|
1227 |
iHierarchyId(aHierarchyId)
|
|
1228 |
{
|
|
1229 |
CActiveScheduler::Add(this);
|
|
1230 |
}
|
|
1231 |
|
|
1232 |
|
|
1233 |
|
|
1234 |
|
|
1235 |
/**
|
|
1236 |
Destructor.
|
|
1237 |
|
279
|
1238 |
Closes the session to the Domain Manager.
|
0
|
1239 |
*/
|
|
1240 |
EXPORT_C CDmDomainManager::~CDmDomainManager()
|
|
1241 |
{
|
|
1242 |
Cancel();
|
|
1243 |
iManager.Close();
|
|
1244 |
}
|
|
1245 |
|
|
1246 |
|
|
1247 |
|
|
1248 |
|
|
1249 |
/**
|
|
1250 |
The second-phase constructor.
|
|
1251 |
|
|
1252 |
This function attempts to connect to the hierarchy
|
|
1253 |
specified in the constructor.
|
|
1254 |
|
|
1255 |
@leave One of the system-wide error codes.
|
|
1256 |
*/
|
|
1257 |
EXPORT_C void CDmDomainManager::ConstructL()
|
|
1258 |
{
|
|
1259 |
User::LeaveIfError(iManager.Connect(iHierarchyId));
|
|
1260 |
}
|
|
1261 |
|
|
1262 |
|
|
1263 |
|
|
1264 |
|
|
1265 |
/**
|
|
1266 |
Requests a system-wide state transition.
|
|
1267 |
|
|
1268 |
The domain hierarchy is traversed in the specified direction
|
|
1269 |
|
|
1270 |
@param aState The target state.
|
|
1271 |
@param aDirection The direction in which to traverse the hierarchy.
|
|
1272 |
*/
|
|
1273 |
EXPORT_C void CDmDomainManager::RequestSystemTransition(TDmDomainState aState, TDmTraverseDirection aDirection)
|
|
1274 |
{
|
|
1275 |
__DM_ASSERT(!IsActive());
|
|
1276 |
iStatus = KRequestPending;
|
|
1277 |
iManager.RequestSystemTransition(aState, aDirection, iStatus);
|
|
1278 |
SetActive();
|
|
1279 |
}
|
|
1280 |
|
|
1281 |
|
|
1282 |
|
|
1283 |
|
|
1284 |
/**
|
|
1285 |
Requests a domain state transition.
|
|
1286 |
|
|
1287 |
The domain hierarchy is traversed in the specified direction.
|
|
1288 |
|
|
1289 |
@param aDomain The Id of the domain for which the state transition
|
|
1290 |
is being requested.
|
|
1291 |
@param aState The target state.
|
|
1292 |
@param aDirection The direction in which to traverse the hierarchy.
|
|
1293 |
*/
|
|
1294 |
EXPORT_C void CDmDomainManager::RequestDomainTransition(TDmDomainId aDomain, TDmDomainState aState, TDmTraverseDirection aDirection)
|
|
1295 |
{
|
|
1296 |
__DM_ASSERT(!IsActive());
|
|
1297 |
iStatus = KRequestPending;
|
|
1298 |
iManager.RequestDomainTransition(aDomain, aState, aDirection, iStatus);
|
|
1299 |
SetActive();
|
|
1300 |
}
|
|
1301 |
|
|
1302 |
|
|
1303 |
|
|
1304 |
|
|
1305 |
/**
|
279
|
1306 |
Adds a domain hierarchy to the Domain Manager.
|
0
|
1307 |
|
|
1308 |
@param aHierarchyId The Id of the domain hierarchy to add
|
|
1309 |
|
|
1310 |
@return KErrNone if successful; otherwise one of the other system-wide
|
279
|
1311 |
or Domain Manager specific error codes.
|
0
|
1312 |
*/
|
|
1313 |
EXPORT_C TInt CDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId)
|
|
1314 |
{
|
|
1315 |
RDmManagerSession session;
|
|
1316 |
TInt r = session.Connect();
|
|
1317 |
if (r != KErrNone)
|
|
1318 |
return r;
|
|
1319 |
r = session.AddDomainHierarchy(aHierarchyId);
|
|
1320 |
session.Close();
|
|
1321 |
return r;
|
|
1322 |
|
|
1323 |
}
|
|
1324 |
|
|
1325 |
|
|
1326 |
|
|
1327 |
|
|
1328 |
/**
|
|
1329 |
Cancels a pending event.
|
|
1330 |
*/
|
|
1331 |
EXPORT_C void CDmDomainManager::DoCancel()
|
|
1332 |
{
|
|
1333 |
iManager.CancelTransition();
|
|
1334 |
}
|
|
1335 |
|
|
1336 |
|
|
1337 |
|
|
1338 |
|
|
1339 |
/**
|
|
1340 |
Requests a list of transition failures since the last transition request.
|
|
1341 |
|
|
1342 |
@param aTransitionFailures A client-supplied array of TTransitionFailure objects which
|
|
1343 |
on exit will contain the failures that have occurred since the last transition
|
|
1344 |
request.
|
|
1345 |
@pre The session must be connected.
|
|
1346 |
|
|
1347 |
@return KErrNone, if successful; otherwise one of the other system-wide
|
279
|
1348 |
or Domain Manager specific error codes.
|
0
|
1349 |
*/
|
|
1350 |
EXPORT_C TInt CDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
|
|
1351 |
{
|
|
1352 |
return iManager.GetTransitionFailures(aTransitionFailures);
|
|
1353 |
}
|
|
1354 |
|
|
1355 |
|
|
1356 |
|
|
1357 |
|
|
1358 |
/**
|
|
1359 |
Gets the number of transition failures since the last transition request.
|
|
1360 |
|
|
1361 |
@return The number of failures if successful, otherwise one of the other system-wide
|
279
|
1362 |
or Domain Manager specific error codes.
|
0
|
1363 |
*/
|
|
1364 |
EXPORT_C TInt CDmDomainManager::GetTransitionFailureCount()
|
|
1365 |
{
|
|
1366 |
return iManager.GetTransitionFailureCount();
|
|
1367 |
}
|
|
1368 |
|
|
1369 |
|
|
1370 |
|
|
1371 |
|
|
1372 |
CHierarchyObserver::CHierarchyObserver(MHierarchyObserver& aHierarchyObserver, TDmHierarchyId aHierarchyId):
|
|
1373 |
CActive(CActive::EPriorityStandard),
|
|
1374 |
iHierarchyId(aHierarchyId),
|
|
1375 |
iObserver(aHierarchyObserver)
|
|
1376 |
{
|
|
1377 |
iTransitionEvents.Reset();
|
|
1378 |
CActiveScheduler::Add(this);
|
|
1379 |
}
|
|
1380 |
|
|
1381 |
|
|
1382 |
|
|
1383 |
|
|
1384 |
/**
|
|
1385 |
Constructs a new observer on the domain hierarchy.
|
|
1386 |
|
|
1387 |
Note that only one observer per domain hierarchy is allowed.
|
|
1388 |
|
279
|
1389 |
@param aHierarchyObserver The implementation of the interface to the Domain Manager.
|
0
|
1390 |
@param aHierarchyId The Id of the domain hierarchy.
|
|
1391 |
|
|
1392 |
@return The newly created CHierarchyObserver object.
|
|
1393 |
*/
|
|
1394 |
EXPORT_C CHierarchyObserver* CHierarchyObserver::NewL(MHierarchyObserver& aHierarchyObserver,TDmHierarchyId aHierarchyId)
|
|
1395 |
{
|
|
1396 |
CHierarchyObserver* observer=new(ELeave)CHierarchyObserver(aHierarchyObserver,aHierarchyId);
|
|
1397 |
|
|
1398 |
CleanupStack::PushL(observer);
|
|
1399 |
User::LeaveIfError(observer->iSession.ConnectObserver(aHierarchyId));
|
|
1400 |
CleanupStack::Pop();
|
|
1401 |
|
|
1402 |
return(observer);
|
|
1403 |
}
|
|
1404 |
|
|
1405 |
|
|
1406 |
|
|
1407 |
|
|
1408 |
/**
|
|
1409 |
Destructor.
|
|
1410 |
|
|
1411 |
Frees resources prior to destruction of the object.
|
|
1412 |
*/
|
|
1413 |
EXPORT_C CHierarchyObserver::~CHierarchyObserver()
|
|
1414 |
{
|
|
1415 |
Cancel();
|
|
1416 |
iSession.Close();
|
|
1417 |
iTransitionEvents.Reset();
|
|
1418 |
}
|
|
1419 |
|
|
1420 |
void CHierarchyObserver::DoCancel()
|
|
1421 |
{
|
|
1422 |
iObserverStarted=EFalse;
|
|
1423 |
iSession.CancelObserver();
|
|
1424 |
}
|
|
1425 |
|
|
1426 |
void CHierarchyObserver::RunL()
|
|
1427 |
//
|
|
1428 |
// Process the reply to client's request for domain transition/failure
|
|
1429 |
//
|
|
1430 |
{
|
|
1431 |
|
|
1432 |
TInt ret= iSession.GetEvents(iTransitionEvents);
|
|
1433 |
|
|
1434 |
User::LeaveIfError(ret);
|
|
1435 |
|
|
1436 |
TInt count = iTransitionEvents.Count();
|
|
1437 |
|
|
1438 |
for(TInt i=0;i<count;i++)
|
|
1439 |
{
|
|
1440 |
if(iTransitionEvents[i].iError==KErrNone)
|
|
1441 |
iObserver.TransProgEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState);
|
|
1442 |
else if(iTransitionEvents[i].iError==KDmErrOutstanding)
|
|
1443 |
iObserver.TransReqEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState);
|
|
1444 |
else
|
|
1445 |
iObserver.TransFailEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState,iTransitionEvents[i].iError);
|
|
1446 |
}
|
|
1447 |
|
|
1448 |
GetNotification();
|
|
1449 |
}
|
|
1450 |
|
|
1451 |
|
|
1452 |
|
|
1453 |
|
|
1454 |
/**
|
|
1455 |
Starts the observer.
|
|
1456 |
|
|
1457 |
@param aDomainId The Id of the domain to which the obsever is attached.
|
|
1458 |
@param aNotifyType The type of notifications of interest to the observer.
|
|
1459 |
|
|
1460 |
@return KErrNone on successful start, otherwise one of the other system wide error codes.
|
|
1461 |
*/
|
|
1462 |
EXPORT_C TInt CHierarchyObserver::StartObserver(TDmDomainId aDomainId, TDmNotifyType aNotifyType)
|
|
1463 |
{
|
|
1464 |
iNotifyType=aNotifyType;
|
|
1465 |
iDomainId=aDomainId;
|
|
1466 |
|
|
1467 |
TInt ret=iSession.StartObserver(iDomainId, iNotifyType);
|
|
1468 |
if(ret!=KErrNone)
|
|
1469 |
return ret;
|
|
1470 |
iObserverStarted=ETrue;
|
|
1471 |
GetNotification();
|
|
1472 |
return KErrNone;
|
|
1473 |
}
|
|
1474 |
|
|
1475 |
|
|
1476 |
|
|
1477 |
|
|
1478 |
/**
|
|
1479 |
Stops the observer.
|
|
1480 |
|
|
1481 |
@return KErrNone if successful; KDmErrBadSequence, if the observer
|
|
1482 |
has not already started.
|
|
1483 |
*/
|
|
1484 |
EXPORT_C TInt CHierarchyObserver::StopObserver()
|
|
1485 |
{
|
|
1486 |
if(!iObserverStarted)
|
|
1487 |
return(KDmErrBadSequence);
|
|
1488 |
Cancel();
|
|
1489 |
return(KErrNone);
|
|
1490 |
}
|
|
1491 |
|
|
1492 |
void CHierarchyObserver::GetNotification()
|
|
1493 |
{
|
|
1494 |
iSession.GetNotification(iStatus);
|
|
1495 |
SetActive();
|
|
1496 |
}
|
|
1497 |
|
|
1498 |
/**
|
|
1499 |
Gets the number of domains that are being observed.
|
|
1500 |
|
|
1501 |
This value is the number of children of the domain member to which the observer
|
|
1502 |
is attached, including itself.
|
|
1503 |
|
|
1504 |
@return The number of observed domain members.
|
|
1505 |
One of the other system wide error codes may be returned on failure;
|
|
1506 |
specifically KErrNotFound if the observer is not already started.
|
|
1507 |
*/
|
|
1508 |
EXPORT_C TInt CHierarchyObserver::ObserverDomainCount()
|
|
1509 |
{
|
|
1510 |
if(!iObserverStarted)
|
|
1511 |
return KErrNotFound;
|
|
1512 |
return(iSession.ObserverDomainCount());
|
|
1513 |
}
|