os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/b2bwatchers.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) 2007-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
// testcaseb2broot.cpp
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <e32std_private.h>
sl@0
    21
#include <u32std.h> 	// unicode builds
sl@0
    22
#include <e32base.h>
sl@0
    23
#include <e32base_private.h>
sl@0
    24
#include <e32cons.h>
sl@0
    25
#include <e32Test.h>	// RTest header
sl@0
    26
#include <e32ver.h>
sl@0
    27
#include <e32def.h>
sl@0
    28
#include <e32def_private.h>
sl@0
    29
#include <d32otgdi.h>		// OTGDI header
sl@0
    30
#include <d32usbc.h>		// USBCC header
sl@0
    31
#include "testcaseroot.h"
sl@0
    32
#include "b2bwatchers.h"
sl@0
    33
sl@0
    34
sl@0
    35
sl@0
    36
void CNotifyWatcherBase::RunL()
sl@0
    37
	{
sl@0
    38
	DisplayEvent(); 
sl@0
    39
	iHandler.HandleEvent(iWatchType, GetEventValue()); // report the event upwards
sl@0
    40
sl@0
    41
	IssueAgain(); 
sl@0
    42
	SetActive();
sl@0
    43
	}
sl@0
    44
sl@0
    45
sl@0
    46
CNotifyCollector::CNotifyCollector(TRequestStatus &aStatus)  : iStatusStep(aStatus) 
sl@0
    47
	{
sl@0
    48
	LOG_FUNC
sl@0
    49
	TTimeIntervalDays oneday(1);
sl@0
    50
	iTimeStarted.HomeTime();
sl@0
    51
	iTimeStarted += (oneday); // force all durations to produce a negative (invalid) value
sl@0
    52
	}
sl@0
    53
sl@0
    54
sl@0
    55
/***************************************************************
sl@0
    56
 *  ~CNotifyCollector
sl@0
    57
 */ 
sl@0
    58
CNotifyCollector::~CNotifyCollector()
sl@0
    59
	{
sl@0
    60
	LOG_FUNC
sl@0
    61
	
sl@0
    62
	ClearAllEvents(); // free event arrays
sl@0
    63
sl@0
    64
	iNotifyObjects.Close();
sl@0
    65
	iFailureEvents.Close();
sl@0
    66
	iRequiredEvents.Close();
sl@0
    67
	iReceivedEvents.Close();
sl@0
    68
	}
sl@0
    69
sl@0
    70
sl@0
    71
/* The test-case calls this to clear the events stored.
sl@0
    72
 * Both the expected and already recieved events get cleared, this method 
sl@0
    73
 * is typically called at the start of each test-step
sl@0
    74
 */
sl@0
    75
void CNotifyCollector::ClearAllEvents(TBool aClearRecieved/*=ETrue*/, TBool aClearRequired /*=ETrue*/)
sl@0
    76
	{
sl@0
    77
	//LOG_FUNC
sl@0
    78
	if (aClearRequired)
sl@0
    79
		{
sl@0
    80
		iRequiredEvents.Reset();
sl@0
    81
		iFailureEvents.Reset();
sl@0
    82
		}
sl@0
    83
	if (aClearRecieved)
sl@0
    84
		{
sl@0
    85
		iReceivedEvents.Reset();
sl@0
    86
		}
sl@0
    87
	}
sl@0
    88
sl@0
    89
sl@0
    90
/* Creates and starts all 4 observers
sl@0
    91
 * Note: The Watchdog does not get started, because it needs an interval
sl@0
    92
 */
sl@0
    93
