• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ALARM_H
17 #define ALARM_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 #include "reactor.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define ALARM_NAME_SIZE 16
28 
29 #define MS_PER_SECOND 1000
30 #define NS_PER_MS 1000000
31 
32 typedef struct Alarm Alarm;
33 typedef void (*AlarmCallback)(void *parameter);
34 
35 /**
36  * @brief Perform instantiation of the Alarm.
37  *
38  * @return Succeed return 0, failed return -1.
39  * @since 6
40  */
41 int32_t AlarmModuleInit();
42 
43 /**
44  * @brief Clean up the Alarm Module.
45  *
46  * @since 6
47  */
48 void AlarmModuleCleanup();
49 
50 /**
51  * @brief Perform instantiation of the Alarm, set Alarm Attributes isPeriodic and name.
52  *
53  * @param name Alarm Name.
54  * @param isPeriodic Alarm isPeriodic.
55  * @return Succeed return Alarm pointer, failed return NULL.
56  * @since 6
57  */
58 Alarm *AlarmCreate(const char *name, const bool isPeriodic);
59 
60 /**
61  * @brief Delete an Alarm Object.
62  *
63  * @param alarm Alarm pointer.
64  * @since 6
65  */
66 void AlarmDelete(Alarm *alarm);
67 
68 /**
69  * @brief Set an Alarm. Set the time(ms) as well as callback function and its parameter.
70  *        Execute AlarmSet, alarm start counting down.
71  *
72  * @param alarm Alarm pointer.
73  * @param timeMs Countdown time, unit(ms).
74  * @param callback Alarm timeout callback.
75  * @param parameter Callback parameter.
76  * @return Succeed return 0, failed return -1.
77  * @since 6
78  */
79 int32_t AlarmSet(Alarm *alarm, uint64_t timeMs, AlarmCallback callback, void *parameter);
80 
81 /**
82  * @brief Cancel an alarm.
83  *        If alarm is running, this operation will stop it.
84  *
85  * @param alarm Alarm pointer.
86  * @since 6
87  */
88 void AlarmCancel(Alarm *alarm);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif  // ALARM_H