| 1 | /* |
| 2 | * diag_os_unix.h |
| 3 | * |
| 4 | * This is totally unix-exclusive and should only be included by diag_os_unix.c ! |
| 5 | * Public functions are in diag_os.h |
| 6 | * |
| 7 | * This file is part of freediag - Vehicle Diagnostic Utility |
| 8 | * |
| 9 | * Copyright (C) 2015 fenugrec <[email protected]> |
| 10 | * |
| 11 | * This program is free software: you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation, either version 3 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | */ |
| 25 | #ifndef _DIAG_OS_UNIX_H_ |
| 26 | #define _DIAG_OS_UNIX_H_ |
| 27 | |
| 28 | #if defined(__cplusplus) |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
| 32 | /****** OS-specific implementation selectors ******/ |
| 33 | /* These are for testing/debugging only, to force compilation of certain implementations |
| 34 | for diag_tty* and diag_os* functions. |
| 35 | |
| 36 | ### Map of features with more than one implementation related to POSIX ### |
| 37 | |
| 38 | ## time-related features ## |
| 39 | SEL_PERIODIC: Periodic timer callback (for L2+L3 keepalives) |
| 40 | A) needs _POSIX_TIMERS, uses timer_create() |
| 41 | B) (available everywhere?) setitimer+sigaction to install a SIGALRM handler |
| 42 | SEL_SLEEP: diag_os_millisleep() |
| 43 | A) needs _POSIX_TIMERS, uses clock_nanosleep() |
| 44 | B) needs __linux__ && (uid==root), uses /dev/rtc |
| 45 | C) (available everywhere?) nanosleep() loop |
| 46 | SEL_HRT: diag_os_gethrt() |
| 47 | A) needs _POSIX_TIMERS, uses clock_gettime() |
| 48 | B) (available everywhere?) gettimeofday() |
| 49 | |
| 50 | ###### |
| 51 | For every feature listed above, it's possible to force compilation of |
| 52 | a specific implementation using the #defines below. |
| 53 | TODO: add compile tests to cmake? |
| 54 | */ |
| 55 | #define S_AUTO 0 |
| 56 | /* First set, for obviously OS-dependant features: */ |
| 57 | #define S_POSIX 1 |
| 58 | #define S_LINUX 2 |
| 59 | #define S_OTHER 3 |
| 60 | /* Second set, not necessarily OS-dependant */ |
| 61 | #define S_ALT1 1 |
| 62 | #define S_ALT2 2 |
| 63 | /** Insert desired selectors here **/ |
| 64 | //example: |
| 65 | //#define SEL_PERIODIC S_OTHER |
| 66 | |
| 67 | /* Default selectors: anything still undefined is set to S_AUTO which |
| 68 | means "force nothing", i.e. "use most appropriate implementation". */ |
| 69 | #ifndef SEL_PERIODIC |
| 70 | #define SEL_PERIODIC S_AUTO |
| 71 | #endif |
| 72 | #ifndef SEL_SLEEP |
| 73 | #define SEL_SLEEP S_AUTO |
| 74 | #endif |
| 75 | #ifndef SEL_HRT |
| 76 | #define SEL_HRT S_AUTO |
| 77 | #endif |
| 78 | |
| 79 | /****** ******/ |
| 80 | |
| 81 | |
| 82 | #if defined(__cplusplus) |
| 83 | } |
| 84 | #endif |
| 85 | #endif /* _DIAG_OS_UNIX_H_ */ |
| 86 | |