void CNotifyCollector::CreateObserversL(COtgRoot &aOtgDriver)
sl@0
    94
	{
sl@0
    95
	LOG_FUNC
sl@0
    96
	TInt watchType;
sl@0
    97
	ASSERT(aOtgDriver.LddLoaded());
sl@0
    98
	
sl@0
    99
	for (watchType=EWatcherTimeouts; watchType < EWatcherInvalid; watchType++)
sl@0
   100
		{
sl@0
   101
		CNotifyWatcherBase *pWatcher=0;
sl@0
   102
		switch ((TWatcherNotifyType )watchType)
sl@0
   103
			{
sl@0
   104
			case EWatcherTimeouts:
sl@0
   105
				pWatcher = COtgWatchdogWatcher::NewL(*this,  EWatcherTimeouts, aOtgDriver);
sl@0
   106
				break;
sl@0
   107
			case EWatcherState:
sl@0
   108
				pWatcher = COtgStateWatcher::NewL(*this , EWatcherState, aOtgDriver);
sl@0
   109
				break;
sl@0
   110
			case EWatcherEvent:
sl@0
   111
				pWatcher = COtgEventWatcher::NewL(*this, EWatcherEvent, aOtgDriver);
sl@0
   112
				break;
sl@0
   113
			case EWatcherMessage:
sl@0
   114
				pWatcher = COtgMessageWatcher::NewL(*this, EWatcherMessage, aOtgDriver);
sl@0
   115
				break;
sl@0
   116
			case EWatcherPeripheralState:
sl@0
   117
				pWatcher = CPeripheralStateWatcher::NewL(*this, EWatcherPeripheralState, aOtgDriver);
sl@0
   118
				break;
sl@0
   119
			case EWatcherAConnectionIdle:
sl@0
   120
				pWatcher = CAConnectionIdleWatcher::NewL(*this, EWatcherAConnectionIdle, aOtgDriver);
sl@0
   121
				break;
sl@0
   122
sl@0
   123
			}
sl@0
   124
		// the TRequest object is added to scheduler in it's own constructor
sl@0
   125
		
sl@0
   126
		// add it to our list so we can kill them after the test.
sl@0
   127
		iNotifyObjects.Append(pWatcher);
sl@0
   128
		//LOG_VERBOSE3(_L("Added watcher type %d, TRequest= %08X.\n"), iType, (TInt)(&pWatcher->iStatus));	
sl@0
   129
		
sl@0
   130
		// start all watchers, except for the watchdog
sl@0
   131
		if (watchType != EWatcherTimeouts)
sl@0
   132
			{
sl@0
   133
			pWatcher->StartWatching(-1);
sl@0
   134
			}
sl@0
   135
		}
sl@0
   136
	test.Printf(_L("\n"));
sl@0
   137
	}
sl@0
   138
sl@0
   139
sl@0
   140
/* NOTE: OTG must still be loaded or else we cannot cancel the outstanding event watches here!
sl@0
   141
 */
sl@0
   142
void CNotifyCollector::DestroyObservers()
sl@0
   143
	{
sl@0
   144
	LOG_FUNC
sl@0
   145
	
sl@0
   146
	// Free the Watchers
sl@0
   147
	for (TInt idx=0; idx < iNotifyObjects.Count(); idx++)
sl@0
   148
		{
sl@0
   149
		LOG_VERBOSE2(_L(".. %d .."), idx);		
sl@0
   150
		delete iNotifyObjects[idx];	// they will call their own Cancel() methods
sl@0
   151
		}
sl@0
   152
	iNotifyObjects.Close();	
sl@0
   153
	}
sl@0
   154
sl@0
   155
sl@0
   156
void CNotifyCollector::AddRequiredNotification(TWatcherNotifyType aType, TInt aValue)
sl@0
   157
	{
sl@0
   158
	AddRequiredOrFailureNotification(aType, aValue, EFalse);
sl@0
   159
	}
sl@0
   160
sl@0
   161
void CNotifyCollector::	AddFailureNotification(const TWatcherNotifyType aType, TInt aValue)
sl@0
   162
	{
sl@0
   163
	AddRequiredOrFailureNotification(aType, aValue, ETrue);
sl@0
   164
	}
sl@0
   165
sl@0
   166
/* Checks that a watcher for the event exists, and then adds it to a list of events required for a PASS condition
sl@0
   167
 * The timout event does not get added to this list.
sl@0
   168
 * If the parameter is a time, the timer gets started
sl@0
   169
 * If aEventMeansFailure is set True, then the reception of the event will cause the current test step to fail
sl@0
   170
 */	
sl@0
   171
