sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Name : timer_funcs.cpp sl@0: // Part of : librt-timer specific cpp file sl@0: // This is a project specific source file for building the sl@0: // timer related functions as part of librt library. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "lposix.h" sl@0: #include "timerhandler.h" sl@0: sl@0: const TInt KErrWouldBlock=-1000; sl@0: sl@0: extern "C" { sl@0: sl@0: /* Create new per-process timer using CLOCK_ID. */ sl@0: EXPORT_C int timer_create (clockid_t __clock_id, sl@0: struct sigevent *__restrict __evp, sl@0: timer_t *__restrict __timerid) sl@0: { sl@0: if(__timerid == NULL) sl@0: { sl@0: errno = EFAULT; sl@0: return -1; sl@0: } sl@0: sl@0: if(__clock_id != CLOCK_REALTIME) sl@0: { sl@0: errno = EINVAL; sl@0: return -1; sl@0: } sl@0: sl@0: int err = getTimerHandler()->CreateTimer(*__timerid, __evp); sl@0: sl@0: if (err == KErrWouldBlock) sl@0: { sl@0: return MapError(EAGAIN, errno); sl@0: } sl@0: sl@0: return MapError(err, errno); sl@0: } sl@0: sl@0: sl@0: /* Delete timer TIMERID. */ sl@0: EXPORT_C int timer_delete (timer_t __timerid) sl@0: { sl@0: return MapError(getTimerHandler()->RemoveTimer(__timerid),errno); sl@0: } sl@0: sl@0: sl@0: sl@0: /* Set timer TIMERID to VALUE, returning old value in OVLAUE. */ sl@0: EXPORT_C int timer_settime (timer_t __timerid, int __flags, sl@0: const struct itimerspec *__restrict __value, sl@0: struct itimerspec *__restrict __ovalue) sl@0: { sl@0: return MapError(getTimerHandler()->SetTime(__timerid, __flags, __value, __ovalue),errno); sl@0: } sl@0: sl@0: /* Get current value of timer TIMERID and store it in VLAUE. */ sl@0: EXPORT_C int timer_gettime (timer_t __timerid, struct itimerspec *__value) sl@0: { sl@0: if(__value == NULL) sl@0: { sl@0: errno = EFAULT; sl@0: return -1; sl@0: } sl@0: sl@0: return MapError(getTimerHandler()->Time(__timerid, __value),errno); sl@0: } sl@0: sl@0: /* Get expiration overrun for timer TIMERID. */ sl@0: EXPORT_C int timer_getoverrun (timer_t __timerid) sl@0: { sl@0: sl@0: #if (!defined SYMBIAN_OE_POSIX_SIGNALS || !defined SYMBIAN_OE_LIBRT) sl@0: __timerid = __timerid;//warning fix sl@0: errno = ENOSYS; sl@0: return -1; sl@0: #else sl@0: int overrun = 0; sl@0: int lerr = MapError(getTimerHandler()->OverrunCount(__timerid, overrun),errno); sl@0: if(lerr == -1 && errno == EINVAL) sl@0: { sl@0: return lerr; sl@0: } sl@0: else sl@0: { sl@0: overrun = (overrun <= 1) ? 0 : (overrun-1); sl@0: } sl@0: sl@0: return overrun; sl@0: #endif sl@0: } sl@0: sl@0: } // extern "C" sl@0: sl@0: //EOF sl@0: sl@0: