Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
15 // Part of : librt-timer specific cpp file
16 // This is a project specific source file for building the
17 // timer related functions as part of librt library.
25 #include "timerhandler.h"
26 #include "timermessage.h"
28 #define BOUNDARY_CHECK(rqtp) ((rqtp.tv_nsec != 0 && rqtp.tv_nsec < 1000) || \
29 rqtp.tv_nsec >= 1000000000L )\
32 static TInt64 seed = 0xdeadbeef;
33 CRtTimer::CRtTimer(struct sigevent *aSig)
36 iTimerId = Math::Rand (seed);
40 iSigEvent.sigev_notify = SIGEV_SIGNAL;
41 iSigEvent.sigev_signo = SIGALRM;
54 //should be called in context of the timer server thread.
62 CRtTimer* CRtTimer::New(struct sigevent *aSig)
64 return new CRtTimer(aSig);
67 //sets the timer for the given value
68 TInt CRtTimer::SetTime(TInt aFlag, const struct itimerspec *aIpTime,
69 struct itimerspec *aOpTime)
71 //Check for boundary values of seconds and microseconds
72 if (aIpTime == NULL || ((BOUNDARY_CHECK(aIpTime->it_value) || BOUNDARY_CHECK(aIpTime->it_interval)) &&
73 (aIpTime->it_value.tv_sec != 0 || aIpTime->it_value.tv_nsec != 0)) )
78 if(aIpTime->it_value.tv_sec == 0 && aIpTime->it_value.tv_nsec == 0)
83 iIsTimerReset = ETrue;
86 //load the time to expiration in the output timer value.
92 //start setting the timer value...
93 clock_gettime(CLOCK_REALTIME, &iStartTime.it_value);
95 iStartTime.it_interval = aIpTime->it_interval;
96 iEndTime = aIpTime->it_value;
98 if((aFlag & TIMER_ABSTIME) == 0) // relative timer
100 iEndTime.tv_sec+=iStartTime.it_value.tv_sec;
101 iEndTime.tv_nsec+=iStartTime.it_value.tv_nsec;
103 getTimerHandler()->session.OnDemandConnect(getTimerHandler()->iServer);
104 TInt lRet = getTimerHandler()->session.SetTime(iTimerId);
108 //gets the time to expiry.
109 TInt CRtTimer::Time(struct itimerspec *aTime) const
118 memset(aTime, 0, sizeof(struct itimerspec));
122 struct timespec clktime;
123 clock_gettime(CLOCK_REALTIME, &clktime);
125 aTime->it_value.tv_sec = iEndTime.tv_sec - clktime.tv_sec;
126 aTime->it_value.tv_nsec = iEndTime.tv_nsec - clktime.tv_nsec;
127 aTime->it_interval = iStartTime.it_interval;
133 //gets the overruns for this timer
134 TInt CRtTimer::OverrunCount(TInt& aOverrunCount) const
136 #if (!defined SYMBIAN_OE_POSIX_SIGNALS || !defined SYMBIAN_OE_LIBRT)
137 aOverrunCount = aOverrunCount;//warning fix
138 return KErrNotSupported;
141 aOverrunCount = Backend()->Overrun(iTimerId);
142 if(aOverrunCount >= DELAYTIMER_MAX)
143 aOverrunCount = DELAYTIMER_MAX;