Moved global diskio variables into info
[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 struct fs_stat {
133         char path[DEFAULT_TEXT_BUFFER_SIZE];
134         char type[DEFAULT_TEXT_BUFFER_SIZE];
135         long long size;
136         long long avail;
137         long long free;
138         char set;
139 };
140
141 #include "diskio.h"
142
143 struct mail_s {                 // for imap and pop3
144         unsigned long unseen;
145         unsigned long messages;
146         unsigned long used;
147         unsigned long quota;
148         unsigned long port;
149         float interval;
150         double last_update;
151         char host[128];
152         char user[128];
153         char pass[128];
154         char command[1024];
155         char folder[128];
156         timed_thread *p_timed_thread;
157         char secure;
158 };
159
160 /* struct cpu_stat {
161         unsigned int user, nice, system, idle, iowait, irq, softirq;
162         int cpu_avg_samples;
163 }; */
164
165 #ifdef MPD
166 #include "mpd.h"
167 #endif
168
169 #ifdef XMMS2
170 #include "xmms2.h"
171 #endif
172
173 #ifdef AUDACIOUS
174 #include "audacious.h"
175 #endif
176
177 #ifdef BMPX
178 #include "bmpx.h"
179 #endif
180
181 void update_entropy(void);
182 struct entropy_s {
183         unsigned int entropy_avail;
184         unsigned int poolsize;
185 };
186
187 struct usr_info {
188         char *names;
189         char *times;
190         char *terms;
191         int number;
192 };
193
194 struct gateway_info {
195         char *iface;
196         char *ip;
197         int count;
198 };
199
200 #ifdef TCP_PORT_MONITOR
201 #include "libtcp-portmon.h"
202 #endif
203
204 enum {
205         INFO_CPU = 0,
206         INFO_MAIL = 1,
207         INFO_MEM = 2,
208         INFO_NET = 3,
209         INFO_PROCS = 4,
210         INFO_RUN_PROCS = 5,
211         INFO_UPTIME = 6,
212         INFO_BUFFERS = 7,
213         INFO_FS = 8,
214         INFO_SYSFS = 9,
215         INFO_MIXER = 10,
216         INFO_LOADAVG = 11,
217         INFO_UNAME = 12,
218         INFO_FREQ = 13,
219 #ifdef MPD
220         INFO_MPD = 14,
221 #endif
222         INFO_TOP = 15,
223         INFO_WIFI = 16,
224         INFO_DISKIO = 17,
225         INFO_I8K = 18,
226 #ifdef TCP_PORT_MONITOR
227         INFO_TCP_PORT_MONITOR = 19,
228 #endif
229 #ifdef AUDACIOUS
230         INFO_AUDACIOUS = 20,
231 #endif
232 #ifdef BMPX
233         INFO_BMPX = 21,
234 #endif
235 #ifdef XMMS2
236         INFO_XMMS2 = 22,
237 #endif
238         INFO_ENTROPY = 23,
239 #ifdef RSS
240         INFO_RSS = 24,
241 #endif
242 #ifdef SMAPI
243         INFO_SMAPI = 25,
244 #endif
245         INFO_USERS = 26,
246         INFO_GW = 27,
247         INFO_DNS = 28
248 #ifdef NVIDIA
249 ,       INFO_NVIDIA = 29
250 #endif
251
252 };
253
254 /* get_battery_stuff() item selector */
255 enum {
256         BATTERY_STATUS,
257         BATTERY_TIME
258 };
259
260 /* if_up strictness selector */
261 enum {
262         IFUP_UP,
263         IFUP_LINK,
264         IFUP_ADDR
265 } ifup_strictness;
266
267 /* Update interval */
268 double update_interval;
269
270 volatile int g_signal_pending;
271
272 struct information {
273         unsigned int mask;
274
275         struct utsname uname_s;
276
277         char freq[10];
278
279         double uptime;
280
281         /* memory information in kilobytes */
282         unsigned long long mem, memmax, swap, swapmax;
283         unsigned long long bufmem, buffers, cached;
284
285         unsigned short procs;
286         unsigned short run_procs;
287
288         float *cpu_usage;
289         /* struct cpu_stat cpu_summed; what the hell is this? */
290         unsigned int cpu_count;
291         unsigned int cpu_avg_samples;
292
293         unsigned int net_avg_samples;
294
295         float loadavg[3];
296
297         struct mail_s *mail;
298         int mail_running;
299 #ifdef MPD
300         struct mpd_s mpd;
301 #endif
302 #ifdef XMMS2
303         struct xmms2_s xmms2;
304         int xmms2_conn_state;
305         xmms_socket_t xmms2_fd;
306         fd_set xmms2_fdset;
307         xmmsc_connection_t *xmms2_conn;
308 #endif
309 #ifdef AUDACIOUS
310         AUDACIOUS_S audacious;
311 #endif
312 #ifdef BMPX
313         struct bmpx_s bmpx;
314 #endif
315         struct usr_info users;
316         struct gateway_info gw_info;
317         struct dns_data nameserver_info;
318         struct process *cpu[10];
319         struct process *memu[10];
320         struct process *first_process;
321         unsigned long looped;
322 #ifdef TCP_PORT_MONITOR
323         tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
324 #endif
325         struct entropy_s entropy;
326         double music_player_interval;
327
328         short kflags;   /* kernel settings, see enum KFLAG */
329
330         unsigned int diskio_value;
331         unsigned int diskio_read_value;
332         unsigned int diskio_write_value;
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