os/kernelhwsrv/kerneltest/e32test/system/d_nanowait.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1997-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
// e32test\system\d_nanowait.cpp
sl@0
    15
// LDD for testing nanosecond blocking
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "plat_priv.h"
sl@0
    20
#include "d_nanowait.h"
sl@0
    21
sl@0
    22
const TInt KMajorVersionNumber=0;
sl@0
    23
const TInt KMinorVersionNumber=1;
sl@0
    24
const TInt KBuildVersionNumber=1;
sl@0
    25
sl@0
    26
sl@0
    27
// global Dfc Que
sl@0
    28
TDynamicDfcQue* gDfcQ;
sl@0
    29
sl@0
    30
sl@0
    31
class DNanoWaitFactory : public DLogicalDevice
sl@0
    32
//
sl@0
    33
// NanoWait LDD factory
sl@0
    34
//
sl@0
    35
	{
sl@0
    36
public:
sl@0
    37
	DNanoWaitFactory();
sl@0
    38
	~DNanoWaitFactory();
sl@0
    39
	virtual TInt Install();						//overriding pure virtual
sl@0
    40
	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
sl@0
    41
	virtual TInt Create(DLogicalChannelBase*& aChannel);	//overriding pure virtual
sl@0
    42
	};
sl@0
    43
sl@0
    44
class DNanoWait : public DLogicalChannel
sl@0
    45
//
sl@0
    46
// nanowait LDD channel
sl@0
    47
//
sl@0
    48
	{
sl@0
    49
public:
sl@0
    50
	DNanoWait();
sl@0
    51
	~DNanoWait();
sl@0
    52
protected:
sl@0
    53
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    54
	TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
sl@0
    55
	virtual void HandleMsg(TMessageBase* aMsg);
sl@0
    56
public:
sl@0
    57
	inline DThread* Client() { return iThread; }
sl@0
    58
public:
sl@0
    59
	DThread* iThread;
sl@0
    60
	TDynamicDfcQue* iDfcQ;
sl@0
    61
	};
sl@0
    62
sl@0
    63
sl@0
    64
sl@0
    65
DECLARE_STANDARD_LDD()
sl@0
    66
	{
sl@0
    67
    return new DNanoWaitFactory;
sl@0
    68
    }
sl@0
    69
sl@0
    70
DNanoWaitFactory::DNanoWaitFactory()
sl@0
    71
//
sl@0
    72
// Constructor
sl@0
    73
//
sl@0
    74
    {
sl@0
    75
    iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
    76
    //iParseMask=0;//No units, no info, no PDD
sl@0
    77
    //iUnitsMask=0;//Only one thing
sl@0
    78
    }
sl@0
    79
sl@0
    80
TInt DNanoWaitFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
    81
//
sl@0
    82
// Create a new DMsTim on this logical device
sl@0
    83
//
sl@0
    84
    {
sl@0
    85
	aChannel=new DNanoWait;
sl@0
    86
	return aChannel?KErrNone:KErrNoMemory;
sl@0
    87
    }
sl@0
    88
sl@0
    89
const TInt KDNanoWaitThreadPriority = 27;
sl@0
    90
_LIT(KDNanoWaitThread,"DNanoWaitThread");
sl@0
    91
sl@0
    92
TInt DNanoWaitFactory::Install()
sl@0
    93
//
sl@0
    94
// Install the LDD - overriding pure virtual
sl@0
    95
//
sl@0
    96
    {
sl@0
    97
	// Allocate a kernel thread to run the DFC 
sl@0
    98
	TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDNanoWaitThreadPriority, KDNanoWaitThread);
sl@0
    99
sl@0
   100
#ifdef CPU_AFFINITY_ANY
sl@0
   101
	NKern::ThreadSetCpuAffinity((NThread*)(gDfcQ->iThread), KCpuAffinityAny);			
sl@0
   102
#endif
sl@0
   103
sl@0
   104
	if (r != KErrNone)
sl@0
   105
		return r; 	
sl@0
   106
sl@0
   107
    return SetName(&KNanoWaitLddName);
sl@0
   108
    }
sl@0
   109
sl@0
   110
void DNanoWaitFactory::GetCaps(TDes8& aDes) const
sl@0
   111
//
sl@0
   112
// Get capabilities - overriding pure virtual
sl@0
   113
//
sl@0
   114
    {
sl@0
   115
    TCapsNanoWaitV01 b;
sl@0
   116
    b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   117
    Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
sl@0
   118
    }
sl@0
   119
sl@0
   120
/**
sl@0
   121
  Destructor
sl@0
   122
*/
sl@0
   123
DNanoWaitFactory::~DNanoWaitFactory()
sl@0
   124
	{
sl@0
   125
	if (gDfcQ)
sl@0
   126
		gDfcQ->Destroy();
sl@0
   127
	}
sl@0
   128
sl@0
   129
DNanoWait::DNanoWait()
sl@0
   130
//
sl@0
   131
// Constructor
sl@0
   132
//
sl@0
   133
    {
sl@0
   134
	iThread=&Kern::CurrentThread();
sl@0
   135
	iThread->Open();
sl@0
   136
    }
sl@0
   137
sl@0
   138
TInt DNanoWait::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
sl@0
   139
//
sl@0
   140
// Create channel
sl@0
   141
//
sl@0
   142
    {
sl@0
   143
sl@0
   144
    if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
sl@0
   145
    	return KErrNotSupported;
sl@0
   146
	SetDfcQ(gDfcQ);
sl@0
   147
	iMsgQ.Receive();
sl@0
   148
	return KErrNone;
sl@0
   149
	}
sl@0
   150
sl@0
   151
DNanoWait::~DNanoWait()
sl@0
   152
//
sl@0
   153
// Destructor
sl@0
   154
//
sl@0
   155
    {
sl@0
   156
	Kern::SafeClose((DObject*&)iThread, NULL);
sl@0
   157
    }
sl@0
   158
sl@0
   159
void DNanoWait::HandleMsg(TMessageBase* aMsg)
sl@0
   160
	{
sl@0
   161
	TInt r=KErrNone;
sl@0
   162
	TThreadMessage& m=*(TThreadMessage*)aMsg;
sl@0
   163
	TInt id=m.iValue;
sl@0
   164
	if (id==(TInt)ECloseMsg)
sl@0
   165
		{
sl@0
   166
		m.Complete(KErrNone,EFalse);
sl@0
   167
		iMsgQ.CompleteAll(KErrServerTerminated);
sl@0
   168
		return;
sl@0
   169
		}
sl@0
   170
	else
sl@0
   171
		{
sl@0
   172
		r=DoControl(id,m.Ptr0(),m.Ptr1());
sl@0
   173
		}
sl@0
   174
	m.Complete(r,ETrue);
sl@0
   175
	}
sl@0
   176
sl@0
   177
TInt DNanoWait::DoControl(TInt aFunction, TAny* a1, TAny* a2)
sl@0
   178
	{
sl@0
   179
	TInt r=KErrNone;
sl@0
   180
	TInt interval=(TInt)a2;
sl@0
   181
	switch (aFunction)
sl@0
   182
		{
sl@0
   183
		case RNanoWait::EControlStartNanoWait:
sl@0
   184
			{
sl@0
   185
			TInt loopCount=(TInt)a1;
sl@0
   186
			for( int loop = 0; loop < loopCount; loop++)
sl@0
   187
				{
sl@0
   188
				Kern::NanoWait(interval);	
sl@0
   189
				}
sl@0
   190
			break;
sl@0
   191
			}
sl@0
   192
		default:
sl@0
   193
			r=KErrNotSupported;
sl@0
   194
			break;
sl@0
   195
		}
sl@0
   196
	return r;
sl@0
   197
	}
sl@0
   198