root/luci2/upsd/core.h @ 5807

Revision 5807, 2.7 KB (checked in by Cyrus, 3 years ago)

upsd: Add extension hooks, Implement builtin start-stop-daemon utility,
Make runlevel API more straight-forward, Add a lock for interactive processes

Line 
1#ifndef UPSDCORE_H_
2#define UPSDCORE_H_
3
4#include <time.h>
5#include <sys/types.h>
6#include <stdint.h>
7#include "upsd.h"
8#include "upsd_config.h"
9
10#if __GNUC__ >= 4
11    #define UPSD_LOCAL  __attribute__ ((visibility("hidden")))
12#else
13    #define UPSD_LOCAL
14#endif
15
16#define UPSD_LENGTHOF(array) (sizeof(array) / sizeof(*array))
17#define UPSD_MACRO_STRING(x) _UPSD_MACRO_STRING(x)
18#define _UPSD_MACRO_STRING(x) #x
19#define UPSD_LITERAL_PTRSIZE(x) x, (sizeof(x) - 1)
20
21
22typedef struct upsd_listener upsd_listener_t;
23typedef struct upsd_event upsd_event_t;
24typedef struct upsd_inst upsd_inst_t;
25typedef struct upsd_initlist upsd_initlist_t;
26typedef struct upsd_handler upsd_handler_t;
27typedef struct upsd_extension upsd_extension_t;
28typedef union upsd_handle upsd_handle_t;
29
30#define UPSD_ACTION_INTERNAL_CLEAN  ((upsd_action_t) -1)
31
32/* Status handle for asynchronous init actions */
33union upsd_handle {
34    pid_t pid;
35    int descriptor;
36    void *pointer;
37};
38
39/* Dynamic state part of a service, changing throughout commands */
40struct upsd_handler {
41    uint16_t flags;
42    uint16_t awaiting;
43    int16_t status;
44    time_t timeout;
45    upsd_handle_t handle;
46};
47
48/* Service dataset */
49struct upsd_init {
50    uint16_t flags;
51    void *identifier;
52    char **options;
53    char **provides;
54    upsd_worker_t *worker;
55    upsd_handler_t hndl;
56};
57
58/* Event listener instance */
59struct upsd_listener {
60    uint16_t flags;
61    upsd_action_t action;
62    char *emitter;
63    char *receiver;
64};
65
66/* Event dataset */
67struct upsd_event {
68    uint16_t receiving;
69    uint16_t emitting;
70    upsd_listener_t **receivers;
71    upsd_listener_t **emitters;
72    upsd_init_t *designated;
73};
74
75/* Service list */
76struct upsd_initlist {
77    upsd_init_t *init;
78    upsd_initlist_t *next;
79};
80
81/* Command action instance */
82struct upsd_inst {
83    uint16_t flags;
84    uint16_t remaining;
85    uint16_t active;
86    uint16_t lasterror;
87    time_t time;
88    upsd_initlist_t *actions;
89};
90
91struct upsd_extension {
92    upsd_extension_t *next;
93    uint16_t flags;
94    upsd_action_t action;
95    upsd_hook_t *hook;
96    void *context;
97};
98
99
100#include "cbi2/hmap.h"
101
102struct upsd_state {
103    cbi2_hmap_t *events;
104    upsd_extension_t *extensions;
105    upsd_report_t *report;
106    size_t reportidx;
107    upsd_inst_t inst;
108};
109
110#define UPSD_INIT_LEGACY            0x01
111#define UPSD_INIT_INTERNAL          0x02
112#define UPSD_INIT_INTERACTIVE       0x04
113
114
115#if UPSD_LOGGING >= 4
116    #define UPSD_LOG_INFO(...)      syslog(LOG_INFO, __VA_ARGS__)
117#else
118    #define UPSD_LOG_INFO(...)
119#endif
120
121#if UPSD_LOGGING >= 3
122    #define UPSD_LOG_NOTE(...)      syslog(LOG_NOTICE, __VA_ARGS__)
123#else
124    #define UPSD_LOG_NOTE(...)
125#endif
126
127#if UPSD_LOGGING >= 2
128    #define UPSD_LOG_WARN(...)      syslog(LOG_WARNING, __VA_ARGS__)
129#else
130    #define UPSD_LOG_WARN(...)
131#endif
132
133#if UPSD_LOGGING >= 1
134    #define UPSD_LOG_ERROR(...)     syslog(LOG_ERR, __VA_ARGS__)
135    #include <syslog.h>
136#else
137    #define UPSD_LOG_ERROR(...)
138#endif
139
140#endif /* UPSDCORE_H_ */
Note: See TracBrowser for help on using the browser.