Enlightenment CVS committal Author : devilhorns Project : e_modules Module : net
Dir : e_modules/net Modified Files: e_mod_main.h e_mod_main.c e_mod_config.c Log Message: Reworked "graphing" code to be a bit more accurate. Do not display old values from /proc/net/dev on startup. Added config value for Max MTU of devices. Added config value for always showing text or just on mouse over. Minor edc correction in script code. (read: no theme changes) Users may need to remove old module.net.cfg if your having problems after this update. =================================================================== RCS file: /cvs/e/e_modules/net/e_mod_main.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -3 -r1.9 -r1.10 --- e_mod_main.h 23 May 2006 22:07:37 -0000 1.9 +++ e_mod_main.h 25 May 2006 12:06:14 -0000 1.10 @@ -6,7 +6,7 @@ typedef struct _Config Config; typedef struct _Config_Item Config_Item; -struct _Config +struct _Config { E_Module *module; E_Config_Dialog *config_dialog; @@ -15,12 +15,13 @@ Evas_List *items; }; -struct _Config_Item +struct _Config_Item { const char *id; const char *device; double poll_time; double max; + int always_text; }; EAPI extern E_Module_Api e_modapi; =================================================================== RCS file: /cvs/e/e_modules/net/e_mod_main.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -3 -r1.28 -r1.29 --- e_mod_main.c 25 May 2006 09:01:10 -0000 1.28 +++ e_mod_main.c 25 May 2006 12:06:14 -0000 1.29 @@ -1,10 +1,11 @@ #include <e.h> #include "e_mod_main.h" +#include <math.h> typedef struct _Instance Instance; typedef struct _Net Net; -struct _Instance +struct _Instance { E_Gadcon_Client *gcc; Evas_Object *net_obj; @@ -12,7 +13,7 @@ Ecore_Timer *check_timer; }; -struct _Net +struct _Net { Instance *inst; Evas_Object *net_obj; @@ -34,8 +35,8 @@ static Config_Item *_net_config_item_get(const char *id); static Net *_net_new(Evas *evas); static void _net_free(Net *net); -static void _net_update_rx(Instance *inst, int value); -static void _net_update_tx(Instance *inst, int value); +static void _net_update_rx(void *data, int value); +static void _net_update_tx(void *data, int value); static int _net_cb_check(void *data); static E_Config_DD *conf_edd = NULL; @@ -44,14 +45,13 @@ Config *net_config = NULL; /* Define the gadcon class and functions provided by this module */ -static const E_Gadcon_Client_Class _gc_class = -{ +static const E_Gadcon_Client_Class _gc_class = { GADCON_CLIENT_CLASS_VERSION, - "net", { _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon } + "net", {_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon} }; static E_Gadcon_Client * -_gc_init(E_Gadcon *gc, char *name, char *id, char *style) +_gc_init(E_Gadcon *gc, char *name, char *id, char *style) { E_Gadcon_Client *gcc; Evas_Object *o; @@ -59,12 +59,13 @@ Config_Item *ci; Net *net; char buf[4096]; - + inst = E_NEW(Instance, 1); + ci = _net_config_item_get(id); - if (!ci->id) - ci->id = evas_stringshare_add(id); - + if (!ci->id) + ci->id = evas_stringshare_add(id); + net = _net_new(gc->evas); net->inst = inst; inst->net = net; @@ -74,40 +75,42 @@ gcc->data = inst; inst->gcc = gcc; inst->net_obj = o; + + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _net_cb_mouse_down, inst); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, - _net_cb_mouse_down, inst); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_IN, - _net_cb_mouse_in, inst); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_OUT, - _net_cb_mouse_out, inst); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_IN, _net_cb_mouse_in, inst); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_OUT, _net_cb_mouse_out, inst); - inst->check_timer = ecore_timer_add(ci->poll_time, _net_cb_check, inst); + if (ci->always_text) + edje_object_signal_emit(inst->net_obj, "label_active", ""); + + _net_cb_check(inst); + inst->check_timer = ecore_timer_add(ci->poll_time, _net_cb_check, inst); net_config->instances = evas_list_append(net_config->instances, inst); - + return gcc; } static void -_gc_orient(E_Gadcon_Client *gcc) +_gc_orient(E_Gadcon_Client *gcc) { e_gadcon_client_aspect_set(gcc, 16, 16); e_gadcon_client_min_size_set(gcc, 16, 16); } static char * -_gc_label(void) +_gc_label(void) { return D_("Net"); } static Evas_Object * -_gc_icon(Evas *evas) +_gc_icon(Evas *evas) { Evas_Object *o; char buf[4096]; - + o = edje_object_add(evas); snprintf(buf, sizeof(buf), "%s/module.eap", e_module_dir_get(net_config->module)); edje_object_file_set(o, buf, "icon"); @@ -115,20 +118,20 @@ } static void -_gc_shutdown(E_Gadcon_Client *gcc) +_gc_shutdown(E_Gadcon_Client *gcc) { Instance *inst; - + inst = gcc->data; if (inst->check_timer) - ecore_timer_del(inst->check_timer); + ecore_timer_del(inst->check_timer); net_config->instances = evas_list_remove(net_config->instances, inst); _net_free(inst->net); free(inst); } static void -_net_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) +_net_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) { Instance *inst; Evas_Event_Mouse_Down *ev; @@ -156,125 +159,132 @@ e_util_zone_current_get(e_manager_current_get()), x + ev->output.x, y + ev->output.y, 1, 1, E_MENU_POP_DIRECTION_DOWN, ev->timestamp); evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button, EVAS_BUTTON_NONE, ev->timestamp, NULL); - } + } } static void -_net_menu_cb_post(void *data, E_Menu *m) +_net_menu_cb_post(void *data, E_Menu *m) { if (!net_config->menu) - return; + return; e_object_del(E_OBJECT(net_config->menu)); net_config->menu = NULL; } static void -_net_menu_cb_configure(void *data, E_Menu *m, E_Menu_Item *mi) +_net_menu_cb_configure(void *data, E_Menu *m, E_Menu_Item *mi) { Instance *inst; Config_Item *ci; - + inst = data; ci = _net_config_item_get(inst->gcc->id); _config_net_module(ci); } void -_net_config_updated(const char *id) +_net_config_updated(const char *id) { Evas_List *l; Config_Item *ci; - + if (!net_config) - return; - + return; + ci = _net_config_item_get(id); - for (l = net_config->instances; l; l = l->next) + for (l = net_config->instances; l; l = l->next) { - Instance *inst; - - inst = l->data; - if (!inst->gcc->id) - continue; - - if (!strcmp(inst->gcc->id, ci->id)) - { - if (inst->check_timer) - ecore_timer_interval_set(inst->check_timer, (double)ci->poll_time); + Instance *inst; + + inst = l->data; + if (!inst->gcc->id) + continue; + + if (!strcmp(inst->gcc->id, ci->id)) + { + if (inst->check_timer) + ecore_timer_del(inst->check_timer); + inst->check_timer = ecore_timer_add((double)ci->poll_time, _net_cb_check, inst); + if (ci->always_text) + edje_object_signal_emit(inst->net_obj, "label_active", ""); else - inst->check_timer = ecore_timer_add((double)ci->poll_time, _net_cb_check, inst); - break; - } + edje_object_signal_emit(inst->net_obj, "label_passive", ""); + + break; + } } } static Config_Item * -_net_config_item_get(const char *id) +_net_config_item_get(const char *id) { Evas_List *l; Config_Item *ci; - - for (l = net_config->items; l; l = l->next) + + for (l = net_config->items; l; l = l->next) { - ci = l->data; - if (!ci->id) - continue; - if (!strcmp(ci->id, id)) - return ci; + ci = l->data; + if (!ci->id) + continue; + if (!strcmp(ci->id, id)) + return ci; } ci = E_NEW(Config_Item, 1); ci->id = evas_stringshare_add(id); ci->device = evas_stringshare_add("eth0"); ci->poll_time = 1.0; - ci->max = 1500; + ci->max = 1500.0; + ci->always_text = 0; net_config->items = evas_list_append(net_config->items, ci); return ci; } /* Module routines */ -EAPI E_Module_Api e_modapi = -{ +EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, - "Net" + "Net" }; EAPI void * -e_modapi_init(E_Module *m) +e_modapi_init(E_Module *m) { bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); - + conf_item_edd = E_CONFIG_DD_NEW("Net_Config_Item", Config_Item); - - #undef T - #undef D - #define T Config_Item - #define D conf_item_edd + +#undef T +#undef D +#define T Config_Item +#define D conf_item_edd E_CONFIG_VAL(D, T, id, STR); E_CONFIG_VAL(D, T, device, STR); E_CONFIG_VAL(D, T, max, DOUBLE); E_CONFIG_VAL(D, T, poll_time, DOUBLE); + E_CONFIG_VAL(D, T, always_text, INT); conf_edd = E_CONFIG_DD_NEW("Net_Config", Config); - - #undef T - #undef D - #define T Config - #define D conf_edd + +#undef T +#undef D +#define T Config +#define D conf_edd E_CONFIG_LIST(D, T, items, conf_item_edd); - + net_config = e_config_domain_load("module.net", conf_edd); - if (!net_config) + if (!net_config) { - Config_Item *ci; - - net_config = E_NEW(Config, 1); - ci = E_NEW(Config_Item, 1); - ci->id = evas_stringshare_add("0"); - ci->device = evas_stringshare_add("eth0"); - ci->poll_time = 1.0; - ci->max = 1500; - net_config->items = evas_list_append(net_config->items, ci); + Config_Item *ci; + + net_config = E_NEW(Config, 1); + ci = E_NEW(Config_Item, 1); + + ci->id = evas_stringshare_add("0"); + ci->device = evas_stringshare_add("eth0"); + ci->poll_time = 1.0; + ci->max = 1500.0; + ci->always_text = 0; + net_config->items = evas_list_append(net_config->items, ci); } net_config->module = m; e_gadcon_provider_register(&_gc_class); @@ -282,28 +292,28 @@ } EAPI int -e_modapi_shutdown(E_Module *m) +e_modapi_shutdown(E_Module *m) { net_config->module = NULL; e_gadcon_provider_unregister(&_gc_class); - + if (net_config->config_dialog) - e_object_del(E_OBJECT(net_config->config_dialog)); - if (net_config->menu) + e_object_del(E_OBJECT(net_config->config_dialog)); + if (net_config->menu) { - e_menu_post_deactivate_callback_set(net_config->menu, NULL, NULL); - e_object_del(E_OBJECT(net_config->menu)); - net_config->menu = NULL; - } - while (net_config->items) - { - Config_Item *ci; - - ci = net_config->items->data; - if (ci->id) - evas_stringshare_del(ci->id); - net_config->items = evas_list_remove_list(net_config->items, net_config->items); - free(ci); + e_menu_post_deactivate_callback_set(net_config->menu, NULL, NULL); + e_object_del(E_OBJECT(net_config->menu)); + net_config->menu = NULL; + } + while (net_config->items) + { + Config_Item *ci; + + ci = net_config->items->data; + net_config->items = evas_list_remove_list(net_config->items, net_config->items); + if (ci->id) + evas_stringshare_del(ci->id); + free(ci); } free(net_config); net_config = NULL; @@ -313,84 +323,88 @@ } EAPI int -e_modapi_info(E_Module *m) +e_modapi_info(E_Module *m) { char buf[4096]; - + snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m)); m->icon_file = strdup(buf); return 1; } EAPI int -e_modapi_save(E_Module *m) +e_modapi_save(E_Module *m) { Evas_List *l; - - for (l = net_config->instances; l; l = l->next) + + for (l = net_config->instances; l; l = l->next) { - Instance *inst; - Config_Item *ci; - - inst = l->data; - ci = _net_config_item_get(inst->gcc->id); - if (ci->id) - evas_stringshare_del(ci->id); - ci->id = evas_stringshare_add(inst->gcc->id); + Instance *inst; + Config_Item *ci; + + inst = l->data; + ci = _net_config_item_get(inst->gcc->id); + if (ci->id) + evas_stringshare_del(ci->id); + ci->id = evas_stringshare_add(inst->gcc->id); } e_config_domain_save("module.net", conf_edd, net_config); return 1; } EAPI int -e_modapi_about(E_Module *m) +e_modapi_about(E_Module *m) { - e_module_dialog_show(D_("Enlightenment Network Monitor Module"), - D_("This module is used to monitor a network device.")); + e_module_dialog_show(D_("Enlightenment Network Monitor Module"), D_("This module is used to monitor a network device.")); return 1; } static Net * -_net_new(Evas *evas) +_net_new(Evas *evas) { Net *net; char buf[4096]; - + net = E_NEW(Net, 1); + net->net_obj = edje_object_add(evas); - + snprintf(buf, sizeof(buf), "%s/net.edj", e_module_dir_get(net_config->module)); if (!e_theme_edje_object_set(net->net_obj, "base/theme/modules/net", "modules/net/main")) - edje_object_file_set(net->net_obj, buf, "modules/net/main"); + edje_object_file_set(net->net_obj, buf, "modules/net/main"); evas_object_show(net->net_obj); return net; } static void -_net_free(Net *n) +_net_free(Net *n) { evas_object_del(n->net_obj); free(n); } -static void -_net_update_rx(Instance *inst, int value) +static void +_net_update_rx(void *data, int value) { Edje_Message_Int_Set *val; + Instance *inst; + inst = data; val = malloc(sizeof(Edje_Message_Int_Set) + (1 * sizeof(int))); val->count = 1; val->val[0] = value; edje_object_message_send(inst->net_obj, EDJE_MESSAGE_INT_SET, 1, val); - free(val); + free(val); } -static void -_net_update_tx(Instance *inst, int value) +static void +_net_update_tx(void *data, int value) { Edje_Message_Int_Set *val; - + Instance *inst; + + inst = data; val = malloc(sizeof(Edje_Message_Int_Set) + (1 * sizeof(int))); val->count = 1; val->val[0] = value; @@ -398,26 +412,29 @@ free(val); } -static void -_net_cb_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info) +static void +_net_cb_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info) { Instance *inst; - - inst = data; + + inst = data; edje_object_signal_emit(inst->net_obj, "label_active", ""); } -static void -_net_cb_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info) +static void +_net_cb_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info) { Instance *inst; + Config_Item *ci; inst = data; - edje_object_signal_emit(inst->net_obj, "label_passive", ""); + ci = _net_config_item_get(inst->gcc->id); + if (!ci->always_text) + edje_object_signal_emit(inst->net_obj, "label_passive", ""); } -static int -_net_cb_check(void *data) +static int +_net_cb_check(void *data) { Instance *inst; Config_Item *ci; @@ -426,6 +443,7 @@ char buf[256]; static unsigned long old_in = 0; static unsigned long old_out = 0; + static int first_time = 1; unsigned long in = 0; unsigned long out = 0; unsigned long dummy = 0; @@ -434,14 +452,12 @@ long max_out = 28672; long bytes_in; long bytes_out; - double in_use = 0.0; - double out_use = 0.0; char in_str[100]; char out_str[100]; - + inst = data; ci = _net_config_item_get(inst->gcc->id); - + stat = fopen("/proc/net/dev", "r"); if (!stat) return 1; @@ -460,8 +476,8 @@ "%lu %lu %lu %lu\n", dev, &in, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &out, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17) continue; - if (!ci->device) - continue; + if (!ci->device) + continue; if (!strcmp(dev, ci->device)) { found = 1; @@ -473,86 +489,74 @@ if (!found) return 1; - if (old_in && old_out) - { - bytes_in = in - old_in; - bytes_out = out - old_out; - - if (bytes_in < 0) - bytes_in = 0; - if (bytes_out < 0) - bytes_out = 0; + bytes_in = in - old_in; + bytes_out = out - old_out; + if (bytes_in < 0) + bytes_in = 0; + if (bytes_out < 0) + bytes_out = 0; + + old_in = in; + old_out = out; - in_use = ((bytes_in * 100L) / max_in); - out_use = ((bytes_out * 100L) / max_out); - } - else + if (first_time) { - in_use = 0.0; - out_use = 0.0; + first_time = 0; + return 1; } - - old_in = in; - old_out = out; - + if (bytes_in <= 0) - edje_object_part_text_set(inst->net_obj, "rx_label", "Rx: 0 B"); - else + edje_object_part_text_set(inst->net_obj, "rx_label", "Rx: 0 B"); + else { if (bytes_in > 1048576) - { - bytes_in = bytes_in / 1048576; - snprintf(in_str, sizeof(in_str), "Rx: %d Mb", bytes_in); - } + snprintf(in_str, sizeof(in_str), "Rx: %d Mb", (bytes_in / 1048576)); else if (bytes_in > 1024 && bytes_in < 1048576) - { - bytes_in = bytes_in / 1024; - snprintf(in_str, sizeof(in_str), "Rx: %d Kb", bytes_in); - } + snprintf(in_str, sizeof(in_str), "Rx: %d Kb", (bytes_in / 1024)); else snprintf(in_str, sizeof(in_str), "Rx: %d B", bytes_in); - - edje_object_part_text_set(inst->net_obj, "rx_label", in_str); + + edje_object_part_text_set(inst->net_obj, "rx_label", in_str); } - - if (bytes_out <= 0) - edje_object_part_text_set(inst->net_obj, "tx_label", "Tx: 0 B"); - else + + if (bytes_out <= 0) + edje_object_part_text_set(inst->net_obj, "tx_label", "Tx: 0 B"); + else { if (bytes_out > 1048576) - { - bytes_out = bytes_out / 1048576; - snprintf(out_str, sizeof(out_str), "Tx: %d Mb", bytes_out); - } + snprintf(out_str, sizeof(out_str), "Tx: %d Mb", (bytes_out / 1048576)); else if (bytes_out > 1024 && bytes_out < 1048576) - { - bytes_out = bytes_out / 1024; - snprintf(out_str, sizeof(out_str), "Tx: %d Kb", bytes_out); - } + snprintf(out_str, sizeof(out_str), "Tx: %d Kb", (bytes_out / 1024)); else snprintf(out_str, sizeof(out_str), "Tx: %d B", bytes_out); - - edje_object_part_text_set(inst->net_obj, "tx_label", out_str); + + edje_object_part_text_set(inst->net_obj, "tx_label", out_str); } - int x, y, w, h; double i, o; - evas_object_geometry_get(inst->net_obj, &x, &y, &w, &h); - i = ((double)in_use * ((double)w / (double)100)); - o = ((double)out_use * ((double)w / (double)100)); - if (i < 0) + if (bytes_in != 0.0) + i = ((double)bytes_in / (double)ci->max); + else i = 0.0; - if (o < 0) - o = 0.0; - - if ((i > 0) && (i < 1)) - i = 10.0; - if ((o > 0) && (o < 1)) - o = 10.0; - _net_update_rx(inst, (i / 10)); - _net_update_tx(inst, (o / 10)); + if (bytes_out != 0.0) + o = ((double)bytes_out / (double)ci->max); + else + o = 0.0; + if (i < 0.0) + i = 0.0; + if (o < 0.0) + o = 0.0; + + if ((i > 0.0) && (i < 1.0)) + i = 1.0; + if ((o > 0.0) && (o < 1.0)) + o = 1.0; + + _net_update_rx(inst, i); + _net_update_tx(inst, o); + return 1; } =================================================================== RCS file: /cvs/e/e_modules/net/e_mod_config.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -3 -r1.12 -r1.13 --- e_mod_config.c 24 May 2006 20:02:51 -0000 1.12 +++ e_mod_config.c 25 May 2006 12:06:14 -0000 1.13 @@ -6,7 +6,8 @@ { char *device; double poll_time; - + int always_text; + double max; Ecore_List *devs; int dev_num; }; @@ -46,7 +47,9 @@ int i; cfdata->poll_time = ci->poll_time; - + cfdata->always_text = ci->always_text; + cfdata->max = ci->max; + if (ci->device != NULL) cfdata->device = strdup(ci->device); else @@ -82,6 +85,7 @@ ci = cfd->data; cfdata = E_NEW(E_Config_Dialog_Data, 1); + _fill_data(ci, cfdata); return cfdata; } @@ -90,7 +94,7 @@ _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) { if (!net_config) - return; + return; net_config->config_dialog = NULL; E_FREE(cfdata->device); if (cfdata->devs) @@ -107,6 +111,15 @@ int i; o = e_widget_list_add(evas, 0, 0); + + of = e_widget_framelist_add(evas, D_("General Settings"), 0); + rg = e_widget_radio_group_new(&(cfdata->always_text)); + ob = e_widget_radio_add(evas, D_("Always Show Text"), 1, rg); + e_widget_framelist_object_append(of, ob); + ob = e_widget_radio_add(evas, D_("Show Text On Mouse Over"), 0, rg); + e_widget_framelist_object_append(of, ob); + e_widget_list_object_append(o, of, 1, 1, 0.5); + of = e_widget_framelist_add(evas, D_("Device Settings"), 0); ot = e_widget_table_add(evas, 0); rg = e_widget_radio_group_new(&(cfdata->dev_num)); @@ -124,9 +137,15 @@ i++; ob = e_widget_slider_add(evas, 1, 0, _("%1.0f seconds"), 1, 60, 1, 0, &(cfdata->poll_time), NULL, 150); e_widget_table_object_append(ot, ob, 0, i, 1, 1, 1, 0, 1, 0); + i++; + ob = e_widget_label_add(evas, D_("Max MTU:")); + e_widget_table_object_append(ot, ob, 0, i, 1, 1, 0, 0, 1, 0); + i++; + ob = e_widget_slider_add(evas, 1, 0, _("%1.0f"), 100, 1500, 100, 0, &(cfdata->max), NULL, 150); + e_widget_table_object_append(ot, ob, 0, i, 1, 1, 1, 0, 1, 0); e_widget_framelist_object_append(of, ot); e_widget_list_object_append(o, of, 1, 1, 0.5); - + return o; } @@ -135,16 +154,19 @@ { char *tmp; Config_Item *ci; - + ci = cfd->data; tmp = ecore_list_goto_index(cfdata->devs, cfdata->dev_num); if (tmp != NULL) { - evas_stringshare_del(ci->device); - ci->device = evas_stringshare_add(tmp); + evas_stringshare_del(ci->device); + ci->device = evas_stringshare_add(tmp); } ci->poll_time = cfdata->poll_time; + ci->always_text = cfdata->always_text; + ci->max = cfdata->max; + e_config_save_queue(); _net_config_updated(ci->id); return 1; ------------------------------------------------------- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs