os/kernelhwsrv/userlibandfileserver/domainmgr/src/domaincli.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// domain\src\domaincli.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32base.h>
sl@0
    19
#include <e32base_private.h>
sl@0
    20
#include <e32property.h>
sl@0
    21
sl@0
    22
#include <domainmember.h>
sl@0
    23
#include <domainmanager.h>
sl@0
    24
#include "domainobserver.h"
sl@0
    25
#include "domainsrv.h"
sl@0
    26
sl@0
    27
#define __DM_PANIC(aError) User::Panic(_L("domainCli.cpp"), (-(aError)) | (__LINE__ << 16))
sl@0
    28
#define __DM_ASSERT(aCond) __ASSERT_DEBUG(aCond,User::Panic(_L("domainCli.cpp; assertion failed"), __LINE__))
sl@0
    29
sl@0
    30
TInt RDmDomainSession::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId, TUint* aKey)
sl@0
    31
	{
sl@0
    32
	TInt r = RSessionBase::CreateSession(KDmDomainServerNameLit, KDmDomainServerVersion, 1);
sl@0
    33
	if (r != KErrNone)
sl@0
    34
		return r;
sl@0
    35
	TIpcArgs a( (TInt)aHierarchyId, (TInt)aDomainId );
sl@0
    36
	r = RSessionBase::SendReceive(EDmDomainJoin, a);
sl@0
    37
	if (r != KErrNone)
sl@0
    38
		{
sl@0
    39
		RSessionBase::Close();
sl@0
    40
		return r;
sl@0
    41
		}
sl@0
    42
	*aKey = DmStatePropertyKey(
sl@0
    43
		aHierarchyId, 
sl@0
    44
		aDomainId);
sl@0
    45
sl@0
    46
	return KErrNone;
sl@0
    47
	}
sl@0
    48
sl@0
    49
void RDmDomainSession::Acknowledge(TInt aValue, TInt aError)
sl@0
    50
	{
sl@0
    51
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
    52
sl@0
    53
	TIpcArgs a(aValue, aError);
sl@0
    54
	TInt r = RSessionBase::SendReceive(EDmStateAcknowledge, a);
sl@0
    55
	if (r != KErrNone)
sl@0
    56
		__DM_PANIC(r);
sl@0
    57
	}
sl@0
    58
sl@0
    59
void RDmDomainSession::RequestTransitionNotification()
sl@0
    60
	{
sl@0
    61
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
    62
	TInt r = RSessionBase::SendReceive(EDmStateRequestTransitionNotification);
sl@0
    63
	if (r != KErrNone)
sl@0
    64
		__DM_PANIC(r);
sl@0
    65
	}
sl@0
    66
sl@0
    67
void RDmDomainSession::CancelTransitionNotification()
sl@0
    68
	{
sl@0
    69
	if (Handle() != KNullHandle)
sl@0
    70
		{
sl@0
    71
		TInt r = RSessionBase::SendReceive(EDmStateCancelTransitionNotification);
sl@0
    72
		if (r != KErrNone)
sl@0
    73
			__DM_PANIC(r);
sl@0
    74
		}
sl@0
    75
	}
sl@0
    76
sl@0
    77
sl@0
    78
sl@0
    79
/**
sl@0
    80
Connects to the domain identified by the specified domain Id.
sl@0
    81
sl@0
    82
To connect to the root domain, which has the Id KDmIdRoot,
sl@0
    83
the capability WriteDeviceData is required.
sl@0
    84
sl@0
    85
Once connected, an  application can use this RDmDomain object to read
sl@0
    86
the domain's power state and to request notification
sl@0
    87
when the power state changes.
sl@0
    88
sl@0
    89
@param aDomainId The identifier of the domain to be connected to.
sl@0
    90
sl@0
    91
@return KErrNone, if successful; otherwise one of the other system-wide
sl@0
    92
        or domain manager specific error codes.
sl@0
    93
sl@0
    94
@capability WriteDeviceData If aDomainId==KDmIdRoot
sl@0
    95
*/
sl@0
    96
EXPORT_C TInt RDmDomain::Connect(TDmDomainId aDomainId)
sl@0
    97
	{
sl@0
    98
	TUint key;
sl@0
    99
	TInt r = iSession.Connect(KDmHierarchyIdPower, aDomainId, &key);
sl@0
   100
	if (r != KErrNone)
sl@0
   101
		return r;
sl@0
   102
	r = iStateProperty.Attach(KUidDmPropertyCategory, key);
sl@0
   103
	if (r != KErrNone)
sl@0
   104
		{
sl@0
   105
		iSession.Close();
sl@0
   106
		return r;
sl@0
   107
		}
sl@0
   108
	return KErrNone;
sl@0
   109
	}
sl@0
   110
	
sl@0
   111
sl@0
   112
sl@0
   113
sl@0
   114
/**
sl@0
   115
Connects to the domain identified by the specified domain Id.
sl@0
   116
sl@0
   117
To connect to the root domain, which has the Id KDmIdRoot,
sl@0
   118
the capability WriteDeviceData is required.
sl@0
   119
sl@0
   120
Once connected, an  application can use this RDmDomain object to read
sl@0
   121
the domain's state and to request notification
sl@0
   122
when the state changes.
sl@0
   123
sl@0
   124
@param aHierarchyId	The Id of the domain hierarchy to connect to.
sl@0
   125
@param aDomainId    The identifier of the domain to be connected to.
sl@0
   126
sl@0
   127
@return KErrNone, if successful; otherwise one of the other system-wide
sl@0
   128
        or domain manager specific error codes.
sl@0
   129
sl@0
   130
@capability WriteDeviceData If aDomainId==KDmIdRoot
sl@0
   131
*/
sl@0
   132
EXPORT_C TInt RDmDomain::Connect(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId)
sl@0
   133
	{
sl@0
   134
	TUint key;
sl@0
   135
	TInt r = iSession.Connect(aHierarchyId, aDomainId, &key);
sl@0
   136
	if (r != KErrNone)
sl@0
   137
		return r;
sl@0
   138
	r = iStateProperty.Attach(KUidDmPropertyCategory, key);
sl@0
   139
	if (r != KErrNone)
sl@0
   140
		{
sl@0
   141
		iSession.Close();
sl@0
   142
		return r;
sl@0
   143
		}
sl@0
   144
	return KErrNone;
sl@0
   145
	}
sl@0
   146
	
sl@0
   147
sl@0
   148
	
sl@0
   149
	
sl@0
   150
/**
sl@0
   151
Disconnects from the associated domain.
sl@0
   152
	
sl@0
   153
If this object is not connected to any domain, then it returns silently.
sl@0
   154
*/
sl@0
   155
EXPORT_C void RDmDomain::Close()
sl@0
   156
	{
sl@0
   157
	iSession.Close();
sl@0
   158
	iStateProperty.Close();
sl@0
   159
	}
sl@0
   160
sl@0
   161
sl@0
   162
sl@0
   163
sl@0
   164
/**
sl@0
   165
Requests notification when the domain's state changes.
sl@0
   166
sl@0
   167
This is an asynchronous request that completes when
sl@0
   168
the domain's state changes.
sl@0
   169
sl@0
   170
@param aStatus The request status object for this asynchronous request.
sl@0
   171
sl@0
   172
@see RDmDomain::CancelTransitionNotification()
sl@0
   173
*/
sl@0
   174
EXPORT_C void RDmDomain::RequestTransitionNotification(TRequestStatus& aStatus)
sl@0
   175
	{
sl@0
   176
	iStateProperty.Subscribe(aStatus);
sl@0
   177
	iSession.RequestTransitionNotification();
sl@0
   178
	}
sl@0
   179
sl@0
   180
sl@0
   181
sl@0
   182
sl@0
   183
/**
sl@0
   184
Cancels an outstanding notification request.
sl@0
   185
sl@0
   186
Any outstanding notification request completes with KErrCancel.
sl@0
   187
*/
sl@0
   188
EXPORT_C void RDmDomain::CancelTransitionNotification()
sl@0
   189
	{
sl@0
   190
	iSession.CancelTransitionNotification();
sl@0
   191
	iStateProperty.Cancel();
sl@0
   192
	}
sl@0
   193
sl@0
   194
sl@0
   195
sl@0
   196
sl@0
   197
/**
sl@0
   198
Gets the domain's power state.
sl@0
   199
	
sl@0
   200
An application normally calls this function after a notification request
sl@0
   201
has completed. It then performs any application-dependent action demanded by
sl@0
   202
the power state, and then acknowledges the state transition.
sl@0
   203
sl@0
   204
Note that the domain manager requires any domain power state change to be
sl@0
   205
acknowledged by all applications connected to the domain.
sl@0
   206
sl@0
   207
@return The connected domain's power state.
sl@0
   208
sl@0
   209
@see RDmDomain::AcknowledgeLastState()
sl@0
   210
*/
sl@0
   211
EXPORT_C TPowerState RDmDomain::GetPowerState()
sl@0
   212
	{
sl@0
   213
	TInt value;
sl@0
   214
	TInt r = iStateProperty.Get(value);
sl@0
   215
	if (r != KErrNone)
sl@0
   216
		__DM_PANIC(r);
sl@0
   217
	iLastStatePropertyValue = value;
sl@0
   218
	return (TPowerState) DmStateFromPropertyValue(value);
sl@0
   219
	}
sl@0
   220
sl@0
   221
sl@0
   222
sl@0
   223
sl@0
   224
/**
sl@0
   225
Acknowledges the state change.
sl@0
   226
	
sl@0
   227
An application must acknowledge that it has performed all actions required
sl@0
   228
by the last known state of the domain.
sl@0
   229
*/
sl@0
   230
EXPORT_C void RDmDomain::AcknowledgeLastState()
sl@0
   231
	{
sl@0
   232
	iSession.Acknowledge(iLastStatePropertyValue, KErrNone);
sl@0
   233
	}
sl@0
   234
sl@0
   235
sl@0
   236
/**
sl@0
   237
Acknowledges the state change with the specified error
sl@0
   238
	
sl@0
   239
An application must acknowledge that it has performed all actions required
sl@0
   240
by the last known state of the domain.
sl@0
   241
sl@0
   242
@param aError KDmErrNotJoin if domain is not part of the hierarhcy or a 
sl@0
   243
	system wide error value associated with the state change.
sl@0
   244
*/
sl@0
   245
EXPORT_C void RDmDomain::AcknowledgeLastState(TInt aError)
sl@0
   246
	{
sl@0
   247
	iSession.Acknowledge(iLastStatePropertyValue, aError);
sl@0
   248
	}
sl@0
   249
sl@0
   250
sl@0
   251
sl@0
   252
/**
sl@0
   253
Gets the domain's state.
sl@0
   254
	
sl@0
   255
An application normally calls this function after a notification request
sl@0
   256
has completed. It then performs any application-dependent action demanded by
sl@0
   257
the state, and then acknowledges the state transition.
sl@0
   258
sl@0
   259
Note, that the domain manager requires any domain state change to be
sl@0
   260
acknowledged by all applications connected to the domain.
sl@0
   261
sl@0
   262
@return The connected domain's state.
sl@0
   263
*/
sl@0
   264
EXPORT_C TDmDomainState RDmDomain::GetState()
sl@0
   265
	{
sl@0
   266
	TInt value;
sl@0
   267
	TInt r = iStateProperty.Get(value);
sl@0
   268
	if (r != KErrNone)
sl@0
   269
		__DM_PANIC(r);
sl@0
   270
	iLastStatePropertyValue = value;
sl@0
   271
	return DmStateFromPropertyValue(value);
sl@0
   272
	}
sl@0
   273
sl@0
   274
TInt RDmManagerSession::Connect()
sl@0
   275
	{
sl@0
   276
	__DM_ASSERT(Handle() == KNullHandle);
sl@0
   277
sl@0
   278
	return RSessionBase::CreateSession(
sl@0
   279
				KDmManagerServerNameLit, 
sl@0
   280
				KDmManagerServerVersion, 
sl@0
   281
				2);
sl@0
   282
	}
sl@0
   283
sl@0
   284
TInt RDmManagerSession::ConnectObserver(TDmHierarchyId aHierarchyId)
sl@0
   285
	{
sl@0
   286
	TInt r = Connect();
sl@0
   287
	if (r != KErrNone)
sl@0
   288
		return r;
sl@0
   289
sl@0
   290
	TIpcArgs a( (TInt)aHierarchyId);
sl@0
   291
	r = RSessionBase::SendReceive(EDmObserverJoin, a);
sl@0
   292
	if (r != KErrNone)
sl@0
   293
		{
sl@0
   294
		RSessionBase::Close();
sl@0
   295
		return r;
sl@0
   296
		}
sl@0
   297
	return KErrNone;
sl@0
   298
	}
sl@0
   299
sl@0
   300
TInt RDmManagerSession::Connect(TDmHierarchyId aHierarchyId)
sl@0
   301
	{
sl@0
   302
	TInt r = Connect();
sl@0
   303
	if (r != KErrNone)
sl@0
   304
		return r;
sl@0
   305
sl@0
   306
	TIpcArgs a( (TInt)aHierarchyId);
sl@0
   307
	r = RSessionBase::SendReceive(EDmHierarchyJoin, a);
sl@0
   308
	if (r != KErrNone)
sl@0
   309
		{
sl@0
   310
		RSessionBase::Close();
sl@0
   311
		return r;
sl@0
   312
		}
sl@0
   313
	return KErrNone;
sl@0
   314
	}
sl@0
   315
sl@0
   316
void RDmManagerSession::RequestDomainTransition(
sl@0
   317
	TDmDomainId aDomainId, 
sl@0
   318
	TDmDomainState aState,
sl@0
   319
	TDmTraverseDirection aDirection,
sl@0
   320
	TRequestStatus& aStatus)
sl@0
   321
	{
sl@0
   322
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   323
	
sl@0
   324
	if(aDirection < 0 || aDirection > ETraverseMax)
sl@0
   325
		__DM_PANIC(KErrArgument);
sl@0
   326
sl@0
   327
	TIpcArgs a(aDomainId, aState, aDirection);
sl@0
   328
	RSessionBase::SendReceive(EDmRequestDomainTransition, a, aStatus);
sl@0
   329
	}
sl@0
   330
sl@0
   331
void RDmManagerSession::CancelTransition()
sl@0
   332
	{
sl@0
   333
	if (Handle() != KNullHandle)
sl@0
   334
		{
sl@0
   335
		TInt r = RSessionBase::SendReceive(EDmCancelTransition);
sl@0
   336
		if (r != KErrNone)
sl@0
   337
			__DM_PANIC(r);
sl@0
   338
		}
sl@0
   339
	}
sl@0
   340
sl@0
   341
void RDmManagerSession::CancelObserver()
sl@0
   342
	{
sl@0
   343
	if (Handle() != KNullHandle)
sl@0
   344
		{
sl@0
   345
		TInt r = RSessionBase::SendReceive(EDmObserverCancel);
sl@0
   346
		if (r != KErrNone)
sl@0
   347
			__DM_PANIC(r);
sl@0
   348
		}
sl@0
   349
	}
sl@0
   350
sl@0
   351
void RDmManagerSession::RequestSystemTransition(
sl@0
   352
	TDmDomainState aState,
sl@0
   353
	TDmTraverseDirection aDirection,
sl@0
   354
	TRequestStatus& aStatus)
sl@0
   355
	{
sl@0
   356
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   357
sl@0
   358
	TIpcArgs a(aState, aDirection);
sl@0
   359
	RSessionBase::SendReceive(EDmRequestSystemTransition, a, aStatus);
sl@0
   360
	}
sl@0
   361
sl@0
   362
TInt RDmManagerSession::AddDomainHierarchy(TDmHierarchyId aHierarchyId)
sl@0
   363
	{
sl@0
   364
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   365
sl@0
   366
	TIpcArgs a( (TInt)aHierarchyId);
sl@0
   367
	TInt r = RSessionBase::SendReceive(EDmHierarchyAdd, a);
sl@0
   368
sl@0
   369
	return r;
sl@0
   370
	}
sl@0
   371
sl@0
   372
TInt RDmManagerSession::GetTransitionFailureCount()
sl@0
   373
	{
sl@0
   374
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   375
sl@0
   376
	return RSessionBase::SendReceive(EDmGetTransitionFailureCount);
sl@0
   377
	}
sl@0
   378
sl@0
   379
TInt RDmManagerSession::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
sl@0
   380
	{
sl@0
   381
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   382
sl@0
   383
	aTransitionFailures.Reset();
sl@0
   384
sl@0
   385
	TInt err = KErrNone;
sl@0
   386
sl@0
   387
	TInt failureCount = GetTransitionFailureCount();
sl@0
   388
	if (failureCount <= 0)
sl@0
   389
		return failureCount;
sl@0
   390
sl@0
   391
	TTransitionFailure* failures = new TTransitionFailure[failureCount];
sl@0
   392
	if(failures == NULL)
sl@0
   393
		return(KErrNoMemory);
sl@0
   394
	TPtr8 dataPtr(reinterpret_cast<TUint8*>(failures), failureCount * sizeof(TTransitionFailure));
sl@0
   395
sl@0
   396
	TIpcArgs a(&dataPtr);
sl@0
   397
	err = RSessionBase::SendReceive(EDmGetTransitionFailures, a);
sl@0
   398
	
sl@0
   399
	if (err == KErrNone)
sl@0
   400
		{
sl@0
   401
		for (TInt i=0; i<failureCount; i++)
sl@0
   402
			aTransitionFailures.Append(failures[i]);
sl@0
   403
		}
sl@0
   404
sl@0
   405
	delete [] failures;
sl@0
   406
sl@0
   407
	return err;
sl@0
   408
	}
sl@0
   409
sl@0
   410
TInt RDmManagerSession::StartObserver(TDmDomainId aDomainId, TDmNotifyType aNotifyType)
sl@0
   411
	{
sl@0
   412
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   413
	
sl@0
   414
	TIpcArgs a(aDomainId,aNotifyType);
sl@0
   415
	return(RSessionBase::SendReceive(EDmObserverStart,a));
sl@0
   416
	}
sl@0
   417
sl@0
   418
void RDmManagerSession::GetNotification(TRequestStatus& aStatus)
sl@0
   419
	{
sl@0
   420
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   421
	RSessionBase::SendReceive(EDmObserverNotify,aStatus);
sl@0
   422
	}
sl@0
   423
	
sl@0
   424
TInt RDmManagerSession::GetEventCount()
sl@0
   425
	{
sl@0
   426
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   427
	return(RSessionBase::SendReceive(EDmObserverEventCount));
sl@0
   428
	}
sl@0
   429
sl@0
   430
TInt RDmManagerSession::GetEvents(RArray<const TTransInfo>& aTransitions)
sl@0
   431
	{
sl@0
   432
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   433
sl@0
   434
	aTransitions.Reset();
sl@0
   435
sl@0
   436
sl@0
   437
	TInt count = GetEventCount();
sl@0
   438
	// This shouldn't happen unless something gone terribly wrong
sl@0
   439
	if (count <= 0)
sl@0
   440
		return KErrGeneral;
sl@0
   441
sl@0
   442
	TTransInfo* trans = new TTransInfo[count];
sl@0
   443
	if(trans == NULL)
sl@0
   444
		return(KErrNoMemory);
sl@0
   445
	
sl@0
   446
	TPtr8 dataPtr(reinterpret_cast<TUint8*>(trans), count * sizeof(TTransInfo));
sl@0
   447
sl@0
   448
	TIpcArgs a(&dataPtr);
sl@0
   449
	TInt ret=RSessionBase::SendReceive(EDmObserverGetEvent, a);
sl@0
   450
	
sl@0
   451
	if(ret==KErrNone)
sl@0
   452
		{
sl@0
   453
		for (TInt i=0; i<count; i++)
sl@0
   454
			aTransitions.Append(trans[i]);
sl@0
   455
		}
sl@0
   456
	
sl@0
   457
	delete [] trans;
sl@0
   458
	return ret;
sl@0
   459
	
sl@0
   460
	}
sl@0
   461
sl@0
   462
TInt RDmManagerSession::ObserverDomainCount()
sl@0
   463
	{
sl@0
   464
	__DM_ASSERT(Handle() != KNullHandle);
sl@0
   465
	return(RSessionBase::SendReceive(EDmObserveredCount));
sl@0
   466
	}
sl@0
   467
sl@0
   468
/**
sl@0
   469
@internalAll
sl@0
   470
@released
sl@0
   471
*/
sl@0
   472
EXPORT_C TInt RDmDomainManager::WaitForInitialization()
sl@0
   473
	{
sl@0
   474
	RProperty prop;
sl@0
   475
	TInt r = prop.Attach(KUidDmPropertyCategory, KDmPropertyKeyInit);
sl@0
   476
	if (r != KErrNone)
sl@0
   477
		return r;
sl@0
   478
sl@0
   479
#ifdef _DEBUG
sl@0
   480
	TInt count = RThread().RequestCount();
sl@0
   481
#endif
sl@0
   482
sl@0
   483
	TRequestStatus status;
sl@0
   484
	for (;;)
sl@0
   485
		{
sl@0
   486
		prop.Subscribe(status);
sl@0
   487
		TInt value;
sl@0
   488
		r = prop.Get(value);
sl@0
   489
		if (r == KErrNone)
sl@0
   490
			{
sl@0
   491
			if (value) break; // initialized
sl@0
   492
			// property exists but the server is not intialized yet
sl@0
   493
			}
sl@0
   494
		else
sl@0
   495
			{
sl@0
   496
			if (r != KErrNotFound) break; // error
sl@0
   497
			// property doesn't exist yet
sl@0
   498
			}
sl@0
   499
		User::WaitForRequest(status);
sl@0
   500
		if (status.Int() != KErrNone)
sl@0
   501
			break;	// error
sl@0
   502
		}
sl@0
   503
sl@0
   504
	if (status.Int() == KRequestPending)
sl@0
   505
		{
sl@0
   506
		prop.Cancel();
sl@0
   507
		User::WaitForRequest(status);
sl@0
   508
		}
sl@0
   509
	prop.Close();
sl@0
   510
sl@0
   511
	__DM_ASSERT(RThread().RequestCount() == count);
sl@0
   512
sl@0
   513
	return r;
sl@0
   514
	}
sl@0
   515
sl@0
   516
sl@0
   517
sl@0
   518
sl@0
   519
/**
sl@0
   520
Opens a controlling connection to the standard power domain hierarchy
sl@0
   521
in the domain manager.
sl@0
   522
sl@0
   523
The domain manger allows only one open connection at any one time to the 
sl@0
   524
power domain hierarchy.
sl@0
   525
Connection is usually made by the power policy entity.
sl@0
   526
sl@0
   527
@return KErrNone, if successful; otherwise one of the other system-wide
sl@0
   528
        or the domain manager specific error codes.
sl@0
   529
        
sl@0
   530
@see KDmErrAlreadyJoin   
sl@0
   531
*/
sl@0
   532
EXPORT_C TInt RDmDomainManager::Connect()
sl@0
   533
	{
sl@0
   534
	return iSession.Connect(KDmHierarchyIdPower);
sl@0
   535
	}
sl@0
   536
sl@0
   537
sl@0
   538
sl@0
   539
sl@0
   540
/**
sl@0
   541
Opens a controlling connection to a specific domain hieararchy owned 
sl@0
   542
by the domain manager.
sl@0
   543
sl@0
   544
The domain manger allows only one open connection at any one time to a 
sl@0
   545
particular hierarchy.
sl@0
   546
sl@0
   547
@param	aHierarchyId	The Id of the domain hierarchy to connect to.
sl@0
   548
sl@0
   549
@return KErrNone, if successful; otherwise one of the other system-wide
sl@0
   550
        or domain manager specific error codes.
sl@0
   551
        
sl@0
   552
@see KDmErrAlreadyJoin
sl@0
   553
@see KErrBadHierarchyId       
sl@0
   554
*/
sl@0
   555
EXPORT_C TInt RDmDomainManager::Connect(TDmHierarchyId aHierarchyId)
sl@0
   556
sl@0
   557
	{
sl@0
   558
	return iSession.Connect(aHierarchyId);
sl@0
   559
	}
sl@0
   560
sl@0
   561
sl@0
   562
sl@0
   563
sl@0
   564
/**
sl@0
   565
Closes this connection to the domain manager.
sl@0
   566
	
sl@0
   567
If there is no existing connection, then it returns silently.
sl@0
   568
*/
sl@0
   569
EXPORT_C void RDmDomainManager::Close()
sl@0
   570
	{
sl@0
   571
	iSession.Close();
sl@0
   572
	}
sl@0
   573
sl@0
   574
sl@0
   575
sl@0
   576
sl@0
   577
/**
sl@0
   578
Requests a system-wide power state transition.
sl@0
   579
sl@0
   580
The domain hierarchy is traversed in the default direction
sl@0
   581
		
sl@0
   582
@param aState   The target power state.
sl@0
   583
@param aStatus  The request status object for this asynchronous request.
sl@0
   584
sl@0
   585
@see RDmDomainManager::CancelTransition()
sl@0
   586
*/
sl@0
   587
EXPORT_C void RDmDomainManager::RequestSystemTransition(TPowerState aState, TRequestStatus& aStatus)
sl@0
   588
	{
sl@0
   589
	if (aState == EPwActive)
sl@0
   590
		{
sl@0
   591
		TRequestStatus* status = &aStatus;
sl@0
   592
		User::RequestComplete(status, KErrArgument);
sl@0
   593
		return;
sl@0
   594
		}
sl@0
   595
	RequestSystemTransition((TDmDomainState) aState, ETraverseDefault, aStatus);
sl@0
   596
	}
