Merging upstream version 0.7.0 (Closes: #493243, #510888, #567617, #699414, #709777...
[debian/lxpanel.git] / plugins / netstatus / netstatus-util.h
1 /*
2 * Copyright (C) 2003 Sun Microsystems, Inc.
3 * Copyright (C) 2004 Red Hat Inc.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 * 02111-1307, USA.
19
20 * Authors:
21 * Mark McLoughlin <mark@skynet.ie>
22 */
23
24 #ifndef __NETSTATUS_UTIL_H__
25 #define __NETSTATUS_UTIL_H__
26
27 #include <glib-object.h>
28
29 G_BEGIN_DECLS
30
31 #define NETSTATUS_ERROR (netstatus_error_quark ())
32 #define NETSTATUS_TYPE_G_ERROR (netstatus_g_error_get_type ())
33 #define NETSTATUS_TYPE_STATS (netstatus_stats_get_type ())
34
35 typedef enum {
36 NETSTATUS_STATE_DISCONNECTED = 0,
37 NETSTATUS_STATE_IDLE = 1,
38 NETSTATUS_STATE_TX = 2,
39 NETSTATUS_STATE_RX = 3,
40 NETSTATUS_STATE_TX_RX = 4,
41 NETSTATUS_STATE_ERROR = 5,
42 NETSTATUS_STATE_LAST = 6
43 } NetstatusState;
44
45 typedef enum {
46 NETSTATUS_ERROR_NONE = 0,
47 NETSTATUS_ERROR_ICONS = 1, /* Can't locate the icon files */
48 NETSTATUS_ERROR_SOCKET = 2, /* Can't open socket */
49 NETSTATUS_ERROR_STATISTICS = 3, /* Can't find statistics on the interface */
50 NETSTATUS_ERROR_IOCTL_IFFLAGS = 4, /* SIOCGIFFLAGS failed */
51 NETSTATUS_ERROR_IOCTL_IFCONF = 5, /* SIOCGIFCONF failed */
52 NETSTATUS_ERROR_NO_INTERFACES = 6, /* No interfaces found */
53 NETSTATUS_ERROR_WIRELESS_DETAILS = 7 /* Error finding wireless details
54 * (not an error if iface isn't wireless)
55 */
56 } NetstatusError;
57
58 typedef enum {
59 NETSTATUS_DEBUG_NONE = 0,
60 NETSTATUS_DEBUG_POLLING = 1 << 0
61 } NetstatusDebugFlags;
62
63 typedef struct
64 {
65 gulong in_packets;
66 gulong out_packets;
67 gulong in_bytes;
68 gulong out_bytes;
69 } NetstatusStats;
70
71 GQuark netstatus_error_quark (void);
72 GType netstatus_g_error_get_type (void);
73 GType netstatus_stats_get_type (void);
74 void netstatus_adopt_error (GError *error,
75 NetstatusError code);
76
77 const char * netstatus_get_state_string (NetstatusState state);
78
79 GList *netstatus_list_insert_unique (GList *list,
80 char *str);
81
82 void netstatus_connect_signal_while_alive (gpointer object,
83 const char *detailed_signal,
84 GCallback func,
85 gpointer func_data,
86 gpointer alive_object);
87
88 #ifdef G_ENABLE_DEBUG
89
90 #include <stdio.h>
91
92 extern NetstatusDebugFlags _netstatus_debug_flags;
93
94 #ifdef G_HAVE_ISO_VARARGS
95 # define dprintf(type, ...) G_STMT_START { \
96 if (_netstatus_debug_flags & NETSTATUS_DEBUG_##type) \
97 fprintf (stderr, __VA_ARGS__); \
98 } G_STMT_END
99 #elif defined(G_HAVE_GNUC_VARARGS)
100 # define dprintf(type, args...) G_STMT_START { \
101 if (_netstatus_debug_flags & NETSTATUS_DEBUG_##type) \
102 fprintf (stderr, args); \
103 } G_STMT_END
104 #endif
105
106 void netstatus_setup_debug_flags (void);
107
108 #else /* if !defined (G_ENABLE_DEBUG) */
109
110 #ifdef G_HAVE_ISO_VARARGS
111 # define dprintf(...)
112 #elif defined(G_HAVE_GNUC_VARARGS)
113 # define dprintf(args...)
114 #endif
115
116 #define netstatus_setup_debug_flags()
117
118 #endif /* G_ENABLE_DEBUG */
119
120 G_END_DECLS
121
122 #endif /* __NETSTATUS_UTIL_H__ */