genericopenlibs/posixrealtimeextensions/src/timer_funcs.cpp
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 // Name        : timer_funcs.cpp
       
    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.
       
    18 // 
       
    19 //
       
    20 
       
    21 #include <signal.h>
       
    22 #include <time.h>
       
    23 #include <errno.h>
       
    24 
       
    25 #include "lposix.h"
       
    26 #include "timerhandler.h"
       
    27 
       
    28 const TInt KErrWouldBlock=-1000;
       
    29 
       
    30 extern "C" {
       
    31 
       
    32 /* Create new per-process timer using CLOCK_ID.  */
       
    33 EXPORT_C int timer_create (clockid_t __clock_id,
       
    34                          struct sigevent *__restrict __evp,
       
    35                          timer_t *__restrict __timerid)
       
    36 	{
       
    37 	if(__timerid == NULL)
       
    38 		{
       
    39 		errno = EFAULT;	
       
    40 		return -1;
       
    41 		}
       
    42 		
       
    43 	if(__clock_id != CLOCK_REALTIME)
       
    44 		{
       
    45 		errno = EINVAL;	
       
    46 		return -1;
       
    47 		}
       
    48 		
       
    49 	int err = getTimerHandler()->CreateTimer(*__timerid, __evp);
       
    50 	 
       
    51 	if (err == KErrWouldBlock)
       
    52 		{
       
    53 		return MapError(EAGAIN, errno);
       
    54 		}
       
    55 	
       
    56 	return MapError(err, errno);
       
    57 	}
       
    58 
       
    59 
       
    60 /* Delete timer TIMERID.  */
       
    61 EXPORT_C int timer_delete (timer_t __timerid)
       
    62 	{
       
    63 	return MapError(getTimerHandler()->RemoveTimer(__timerid),errno);
       
    64 	}
       
    65 
       
    66 
       
    67 
       
    68 /* Set timer TIMERID to VALUE, returning old value in OVLAUE.  */
       
    69 EXPORT_C int timer_settime (timer_t __timerid, int __flags,
       
    70                           const struct itimerspec *__restrict __value,
       
    71                           struct itimerspec *__restrict __ovalue)
       
    72 	{
       
    73 	return MapError(getTimerHandler()->SetTime(__timerid, __flags, __value, __ovalue),errno);
       
    74 	}
       
    75 
       
    76 /* Get current value of timer TIMERID and store it in VLAUE.  */
       
    77 EXPORT_C int timer_gettime (timer_t __timerid, struct itimerspec *__value)
       
    78 	{
       
    79 	if(__value == NULL)
       
    80 		{
       
    81 		errno = EFAULT;	
       
    82 		return -1;
       
    83 		}
       
    84 		
       
    85 	return MapError(getTimerHandler()->Time(__timerid, __value),errno);
       
    86 	}
       
    87 
       
    88 /* Get expiration overrun for timer TIMERID.  */
       
    89 EXPORT_C int timer_getoverrun (timer_t __timerid)
       
    90 	{
       
    91 		
       
    92 #if (!defined SYMBIAN_OE_POSIX_SIGNALS || !defined SYMBIAN_OE_LIBRT)
       
    93 	__timerid = __timerid;//warning fix	
       
    94 	errno = ENOSYS;
       
    95 	return -1;
       
    96 #else
       
    97 	int overrun = 0;
       
    98 	int lerr = MapError(getTimerHandler()->OverrunCount(__timerid, overrun),errno); 	
       
    99 	if(lerr == -1 && errno == EINVAL)
       
   100 		{
       
   101 		return lerr;	
       
   102 		}
       
   103 	else
       
   104 		{
       
   105 		overrun = (overrun <= 1) ? 0 : (overrun-1);
       
   106 		}
       
   107  	
       
   108 	return overrun;
       
   109 #endif		
       
   110 	}
       
   111 
       
   112 } // extern "C"
       
   113 
       
   114 //EOF
       
   115 
       
   116