Removing old svn keywords.
[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  */
27
28 #ifndef _conky_h_
29 #define _conky_h_
30
31 #if defined(HAS_MCHECK_H)
32 #include <mcheck.h>
33 #endif /* HAS_MCHECK_H */
34
35 #undef EQUAL
36 #undef FALSE
37 #undef TRUE
38 #define EQUAL 0 //returnvalue of strcmp-variants when strings are equal
39 #define FALSE 0
40 #define TRUE 1
41
42 #include "config.h"
43 #include <sys/utsname.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <locale.h>
48 #include <langinfo.h>
49 #include <wchar.h>
50 #include <sys/param.h>
51
52 #if !defined(__GNUC__)
53 #  define __attribute__(x) /* nothing */
54 #endif
55
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
57 #include "freebsd.h"
58 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
59
60 #if defined(__OpenBSD__)
61 #include "openbsd.h"
62 #endif /* __OpenBSD__ */
63
64 #ifndef HAVE_STRNDUP
65 // use our own strndup() if it's not available
66 char *strndup(const char *s, size_t n);
67 #endif /* HAVE_STRNDUP */
68
69 #ifdef AUDACIOUS
70 #include "audacious.h"
71 #endif
72
73 #ifdef XMMS2
74 #include <xmmsclient/xmmsclient.h>
75 #endif
76
77 #ifdef RSS
78 #include "rss.h"
79 #endif
80
81 #ifdef EVE
82 #include "eve.h"
83 #endif
84
85 #ifdef SMAPI
86 #include "smapi.h"
87 #endif
88
89 #ifdef NVIDIA
90 #include "nvidia.h"
91 #endif
92
93 #include "mboxscan.h"
94 #include "timed_thread.h"
95 #include "top.h"
96
97 #define DEFAULT_TEXT_BUFFER_SIZE 256
98 extern unsigned int text_buffer_size;
99
100 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
101 #define MAX_SPECIALS_DEFAULT 512
102
103 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
104 #define MAX_USER_TEXT_DEFAULT 16384
105
106 #include <sys/socket.h>
107
108 #define ERR(...) { \
109         fprintf(stderr, PACKAGE_NAME": "); \
110         fprintf(stderr, __VA_ARGS__); \
111         fprintf(stderr, "\n"); \
112 }
113
114 /* critical error */
115 #define CRIT_ERR(...) \
116         { ERR(__VA_ARGS__); exit(EXIT_FAILURE); }
117
118 /* debugging output */
119 extern int global_debug_level;
120 #define __DBGP(level, ...) \
121         if (global_debug_level > level) { \
122                 fprintf(stderr, "DEBUG(%d) [" __FILE__ ":%d]: ", level, __LINE__); \
123                 fprintf(stderr, __VA_ARGS__); \
124                 fprintf(stderr, "\n"); \
125         }
126 #define DBGP(...) __DBGP(0, __VA_ARGS__)
127 #define DBGP2(...) __DBGP(1, __VA_ARGS__)
128
129 struct net_stat {
130         const char *dev;
131         int up;
132         long long last_read_recv, last_read_trans;
133         long long recv, trans;
134         double recv_speed, trans_speed;
135         struct sockaddr addr;
136         char* addrs;
137         double net_rec[15], net_trans[15];
138         // wireless extensions
139         char essid[32];
140         char bitrate[16];
141         char mode[16];
142         int link_qual;
143         int link_qual_max;
144         char ap[18];
145 };
146
147 struct dns_data {
148         int nscount;
149         char **ns_list;
150 };
151
152 struct fs_stat {
153         char path[DEFAULT_TEXT_BUFFER_SIZE];
154         char type[DEFAULT_TEXT_BUFFER_SIZE];
155         long long size;
156         long long avail;
157         long long free;
158         char set;
159 };
160
161 #include "diskio.h"
162
163 struct mail_s {                 // for imap and pop3
164         unsigned long unseen;
165         unsigned long messages;
166         unsigned long used;
167         unsigned long quota;
168         unsigned long port;
169         unsigned int retries;
170         float interval;
171         double last_update;
172         char host[128];
173         char user[128];
174         char pass[128];
175         char command[1024];
176         char folder[128];
177         timed_thread *p_timed_thread;
178         char secure;
179 };
180
181 /* struct cpu_stat {
182         unsigned int user, nice, system, idle, iowait, irq, softirq;
183         int cpu_avg_samples;
184 }; */
185
186 #ifdef MPD
187 #include "mpd.h"
188 #endif
189
190 #ifdef MOC
191 #include "moc.h"
192 #endif
193
194 #ifdef XMMS2
195 #include "xmms2.h"
196 #endif
197
198 #ifdef AUDACIOUS
199 #include "audacious.h"
200 #endif
201
202 #ifdef BMPX
203 #include "bmpx.h"
204 #endif
205
206 void update_entropy(void);
207 struct entropy_s {
208         unsigned int entropy_avail;
209         unsigned int poolsize;
210 };
211
212 struct usr_info {
213         char *names;
214         char *times;
215         char *terms;
216         int number;
217 };
218
219 struct gateway_info {
220         char *iface;
221         char *ip;
222         int count;
223 };
224
225 #ifdef X11
226 struct monitor_info {
227         int number;
228         int current;
229 };
230
231 struct x11_info {
232         struct monitor_info monitor;
233 };
234 #endif
235
236 #ifdef TCP_PORT_MONITOR
237 #include "libtcp-portmon.h"
238 #endif
239
240 enum {
241         INFO_CPU = 0,
242         INFO_MAIL = 1,
243         INFO_MEM = 2,
244         INFO_NET = 3,
245         INFO_PROCS = 4,
246         INFO_RUN_PROCS = 5,
247         INFO_UPTIME = 6,
248         INFO_BUFFERS = 7,
249         INFO_FS = 8,
250         INFO_SYSFS = 9,
251         INFO_MIXER = 10,
252         INFO_LOADAVG = 11,
253         INFO_UNAME = 12,
254         INFO_FREQ = 13,
255 #ifdef MPD
256         INFO_MPD = 14,
257 #endif
258         INFO_TOP = 15,
259         INFO_WIFI = 16,
260         INFO_DISKIO = 17,
261         INFO_I8K = 18,
262 #ifdef TCP_PORT_MONITOR
263         INFO_TCP_PORT_MONITOR = 19,
264 #endif
265 #ifdef AUDACIOUS
266         INFO_AUDACIOUS = 20,
267 #endif
268 #ifdef BMPX
269         INFO_BMPX = 21,
270 #endif
271 #ifdef XMMS2
272         INFO_XMMS2 = 22,
273 #endif
274         INFO_ENTROPY = 23,
275 #ifdef RSS
276         INFO_RSS = 24,
277 #endif
278 #ifdef SMAPI
279         INFO_SMAPI = 25,
280 #endif
281         INFO_USERS = 26,
282         INFO_GW = 27,
283 #ifdef NVIDIA
284         INFO_NVIDIA = 28,
285 #endif
286 #ifdef X11
287         INFO_X11 = 29,
288 #endif
289         INFO_DNS = 30,
290 #ifdef MOC
291   INFO_MOC = 31
292 #endif
293 };
294
295 /* get_battery_stuff() item selector */
296 enum {
297         BATTERY_STATUS,
298         BATTERY_TIME
299 };
300
301 /* if_up strictness selector */
302 enum {
303         IFUP_UP,
304         IFUP_LINK,
305         IFUP_ADDR
306 } ifup_strictness;
307
308 /* Update interval */
309 double update_interval;
310
311 volatile int g_signal_pending;
312
313 struct information {
314         unsigned int mask;
315
316         struct utsname uname_s;
317
318         char freq[10];
319
320         double uptime;
321
322         /* memory information in kilobytes */
323         unsigned long long mem, memeasyfree, memfree, memmax, swap, swapmax;
324         unsigned long long bufmem, buffers, cached;
325
326         unsigned short procs;
327         unsigned short run_procs;
328
329         float *cpu_usage;
330         /* struct cpu_stat cpu_summed; what the hell is this? */
331         unsigned int cpu_count;
332         unsigned int cpu_avg_samples;
333
334         unsigned int net_avg_samples;
335
336         float loadavg[3];
337
338         struct mail_s *mail;
339         int mail_running;
340 #ifdef MPD
341         struct mpd_s mpd;
342 #endif
343 #ifdef MOC
344   struct moc_s moc;
345 #endif
346 #ifdef XMMS2
347         struct xmms2_s xmms2;
348         int xmms2_conn_state;
349         xmms_socket_t xmms2_fd;
350         fd_set xmms2_fdset;
351         xmmsc_connection_t *xmms2_conn;
352 #endif
353 #ifdef AUDACIOUS
354         AUDACIOUS_S audacious;
355 #endif
356 #ifdef BMPX
357         struct bmpx_s bmpx;
358 #endif
359         struct usr_info users;
360         struct gateway_info gw_info;
361         struct dns_data nameserver_info;
362         struct process *cpu[10];
363         struct process *memu[10];
364         struct process *first_process;
365         unsigned long looped;
366 #ifdef TCP_PORT_MONITOR
367         tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
368 #endif
369         struct entropy_s entropy;
370         double music_player_interval;
371
372 #ifdef X11
373         struct x11_info x11;
374 #endif
375
376         short kflags;   /* kernel settings, see enum KFLAG */
377
378         unsigned int diskio_value;
379         unsigned int diskio_read_value;
380         unsigned int diskio_write_value;
381 };
382
383 enum {
384         /* set to true if kernel uses "long" format for /proc/stats */
385         KFLAG_IS_LONGSTAT = 0x01,
386         /* set to true if kernel shows # of threads for the proc value
387          * in sysinfo() call */
388         KFLAG_PROC_IS_THREADS = 0x02
389         /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
390         /* KFLAG_NEXT_ONE = 0x04 */
391 };
392
393 #define KFLAG_SETON(a) info.kflags |= a
394 #define KFLAG_SETOFF(a) info.kflags &= (~a)
395 #define KFLAG_FLIP(a) info.kflags ^= a
396 #define KFLAG_ISSET(a) info.kflags & a
397
398 #define TO_X 1
399 #define TO_STDOUT 2
400 int output_methods;
401
402 int top_cpu;
403 int top_mem;
404
405 int use_spacer;
406
407 enum spacer_opts { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
408
409 char *tmpstring1;
410 char *tmpstring2;
411
412 #ifdef X11
413 #include "x11.h"
414 #endif /* X11 */
415
416 int cpu_separate;
417 int short_units;
418
419 /* struct that has all info */
420 struct information info;
421
422 void signal_handler(int);
423 void reload_config(void);
424 void clean_up(void);
425
426 void update_uname(void);
427 double get_time(void);
428 FILE *open_file(const char *file, int *reported);
429 void variable_substitute(const char *s, char *dest, unsigned int n);
430 void format_seconds(char *buf, unsigned int n, long t);
431 void format_seconds_short(char *buf, unsigned int n, long t);
432 struct net_stat *get_net_stat(const char *dev);
433 void clear_net_stats(void);
434 void free_dns_data(void);
435 void update_dns_data(void);
436 void update_users(void);
437
438 #ifdef X11
439 void update_x11info(void);
440 #endif
441
442 void update_stuff(void);
443
444 int round_to_int(float f);
445
446 extern unsigned long long need_mask;
447
448 extern double current_update_time, last_update_time;
449
450 extern int no_buffers;
451
452 #if defined(__linux__)
453 #include "linux.h"
454 #endif
455
456 #include "fs.h"
457 #include "mixer.h"
458 #include "mail.h"
459
460 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
461                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
462 int apm_getinfo(int fd, apm_info_t aip);
463 char *get_apm_adapter(void);
464 char *get_apm_battery_life(void);
465 char *get_apm_battery_time(void);
466 #endif
467
468 #ifdef HDDTEMP
469 #include "hddtemp.h"
470 #endif /* HDDTEMP */
471
472 #endif