void CNotifyCollector::AddRequiredOrFailureNotification(TWatcherNotifyType aType, TInt aValue, TBool aEventMeansFailure)
sl@0
   172
	{
sl@0
   173
	CNotifyWatcherBase *pWatcher=0;
sl@0
   174
	TInt index=0;
sl@0
   175
	TBuf<MAX_DSTRLEN> aDescription;	
sl@0
   176
sl@0
   177
	// print a usefull debug message
sl@0
   178
	switch (aType)
sl@0
   179
		{
sl@0
   180
		case EWatcherTimeouts:
sl@0
   181
			break;
sl@0
   182
		case EWatcherState:
sl@0
   183
			COtgRoot::OtgStateString(static_cast<RUsbOtgDriver::TOtgState>(aValue), aDescription);
sl@0
   184
			LOG_VERBOSE3(_L("AddRequiredNotification() State %d '%S' wanted\n"), aValue, &aDescription);
sl@0
   185
			break;
sl@0
   186
		case EWatcherEvent:
sl@0
   187
			COtgRoot::OtgEventString(static_cast<RUsbOtgDriver::TOtgEvent>(aValue), aDescription);
sl@0
   188
			LOG_VERBOSE3(_L("AddRequiredNotification() Event %d '%S' wanted\n"), aValue, &aDescription);
sl@0
   189
			break;
sl@0
   190
		case EWatcherMessage:
sl@0
   191
			COtgRoot::OtgMessageString(static_cast<RUsbOtgDriver::TOtgMessage>(aValue), aDescription);
sl@0
   192
			LOG_VERBOSE3(_L("AddRequiredNotification() Message %d '%S' wanted\n"), aValue, &aDescription);
sl@0
   193
			break;
sl@0
   194
		case EWatcherPeripheralState:
sl@0
   195
			COtgRoot::PeripheralStateString(static_cast<TUint>(aValue), aDescription);
sl@0
   196
			LOG_VERBOSE3(_L("AddRequiredNotification() Peripheral State %d '%S' wanted\n"), aValue, &aDescription);
sl@0
   197
			break;
sl@0
   198
		case EWatcherAConnectionIdle:
sl@0
   199
			COtgRoot::AConnectionIdleString(static_cast<RUsbOtgDriver::TOtgConnection>(aValue), aDescription);
sl@0
   200
			LOG_VERBOSE3(_L("AddRequiredNotification() AConnectionIdle %d '%S' wanted\n"), aValue, &aDescription);
sl@0
   201
			break;
sl@0
   202
sl@0
   203
		}
sl@0
   204
	
sl@0
   205
	// Find the watcher if possible
sl@0
   206
	while (index < iNotifyObjects.Count())
sl@0
   207
		{
sl@0
   208
sl@0
   209
		TEST_ASSERTION(iNotifyObjects[index]!=NULL, _L("iNotifyObjects element gone!"));
sl@0
   210
sl@0
   211
		if (iNotifyObjects[index]->GetType() == aType)
sl@0
   212
			{
sl@0
   213
			pWatcher = iNotifyObjects[index];
sl@0
   214
			break;
sl@0
   215
			}
sl@0
   216
		index++;
sl@0
   217
		}
sl@0
   218
	
sl@0
   219
	TEST_ASSERTION(pWatcher!=NULL, _L("pWatcher=0!"));
sl@0
   220
	if (aType == EWatcherTimeouts)	
sl@0
   221
		{ // other watchers are already running, but we start the timer now
sl@0
   222
		pWatcher->StartWatching(aValue);
sl@0
   223
		}
sl@0
   224
	else
sl@0
   225
		{ // timeouts are not added to the Q
sl@0
   226
		TOtgObservedEvent evt(aType, aValue);	
sl@0
   227
		if(aEventMeansFailure)
sl@0
   228
			{
sl@0
   229
			iFailureEvents.Append(evt);
sl@0
   230
			}
sl@0
   231
		else
sl@0
   232
			{
sl@0
   233
			iRequiredEvents.Append(evt);
sl@0
   234
			}
sl@0
   235
		}
sl@0
   236
	// flag as pending
sl@0
   237
	iStatusStep = KRequestPending;
sl@0
   238
	iTimeStarted.HomeTime();
sl@0
   239
	}
sl@0
   240
sl@0
   241
sl@0
   242
/* Return the number of milliseconds since the last call to AddRequiredNotification()
sl@0
   243
 */
sl@0
   244
TInt CNotifyCollector::DurationElapsed()
sl@0
   245
	{
sl@0
   246
	TTime TimeEnd;
sl@0
   247
	TInt Millisec;
sl@0
   248
sl@0
   249
	TimeEnd.HomeTime();
sl@0
   250
	TTimeIntervalMicroSeconds ivlMicro(TimeEnd.MicroSecondsFrom(iTimeStarted));
sl@0
   251
	Millisec = (TInt)(ivlMicro.Int64())/1000;	// USB times are in uSec, but in ms for the user layer
sl@0
   252
sl@0
   253
	if (Millisec < 0)
sl@0
   254
		Millisec = -1; // TRUE for when the Notifiers are not yet being used.
sl@0
   255
	return(Millisec);				
sl@0
   256
	}
sl@0
   257
sl@0
   258
sl@0
   259
/* Search for an event in the received Q
sl@0
   260
 * @return :TRUE if the specified event has been received
sl@0
   261
 */
sl@0
   262
TBool CNotifyCollector::EventReceivedAlready(const TOtgObservedEvent& aEvent)
sl@0
   263
	{
sl@0
   264
	for (TInt idx=0; idx < iReceivedEvents.Count(); idx++)
sl@0
   265
		if (iReceivedEvents[idx] == aEvent)
sl@0
   266
			return(ETrue);
sl@0
   267
	return(EFalse);
sl@0
   268
	}
sl@0
   269
sl@0
   270
/* Search for an event in the failure event queue
sl@0
   271
 * @return :TRUE if the specified event does denote a failure
sl@0
   272
 */
sl@0
   273
TBool CNotifyCollector::IsFailureEvent(TOtgObservedEvent &aEvent)
sl@0
   274
	{
sl@0
   275
	for (TInt idx=0; idx < iFailureEvents.Count(); idx++)
sl@0
   276
		if (iFailureEvents[idx] == aEvent)
sl@0
   277
			return(ETrue);
sl@0
   278
	return(EFalse);
sl@0
   279
	}
sl@0
   280
sl@0
   281
/* @return 0 if the watcher has not yet been created. (for instance early in the test)
sl@0
   282
 */
sl@0
   283
CNotifyWatcherBase* CNotifyCollector::GetWatcher(TWatcherNotifyType aType)
sl@0
   284
	{
sl@0
   285
	CNotifyWatcherBase *pWatcher=0;
sl@0
   286
	// Find the watcher 
sl@0
   287
	TInt index=0;
sl@0
   288
	
sl@0
   289
	while (index < iNotifyObjects.Count())
sl@0
   290
		{
sl@0
   291
sl@0
   292
		TEST_ASSERTION(iNotifyObjects[index]!=NULL, _L("iNotifyObjects element gone!"));
sl@0
   293
sl@0
   294
		if (iNotifyObjects[index]->GetType() == aType)
sl@0
   295
			{
sl@0
   296
			pWatcher = iNotifyObjects[index];
sl@0
   297
			break;
sl@0
   298
			}
sl@0
   299
		index++;
sl@0
   300
		}
sl@0
   301
sl@0
   302
	return(pWatcher);
sl@0
   303
	}
sl@0
   304
sl@0
   305
sl@0
   306
/* Process the event. The OTG watchers are responsible for renewing themselves
sl@0
   307
 * but the Timer event does not renew
sl@0
   308
 */
sl@0
   309
