userlibandfileserver/domainmgr/src/domaincli.cpp
changeset 279 957c583b417b
parent 243 c7a0ce20c48c
equal deleted inserted replaced
275:2b433474f2ba 279:957c583b417b
    20 #include <e32property.h>
    20 #include <e32property.h>
    21 
    21 
    22 
    22 
    23 #include <domainmember.h>
    23 #include <domainmember.h>
    24 #include <domainmanager.h>
    24 #include <domainmanager.h>
       
    25 #include "domainmanager_private.h"
    25 #include "domainobserver.h"
    26 #include "domainobserver.h"
    26 #include "domainsrv.h"
    27 #include "domainsrv.h"
       
    28 #include "domainmember_private.h"
    27 
    29 
    28 #define __DM_PANIC(aError) User::Panic(_L("domainCli.cpp"), (-(aError)) | (__LINE__ << 16))
    30 #define __DM_PANIC(aError) User::Panic(_L("domainCli.cpp"), (-(aError)) | (__LINE__ << 16))
    29 #define __DM_ASSERT(aCond) __ASSERT_DEBUG(aCond,User::Panic(_L("domainCli.cpp; assertion failed"), __LINE__))
    31 #define __DM_ASSERT(aCond) __ASSERT_DEBUG(aCond,User::Panic(_L("domainCli.cpp; assertion failed"), __LINE__))
    30 
    32 
    31 TInt RDmDomainSession::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId, TUint* aKey)
    33 TInt RDmDomainSession::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId, TUint* aKey)
    45 		aDomainId);
    47 		aDomainId);
    46 
    48 
    47 	return KErrNone;
    49 	return KErrNone;
    48 	}
    50 	}
    49 
    51 
    50 void RDmDomainSession::Acknowledge(TInt aValue, TInt aError)
    52 TInt RDmDomainSession::Acknowledge(TInt aValue, TInt aError)
    51 	{
    53 	{
    52 	__DM_ASSERT(Handle() != KNullHandle);
    54 	__DM_ASSERT(Handle() != KNullHandle);
    53 
    55 
    54 	TIpcArgs a(aValue, aError);
    56 	TIpcArgs a(aValue, aError);
    55 	TInt r = RSessionBase::SendReceive(EDmStateAcknowledge, a);
    57 	return RSessionBase::SendReceive(EDmStateAcknowledge, a);
    56 	if (r != KErrNone)
       
    57 		__DM_PANIC(r);
       
    58 	}
    58 	}
    59 
    59 
    60 void RDmDomainSession::RequestTransitionNotification()
    60 void RDmDomainSession::RequestTransitionNotification()
    61 	{
    61 	{
    62 	__DM_ASSERT(Handle() != KNullHandle);
    62 	__DM_ASSERT(Handle() != KNullHandle);
    74 			__DM_PANIC(r);
    74 			__DM_PANIC(r);
    75 		}
    75 		}
    76 	}
    76 	}
    77 
    77 
    78 
    78 
       
    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 
    79 
    96 
    80 /**
    97 /**
    81 Connects to the domain identified by the specified domain Id.
    98 Connects to the domain identified by the specified domain Id.
    82 
    99 
    83 To connect to the root domain, which has the Id KDmIdRoot,
   100 To connect to the root domain, which has the Id KDmIdRoot,
    88 when the power state changes.
   105 when the power state changes.
    89 
   106 
    90 @param aDomainId The identifier of the domain to be connected to.
   107 @param aDomainId The identifier of the domain to be connected to.
    91 
   108 
    92 @return KErrNone, if successful; otherwise one of the other system-wide
   109 @return KErrNone, if successful; otherwise one of the other system-wide
    93         or domain manager specific error codes.
   110         or Domain Manager specific error codes.
    94 
   111 
    95 @capability WriteDeviceData If aDomainId==KDmIdRoot
   112 @capability WriteDeviceData If aDomainId==KDmIdRoot
    96 */
   113 */
    97 EXPORT_C TInt RDmDomain::Connect(TDmDomainId aDomainId)
   114 EXPORT_C TInt RDmDomain::Connect(TDmDomainId aDomainId)
    98 	{
   115 	{
   124 
   141 
   125 @param aHierarchyId	The Id of the domain hierarchy to connect to.
   142 @param aHierarchyId	The Id of the domain hierarchy to connect to.
   126 @param aDomainId    The identifier of the domain to be connected to.
   143 @param aDomainId    The identifier of the domain to be connected to.
   127 
   144 
   128 @return KErrNone, if successful; otherwise one of the other system-wide
   145 @return KErrNone, if successful; otherwise one of the other system-wide
   129         or domain manager specific error codes.
   146         or Domain Manager specific error codes.
   130 
   147 
   131 @capability WriteDeviceData If aDomainId==KDmIdRoot
   148 @capability WriteDeviceData If aDomainId==KDmIdRoot
   132 */
   149 */
   133 EXPORT_C TInt RDmDomain::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId)
   150 EXPORT_C TInt RDmDomain::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId)
   134 	{
   151 	{
   192 	iStateProperty.Cancel();
   209 	iStateProperty.Cancel();
   193 	}
   210 	}
   194 
   211 
   195 
   212 
   196 
   213 
   197 
       
   198 /**
   214 /**
   199 Gets the domain's power state.
   215 Gets the domain's power state.
   200 	
   216 
   201 An application normally calls this function after a notification request
   217 An application normally calls this function after a notification request
   202 has completed. It then performs any application-dependent action demanded by
   218 has completed. It then performs any application-dependent action demanded by
   203 the power state, and then acknowledges the state transition.
   219 the power state, and then acknowledges the state transition.
   204 
   220 
   205 Note that the domain manager requires any domain power state change to be
   221 Note that the Domain Manager requires any domain power state change to be
   206 acknowledged by all applications connected to the domain.
   222 acknowledged by all applications connected to the domain.
   207 
   223 
   208 @return The connected domain's power state.
   224 @return The connected domain's power state.
   209 
   225 
   210 @see RDmDomain::AcknowledgeLastState()
   226 @see RDmDomain::AcknowledgeLastState()
   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()
   496 	{
   591 	{
   497 	__DM_ASSERT(Handle() != KNullHandle);
   592 	__DM_ASSERT(Handle() != KNullHandle);
   498 	return(RSessionBase::SendReceive(EDmObserveredCount));
   593 	return(RSessionBase::SendReceive(EDmObserveredCount));
   499 	}
   594 	}
   500 
   595 
   501 /**
   596 
   502 @internalAll
   597 
   503 @released
   598 //-- RDmDomainManager ---------------------------------------------------------
       
   599 
       
   600 
       
   601 
       
   602 /**
       
   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.
   504 */
   608 */
   505 EXPORT_C TInt RDmDomainManager::WaitForInitialization()
   609 EXPORT_C TInt RDmDomainManager::WaitForInitialization()
   506 	{
   610 	{
   507 	RProperty prop;
   611 	RProperty prop;
   508 	TInt r = prop.Attach(KUidDmPropertyCategory, KDmPropertyKeyInit);
   612 	TInt r = prop.Attach(KUidDmPropertyCategory, KDmPropertyKeyInit);
   520 		TInt value;
   624 		TInt value;
   521 		r = prop.Get(value);
   625 		r = prop.Get(value);
   522 		if (r == KErrNone)
   626 		if (r == KErrNone)
   523 			{
   627 			{
   524 			if (value) break; // initialized
   628 			if (value) break; // initialized
   525 			// property exists but the server is not intialized yet
   629 			// property exists but the server is not initialised yet
   526 			}
   630 			}
   527 		else
   631 		else
   528 			{
   632 			{
   529 			if (r != KErrNotFound) break; // error
   633 			if (r != KErrNotFound) break; // error
   530 			// property doesn't exist yet
   634 			// property doesn't exist yet
   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
   820 
   924 
   821 
   925 
   822 /**
   926 /**
   823 Destructor.
   927 Destructor.
   824 
   928 
   825 Closes the session to the domain manager.
   929 Closes the session to the Domain Manager.
   826 */
   930 */
   827 EXPORT_C CDmDomain::~CDmDomain()
   931 EXPORT_C CDmDomain::~CDmDomain()
   828 	{
   932 	{
   829 	Cancel();
   933 	Cancel();
   830 	iDomain.Close();
   934 	iDomain.Close();
   850 
   954 
   851 /**
   955 /**
   852 Requests notification when the domain's state changes.
   956 Requests notification when the domain's state changes.
   853 
   957 
   854 RunL() will be called when this happens.
   958 RunL() will be called when this happens.
       
   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.
   855 */
   967 */
   856 EXPORT_C void CDmDomain::RequestTransitionNotification()
   968 EXPORT_C void CDmDomain::RequestTransitionNotification()
   857 	{
   969 	{
   858 	__DM_ASSERT(!IsActive());
   970 	__DM_ASSERT(!IsActive());
   859 	iDomain.RequestTransitionNotification(iStatus);
   971 	iDomain.RequestTransitionNotification(iStatus);
   880 Acknowledges the last state change.
   992 Acknowledges the last state change.
   881 	
   993 	
   882 An application must acknowledge that it has performed all actions required
   994 An application must acknowledge that it has performed all actions required
   883 by the last known state of the domain.
   995 by the last known state of the domain.
   884 
   996 
   885 @param aError	The error to return to the domain manager. The client should
   997 @param aError	The error to return to the Domain Manager. The client should
   886 				set this to KErrNone if it successfully transitioned to the 
   998 				set this to KErrNone if it successfully transitioned to the 
   887 				new state or to one of the system-wide error codes.
   999 				new state or to one of the system-wide error codes.
   888 */
  1000 */
   889 EXPORT_C void CDmDomain::AcknowledgeLastState(TInt aError)
  1001 EXPORT_C void CDmDomain::AcknowledgeLastState(TInt aError)
   890 	{
  1002 	{
   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 
   928 
  1233 
   929 
  1234 
   930 /**
  1235 /**
   931 Destructor.
  1236 Destructor.
   932 
  1237 
   933 Closes the session to the domain manager.
  1238 Closes the session to the Domain Manager.
   934 */
  1239 */
   935 EXPORT_C CDmDomainManager::~CDmDomainManager()
  1240 EXPORT_C CDmDomainManager::~CDmDomainManager()
   936 	{
  1241 	{
   937 	Cancel();
  1242 	Cancel();
   938 	iManager.Close();
  1243 	iManager.Close();
   996 
  1301 
   997 
  1302 
   998 
  1303 
   999 
  1304 
  1000 /**
  1305 /**
  1001 Adds a domain hierarchy to the domain manager.
  1306 Adds a domain hierarchy to the Domain Manager.
  1002 
  1307 
  1003 @param aHierarchyId The Id of the domain hierarchy to add
  1308 @param aHierarchyId The Id of the domain hierarchy to add
  1004 
  1309 
  1005 @return	KErrNone if successful; otherwise one of the other system-wide
  1310 @return	KErrNone if successful; otherwise one of the other system-wide
  1006         or domain manager specific error codes.
  1311         or Domain Manager specific error codes.
  1007 */
  1312 */
  1008 EXPORT_C TInt CDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId)
  1313 EXPORT_C TInt CDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId)
  1009 	{
  1314 	{
  1010 	RDmManagerSession	session;
  1315 	RDmManagerSession	session;
  1011 	TInt r = session.Connect();
  1316 	TInt r = session.Connect();
  1038 		on exit will contain the failures that have occurred since the last transition 
  1343 		on exit will contain the failures that have occurred since the last transition 
  1039 		request. 
  1344 		request. 
  1040 @pre	The session must be connected.
  1345 @pre	The session must be connected.
  1041 
  1346 
  1042 @return KErrNone, if successful; otherwise one of the other system-wide
  1347 @return KErrNone, if successful; otherwise one of the other system-wide
  1043         or domain manager specific error codes.
  1348         or Domain Manager specific error codes.
  1044 */
  1349 */
  1045 EXPORT_C TInt CDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
  1350 EXPORT_C TInt CDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
  1046 	{
  1351 	{
  1047 	return iManager.GetTransitionFailures(aTransitionFailures);
  1352 	return iManager.GetTransitionFailures(aTransitionFailures);
  1048 	}
  1353 	}
  1052 
  1357 
  1053 /**
  1358 /**
  1054 Gets the number of transition failures since the last transition request.
  1359 Gets the number of transition failures since the last transition request.
  1055 
  1360 
  1056 @return	The number of failures if successful, otherwise one of the other system-wide
  1361 @return	The number of failures if successful, otherwise one of the other system-wide
  1057         or domain manager specific error codes.
  1362         or Domain Manager specific error codes.
  1058 */
  1363 */
  1059 EXPORT_C TInt CDmDomainManager::GetTransitionFailureCount()
  1364 EXPORT_C TInt CDmDomainManager::GetTransitionFailureCount()
  1060 	{
  1365 	{
  1061 	return iManager.GetTransitionFailureCount();
  1366 	return iManager.GetTransitionFailureCount();
  1062 	}
  1367 	}
  1079 /**
  1384 /**
  1080 Constructs a new observer on the domain hierarchy.
  1385 Constructs a new observer on the domain hierarchy.
  1081 
  1386 
  1082 Note that only one observer per domain hierarchy is allowed.
  1387 Note that only one observer per domain hierarchy is allowed.
  1083 
  1388 
  1084 @param	aHierarchyObserver	The implementation of the interface to the domain manager.
  1389 @param	aHierarchyObserver	The implementation of the interface to the Domain Manager.
  1085 @param	aHierarchyId		The Id of the domain hierarchy.
  1390 @param	aHierarchyId		The Id of the domain hierarchy.
  1086 
  1391 
  1087 @return The newly created CHierarchyObserver object.
  1392 @return The newly created CHierarchyObserver object.
  1088 */
  1393 */
  1089 EXPORT_C CHierarchyObserver* CHierarchyObserver::NewL(MHierarchyObserver& aHierarchyObserver,TDmHierarchyId aHierarchyId)
  1394 EXPORT_C CHierarchyObserver* CHierarchyObserver::NewL(MHierarchyObserver& aHierarchyObserver,TDmHierarchyId aHierarchyId)