UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / include / extern.h
blob31ab90c995bbcc85656e0eb94202b40fd029ddd3
1 /*
2 * extern.h
4 * Public exports.
5 */
7 /*
8 * Copyright (C) 2000-2005 Kern Sibbald
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General
12 * Public License as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * MA 02111-1307, USA.
25 #ifndef _EXTERN_H
26 #define _EXTERN_H
28 /* Function Prototypes */
30 extern UPSINFO myUPS;
31 extern UPSINFO *core_ups;
32 extern char argvalue[MAXSTRING];
33 extern void (*error_out) (const char *file, int line, const char *fmt, ...);
34 extern void (*error_exit) (const char *fmt, ...);
35 extern void (*error_cleanup) (void);
37 extern UPSCOMMANDS ups_event[];
38 extern UPSCMDMSG event_msg[];
41 /* Serial bits */
42 extern int le_bit;
43 extern int dtr_bit;
44 extern int rts_bit;
45 extern int st_bit;
46 extern int sr_bit;
47 extern int cts_bit;
48 extern int cd_bit;
49 extern int rng_bit;
50 extern int dsr_bit;
52 /* File opened */
53 extern int flags;
55 extern struct termios newtio;
57 extern int debug_net;
59 /* getopt flags (see apcoptd.c) */
60 extern int show_version;
61 extern char *cfgfile;
62 extern int configure_ups;
63 extern int update_battery_date;
64 extern int debug_level;
65 extern int rename_ups;
66 extern int terminate_on_powerfail;
67 extern int hibernate_ups;
68 extern int shutdown_ups;
69 extern int dumb_mode_test;
70 extern int go_background;
73 /* In apceeprom.c */
74 extern int do_eeprom_programming(UPSINFO *ups);
77 /* In apcopt.c */
78 extern int parse_options(int argc, char *argv[]);
80 /* In apcupsd.c */
81 extern void apc_thread_terminate(int sig);
82 extern void clean_threads(void);
83 extern void apcupsd_terminate(int sig);
84 extern void clear_files(void);
85 extern void make_pid(void);
87 /* In apcdevice.c */
88 void setup_device(UPSINFO *ups);
89 extern void setup_serial(UPSINFO *ups);
90 extern void initiate_hibernate(UPSINFO *ups);
91 extern void initiate_shutdown(UPSINFO *ups);
92 extern void save_dumb_status(UPSINFO *ups);
93 extern int check_serial(UPSINFO *ups);
94 extern void prep_device(UPSINFO *ups);
95 extern void do_device(UPSINFO *ups);
97 /* In apcaction.c */
98 extern void timer_action(int sig);
99 extern void do_action(UPSINFO *ups);
100 extern void generate_event(UPSINFO *ups, int event);
102 /* In apclock.c */
103 extern int create_lockfile(UPSINFO *ups);
104 extern void delete_lockfile(UPSINFO *ups);
106 /* In apcnet.c */
107 extern int write_struct_net(int wsocketfd, struct netdata *write_struct,
108 size_t size);
109 extern int read_struct_net(int rsocketfd, struct netdata *read_struct, size_t size);
110 extern void log_struct(struct netdata *logstruct);
112 extern int reconnect_master(UPSINFO *ups, int who);
113 extern int prepare_master(UPSINFO *ups);
115 extern int reconnect_slave(UPSINFO *ups);
116 extern int prepare_slave(UPSINFO *ups);
117 extern void kill_net(UPSINFO *ups);
119 extern void timer_net(int sig);
120 extern void do_net(UPSINFO *ups);
121 extern void timer_slaves(int sig);
122 extern void do_slaves(UPSINFO *ups);
124 /* In apcfile.c */
125 extern int make_file(UPSINFO *ups, const char *path);
126 extern void make_pid_file(void);
128 /* In apcconfig.c */
129 extern char APCCONF[APC_FILENAME_MAX];
130 extern void init_ups_struct(UPSINFO *ups);
131 extern void check_for_config(UPSINFO *ups, char *cfgfile);
133 /* In apcsetup.c */
134 extern void setup_ups_name(UPSINFO *ups);
135 extern void setup_ups_replace(UPSINFO *ups);
137 extern char *setup_ups_string(UPSINFO *ups, char cmd, char *setting);
138 extern int setup_ups_single(UPSINFO *ups, char cmd, int single);
139 extern int setup_ups_bubble(UPSINFO *ups, char cmd, int setting);
141 extern void setup_ups_sensitivity(UPSINFO *ups);
142 extern void setup_ups_wakeup(UPSINFO *ups);
143 extern void setup_ups_sleep(UPSINFO *ups);
144 extern void setup_ups_lo_xfer(UPSINFO *ups);
145 extern void setup_ups_hi_xfer(UPSINFO *ups);
146 extern void setup_ups_chargepoint(UPSINFO *ups);
147 extern void setup_ups_alarm(UPSINFO *ups);
148 extern void setup_ups_lowbatt_delay(UPSINFO *ups);
149 extern void setup_ups_selftest(UPSINFO *ups);
151 extern const char *get_model_from_oldfwrev(const char *s);
152 extern void get_apc_capabilities(UPSINFO *ups);
153 extern void read_extended(UPSINFO *ups);
154 extern void setup_extended(UPSINFO *ups);
156 /* In apcnis.c */
157 extern void do_server(UPSINFO *ups);
158 extern int check_wrappers(char *av, int newsock);
160 /* In apcstatus.c */
161 extern int output_status(UPSINFO *ups, int fd, void s_open(UPSINFO * ups),
162 void s_write(UPSINFO *ups, const char *fmt, ...), int s_close(UPSINFO * ups, int fd));
163 extern void stat_open(UPSINFO *ups);
164 extern int stat_close(UPSINFO *ups, int fd);
165 extern void stat_print(UPSINFO *ups, const char *fmt, ...);
168 /* In apcevents.c */
169 extern int trim_eventfile(UPSINFO *ups);
170 extern int output_events(int sockfd, FILE *events_file);
173 /* In apcreports.c */
174 extern void clear_files(void);
175 extern int log_status(UPSINFO *ups);
177 extern void timer_reports(int sig);
178 extern void do_reports(UPSINFO *ups);
180 /* In apcsmart.c */
181 extern int apc_enable(UPSINFO *ups);
182 extern int writechar(char a, UPSINFO *ups);
183 extern int getline(char *s, int len, UPSINFO *ups);
184 extern void UPSlinkCheck(UPSINFO *ups);
185 extern char *smart_poll(char cmd, UPSINFO *ups);
186 extern int fillUPS(UPSINFO *ups);
188 /* In apcsignal.c */
189 extern void init_signals(void (*handler) (int));
190 extern void init_thread_signals(void);
191 extern void restore_signals(void);
193 /* In newups.c */
194 extern UPSINFO *new_ups(void);
195 extern UPSINFO *attach_ups(UPSINFO *ups);
196 extern void detach_ups(UPSINFO *ups);
197 extern void destroy_ups(UPSINFO *ups);
199 #define read_lock(ups) _read_lock(__FILE__, __LINE__, (ups))
200 #define read_unlock(ups) _read_unlock(__FILE__, __LINE__, (ups))
201 #define write_lock(ups) _write_lock(__FILE__, __LINE__, (ups))
202 #define write_unlock(ups) _write_unlock(__FILE__, __LINE__, (ups))
203 #define read_lock(ups) _read_lock(__FILE__, __LINE__, (ups))
205 extern void _read_lock(const char *file, int line, UPSINFO *ups);
206 extern void _read_unlock(const char *file, int line, UPSINFO *ups);
207 extern void _write_lock(const char *file, int line, UPSINFO *ups);
208 extern void _write_unlock(const char *file, int line, UPSINFO *ups);
210 /* In apcexec.c */
211 extern int start_thread(UPSINFO *ups, void (*action) (UPSINFO * ups),
212 const char *proctitle, char *argv0);
213 extern int execute_command(UPSINFO *ups, UPSCOMMANDS cmd);
214 extern void wait_for_termination(int serial_pid);
216 /* In apclog.c */
217 extern void log_event(const UPSINFO *ups, int level, const char *fmt, ...);
218 extern void logf(const char *fmt, ...);
219 extern void hex_dump(int level, void *data, unsigned int len);
220 extern int format_date(time_t timestamp, char *dest, size_t destlen);
222 /* In apcnetlib.c */
223 extern int net_open(const char *host, char *service, int port);
224 extern void net_close(int sockfd);
225 extern int net_send(int sockfd, const char *buff, int len);
226 extern int net_recv(int sockfd, char *buff, int maxlen);
228 /* In apclist.c */
229 extern int insertUps(UPSINFO *ups);
230 extern UPSINFO *getNextUps(UPSINFO *ups);
231 extern UPSINFO *getUpsByname(char *name);
233 /* In apcerror.c */
234 extern void generic_error_out(const char *file, int line, const char *fmt, ...);
235 extern void generic_error_exit(const char *fmt, ...);
237 /* In asys.c */
238 int avsnprintf(char *str, size_t size, const char *format, va_list ap);
239 int asnprintf(char *str, size_t size, const char *fmt, ...);
240 char *astrncpy(char *dest, const char *src, int maxlen);
241 char *astrncat(char *dest, const char *src, int maxlen);
242 //struct tm *localtime_r(const time_t *timep, struct tm *tm);
243 char *afgets(char *s, int size, FILE *fd);
244 void *amalloc(size_t size);
245 void *arealloc(void *buf, size_t size);
246 void *acalloc(size_t size1, size_t size2);
248 /* In apcwinipc.c */
249 int winioctl(int fd, int func, int *addr);
251 /* In sleep.c */
252 #ifndef HAVE_NANOSLEEP
253 int nanosleep(const struct timespec *req, struct timespec *rem);
254 #endif
257 * Common interface to the various versions of gethostbyname_r().
258 * Implemented in gethostname.c.
260 struct hostent * gethostname_re
261 (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen);
263 #endif /* _EXTERN_H */