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