sl@0
   597
sl@0
   598
sl@0
   599
sl@0
   600
sl@0
   601
/**
sl@0
   602
Requests a system-wide power shutdown.
sl@0
   603
sl@0
   604
This is a request to change the system's power state to EPwOff.
sl@0
   605
This call does not return; the system can only return by rebooting.
sl@0
   606
*/
sl@0
   607
EXPORT_C void RDmDomainManager::SystemShutdown()
sl@0
   608
	{
sl@0
   609
	TRequestStatus status;
sl@0
   610
	RequestSystemTransition((TDmDomainState) EPwOff, ETraverseDefault, status);
sl@0
   611
	User::WaitForRequest(status);
sl@0
   612
	__DM_ASSERT(0);
sl@0
   613
	}
sl@0
   614
sl@0
   615
sl@0
   616
sl@0
   617
sl@0
   618
/**
sl@0
   619
Requests a domain state transition.
sl@0
   620
sl@0
   621
The domain hierarchy is traversed in the default direction.
sl@0
   622
sl@0
   623
@param aDomainId The Id of the domain for which the state transition
sl@0
   624
                 is being requested.
sl@0
   625
@param aState    The target state.
sl@0
   626
@param aStatus   The request status object for this asynchronous request.
sl@0
   627
sl@0
   628
@see RDmDomainManager::CancelTransition()
sl@0
   629
*/
sl@0
   630
EXPORT_C void RDmDomainManager::RequestDomainTransition(
sl@0
   631
	TDmDomainId aDomainId, 
sl@0
   632
	TPowerState aState, 
sl@0
   633
	TRequestStatus& aStatus)
sl@0
   634
	{
sl@0
   635
	RequestDomainTransition(aDomainId,(TDmDomainState)  aState, ETraverseDefault, aStatus);
sl@0
   636
	}
sl@0
   637
sl@0
   638
sl@0
   639
sl@0
   640
sl@0
   641
/**
sl@0
   642
Cancels a state transition, whether initiated by a call
sl@0
   643
to RequestSystemTransition() or RequestDomainTransition().
sl@0
   644
sl@0
   645
An outstanding state transition request completes with KErrCancel.
sl@0
   646
*/
sl@0
   647
EXPORT_C void RDmDomainManager::CancelTransition()
sl@0
   648
	{
sl@0
   649
	iSession.CancelTransition();
sl@0
   650
	}
sl@0
   651
sl@0
   652
sl@0
   653
sl@0
   654
sl@0
   655
/**
sl@0
   656
Requests a system-wide state transition.
sl@0
   657
sl@0
   658
The domain hierarchy is traversed in the specified direction.
sl@0
   659
		
sl@0
   660
@param aState   The target state.
sl@0
   661
@param aDirection The direction in which to traverse the hierarchy
sl@0
   662
@param aStatus  The request status object for this asynchronous request.
sl@0
   663
sl@0
   664
@see RDmDomainManager::CancelTransition()
sl@0
   665
sl@0
   666
@panic domainCli.cpp; assertion failed VARNUM if the numerical value of aDirection
sl@0
   667
       is greater than the value of ETraverseMax. NOTE: VARNUM is the line number
sl@0
   668
       in the source code and may change if the implementation changes.
sl@0
   669
*/
sl@0
   670
EXPORT_C void RDmDomainManager::RequestSystemTransition(
sl@0
   671
	TDmDomainState aState, 
sl@0
   672
	TDmTraverseDirection aDirection, 
sl@0
   673
	TRequestStatus& aStatus)
sl@0
   674
	{
sl@0
   675
	__DM_ASSERT(aDirection <= ETraverseMax);
sl@0
   676
	iSession.RequestSystemTransition(aState, aDirection, aStatus);
sl@0
   677
	}
sl@0
   678
sl@0
   679
sl@0
   680
sl@0
   681
sl@0
   682
/**
sl@0
   683
Requests a domain state transition.
sl@0
   684
sl@0
   685
The domain hierarchy is traversed in the specified direction
sl@0
   686
sl@0
   687
@param aDomainId The Id of the domain for which the state transition
sl@0
   688
                 is being requested.
sl@0
   689
@param aState    The target state.
sl@0
   690
@param aDirection The direction in which to traverse the hierarchy.
sl@0
   691
@param aStatus   The request status object for this asynchronous request.
sl@0
   692
sl@0
   693
@see RDmDomainManager::CancelTransition()
sl@0
   694
sl@0
   695
@panic domainCli.cpp; assertion failed VARNUM if the numerical value of aDirection
sl@0
   696
       is greater than the value of ETraverseMax. NOTE: VARNUM is the line number
sl@0
   697
       in the source code and may change if the implementation changes.
sl@0
   698
*/
sl@0
   699
EXPORT_C void RDmDomainManager::RequestDomainTransition(
sl@0
   700
	TDmDomainId aDomainId, 
sl@0
   701
	TDmDomainState aState, 
sl@0
   702
	TDmTraverseDirection aDirection,
sl@0
   703
	TRequestStatus& aStatus)
sl@0
   704
	{
sl@0
   705
	__DM_ASSERT(aDirection <= ETraverseMax);
sl@0
   706
	iSession.RequestDomainTransition(aDomainId, aState, aDirection, aStatus);
sl@0
   707
	}
sl@0
   708
sl@0
   709
sl@0
   710
sl@0
   711
sl@0
   712
/**
sl@0
   713
Adds a domain hierarchy to the domain manager.
sl@0
   714
sl@0
   715
@param aHierarchyId The Id of the domain hierarchy to be added.
sl@0
   716
sl@0
   717
@return	KErrNone if successful; otherwise one of the other system-wide
sl@0
   718
        or domain manager specific error codes.
sl@0
   719
*/
sl@0
   720
EXPORT_C TInt RDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId)
sl@0
   721
	{
sl@0
   722
	RDmManagerSession	session;
sl@0
   723
	TInt r = session.Connect();
sl@0
   724
	if (r != KErrNone)
sl@0
   725
		return r;
sl@0
   726
	r = session.AddDomainHierarchy(aHierarchyId);
sl@0
   727
	session.Close();
sl@0
   728
	return r;
sl@0
   729
	}
sl@0
   730
sl@0
   731
sl@0
   732
sl@0
   733