void CNotifyCollector::HandleEvent(TWatcherNotifyType aType, TInt aValue)
sl@0
   310
	{
sl@0
   311
	if (aType == EWatcherTimeouts)
sl@0
   312
		{
sl@0
   313
		test.Printf(_L("Step timed out..(%dms).\n\n"), GetWatcher(aType)->GetEventValue());
sl@0
   314
		CompleteStep(KTestCaseWatchdogTO);
sl@0
   315
		return;
sl@0
   316
		}
sl@0
   317
	
sl@0
   318
	TOtgObservedEvent evt(aType, aValue);
sl@0
   319
	TInt start=0;
sl@0
   320
	iReceivedEvents.Append(evt);  // store incomming evt
sl@0
   321
sl@0
   322
	//	Check to see whether the event denotes a failure for this event
sl@0
   323
	if (IsFailureEvent(evt))
sl@0
   324
		{
sl@0
   325
		test.Printf(_L("This event denotes failure for this test\n"));
sl@0
   326
		CompleteStep(KTestCaseFailureEventReceived);
sl@0
   327
		return;
sl@0
   328
		}
sl@0
   329
	
sl@0
   330
	if (iRequiredEvents.Count())
sl@0
   331
		{
sl@0
   332
		// itterate all required events, search for each one in the incomming events list
sl@0
   333
		while (start< iRequiredEvents.Count())
sl@0
   334
			{
sl@0
   335
				//LOG_VERBOSE3(_L("Search for=[%d,%d] :"), 
sl@0
   336
				//					iRequiredEvents[start].GetType(), iRequiredEvents[start].GetValue());
sl@0
   337
				
sl@0
   338
				if (!EventReceivedAlready(iRequiredEvents[start]))
sl@0
   339
					return;	// missing still, continue
sl@0
   340
			start++; 
sl@0
   341
			}
sl@0
   342
		// found all the required events
sl@0
   343
		LOG_VERBOSE1(_L("Found all.\n"));
sl@0
   344
		CompleteStep(KErrNone);
sl@0
   345
		}
sl@0
   346
	else
sl@0
   347
		{
sl@0
   348
		test.Printf(_L("Warning : No required events!\n"));
sl@0
   349
		}	
sl@0
   350
	}
sl@0
   351
sl@0
   352
//	Complete the test step's TRequestStatus (checking it is currently KRequestPending
sl@0
   353
//	to try and avoid multiple completions).
sl@0
   354
//
sl@0
   355
void CNotifyCollector::CompleteStep(TInt aCompletionCode)
sl@0
   356
	{
sl@0
   357
	if(iStatusStep.Int() != KRequestPending)
sl@0
   358
		{
sl@0
   359
		test.Printf(_L("Can't complete step - not KRequestPending!\n"));
sl@0
   360
		}
sl@0
   361
	else
sl@0
   362
		{
sl@0
   363
		TRequestStatus *StatusStepPtr = &iStatusStep;
sl@0
   364
		User::RequestComplete(StatusStepPtr, aCompletionCode);
sl@0
   365
		}
sl@0
   366
	}
sl@0
   367
sl@0
   368
/****************************************************************************
sl@0
   369
 * COtg Watchdog Watcher
sl@0
   370
 */
sl@0
   371
COtgWatchdogWatcher *COtgWatchdogWatcher::NewL(MOtgNotificationHandler &wdHandler, 
sl@0
   372
												const TWatcherNotifyType aWatchType, 
sl@0
   373
												COtgRoot &aOtgRoot)
sl@0
   374
	{
sl@0
   375
	LOG_FUNC 
sl@0
   376
	COtgWatchdogWatcher* self = new (ELeave) COtgWatchdogWatcher(wdHandler, aWatchType, aOtgRoot);
sl@0
   377
	CleanupStack::PushL(self);
sl@0
   378
	self->ConstructL();
sl@0
   379
	CleanupStack::Pop(self);
sl@0
   380
	return self;
sl@0
   381
	}
sl@0
   382
sl@0
   383
sl@0
   384
void COtgWatchdogWatcher::ConstructL()
sl@0
   385
	{
sl@0
   386
	LOG_FUNC
sl@0
   387
	
sl@0
   388
	iTimer.CreateLocal();
sl@0
   389
	iIntervalMs = -1;
sl@0
   390
	}
sl@0
   391
sl@0
   392
sl@0
   393
void COtgWatchdogWatcher::StepExpired(TInt aInterval) 
sl@0
   394
	{
sl@0
   395
	LOG_FUNC ; 
sl@0
   396
	iHandler.HandleEvent(EWatcherTimeouts, aInterval) ; 
sl@0
   397
	}
sl@0
   398
sl@0
   399
sl@0
   400
void COtgWatchdogWatcher::RunL()
sl@0
   401
	{ 
sl@0
   402
	//LOG_FUNC 
sl@0
   403
	StepExpired(iIntervalMs); 
sl@0
   404
	}
sl@0
   405
sl@0
   406
sl@0
   407
