1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
*
* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _ALARM_API_H_
#define _ALARM_API_H_
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
#define NSFW_ALARM_MODULE "nstack_alarm"
/* alarm ID for every event, when need add new alarm, here add a alarm_id define */
typedef enum _alarm_id
{
ALARM_EVENT_BASE,
ALARM_EVENT_NSTACK_RESOURCE_ALARM,
ALARM_EVENT_NSTACK_NO_USE,
ALARM_EVENT_NSTACK_MAIN_ABNORMAL,
ALARM_EVENT_MAX
} enum_alarm_id;
/* support both type alarm:
1. support other module call func:ns_send_alarm to product alarm;
2. alarm module call function periodly to check whether need product alarm */
typedef enum _alarm_type
{
ALARM_PERIOD_CHECK,
ALARM_SEND_ONCE
} alarm_type;
typedef enum _alarm_flag
{
ALARM_PRODUCT,
ALARM_CLEAN,
ALARM_MAX
} alarm_flag;
typedef enum _alarm_reason
{
ALARM_REASON_BEGIN,
ALARM_REASON_SOCKET = 0,
ALARM_REASON_MSG_BUF,
ALARM_REASON_NSMAIN,
ALARM_REASON_MAX
} alarm_reason;
typedef struct _alarm_result
{
enum_alarm_id alarm_id_get;
alarm_reason alarm_reason_get;
alarm_flag alarm_flag_get;
} alarm_result;
/* check whether need product alarm,if return 0, then product alarm */
typedef alarm_result (*alarm_check_func) (void *para);
typedef alarm_result (*alarm_check_func_period) (void);
typedef struct _alarm_para
{
union
{
int time_length;
} period_alarm;
union
{
alarm_check_func func_alarm_check[ALARM_REASON_MAX];
alarm_check_func_period func_alarm_check_period[ALARM_REASON_MAX];
};
alarm_reason alarm_reason_set[ALARM_REASON_MAX];
int alarm_reason_count;
} alarm_para;
/* for any alarm added, firstly call following function to reg */
int ns_reg_alarm (enum_alarm_id alarm_id, alarm_type _alarm_type,
alarm_para * _alarm_para);
void ns_send_init_alarm (enum_alarm_id alarm_id);
/* other module call this func to product alarm, here para is same as alarm_check_func's para */
void ns_send_alarm (enum_alarm_id alarm_id, void *para);
int ns_alarm_module_init (void *param);
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#endif
|