222 |
238 |
223 |
239 |
224 |
240 |
225 /** |
241 /** |
226 Acknowledges the state change. |
242 Acknowledges the state change. |
227 |
243 |
228 An application must acknowledge that it has performed all actions required |
244 An application must acknowledge that it has performed all actions required |
229 by the last known state of the domain. |
245 by the last known state of the domain. |
230 */ |
246 */ |
231 EXPORT_C void RDmDomain::AcknowledgeLastState() |
247 EXPORT_C void RDmDomain::AcknowledgeLastState() |
232 { |
248 { |
233 iSession.Acknowledge(iLastStatePropertyValue, KErrNone); |
249 TInt r = iSession.Acknowledge(iLastStatePropertyValue, KErrNone); |
234 } |
250 |
235 |
251 if (r != KErrNone && r != KErrNotFound) |
|
252 __DM_PANIC(r); |
|
253 } |
236 |
254 |
237 /** |
255 /** |
238 Acknowledges the state change with the specified error |
256 Acknowledges the state change with the specified error |
239 |
257 |
240 An application must acknowledge that it has performed all actions required |
258 An application must acknowledge that it has performed all actions required |
241 by the last known state of the domain. |
259 by the last known state of the domain. |
242 |
260 |
243 @param aError KDmErrNotJoin if domain is not part of the hierarhcy or a |
261 @param aError KDmErrNotJoin if domain is not part of the hierarchy or a |
244 system wide error value associated with the state change. |
262 system wide error value associated with the state change. |
245 */ |
263 */ |
246 EXPORT_C void RDmDomain::AcknowledgeLastState(TInt aError) |
264 EXPORT_C void RDmDomain::AcknowledgeLastState(TInt aError) |
247 { |
265 { |
248 iSession.Acknowledge(iLastStatePropertyValue, aError); |
266 TInt r = iSession.Acknowledge(iLastStatePropertyValue, aError); |
249 } |
267 |
250 |
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); |
|
283 } |
|
284 |
|
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 } |
251 |
346 |
252 |
347 |
253 /** |
348 /** |
254 Gets the domain's state. |
349 Gets the domain's state. |
255 |
350 |
256 An application normally calls this function after a notification request |
351 An application normally calls this function after a notification request |
257 has completed. It then performs any application-dependent action demanded by |
352 has completed. It then performs any application-dependent action demanded by |
258 the state, and then acknowledges the state transition. |
353 the state, and then acknowledges the state transition. |
259 |
354 |
260 Note, that the domain manager requires any domain state change to be |
355 Note, that the Domain Manager requires any domain state change to be |
261 acknowledged by all applications connected to the domain. |
356 acknowledged by all applications connected to the domain. |
262 |
357 |
263 @return The connected domain's state. |
358 @return The connected domain's state. |
264 */ |
359 */ |
265 EXPORT_C TDmDomainState RDmDomain::GetState() |
360 EXPORT_C TDmDomainState RDmDomain::GetState() |
545 |
649 |
546 return r; |
650 return r; |
547 } |
651 } |
548 |
652 |
549 |
653 |
550 |
|
551 |
|
552 /** |
654 /** |
553 Opens a controlling connection to the standard power domain hierarchy |
655 Opens a controlling connection to the standard power domain hierarchy |
554 in the domain manager. |
656 in the Domain Manager. |
555 |
657 |
556 The domain manger allows only one open connection at any one time to the |
658 The Domain Manager allows only one open connection at any one time to the |
557 power domain hierarchy. |
659 power domain hierarchy. |
558 Connection is usually made by the power policy entity. |
660 |
559 |
661 @return KErrNone if successful, otherwise one of the other system-wide |
560 @return KErrNone, if successful; otherwise one of the other system-wide |
662 or the Domain Manager specific error codes. |
561 or the domain manager specific error codes. |
663 @return KErrInUse when the power hierarchy already has a controller connected. |
562 |
664 @return KErrBadHierarchyId when the server has failed to load the power hierarchy. |
563 @see KDmErrAlreadyJoin |
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 |
564 */ |
669 */ |
565 EXPORT_C TInt RDmDomainManager::Connect() |
670 EXPORT_C TInt RDmDomainManager::Connect() |
566 { |
671 { |
567 return iSession.Connect(KDmHierarchyIdPower); |
672 return iSession.Connect(KDmHierarchyIdPower); |
568 } |
673 } |
569 |
674 |
570 |
675 |
571 |
676 /** |
572 |
677 Opens a controlling connection to a specific domain hierarchy previously |
573 /** |
678 loaded into the Domain Manager by the controller. The Domain Manager allows only |
574 Opens a controlling connection to a specific domain hieararchy owned |
679 one open connection at any one time to a particular hierarchy. |
575 by the domain manager. |
680 |
576 |
681 @param aHierarchyId The Id of the domain hierarchy to connect to. |
577 The domain manger allows only one open connection at any one time to a |
682 |
578 particular hierarchy. |
683 @return KErrNone if successful, otherwise one of the other system-wide |
579 |
684 or the Domain Manager specific error codes. |
580 @param aHierarchyId The Id of the domain hierarchy to connect to. |
685 @return KErrInUse when the power hierarchy already has a controller connected. |
581 |
686 @return KErrBadHierarchyId when the server has failed to load the power hierarchy. |
582 @return KErrNone, if successful; otherwise one of the other system-wide |
687 @return KErrPermissionDenied when the client has insufficient capabilities |
583 or domain manager specific error codes. |
688 |
584 |
689 @capability PowerMgmt Required to create a connection to the Domain Manager. |
585 @see KDmErrAlreadyJoin |
|
586 @see KErrBadHierarchyId |
|
587 */ |
690 */ |
588 EXPORT_C TInt RDmDomainManager::Connect(TDmHierarchyId aHierarchyId) |
691 EXPORT_C TInt RDmDomainManager::Connect(TDmHierarchyId aHierarchyId) |
589 |
|
590 { |
692 { |
591 return iSession.Connect(aHierarchyId); |
693 return iSession.Connect(aHierarchyId); |
592 } |
694 } |
593 |
695 |
594 |
696 |
595 |
697 /** |
596 |
698 Closes this connection to the Domain Manager. |
597 /** |
|
598 Closes this connection to the domain manager. |
|
599 |
699 |
600 If there is no existing connection, then it returns silently. |
700 If there is no existing connection, then it returns silently. |
601 */ |
701 */ |
602 EXPORT_C void RDmDomainManager::Close() |
702 EXPORT_C void RDmDomainManager::Close() |
603 { |
703 { |
604 iSession.Close(); |
704 iSession.Close(); |
605 } |
705 } |
606 |
706 |
607 |
707 |
608 |
708 /** |
609 |
709 Requests a system-wide power state transition and is used with the |
610 /** |
710 KDmHierarchyIdPower hierarchy. The domain hierarchy is traversed in the |
611 Requests a system-wide power state transition. |
711 default direction. |
612 |
712 |
613 The domain hierarchy is traversed in the default direction |
713 A transition to the power state EPwActive is an error and result in |
614 |
714 async completion with KErrArgument. |
615 @param aState The target power state. |
715 |
616 @param aStatus The request status object for this asynchronous request. |
716 @param aState The target power state, not EPwActive or >=EPwLimit. |
|
717 @param aStatus The request status object for this asynchronous request. |
617 |
718 |
618 @see RDmDomainManager::CancelTransition() |
719 @see RDmDomainManager::CancelTransition() |
|
720 @see KDmHierarchyIdPower |
619 */ |
721 */ |
620 EXPORT_C void RDmDomainManager::RequestSystemTransition(TPowerState aState, TRequestStatus& aStatus) |
722 EXPORT_C void RDmDomainManager::RequestSystemTransition(TPowerState aState, TRequestStatus& aStatus) |
621 { |
723 { |
622 if (aState == EPwActive) |
724 if ((aState == EPwActive) || (aState >= EPwLimit)) |
623 { |
725 { |
624 TRequestStatus* status = &aStatus; |
726 TRequestStatus* status = &aStatus; |
625 User::RequestComplete(status, KErrArgument); |
727 User::RequestComplete(status, KErrArgument); |
626 return; |
728 return; |
627 } |
729 } |
628 RequestSystemTransition((TDmDomainState) aState, ETraverseDefault, aStatus); |
730 RequestSystemTransition((TDmDomainState) aState, ETraverseDefault, aStatus); |
629 } |
731 } |
630 |
732 |
631 |
733 |
632 |
734 /** |
633 |
735 Requests a system-wide power off (EPwOff) state transition to shutdown the |
634 /** |
736 platform. Applicable to the KDmHierarchyIdPower hierarchy. |
635 Requests a system-wide power shutdown. |
737 |
636 |
738 This call does not return; the system can only return by physical button restart. |
637 This is a request to change the system's power state to EPwOff. |
739 |
638 This call does not return; the system can only return by rebooting. |
740 @see KDmHierarchyIdPower |
639 */ |
741 */ |
640 EXPORT_C void RDmDomainManager::SystemShutdown() |
742 EXPORT_C void RDmDomainManager::SystemShutdown() |
641 { |
743 { |
642 TRequestStatus status; |
744 TRequestStatus status; |
643 RequestSystemTransition((TDmDomainState) EPwOff, ETraverseDefault, status); |
745 RequestSystemTransition((TDmDomainState) EPwOff, ETraverseDefault, status); |
644 User::WaitForRequest(status); |
746 User::WaitForRequest(status); |
645 __DM_ASSERT(0); |
747 __DM_ASSERT(0); |
646 } |
748 } |
647 |
749 |
648 |
750 |
649 |
751 /** |
650 |
752 Requests a domain power state transition and is used with the |
651 /** |
753 KDmHierarchyIdPower hierarchy. The domain hierarchy is traversed in the |
652 Requests a domain state transition. |
754 default direction. |
653 |
|
654 The domain hierarchy is traversed in the default direction. |
|
655 |
755 |
656 @param aDomainId The Id of the domain for which the state transition |
756 @param aDomainId The Id of the domain for which the state transition |
657 is being requested. |
757 is being requested. |
658 @param aState The target state. |
758 @param aState The target power state. |
659 @param aStatus The request status object for this asynchronous request. |
759 @param aStatus The request status object to receive the asynchronous result. |
660 |
760 KErrNone if successful, otherwise one of the other system-wide |
|
761 or the Domain Manager specific error codes. |
|
762 |
|
763 @see KDmHierarchyIdPower |
661 @see RDmDomainManager::CancelTransition() |
764 @see RDmDomainManager::CancelTransition() |
662 */ |
765 */ |
663 EXPORT_C void RDmDomainManager::RequestDomainTransition( |
766 EXPORT_C void RDmDomainManager::RequestDomainTransition( |
664 TDmDomainId aDomainId, |
767 TDmDomainId aDomainId, |
665 TPowerState aState, |
768 TPowerState aState, |
667 { |
770 { |
668 RequestDomainTransition(aDomainId,(TDmDomainState) aState, ETraverseDefault, aStatus); |
771 RequestDomainTransition(aDomainId,(TDmDomainState) aState, ETraverseDefault, aStatus); |
669 } |
772 } |
670 |
773 |
671 |
774 |
672 |
775 /** |
673 |
776 Cancels an outstanding state transition, whether initiated by a call |
674 /** |
|
675 Cancels a state transition, whether initiated by a call |
|
676 to RequestSystemTransition() or RequestDomainTransition(). |
777 to RequestSystemTransition() or RequestDomainTransition(). |
677 |
778 |
678 An outstanding state transition request completes with KErrCancel. |
779 The outstanding state transition request completes with KErrCancel. |
679 */ |
780 */ |
680 EXPORT_C void RDmDomainManager::CancelTransition() |
781 EXPORT_C void RDmDomainManager::CancelTransition() |
681 { |
782 { |
682 iSession.CancelTransition(); |
783 iSession.CancelTransition(); |
683 } |
784 } |
684 |
785 |
685 |
786 |
686 |
787 /** |
687 |
788 Requests a state transition across the whole domain hierarchy that |
688 /** |
789 this connection is controlling. The domain hierarchy is traversed in the |
689 Requests a system-wide state transition. |
790 specified direction. |
690 |
|
691 The domain hierarchy is traversed in the specified direction. |
|
692 |
791 |
693 @param aState The target state. |
792 @param aState The target state, hierarchy specific state value. |
694 @param aDirection The direction in which to traverse the hierarchy |
793 @param aDirection The direction in which to traverse the hierarchy |
695 @param aStatus The request status object for this asynchronous request. |
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. |
|
797 |
|
798 @panic domainCli.cpp; assertion failed line - if the numerical value of |
|
799 aDirection is greater than the value of ETraverseMax. |
696 |
800 |
697 @see RDmDomainManager::CancelTransition() |
801 @see RDmDomainManager::CancelTransition() |
698 |
|
699 @panic domainCli.cpp; assertion failed VARNUM if the numerical value of aDirection |
|
700 is greater than the value of ETraverseMax. NOTE: VARNUM is the line number |
|
701 in the source code and may change if the implementation changes. |
|
702 */ |
802 */ |
703 EXPORT_C void RDmDomainManager::RequestSystemTransition( |
803 EXPORT_C void RDmDomainManager::RequestSystemTransition( |
704 TDmDomainState aState, |
804 TDmDomainState aState, |
705 TDmTraverseDirection aDirection, |
805 TDmTraverseDirection aDirection, |
706 TRequestStatus& aStatus) |
806 TRequestStatus& aStatus) |
709 iSession.RequestSystemTransition(aState, aDirection, aStatus); |
809 iSession.RequestSystemTransition(aState, aDirection, aStatus); |
710 } |
810 } |
711 |
811 |
712 |
812 |
713 |
813 |
714 |
814 /** |
715 /** |
815 Requests a domain state transition for the hierarchy that this connection is |
716 Requests a domain state transition. |
816 controlling. The domain hierarchy is traversed in the specified direction. |
717 |
|
718 The domain hierarchy is traversed in the specified direction |
|
719 |
817 |
720 @param aDomainId The Id of the domain for which the state transition |
818 @param aDomainId The Id of the domain for which the state transition |
721 is being requested. |
819 is being requested. |
722 @param aState The target state. |
820 @param aState The target state. |
723 @param aDirection The direction in which to traverse the hierarchy. |
821 @param aDirection The direction in which to traverse the hierarchy. |
724 @param aStatus The request status object for this asynchronous request. |
822 @param aStatus The request status object to receive the asynchronous result. |
725 |
823 KErrNone if successful, otherwise one of the other system-wide |
726 @see RDmDomainManager::CancelTransition() |
824 or the Domain Manager specific error codes. |
727 |
825 |
728 @panic domainCli.cpp; assertion failed VARNUM if the numerical value of aDirection |
826 @panic domainCli.cpp; assertion failed VARNUM if the numerical value of aDirection |
729 is greater than the value of ETraverseMax. NOTE: VARNUM is the line number |
827 is greater than the value of ETraverseMax. NOTE: VARNUM is the line number |
730 in the source code and may change if the implementation changes. |
828 in the source code and may change if the implementation changes. |
|
829 |
|
830 @see RDmDomainManager::CancelTransition() |
731 */ |
831 */ |
732 EXPORT_C void RDmDomainManager::RequestDomainTransition( |
832 EXPORT_C void RDmDomainManager::RequestDomainTransition( |
733 TDmDomainId aDomainId, |
833 TDmDomainId aDomainId, |
734 TDmDomainState aState, |
834 TDmDomainState aState, |
735 TDmTraverseDirection aDirection, |
835 TDmTraverseDirection aDirection, |
739 iSession.RequestDomainTransition(aDomainId, aState, aDirection, aStatus); |
839 iSession.RequestDomainTransition(aDomainId, aState, aDirection, aStatus); |
740 } |
840 } |
741 |
841 |
742 |
842 |
743 |
843 |
744 |
844 /** |
745 /** |
845 Instructs the Domain Manager to load the domain hierarchy library for |
746 Adds a domain hierarchy to the domain manager. |
846 aHierarchyId. The library takes the name "domainpolicyNN.dll" where NN is |
|
847 the hierarchy number as supplied. |
747 |
848 |
748 @param aHierarchyId The Id of the domain hierarchy to be added. |
849 @param aHierarchyId The Id of the domain hierarchy to be added. |
749 |
850 |
750 @return KErrNone if successful; otherwise one of the other system-wide |
851 @return KErrNone if successful, otherwise one of the other system-wide |
751 or domain manager specific error codes. |
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. |
752 */ |
857 */ |
753 EXPORT_C TInt RDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId) |
858 EXPORT_C TInt RDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId) |
754 { |
859 { |
755 RDmManagerSession session; |
860 RDmManagerSession session; |
756 TInt r = session.Connect(); |
861 TInt r = session.Connect(); |
760 session.Close(); |
865 session.Close(); |
761 return r; |
866 return r; |
762 } |
867 } |
763 |
868 |
764 |
869 |
765 |
|
766 /** |
870 /** |
767 Requests a list of transition failures since the last transition request. |
871 Requests a list of transition failures since the last transition request. |
768 |
872 |
769 @param aTransitionFailures A client-supplied array of TTransitionFailure objects which |
873 @param aTransitionFailures A client supplied array of TTransitionFailure objects |
770 on exit will contain the failures that have occurred since the last transition |
874 which on exit will contain the failures that have occurred since the |
771 request. |
875 last transition request. |
772 @pre The session must be connected. |
876 |
773 |
877 @return KErrNone if successful, otherwise one of the other system-wide |
774 @return KErrNone, if successful; otherwise one of the other system-wide |
878 or the Domain Manager specific error codes. |
775 or domain manager specific error codes. |
|
776 */ |
879 */ |
777 EXPORT_C TInt RDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures) |
880 EXPORT_C TInt RDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures) |
778 { |
881 { |
779 return iSession.GetTransitionFailures(aTransitionFailures); |
882 return iSession.GetTransitionFailures(aTransitionFailures); |
780 } |
883 } |
781 |
884 |
782 |
885 |
783 |
|
784 /** |
886 /** |
785 Gets the number of transition failures since the last transition request. |
887 Gets the number of transition failures since the last transition request. |
786 |
888 |
787 @return The number of failures, if successful; otherwise one of the other system-wide |
889 @return KErrNone if successful, otherwise one of the other system-wide |
788 or domain manager specific error codes. |
890 or the Domain Manager specific error codes. |
789 */ |
891 */ |
790 EXPORT_C TInt RDmDomainManager::GetTransitionFailureCount() |
892 EXPORT_C TInt RDmDomainManager::GetTransitionFailureCount() |
791 { |
893 { |
792 return iSession.GetTransitionFailureCount(); |
894 return iSession.GetTransitionFailureCount(); |
793 } |
895 } |
794 |
896 |
795 |
897 |
796 |
898 |
797 // CDmDomain |
899 //-- CDmDomain ---------------------------------------------------------------- |
|
900 |
|
901 |
798 |
902 |
799 /** |
903 /** |
800 Constructor. |
904 Constructor. |
801 |
905 |
802 Adds this active object to the active scheduler. The priority of the active object |
906 Adds this active object to the active scheduler. The priority of the active object |
906 EXPORT_C TDmDomainState CDmDomain::GetState() |
1018 EXPORT_C TDmDomainState CDmDomain::GetState() |
907 { |
1019 { |
908 return iDomain.GetState(); |
1020 return iDomain.GetState(); |
909 } |
1021 } |
910 |
1022 |
|
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 |
911 // CDmDomainManager |
1216 // CDmDomainManager |
912 |
1217 |
913 /** |
1218 /** |
914 Constructor. |
1219 Constructor. |
915 |
1220 |