diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-08-22 12:46:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-08-22 12:46:02 +0000 |
commit | a8706543b6d37767d5ca0f90f0a334a1fb8e7ecf (patch) | |
tree | d826dc63f00b0559427a96244f019c3b5ea4172e | |
parent | afe59005c106768970ae8d195489c1899fcf6311 (diff) | |
download | gnunet-gtk-a8706543b6d37767d5ca0f90f0a334a1fb8e7ecf.tar.gz gnunet-gtk-a8706543b6d37767d5ca0f90f0a334a1fb8e7ecf.zip |
indentation, DCE
-rw-r--r-- | src/statistics/gnunet-statistics-gtk.c | 100 |
1 files changed, 61 insertions, 39 deletions
diff --git a/src/statistics/gnunet-statistics-gtk.c b/src/statistics/gnunet-statistics-gtk.c index 8ef66ac6..79d2a9a2 100644 --- a/src/statistics/gnunet-statistics-gtk.c +++ b/src/statistics/gnunet-statistics-gtk.c | |||
@@ -119,11 +119,6 @@ static int tray_only; | |||
119 | static struct GNUNET_STATISTICS_Handle *statistics; | 119 | static struct GNUNET_STATISTICS_Handle *statistics; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Task that refreshes connection graphic. | ||
123 | */ | ||
124 | static struct GNUNET_SCHEDULER_Task * connection_task; | ||
125 | |||
126 | /** | ||
127 | * When did this process start? | 122 | * When did this process start? |
128 | */ | 123 | */ |
129 | static struct GNUNET_TIME_Absolute start_time; | 124 | static struct GNUNET_TIME_Absolute start_time; |
@@ -136,20 +131,28 @@ static struct GNUNET_TIME_Absolute start_time; | |||
136 | * @param subsystem name of subsystem that created the statistic | 131 | * @param subsystem name of subsystem that created the statistic |
137 | * @param name the name of the datum | 132 | * @param name the name of the datum |
138 | * @param value the current value | 133 | * @param value the current value |
139 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | 134 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not |
140 | * @return GNUNET_OK to continue | 135 | * @return #GNUNET_OK to continue |
141 | */ | 136 | */ |
142 | static int | 137 | static int |
143 | process_value_update (void *cls, const char *subsystem, const char *name, | 138 | process_value_update (void *cls, |
144 | uint64_t value, int is_persistent) | 139 | const char *subsystem, |
140 | const char *name, | ||
141 | uint64_t value, | ||
142 | int is_persistent) | ||
145 | { | 143 | { |
146 | GtkStatistics *stats = cls; | 144 | GtkStatistics *stats = cls; |
147 | char *id; | 145 | char *id; |
148 | 146 | ||
149 | GNUNET_asprintf (&id, "%s: %s", subsystem, name); | 147 | GNUNET_asprintf (&id, |
150 | gtk_statistics_update_value (stats, id, | 148 | "%s: %s", |
149 | subsystem, | ||
150 | name); | ||
151 | gtk_statistics_update_value (stats, | ||
152 | id, | ||
151 | GNUNET_TIME_absolute_get_duration | 153 | GNUNET_TIME_absolute_get_duration |
152 | (start_time).rel_value_us / 1000000LL, value); | 154 | (start_time).rel_value_us / 1000000LL, |
155 | value); | ||
153 | GNUNET_free (id); | 156 | GNUNET_free (id); |
154 | return GNUNET_OK; | 157 | return GNUNET_OK; |
155 | } | 158 | } |
@@ -175,26 +178,39 @@ get_object (const char *name) | |||
175 | * @param info what to draw | 178 | * @param info what to draw |
176 | */ | 179 | */ |
177 | static void | 180 | static void |
178 | create_plot (const char *box_name, const struct PlotInfo *info) | 181 | create_plot (const char *box_name, |
182 | const struct PlotInfo *info) | ||
179 | { | 183 | { |
180 | GtkBox *box; | 184 | GtkBox *box; |
181 | GtkStatistics *ret; | 185 | GtkStatistics *ret; |
182 | unsigned int i; | ||
183 | char *id; | 186 | char *id; |
184 | 187 | ||
185 | ret = GTK_STATISTICS (gtk_statistics_new ()); | 188 | ret = GTK_STATISTICS (gtk_statistics_new ()); |
186 | box = GTK_BOX (get_object (box_name)); | 189 | box = GTK_BOX (get_object (box_name)); |
187 | 190 | ||
188 | for (i = 0; NULL != info[i].subsystem; i++) | 191 | for (unsigned int i = 0; NULL != info[i].subsystem; i++) |
189 | { | 192 | { |
190 | GNUNET_asprintf (&id, "%s: %s", info[i].subsystem, info[i].name); | 193 | GNUNET_asprintf (&id, |
191 | gtk_statistics_add_line (ret, id, info[i].label, info[i].color_name); | 194 | "%s: %s", |
195 | info[i].subsystem, | ||
196 | info[i].name); | ||
197 | gtk_statistics_add_line (ret, | ||
198 | id, | ||
199 | info[i].label, | ||
200 | info[i].color_name); | ||
192 | GNUNET_free (id); | 201 | GNUNET_free (id); |
193 | GNUNET_STATISTICS_watch (statistics, info[i].subsystem, info[i].name, | 202 | GNUNET_STATISTICS_watch (statistics, |
194 | &process_value_update, ret); | 203 | info[i].subsystem, |
204 | info[i].name, | ||
205 | &process_value_update, | ||
206 | ret); | ||
195 | } | 207 | } |
196 | gtk_widget_show (GTK_WIDGET (ret)); | 208 | gtk_widget_show (GTK_WIDGET (ret)); |
197 | gtk_box_pack_start (box, GTK_WIDGET (ret), TRUE, TRUE, 0); | 209 | gtk_box_pack_start (box, |
210 | GTK_WIDGET (ret), | ||
211 | TRUE, | ||
212 | TRUE, | ||
213 | 0); | ||
198 | } | 214 | } |
199 | 215 | ||
200 | 216 | ||
@@ -209,13 +225,9 @@ shutdown_task (void *cls) | |||
209 | GNUNET_GTK_tray_icon_destroy (); | 225 | GNUNET_GTK_tray_icon_destroy (); |
210 | GNUNET_GTK_main_loop_quit (ml); | 226 | GNUNET_GTK_main_loop_quit (ml); |
211 | ml = NULL; | 227 | ml = NULL; |
212 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); | 228 | GNUNET_STATISTICS_destroy (statistics, |
229 | GNUNET_NO); | ||
213 | statistics = NULL; | 230 | statistics = NULL; |
214 | if (connection_task != NULL) | ||
215 | { | ||
216 | GNUNET_SCHEDULER_cancel (connection_task); | ||
217 | connection_task = NULL; | ||
218 | } | ||
219 | } | 231 | } |
220 | 232 | ||
221 | 233 | ||
@@ -223,7 +235,8 @@ shutdown_task (void *cls) | |||
223 | * Callback invoked if the application is supposed to exit. | 235 | * Callback invoked if the application is supposed to exit. |
224 | */ | 236 | */ |
225 | void | 237 | void |
226 | GNUNET_STATISTICS_GTK_quit_cb (GObject * object, gpointer user_data) | 238 | GNUNET_STATISTICS_GTK_quit_cb (GObject *object, |
239 | gpointer user_data) | ||
227 | { | 240 | { |
228 | GNUNET_SCHEDULER_shutdown (); | 241 | GNUNET_SCHEDULER_shutdown (); |
229 | } | 242 | } |
@@ -240,13 +253,15 @@ run (void *cls) | |||
240 | 253 | ||
241 | ml = cls; | 254 | ml = cls; |
242 | 255 | ||
243 | if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL)) | 256 | if (GNUNET_OK != |
257 | GNUNET_GTK_main_loop_build_window (ml, | ||
258 | NULL)) | ||
244 | { | 259 | { |
245 | return; | 260 | return; |
246 | } | 261 | } |
247 | 262 | ||
248 | statistics = | 263 | statistics |
249 | GNUNET_STATISTICS_create ("gnunet-statistics-gtk", | 264 | = GNUNET_STATISTICS_create ("gnunet-statistics-gtk", |
250 | GNUNET_GTK_main_loop_get_configuration (ml)); | 265 | GNUNET_GTK_main_loop_get_configuration (ml)); |
251 | if (NULL == statistics) | 266 | if (NULL == statistics) |
252 | { | 267 | { |
@@ -265,25 +280,30 @@ run (void *cls) | |||
265 | if (NULL == getenv ("GNUNET_STATISTICS_GTK_PLUG")) | 280 | if (NULL == getenv ("GNUNET_STATISTICS_GTK_PLUG")) |
266 | GNUNET_GTK_tray_icon_create (ml, | 281 | GNUNET_GTK_tray_icon_create (ml, |
267 | GTK_WINDOW (main_window), | 282 | GTK_WINDOW (main_window), |
268 | "gnunet-gtk" /* FIXME: different icon? */ , | 283 | "gnunet-gtk" /* FIXME: different icon? */, |
269 | "gnunet-statistics-gtk"); | 284 | "gnunet-statistics-gtk"); |
270 | 285 | ||
271 | create_plot ("GNUNET_STATISTICS_GTK_connectivity_box", connection_data); | 286 | create_plot ("GNUNET_STATISTICS_GTK_connectivity_box", |
272 | create_plot ("GNUNET_STATISTICS_GTK_traffic_box", traffic_data); | 287 | connection_data); |
273 | create_plot ("GNUNET_STATISTICS_GTK_storage_box", storage_data); | 288 | create_plot ("GNUNET_STATISTICS_GTK_traffic_box", |
289 | traffic_data); | ||
290 | create_plot ("GNUNET_STATISTICS_GTK_storage_box", | ||
291 | storage_data); | ||
274 | 292 | ||
275 | /* make GUI visible */ | 293 | /* make GUI visible */ |
276 | if (!tray_only) | 294 | if (! tray_only) |
277 | { | 295 | { |
278 | gtk_widget_show (main_window); | 296 | gtk_widget_show (main_window); |
279 | gtk_window_present (GTK_WINDOW (main_window)); | 297 | gtk_window_present (GTK_WINDOW (main_window)); |
280 | } | 298 | } |
281 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 299 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
300 | NULL); | ||
282 | } | 301 | } |
283 | 302 | ||
284 | 303 | ||
285 | int | 304 | int |
286 | main (int argc, char *const *argv) | 305 | main (int argc, |
306 | char *const *argv) | ||
287 | { | 307 | { |
288 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 308 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
289 | {'t', "tray", NULL, | 309 | {'t', "tray", NULL, |
@@ -295,8 +315,10 @@ main (int argc, char *const *argv) | |||
295 | start_time = GNUNET_TIME_absolute_get (); | 315 | start_time = GNUNET_TIME_absolute_get (); |
296 | if (GNUNET_OK != | 316 | if (GNUNET_OK != |
297 | GNUNET_GTK_main_loop_start ("gnunet-statistics-gtk", | 317 | GNUNET_GTK_main_loop_start ("gnunet-statistics-gtk", |
298 | "GTK GUI for viewing GNUnet statistics", argc, | 318 | "GTK GUI for viewing GNUnet statistics", |
299 | argv, options, | 319 | argc, |
320 | argv, | ||
321 | options, | ||
300 | "gnunet_statistics_gtk_main_window.glade", | 322 | "gnunet_statistics_gtk_main_window.glade", |
301 | &run)) | 323 | &run)) |
302 | return 1; | 324 | return 1; |