IOT-1583: Adding /W4 and /WX to timer build.
[platform/upstream/iotivity.git] / extlibs / timer / timer.h
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef TIMER_H_
22 #define TIMER_H_
23
24 #include "iotivity_config.h"
25 #ifdef HAVE_SYS_TIME_H
26 #include <sys/time.h>
27 #endif
28 #ifdef HAVE_ARDUINO_TIME_H
29 #include <Time.h>
30 #endif
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 #include <math.h>
38
39 #ifndef WITH_ARDUINO
40 #define SECS_PER_MIN  (60L)
41 #define SECS_PER_HOUR (SECS_PER_MIN * 60L)
42 #define SECS_PER_DAY  (SECS_PER_HOUR * 24L)
43 #define DAYS_PER_WEEK (7L)
44 #define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK)
45 #define SECS_PER_YEAR (SECS_PER_WEEK * 52L)
46 #define SECS_YR_2000  (946684800L)
47 #endif
48
49 typedef void(*TimerCallback)();
50
51 time_t timespec_diff(const time_t after, const time_t before);
52 void timespec_add(time_t * to, const time_t seconds);
53 void checkTimeout();
54
55 #ifndef WITH_ARDUINO
56 long int getSeconds(struct tm* tp);
57 time_t getRelativeIntervalOfWeek(struct tm* tp);
58 time_t getSecondsFromAbsTime(struct tm* tp);
59
60 int initThread();
61 void *loop(void *threadid);
62 time_t registerTimer(const time_t seconds, int *id, TimerCallback cb);
63 void unregisterTimer(int id);
64
65 #else
66
67 time_t timeToSecondsFromNow(tmElements_t *t);
68 time_t registerTimer(const time_t seconds, int *id, TimerCallback cb);
69 void unregisterTimer(int id);
70
71
72 #endif
73
74 #ifdef __cplusplus
75 }
76 #endif
77 #endif /* TIMER_H_ */
78