Merge branch 'windows-port'
[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 #ifdef HAVE_SYS_TIME_H
25 #include <sys/time.h>
26 #endif
27 #ifdef HAVE_ARDUINO_TIME_H
28 #include <Time.h>
29 #endif
30
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35
36 #include <math.h>
37
38 #ifndef WITH_ARDUINO
39 #define SECS_PER_MIN  (60L)
40 #define SECS_PER_HOUR (SECS_PER_MIN * 60L)
41 #define SECS_PER_DAY  (SECS_PER_HOUR * 24L)
42 #define DAYS_PER_WEEK (7L)
43 #define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK)
44 #define SECS_PER_YEAR (SECS_PER_WEEK * 52L)
45 #define SECS_YR_2000  (946684800L)
46 #endif
47
48 time_t timespec_diff(const time_t after, const time_t before);
49 void timespec_add(time_t * to, const time_t seconds);
50 void checkTimeout();
51
52 #ifndef WITH_ARDUINO
53 long int getSeconds(struct tm* tp);
54 long int getRelativeIntervalOfWeek(struct tm* tp);
55 long int getSecondsFromAbsTime(struct tm* tp);
56
57 int initThread();
58 void *loop(void *threadid);
59 time_t registerTimer(const time_t seconds, int *id, void *cb);
60 void unregisterTimer(int id);
61
62 #else
63
64 time_t timeToSecondsFromNow(tmElements_t *t);
65 time_t registerTimer(const time_t seconds, int *id,  void (*cb)());
66 void unregisterTimer(int id);
67
68
69 #endif
70
71 #ifdef __cplusplus
72 }
73 #endif
74 #endif /* TIMER_H_ */
75