9 // Nokia Corporation - initial contribution. |
9 // Nokia Corporation - initial contribution. |
10 // |
10 // |
11 // Contributors: |
11 // Contributors: |
12 // |
12 // |
13 // Description: |
13 // Description: |
14 // domain\src\domainsrv.cpp |
14 // domainmgr/src/domainsrv.cpp |
15 // |
15 // |
16 // |
16 // |
17 |
17 |
18 #include <e32debug.h> |
18 #include <e32debug.h> |
19 #include <e32base.h> |
19 #include <e32base.h> |
20 #include <e32base_private.h> |
20 #include <e32base_private.h> |
21 #include <e32property.h> |
21 #include <e32property.h> |
22 #include <f32file.h> |
22 #include <f32file.h> |
23 |
23 |
24 #include <domainpolicy.h> |
24 #include <domainpolicy.h> |
25 #include "domainsrv.h" |
25 #include "domainsrv.h" |
|
26 #include "domaincfg.h" |
26 |
27 |
27 #define __DS_PANIC(aError) User::Panic(_L("domainSrv.cpp"), (-(aError)) | (__LINE__ << 16)) |
28 #define __DS_PANIC(aError) User::Panic(_L("domainSrv.cpp"), (-(aError)) | (__LINE__ << 16)) |
|
29 #define __DS_PANIC_IFERR(aError) ((aError == KErrNone) || (User::Panic(_L("domainSrv.cpp"), (-(aError)) | (__LINE__ << 16)), 1)) |
|
30 #define __DS_PANIC_IFNUL(aPtr) ((aPtr != NULL) || (User::Panic(_L("domainSrv.cpp"), (-(KErrNoMemory)) | (__LINE__ << 16)), 1)) |
28 #define __DS_ASSERT(aCond) ((aCond) || (User::Panic(_L("domainSrv.cpp; assertion failed"), __LINE__), 1)) |
31 #define __DS_ASSERT(aCond) ((aCond) || (User::Panic(_L("domainSrv.cpp; assertion failed"), __LINE__), 1)) |
29 |
32 #define __DS_ASSERT_STARTUP(aCond) ((aCond) || (User::Panic(_L("Domain Server start-up error, server exiting"), __LINE__), 1)) |
30 //#define __DS_DEBUG |
|
31 |
|
32 #ifdef __DS_DEBUG |
|
33 #define __DS_TRACE(s) RDebug::Print s |
|
34 #else |
|
35 #define __DS_TRACE(s) |
|
36 #endif |
|
37 |
33 |
38 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
34 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
39 static _LIT_SECURITY_POLICY_C1(KPowerMgmtPolicy,ECapabilityPowerMgmt); |
35 static _LIT_SECURITY_POLICY_C1(KPowerMgmtPolicy, ECapabilityPowerMgmt); |
|
36 static _LIT_SECURITY_POLICY_C1(KWddPolicy, ECapabilityWriteDeviceData); |
|
37 static _LIT_SECURITY_POLICY_C1(KProtServPolicy, ECapabilityProtServ); |
40 |
38 |
41 // forward refs |
39 // forward refs |
42 class CSvrDomain; |
40 class CSvrDomain; |
43 class CDmHierarchy; |
41 class CDmHierarchy; |
44 class CPowerUpHandler; |
42 class CPowerUpHandler; |
79 void RequestChildrenTransition(); |
87 void RequestChildrenTransition(); |
80 void MembersTransitionDone(); |
88 void MembersTransitionDone(); |
81 void ChildrenTransitionDone(); |
89 void ChildrenTransitionDone(); |
82 void CompleteDomainTransition(); |
90 void CompleteDomainTransition(); |
83 |
91 |
|
92 void SetMemberDeferralBudgets(); |
|
93 TBool ExpireMemberDeferrals(); |
|
94 |
84 private: |
95 private: |
85 CDmHierarchy& iHierarchy; |
96 CDmHierarchy& iHierarchy; |
86 CSvrDomain* iParent; |
97 CSvrDomain* iParent; |
87 CSvrDomain* iPeer; |
98 CSvrDomain* iPeer; |
88 CSvrDomain* iChild; |
99 CSvrDomain* iChild; |
89 RProperty iProperty; |
100 RProperty iProperty; |
90 CDmDomainSession* iSessions; |
101 CDmDomainSession* iSessions; |
91 TUint16 iChildrenCount; |
102 TUint16 iChildrenCount; |
92 TUint16 iTransCount; |
103 TUint16 iTransCount; |
93 TTimeIntervalMicroSeconds32 iTransTimeBudget; |
104 |
|
105 TOverrideableSetting<TTimeIntervalMicroSeconds32, &CHierarchySettings::GetDomainTimeout> |
|
106 iTransTimeBudget; |
|
107 |
|
108 |
|
109 TOverrideableSetting<TInt, &CHierarchySettings::GetDeferralBudget> |
|
110 iTransitionDeferralBudget; |
94 |
111 |
95 public: |
112 public: |
96 const TSecurityPolicy iJoinPolicy; |
113 const TSecurityPolicy iJoinPolicy; |
97 TBool iIsObserved; |
114 TBool iIsObserved; |
98 TDmDomainId iId; |
115 TDmDomainId iId; |
114 TBool OutstandingNotification(); |
133 TBool OutstandingNotification(); |
115 void StopObserver(); |
134 void StopObserver(); |
116 virtual TInt RequestSystemTransition(TDmDomainState aTargetState, TDmTraverseDirection aTraverseDirection, const RMessage2* aMessage); |
135 virtual TInt RequestSystemTransition(TDmDomainState aTargetState, TDmTraverseDirection aTraverseDirection, const RMessage2* aMessage); |
117 virtual void CompleteTransition(TInt aError); |
136 virtual void CompleteTransition(TInt aError); |
118 virtual void NotifyCompletion(TInt aReason); |
137 virtual void NotifyCompletion(TInt aReason); |
119 |
138 |
|
139 CHierarchySettings& HierachySettings() |
|
140 { |
|
141 return *iSettings; |
|
142 } |
|
143 |
120 protected: |
144 protected: |
121 CDmHierarchy(TDmHierarchyId aHierarchyId, TDmHierarchyPolicy& aPolicy); |
145 CDmHierarchy(TDmHierarchyId aHierarchyId, TDmHierarchyPolicy& aPolicy); |
122 void SetState(TDmDomainState aTargetState, TDmTraverseDirection aTraverseDirection = ETraverseDefault); |
146 void SetState(TDmDomainState aTargetState, TDmTraverseDirection aTraverseDirection = ETraverseDefault); |
123 |
147 |
124 private: |
148 private: |
125 RMessagePtr2 iTransMessagePtr; |
|
126 RMessagePtr2 iObsvrMessagePtr; |
|
127 CSvrDomain* iObservedDomain; |
149 CSvrDomain* iObservedDomain; |
128 TBool iOutstandingNotification; |
150 |
|
151 CHierarchySettings* iSettings; |
|
152 |
|
153 /** Direction of traversal if target state is after current state */ |
|
154 TDmTraverseDirection iPositiveTransitions; |
|
155 |
|
156 /** Direction of traversal if target state is before current state */ |
|
157 TDmTraverseDirection iNegativeTransitions; |
|
158 |
129 public: |
159 public: |
|
160 /** Policy which outlines the action upon transition failure */ |
|
161 TOverrideableSetting<TDmTransitionFailurePolicy, &CHierarchySettings::GetFailurePolicy> |
|
162 iFailurePolicy; |
|
163 |
130 TDmHierarchyId iHierarchyId; |
164 TDmHierarchyId iHierarchyId; |
131 CSvrDomain* iRootDomain; |
165 CSvrDomain* iRootDomain; |
132 CSvrDomain* iTransDomain; |
166 CSvrDomain* iTransDomain; |
133 TInt iTransPropValue; |
167 TInt iTransPropValue; |
134 TDmDomainState iTransState; |
168 TDmDomainState iTransState; |
135 TDmTraverseDirection iTraverseDirection; |
169 TDmTraverseDirection iTraverseDirection; |
136 TUint8 iTransId; |
170 TUint8 iTransId; |
137 CDmManagerSession* iControllerSession; // only one controller per hierarchy |
171 CDmManagerSession* iControllerSession; // only one controller per hierarchy |
138 TDmHierarchyPolicy iPolicy; |
172 |
|
173 |
139 RArray<TTransitionFailure> iTransitionFailures; |
174 RArray<TTransitionFailure> iTransitionFailures; |
140 |
175 |
141 // observer stuff |
176 // observer stuff |
142 TBool iObserverStarted; |
177 TBool iObserverStarted; |
143 TDmNotifyType iNotifyType; |
178 TDmNotifyType iNotifyType; |
144 RArray<TTransInfo> iTransitions; |
179 RArray<TTransInfo> iTransitions; |
145 CDmManagerSession* iObserverSession; // only one observer per hierarchy |
180 CDmManagerSession* iObserverSession; // only one observer per hierarchy |
204 class CDmSvrManager : public CBase |
239 class CDmSvrManager : public CBase |
205 { |
240 { |
206 public: |
241 public: |
207 static CDmSvrManager* New(); |
242 static CDmSvrManager* New(); |
208 |
243 |
209 TInt BuildDomainTree(TDmHierarchyId aHierarchyId, CDmHierarchy*& aHierarchy); |
244 TInt BuildDomainTree(TDmHierarchyId aHierarchyId); |
210 CDmHierarchy* LookupHierarchy(TDmHierarchyId aHierarchyId); |
245 CDmHierarchy* LookupHierarchy(TDmHierarchyId aHierarchyId); |
211 TInt LookupDomain(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId, CSvrDomain*& aDomain); |
246 TInt LookupDomain(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId, CSvrDomain*& aDomain); |
212 |
247 |
213 private: |
248 private: |
214 CDmSvrManager(); |
249 CDmSvrManager(); |
215 void Construct(); |
250 void Construct(); |
216 |
251 |
|
252 TInt LoadStateSpecs(RLibrary& aLib, CDmHierarchy* aHierarchy); |
|
253 |
217 private: |
254 private: |
218 RPointerArray<CDmHierarchy> iDomainHierarchies; |
255 RPointerArray<CDmHierarchy> iDomainHierarchies; |
219 }; |
256 }; |
220 |
257 |
221 // CDmDomainServer |
258 // CDmDomainServer |
222 class CDmDomainServer : public CServer2 |
259 class CDmDomainServer : public CServer2 |
223 { |
260 { |
224 public: |
261 public: |
225 // from CServer2 |
262 // from CServer2 |
226 CSession2* NewSessionL(const TVersion& aVer) const; |
|
227 CSession2* NewSessionL(const TVersion& aVer, const RMessage2& aMessage) const; |
263 CSession2* NewSessionL(const TVersion& aVer, const RMessage2& aMessage) const; |
228 |
264 |
229 CDmDomainServer(CDmSvrManager* aManager) : CServer2(CActive::EPriorityStandard), iManager(aManager) |
265 // Note, tracing of client thread names relies upon |
|
266 // EUnsharableSessions being used |
|
267 CDmDomainServer(CDmSvrManager* aManager) : CServer2(CActive::EPriorityStandard, EUnsharableSessions), iManager(aManager) |
230 {} |
268 {} |
231 |
269 |
232 public: |
270 public: |
233 CDmSvrManager* iManager; |
271 CDmSvrManager* iManager; |
234 }; |
272 }; |
236 // CDmDomainSession |
274 // CDmDomainSession |
237 class CDmDomainSession : public CSession2 |
275 class CDmDomainSession : public CSession2 |
238 { |
276 { |
239 public: |
277 public: |
240 // from CBase |
278 // from CBase |
|
279 CDmDomainSession(); |
241 ~CDmDomainSession(); |
280 ~CDmDomainSession(); |
242 |
281 |
243 // from CSession2 |
282 // from CSession2 |
244 void ServiceL(const RMessage2& aMessage); |
283 void ServiceL(const RMessage2& aMessage); |
245 |
284 |
|
285 // Called by CSvrDomain |
|
286 void SetDeferralBudget(TInt); |
|
287 TBool DeferralActive() const; |
|
288 void ExpireDeferral(); |
|
289 void CancelDeferral(); |
|
290 |
246 private: |
291 private: |
|
292 // Handle client calls |
|
293 void DeferAcknowledgment(const RMessage2&); |
|
294 void CompleteDeferral(TInt); |
|
295 void ObsoleteDeferral(); |
|
296 |
247 CSvrDomain* iDomain; |
297 CSvrDomain* iDomain; |
|
298 TInt iDeferralsRemaining; |
|
299 RMessagePtr2 iDeferralMsg; |
|
300 |
248 |
301 |
249 public: |
302 public: |
250 CDmDomainSession* iNext; |
303 CDmDomainSession* iNext; |
251 TUint8 iPending; |
304 TUint8 iAcknPending; ///< Indicates if an acknowledgment is pending |
252 TBool iNotificationEnabled; |
305 TBool iNotificationEnabled; |
|
306 |
253 }; |
307 }; |
254 |
308 |
255 class CDmManagerServer : public CServer2 |
309 class CDmManagerServer : public CServer2 |
256 { |
310 { |
257 public: |
311 public: |
258 // from CServer2 |
312 // from CServer2 |
259 CSession2* NewSessionL(const TVersion& aVer) const; |
|
260 CSession2* NewSessionL(const TVersion& aVer, const RMessage2&) const; |
313 CSession2* NewSessionL(const TVersion& aVer, const RMessage2&) const; |
261 |
314 |
262 CDmManagerServer(CDmSvrManager* aManager) : CServer2(CActive::EPriorityStandard), iManager(aManager) |
315 // Note, tracing of client thread names relies upon |
|
316 // EUnsharableSessions being used |
|
317 CDmManagerServer(CDmSvrManager* aManager) : CServer2(CActive::EPriorityStandard, EUnsharableSessions), iManager(aManager) |
263 {} |
318 {} |
264 CDmSvrManager* iManager; |
319 CDmSvrManager* iManager; |
265 }; |
320 }; |
266 |
321 |
267 class CDmManagerSession : public CSession2 |
322 class CDmManagerSession : public CSession2 |
268 { |
323 { |
269 public: |
324 public: |
270 // from CBase |
325 // from CBase |
|
326 CDmManagerSession(); |
271 ~CDmManagerSession(); |
327 ~CDmManagerSession(); |
272 |
328 |
273 // from CSession2 |
329 // from CSession2 |
274 void ServiceL(const RMessage2& aMessage); |
330 void ServiceL(const RMessage2& aMessage); |
275 |
331 |
276 CDmManagerSession(); |
332 RMessagePtr2 iTransMessagePtr; |
|
333 RMessagePtr2 iObsvrMessagePtr; |
|
334 |
277 private: |
335 private: |
278 CDmHierarchy* iHierarchy; // not owned |
336 CDmHierarchy* iHierarchy; // not owned |
279 }; |
337 }; |
280 |
338 |
281 |
339 |
321 |
379 |
322 |
380 |
323 CSvrDomain::CSvrDomain(CDmHierarchy& aHierarchy, const TDmDomainSpec* spec) |
381 CSvrDomain::CSvrDomain(CDmHierarchy& aHierarchy, const TDmDomainSpec* spec) |
324 : CTimer(CActive::EPriorityStandard), |
382 : CTimer(CActive::EPriorityStandard), |
325 iHierarchy(aHierarchy), |
383 iHierarchy(aHierarchy), |
326 iTransTimeBudget(spec->iTimeBudgetUs), |
384 iParent(NULL), |
|
385 iPeer(NULL), |
|
386 iChild(NULL), |
|
387 iChildrenCount(0), |
|
388 iTransTimeBudget(TTimeIntervalMicroSeconds32(spec->iTimeBudgetUs), &iHierarchy.HierachySettings()), |
|
389 iTransitionDeferralBudget(0, &iHierarchy.HierachySettings()), |
327 iJoinPolicy(spec->iJoinPolicy), |
390 iJoinPolicy(spec->iJoinPolicy), |
328 iId(spec->iId) |
391 iId(spec->iId) |
329 {} |
392 { |
|
393 __DS_TRACE((_L("DM: CSvrDomain() @0x%08x, id 0x%x, hierachy id %d"), this, iId, iHierarchy.iHierarchyId)); |
|
394 } |
330 |
395 |
331 CSvrDomain* CSvrDomain::New(CDmHierarchy& aHierarchy, const TDmDomainSpec& aSpec) |
396 CSvrDomain* CSvrDomain::New(CDmHierarchy& aHierarchy, const TDmDomainSpec& aSpec) |
332 { |
397 { |
333 |
|
334 CSvrDomain* self = new CSvrDomain(aHierarchy, &aSpec); |
398 CSvrDomain* self = new CSvrDomain(aHierarchy, &aSpec); |
335 |
399 __DS_PANIC_IFNUL(self); |
336 if (!self) |
400 |
337 __DS_PANIC(KErrNoMemory); |
|
338 self->Construct(&aSpec); |
401 self->Construct(&aSpec); |
339 return self; |
402 return self; |
|
403 } |
|
404 |
|
405 CSvrDomain::~CSvrDomain() |
|
406 { |
|
407 __DS_TRACE((_L("DM: ~CSvrDomain() @0x%08x"), this)); |
|
408 |
|
409 // delete children |
|
410 CSvrDomain* child = iChild; |
|
411 while(child) |
|
412 { |
|
413 CSvrDomain* nextChild = child->iPeer; |
|
414 delete child; |
|
415 child = nextChild; |
|
416 iChildrenCount--; |
|
417 } |
|
418 __DS_ASSERT(iChildrenCount==0); |
|
419 |
|
420 TInt r = iProperty.Delete(DmStatePropertyKey(iHierarchy.iHierarchyId, iId)); |
|
421 __DS_PANIC_IFERR(r); |
340 } |
422 } |
341 |
423 |
342 void CSvrDomain::Construct(const TDmDomainSpec* spec) |
424 void CSvrDomain::Construct(const TDmDomainSpec* spec) |
343 { |
425 { |
344 TInt r = iProperty.Define( |
426 TInt r = iProperty.Define( |
345 KUidDmPropertyCategory, |
427 KUidDmPropertyCategory, |
346 DmStatePropertyKey(iHierarchy.iHierarchyId, iId), |
428 DmStatePropertyKey(iHierarchy.iHierarchyId, iId), |
347 RProperty::EInt, |
429 RProperty::EInt, |
348 KAllowAllPolicy,KPowerMgmtPolicy); |
430 KAllowAllPolicy,KPowerMgmtPolicy); |
349 |
431 |
350 if (r != KErrNone) |
432 __DS_PANIC_IFERR(r); |
351 __DS_PANIC(r); |
|
352 |
433 |
353 r = iProperty.Attach(KUidDmPropertyCategory, DmStatePropertyKey( |
434 r = iProperty.Attach(KUidDmPropertyCategory, DmStatePropertyKey( |
354 iHierarchy.iHierarchyId, |
435 iHierarchy.iHierarchyId, |
355 iId)); |
436 iId)); |
356 |
437 |
357 if (r != KErrNone) |
438 __DS_PANIC_IFERR(r); |
358 __DS_PANIC(r); |
|
359 |
439 |
360 r = iProperty.Set(DmStatePropertyValue(0, spec->iInitState)); |
440 r = iProperty.Set(DmStatePropertyValue(0, spec->iInitState)); |
361 if (r != KErrNone) |
441 __DS_PANIC_IFERR(r); |
362 __DS_PANIC(r); |
|
363 |
442 |
364 TRAP(r, CTimer::ConstructL()); |
443 TRAP(r, CTimer::ConstructL()); |
365 if (r != KErrNone) |
444 __DS_PANIC_IFERR(r); |
366 __DS_PANIC(r); |
445 |
367 CActiveScheduler::Add(this); |
446 CActiveScheduler::Add(this); |
368 } |
447 } |
369 |
448 |
370 void CSvrDomain::Attach(CDmDomainSession* aSession) |
449 void CSvrDomain::Attach(CDmDomainSession* aSession) |
371 { |
450 { |
414 TBool CSvrDomain::CheckPropValue(TInt aPropValue) |
493 TBool CSvrDomain::CheckPropValue(TInt aPropValue) |
415 { return iHierarchy.iTransPropValue == aPropValue; } |
494 { return iHierarchy.iTransPropValue == aPropValue; } |
416 |
495 |
417 void CSvrDomain::RequestMembersTransition() |
496 void CSvrDomain::RequestMembersTransition() |
418 { |
497 { |
419 __DS_TRACE((_L("CSvrDomain::RequestMembersTransition() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
498 __DS_TRACE((_L("DM: CSvrDomain::RequestMembersTransition() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
420 __DS_ASSERT(iTransCount == 0); |
499 __DS_ASSERT(iTransCount == 0); |
421 |
500 |
|
501 SetMemberDeferralBudgets(); |
|
502 |
422 for(CDmDomainSession* s = iSessions; s; s = s->iNext) |
503 for(CDmDomainSession* s = iSessions; s; s = s->iNext) |
423 if (s->iNotificationEnabled) |
504 if (s->iNotificationEnabled) |
424 { |
505 { |
425 ++iTransCount; |
506 ++iTransCount; |
426 s->iPending = ETrue; |
507 s->iAcknPending = ETrue; |
427 // notifications will be disabled until the client makes another |
508 // notifications will be disabled until the client makes another |
428 // call to RDmDomain::RequestTransitionNotification() |
509 // call to RDmDomain::RequestTransitionNotification() |
429 s->iNotificationEnabled = EFalse; |
510 s->iNotificationEnabled = EFalse; |
430 } |
511 } |
431 |
512 |
438 if(iHierarchy.OutstandingNotification()) |
519 if(iHierarchy.OutstandingNotification()) |
439 iHierarchy.CompleteNotification(KErrNone); |
520 iHierarchy.CompleteNotification(KErrNone); |
440 } |
521 } |
441 } |
522 } |
442 if (iTransCount > 0) |
523 if (iTransCount > 0) |
443 CTimer::After(iTransTimeBudget); |
524 CTimer::After(iTransTimeBudget()); |
444 iProperty.Set(iHierarchy.iTransPropValue); |
525 iProperty.Set(iHierarchy.iTransPropValue); |
445 if (iTransCount == 0) |
526 if (iTransCount == 0) |
446 MembersTransitionDone(); |
527 MembersTransitionDone(); |
447 } |
528 } |
448 |
529 |
449 |
530 |
450 void CSvrDomain::RequestChildrenTransition() |
531 void CSvrDomain::RequestChildrenTransition() |
451 { |
532 { |
452 __DS_TRACE((_L("CSvrDomain::RequestChildrenTransition() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
533 __DS_TRACE((_L("DM: CSvrDomain::RequestChildrenTransition() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
453 __DS_ASSERT(iTransCount == 0); |
534 __DS_ASSERT(iTransCount == 0); |
454 iTransCount = iChildrenCount; |
535 iTransCount = iChildrenCount; |
455 if (iTransCount) |
536 if (iTransCount) |
456 { |
537 { |
457 CSvrDomain* child = iChild; |
538 CSvrDomain* child = iChild; |
466 ChildrenTransitionDone(); |
547 ChildrenTransitionDone(); |
467 } |
548 } |
468 |
549 |
469 void CSvrDomain::RequestDomainTransition() |
550 void CSvrDomain::RequestDomainTransition() |
470 { |
551 { |
471 __DS_TRACE((_L("CSvrDomain::RequestDomainTransition() hierarchy=%d, domain=0x%x state=0x%x prop=0x%x"), |
552 __DS_TRACE((_L("DM: CSvrDomain::RequestDomainTransition() hierarchy=%d, domain=0x%x state=0x%x prop=0x%x"), |
472 iHierarchy.iHierarchyId, iId, iHierarchy.iTransState, iHierarchy.iTransPropValue)); |
553 iHierarchy.iHierarchyId, iId, iHierarchy.iTransState, iHierarchy.iTransPropValue)); |
473 __DS_ASSERT(iTransCount == 0); |
554 __DS_ASSERT(iTransCount == 0); |
474 if (iHierarchy.iTraverseDirection == ETraverseChildrenFirst) |
555 if (iHierarchy.iTraverseDirection == ETraverseChildrenFirst) |
475 RequestChildrenTransition(); |
556 RequestChildrenTransition(); |
476 else |
557 else |
477 RequestMembersTransition(); |
558 RequestMembersTransition(); |
478 } |
559 } |
479 |
560 |
480 void CSvrDomain::MembersTransitionDone() |
561 void CSvrDomain::MembersTransitionDone() |
481 { |
562 { |
482 __DS_TRACE((_L("CSvrDomain::MembersTransitionDone() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
563 __DS_TRACE((_L("DM: CSvrDomain::MembersTransitionDone() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
483 __DS_ASSERT(iTransCount == 0); |
564 __DS_ASSERT(iTransCount == 0); |
484 if (iHierarchy.iTraverseDirection == ETraverseChildrenFirst) |
565 if (iHierarchy.iTraverseDirection == ETraverseChildrenFirst) |
485 CompleteDomainTransition(); |
566 CompleteDomainTransition(); |
486 else |
567 else |
487 RequestChildrenTransition(); |
568 RequestChildrenTransition(); |
488 } |
569 } |
489 |
570 |
490 void CSvrDomain::ChildrenTransitionDone() |
571 void CSvrDomain::ChildrenTransitionDone() |
491 { |
572 { |
492 __DS_TRACE((_L("CSvrDomain::ChildrenTransitionDone() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
573 __DS_TRACE((_L("DM: CSvrDomain::ChildrenTransitionDone() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
493 __DS_ASSERT(iTransCount == 0); |
574 __DS_ASSERT(iTransCount == 0); |
494 if (iHierarchy.iTraverseDirection == ETraverseChildrenFirst) |
575 if (iHierarchy.iTraverseDirection == ETraverseChildrenFirst) |
495 RequestMembersTransition(); |
576 RequestMembersTransition(); |
496 else |
577 else |
497 CompleteDomainTransition(); |
578 CompleteDomainTransition(); |
498 } |
579 } |
499 |
580 |
500 void CSvrDomain::CompleteMemberTransition(TInt aError) |
581 void CSvrDomain::CompleteMemberTransition(TInt aError) |
501 { |
582 { |
502 __DS_TRACE((_L("CSvrDomain::CompleteMemberTransition() hierarchy=%d, domain=0x%x, aError = %d"), iHierarchy.iHierarchyId, iId, aError)); |
583 __DS_TRACE((_L("DM: CSvrDomain::CompleteMemberTransition() hierarchy=%d, domain=0x%x, aError = %d"), iHierarchy.iHierarchyId, iId, aError)); |
503 __DS_ASSERT(iTransCount); |
584 __DS_ASSERT(iTransCount); |
504 |
585 |
505 if (aError) |
586 if (aError) |
506 { |
587 { |
507 // Add a transition failure to the array |
588 // Add a transition failure to the array |
543 } |
624 } |
544 } |
625 } |
545 |
626 |
546 void CSvrDomain::RunL() |
627 void CSvrDomain::RunL() |
547 { // Timer expired |
628 { // Timer expired |
548 __DS_TRACE((_L("CSvrDomain::RunL() Members transition timeout hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
629 |
|
630 if (ExpireMemberDeferrals()) |
|
631 { |
|
632 __DS_TRACE((_L("DM: CSvrDomain::RunL() Deferring transition timeout hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
|
633 CTimer::After(iTransTimeBudget()); |
|
634 return; |
|
635 } |
|
636 |
|
637 __DS_TRACE((_L("DM: CSvrDomain::RunL() Members transition timeout hierarchy=%d, domain=0x%x, iTransCount=%d"), iHierarchy.iHierarchyId, iId, iTransCount)); |
549 |
638 |
550 // Add a transition failure to the array |
639 // Add a transition failure to the array |
551 TTransitionFailure failure(iId,KErrTimedOut); |
640 TTransitionFailure failure(iId,KErrTimedOut); |
552 iHierarchy.iTransitionFailures.Append(failure); |
641 iHierarchy.iTransitionFailures.Append(failure); |
553 |
642 |
554 |
643 |
555 // examine the failure policy to work out what to do |
644 // Examine the failure policy to work out what to do |
556 if (iHierarchy.iPolicy.iFailurePolicy == ETransitionFailureStop) |
645 if (iHierarchy.iFailurePolicy() == ETransitionFailureStop) |
557 { |
646 { |
|
647 // CompleteTransition will in turn call CancelTransition, |
|
648 // which will reset iTransCount and the iAcknPending flags |
558 iHierarchy.CompleteTransition(KErrTimedOut); |
649 iHierarchy.CompleteTransition(KErrTimedOut); |
559 return; |
650 return; |
560 } |
651 } |
561 |
652 |
562 if (iTransCount) |
653 if (iTransCount) |
563 { // Complete transition of all members |
654 { // Complete transition of all members |
564 CDmDomainSession* session = iSessions; |
655 CDmDomainSession* session = iSessions; |
565 while (session) |
656 while (session) |
566 { |
657 { |
567 session->iPending = EFalse; |
658 if (session->iAcknPending) |
|
659 { |
|
660 __DS_TRACE((_L("DM: Member transition timeout domain=0x%x: CDmDomainSession Object 0x%08x"), iId, session)); |
|
661 session->iAcknPending = EFalse; |
|
662 } |
568 session = session->iNext; |
663 session = session->iNext; |
569 } |
664 } |
570 iTransCount = 0; |
665 iTransCount = 0; |
571 MembersTransitionDone(); |
666 MembersTransitionDone(); |
572 } |
667 } |
573 } |
668 } |
574 |
669 |
575 |
670 |
576 void CSvrDomain::CompleteDomainTransition() |
671 void CSvrDomain::CompleteDomainTransition() |
577 { |
672 { |
578 __DS_TRACE((_L("CSvrDomain::CompleteDomainTransition() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
673 __DS_TRACE((_L("DM: CSvrDomain::CompleteDomainTransition() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
579 __DS_ASSERT(iTransCount == 0); |
674 __DS_ASSERT(iTransCount == 0); |
580 if (iHierarchy.iTransDomain == this) |
675 if (iHierarchy.iTransDomain == this) |
581 { |
676 { |
582 const TInt err = (iHierarchy.iTransitionFailures.Count() > 0)? |
677 const TInt err = (iHierarchy.iTransitionFailures.Count() > 0)? |
583 iHierarchy.iTransitionFailures[0].iError : KErrNone; |
678 iHierarchy.iTransitionFailures[0].iError : KErrNone; |
592 } |
687 } |
593 } |
688 } |
594 |
689 |
595 void CSvrDomain::CancelTransition() |
690 void CSvrDomain::CancelTransition() |
596 { |
691 { |
597 __DS_TRACE((_L("CSvrDomain::CancelTransition() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
692 __DS_TRACE((_L("DM: CSvrDomain::CancelTransition() hierarchy=%d, domain=0x%x"), iHierarchy.iHierarchyId, iId)); |
598 CTimer::Cancel(); |
693 CTimer::Cancel(); |
599 CSvrDomain* child = iChild; |
694 CSvrDomain* child = iChild; |
600 while (child) |
695 while (child) |
601 { |
696 { |
602 child->CancelTransition(); |
697 child->CancelTransition(); |
603 child = child->iPeer; |
698 child = child->iPeer; |
604 } |
699 } |
605 CDmDomainSession* session = iSessions; |
700 CDmDomainSession* session = iSessions; |
606 while (session) |
701 while (session) |
607 { |
702 { |
608 session->iPending = EFalse; |
703 // At this point the server says that the current transition may no |
|
704 // longer be acknowledged. Therefore, cancel the deferral |
|
705 if (session->DeferralActive()) |
|
706 { |
|
707 session->CancelDeferral(); |
|
708 } |
|
709 |
|
710 session->iAcknPending = EFalse; |
609 session = session->iNext; |
711 session = session->iNext; |
610 } |
712 } |
611 iTransCount = 0; |
713 iTransCount = 0; |
612 } |
714 } |
613 |
715 |
637 TDmDomainState CSvrDomain::State() |
739 TDmDomainState CSvrDomain::State() |
638 { |
740 { |
639 TInt value; |
741 TInt value; |
640 iProperty.Get(value); |
742 iProperty.Get(value); |
641 return DmStateFromPropertyValue(value); |
743 return DmStateFromPropertyValue(value); |
|
744 } |
|
745 |
|
746 /** |
|
747 Called before members are notified of a transition. |
|
748 */ |
|
749 void CSvrDomain::SetMemberDeferralBudgets() |
|
750 { |
|
751 const TInt deferralBudget = iTransitionDeferralBudget(); |
|
752 CDmDomainSession* session = iSessions; |
|
753 while (session) |
|
754 { |
|
755 __DS_ASSERT(!session->DeferralActive()); |
|
756 __DS_ASSERT(!session->iAcknPending); |
|
757 session->SetDeferralBudget(deferralBudget); |
|
758 session = session->iNext; |
|
759 } |
|
760 } |
|
761 |
|
762 /** |
|
763 Called upon completion of the domain's timeout |
|
764 |
|
765 @return True if at least one member had an active deferral |
|
766 */ |
|
767 TBool CSvrDomain::ExpireMemberDeferrals() |
|
768 { |
|
769 TBool deferDomain = EFalse; |
|
770 CDmDomainSession* session = iSessions; |
|
771 while (session) |
|
772 { |
|
773 if (session->DeferralActive()) |
|
774 { |
|
775 __DS_ASSERT(session->iAcknPending); |
|
776 |
|
777 deferDomain = ETrue; |
|
778 session->ExpireDeferral(); |
|
779 } |
|
780 session = session->iNext; |
|
781 } |
|
782 |
|
783 return deferDomain; |
642 } |
784 } |
643 |
785 |
644 //********************************************************* |
786 //********************************************************* |
645 // CDmHierarchy |
787 // CDmHierarchy |
646 //********************************************************* |
788 //********************************************************* |
652 if (aHierarchyId == KDmHierarchyIdPower) |
794 if (aHierarchyId == KDmHierarchyIdPower) |
653 self = CDmHierarchyPower::New(aHierarchyId, aPolicy); |
795 self = CDmHierarchyPower::New(aHierarchyId, aPolicy); |
654 else |
796 else |
655 self = new CDmHierarchy(aHierarchyId, aPolicy); |
797 self = new CDmHierarchy(aHierarchyId, aPolicy); |
656 |
798 |
657 if (!self) |
799 __DS_PANIC_IFNUL(self); |
658 __DS_PANIC(KErrNoMemory); |
800 |
|
801 self->iSettings = new CHierarchySettings(); |
|
802 __DS_TRACE((_L("DM: CDmHierarchy::New() @0x%08x, CHierarchySettings @0x%08x"), self, self->iSettings)); |
|
803 |
|
804 __DS_PANIC_IFNUL(self->iSettings); |
|
805 |
|
806 self->iFailurePolicy.SetSettings(self->iSettings); |
659 |
807 |
660 return self; |
808 return self; |
661 } |
809 } |
662 |
810 |
663 CDmHierarchy::CDmHierarchy(TDmHierarchyId aHierarchyId, TDmHierarchyPolicy& aPolicy) : |
811 CDmHierarchy::CDmHierarchy(TDmHierarchyId aHierarchyId, TDmHierarchyPolicy& aPolicy) : |
664 iOutstandingNotification(EFalse), |
812 iPositiveTransitions(aPolicy.iPositiveTransitions), |
665 iHierarchyId(aHierarchyId), |
813 iNegativeTransitions(aPolicy.iNegativeTransitions), |
666 iPolicy(aPolicy) |
814 iFailurePolicy(aPolicy.iFailurePolicy, iSettings), |
667 { |
815 iHierarchyId(aHierarchyId) |
|
816 { |
|
817 __DS_TRACE((_L("DM: CDmHierarchy::CDmHierarchy() @0x%08x, hierarchy=%d"), this, iHierarchyId)); |
|
818 |
668 iTransitionFailures.Reset(); |
819 iTransitionFailures.Reset(); |
|
820 } |
|
821 |
|
822 CDmHierarchy::~CDmHierarchy() |
|
823 { |
|
824 __DS_TRACE((_L("DM: CDmHierarchy::~CDmHierarchy() @0x%08x"), this)); |
|
825 |
|
826 delete iRootDomain; |
|
827 delete iSettings; |
|
828 iTransitionFailures.Close(); |
|
829 iTransitions.Close(); |
669 } |
830 } |
670 |
831 |
671 CSvrDomain* CDmHierarchy::LookupDomain(TDmDomainId aDomainId) |
832 CSvrDomain* CDmHierarchy::LookupDomain(TDmDomainId aDomainId) |
672 { |
833 { |
673 return iRootDomain ? iRootDomain->Lookup(aDomainId) : NULL; |
834 return iRootDomain ? iRootDomain->Lookup(aDomainId) : NULL; |
702 |
869 |
703 void CDmHierarchy::SetNotifyMessage(const RMessage2* aMessage) |
870 void CDmHierarchy::SetNotifyMessage(const RMessage2* aMessage) |
704 { |
871 { |
705 if (aMessage) |
872 if (aMessage) |
706 { |
873 { |
707 iObsvrMessagePtr = *aMessage; |
874 __DS_PANIC_IFNUL(iObserverSession); |
708 iOutstandingNotification=ETrue; |
875 iObserverSession->iObsvrMessagePtr = *aMessage; |
709 } |
876 } |
710 } |
877 } |
711 |
878 |
712 TBool CDmHierarchy::OutstandingNotification() |
879 TBool CDmHierarchy::OutstandingNotification() |
713 { |
880 { |
714 return iOutstandingNotification; |
881 return iObserverSession && !(iObserverSession->iObsvrMessagePtr.IsNull()); |
715 } |
882 } |
716 |
883 |
717 void CDmHierarchy::CompleteNotification(TInt aError) |
884 void CDmHierarchy::CompleteNotification(TInt aError) |
718 { |
885 { |
719 if(iOutstandingNotification) |
886 if (OutstandingNotification()) |
720 { |
887 { |
721 iObsvrMessagePtr.Complete(aError); |
888 iObserverSession->iObsvrMessagePtr.Complete(aError); |
722 iOutstandingNotification=EFalse; |
|
723 } |
889 } |
724 } |
890 } |
725 |
891 |
726 void CDmHierarchy::StopObserver() |
892 void CDmHierarchy::StopObserver() |
727 { |
893 { |
728 |
894 |
729 iObservedDomain->SetObserver(EFalse); |
895 iObservedDomain->SetObserver(EFalse); |
730 iTransitions.Reset(); |
896 iTransitions.Reset(); |
731 iObserverStarted=EFalse; |
897 iObserverStarted=EFalse; |
732 } |
898 } |
|
899 |
733 void CDmHierarchy::NotifyCompletion(TInt aReason) |
900 void CDmHierarchy::NotifyCompletion(TInt aReason) |
734 { |
901 { |
735 iTransDomain = NULL; |
902 iTransDomain = NULL; |
736 iTransPropValue = 0; |
903 iTransPropValue = 0; |
737 iTransMessagePtr.Complete(aReason); |
904 |
|
905 if(iControllerSession) |
|
906 { |
|
907 __DS_ASSERT(!(iControllerSession->iTransMessagePtr.IsNull())); |
|
908 iControllerSession->iTransMessagePtr.Complete(aReason); |
|
909 } |
738 } |
910 } |
739 |
911 |
740 TInt CDmHierarchy::RequestSystemTransition(TDmDomainState aTargetState, TDmTraverseDirection aTraverseDirection, const RMessage2* aMessage) |
912 TInt CDmHierarchy::RequestSystemTransition(TDmDomainState aTargetState, TDmTraverseDirection aTraverseDirection, const RMessage2* aMessage) |
741 { |
913 { |
742 iTransDomain = iRootDomain; |
914 iTransDomain = iRootDomain; |
750 TDmDomainId aDomainId, |
922 TDmDomainId aDomainId, |
751 TDmDomainState aTargetState, |
923 TDmDomainState aTargetState, |
752 TDmTraverseDirection aTraverseDirection, |
924 TDmTraverseDirection aTraverseDirection, |
753 const RMessage2* aMessage) |
925 const RMessage2* aMessage) |
754 { |
926 { |
755 __DS_TRACE((_L("CDmHierarchy::RequestTransition() hierarchy=%d domain=0x%x state=0x%x"), iHierarchyId, aDomainId, aTargetState)); |
927 __DS_TRACE((_L("DM: CDmHierarchy::RequestTransition() hierarchy=%d domain=0x%x state=0x%x"), iHierarchyId, aDomainId, aTargetState)); |
756 iTransDomain = LookupDomain(aDomainId); |
928 iTransDomain = LookupDomain(aDomainId); |
757 if (!iTransDomain) |
929 if (!iTransDomain) |
758 return KDmErrBadDomainId; |
930 return KDmErrBadDomainId; |
759 SetState(aTargetState, aTraverseDirection); |
931 SetState(aTargetState, aTraverseDirection); |
760 RequestTransition(aMessage); |
932 RequestTransition(aMessage); |
873 |
1044 |
874 |
1045 |
875 void CDmHierarchyPower::Construct() |
1046 void CDmHierarchyPower::Construct() |
876 { |
1047 { |
877 iPowerUpHandler = CPowerUpHandler::New(*this); |
1048 iPowerUpHandler = CPowerUpHandler::New(*this); |
878 if (!iPowerUpHandler) |
1049 __DS_PANIC_IFNUL(iPowerUpHandler); |
879 __DS_PANIC(KErrNoMemory); |
|
880 } |
1050 } |
881 |
1051 |
882 void CDmHierarchyPower::NotifyCompletion(TInt aReason) |
1052 void CDmHierarchyPower::NotifyCompletion(TInt aReason) |
883 { |
1053 { |
884 iTransStatus = 0; |
1054 iTransStatus = 0; |
885 CDmHierarchy::NotifyCompletion(aReason); |
1055 CDmHierarchy::NotifyCompletion(aReason); |
886 } |
1056 } |
887 |
1057 |
888 TInt CDmHierarchyPower::RequestSystemTransition(TDmDomainState aTargetState, TDmTraverseDirection aTraverseDirection, const RMessage2* aMessage) |
1058 TInt CDmHierarchyPower::RequestSystemTransition(TDmDomainState aTargetState, TDmTraverseDirection aTraverseDirection, const RMessage2* aMessage) |
889 { |
1059 { |
890 __DS_TRACE((_L("CDmSvrManager::RequestSystemTransition() state = 0x%x"), aTargetState)); |
1060 __DS_TRACE((_L("DM: CDmHierarchyPower::RequestSystemTransition() state = 0x%x"), aTargetState)); |
891 |
1061 |
892 TInt r = Power::EnableWakeupEvents((TPowerState) aTargetState); |
1062 TInt r = Power::EnableWakeupEvents((TPowerState) aTargetState); |
893 if (r != KErrNone) |
1063 if (r != KErrNone) |
894 return r; |
1064 return r; |
895 |
1065 |
903 void CDmHierarchyPower::CompleteTransition(TInt aError) |
1073 void CDmHierarchyPower::CompleteTransition(TInt aError) |
904 { |
1074 { |
905 if (!iTransDomain) |
1075 if (!iTransDomain) |
906 return; |
1076 return; |
907 |
1077 |
908 __DS_TRACE((_L("CDmHierarchyPower::CompleteTransition() domain=0x%x"), iTransDomain->iId)); |
1078 __DS_TRACE((_L("DM: CDmHierarchyPower::CompleteTransition() domain=0x%x error=%d"), |
|
1079 iTransDomain->iId, aError)); |
909 |
1080 |
910 if (iTransDomain && aError == KErrCancel) |
1081 if (iTransDomain && aError == KErrCancel) |
911 iPowerUpHandler->Cancel(); |
1082 iPowerUpHandler->Cancel(); |
912 |
1083 |
913 if (iTransStatus & EPoweringDown) |
1084 if ((iTransStatus & EPoweringDown) && (aError != KErrCancel)) |
914 { |
1085 { |
915 RFs fs; |
1086 RFs fs; |
916 TInt r=fs.Connect(); |
1087 TInt r=fs.Connect(); |
917 __DS_ASSERT(r==KErrNone); |
1088 __DS_ASSERT(r==KErrNone); |
918 __DS_TRACE((_L("CDmSvrManager::CompleteTransition() Calling FinaliseDrives"))); |
1089 __DS_TRACE((_L("DM: CDmSvrManager::CompleteTransition() Calling FinaliseDrives"))); |
919 r=fs.FinaliseDrives(); |
1090 r=fs.FinaliseDrives(); |
920 __DS_TRACE((_L("CDmSvrManager::CompleteTransition() Finalise returned %d"),r)); |
1091 __DS_TRACE((_L("DM: CDmSvrManager::CompleteTransition() Finalise returned %d"),r)); |
921 fs.Close(); |
1092 fs.Close(); |
922 |
1093 |
923 Power::PowerDown(); |
1094 Power::PowerDown(); |
924 __DS_ASSERT(iTransState != (TDmDomainState) EPwOff); |
1095 __DS_ASSERT(iTransState != (TDmDomainState) EPwOff); |
925 __DS_ASSERT(iPowerUpHandler->iStatus.Int() == KErrNone); |
1096 __DS_ASSERT(iPowerUpHandler->iStatus.Int() == KErrNone); |
950 //********************************************************* |
1121 //********************************************************* |
951 |
1122 |
952 CDmSvrManager* CDmSvrManager::New() |
1123 CDmSvrManager* CDmSvrManager::New() |
953 { |
1124 { |
954 CDmSvrManager* self = new CDmSvrManager(); |
1125 CDmSvrManager* self = new CDmSvrManager(); |
955 if (!self) |
1126 __DS_PANIC_IFNUL(self); |
956 __DS_PANIC(KErrNoMemory); |
1127 |
957 self->Construct(); |
1128 self->Construct(); |
958 return self; |
1129 return self; |
959 } |
1130 } |
960 |
1131 |
961 CDmSvrManager::CDmSvrManager() |
1132 CDmSvrManager::CDmSvrManager() |
962 { |
1133 { |
963 } |
1134 } |
964 |
1135 |
965 void CDmSvrManager::Construct() |
1136 void CDmSvrManager::Construct() |
966 { |
1137 { |
967 // load the power hierarchy- Other hieratchies need to be loaded |
1138 // Load the power hierarchy - other hierarchies need to be loaded |
968 // explicitly using RDmDomainManager::AddDomainHierarchy() |
1139 // explicitly using RDmDomainManager::AddDomainHierarchy() |
969 CDmHierarchy* hierarchy; |
1140 TInt r = BuildDomainTree(KDmHierarchyIdPower); |
970 TInt r = BuildDomainTree(KDmHierarchyIdPower, hierarchy); |
1141 __DS_PANIC_IFERR(r); |
971 if (r != KErrNone) |
|
972 __DS_PANIC(r); |
|
973 |
|
974 |
1142 |
975 RProperty prop; |
1143 RProperty prop; |
976 r = prop.Define(KUidDmPropertyCategory, KDmPropertyKeyInit, RProperty::EInt, |
1144 r = prop.Define(KUidDmPropertyCategory, KDmPropertyKeyInit, RProperty::EInt, |
977 KAllowAllPolicy,KPowerMgmtPolicy); |
1145 KAllowAllPolicy,KPowerMgmtPolicy); |
978 if (r != KErrNone) |
1146 __DS_PANIC_IFERR(r); |
979 __DS_PANIC(r); |
|
980 |
1147 |
981 prop.Set(KUidDmPropertyCategory, KDmPropertyKeyInit, ETrue); |
1148 prop.Set(KUidDmPropertyCategory, KDmPropertyKeyInit, ETrue); |
982 } |
1149 } |
983 |
1150 |
984 TInt CDmSvrManager::BuildDomainTree(TDmHierarchyId aHierarchyId, CDmHierarchy*& aHierarchy) |
1151 TInt CDmSvrManager::BuildDomainTree(TDmHierarchyId aHierarchyId) |
985 { |
1152 { |
986 |
1153 // We have already checked that the hierarchy doesn't already exist. |
987 aHierarchy = NULL; |
1154 |
988 |
1155 // Get the name of the policy DLL. |
989 // assume we have already checked that the hierarchy doesn't already exist |
|
990 |
|
991 // Get the name of the policy Dll |
|
992 // This will be "domainPolicy.dll" for the power hierarchy |
1156 // This will be "domainPolicy.dll" for the power hierarchy |
993 // and "domainPolicy<n>.dll" for other hierarchies where <n> is the hierarchy ID. |
1157 // and "domainPolicy<n>.dll" for other hierarchies where <n> is the hierarchy ID. |
994 // |
|
995 // If the hierarchy ID is less than KMaxCriticalPolicyDll, load only from ROM |
|
996 |
1158 |
997 TFullName dllName; |
1159 TFullName dllName; |
998 |
1160 _LIT(KSysBin,"z:\\sys\\bin\\"); |
999 // is this policy "critical" i.e non-replaceable ? |
|
1000 _LIT(KSysBin,"z:\\sys\\bin\\"); |
|
1001 // const TInt KMaxCriticalPolicyDll = 1000; |
|
1002 // if (aHierarchyId < KMaxCriticalPolicyDll) // <-- cannot be false while aHierarchyId is a TUint8 (typedef'd to TDmHierarchyId) |
|
1003 dllName.Append(KSysBin); |
1161 dllName.Append(KSysBin); |
1004 |
|
1005 dllName.Append(_L("domainPolicy")); |
1162 dllName.Append(_L("domainPolicy")); |
1006 if (aHierarchyId != KDmHierarchyIdPower) |
1163 if (aHierarchyId != KDmHierarchyIdPower) |
1007 dllName.AppendNum(aHierarchyId); |
1164 dllName.AppendNum(aHierarchyId); |
1008 |
1165 |
1009 dllName.Append(_L(".dll")); |
1166 dllName.Append(_L(".dll")); |
1071 break; |
1227 break; |
1072 } |
1228 } |
1073 |
1229 |
1074 domain = CSvrDomain::New(*hierarchy, *spec); |
1230 domain = CSvrDomain::New(*hierarchy, *spec); |
1075 __DS_ASSERT(domain); |
1231 __DS_ASSERT(domain); |
1076 |
1232 |
1077 if (spec->iParentId == KDmIdNone) |
1233 if (spec->iParentId == KDmIdNone) |
1078 { |
1234 { |
1079 if (hierarchy->iRootDomain) |
1235 if (hierarchy->iRootDomain) |
1080 { |
1236 { |
|
1237 delete domain; |
|
1238 domain = NULL; |
1081 r = KDmErrBadDomainSpec; |
1239 r = KDmErrBadDomainSpec; |
1082 break; |
1240 break; |
1083 } |
1241 } |
1084 hierarchy->iRootDomain = domain; |
1242 hierarchy->iRootDomain = domain; |
1085 } |
1243 } |
1086 else |
1244 else |
1087 { |
1245 { |
1088 CSvrDomain* parent = hierarchy->LookupDomain(spec->iParentId); |
1246 CSvrDomain* parent = hierarchy->LookupDomain(spec->iParentId); |
1089 if (!parent) |
1247 if (!parent) |
1090 { |
1248 { |
|
1249 delete domain; |
|
1250 domain = NULL; |
1091 r = KDmErrBadDomainSpec; |
1251 r = KDmErrBadDomainSpec; |
1092 break; |
1252 break; |
1093 } |
1253 } |
1094 parent->AddChild(domain); |
1254 parent->AddChild(domain); |
1095 } |
1255 } |
1096 ++spec; |
1256 ++spec; |
1097 } |
1257 } |
|
1258 |
|
1259 |
1098 |
1260 |
1099 if (spec) |
1261 if (spec) |
1100 (*release)(spec); |
1262 (*release)(spec); |
1101 |
1263 |
|
1264 // Load state specs |
|
1265 if (r == KErrNone) |
|
1266 { |
|
1267 TInt err = LoadStateSpecs(lib, hierarchy); |
|
1268 |
|
1269 // KErrNotFound indicates that policy does not contain state |
|
1270 // specs i.e. it is Version 1 |
|
1271 if ( (err !=KErrNone) && (err !=KErrNotFound)) |
|
1272 { |
|
1273 r = err; |
|
1274 } |
|
1275 } |
1102 |
1276 |
1103 if (r == KErrNone) |
1277 if (r == KErrNone) |
1104 { |
1278 { |
1105 __DS_ASSERT(hierarchy->iRootDomain); |
1279 __DS_ASSERT(hierarchy->iRootDomain); |
1106 iDomainHierarchies.Append(hierarchy); |
1280 iDomainHierarchies.Append(hierarchy); |
1107 aHierarchy = hierarchy; |
|
1108 } |
1281 } |
1109 else |
1282 else |
1110 { |
1283 { |
1111 delete hierarchy; |
1284 delete hierarchy; |
1112 hierarchy = NULL; |
1285 hierarchy = NULL; |
1113 } |
1286 } |
1114 |
1287 |
1115 lib.Close(); |
1288 lib.Close(); |
|
1289 |
|
1290 return r; |
|
1291 } |
|
1292 |
|
1293 TInt CDmSvrManager::LoadStateSpecs(RLibrary& aLib, CDmHierarchy* aHierarchy) |
|
1294 { |
|
1295 __DS_TRACE((_L("DM: CDmSvrManager::LoadStateSpecs() on CDmHierarchy @0x%08x"), aHierarchy)); |
|
1296 TLibraryFunction ordinal4 = aLib.Lookup(EDmPolicyGetStateSpec); |
|
1297 DmPolicyGetStateSpec getStateSpec = reinterpret_cast<DmPolicyGetStateSpec>(ordinal4); |
|
1298 if (getStateSpec == NULL) |
|
1299 return KErrNotFound; |
|
1300 |
|
1301 TLibraryFunction ordinal5 = aLib.Lookup(EDmPolicyReleaseStateSpec); |
|
1302 DmPolicyReleaseStateSpec releaseStateSpec = reinterpret_cast<DmPolicyReleaseStateSpec>(ordinal5); |
|
1303 if (releaseStateSpec == NULL) |
|
1304 return KErrNotFound; |
|
1305 |
|
1306 TAny* spec = NULL; |
|
1307 TUint count = 0; |
|
1308 TInt version = (*getStateSpec)(spec, count); |
|
1309 TInt r = KErrNone; |
|
1310 |
|
1311 switch (version) |
|
1312 { |
|
1313 case 0: |
|
1314 { |
|
1315 r = KErrNotFound; |
|
1316 break; |
|
1317 } |
|
1318 case 1: |
|
1319 { |
|
1320 if (count < 1) |
|
1321 { |
|
1322 r = KDmErrBadDomainSpec; |
|
1323 break; |
|
1324 } |
|
1325 |
|
1326 SDmStateSpecV1* specV1 = reinterpret_cast<SDmStateSpecV1*>(spec); |
|
1327 for(TUint i = 0; i<count; ++i) |
|
1328 { |
|
1329 const TTransitionConfig transitionCfg(specV1[i]); |
|
1330 r = transitionCfg.CheckValues(); |
|
1331 if (r != KErrNone) |
|
1332 { |
|
1333 break; |
|
1334 } |
|
1335 TRAP(r, aHierarchy->HierachySettings().StoreConfigL(transitionCfg)); |
|
1336 if (r != KErrNone) |
|
1337 { |
|
1338 break; |
|
1339 } |
|
1340 } |
|
1341 break; |
|
1342 } |
|
1343 default: |
|
1344 { |
|
1345 if (version > 1) |
|
1346 { |
|
1347 r = KDmErrBadDomainSpec; |
|
1348 } |
|
1349 else |
|
1350 { |
|
1351 r = version; |
|
1352 } |
|
1353 break; |
|
1354 } |
|
1355 } |
|
1356 |
|
1357 if(spec) |
|
1358 (*releaseStateSpec)(spec); |
1116 |
1359 |
1117 return r; |
1360 return r; |
1118 } |
1361 } |
1119 |
1362 |
1120 CDmHierarchy* CDmSvrManager::LookupHierarchy(TDmHierarchyId aHierarchyId) |
1363 CDmHierarchy* CDmSvrManager::LookupHierarchy(TDmHierarchyId aHierarchyId) |
1148 if (aDomain == NULL) |
1391 if (aDomain == NULL) |
1149 return KDmErrBadDomainId; |
1392 return KDmErrBadDomainId; |
1150 |
1393 |
1151 return KErrNone; |
1394 return KErrNone; |
1152 } |
1395 } |
1153 |
1396 |
|
1397 |
1154 CSession2* CDmManagerServer::NewSessionL(const TVersion&, const RMessage2& aMessage) const |
1398 CSession2* CDmManagerServer::NewSessionL(const TVersion&, const RMessage2& aMessage) const |
1155 { |
1399 { |
1156 |
|
1157 // If the client does not have ECapabilityPowerMgmt capability, then it has no |
1400 // If the client does not have ECapabilityPowerMgmt capability, then it has no |
1158 // right to make this request. Blow it up. |
1401 // right to make this request. Blow it up. |
1159 if (!KPowerMgmtPolicy.CheckPolicy(aMessage)) |
1402 if (!KPowerMgmtPolicy.CheckPolicy(aMessage)) |
1160 { |
1403 { |
1161 |
|
1162 User::Leave(KErrPermissionDenied); |
1404 User::Leave(KErrPermissionDenied); |
1163 |
1405 } |
1164 } |
1406 |
1165 |
1407 CDmManagerSession* session = new CDmManagerSession(); |
1166 return new CDmManagerSession(); |
1408 #if defined(_DEBUG) || defined(__DS_DEBUG) |
1167 } |
1409 CleanupStack::PushL(session); |
1168 |
1410 TFullName clientName; |
1169 CSession2* CDmManagerServer::NewSessionL(const TVersion&) const |
1411 GetClientNameFromMessageL(aMessage, clientName); |
1170 { |
1412 |
1171 __DS_PANIC(KErrGeneral); |
1413 // Sessions on this server may not be shared by clients |
1172 return 0; |
1414 __DS_TRACE((_L("DM: New CDmManagerSession @0x%08x, client %S"), session, &clientName)); |
|
1415 CleanupStack::Pop(); |
|
1416 #else |
|
1417 (void)aMessage; |
|
1418 #endif |
|
1419 return session; |
1173 } |
1420 } |
1174 |
1421 |
1175 CDmManagerSession::CDmManagerSession() |
1422 CDmManagerSession::CDmManagerSession() |
1176 {} |
1423 { |
|
1424 __DS_TRACE((_L("DM: CDmManagerSession() @0x%08x"), this)); |
|
1425 } |
1177 |
1426 |
1178 CDmManagerSession::~CDmManagerSession() |
1427 CDmManagerSession::~CDmManagerSession() |
1179 { |
1428 { |
1180 if (iHierarchy && iHierarchy->iControllerSession == this) |
1429 __DS_TRACE((_L("DM: ~CDmManagerSession() @0x%08x"), this)); |
1181 iHierarchy->iControllerSession = NULL; |
1430 |
1182 if (iHierarchy && iHierarchy->iObserverSession == this) |
1431 if (iHierarchy) |
1183 iHierarchy->iObserverSession = NULL; |
1432 { |
1184 } |
1433 if (iHierarchy->iControllerSession == this) |
1185 |
1434 { |
1186 class MyMessage : public RMessage2 |
1435 iHierarchy->iControllerSession = NULL; |
1187 { |
1436 } |
1188 public: |
1437 if (iHierarchy->iObserverSession == this) |
1189 TInt* ArgRef(TInt i) |
1438 { |
1190 { return &iArgs[i]; } |
1439 iHierarchy->iObserverSession = NULL; |
1191 }; |
1440 } |
|
1441 } |
|
1442 |
|
1443 if(!iTransMessagePtr.IsNull()) |
|
1444 iTransMessagePtr.Complete(KErrCancel); |
|
1445 |
|
1446 if(!iObsvrMessagePtr.IsNull()) |
|
1447 iObsvrMessagePtr.Complete(KErrCancel); |
|
1448 } |
1192 |
1449 |
1193 void CDmManagerSession::ServiceL(const RMessage2& aMessage) |
1450 void CDmManagerSession::ServiceL(const RMessage2& aMessage) |
1194 { |
1451 { |
1195 TInt r; |
1452 TInt r; |
1196 CDmSvrManager* manager = ((CDmManagerServer*) Server()) -> iManager; |
1453 CDmSvrManager* manager = ((CDmManagerServer*) Server()) -> iManager; |
1197 |
1454 |
1198 // Check client has ECapabilityPowerMgmt capability |
|
1199 /* |
|
1200 if (!KPowerMgmtPolicy.CheckPolicy(aMessage)) |
|
1201 { |
|
1202 aMessage.Complete(KErrPermissionDenied); |
|
1203 return; |
|
1204 } |
|
1205 */ |
|
1206 switch (aMessage.Function()) |
1455 switch (aMessage.Function()) |
1207 { |
1456 { |
1208 case EDmHierarchyAdd: |
1457 case EDmHierarchyAdd: |
1209 { |
1458 { |
1210 r = KErrNone; |
1459 r = KErrNone; |
1211 TDmHierarchyId hierarchyId = (TDmHierarchyId) aMessage.Int0(); |
1460 TDmHierarchyId hierarchyId = (TDmHierarchyId) aMessage.Int0(); |
1212 |
1461 __DS_TRACE((_L("DM: CDmManagerSession::ServiceL @0x%08x EDmHierarchyAdd, HierarchyId %d"), this, hierarchyId)); |
1213 CDmHierarchy* hierarchy = manager->LookupHierarchy(hierarchyId); |
1462 |
1214 if (hierarchy == NULL) |
1463 if (manager->LookupHierarchy(hierarchyId) == NULL) |
1215 r = manager->BuildDomainTree(hierarchyId, hierarchy); |
1464 r = manager->BuildDomainTree(hierarchyId); |
1216 aMessage.Complete(r); |
1465 aMessage.Complete(r); |
1217 } |
1466 } |
1218 break; |
1467 break; |
1219 |
1468 |
1220 case EDmHierarchyJoin: |
1469 case EDmHierarchyJoin: |
1221 { |
1470 { |
1222 r = KErrNone; |
1471 r = KErrNone; |
1223 TDmHierarchyId hierarchyId = (TDmHierarchyId) aMessage.Int0(); |
1472 TDmHierarchyId hierarchyId = (TDmHierarchyId) aMessage.Int0(); |
|
1473 __DS_TRACE((_L("DM: CDmManagerSession::ServiceL @0x%08x EDmHierarchyJoin, HierarchyId %d"), this, hierarchyId)); |
1224 |
1474 |
1225 iHierarchy = manager->LookupHierarchy(hierarchyId); |
1475 iHierarchy = manager->LookupHierarchy(hierarchyId); |
1226 if (iHierarchy == NULL) |
1476 if (iHierarchy == NULL) |
1227 r = KErrBadHierarchyId; |
1477 r = KErrBadHierarchyId; |
1228 |
1478 |
1250 aMessage.Complete(KDmErrBadSequence); |
1507 aMessage.Complete(KDmErrBadSequence); |
1251 break; |
1508 break; |
1252 } |
1509 } |
1253 |
1510 |
1254 r = iHierarchy->RequestSystemTransition( |
1511 r = iHierarchy->RequestSystemTransition( |
1255 (TDmDomainState) aMessage.Int0(), |
1512 targetState, |
1256 (TDmTraverseDirection) aMessage.Int1(), |
1513 direction, |
1257 &aMessage); |
1514 &aMessage); |
1258 |
1515 |
1259 if (r != KErrNone) |
1516 if (r != KErrNone) |
1260 aMessage.Complete(r); |
1517 aMessage.Complete(r); |
1261 break; |
1518 break; |
|
1519 } |
1262 |
1520 |
1263 case EDmRequestDomainTransition: |
1521 case EDmRequestDomainTransition: |
|
1522 { |
|
1523 const TDmDomainId domain = (TDmDomainId)aMessage.Int0(); |
|
1524 const TDmDomainState targetState = aMessage.Int1(); |
|
1525 const TDmTraverseDirection direction = (TDmTraverseDirection)aMessage.Int2(); |
|
1526 |
|
1527 __DS_TRACE((_L("DM: CDmManagerSession::ServiceL @0x%08x EDmRequestDomainTransition, Domain 0x%x, TargetState %d, Direction %d"), |
|
1528 this, domain, targetState, direction)); |
|
1529 |
1264 if (iHierarchy==NULL) |
1530 if (iHierarchy==NULL) |
1265 { |
1531 { |
1266 aMessage.Complete(KErrBadHierarchyId); |
1532 aMessage.Complete(KErrBadHierarchyId); |
1267 break; |
1533 break; |
1268 } |
1534 } |
1269 if (iHierarchy->iTransDomain) |
1535 if (iHierarchy->iTransDomain) |
1270 { |
1536 { |
1271 aMessage.Complete(KDmErrBadSequence); |
1537 aMessage.Complete(KDmErrBadSequence); |
1272 break; |
1538 break; |
1273 } |
1539 } |
|
1540 |
1274 r = iHierarchy->RequestDomainTransition( |
1541 r = iHierarchy->RequestDomainTransition( |
1275 (TDmDomainId) aMessage.Int0(), |
1542 domain, |
1276 (TDmDomainState) aMessage.Int1(), |
1543 targetState, |
1277 (TDmTraverseDirection) aMessage.Int2(), |
1544 direction, |
1278 &aMessage); |
1545 &aMessage); |
1279 |
1546 |
1280 if (r != KErrNone) |
1547 if (r != KErrNone) |
1281 aMessage.Complete(r); |
1548 aMessage.Complete(r); |
1282 break; |
1549 break; |
|
1550 } |
1283 |
1551 |
1284 case EDmGetTransitionFailureCount: |
1552 case EDmGetTransitionFailureCount: |
1285 { |
1553 { |
1286 if (iHierarchy==NULL) |
1554 if (iHierarchy==NULL) |
1287 { |
1555 { |
1496 aMessage.Complete(KDmErrBadRequest); |
1768 aMessage.Complete(KDmErrBadRequest); |
1497 break; |
1769 break; |
1498 } |
1770 } |
1499 } |
1771 } |
1500 |
1772 |
1501 CSession2* CDmDomainServer::NewSessionL(const TVersion&, const RMessage2&) const |
1773 CSession2* CDmDomainServer::NewSessionL(const TVersion&, const RMessage2& aMessage) const |
1502 { |
1774 { |
1503 |
1775 CDmDomainSession* session = new (ELeave) CDmDomainSession; |
1504 return new CDmDomainSession(); |
1776 #ifdef __DS_DEBUG |
1505 } |
1777 CleanupStack::PushL(session); |
1506 |
1778 TFullName clientName; |
1507 CSession2* CDmDomainServer::NewSessionL(const TVersion&) const |
1779 GetClientNameFromMessageL(aMessage, clientName); |
1508 { |
1780 |
1509 __DS_PANIC(KErrGeneral); |
1781 // Sessions on this server may not be shared by clients |
1510 return 0; |
1782 __DS_TRACE((_L("DM: New CDmDomainSession @0x%08x, client %S"), session, &clientName)); |
|
1783 CleanupStack::Pop(); |
|
1784 #else |
|
1785 (void)aMessage; |
|
1786 #endif |
|
1787 return session; |
|
1788 } |
|
1789 |
|
1790 CDmDomainSession::CDmDomainSession() |
|
1791 : iDeferralsRemaining(0) |
|
1792 { |
|
1793 __DS_TRACE((_L("DM: CDmDomainSession() @0x%08x"), this)); |
1511 } |
1794 } |
1512 |
1795 |
1513 CDmDomainSession::~CDmDomainSession() |
1796 CDmDomainSession::~CDmDomainSession() |
1514 { |
1797 { |
1515 if (iPending) |
1798 __DS_TRACE((_L("DM: ~CDmDomainSession() @0x%08x"), this)); |
|
1799 if (iAcknPending) |
1516 iDomain->CompleteMemberTransition(KErrNone); |
1800 iDomain->CompleteMemberTransition(KErrNone); |
1517 if (iDomain) |
1801 if (iDomain) |
1518 iDomain->Detach(this); |
1802 iDomain->Detach(this); |
|
1803 if (DeferralActive()) |
|
1804 CancelDeferral(); |
1519 } |
1805 } |
1520 |
1806 |
1521 void CDmDomainSession::ServiceL(const RMessage2& aMessage) |
1807 void CDmDomainSession::ServiceL(const RMessage2& aMessage) |
1522 { |
1808 { |
1523 TInt r = KErrNone; |
1809 TInt r = KErrNone; |
1546 iDomain->Attach(this); |
1834 iDomain->Attach(this); |
1547 break; |
1835 break; |
1548 } |
1836 } |
1549 |
1837 |
1550 case EDmStateRequestTransitionNotification: |
1838 case EDmStateRequestTransitionNotification: |
|
1839 __DS_TRACE((_L("DM: CDmDomainSession::ServiceL @0x%08x EDmStateRequestTransitionNotification"), this)); |
1551 iNotificationEnabled = ETrue; |
1840 iNotificationEnabled = ETrue; |
1552 break; |
1841 break; |
1553 |
1842 |
1554 case EDmStateCancelTransitionNotification: |
1843 case EDmStateCancelTransitionNotification: |
|
1844 __DS_TRACE((_L("DM: CDmDomainSession::ServiceL @0x%08x EDmStateCancelTransitionNotification"), this)); |
1555 iNotificationEnabled = EFalse; |
1845 iNotificationEnabled = EFalse; |
1556 break; |
1846 break; |
1557 |
1847 |
1558 case EDmStateAcknowledge: |
1848 case EDmStateAcknowledge: |
1559 { |
1849 { |
1560 TInt propValue = aMessage.Int0(); |
1850 TInt propValue = aMessage.Int0(); |
1561 TInt error = aMessage.Int1(); |
1851 TInt error = aMessage.Int1(); |
|
1852 |
|
1853 __DS_TRACE((_L("DM: CDmDomainSession::ServiceL @0x%08x EDmStateAcknowledge, error %d"), this, error)); |
|
1854 |
1562 if (!iDomain) |
1855 if (!iDomain) |
1563 { |
1856 { |
1564 r = KDmErrNotJoin; |
1857 r = KDmErrNotJoin; |
1565 break; |
1858 break; |
1566 } |
1859 } |
1567 if (iPending && iDomain->CheckPropValue(propValue)) |
1860 if (iAcknPending && iDomain->CheckPropValue(propValue)) |
1568 { |
1861 { |
1569 iPending = EFalse; |
1862 if (DeferralActive()) |
|
1863 ObsoleteDeferral(); |
|
1864 |
|
1865 iAcknPending = EFalse; |
1570 iDomain->CompleteMemberTransition(error); |
1866 iDomain->CompleteMemberTransition(error); |
1571 } |
1867 } |
1572 } |
1868 else |
|
1869 { |
|
1870 // This error code indicates that there was no pending transition |
|
1871 // corresponding to the cookie supplied in propValue. |
|
1872 r = KErrNotFound; |
|
1873 } |
|
1874 |
1573 break; |
1875 break; |
|
1876 } |
|
1877 |
|
1878 case EDmStateDeferAcknowledgement: |
|
1879 { |
|
1880 __DS_TRACE((_L("DM: CDmDomainSession::ServiceL @0x%08x EDmStateDeferAcknowledgement"), this)); |
|
1881 |
|
1882 // PlatSec check |
|
1883 if (!KWddPolicy.CheckPolicy(aMessage, |
|
1884 __PLATSEC_DIAGNOSTIC_STRING("KWriteDeviceDataPolicy")) && |
|
1885 !KProtServPolicy.CheckPolicy(aMessage, |
|
1886 __PLATSEC_DIAGNOSTIC_STRING("KProtServPolicy"))) |
|
1887 { |
|
1888 // Try harder... |
|
1889 r = KErrPermissionDenied; |
|
1890 break; |
|
1891 } |
|
1892 DeferAcknowledgment(aMessage); |
|
1893 return; // return, not break |
|
1894 } |
|
1895 |
|
1896 case EDmStateCancelDeferral: |
|
1897 { |
|
1898 __DS_TRACE((_L("DM: CDmDomainSession::ServiceL @0x%08x EDmStateCancelDeferral"), this)); |
|
1899 CancelDeferral(); |
|
1900 break; |
|
1901 } |
1574 default: |
1902 default: |
1575 r = KDmErrBadRequest; |
1903 r = KDmErrBadRequest; |
1576 break; |
1904 break; |
1577 } |
1905 } |
|
1906 |
1578 aMessage.Complete(r); |
1907 aMessage.Complete(r); |
1579 } |
1908 } |
1580 |
1909 |
1581 |
1910 void CDmDomainSession::SetDeferralBudget(TInt aDeferralCount) |
|
1911 { |
|
1912 __DS_ASSERT(!DeferralActive()); |
|
1913 iDeferralsRemaining = aDeferralCount; |
|
1914 } |
|
1915 |
|
1916 TBool CDmDomainSession::DeferralActive() const |
|
1917 { |
|
1918 return (!iDeferralMsg.IsNull()); |
|
1919 } |
|
1920 |
|
1921 void CDmDomainSession::ExpireDeferral() |
|
1922 { |
|
1923 __DS_ASSERT(DeferralActive()); |
|
1924 __DS_ASSERT(iDeferralsRemaining >= 0); |
|
1925 |
|
1926 CompleteDeferral(KErrNone); |
|
1927 } |
|
1928 |
|
1929 void CDmDomainSession::DeferAcknowledgment(const RMessage2& aMessage) |
|
1930 { |
|
1931 __DS_ASSERT(aMessage.Function() == EDmStateDeferAcknowledgement); |
|
1932 __DS_ASSERT(!DeferralActive()); |
|
1933 |
|
1934 TInt r = KErrNone; |
|
1935 |
|
1936 if (!iAcknPending) |
|
1937 { |
|
1938 r = KErrNotReady; |
|
1939 } |
|
1940 else if (iDeferralsRemaining == 0) |
|
1941 { |
|
1942 r = KErrNotSupported; |
|
1943 } |
|
1944 |
|
1945 if(KErrNone != r) |
|
1946 { |
|
1947 aMessage.Complete(r); |
|
1948 return; |
|
1949 } |
|
1950 |
|
1951 --iDeferralsRemaining; |
|
1952 iDeferralMsg = aMessage; |
|
1953 } |
|
1954 |
|
1955 void CDmDomainSession::CancelDeferral() |
|
1956 { |
|
1957 if (DeferralActive()) |
|
1958 { |
|
1959 CompleteDeferral(KErrCancel); |
|
1960 } |
|
1961 } |
|
1962 |
|
1963 void CDmDomainSession::ObsoleteDeferral() |
|
1964 { |
|
1965 __DS_ASSERT(DeferralActive()); |
|
1966 |
|
1967 CompleteDeferral(KErrCompletion); |
|
1968 } |
|
1969 |
|
1970 void CDmDomainSession::CompleteDeferral(TInt aError) |
|
1971 { |
|
1972 __DS_TRACE((_L("DM: CDmDomainSession::CompleteDeferral() @0x%08x, aError %d"), this, aError)); |
|
1973 __DS_ASSERT(DeferralActive()); |
|
1974 |
|
1975 iDeferralMsg.Complete(aError); |
|
1976 } |
|
1977 |
|
1978 |
1582 TInt E32Main() |
1979 TInt E32Main() |
1583 { |
1980 { |
|
1981 // Make DM a system critical server |
|
1982 User::SetProcessCritical(User::ESystemCritical); |
|
1983 User::SetCritical(User::ESystemCritical); |
|
1984 |
1584 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
1985 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
1585 if(!cleanupStack) |
1986 __DS_ASSERT_STARTUP(cleanupStack); |
1586 __DS_PANIC(KErrNoMemory); |
|
1587 |
1987 |
1588 CActiveScheduler* sched = new CActiveScheduler(); |
1988 CActiveScheduler* sched = new CActiveScheduler(); |
1589 if (!sched) |
1989 __DS_ASSERT_STARTUP(sched); |
1590 __DS_PANIC(KErrNoMemory); |
|
1591 |
1990 |
1592 CActiveScheduler::Install(sched); |
1991 CActiveScheduler::Install(sched); |
1593 |
1992 |
1594 CDmSvrManager* mngr = CDmSvrManager::New(); |
1993 CDmSvrManager* mngr = CDmSvrManager::New(); |
1595 __DS_ASSERT(mngr); |
1994 __DS_ASSERT_STARTUP(mngr); |
1596 |
1995 |
1597 CDmManagerServer* msrv = new CDmManagerServer(mngr); |
1996 CDmManagerServer* msrv = new CDmManagerServer(mngr); |
1598 if (!msrv) |
1997 __DS_ASSERT_STARTUP(msrv); |
1599 __DS_PANIC(KErrNoMemory); |
|
1600 |
1998 |
1601 TInt r=msrv->Start(KDmManagerServerNameLit); |
1999 TInt r=msrv->Start(KDmManagerServerNameLit); |
1602 if (r != KErrNone) |
2000 __DS_ASSERT_STARTUP(r == KErrNone); |
1603 __DS_PANIC(r); |
|
1604 |
2001 |
1605 CDmDomainServer* dsrv = new CDmDomainServer(mngr); |
2002 CDmDomainServer* dsrv = new CDmDomainServer(mngr); |
1606 if (!dsrv) |
2003 __DS_ASSERT_STARTUP(dsrv); |
1607 __DS_PANIC(KErrNoMemory); |
|
1608 |
2004 |
1609 r=dsrv->Start(KDmDomainServerNameLit); |
2005 r=dsrv->Start(KDmDomainServerNameLit); |
1610 if (r != KErrNone) |
2006 __DS_ASSERT_STARTUP(r == KErrNone); |
1611 __DS_PANIC(r); |
|
1612 |
2007 |
1613 CActiveScheduler::Start(); |
2008 CActiveScheduler::Start(); |
1614 |
2009 |
|
2010 // Server should never shutdown, hence panic to highlight such an event |
1615 __DS_PANIC(0); |
2011 __DS_PANIC(0); |
1616 |
2012 |
1617 return KErrNone; |
2013 return KErrNone; |
1618 } |
2014 } |