os/ossrv/genericopenlibs/posixrealtimeextensions/src/timer_funcs.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/posixrealtimeextensions/src/timer_funcs.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,116 @@
     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 +// Name        : timer_funcs.cpp
    1.18 +// Part of     : librt-timer specific cpp file
    1.19 +// This is a project specific source file for building the 
    1.20 +// timer related functions as part of librt library.
    1.21 +// 
    1.22 +//
    1.23 +
    1.24 +#include <signal.h>
    1.25 +#include <time.h>
    1.26 +#include <errno.h>
    1.27 +
    1.28 +#include "lposix.h"
    1.29 +#include "timerhandler.h"
    1.30 +
    1.31 +const TInt KErrWouldBlock=-1000;
    1.32 +
    1.33 +extern "C" {
    1.34 +
    1.35 +/* Create new per-process timer using CLOCK_ID.  */
    1.36 +EXPORT_C int timer_create (clockid_t __clock_id,
    1.37 +                         struct sigevent *__restrict __evp,
    1.38 +                         timer_t *__restrict __timerid)
    1.39 +	{
    1.40 +	if(__timerid == NULL)
    1.41 +		{
    1.42 +		errno = EFAULT;	
    1.43 +		return -1;
    1.44 +		}
    1.45 +		
    1.46 +	if(__clock_id != CLOCK_REALTIME)
    1.47 +		{
    1.48 +		errno = EINVAL;	
    1.49 +		return -1;
    1.50 +		}
    1.51 +		
    1.52 +	int err = getTimerHandler()->CreateTimer(*__timerid, __evp);
    1.53 +	 
    1.54 +	if (err == KErrWouldBlock)
    1.55 +		{
    1.56 +		return MapError(EAGAIN, errno);
    1.57 +		}
    1.58 +	
    1.59 +	return MapError(err, errno);
    1.60 +	}
    1.61 +
    1.62 +
    1.63 +/* Delete timer TIMERID.  */
    1.64 +EXPORT_C int timer_delete (timer_t __timerid)
    1.65 +	{
    1.66 +	return MapError(getTimerHandler()->RemoveTimer(__timerid),errno);
    1.67 +	}
    1.68 +
    1.69 +
    1.70 +
    1.71 +/* Set timer TIMERID to VALUE, returning old value in OVLAUE.  */
    1.72 +EXPORT_C int timer_settime (timer_t __timerid, int __flags,
    1.73 +                          const struct itimerspec *__restrict __value,
    1.74 +                          struct itimerspec *__restrict __ovalue)
    1.75 +	{
    1.76 +	return MapError(getTimerHandler()->SetTime(__timerid, __flags, __value, __ovalue),errno);
    1.77 +	}
    1.78 +
    1.79 +/* Get current value of timer TIMERID and store it in VLAUE.  */
    1.80 +EXPORT_C int timer_gettime (timer_t __timerid, struct itimerspec *__value)
    1.81 +	{
    1.82 +	if(__value == NULL)
    1.83 +		{
    1.84 +		errno = EFAULT;	
    1.85 +		return -1;
    1.86 +		}
    1.87 +		
    1.88 +	return MapError(getTimerHandler()->Time(__timerid, __value),errno);
    1.89 +	}
    1.90 +
    1.91 +/* Get expiration overrun for timer TIMERID.  */
    1.92 +EXPORT_C int timer_getoverrun (timer_t __timerid)
    1.93 +	{
    1.94 +		
    1.95 +#if (!defined SYMBIAN_OE_POSIX_SIGNALS || !defined SYMBIAN_OE_LIBRT)
    1.96 +	__timerid = __timerid;//warning fix	
    1.97 +	errno = ENOSYS;
    1.98 +	return -1;
    1.99 +#else
   1.100 +	int overrun = 0;
   1.101 +	int lerr = MapError(getTimerHandler()->OverrunCount(__timerid, overrun),errno); 	
   1.102 +	if(lerr == -1 && errno == EINVAL)
   1.103 +		{
   1.104 +		return lerr;	
   1.105 +		}
   1.106 +	else
   1.107 +		{
   1.108 +		overrun = (overrun <= 1) ? 0 : (overrun-1);
   1.109 +		}
   1.110 + 	
   1.111 +	return overrun;
   1.112 +#endif		
   1.113 +	}
   1.114 +
   1.115 +} // extern "C"
   1.116 +
   1.117 +//EOF
   1.118 +
   1.119 +