/**
sl@0
   734
Requests a list of transition failures since the last transition request.
sl@0
   735
sl@0
   736
@param aTransitionFailures A client-supplied array of TTransitionFailure objects which 
sl@0
   737
		on exit will contain the failures that have occurred since the last transition 
sl@0
   738
		request. 
sl@0
   739
@pre	The session must be connected.
sl@0
   740
sl@0
   741
@return KErrNone, if successful; otherwise one of the other system-wide
sl@0
   742
        or domain manager specific error codes.
sl@0
   743
*/
sl@0
   744
EXPORT_C TInt RDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
sl@0
   745
	{
sl@0
   746
	return iSession.GetTransitionFailures(aTransitionFailures);
sl@0
   747
	}
sl@0
   748
sl@0
   749
sl@0
   750
sl@0
   751
/**
sl@0
   752
Gets the number of transition failures since the last transition request.
sl@0
   753
sl@0
   754
@return	The number of failures, if successful; otherwise one of the other system-wide
sl@0
   755
        or domain manager specific error codes.
sl@0
   756
*/
sl@0
   757
EXPORT_C TInt RDmDomainManager::GetTransitionFailureCount()
sl@0
   758
	{
sl@0
   759
	return iSession.GetTransitionFailureCount();
sl@0
   760
	}
sl@0
   761
sl@0
   762
sl@0
   763
sl@0
   764
// CDmDomain
sl@0
   765
sl@0
   766
/**
sl@0
   767
Constructor.
sl@0
   768
sl@0
   769
Adds this active object to the active scheduler. The priority of the active object
sl@0
   770
is the standard value, i.e. CActive::EPriorityStandard.
sl@0
   771
sl@0
   772
@param aHierarchyId The Id of the domain hierarchy to connect to.
sl@0
   773
@param aDomainId	The Id of the domain to connect to.
sl@0
   774
sl@0
   775
@see CActive
sl@0
   776
@see CActive::TPriority
sl@0
   777
*/
sl@0
   778
EXPORT_C CDmDomain::CDmDomain(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId) : 
sl@0
   779
	CActive(CActive::EPriorityStandard), 
sl@0
   780
	iHierarchyId(aHierarchyId), 
sl@0
   781
	iDomainId(aDomainId)
sl@0
   782
	{
sl@0
   783
	CActiveScheduler::Add(this);
sl@0
   784
	}
sl@0
   785
sl@0
   786
sl@0
   787
sl@0
   788
sl@0
   789
/**
sl@0
   790
Destructor.
sl@0
   791
sl@0
   792
Closes the session to the domain manager.
sl@0
   793
*/
sl@0
   794
EXPORT_C CDmDomain::~CDmDomain()
sl@0
   795
	{
sl@0
   796
	Cancel();
sl@0
   797
	iDomain.Close();
sl@0
   798
	}
sl@0
   799
sl@0
   800
sl@0
   801
sl@0
   802
sl@0
   803
/**
sl@0
   804
Second-phase constructor.
sl@0
   805
sl@0
   806
The function attempts to connect to the domain specified in the constructor.
sl@0
   807
sl@0
   808
@leave One of the system-wide error codes
sl@0
   809
*/
sl@0
   810
EXPORT_C void CDmDomain::ConstructL()
sl@0
   811
	{
sl@0
   812
	User::LeaveIfError(iDomain.Connect(iHierarchyId, iDomainId));
sl@0
   813
	}
sl@0
   814
sl@0
   815
sl@0
   816
sl@0
   817
sl@0
   818
/**
sl@0
   819
Requests notification when the domain's state changes.
sl@0
   820
sl@0
   821
RunL() will be called when this happens.
sl@0
   822
*/
sl@0
   823
EXPORT_C void CDmDomain::RequestTransitionNotification()
sl@0
   824
	{
sl@0
   825
	__DM_ASSERT(!IsActive());
sl@0
   826
	iDomain.RequestTransitionNotification(iStatus);
sl@0
   827
	SetActive();
sl@0
   828
	}
sl@0
   829
sl@0
   830
sl@0
   831
sl@0
   832
sl@0
   833
/**
sl@0
   834
Cancels an outstanding notification request.
sl@0
   835
sl@0
   836
Any outstanding notification request completes with KErrCancel.
sl@0
   837
*/
sl@0
   838
EXPORT_C void CDmDomain::DoCancel()
sl@0
   839
	{
sl@0
   840
	iDomain.CancelTransitionNotification();
sl@0
   841
	}
sl@0
   842
sl@0
   843
sl@0
   844
sl@0
   845
sl@0
   846
/**
sl@0
   847
Acknowledges the last state change.
sl@0
   848
	
sl@0
   849
An application must acknowledge that it has performed all actions required
sl@0
   850
by the last known state of the domain.
sl@0
   851
sl@0
   852
@param aError	The error to return to the domain manager. The client should
sl@0
   853
				set this to KErrNone if it successfully transitioned to the 
sl@0
   854
				new state or to one of the system-wide error codes.
sl@0
   855
*/
sl@0
   856
EXPORT_C void CDmDomain::AcknowledgeLastState(TInt aError)
sl@0
   857
	{
sl@0
   858
	iDomain.AcknowledgeLastState(aError);
sl@0
   859
	}
sl@0
   860
sl@0
   861
sl@0
   862
sl@0
   863
sl@0
   864
/**
sl@0
   865
Gets the domain's state.
sl@0
   866
	
sl@0
   867
An application normally calls this function after a notification request
sl@0
   868
has completed. It then performs any application-dependent action demanded by
sl@0
   869
the state, and then acknowledges the state transition.
sl@0
   870
sl@0
   871
@return The connected domain's state.
sl@0
   872
*/
sl@0
   873
EXPORT_C TDmDomainState CDmDomain::GetState()
sl@0
   874
	{
sl@0
   875
	return iDomain.GetState();
sl@0
   876
	}
sl@0
   877
sl@0
   878
// CDmDomainManager
sl@0
   879
sl@0
   880
/**
sl@0
   881
Constructor.
sl@0
   882
sl@0
   883
Adds this active object to the active scheduler.
sl@0
   884
sl@0
   885
@param aHierarchyId The Id of the domain hierarchy to connect to
sl@0
   886
*/
sl@0
   887
EXPORT_C CDmDomainManager::CDmDomainManager(TDmHierarchyId aHierarchyId) : 
sl@0
   888
	CActive(CActive::EPriorityStandard), 
sl@0
   889
	iHierarchyId(aHierarchyId)
