os/ossrv/genericopenlibs/posixrealtimeextensions/src/timer_funcs.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Name        : timer_funcs.cpp
sl@0
    15
// Part of     : librt-timer specific cpp file
sl@0
    16
// This is a project specific source file for building the 
sl@0
    17
// timer related functions as part of librt library.
sl@0
    18
// 
sl@0
    19
//
sl@0
    20
sl@0
    21
#include <signal.h>
sl@0
    22
#include <time.h>
sl@0
    23
#include <errno.h>
sl@0
    24
sl@0
    25
#include "lposix.h"
sl@0
    26
#include "timerhandler.h"
sl@0
    27
sl@0
    28
const TInt KErrWouldBlock=-1000;
sl@0
    29
sl@0
    30
extern "C" {
sl@0
    31
sl@0
    32
/* Create new per-process timer using CLOCK_ID.  */
sl@0
    33
EXPORT_C int timer_create (clockid_t __clock_id,
sl@0
    34
                         struct sigevent *__restrict __evp,
sl@0
    35
                         timer_t *__restrict __timerid)
sl@0
    36
	{
sl@0
    37
	if(__timerid == NULL)
sl@0
    38
		{
sl@0
    39
		errno = EFAULT;	
sl@0
    40
		return -1;
sl@0
    41
		}
sl@0
    42
		
sl@0
    43
	if(__clock_id != CLOCK_REALTIME)
sl@0
    44
		{
sl@0
    45
		errno = EINVAL;	
sl@0
    46
		return -1;
sl@0
    47
		}
sl@0
    48
		
sl@0
    49
	int err = getTimerHandler()->CreateTimer(*__timerid, __evp);
sl@0
    50
	 
sl@0
    51
	if (err == KErrWouldBlock)
sl@0
    52
		{
sl@0
    53
		return MapError(EAGAIN, errno);
sl@0
    54
		}
sl@0
    55
	
sl@0
    56
	return MapError(err, errno);
sl@0
    57
	}
sl@0
    58
sl@0
    59
sl@0
    60
/* Delete timer TIMERID.  */
sl@0
    61
EXPORT_C int timer_delete (timer_t __timerid)
sl@0
    62
	{
sl@0
    63
	return MapError(getTimerHandler()->RemoveTimer(__timerid),errno);
sl@0
    64
	}
sl@0
    65
sl@0
    66
sl@0
    67
sl@0
    68
/* Set timer TIMERID to VALUE, returning old value in OVLAUE.  */
sl@0
    69
EXPORT_C int timer_settime (timer_t __timerid, int __flags,
sl@0
    70
                          const struct itimerspec *__restrict __value,
sl@0
    71
                          struct itimerspec *__restrict __ovalue)
sl@0
    72
	{
sl@0
    73
	return MapError(getTimerHandler()->SetTime(__timerid, __flags, __value, __ovalue),errno);
sl@0
    74
	}
sl@0
    75
sl@0
    76
/* Get current value of timer TIMERID and store it in VLAUE.  */
sl@0
    77
EXPORT_C int timer_gettime (timer_t __timerid, struct itimerspec *__value)
sl@0
    78
	{
sl@0
    79
	if(__value == NULL)
sl@0
    80
		{
sl@0
    81
		errno = EFAULT;	
sl@0
    82
		return -1;
sl@0
    83
		}
sl@0
    84
		
sl@0
    85
	return MapError(getTimerHandler()->Time(__timerid, __value),errno);
sl@0
    86
	}
sl@0
    87
sl@0
    88
/* Get expiration overrun for timer TIMERID.  */
sl@0
    89
EXPORT_C int timer_getoverrun (timer_t __timerid)
sl@0
    90
	{
sl@0
    91
		
sl@0
    92
#if (!defined SYMBIAN_OE_POSIX_SIGNALS || !defined SYMBIAN_OE_LIBRT)
sl@0
    93
	__timerid = __timerid;//warning fix	
sl@0
    94
	errno = ENOSYS;
sl@0
    95
	return -1;
sl@0
    96
#else
sl@0
    97
	int overrun = 0;
sl@0
    98
	int lerr = MapError(getTimerHandler()->OverrunCount(__timerid, overrun),errno); 	
sl@0
    99
	if(lerr == -1 && errno == EINVAL)
sl@0
   100
		{
sl@0
   101
		return lerr;	
sl@0
   102
		}
sl@0
   103
	else
sl@0
   104
		{
sl@0
   105
		overrun = (overrun <= 1) ? 0 : (overrun-1);
sl@0
   106
		}
sl@0
   107
 	
sl@0
   108
	return overrun;
sl@0
   109
#endif		
sl@0
   110
	}
sl@0
   111
sl@0
   112
} // extern "C"
sl@0
   113
sl@0
   114
//EOF
sl@0
   115
sl@0
   116