os/ossrv/genericopenlibs/openenvcore/backend/inc/tsignalmessage.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/backend/inc/tsignalmessage.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,188 @@
     1.4 +// Copyright (c) 2008-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 "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 +// Signal data structure that supports marshalling
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32base.h>
    1.22 +
    1.23 +#ifndef TSIGNALMESSAGE_H
    1.24 +#define TSIGNALMESSAGE_H
    1.25 +
    1.26 +const TInt KSigMsgLength = 32;
    1.27 +const TUint8 KSigMsgVersion = 1;
    1.28 +
    1.29 +/*
    1.30 +@internalComponent
    1.31 +*/
    1.32 +class TSignalMessage
    1.33 +	{
    1.34 +public:
    1.35 +	TUint8	mType;
    1.36 +	union
    1.37 +		{
    1.38 +		struct
    1.39 +			{
    1.40 +			TUint8	mSignal;
    1.41 +			TUint32	mValue;
    1.42 +			} mSigVal;
    1.43 +		struct
    1.44 +			{
    1.45 +			TUint8 	mSignal;	
    1.46 +			TInt32	mTimerId;
    1.47 +			} mRtSignal;
    1.48 +		TUint8 	mSignal;		
    1.49 +		TUint32 mTimeOut;
    1.50 +		TUint32 mData;
    1.51 +		TUint64	mPid;
    1.52 +		};
    1.53 +
    1.54 +	enum {
    1.55 +		ESignal = 0,
    1.56 +		ESignalValuePair,
    1.57 +		EAlarmRegistration,
    1.58 +		EDequeueSignal,
    1.59 +		EWaitOnChild,
    1.60 +		ERtTimerSignal,
    1.61 +	} TSignalMessageType;
    1.62 +
    1.63 +	virtual ~TSignalMessage() {}
    1.64 +
    1.65 +	static TBool SignalMatchBySigNum(const TSignalMessage& aMsg1, const TSignalMessage& aMsg2)
    1.66 +		{
    1.67 +		if(aMsg1.mType != ESignal || aMsg2.mType != ESignal)
    1.68 +			return EFalse;
    1.69 +
    1.70 +		if (aMsg1.mSignal == aMsg2.mSignal)
    1.71 +			{
    1.72 +			return ETrue;
    1.73 +			}
    1.74 +		return EFalse;
    1.75 +		}
    1.76 +
    1.77 +	static TBool SigValMatchBySigNum(const TSignalMessage& aMsg1, const TSignalMessage& aMsg2)
    1.78 +		{
    1.79 +		if(aMsg1.mType != ESignalValuePair || aMsg2.mType != ESignalValuePair)
    1.80 +			return EFalse;
    1.81 +
    1.82 +		if (aMsg1.mSigVal.mSignal == aMsg2.mSigVal.mSignal)
    1.83 +			{
    1.84 +			return ETrue;
    1.85 +			}
    1.86 +		return EFalse;
    1.87 +		}
    1.88 +
    1.89 +	inline TInt Marshall(TDes8& aBuffer)
    1.90 +		{
    1.91 +		TUint8	lBufPtr[KSigMsgLength] = {0};
    1.92 +
    1.93 +		if(aBuffer.MaxSize() != KSigMsgLength)
    1.94 +			return KErrArgument;
    1.95 +
    1.96 +		lBufPtr[0] = KSigMsgVersion;
    1.97 +		lBufPtr[1] = mType;
    1.98 +
    1.99 +		switch(mType)
   1.100 +			{
   1.101 +			case ESignal:
   1.102 +				lBufPtr[2] = mSignal;
   1.103 +				break;
   1.104 +			case ESignalValuePair:
   1.105 +				lBufPtr[2] = mSigVal.mSignal;
   1.106 +
   1.107 +				lBufPtr[3] = (TUint8)(mSigVal.mValue & 0x000000FF);
   1.108 +				lBufPtr[4] = (TUint8)((mSigVal.mValue & 0x0000FF00) >> 8);
   1.109 +				lBufPtr[5] = (TUint8)((mSigVal.mValue & 0x00FF0000) >> 16);
   1.110 +				lBufPtr[6] = (TUint8)((mSigVal.mValue & 0xFF000000) >> 24);
   1.111 +				break;
   1.112 +			case EAlarmRegistration:
   1.113 +				lBufPtr[2] = (TUint8)(mTimeOut & 0x000000FF);
   1.114 +				lBufPtr[3] = (TUint8)((mTimeOut & 0x0000FF00) >> 8);
   1.115 +				lBufPtr[4] = (TUint8)((mTimeOut & 0x00FF0000) >> 16);
   1.116 +				lBufPtr[5] = (TUint8)((mTimeOut & 0xFF000000) >> 24);
   1.117 +				break;
   1.118 +			case EDequeueSignal:
   1.119 +				lBufPtr[2] = mSignal;
   1.120 +				break;
   1.121 +			case EWaitOnChild:
   1.122 +				memcpy(&lBufPtr[2],&mPid,sizeof(mPid));
   1.123 +				break;
   1.124 +			case ERtTimerSignal:
   1.125 +				Mem::Copy(&lBufPtr[2], &mRtSignal.mSignal, sizeof(mRtSignal.mSignal));
   1.126 +				Mem::Copy(&lBufPtr[2+sizeof(mRtSignal.mSignal)], &mRtSignal.mTimerId, sizeof(mRtSignal.mTimerId));
   1.127 +				break;
   1.128 +			default:
   1.129 +				// do nothing
   1.130 +				return KErrGeneral;
   1.131 +				break;
   1.132 +			}
   1.133 +		aBuffer.Zero();
   1.134 +		aBuffer.Append(lBufPtr,KSigMsgLength);
   1.135 +		return KErrNone;
   1.136 +		}
   1.137 +
   1.138 +	inline TInt Unmarshall(TDes8& aBuffer)
   1.139 +		{
   1.140 +		const TUint8* lBufPtr = aBuffer.Ptr();
   1.141 +
   1.142 +		if(aBuffer.MaxSize() != KSigMsgLength)
   1.143 +			return KErrArgument;
   1.144 +
   1.145 +		if(lBufPtr[0] != KSigMsgVersion)
   1.146 +			return KErrGeneral;
   1.147 +
   1.148 +		mType = lBufPtr[1];
   1.149 +
   1.150 +		switch(mType)
   1.151 +			{
   1.152 +			case ESignal:
   1.153 +				mSignal = lBufPtr[2];
   1.154 +				break;
   1.155 +			case ESignalValuePair:
   1.156 +				mSigVal.mSignal = lBufPtr[2];
   1.157 +				mSigVal.mValue = 0;
   1.158 +				mSigVal.mValue |= (TUint32)lBufPtr[3];
   1.159 +				mSigVal.mValue |= (((TUint32)lBufPtr[4]) << 8);
   1.160 +				mSigVal.mValue |= (((TUint32)lBufPtr[5]) << 16);
   1.161 +				mSigVal.mValue |= (((TUint32)lBufPtr[6]) << 24);
   1.162 +				break;
   1.163 +			case EAlarmRegistration:
   1.164 +				mTimeOut = 0;
   1.165 +				mTimeOut |= (TUint32)lBufPtr[2];
   1.166 +				mTimeOut |= (((TUint32)lBufPtr[3]) << 8);
   1.167 +				mTimeOut |= (((TUint32)lBufPtr[4]) << 16);
   1.168 +				mTimeOut |= (((TUint32)lBufPtr[5]) << 24);
   1.169 +				break;
   1.170 +			case EDequeueSignal:
   1.171 +				mSignal = lBufPtr[2];
   1.172 +				break;
   1.173 +			case EWaitOnChild:
   1.174 +				mPid = 0;
   1.175 +				memcpy(&mPid,&lBufPtr[2],sizeof(mPid));
   1.176 +				break;
   1.177 +			case ERtTimerSignal:
   1.178 +				Mem::Copy(&mRtSignal.mSignal, &lBufPtr[2], sizeof(mRtSignal.mSignal));
   1.179 +				Mem::Copy(&mRtSignal.mTimerId,&lBufPtr[2+sizeof(mRtSignal.mSignal)], sizeof(mRtSignal.mTimerId));
   1.180 +				break;
   1.181 +			default:
   1.182 +				// do nothing
   1.183 +				return KErrGeneral;
   1.184 +				break;
   1.185 +			}
   1.186 +
   1.187 +		return KErrNone;
   1.188 +		}
   1.189 +	};
   1.190 +
   1.191 +#endif // TSIGNALMESSAGE_H