void COtgWatchdogWatcher::StartTimer(TInt aIntervalMs)
sl@0
   408
	{
sl@0
   409
	LOG_FUNC ;
sl@0
   410
sl@0
   411
	iIntervalMs = aIntervalMs;	// save value for printing latter 
sl@0
   412
	if (IsActive()) //cancel the last timer we set, this is easier than cancelling it in each test-step
sl@0
   413
		{
sl@0
   414
		iTimer.Cancel();
sl@0
   415
		User::WaitForRequest(iStatus); // swallow it
sl@0
   416
		iTimer.After(iStatus, aIntervalMs*1000);
sl@0
   417
		}
sl@0
   418
	else
sl@0
   419
		{
sl@0
   420
		iTimer.After(iStatus, aIntervalMs*1000);
sl@0
   421
		SetActive();
sl@0
   422
		}
sl@0
   423
	LOG_VERBOSE2(_L("wd Timer %dms\n"), aIntervalMs)
sl@0
   424
	}	
sl@0
   425
sl@0
   426
sl@0
   427
/****************************************************************************
sl@0
   428
 * OTG Event/State/Message Watchers
sl@0
   429
 */
sl@0
   430
COtgMessageWatcher* COtgMessageWatcher::NewL(MOtgNotificationHandler &wdHandler, 
sl@0
   431
										const TWatcherNotifyType aWatchType, 
sl@0
   432
										COtgRoot &aOtgRoot)
sl@0
   433
	{
sl@0
   434
	LOG_FUNC 
sl@0
   435
	COtgMessageWatcher* self = new (ELeave) COtgMessageWatcher(wdHandler, aWatchType, aOtgRoot);
sl@0
   436
	CleanupStack::PushL(self);
sl@0
   437
	self->ConstructL();
sl@0
   438
	CleanupStack::Pop(self);
sl@0
   439
	return self;
sl@0
   440
	}
sl@0
   441
sl@0
   442
sl@0
   443
void COtgMessageWatcher::DisplayEvent()
sl@0
   444
	{
sl@0
   445
	TBuf<MAX_DSTRLEN> aDescription;	
sl@0
   446
	iOtgRoot.OtgMessageString(iMessage, aDescription);
sl@0
   447
	test.Printf(_L("Received Message %d '%S'\n"), iMessage, &aDescription);
sl@0
   448
	}
sl@0
   449
sl@0
   450
sl@0
   451
COtgStateWatcher* COtgStateWatcher::NewL(MOtgNotificationHandler &wdHandler, 
sl@0
   452
										const TWatcherNotifyType aWatchType, 
sl@0
   453
										COtgRoot &aOtgRoot)
sl@0
   454
	{
sl@0
   455
	LOG_FUNC 
sl@0
   456
	COtgStateWatcher* self = new (ELeave) COtgStateWatcher(wdHandler, aWatchType, aOtgRoot);
sl@0
   457
	CleanupStack::PushL(self);
sl@0
   458
	self->ConstructL();
sl@0
   459
	CleanupStack::Pop(self);
sl@0
   460
	return self;
sl@0
   461
	}
sl@0
   462
sl@0
   463
sl@0
   464
void COtgStateWatcher::DisplayEvent() 
sl@0
   465
	{
sl@0
   466
	//LOG_FUNC
sl@0
   467
	TBuf<MAX_DSTRLEN> aDescription;	
sl@0
   468
	iOtgRoot.OtgStateString(iState, aDescription);
sl@0
   469
	test.Printf(_L("Received State %d '%S'\n"), iState, &aDescription);
sl@0
   470
	}
sl@0
   471
sl@0
   472
sl@0
   473
COtgEventWatcher* COtgEventWatcher::NewL(MOtgNotificationHandler &wdHandler, 
sl@0
   474
										const TWatcherNotifyType aWatchType, 
sl@0
   475
										COtgRoot &aOtgRoot)
sl@0
   476
	{
sl@0
   477
	//LOG_FUNC 
sl@0
   478
	COtgEventWatcher* self = new (ELeave) COtgEventWatcher(wdHandler, aWatchType, aOtgRoot);
sl@0
   479
	CleanupStack::PushL(self);
sl@0
   480
	self->ConstructL();
sl@0
   481
	CleanupStack::Pop(self);
sl@0
   482
	return self;
sl@0
   483
	}
sl@0
   484
sl@0
   485
