1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/notifier/textnotifier.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,190 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\notifier\textnotifier1.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#ifndef V2_NOTIFIER
1.22 +#endif
1.23 +
1.24 +#include <twintnotifier.h>
1.25 +#include "textnotifier.h"
1.26 +
1.27 +#ifdef V2_NOTIFIER
1.28 +
1.29 +#define KUidTestTextNotifier KUidTestTextNotifier2
1.30 +#define KUidOtherTestTextNotifier KUidTestTextNotifier1
1.31 +#define NOTIFIER_BASE MNotifierBase2
1.32 +
1.33 +#else
1.34 +
1.35 +#define KUidTestTextNotifier KUidTestTextNotifier1
1.36 +#define KUidOtherTestTextNotifier KUidTestTextNotifier2
1.37 +class MEikSrvNotifierBase : public MNotifierBase {};
1.38 +#define NOTIFIER_BASE MEikSrvNotifierBase
1.39 +
1.40 +#endif
1.41 +
1.42 +
1.43 +// Give each notifers a different channel so they don't block each other
1.44 +// (this is required for the MNotiferManager testing to be valid.)
1.45 +#define KUidOutputChannel KUidTestTextNotifier
1.46 +
1.47 +
1.48 +class CTestNotifier : public CBase, public NOTIFIER_BASE
1.49 + {
1.50 +public:
1.51 + CTestNotifier(TNotifierPriority aPriority);
1.52 + virtual void Release();
1.53 + virtual TNotifierInfo RegisterL();
1.54 + virtual TNotifierInfo Info() const;
1.55 + virtual TPtrC8 StartL(const TDesC8& aBuffer);
1.56 +#ifdef V2_NOTIFIER
1.57 + virtual void StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage);
1.58 +#else
1.59 + virtual void StartL(const TDesC8& aBuffer, const TAny* aReturnVal, RMessage aMessage);
1.60 +#endif
1.61 + virtual void Cancel();
1.62 + virtual TPtrC8 UpdateL(const TDesC8& aBuffer);
1.63 +private:
1.64 + TBool iCancel;
1.65 + TBuf8<256> iResponse;
1.66 + TBool iNotifierManagerTested;
1.67 + TNotifierPriority iPriority;
1.68 + };
1.69 +
1.70 +void CTestNotifier::Release()
1.71 + {
1.72 + delete this;
1.73 + }
1.74 +
1.75 +CTestNotifier::CTestNotifier(TNotifierPriority aPriority)
1.76 + : iPriority(aPriority)
1.77 + {}
1.78 +
1.79 +CTestNotifier::TNotifierInfo CTestNotifier::RegisterL()
1.80 + {
1.81 + CTestNotifier::TNotifierInfo info;
1.82 + info.iUid = KUidTestTextNotifier;
1.83 + info.iChannel = KUidOutputChannel;
1.84 + info.iPriority = iPriority;
1.85 + return info;
1.86 + }
1.87 +
1.88 +
1.89 +CTestNotifier::TNotifierInfo CTestNotifier::Info() const
1.90 + {
1.91 + CTestNotifier::TNotifierInfo info;
1.92 + info.iUid = KUidTestTextNotifier;
1.93 + info.iChannel = KUidOutputChannel;
1.94 + info.iPriority = iPriority;
1.95 + return info;
1.96 + }
1.97 +
1.98 +TPtrC8 CTestNotifier::StartL(const TDesC8& aBuffer)
1.99 + {
1.100 + iCancel = EFalse;
1.101 + if(aBuffer==KMNotifierManager)
1.102 + {
1.103 + iNotifierManagerTested = ETrue;
1.104 + iResponse.SetMax();
1.105 + iResponse.FillZ();
1.106 + iResponse.Zero();
1.107 + iManager->StartNotifierL(KUidOtherTestTextNotifier,KStartData,iResponse);
1.108 + return TPtrC8(iResponse);
1.109 + }
1.110 + if(aBuffer!=KStartData)
1.111 + User::Leave(KErrGeneral);
1.112 + return TPtrC8(KResponseData);
1.113 + }
1.114 +
1.115 +#ifdef V2_NOTIFIER
1.116 +void CTestNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
1.117 +#else
1.118 +void CTestNotifier::StartL(const TDesC8& aBuffer, const TAny* aReturnVal, RMessage aMessage)
1.119 +#endif
1.120 + {
1.121 + TBool cancelled=iCancel;
1.122 + iCancel = EFalse;
1.123 + TInt r=KErrNone;
1.124 + if(aBuffer==KMNotifierManager || aBuffer==KMNotifierManagerWithCancelCheck)
1.125 + {
1.126 + iNotifierManagerTested = ETrue;
1.127 + iResponse.SetMax();
1.128 + iResponse.FillZ();
1.129 + iResponse.Zero();
1.130 + iManager->StartNotifierL(KUidOtherTestTextNotifier,KStartData,iResponse);
1.131 + if(aBuffer==KMNotifierManagerWithCancelCheck)
1.132 + r = cancelled ? KTestNotifierWasPreviouselyCanceled : KErrGeneral;
1.133 + }
1.134 + else if(aBuffer==KStartData)
1.135 + iResponse.Copy(KResponseData);
1.136 + else if(aBuffer==KHeapData)
1.137 + {
1.138 + iResponse.Zero();
1.139 + TInt allocSize;
1.140 + r=User::AllocSize(allocSize);
1.141 + iResponse.Format(_L8("%d"),allocSize);
1.142 + }
1.143 + else if(aBuffer==KStartWithCancelCheckData)
1.144 + {
1.145 + iResponse.Copy(KResponseData);
1.146 + r = cancelled ? KTestNotifierWasPreviouselyCanceled : KErrGeneral;
1.147 + }
1.148 + else
1.149 + User::Leave(KErrGeneral);
1.150 +#ifdef V2_NOTIFIER
1.151 + aMessage.WriteL(aReplySlot,iResponse);
1.152 +#else
1.153 + aMessage.WriteL(aReturnVal,iResponse);
1.154 +#endif
1.155 + aMessage.Complete(r);
1.156 + }
1.157 +
1.158 +void CTestNotifier::Cancel()
1.159 + {
1.160 + if(iNotifierManagerTested)
1.161 + {
1.162 + iNotifierManagerTested = EFalse;
1.163 + iManager->CancelNotifier(KUidOtherTestTextNotifier);
1.164 + }
1.165 + iCancel = ETrue;
1.166 + }
1.167 +
1.168 +TPtrC8 CTestNotifier::UpdateL(const TDesC8& aBuffer)
1.169 + {
1.170 + if(aBuffer==KMNotifierManager)
1.171 + {
1.172 + iNotifierManagerTested = ETrue;
1.173 + iManager->UpdateNotifierL(KUidOtherTestTextNotifier,KUpdateData,iResponse);
1.174 + }
1.175 + else if(aBuffer==KUpdateData)
1.176 + iResponse.Copy(KResponseData);
1.177 + else
1.178 + User::Invariant();
1.179 + return TPtrC8(iResponse);
1.180 + }
1.181 +
1.182 +
1.183 +EXPORT_C CArrayPtr<NOTIFIER_BASE>* NotifierArray()
1.184 + {
1.185 + CArrayPtrFlat<NOTIFIER_BASE>* array = new (ELeave) CArrayPtrFlat<NOTIFIER_BASE>(2);
1.186 + CleanupStack::PushL(array);
1.187 + CTestNotifier* notifier = new (ELeave) CTestNotifier(NOTIFIER_BASE::ENotifierPriorityLow);
1.188 + CleanupStack::PushL(notifier);
1.189 + array->AppendL(notifier);
1.190 + CleanupStack::Pop(2,array);
1.191 + return array;
1.192 + }
1.193 +