First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\notifier\textnotifier1.cpp
21 #include <twintnotifier.h>
22 #include "textnotifier.h"
26 #define KUidTestTextNotifier KUidTestTextNotifier2
27 #define KUidOtherTestTextNotifier KUidTestTextNotifier1
28 #define NOTIFIER_BASE MNotifierBase2
32 #define KUidTestTextNotifier KUidTestTextNotifier1
33 #define KUidOtherTestTextNotifier KUidTestTextNotifier2
34 class MEikSrvNotifierBase : public MNotifierBase {};
35 #define NOTIFIER_BASE MEikSrvNotifierBase
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
45 class CTestNotifier : public CBase, public NOTIFIER_BASE
48 CTestNotifier(TNotifierPriority aPriority);
49 virtual void Release();
50 virtual TNotifierInfo RegisterL();
51 virtual TNotifierInfo Info() const;
52 virtual TPtrC8 StartL(const TDesC8& aBuffer);
54 virtual void StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage);
56 virtual void StartL(const TDesC8& aBuffer, const TAny* aReturnVal, RMessage aMessage);
58 virtual void Cancel();
59 virtual TPtrC8 UpdateL(const TDesC8& aBuffer);
63 TBool iNotifierManagerTested;
64 TNotifierPriority iPriority;
67 void CTestNotifier::Release()
72 CTestNotifier::CTestNotifier(TNotifierPriority aPriority)
73 : iPriority(aPriority)
76 CTestNotifier::TNotifierInfo CTestNotifier::RegisterL()
78 CTestNotifier::TNotifierInfo info;
79 info.iUid = KUidTestTextNotifier;
80 info.iChannel = KUidOutputChannel;
81 info.iPriority = iPriority;
86 CTestNotifier::TNotifierInfo CTestNotifier::Info() const
88 CTestNotifier::TNotifierInfo info;
89 info.iUid = KUidTestTextNotifier;
90 info.iChannel = KUidOutputChannel;
91 info.iPriority = iPriority;
95 TPtrC8 CTestNotifier::StartL(const TDesC8& aBuffer)
98 if(aBuffer==KMNotifierManager)
100 iNotifierManagerTested = ETrue;
104 iManager->StartNotifierL(KUidOtherTestTextNotifier,KStartData,iResponse);
105 return TPtrC8(iResponse);
107 if(aBuffer!=KStartData)
108 User::Leave(KErrGeneral);
109 return TPtrC8(KResponseData);
113 void CTestNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
115 void CTestNotifier::StartL(const TDesC8& aBuffer, const TAny* aReturnVal, RMessage aMessage)
118 TBool cancelled=iCancel;
121 if(aBuffer==KMNotifierManager || aBuffer==KMNotifierManagerWithCancelCheck)
123 iNotifierManagerTested = ETrue;
127 iManager->StartNotifierL(KUidOtherTestTextNotifier,KStartData,iResponse);
128 if(aBuffer==KMNotifierManagerWithCancelCheck)
129 r = cancelled ? KTestNotifierWasPreviouselyCanceled : KErrGeneral;
131 else if(aBuffer==KStartData)
132 iResponse.Copy(KResponseData);
133 else if(aBuffer==KHeapData)
137 r=User::AllocSize(allocSize);
138 iResponse.Format(_L8("%d"),allocSize);
140 else if(aBuffer==KStartWithCancelCheckData)
142 iResponse.Copy(KResponseData);
143 r = cancelled ? KTestNotifierWasPreviouselyCanceled : KErrGeneral;
146 User::Leave(KErrGeneral);
148 aMessage.WriteL(aReplySlot,iResponse);
150 aMessage.WriteL(aReturnVal,iResponse);
152 aMessage.Complete(r);
155 void CTestNotifier::Cancel()
157 if(iNotifierManagerTested)
159 iNotifierManagerTested = EFalse;
160 iManager->CancelNotifier(KUidOtherTestTextNotifier);
165 TPtrC8 CTestNotifier::UpdateL(const TDesC8& aBuffer)
167 if(aBuffer==KMNotifierManager)
169 iNotifierManagerTested = ETrue;
170 iManager->UpdateNotifierL(KUidOtherTestTextNotifier,KUpdateData,iResponse);
172 else if(aBuffer==KUpdateData)
173 iResponse.Copy(KResponseData);
176 return TPtrC8(iResponse);
180 EXPORT_C CArrayPtr<NOTIFIER_BASE>* NotifierArray()
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);