diff -r 000000000000 -r 4e1aa6a622a0 accessoryservices/remotecontrolfw/common/utils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accessoryservices/remotecontrolfw/common/utils.h Tue Feb 02 00:53:00 2010 +0200 @@ -0,0 +1,165 @@ +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// Utilities for Rem Con server. +// +// + +/** + @file + @internalComponent +*/ + +#ifndef REMCONUTILS_H +#define REMCONUTILS_H + +#include +#include +#include +#include + +// In debug, using checking forms of CleanupStack::Pop. In release builds, +// use the non-checking form to save a little bit of ROM. +#ifdef _DEBUG +#define CLEANUPSTACK_POP1(a) CleanupStack::Pop(a); +#define CLEANUPSTACK_POP2(a, b) CleanupStack::Pop(a, b); +#else +#define CLEANUPSTACK_POP1(a) CleanupStack::Pop(); +#define CLEANUPSTACK_POP2(a, b) CleanupStack::Pop(2); +#endif // _DEBUG + +// Used for cleanup stack-based cleanup of RImplInfoPtrArrays. +void CleanupResetAndDestroyPushL(RImplInfoPtrArray& aArray); +// Used for cleanup stack-based cleanup of temporary heaps. +void CleanupSwitchHeapPushL(RHeap& aHeap); + + +template +class CleanupDeleteAndNull + { +public: + inline static void PushL(T*& aRef) {CleanupStack::PushL(TCleanupItem(&DeleteAndNull,&aRef));}; +private: + static void DeleteAndNull(TAny *aPtr) {T*& ptr = *static_cast(aPtr); delete ptr; ptr = NULL;}; + }; +template +inline void CleanupDeleteAndNullPushL(T*& aRef) + {CleanupDeleteAndNull::PushL(aRef);} + +template +class CleanupReset + { +public: + inline static void PushL(T& aRef) {CleanupStack::PushL(TCleanupItem(&Reset,&aRef));}; +private: + static void Reset(TAny *aPtr) {(static_cast(aPtr))->Reset();}; + }; +template +inline void CleanupResetPushL(T& aRef) + {CleanupReset::PushL(aRef);} + +template +class CleanupSignal + { +public: + inline static void PushL(T& aRef) {CleanupStack::PushL(TCleanupItem(&Signal,&aRef));}; +private: + static void Signal(TAny *aPtr) {(static_cast(aPtr))->Signal();}; + }; +template +inline void CleanupSignalPushL(T& aRef) + {CleanupSignal::PushL(aRef);} + +template +class CleanupNull + { +public: + inline static void PushL(T*& aRef) {CleanupStack::PushL(TCleanupItem(&Null,&aRef));}; +private: + static void Null(TAny *aPtr) {T*& ptr = *static_cast(aPtr); ptr = NULL;}; + }; +template +inline void CleanupNullPushL(T*& aRef) + {CleanupNull::PushL(aRef);} + + + +/** +A wrapper class around an RFastLock that enables locks to be nested. +*/ +NONSHARABLE_CLASS(RNestableLock) + { +public: + RNestableLock(); + TInt CreateLocal(); + void Close(); + + void Wait(); + void Signal(); + +private: + static const TUint32 KInvalidThreadId = ~0u; + +private: + RFastLock iLock; + RFastLock iMetaLock; + TThreadId iThreadId; + TInt iRefCount; + }; + + +class CSpecificThreadCallBackBody; + +NONSHARABLE_CLASS(RSpecificThreadCallBack) + { +public: + RSpecificThreadCallBack(); + + TInt Create(const TCallBack& aCallBack, TInt aPriority); + void Close(); + + TInt Start(); + TInt CallBack(); + void Cancel(); + +private: + CSpecificThreadCallBackBody* iBody; + }; + + +NONSHARABLE_CLASS(RCountSizeWriteStream) + : public RWriteStream + , public MStreamBuf + { +public: + using RWriteStream::Close; + RCountSizeWriteStream(); + TInt Size() const; + void Reset(); + +private: // MStreamBuf + void DoRelease(); + void DoSynchL(); + TInt DoReadL(TAny* aPtr,TInt aMaxLength); + TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus); + TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer); + void DoWriteL(const TAny* aPtr,TInt aLength); + TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus); + TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer); + TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset); + +private: + TInt iSize; + }; + +#endif // REMCONUTILS_H