sl@0
   890
	{
sl@0
   891
	CActiveScheduler::Add(this);
sl@0
   892
	}
sl@0
   893
sl@0
   894
sl@0
   895
sl@0
   896
sl@0
   897
/**
sl@0
   898
Destructor.
sl@0
   899
sl@0
   900
Closes the session to the domain manager.
sl@0
   901
*/
sl@0
   902
EXPORT_C CDmDomainManager::~CDmDomainManager()
sl@0
   903
	{
sl@0
   904
	Cancel();
sl@0
   905
	iManager.Close();
sl@0
   906
	}
sl@0
   907
sl@0
   908
sl@0
   909
sl@0
   910
sl@0
   911
/**
sl@0
   912
The second-phase constructor.
sl@0
   913
sl@0
   914
This function attempts to connect to the hierarchy 
sl@0
   915
specified in the constructor.
sl@0
   916
sl@0
   917
@leave One of the system-wide error codes.
sl@0
   918
*/
sl@0
   919
EXPORT_C void CDmDomainManager::ConstructL()
sl@0
   920
	{
sl@0
   921
	User::LeaveIfError(iManager.Connect(iHierarchyId));
sl@0
   922
	}
sl@0
   923
sl@0
   924
sl@0
   925
sl@0
   926
sl@0
   927
/**
sl@0
   928
Requests a system-wide state transition.
sl@0
   929
sl@0
   930
The domain hierarchy is traversed in the specified direction
sl@0
   931
		
sl@0
   932
@param aState   The target state.
sl@0
   933
@param aDirection The direction in which to traverse the hierarchy.
sl@0
   934
*/
sl@0
   935
EXPORT_C void CDmDomainManager::RequestSystemTransition(TDmDomainState aState, TDmTraverseDirection aDirection)
sl@0
   936
	{
sl@0
   937
	__DM_ASSERT(!IsActive());
sl@0
   938
	iStatus = KRequestPending;
sl@0
   939
	iManager.RequestSystemTransition(aState, aDirection, iStatus);
sl@0
   940
	SetActive();
sl@0
   941
	}
sl@0
   942
sl@0
   943
sl@0
   944
sl@0
   945
sl@0
   946
/**
sl@0
   947
Requests a domain state transition.
sl@0
   948
sl@0
   949
The domain hierarchy is traversed in the specified direction.
sl@0
   950
sl@0
   951
@param aDomain The Id of the domain for which the state transition
sl@0
   952
                 is being requested.
sl@0
   953
@param aState    The target state.
sl@0
   954
@param aDirection The direction in which to traverse the hierarchy.
sl@0
   955
*/
sl@0
   956
EXPORT_C void CDmDomainManager::RequestDomainTransition(TDmDomainId aDomain, TDmDomainState aState, TDmTraverseDirection aDirection)
sl@0
   957
	{
sl@0
   958
	__DM_ASSERT(!IsActive());
sl@0
   959
	iStatus = KRequestPending;
sl@0
   960
	iManager.RequestDomainTransition(aDomain, aState, aDirection, iStatus);
sl@0
   961
	SetActive();
sl@0
   962
	}
sl@0
   963
sl@0
   964
sl@0
   965
sl@0
   966
sl@0
   967
/**
sl@0
   968
Adds a domain hierarchy to the domain manager.
sl@0
   969
sl@0
   970
@param aHierarchyId The Id of the domain hierarchy to add
sl@0
   971
sl@0
   972
@return	KErrNone if successful; otherwise one of the other system-wide
sl@0
   973
        or domain manager specific error codes.
sl@0
   974
*/
sl@0
   975
EXPORT_C TInt CDmDomainManager::AddDomainHierarchy(TDmHierarchyId aHierarchyId)
sl@0
   976
	{
sl@0
   977
	RDmManagerSession	session;
sl@0
   978
	TInt r = session.Connect();
sl@0
   979
	if (r != KErrNone)
sl@0
   980
		return r;
sl@0
   981
	r = session.AddDomainHierarchy(aHierarchyId);
sl@0
   982
	session.Close();
sl@0
   983
	return r;
sl@0
   984
sl@0
   985
	}
sl@0
   986
sl@0
   987
sl@0
   988
sl@0
   989
sl@0
   990
/**
sl@0
   991
Cancels a pending event.
sl@0
   992
*/
sl@0
   993
EXPORT_C void CDmDomainManager::DoCancel()
sl@0
   994
	{
sl@0
   995
	iManager.CancelTransition();
sl@0
   996
	}
sl@0
   997
sl@0
   998
sl@0
   999
sl@0
  1000
sl@0
  1001
/**
sl@0
  1002
Requests a list of transition failures since the last transition request.
sl@0
  1003
sl@0
  1004
@param aTransitionFailures A client-supplied array of TTransitionFailure objects which 
sl@0
  1005
		on exit will contain the failures that have occurred since the last transition 
sl@0
  1006
		request. 
sl@0
  1007
@pre	The session must be connected.
sl@0
  1008
sl@0
  1009
@return KErrNone, if successful; otherwise one of the other system-wide
sl@0
  1010
        or domain manager specific error codes.
sl@0
  1011
*/
sl@0
  1012
EXPORT_C TInt CDmDomainManager::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
sl@0
  1013
	{
sl@0
  1014
	return iManager.GetTransitionFailures(aTransitionFailures);
sl@0
  1015
	}
sl@0
  1016
sl@0
  1017
sl@0
  1018
sl@0
  1019
sl@0
  1020
/**
sl@0
  1021
Gets the number of transition failures since the last transition request.
sl@0
  1022
sl@0
  1023
@return	The number of failures if successful, otherwise one of the other system-wide
sl@0
  1024
        or domain manager specific error codes.
sl@0
  1025
*/
sl@0
  1026
EXPORT_C TInt CDmDomainManager::GetTransitionFailureCount()
sl@0
  1027
	{
sl@0
  1028
	return iManager.GetTransitionFailureCount();
sl@0
  1029
	}
sl@0
  1030
sl@0
  1031
sl@0
  1032
sl@0
  1033
sl@0
  1034
CHierarchyObserver::CHierarchyObserver(MHierarchyObserver& aHierarchyObserver, TDmHierarchyId aHierarchyId):
sl@0
  1035
	CActive(CActive::EPriorityStandard), 
sl@0
  1036
	iHierarchyId(aHierarchyId),
sl@0
  1037
	iObserver(aHierarchyObserver)
sl@0
  1038
	{
sl@0
  1039
	iTransitionEvents.Reset();
sl@0
  1040
	CActiveScheduler::Add(this);
sl@0
  1041
	}
