genericopenlibs/posixrealtimeextensions/inc/timermessage.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2008-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 // timer message header file
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 #ifndef  __TIMERMESSAGE__H
       
    20 #define  __TIMERMESSAGE__H
       
    21 
       
    22 #include <e32des8.h>
       
    23 const TInt KTimerMsgMaxLen = 12;
       
    24 
       
    25 //encapsulates the timer request message.
       
    26 class TRtTimerMsg
       
    27 {
       
    28 public:
       
    29 	TRtTimerMsg(const TInt& aTimerId, const TInt& aAction = 0): iTimerId(aTimerId), iRqstAct(aAction){}
       
    30 	TRtTimerMsg(){}
       
    31 	inline TInt Serialize(TDes8& aTo) const; 
       
    32 	inline TInt DeSerialize(const TDes8& aFrom);
       
    33 
       
    34 	enum 
       
    35 		{
       
    36 		EDELETETIMER = 2,	
       
    37 		}TRqstAction;
       
    38 		
       
    39 	TInt 				iTimerId;	// timer id
       
    40 	TInt				iRqstAct;
       
    41 };
       
    42 
       
    43 //serialize the timer request. 
       
    44 TInt TRtTimerMsg::Serialize(TDes8& aTo) const
       
    45 	{
       
    46 	TInt lRet = KErrNone;
       
    47 	if(aTo.MaxSize() != KTimerMsgMaxLen)
       
    48 		lRet = KErrArgument;	
       
    49 	else
       
    50 		{
       
    51 		TUint8	lBuf[KTimerMsgMaxLen];		
       
    52 		Mem::FillZ(&lBuf[0], KTimerMsgMaxLen);
       
    53 		
       
    54 		Mem::Copy(&lBuf[0], &iTimerId, sizeof(TInt));
       
    55 		Mem::Copy(&lBuf[sizeof (TInt)], &iRqstAct, sizeof(TInt));
       
    56 			
       
    57 		aTo.Zero();
       
    58 		aTo.Append(lBuf,KTimerMsgMaxLen);
       
    59 		}	
       
    60 		
       
    61 	return lRet;		
       
    62 	}
       
    63 
       
    64 //deserialize the timer request.
       
    65 TInt TRtTimerMsg::DeSerialize(const TDes8& aFrom)
       
    66 	{
       
    67 	TInt lRet = KErrNone;
       
    68 	if(aFrom.MaxSize() != KTimerMsgMaxLen)
       
    69 		lRet = KErrArgument;
       
    70 	else
       
    71 		{
       
    72 		const TUint8* lBuf = aFrom.Ptr();	
       
    73 		Mem::Copy(&iTimerId, &lBuf[0], sizeof(TInt));
       
    74 		Mem::Copy(&iRqstAct, &lBuf[sizeof (TInt)], sizeof(TInt));
       
    75 		}
       
    76 
       
    77 	return lRet;		
       
    78 	}
       
    79 	
       
    80 #endif // __TIMERMESSAGE__H
       
    81