void COtgEventWatcher::DisplayEvent()
sl@0
   486
	{
sl@0
   487
	TBuf<MAX_DSTRLEN> aDescription;	
sl@0
   488
	iOtgRoot.OtgEventString(iEvent, aDescription);
sl@0
   489
	test.Printf(_L("Received Event %d '%S'\n"), iEvent, &aDescription);
sl@0
   490
	}
sl@0
   491
sl@0
   492
CPeripheralStateWatcher* CPeripheralStateWatcher::NewL(MOtgNotificationHandler &wdHandler, 
sl@0
   493
														const TWatcherNotifyType aWatchType, 
sl@0
   494
														COtgRoot &aOtgRoot)
sl@0
   495
	{
sl@0
   496
	//LOG_FUNC 
sl@0
   497
	CPeripheralStateWatcher* self = new (ELeave) CPeripheralStateWatcher(wdHandler, aWatchType, aOtgRoot);
sl@0
   498
	CleanupStack::PushL(self);
sl@0
   499
	self->ConstructL();
sl@0
   500
	CleanupStack::Pop(self);
sl@0
   501
	return self;
sl@0
   502
	}
sl@0
   503
sl@0
   504
void CPeripheralStateWatcher::DisplayEvent()
sl@0
   505
	{
sl@0
   506
	TBuf<MAX_DSTRLEN> aDescription;	
sl@0
   507
	iOtgRoot.PeripheralStateString(iPeripheralState, aDescription);
sl@0
   508
	test.Printf(_L("Peripheral State %d '%S'\n"), iPeripheralState, &aDescription);
sl@0
   509
	}
sl@0
   510
sl@0
   511
CAConnectionIdleWatcher* CAConnectionIdleWatcher::NewL(MOtgNotificationHandler &wdHandler, 
sl@0
   512
														const TWatcherNotifyType aWatchType, 
sl@0
   513
														COtgRoot &aOtgRoot)
sl@0
   514
	{
sl@0
   515
	//LOG_FUNC 
sl@0
   516
	CAConnectionIdleWatcher* self = new (ELeave) CAConnectionIdleWatcher(wdHandler, aWatchType, aOtgRoot);
sl@0
   517
	CleanupStack::PushL(self);
sl@0
   518
	self->ConstructL();
sl@0
   519
	CleanupStack::Pop(self);
sl@0
   520
	return self;
sl@0
   521
	}
sl@0
   522
sl@0
   523
void CAConnectionIdleWatcher::RunL()
sl@0
   524
	{
sl@0
   525
	//	We need to override the RunL for this event type, as
sl@0
   526
	//	the semantics of the asynchronous function are somewhat
sl@0
   527
	//	different to the rest of the ones being serviced by 
sl@0
   528
	//	CNotifyWatcherBase.
sl@0
   529
	//
sl@0
   530
	//	In the case of QueueOtgConnectionNotification, the value
sl@0
   531
	//	passed in is updated *immediately* to reflect the current
sl@0
   532
	//	activity or otherwise of the connection (unlike the other
sl@0
   533
	//	async functions which update the value on completion).
sl@0
   534
	//	The completion in the case of QueueOtgConnectionNotification
sl@0
   535
	//	is used to indicate that the value has changed, and
sl@0
   536
	//	another request should be queued to pick up this new value.
sl@0
   537
	//
sl@0
   538
	//	The practical upshot of this is that the IssueAgain needs
sl@0
   539
	//	to happen before the event is displayed and handled...
sl@0
   540
	
sl@0
   541
	IssueAgain(); 
sl@0
   542
	DisplayEvent(); 
sl@0
   543
	iHandler.HandleEvent(iWatchType, GetEventValue()); // report the event upwards
sl@0
   544
	SetActive();
sl@0
   545
	}
sl@0
   546
sl@0
   547
sl@0
   548
void CAConnectionIdleWatcher::DisplayEvent()
sl@0
   549
	{
sl@0
   550
	TBuf<MAX_DSTRLEN> aDescription;	
sl@0
   551
	iOtgRoot.AConnectionIdleString(iAConnectionIdle, aDescription);
sl@0
   552
	test.Printf(_L("AConnectionIdle %d '%S'\n"), iAConnectionIdle, &aDescription);
sl@0
   553
	}