sl@0
  1042
sl@0
  1043
sl@0
  1044
sl@0
  1045
sl@0
  1046
/**
sl@0
  1047
Constructs a new observer on the domain hierarchy.
sl@0
  1048
sl@0
  1049
Note that only one observer per domain hierarchy is allowed.
sl@0
  1050
sl@0
  1051
@param	aHierarchyObserver	The implementation of the interface to the domain manager.
sl@0
  1052
@param	aHierarchyId		The Id of the domain hierarchy.
sl@0
  1053
sl@0
  1054
@return The newly created CHierarchyObserver object.
sl@0
  1055
*/
sl@0
  1056
EXPORT_C CHierarchyObserver* CHierarchyObserver::NewL(MHierarchyObserver& aHierarchyObserver,TDmHierarchyId aHierarchyId)
sl@0
  1057
	{
sl@0
  1058
	CHierarchyObserver* observer=new(ELeave)CHierarchyObserver(aHierarchyObserver,aHierarchyId);
sl@0
  1059
sl@0
  1060
	CleanupStack::PushL(observer);
sl@0
  1061
	User::LeaveIfError(observer->iSession.ConnectObserver(aHierarchyId));
sl@0
  1062
	CleanupStack::Pop();
sl@0
  1063
	
sl@0
  1064
	return(observer);
sl@0
  1065
	}
sl@0
  1066
sl@0
  1067
sl@0
  1068
sl@0
  1069
sl@0
  1070
/**
sl@0
  1071
Destructor.
sl@0
  1072
sl@0
  1073
Frees resources prior to destruction of the object.
sl@0
  1074
*/
sl@0
  1075
EXPORT_C CHierarchyObserver::~CHierarchyObserver()
sl@0
  1076
	{
sl@0
  1077
	Cancel();
sl@0
  1078
	iSession.Close();
sl@0
  1079
	iTransitionEvents.Reset();
sl@0
  1080
	}
sl@0
  1081
sl@0
  1082
void CHierarchyObserver::DoCancel()
sl@0
  1083
	{
sl@0
  1084
	iObserverStarted=EFalse;
sl@0
  1085
	iSession.CancelObserver();
sl@0
  1086
	}
sl@0
  1087
sl@0
  1088
void CHierarchyObserver::RunL()
sl@0
  1089
//
sl@0
  1090
// Process the reply to client's request for domain transition/failure
sl@0
  1091
//
sl@0
  1092
	{
sl@0
  1093
sl@0
  1094
	TInt ret= iSession.GetEvents(iTransitionEvents);
sl@0
  1095
	
sl@0
  1096
	User::LeaveIfError(ret);
sl@0
  1097
	
sl@0
  1098
	TInt count = iTransitionEvents.Count();
sl@0
  1099
sl@0
  1100
	for(TInt i=0;i<count;i++)
sl@0
  1101
		{
sl@0
  1102
		if(iTransitionEvents[i].iError==KErrNone)
sl@0
  1103
			iObserver.TransProgEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState);
sl@0
  1104
		else if(iTransitionEvents[i].iError==KDmErrOutstanding)
sl@0
  1105
			iObserver.TransReqEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState);
sl@0
  1106
		else
sl@0
  1107
			iObserver.TransFailEvent(iTransitionEvents[i].iDomainId,iTransitionEvents[i].iState,iTransitionEvents[i].iError);
sl@0
  1108
		}
sl@0
  1109
sl@0
  1110
	GetNotification();
sl@0
  1111
	}
sl@0
  1112
sl@0
  1113
sl@0
  1114
sl@0
  1115
sl@0
  1116
/**
sl@0
  1117
Starts the observer. 
sl@0
  1118
sl@0
  1119
@param	aDomainId		The Id of the domain to which the obsever is attached.
sl@0
  1120
@param	aNotifyType		The type of notifications of interest to the observer.
sl@0
  1121
sl@0
  1122
@return KErrNone on successful start, otherwise one of the other system wide error codes.
sl@0
  1123
*/
sl@0
  1124
EXPORT_C TInt CHierarchyObserver::StartObserver(TDmDomainId aDomainId, TDmNotifyType aNotifyType)
sl@0
  1125
	{
sl@0
  1126
	iNotifyType=aNotifyType;
sl@0
  1127
	iDomainId=aDomainId;
sl@0
  1128
	
sl@0
  1129
	TInt ret=iSession.StartObserver(iDomainId, iNotifyType);
sl@0
  1130
	if(ret!=KErrNone)
sl@0
  1131
		return ret;
sl@0
  1132
	iObserverStarted=ETrue;
sl@0
  1133
	GetNotification();
sl@0
  1134
	return KErrNone;
sl@0
  1135
	}
sl@0
  1136
sl@0
  1137
sl@0
  1138
sl@0
  1139
sl@0
  1140
/**
sl@0
  1141
Stops the observer. 
sl@0
  1142
sl@0
  1143
@return KErrNone if successful; KDmErrBadSequence, if the observer 
sl@0
  1144
        has not already started.
sl@0
  1145
*/
sl@0
  1146
EXPORT_C TInt CHierarchyObserver::StopObserver()
sl@0
  1147
	{
sl@0
  1148
	if(!iObserverStarted)
sl@0
  1149
		return(KDmErrBadSequence);
sl@0
  1150
	Cancel();
sl@0
  1151
	return(KErrNone);
sl@0
  1152
	}
sl@0
  1153
sl@0
  1154
void CHierarchyObserver::GetNotification()
sl@0
  1155
	{
sl@0
  1156
	iSession.GetNotification(iStatus);
sl@0
  1157
	SetActive();
sl@0
  1158
	}
sl@0
  1159
sl@0
  1160
/**
sl@0
  1161
Gets the number of domains that are being observed.
sl@0
  1162
sl@0
  1163
This value is the number of children of the domain member to which the observer
sl@0
  1164
is attached, including itself. 
sl@0
  1165
sl@0
  1166
@return The number of observed domain members.
sl@0
  1167
        One of the other system wide error codes may be returned on failure;
sl@0
  1168
        specifically KErrNotFound if the observer is not already started.
sl@0
  1169
*/
sl@0
  1170
EXPORT_C TInt CHierarchyObserver::ObserverDomainCount()
sl@0
  1171
	{
sl@0
  1172
	if(!iObserverStarted)
sl@0
  1173
		return KErrNotFound;
sl@0
  1174
	return(iSession.ObserverDomainCount());	
sl@0
  1175
	}