sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // domain\src\domaincli.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include "domainobserver.h" sl@0: #include "domainsrv.h" sl@0: sl@0: #define __DM_PANIC(aError) User::Panic(_L("domainCli.cpp"), (-(aError)) | (__LINE__ << 16)) sl@0: #define __DM_ASSERT(aCond) __ASSERT_DEBUG(aCond,User::Panic(_L("domainCli.cpp; assertion failed"), __LINE__)) sl@0: sl@0: TInt RDmDomainSession::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId, TUint* aKey) sl@0: { sl@0: TInt r = RSessionBase::CreateSession(KDmDomainServerNameLit, KDmDomainServerVersion, 1); sl@0: if (r != KErrNone) sl@0: return r; sl@0: TIpcArgs a( (TInt)aHierarchyId, (TInt)aDomainId ); sl@0: r = RSessionBase::SendReceive(EDmDomainJoin, a); sl@0: if (r != KErrNone) sl@0: { sl@0: RSessionBase::Close(); sl@0: return r; sl@0: } sl@0: *aKey = DmStatePropertyKey( sl@0: aHierarchyId, sl@0: aDomainId); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: void RDmDomainSession::Acknowledge(TInt aValue, TInt aError) sl@0: { sl@0: __DM_ASSERT(Handle() != KNullHandle); sl@0: sl@0: TIpcArgs a(aValue, aError); sl@0: TInt r = RSessionBase::SendReceive(EDmStateAcknowledge, a); sl@0: if (r != KErrNone) sl@0: __DM_PANIC(r); sl@0: } sl@0: sl@0: void RDmDomainSession::RequestTransitionNotification() sl@0: { sl@0: __DM_ASSERT(Handle() != KNullHandle); sl@0: TInt r = RSessionBase::SendReceive(EDmStateRequestTransitionNotification); sl@0: if (r != KErrNone) sl@0: __DM_PANIC(r); sl@0: } sl@0: sl@0: void RDmDomainSession::CancelTransitionNotification() sl@0: { sl@0: if (Handle() != KNullHandle) sl@0: { sl@0: TInt r = RSessionBase::SendReceive(EDmStateCancelTransitionNotification); sl@0: if (r != KErrNone) sl@0: __DM_PANIC(r); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: Connects to the domain identified by the specified domain Id. sl@0: sl@0: To connect to the root domain, which has the Id KDmIdRoot, sl@0: the capability WriteDeviceData is required. sl@0: sl@0: Once connected, an application can use this RDmDomain object to read sl@0: the domain's power state and to request notification sl@0: when the power state changes. sl@0: sl@0: @param aDomainId The identifier of the domain to be connected to. sl@0: sl@0: @return KErrNone, if successful; otherwise one of the other system-wide sl@0: or domain manager specific error codes. sl@0: sl@0: @capability WriteDeviceData If aDomainId==KDmIdRoot sl@0: */ sl@0: EXPORT_C TInt RDmDomain::Connect(TDmDomainId aDomainId) sl@0: { sl@0: TUint key; sl@0: TInt r = iSession.Connect(KDmHierarchyIdPower, aDomainId, &key); sl@0: if (r != KErrNone) sl@0: return r; sl@0: r = iStateProperty.Attach(KUidDmPropertyCategory, key); sl@0: if (r != KErrNone) sl@0: { sl@0: iSession.Close(); sl@0: return r; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Connects to the domain identified by the specified domain Id. sl@0: sl@0: To connect to the root domain, which has the Id KDmIdRoot, sl@0: the capability WriteDeviceData is required. sl@0: sl@0: Once connected, an application can use this RDmDomain object to read sl@0: the domain's state and to request notification sl@0: when the state changes. sl@0: sl@0: @param aHierarchyId The Id of the domain hierarchy to connect to. sl@0: @param aDomainId The identifier of the domain to be connected to. sl@0: sl@0: @return KErrNone, if successful; otherwise one of the other system-wide sl@0: or domain manager specific error codes. sl@0: sl@0: @capability WriteDeviceData If aDomainId==KDmIdRoot sl@0: */ sl@0: EXPORT_C TInt RDmDomain::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId) sl@0: { sl@0: TUint key; sl@0: TInt r = iSession.Connect(aHierarchyId, aDomainId, &key); sl@0: if (r != KErrNone) sl@0: return r; sl@0: r = iStateProperty.Attach(KUidDmPropertyCategory, key); sl@0: if (r != KErrNone) sl@0: { sl@0: iSession.Close(); sl@0: return r; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Disconnects from the associated domain. sl@0: sl@0: If this object is not connected to any domain, then it returns silently. sl@0: */ sl@0: EXPORT_C void RDmDomain::Close() sl@0: { sl@0: iSession.Close(); sl@0: iStateProperty.Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Requests notification when the domain's state changes. sl@0: sl@0: This is an asynchronous request that completes when sl@0: the domain's state changes. sl@0: sl@0: @param aStatus The request status object for this asynchronous request. sl@0: sl@0: @see RDmDomain::CancelTransitionNotification() sl@0: */ sl@0: EXPORT_C void RDmDomain::RequestTransitionNotification(TRequestStatus& aStatus) sl@0: { sl@0: iStateProperty.Subscribe(aStatus); sl@0: iSession.RequestTransitionNotification(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Cancels an outstanding notification request. sl@0: sl@0: Any outstanding notification request completes with KErrCancel. sl@0: */ sl@0: EXPORT_C void RDmDomain::CancelTransitionNotification() sl@0: { sl@0: iSession.CancelTransitionNotification(); sl@0: iStateProperty.Cancel(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets the domain's power state. sl@0: sl@0: An application normally calls this function after a notification request sl@0: has completed. It then performs any application-dependent action demanded by sl@0: the power state, and then acknowledges the state transition. sl@0: sl@0: Note that the domain manager requires any domain power state change to be sl@0: acknowledged by all applications connected to the domain. sl@0: sl@0: @return The connected domain's power state. sl@0: sl@0: @see RDmDomain::AcknowledgeLastState() sl@0: */ sl@0: EXPORT_C TPowerState RDmDomain::GetPowerState() sl@0: { sl@0: TInt value; sl@0: TInt r = iStateProperty.Get(value); sl@0: if (r != KErrNone) sl@0: __DM_PANIC(r); sl@0: iLastStatePropertyValue = value; sl@0: return (TPowerState) DmStateFromPropertyValue(value); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Acknowledges the state change. sl@0: sl@0: An application must acknowledge that it has performed all actions required sl@0: by the last known state of the domain. sl@0: */ sl@0: EXPORT_C void RDmDomain::AcknowledgeLastState() sl@0: { sl@0: iSession.Acknowledge(iLastStatePropertyValue, KErrNone); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Acknowledges the state change with the specified error sl@0: sl@0: An application must acknowledge that it has performed all actions required sl@0: by the last known state of the domain. sl@0: sl@0: @param aError KDmErrNotJoin if domain is not part of the hierarhcy or a sl@0: system wide error value associated with the state change. sl@0: */ sl@0: EXPORT_C void RDmDomain::AcknowledgeLastState(TInt aError) sl@0: { sl@0: iSession.Acknowledge(iLastStatePropertyValue, aError); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets the domain's state. sl@0: sl@0: An application normally calls this function after a notification request sl@0: has completed. It then performs any application-dependent action demanded by sl@0: the state, and then acknowledges the state transition. sl@0: sl@0: Note, that the domain manager requires any domain state change to be sl@0: acknowledged by all applications connected to the domain. sl@0: sl@0: @return The connected domain's state. sl@0: */ sl@0: EXPORT_C TDmDomainState RDmDomain::GetState() sl@0: { sl@0: TInt value; sl@0: TInt r = iStateProperty.Get(value); sl@0: if (r != KErrNone) sl@0: __DM_PANIC(r); sl@0: iLastStatePropertyValue = value; sl@0: return DmStateFromPropertyValue(value); sl@0: } sl@0: sl@0: TInt RDmManagerSession::Connect() sl@0: { sl@0: __DM_ASSERT(Handle() == KNullHandle); sl@0: sl@0: return RSessionBase::CreateSession( sl@0: KDmManagerServerNameLit, sl@0: KDmManagerServerVersion, sl@0: 2); sl@0: } sl@0: sl@0: TInt RDmManagerSession::ConnectObserver(TDmHierarchyId aHierarchyId) sl@0: { sl@0: TInt r = Connect(); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: TIpcArgs a( (TInt)aHierarchyId); sl@0: r = RSessionBase::SendReceive(EDmObserverJoin, a); sl@0: if (r != KErrNone) sl@0: { sl@0: RSessionBase::Close(); sl@0: return r; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt RDmManagerSession::Connect(TDmHierarchyId aHierarchyId) sl@0: { sl@0: TInt r = Connect(); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: TIpcArgs a( (TInt)aHierarchyId); sl@0: r = RSessionBase::SendReceive(EDmHierarchyJoin, a); sl@0: if (r != KErrNone) sl@0: { sl@0: RSessionBase::Close(); sl@0: return r; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: void RDmManagerSession::RequestDomainTransition( sl@0: TDmDomainId aDomainId, sl@0: TDmDomainState aState, sl@0: TDmTraverseDirection aDirection, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: __DM_ASSERT(Handle() != KNullHandle); sl@0: sl@0: if(aDirection < 0 || aDirection > ETraverseMax) sl@0: __DM_PANIC(KErrArgument); sl@0: sl@0: TIpcArgs a(aDomainId, aState, aDirection); sl@0: RSessionBase::SendReceive(EDmRequestDomainTransition, a, aStatus); sl@0: } sl@0: sl@0: void RDmManagerSession::CancelTransition() sl@0: { sl@0: if (Handle() != KNullHandle) sl@0: { sl@0: TInt r = RSessionBase::SendReceive(EDmCancelTransition); sl@0: if (r != KErrNone) sl@0: __DM_PANIC(r); sl@0: } sl@0: } sl@0: sl@0: void RDmManagerSession::CancelObserver() sl@0: { sl@0: if (Handle() != KNullHandle) sl@0: { sl@0: TInt r = RSessionBase::SendReceive(EDmObserverCancel); sl@0: if (r != KErrNone) sl@0: __DM_PANIC(r); sl@0: } sl@0: } sl@0: sl@0: void RDmManagerSession::RequestSystemTransition( sl@0: TDmDomainState aState, sl@0: TDmTraverseDirection aDirection, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: __DM_ASSERT(Handle() != KNullHandle); sl@0: sl@0: TIpcArgs a(aState, aDirection); sl@0: RSessionBase::SendReceive(EDmRequestSystemTransition, a, aStatus); sl@0: } sl@0: sl@0: TInt RDmManagerSession::AddDomainHierarchy(TDmHierarchyId aHierarchyId) sl@0: { sl@0: __DM_ASSERT(Handle() != KNullHandle); sl@0: sl@0: TIpcArgs a( (TInt)aHierarchyId); sl@0: TInt r = RSessionBase::SendReceive(EDmHierarchyAdd, a); sl@0: sl@0: return r; sl@0: } sl@0: sl@0: TInt RDmManagerSession::GetTransitionFailureCount() sl@0: { sl@0: __DM_ASSERT(Handle() != KNullHandle); sl@0: sl@0: return RSessionBase::SendReceive(EDmGetTransitionFailureCount); sl@0: } sl@0: sl@0: TInt RDmManagerSession::GetTransitionFailures(RArray& aTransitionFailures) sl@0: { sl@0: __DM_ASSERT(Handle() != KNullHandle); sl@0: sl@0: aTransitionFailures.Reset(); sl@0: sl@0: TInt err = KErrNone; sl@0: sl@0: TInt failureCount = GetTransitionFailureCount(); sl@0: if (failureCount <= 0) sl@0: return failureCount; sl@0: sl@0: TTransitionFailure* failures = new TTransitionFailure[failureCount]; sl@0: if(failures == NULL) sl@0: return(KErrNoMemory); sl@0: TPtr8 dataPtr(reinterpret_cast(failures), failureCount * sizeof(TTransitionFailure)); sl@0: sl@0: TIpcArgs a(&dataPtr); sl@0: err = RSessionBase::SendReceive(EDmGetTransitionFailures, a); sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: for (TInt i=0; i& aTransitions) sl@0: { sl@0: __DM_ASSERT(Handle() != KNullHandle); sl@0: sl@0: aTransitions.Reset(); sl@0: sl@0: sl@0: TInt count = GetEventCount(); sl@0: // This shouldn't happen unless something gone terribly wrong sl@0: if (count <= 0) sl@0: return KErrGeneral; sl@0: sl@0: TTransInfo* trans = new TTransInfo[count]; sl@0: if(trans == NULL) sl@0: return(KErrNoMemory); sl@0: sl@0: TPtr8 dataPtr(reinterpret_cast(trans), count * sizeof(TTransInfo)); sl@0: sl@0: TIpcArgs a(&dataPtr); sl@0: TInt ret=RSessionBase::SendReceive(EDmObserverGetEvent, a); sl@0: sl@0: if(ret==KErrNone) sl@0: { sl@0: for (TInt i=0; i& aTransitionFailures) sl@0: { sl@0: return iSession.GetTransitionFailures(aTransitionFailures); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets the number of transition failures since the last transition request. sl@0: sl@0: @return The number of failures, if successful; otherwise one of the other system-wide sl@0: or domain manager specific error codes. sl@0: */ sl@0: EXPORT_C TInt RDmDomainManager::GetTransitionFailureCount() sl@0: { sl@0: return iSession.GetTransitionFailureCount(); sl@0: } sl@0: sl@0: sl@0: sl@0: // CDmDomain sl@0: sl@0: /** sl@0: Constructor. sl@0: sl@0: Adds this active object to the active scheduler. The priority of the active object sl@0: is the standard value, i.e. CActive::EPriorityStandard. sl@0: sl@0: @param aHierarchyId The Id of the domain hierarchy to connect to. sl@0: @param aDomainId The Id of the domain to connect to. sl@0: sl@0: @see CActive sl@0: @see CActive::TPriority sl@0: */ sl@0: EXPORT_C CDmDomain::CDmDomain(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId) : sl@0: CActive(CActive::EPriorityStandard), sl@0: iHierarchyId(aHierarchyId), sl@0: iDomainId(aDomainId) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Destructor. sl@0: sl@0: Closes the session to the domain manager. sl@0: */ sl@0: EXPORT_C CDmDomain::~CDmDomain() sl@0: { sl@0: Cancel(); sl@0: iDomain.Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Second-phase constructor. sl@0: sl@0: The function attempts to connect to the domain specified in the constructor. sl@0: sl@0: @leave One of the system-wide error codes sl@0: */ sl@0: EXPORT_C void CDmDomain::ConstructL() sl@0: { sl@0: User::LeaveIfError(iDomain.Connect(iHierarchyId, iDomainId)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Requests notification when the domain's state changes. sl@0: sl@0: RunL() will be called when this happens. sl@0: */ sl@0: EXPORT_C void CDmDomain::RequestTransitionNotification() sl@0: { sl@0: __DM_ASSERT(!IsActive()); sl@0: iDomain.RequestTransitionNotification(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Cancels an outstanding notification request. sl@0: sl@0: Any outstanding notification request completes with KErrCancel. sl@0: */ sl@0: EXPORT_C void CDmDomain::DoCancel() sl@0: { sl@0: iDomain.CancelTransitionNotification(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Acknowledges the last state change. sl@0: sl@0: An application must acknowledge that it has performed all actions required sl@0: by the last known state of the domain. sl@0: sl@0: @param aError The error to return to the domain manager. The client should sl@0: set this to KErrNone if it successfully transitioned to the sl@0: new state or to one of the system-wide error codes. sl@0: */ sl@0: EXPORT_C void CDmDomain::AcknowledgeLastState(TInt aError) sl@0: { sl@0: iDomain.AcknowledgeLastState(aError); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets the domain's state. sl@0: sl@0: An application normally calls this function after a notification request sl@0: has completed. It then performs any application-dependent action demanded by sl@0: the state, and then acknowledges the state transition. sl@0: sl@0: @return The connected domain's state. sl@0: */ sl@0: EXPORT_C TDmDomainState CDmDomain::GetState() sl@0: { sl@0: return iDomain.GetState(); sl@0: } sl@0: sl@0: // CDmDomainManager sl@0: sl@0: /** sl@0: Constructor. sl@0: sl@0: Adds this active object to the active scheduler. sl@0: sl@0: @param aHierarchyId The Id of the domain hierarchy to connect to sl@0: */ sl@0: EXPORT_C CDmDomainManager::CDmDomainManager(TDmHierarchyId aHierarchyId) : sl@0: CActive(CActive::EPriorityStandard), sl@0: iHierarchyId(aHierarchyId) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Destructor. sl@0: sl@0: Closes the session to the domain manager. sl@0: */ sl@0: EXPORT_C CDmDomainManager::~CDmDomainManager() sl@0: { sl@0: Cancel(); sl@0: iManager.Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: The second-phase constructor. sl@0: sl@0: This function attempts to connect to the hierarchy sl@0: specified in the constructor. sl@0: sl@0: @leave One of the system-wide error codes. sl@0: */ sl@0: EXPORT_C void CDmDomainManager::ConstructL() sl@0: { sl@0: User::LeaveIfError(iManager.Connect(iHierarchyId)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Requests a system-wide state transition. sl@0: sl@0: The domain hierarchy is traversed in the specified direction sl@0: sl@0: @param aState The target state. sl@0: @param aDirection The direction in which to traverse the hierarchy. sl@0: */ sl@0: EXPORT_C void CDmDomainManager::RequestSystemTransition(TDmDomainState aState, TDmTraverseDirection aDirection) sl@0: { sl@0: __DM_ASSERT(!IsActive()); sl@0: iStatus = KRequestPending; sl@0: iManager.RequestSystemTransition(aState, aDirection, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Requests a domain state transition. sl@0: sl@0: The domain hierarchy is traversed in the specified direction. sl@0: sl@0: @param aDomain The Id of the domain for which the state transition sl@0: is being requested. sl@0: @param aState The target state. sl@0: @param aDirection The direction in which to traverse the hierarchy. sl@0: */ sl@0: EXPORT_C void CDmDomainManager::RequestDomainTransition(TDmDomainId aDomain, TDmDomainState aState, TDmTraverseDirection aDirection) sl@0: { sl@0: __DM_ASSERT(!IsActive()); sl@0: iStatus = KRequestPending; sl@0: iManager.RequestDomainTransition(aDomain, aState, aDirection, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Adds a domain hierarchy to the domain manager. sl@0: sl@0: @param aHierarchyId The Id of the domain hierarchy to add sl@0: sl@0: @return KErrNone if successful; otherwise one of the other system-wide sl@0: or domain manager specific error codes. sl@0: */ sl@0: EXPORT_C TInt CDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId) sl@0: { sl@0: RDmManagerSession session; sl@0: TInt r = session.Connect(); sl@0: if (r != KErrNone) sl@0: return r; sl@0: r = session.AddDomainHierarchy(aHierarchyId); sl@0: session.Close(); sl@0: return r; sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Cancels a pending event. sl@0: */ sl@0: EXPORT_C void CDmDomainManager::DoCancel() sl@0: { sl@0: iManager.CancelTransition(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Requests a list of transition failures since the last transition request. sl@0: sl@0: @param aTransitionFailures A client-supplied array of TTransitionFailure objects which sl@0: on exit will contain the failures that have occurred since the last transition sl@0: request. sl@0: @pre The session must be connected. sl@0: sl@0: @return KErrNone, if successful; otherwise one of the other system-wide sl@0: or domain manager specific error codes. sl@0: */ sl@0: EXPORT_C TInt CDmDomainManager::GetTransitionFailures(RArray& aTransitionFailures) sl@0: { sl@0: return iManager.GetTransitionFailures(aTransitionFailures); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets the number of transition failures since the last transition request. sl@0: sl@0: @return The number of failures if successful, otherwise one of the other system-wide sl@0: or domain manager specific error codes. sl@0: */ sl@0: EXPORT_C TInt CDmDomainManager::GetTransitionFailureCount() sl@0: { sl@0: return iManager.GetTransitionFailureCount(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: CHierarchyObserver::CHierarchyObserver(MHierarchyObserver& aHierarchyObserver, TDmHierarchyId aHierarchyId): sl@0: CActive(CActive::EPriorityStandard), sl@0: iHierarchyId(aHierarchyId), sl@0: iObserver(aHierarchyObserver) sl@0: { sl@0: iTransitionEvents.Reset(); sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Constructs a new observer on the domain hierarchy. sl@0: sl@0: Note that only one observer per domain hierarchy is allowed. sl@0: sl@0: @param aHierarchyObserver The implementation of the interface to the domain manager. sl@0: @param aHierarchyId The Id of the domain hierarchy. sl@0: sl@0: @return The newly created CHierarchyObserver object. sl@0: */ sl@0: EXPORT_C CHierarchyObserver* CHierarchyObserver::NewL(MHierarchyObserver& aHierarchyObserver,TDmHierarchyId aHierarchyId) sl@0: { sl@0: CHierarchyObserver* observer=new(ELeave)CHierarchyObserver(aHierarchyObserver,aHierarchyId); sl@0: sl@0: CleanupStack::PushL(observer); sl@0: User::LeaveIfError(observer->iSession.ConnectObserver(aHierarchyId)); sl@0: CleanupStack::Pop(); sl@0: sl@0: return(observer); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Destructor. sl@0: sl@0: Frees resources prior to destruction of the object. sl@0: */ sl@0: EXPORT_C CHierarchyObserver::~CHierarchyObserver() sl@0: { sl@0: Cancel(); sl@0: iSession.Close(); sl@0: iTransitionEvents.Reset(); sl@0: } sl@0: sl@0: void CHierarchyObserver::DoCancel() sl@0: { sl@0: iObserverStarted=EFalse; sl@0: iSession.CancelObserver(); sl@0: } sl@0: sl@0: void CHierarchyObserver::RunL() sl@0: // sl@0: // Process the reply to client's request for domain transition/failure sl@0: // sl@0: { sl@0: sl@0: TInt ret= iSession.GetEvents(iTransitionEvents); sl@0: sl@0: User::LeaveIfError(ret); sl@0: sl@0: TInt count = iTransitionEvents.Count(); sl@0: sl@0: for(TInt i=0;i