Split conky.h into several smaller header files
[monky] / src / conky.h
1 /* Conky, a system monitor, based on torsmo
2  *
3  * Any original torsmo code is licensed under the BSD license
4  *
5  * All code written since the fork of torsmo is licensed under the GPL
6  *
7  * Please see COPYING for details
8  *
9  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10  * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
11  *      (see AUTHORS)
12  * All rights reserved.
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  *
26  * $Id$
27  *
28  */
29
30 #ifndef _conky_h_
31 #define _conky_h_
32
33 #if defined(HAS_MCHECK_H)
34 #include <mcheck.h>
35 #endif /* HAS_MCHECK_H */
36
37 #include "config.h"
38 #include <sys/utsname.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <locale.h>
43 #include <langinfo.h>
44 #include <wchar.h>
45 #include <sys/param.h>
46
47 #if !defined(__GNUC__)
48 #  define __attribute__(x) /* nothing */
49 #endif
50
51 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
52 #include "freebsd.h"
53 #endif /* __FreeBSD__ */
54
55 #if defined(__OpenBSD__)
56 #include "openbsd.h"
57 #endif /* __OpenBSD__ */
58
59 #ifndef HAVE_STRNDUP
60 // use our own strndup() if it's not available
61 char *strndup(const char *s, size_t n);
62 #endif /* HAVE_STRNDUP */
63
64 #ifdef AUDACIOUS
65 #include "audacious.h"
66 #endif
67
68 #ifdef XMMS2
69 #include <xmmsclient/xmmsclient.h>
70 #endif
71
72 #ifdef RSS
73 #include "rss.h"
74 #endif
75
76 #ifdef SMAPI
77 #include "smapi.h"
78 #endif
79
80 #ifdef NVIDIA
81 #include "nvidia.h"
82 #endif
83  
84 #include "mboxscan.h"
85 #include "timed_thread.h"
86 #include "top.h"
87
88 #define DEFAULT_TEXT_BUFFER_SIZE 256
89 extern unsigned int text_buffer_size;
90
91 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
92 #define MAX_SPECIALS_DEFAULT 512
93
94 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
95 #define MAX_USER_TEXT_DEFAULT 16384
96
97 #include <sys/socket.h>
98
99 #define ERR(...) { \
100         fprintf(stderr, "Conky: "); \
101         fprintf(stderr, __VA_ARGS__); \
102         fprintf(stderr, "\n"); \
103 }
104
105 /* critical error */
106 #define CRIT_ERR(...) \
107         { ERR(__VA_ARGS__); exit(EXIT_FAILURE); }
108
109 struct net_stat {
110         const char *dev;
111         int up;
112         long long last_read_recv, last_read_trans;
113         long long recv, trans;
114         double recv_speed, trans_speed;
115         struct sockaddr addr;
116         char* addrs;
117         double net_rec[15], net_trans[15];
118         // wireless extensions
119         char essid[32];
120         char bitrate[16];
121         char mode[16];
122         int link_qual;
123         int link_qual_max;
124         char ap[18];
125 };
126
127 struct dns_data {
128         int nscount;
129         char **ns_list;
130 };
131
132 unsigned int diskio_value;
133 unsigned int diskio_read_value;
134 unsigned int diskio_write_value;
135
136 struct fs_stat {
137         char path[DEFAULT_TEXT_BUFFER_SIZE];
138         char type[DEFAULT_TEXT_BUFFER_SIZE];
139         long long size;
140         long long avail;
141         long long free;
142         char set;
143 };
144
145 #include "diskio.h"
146
147 struct mail_s {                 // for imap and pop3
148         unsigned long unseen;
149         unsigned long messages;
150         unsigned long used;
151         unsigned long quota;
152         unsigned long port;
153         float interval;
154         double last_update;
155         char host[128];
156         char user[128];
157         char pass[128];
158         char command[1024];
159         char folder[128];
160         timed_thread *p_timed_thread;
161         char secure;
162 };
163
164 /* struct cpu_stat {
165         unsigned int user, nice, system, idle, iowait, irq, softirq;
166         int cpu_avg_samples;
167 }; */
168
169 #ifdef MPD
170 #include "mpd.h"
171 #endif
172
173 #ifdef XMMS2
174 #include "xmms2.h"
175 #endif
176
177 #ifdef AUDACIOUS
178 #include "audacious.h"
179 #endif
180
181 #ifdef BMPX
182 #include "bmpx.h"
183 #endif
184
185 void update_entropy(void);
186 struct entropy_s {
187         unsigned int entropy_avail;
188         unsigned int poolsize;
189 };
190
191 struct usr_info {
192         char *names;
193         char *times;
194         char *terms;
195         int number;
196 };
197
198 struct gateway_info {
199         char *iface;
200         char *ip;
201         int count;
202 };
203
204 #ifdef TCP_PORT_MONITOR
205 #include "libtcp-portmon.h"
206 #endif
207
208 enum {
209         INFO_CPU = 0,
210         INFO_MAIL = 1,
211         INFO_MEM = 2,
212         INFO_NET = 3,
213         INFO_PROCS = 4,
214         INFO_RUN_PROCS = 5,
215         INFO_UPTIME = 6,
216         INFO_BUFFERS = 7,
217         INFO_FS = 8,
218         INFO_SYSFS = 9,
219         INFO_MIXER = 10,
220         INFO_LOADAVG = 11,
221         INFO_UNAME = 12,
222         INFO_FREQ = 13,
223 #ifdef MPD
224         INFO_MPD = 14,
225 #endif
226         INFO_TOP = 15,
227         INFO_WIFI = 16,
228         INFO_DISKIO = 17,
229         INFO_I8K = 18,
230 #ifdef TCP_PORT_MONITOR
231         INFO_TCP_PORT_MONITOR = 19,
232 #endif
233 #ifdef AUDACIOUS
234         INFO_AUDACIOUS = 20,
235 #endif
236 #ifdef BMPX
237         INFO_BMPX = 21,
238 #endif
239 #ifdef XMMS2
240         INFO_XMMS2 = 22,
241 #endif
242         INFO_ENTROPY = 23,
243 #ifdef RSS
244         INFO_RSS = 24,
245 #endif
246 #ifdef SMAPI
247         INFO_SMAPI = 25,
248 #endif
249         INFO_USERS = 26,
250         INFO_GW = 27,
251         INFO_DNS = 28
252 #ifdef NVIDIA
253 ,       INFO_NVIDIA = 29
254 #endif
255
256 };
257
258 /* get_battery_stuff() item selector */
259 enum {
260         BATTERY_STATUS,
261         BATTERY_TIME
262 };
263
264 /* if_up strictness selector */
265 enum {
266         IFUP_UP,
267         IFUP_LINK,
268         IFUP_ADDR
269 } ifup_strictness;
270
271 /* Update interval */
272 double update_interval;
273
274 volatile int g_signal_pending;
275
276 struct information {
277         unsigned int mask;
278
279         struct utsname uname_s;
280
281         char freq[10];
282
283         double uptime;
284
285         /* memory information in kilobytes */
286         unsigned long long mem, memmax, swap, swapmax;
287         unsigned long long bufmem, buffers, cached;
288
289         unsigned short procs;
290         unsigned short run_procs;
291
292         float *cpu_usage;
293         /* struct cpu_stat cpu_summed; what the hell is this? */
294         unsigned int cpu_count;
295         unsigned int cpu_avg_samples;
296
297         unsigned int net_avg_samples;
298
299         float loadavg[3];
300
301         struct mail_s *mail;
302         int mail_running;
303 #ifdef MPD
304         struct mpd_s mpd;
305 #endif
306 #ifdef XMMS2
307         struct xmms2_s xmms2;
308         int xmms2_conn_state;
309         xmms_socket_t xmms2_fd;
310         fd_set xmms2_fdset;
311         xmmsc_connection_t *xmms2_conn;
312 #endif
313 #ifdef AUDACIOUS
314         struct audacious_s audacious;
315 #endif
316 #ifdef BMPX
317         struct bmpx_s bmpx;
318 #endif
319         struct usr_info users;
320         struct gateway_info gw_info;
321         struct dns_data nameserver_info;
322         struct process *cpu[10];
323         struct process *memu[10];
324         struct process *first_process;
325         unsigned long looped;
326 #ifdef TCP_PORT_MONITOR
327         tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
328 #endif
329         struct entropy_s entropy;
330         double music_player_interval;
331
332         short kflags;   /* kernel settings, see enum KFLAG */
333 };
334
335 enum {
336         /* set to true if kernel uses "long" format for /proc/stats */
337         KFLAG_IS_LONGSTAT = 0x01,
338         /* set to true if kernel shows # of threads for the proc value
339          * in sysinfo() call */
340         KFLAG_PROC_IS_THREADS = 0x02
341         /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
342         /* KFLAG_NEXT_ONE = 0x04 */
343 };
344
345 #define KFLAG_SETON(a) info.kflags |= a
346 #define KFLAG_SETOFF(a) info.kflags &= (~a)
347 #define KFLAG_FLIP(a) info.kflags ^= a
348 #define KFLAG_ISSET(a) info.kflags & a
349
350 int out_to_console;
351
352 int top_cpu;
353 int top_mem;
354
355 int use_spacer;
356
357 enum spacer_opts { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
358
359 char *tmpstring1;
360 char *tmpstring2;
361
362 #ifdef X11
363 #include "x11.h"
364 #endif /* X11 */
365
366 int cpu_separate;
367 int short_units;
368
369 /* struct that has all info */
370 struct information info;
371
372 void signal_handler(int);
373 void reload_config(void);
374 void clean_up(void);
375
376 void update_uname(void);
377 double get_time(void);
378 FILE *open_file(const char *file, int *reported);
379 void variable_substitute(const char *s, char *dest, unsigned int n);
380 void format_seconds(char *buf, unsigned int n, long t);
381 void format_seconds_short(char *buf, unsigned int n, long t);
382 struct net_stat *get_net_stat(const char *dev);
383 void clear_net_stats(void);
384 void free_dns_data(void);
385 void update_dns_data(void);
386 void update_users(void);
387
388 void update_stuff(void);
389
390 int round_to_int(float f);
391
392 extern unsigned long long need_mask;
393
394 extern double current_update_time, last_update_time;
395
396 extern int no_buffers;
397
398 #if defined(__linux__)
399 #include "linux.h"
400 #endif
401
402 #include "fs.h"
403 #include "mixer.h"
404 #include "mail.h"
405
406 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
407                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
408 int apm_getinfo(int fd, apm_info_t aip);
409 char *get_apm_adapter(void);
410 char *get_apm_battery_life(void);
411 char *get_apm_battery_time(void);
412 #endif
413
414 #ifdef HDDTEMP
415 #include "hddtemp.h"
416 #endif /* HDDTEMP */
417
418 /* in nvidia.c */
419 #ifdef NVIDIA
420
421 int get_nvidia_value(QUERY_ID qid, Display *dpy, int highorlow);
422
423 #endif /* NVIDIA */
424
425 #endif