genericopenlibs/posixrealtimeextensions/inc/timerhandler.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 31 Aug 2010 16:54:36 +0300
branchRCL_3
changeset 56 acd3cd4aaceb
parent 0 e4d67989cc36
permissions -rw-r--r--
Revision: 201021 Kit: 201035

// Copyright (c) 2008-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:
// timer handler header file
// 
//


#ifndef __TIMERHANDLER__H
#define __TIMERHANDLER__H

#include "timer.h"
#include "timerserver.h"
#include "timerclient.h"

#define MAXTIMERLIMIT 512
#define DELAYTIMER_MAX 32

class CTimerReqHandler: public CBase
{
public:	
	friend class CTimerServer;
	friend class CLibRtTimer;
	TInt CreateTimer(TInt& aTimerId, struct sigevent *aSig);
	TInt RemoveTimer(const TInt& aTimerId);	
	TInt Time(const TInt& aTimerId, struct itimerspec *aTime);
	TInt SetTime(const TInt& aTimerId, TInt aFlag, const struct itimerspec *aIpTime,
			 struct itimerspec *aOpTime);	
	TInt OverrunCount(const TInt& aTimerId, TInt& aOverrunCount);
	TInt TimerRequestHandler();
	
	CTimerReqHandler();	 						   							   
	~CTimerReqHandler();
	RTimerSession session;
	inline void SetServerHandle(RServer2 aServer)
		{
		iServer = aServer;
		}
	RServer2 iServer;
	inline void ResetClientFlag()
	    {
	    session.ResetConnectionFlag();
	    }
	inline void ResetServerFlag()
		{
		iServConnectLock.Wait();
		iIsServStarted = EFalse;
		iServConnectLock.Signal();
		}
private:
	TInt Connect();
	CRtTimer* FindTimer(const TInt& aTimerId);
	TInt StartTimerServer();

	const static TInt KTimersGran = 4;			 						   
	CArrayPtrSeg<CRtTimer> iTimers;
	RMutex iTimersLock;	
	
	RThread	iServ; //timer server thread

	TBool 	iIsServStarted;
	RMutex 	iServConnectLock;
	RSemaphore iTimerSemaphore;
};

CTimerReqHandler* getTimerHandler();

#endif //__TIMERHANDLER__H