os/kernelhwsrv/kerneltest/e32test/notifier/textnotifier.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) 2003-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\notifier\textnotifier1.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef V2_NOTIFIER
sl@0
    19
#endif
sl@0
    20
sl@0
    21
#include <twintnotifier.h>
sl@0
    22
#include "textnotifier.h"
sl@0
    23
sl@0
    24
#ifdef V2_NOTIFIER
sl@0
    25
sl@0
    26
#define KUidTestTextNotifier KUidTestTextNotifier2
sl@0
    27
#define KUidOtherTestTextNotifier KUidTestTextNotifier1
sl@0
    28
#define NOTIFIER_BASE MNotifierBase2
sl@0
    29
sl@0
    30
#else
sl@0
    31
sl@0
    32
#define KUidTestTextNotifier KUidTestTextNotifier1
sl@0
    33
#define KUidOtherTestTextNotifier KUidTestTextNotifier2
sl@0
    34
class MEikSrvNotifierBase : public MNotifierBase {};
sl@0
    35
#define NOTIFIER_BASE MEikSrvNotifierBase
sl@0
    36
sl@0
    37
#endif
sl@0
    38
sl@0
    39
sl@0
    40
// Give each notifers a different channel so they don't block each other
sl@0
    41
// (this is required for the MNotiferManager testing to be valid.)
sl@0
    42
#define KUidOutputChannel KUidTestTextNotifier
sl@0
    43
sl@0
    44
sl@0
    45
class CTestNotifier : public CBase, public NOTIFIER_BASE
sl@0
    46
	{
sl@0
    47
public:
sl@0
    48
	CTestNotifier(TNotifierPriority aPriority);
sl@0
    49
	virtual void Release();
sl@0
    50
	virtual TNotifierInfo RegisterL();
sl@0
    51
	virtual TNotifierInfo Info() const;
sl@0
    52
	virtual TPtrC8 StartL(const TDesC8& aBuffer);
sl@0
    53
#ifdef V2_NOTIFIER
sl@0
    54
	virtual void StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage);
sl@0
    55
#else
sl@0
    56
	virtual void StartL(const TDesC8& aBuffer, const TAny* aReturnVal, RMessage aMessage);
sl@0
    57
#endif
sl@0
    58
	virtual void Cancel();
sl@0
    59
	virtual TPtrC8 UpdateL(const TDesC8& aBuffer);
sl@0
    60
private:
sl@0
    61
	TBool iCancel;
sl@0
    62
	TBuf8<256> iResponse;
sl@0
    63
	TBool iNotifierManagerTested;
sl@0
    64
	TNotifierPriority iPriority;
sl@0
    65
	};
sl@0
    66
sl@0
    67
void CTestNotifier::Release()
sl@0
    68
	{
sl@0
    69
	delete this;
sl@0
    70
	}
sl@0
    71
sl@0
    72
CTestNotifier::CTestNotifier(TNotifierPriority aPriority)
sl@0
    73
	: iPriority(aPriority)
sl@0
    74
	{}
sl@0
    75
sl@0
    76
CTestNotifier::TNotifierInfo CTestNotifier::RegisterL()
sl@0
    77
	{
sl@0
    78
	CTestNotifier::TNotifierInfo info;
sl@0
    79
	info.iUid = KUidTestTextNotifier;
sl@0
    80
	info.iChannel = KUidOutputChannel;
sl@0
    81
	info.iPriority = iPriority;
sl@0
    82
	return info;
sl@0
    83
	}
sl@0
    84
sl@0
    85
sl@0
    86
CTestNotifier::TNotifierInfo CTestNotifier::Info() const
sl@0
    87
	{
sl@0
    88
	CTestNotifier::TNotifierInfo info;
sl@0
    89
	info.iUid = KUidTestTextNotifier;
sl@0
    90
	info.iChannel = KUidOutputChannel;
sl@0
    91
	info.iPriority = iPriority;
sl@0
    92
	return info;
sl@0
    93
	}
sl@0
    94
sl@0
    95
TPtrC8 CTestNotifier::StartL(const TDesC8& aBuffer)
sl@0
    96
	{
sl@0
    97
	iCancel = EFalse;
sl@0
    98
	if(aBuffer==KMNotifierManager)
sl@0
    99
		{
sl@0
   100
		iNotifierManagerTested = ETrue;
sl@0
   101
		iResponse.SetMax();
sl@0
   102
		iResponse.FillZ();
sl@0
   103
		iResponse.Zero();
sl@0
   104
		iManager->StartNotifierL(KUidOtherTestTextNotifier,KStartData,iResponse);
sl@0
   105
		return TPtrC8(iResponse);
sl@0
   106
		}
sl@0
   107
	if(aBuffer!=KStartData)
sl@0
   108
		User::Leave(KErrGeneral);
sl@0
   109
	return TPtrC8(KResponseData);
sl@0
   110
	}
