Ported messages from gear racing controller
[apps/native/gear-racing-car.git] / src / messages / clock.c
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdlib.h>
18
19 #include "messages/clock.h"
20
21 float clock_monotonic_get()
22 {
23         struct timespec ret = {0,};
24
25         if (clock_gettime(CLOCK_MONOTONIC, &ret) != 0) {
26                 abort();
27         }
28
29         return ret.tv_sec + (float)ret.tv_nsec / 1000000000.0f;
30 }
31
32 time_t clock_realtime_get()
33 {
34         struct timespec ret = {0,};
35
36         if (clock_gettime(CLOCK_REALTIME, &ret) != 0) {
37                 abort();
38         }
39
40         return ret.tv_sec;
41 }
42
43 bool clock_is_supported()
44 {
45         struct timespec ret = {0,};
46
47         if (clock_gettime(CLOCK_MONOTONIC, &ret) != 0) {
48                 return false;
49         }
50         if (clock_gettime(CLOCK_REALTIME, &ret) != 0) {
51                 return false;
52         }
53         return true;
54 }
55