-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgkrellm-wifi.c
162 lines (123 loc) · 5 KB
/
gkrellm-wifi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* gkrellm-wifi - A wireless link monitor plug-in for GKrellM2
*
* Copyright (C) 2003 Henrik Brix Andersen <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "gkrellm-wifi.h"
#include "gkrellm-wifi-chart.h"
#include "gkrellm-wifi-linux.h"
#include "gkrellm-wifi-preferences.h"
#define PLUGIN_PLACEMENT MON_NET | MON_INSERT_AFTER
#define STYLE_NAME GKRELLM_WIFI_PLUGIN_NAME
/* prototypes */
static void gkrellm_wifi_create (GtkWidget *vbox,
gint first_create);
static void gkrellm_wifi_update (void);
/* global variables */
GkrellmMonitor *gkrellm_wifi;
gint gkrellm_wifi_style_id;
GtkWidget *gkrellm_wifi_vbox;
GkrellmTicks *gkrellm_wifi_ticks;
gchar *gkrellm_wifi_format_string;
GList *gkrellm_wifi_monitor_list = NULL;
/* public function */
GkrellmMonitor *
gkrellm_init_plugin (void)
{
static GkrellmMonitor plugin_mon = {
N_("WiFi Monitor"), /* name, for config tab */
0, /* id, 0 if a plugin */
gkrellm_wifi_create, /* the create_plugin() function */
gkrellm_wifi_update, /* the update_plugin() function */
gkrellm_wifi_preferences_show, /* the create_plugin_tab() config function */
gkrellm_wifi_preferences_apply, /* the apply_plugin_config() function */
gkrellm_wifi_preferences_save, /* the save_plugin_config() function */
gkrellm_wifi_preferences_load, /* the load_plugin_config() function */
GKRELLM_WIFI_PLUGIN_KEYWORD, /* config keyword */
NULL, /* undefined 2 */
NULL, /* undefined 1 */
NULL, /* undefined 0 */
PLUGIN_PLACEMENT, /* insert plugin before this monitor */
NULL, /* handle if a plugin, filled in by GKrellM */
NULL /* path if a plugin, filled in by GKrellM */
};
gkrellm_wifi_format_string = g_strdup (GKRELLM_WIFI_DEFAULT_FORMAT_STRING);
gkrellm_wifi_ticks = gkrellm_ticks ();
gkrellm_wifi_style_id = gkrellm_add_chart_style (&plugin_mon, STYLE_NAME);
gkrellm_wifi = &plugin_mon;
return gkrellm_wifi;
}
/* private functions */
static void
gkrellm_wifi_create (GtkWidget *vbox,
gint first_create)
{
GkrellmWifiMonitor *wifimon;
GList *list;
g_assert (vbox != NULL);
if (first_create)
gkrellm_wifi_vbox = vbox;
for (list = gkrellm_wifi_monitor_list; list; list = g_list_next (list))
{
wifimon = list->data;
if (wifimon->chart)
{
gkrellm_wifi_chart_create (wifimon);
gkrellm_refresh_chart (wifimon->chart);
}
}
}
static void
gkrellm_wifi_update (void)
{
GkrellmWifiMonitor *wifimon;
GList *list;
if (gkrellm_wifi_ticks->second_tick)
{
gkrellm_wifi_wireless_info_read ();
for (list = gkrellm_wifi_monitor_list; list; list = g_list_next (list))
{
wifimon = list->data;
if ((wifimon->enabled && wifimon->updated) ||
(wifimon->enabled && wifimon->forced))
{
if (! wifimon->chart)
gkrellm_wifi_chart_create (wifimon);
if (! wifimon->updated)
{
wifimon->quality = 0;
wifimon->quality_max = 0;
wifimon->signal = 0;
wifimon->noise = 0;
wifimon->bitrate = 0;
wifimon->percent = 0;
if (wifimon->essid)
g_free (wifimon->essid);
wifimon->essid = g_strdup (_("n/a"));;
}
gkrellm_store_chartdata (wifimon->chart, 0, wifimon->percent);
gkrellm_refresh_chart (wifimon->chart);
gkrellm_check_alert (wifimon->alert, wifimon->percent);
wifimon->updated = FALSE;
}
else if (wifimon->chart)
{
gkrellm_chart_destroy (wifimon->chart);
wifimon->chart = NULL;
}
}
}
}