sl@0
   111
sl@0
   112
#ifdef V2_NOTIFIER
sl@0
   113
void CTestNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
sl@0
   114
#else
sl@0
   115
void CTestNotifier::StartL(const TDesC8& aBuffer, const TAny* aReturnVal, RMessage aMessage)
sl@0
   116
#endif
sl@0
   117
	{
sl@0
   118
	TBool cancelled=iCancel;
sl@0
   119
	iCancel = EFalse;
sl@0
   120
	TInt r=KErrNone;
sl@0
   121
	if(aBuffer==KMNotifierManager || aBuffer==KMNotifierManagerWithCancelCheck)
sl@0
   122
		{
sl@0
   123
		iNotifierManagerTested = ETrue;
sl@0
   124
		iResponse.SetMax();
sl@0
   125
		iResponse.FillZ();
sl@0
   126
		iResponse.Zero();
sl@0
   127
		iManager->StartNotifierL(KUidOtherTestTextNotifier,KStartData,iResponse);
sl@0
   128
		if(aBuffer==KMNotifierManagerWithCancelCheck)
sl@0
   129
			r = cancelled ? KTestNotifierWasPreviouselyCanceled : KErrGeneral;
sl@0
   130
		}
sl@0
   131
	else if(aBuffer==KStartData)
sl@0
   132
		iResponse.Copy(KResponseData);
sl@0
   133
	else if(aBuffer==KHeapData)
sl@0
   134
		{
sl@0
   135
		iResponse.Zero();
sl@0
   136
		TInt allocSize;
sl@0
   137
		r=User::AllocSize(allocSize); 
sl@0
   138
		iResponse.Format(_L8("%d"),allocSize);
sl@0
   139
		}
sl@0
   140
	else if(aBuffer==KStartWithCancelCheckData)
sl@0
   141
		{
sl@0
   142
		iResponse.Copy(KResponseData);
sl@0
   143
		r = cancelled ? KTestNotifierWasPreviouselyCanceled : KErrGeneral;
sl@0
   144
		}
sl@0
   145
	else
sl@0
   146
		User::Leave(KErrGeneral);
sl@0
   147
#ifdef V2_NOTIFIER
sl@0
   148
	aMessage.WriteL(aReplySlot,iResponse);
sl@0
   149
#else
sl@0
   150
	aMessage.WriteL(aReturnVal,iResponse);
sl@0
   151
#endif
sl@0
   152
	aMessage.Complete(r);
sl@0
   153
	}
sl@0
   154
sl@0
   155
void CTestNotifier::Cancel()
sl@0
   156
	{
sl@0
   157
	if(iNotifierManagerTested)
sl@0
   158
		{
sl@0
   159
		iNotifierManagerTested = EFalse;
sl@0
   160
		iManager->CancelNotifier(KUidOtherTestTextNotifier);
sl@0
   161
		}
sl@0
   162
	iCancel = ETrue;
sl@0
   163
	}
sl@0
   164
sl@0
   165
TPtrC8 CTestNotifier::UpdateL(const TDesC8& aBuffer)
sl@0
   166
	{
sl@0
   167
	if(aBuffer==KMNotifierManager)
sl@0
   168
		{
sl@0
   169
		iNotifierManagerTested = ETrue;
sl@0
   170
		iManager->UpdateNotifierL(KUidOtherTestTextNotifier,KUpdateData,iResponse);
sl@0
   171
		}
sl@0
   172
	else if(aBuffer==KUpdateData)
sl@0
   173
		iResponse.Copy(KResponseData);
sl@0
   174
	else
sl@0
   175
		User::Invariant();
sl@0
   176
	return TPtrC8(iResponse);
sl@0
   177
	}
sl@0
   178
sl@0
   179
sl@0
   180
EXPORT_C CArrayPtr<NOTIFIER_BASE>* NotifierArray()
sl@0
   181
	{
sl@0
   182
    CArrayPtrFlat<NOTIFIER_BASE>* array = new (ELeave) CArrayPtrFlat<NOTIFIER_BASE>(2);
sl@0
   183
	CleanupStack::PushL(array);
sl@0
   184
    CTestNotifier* notifier = new (ELeave) CTestNotifier(NOTIFIER_BASE::ENotifierPriorityLow);
sl@0
   185
    CleanupStack::PushL(notifier);
sl@0
   186
    array->AppendL(notifier);
sl@0
   187
    CleanupStack::Pop(2,array);
sl@0
   188
    return array;
sl@0
   189
	}
sl@0
   190