accessoryservices/remotecontrolfw/common/utils.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2004-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 "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 // Utilities for Rem Con server.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef REMCONUTILS_H
       
    24 #define REMCONUTILS_H
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <ecom/ecom.h>
       
    28 #include <s32strm.h>
       
    29 #include <s32buf.h>
       
    30 
       
    31 // In debug, using checking forms of CleanupStack::Pop. In release builds, 
       
    32 // use the non-checking form to save a little bit of ROM.
       
    33 #ifdef _DEBUG
       
    34 #define CLEANUPSTACK_POP1(a)		CleanupStack::Pop(a);
       
    35 #define CLEANUPSTACK_POP2(a, b) 	CleanupStack::Pop(a, b);
       
    36 #else
       
    37 #define CLEANUPSTACK_POP1(a)		CleanupStack::Pop();
       
    38 #define CLEANUPSTACK_POP2(a, b) 	CleanupStack::Pop(2);
       
    39 #endif // _DEBUG
       
    40 
       
    41 // Used for cleanup stack-based cleanup of RImplInfoPtrArrays.
       
    42 void CleanupResetAndDestroyPushL(RImplInfoPtrArray& aArray);
       
    43 // Used for cleanup stack-based cleanup of temporary heaps.
       
    44 void CleanupSwitchHeapPushL(RHeap& aHeap);
       
    45 
       
    46 
       
    47 template <class T>
       
    48 class CleanupDeleteAndNull
       
    49 	{
       
    50 public:
       
    51 	inline static void PushL(T*& aRef) {CleanupStack::PushL(TCleanupItem(&DeleteAndNull,&aRef));};
       
    52 private:
       
    53 	static void DeleteAndNull(TAny *aPtr) {T*& ptr = *static_cast<T**>(aPtr); delete ptr; ptr = NULL;};
       
    54 	};
       
    55 template <class T>
       
    56 inline void CleanupDeleteAndNullPushL(T*& aRef)
       
    57 	{CleanupDeleteAndNull<T>::PushL(aRef);}
       
    58 
       
    59 template <class T>
       
    60 class CleanupReset
       
    61 	{
       
    62 public:
       
    63 	inline static void PushL(T& aRef) {CleanupStack::PushL(TCleanupItem(&Reset,&aRef));};
       
    64 private:
       
    65 	static void Reset(TAny *aPtr) {(static_cast<T*>(aPtr))->Reset();};
       
    66 	};
       
    67 template <class T>
       
    68 inline void CleanupResetPushL(T& aRef)
       
    69 	{CleanupReset<T>::PushL(aRef);}
       
    70 
       
    71 template <class T>
       
    72 class CleanupSignal
       
    73 	{
       
    74 public:
       
    75 	inline static void PushL(T& aRef) {CleanupStack::PushL(TCleanupItem(&Signal,&aRef));};
       
    76 private:
       
    77 	static void Signal(TAny *aPtr) {(static_cast<T*>(aPtr))->Signal();};
       
    78 	};
       
    79 template <class T>
       
    80 inline void CleanupSignalPushL(T& aRef)
       
    81 	{CleanupSignal<T>::PushL(aRef);}
       
    82 
       
    83 template <class T>
       
    84 class CleanupNull
       
    85 	{
       
    86 public:
       
    87 	inline static void PushL(T*& aRef) {CleanupStack::PushL(TCleanupItem(&Null,&aRef));};
       
    88 private:
       
    89 	static void Null(TAny *aPtr) {T*& ptr = *static_cast<T**>(aPtr); ptr = NULL;};
       
    90 	};
       
    91 template <class T>
       
    92 inline void CleanupNullPushL(T*& aRef)
       
    93 	{CleanupNull<T>::PushL(aRef);}
       
    94 
       
    95 
       
    96 
       
    97 /**
       
    98 A wrapper class around an RFastLock that enables locks to be nested.
       
    99 */
       
   100 NONSHARABLE_CLASS(RNestableLock)
       
   101 	{
       
   102 public:
       
   103 	RNestableLock();
       
   104 	TInt CreateLocal();
       
   105 	void Close();
       
   106 	
       
   107 	void Wait();
       
   108 	void Signal();
       
   109 	
       
   110 private:
       
   111 	static const TUint32 KInvalidThreadId = ~0u;
       
   112 	
       
   113 private:
       
   114 	RFastLock	iLock;
       
   115 	RFastLock	iMetaLock;
       
   116 	TThreadId	iThreadId;
       
   117 	TInt		iRefCount;
       
   118 	};
       
   119 
       
   120 
       
   121 class CSpecificThreadCallBackBody;
       
   122 
       
   123 NONSHARABLE_CLASS(RSpecificThreadCallBack)
       
   124 	{
       
   125 public:
       
   126 	RSpecificThreadCallBack();
       
   127 	
       
   128 	TInt Create(const TCallBack& aCallBack, TInt aPriority);
       
   129 	void Close();
       
   130 	
       
   131 	TInt Start();
       
   132 	TInt CallBack();
       
   133 	void Cancel();
       
   134 	
       
   135 private:
       
   136 	CSpecificThreadCallBackBody*	iBody;
       
   137 	};
       
   138 
       
   139 
       
   140 NONSHARABLE_CLASS(RCountSizeWriteStream)
       
   141 	: public RWriteStream
       
   142 	, public MStreamBuf
       
   143 	{
       
   144 public:
       
   145 	using RWriteStream::Close;
       
   146 	RCountSizeWriteStream();
       
   147 	TInt Size() const;
       
   148 	void Reset();
       
   149 
       
   150 private: // MStreamBuf
       
   151 	void DoRelease();
       
   152 	void DoSynchL();
       
   153 	TInt DoReadL(TAny* aPtr,TInt aMaxLength);
       
   154 	TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
       
   155 	TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer);
       
   156 	void DoWriteL(const TAny* aPtr,TInt aLength);
       
   157 	TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
       
   158 	TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer);
       
   159 	TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
       
   160 	
       
   161 private:
       
   162 	TInt iSize;
       
   163 	};
       
   164 
       
   165 #endif // REMCONUTILS_H