Sysinfo Gadget: More thread vs object lifetime work: Make threads no longer dependent on the main loop objects and vice versa.

This commit is contained in:
Stephen 'Okra' Houston 2017-07-15 21:31:06 -05:00
parent 139045c120
commit 5370793399
25 changed files with 346 additions and 696 deletions

View File

@ -617,19 +617,6 @@ sysinfo_batman_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNU
(void) inst; (void) inst;
_batman_fallback_stop(); _batman_fallback_stop();
#endif #endif
inst->cfg->batman.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->memusage.done && inst->cfg->thermal.done &&
inst->cfg->netstatus.done && inst->cfg->cpuclock.done && inst->cfg->cpumonitor.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
} }
static void static void
@ -678,7 +665,6 @@ sysinfo_batman_create(Evas_Object *parent, Instance *inst)
inst->cfg->batman.time_left = -2; inst->cfg->batman.time_left = -2;
inst->cfg->batman.have_battery = -2; inst->cfg->batman.have_battery = -2;
inst->cfg->batman.have_power = -2; inst->cfg->batman.have_power = -2;
inst->cfg->batman.done = EINA_FALSE;
inst->cfg->batman.o_gadget = elm_layout_add(parent); inst->cfg->batman.o_gadget = elm_layout_add(parent);
e_theme_edje_object_set(inst->cfg->batman.o_gadget, "base/theme/gadget/batman", e_theme_edje_object_set(inst->cfg->batman.o_gadget, "base/theme/gadget/batman",
@ -750,7 +736,6 @@ batman_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_UNU
inst = E_NEW(Instance, 1); inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id); inst->cfg = _conf_item_get(id);
*id = inst->cfg->id; *id = inst->cfg->id;
inst->cfg->batman.done = EINA_FALSE;
inst->o_main = elm_box_add(parent); inst->o_main = elm_box_add(parent);
E_EXPAND(inst->o_main); E_EXPAND(inst->o_main);
evas_object_data_set(inst->o_main, "Instance", inst); evas_object_data_set(inst->o_main, "Instance", inst);

View File

@ -7,7 +7,7 @@ _config_close(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
Instance *inst = bc->inst; Instance *inst = bc->inst;
E_FREE_FUNC(inst->cfg->batman.configure, evas_object_del); E_FREE_FUNC(inst->cfg->batman.configure, evas_object_del);
E_FREE_FUNC(bc, free); E_FREE(bc);
e_config_save_queue(); e_config_save_queue();
} }

View File

@ -277,8 +277,8 @@ linux_sys_class_power_supply_cb_re_init(void *data)
// if (sysev->fd_handler) // if (sysev->fd_handler)
// ecore_main_fd_handler_del(sysev->fd_handler); // ecore_main_fd_handler_del(sysev->fd_handler);
// if (sysev->fd >= 0) close(sysev->fd); // if (sysev->fd >= 0) close(sysev->fd);
free(sysev->name); E_FREE(sysev->name);
free(sysev); E_FREE(sysev);
} }
} }
linux_sys_class_power_supply_init(); linux_sys_class_power_supply_init();
@ -319,8 +319,8 @@ linux_sys_class_power_supply_cb_event_fd_active(void *data,
// if (sysev->fd_handler) // if (sysev->fd_handler)
// ecore_main_fd_handler_del(sysev->fd_handler); // ecore_main_fd_handler_del(sysev->fd_handler);
// if (sysev->fd >= 0) close(sysev->fd); // if (sysev->fd >= 0) close(sysev->fd);
free(sysev->name); E_FREE(sysev->name);
free(sysev); E_FREE(sysev);
if (re_init_timer) ecore_timer_del(re_init_timer); if (re_init_timer) ecore_timer_del(re_init_timer);
re_init_timer = ecore_timer_loop_add(1.0, linux_sys_class_power_supply_cb_re_init, NULL); re_init_timer = ecore_timer_loop_add(1.0, linux_sys_class_power_supply_cb_re_init, NULL);
@ -476,7 +476,7 @@ linux_sys_class_power_supply_init(void)
if (!(linux_sys_class_power_supply_is_battery(name))) if (!(linux_sys_class_power_supply_is_battery(name)))
{ {
free(name); E_FREE(name);
continue; continue;
} }
sysev = (Sys_Class_Power_Supply_Uevent *)calloc(1, sizeof(Sys_Class_Power_Supply_Uevent)); sysev = (Sys_Class_Power_Supply_Uevent *)calloc(1, sizeof(Sys_Class_Power_Supply_Uevent));
@ -573,7 +573,7 @@ linux_sys_class_power_supply_check(void)
full = 1; full = 1;
charging = 0; charging = 0;
} }
free(tmp); E_FREE(tmp);
} }
/* some batteries can/will/want to predict how long they will /* some batteries can/will/want to predict how long they will
* last. if so - take what the battery says. too bad if it's * last. if so - take what the battery says. too bad if it's
@ -825,7 +825,7 @@ linux_acpi_init(void)
if (tmp) if (tmp)
{ {
if (!strcmp(tmp, "on-line")) have_power = 1; if (!strcmp(tmp, "on-line")) have_power = 1;
free(tmp); E_FREE(tmp);
} }
fclose(f); fclose(f);
} }
@ -853,7 +853,7 @@ linux_acpi_init(void)
if (tmp) if (tmp)
{ {
if (!strcmp(tmp, "yes")) have_battery = 1; if (!strcmp(tmp, "yes")) have_battery = 1;
free(tmp); E_FREE(tmp);
} }
/* design cap */ /* design cap */
tmp = fgets(buf, sizeof(buf), f); tmp = fgets(buf, sizeof(buf), f);
@ -861,7 +861,7 @@ linux_acpi_init(void)
if (tmp) if (tmp)
{ {
if (strcmp(tmp, "unknown")) acpi_max_design += atoi(tmp); if (strcmp(tmp, "unknown")) acpi_max_design += atoi(tmp);
free(tmp); E_FREE(tmp);
} }
/* last full cap */ /* last full cap */
tmp = fgets(buf, sizeof(buf), f); tmp = fgets(buf, sizeof(buf), f);
@ -869,7 +869,7 @@ linux_acpi_init(void)
if (tmp) if (tmp)
{ {
if (strcmp(tmp, "unknown")) acpi_max_full += atoi(tmp); if (strcmp(tmp, "unknown")) acpi_max_full += atoi(tmp);
free(tmp); E_FREE(tmp);
} }
fclose(f); fclose(f);
} }
@ -930,34 +930,34 @@ linux_acpi_check(void)
FILE *f; FILE *f;
snprintf(buf, sizeof(buf), "/proc/acpi/battery/%s/state", name); snprintf(buf, sizeof(buf), "/proc/acpi/battery/%s/state", name);
free(name); E_FREE(name);
f = fopen(buf, "r"); f = fopen(buf, "r");
if (!f) continue; if (!f) continue;
tmp = file_str_entry_get(f, "present:"); tmp = file_str_entry_get(f, "present:");
if (!tmp) goto fclose_and_continue; if (!tmp) goto fclose_and_continue;
if (!strcasecmp(tmp, "yes")) have_battery = 1; if (!strcasecmp(tmp, "yes")) have_battery = 1;
free(tmp); E_FREE(tmp);
tmp = file_str_entry_get(f, "capacity state:"); tmp = file_str_entry_get(f, "capacity state:");
if (!tmp) goto fclose_and_continue; if (!tmp) goto fclose_and_continue;
free(tmp); E_FREE(tmp);
tmp = file_str_entry_get(f, "charging state:"); tmp = file_str_entry_get(f, "charging state:");
if (!tmp) goto fclose_and_continue; if (!tmp) goto fclose_and_continue;
if ((have_power == 0) && (!strcasecmp(tmp, "charging"))) if ((have_power == 0) && (!strcasecmp(tmp, "charging")))
have_power = 1; have_power = 1;
free(tmp); E_FREE(tmp);
tmp = file_str_entry_get(f, "present rate:"); tmp = file_str_entry_get(f, "present rate:");
if (!tmp) goto fclose_and_continue; if (!tmp) goto fclose_and_continue;
if (strcasecmp(tmp, "unknown")) rate += atoi(tmp); if (strcasecmp(tmp, "unknown")) rate += atoi(tmp);
free(tmp); E_FREE(tmp);
tmp = file_str_entry_get(f, "remaining capacity:"); tmp = file_str_entry_get(f, "remaining capacity:");
if (!tmp) goto fclose_and_continue; if (!tmp) goto fclose_and_continue;
if (strcasecmp(tmp, "unknown")) capacity += atoi(tmp); if (strcasecmp(tmp, "unknown")) capacity += atoi(tmp);
free(tmp); E_FREE(tmp);
fclose_and_continue: fclose_and_continue:
fclose(f); fclose(f);
@ -1182,7 +1182,7 @@ fclose_and_continue:
} }
} }
free(name); E_FREE(name);
} }
if (max_charge > 0) battery_full = ((long long)charge * 100) / max_charge; if (max_charge > 0) battery_full = ((long long)charge * 100) / max_charge;
else battery_full = 0; else battery_full = 0;
@ -1251,7 +1251,7 @@ dir_has_contents(const char *dir)
count = eina_list_count(bats); count = eina_list_count(bats);
EINA_LIST_FREE(bats, file) EINA_LIST_FREE(bats, file)
free(file); E_FREE(file);
if (count > 0) return 1; if (count > 0) return 1;
return 0; return 0;
} }

View File

@ -144,8 +144,8 @@ _batman_sysctl_stop(void)
EINA_LIST_FREE(batman_device_ac_adapters, ac) EINA_LIST_FREE(batman_device_ac_adapters, ac)
{ {
E_FREE_FUNC(ac->udi, eina_stringshare_del); E_FREE_FUNC(ac->udi, eina_stringshare_del);
E_FREE_FUNC(ac->mib, free); E_FREE(ac->mib);
E_FREE_FUNC(ac, free); E_FREE(ac);
} }
EINA_LIST_FREE(batman_device_batteries, bat) EINA_LIST_FREE(batman_device_batteries, bat)
@ -156,12 +156,12 @@ _batman_sysctl_stop(void)
E_FREE_FUNC(bat->vendor, eina_stringshare_del); E_FREE_FUNC(bat->vendor, eina_stringshare_del);
E_FREE_FUNC(bat->poll, ecore_poller_del); E_FREE_FUNC(bat->poll, ecore_poller_del);
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
E_FREE_FUNC(bat->mib_state, free); E_FREE(bat->mib_state);
E_FREE_FUNC(bat->mib_time, free); E_FREE(bat->mib_time);
E_FREE_FUNC(bat->mib_units, free); E_FREE(bat->mib_units);
#endif #endif
E_FREE_FUNC(bat->mib, free); E_FREE(bat->mib);
E_FREE_FUNC(bat, free); E_FREE(bat);
} }
} }

View File

@ -50,7 +50,7 @@ _batman_udev_stop(Instance *inst)
EINA_LIST_FREE(batman_device_ac_adapters, ac) EINA_LIST_FREE(batman_device_ac_adapters, ac)
{ {
E_FREE_FUNC(ac, free); E_FREE(ac);
} }
EINA_LIST_FREE(batman_device_batteries, bat) EINA_LIST_FREE(batman_device_batteries, bat)
{ {
@ -59,7 +59,7 @@ _batman_udev_stop(Instance *inst)
eina_stringshare_del(bat->model); eina_stringshare_del(bat->model);
eina_stringshare_del(bat->vendor); eina_stringshare_del(bat->vendor);
E_FREE_FUNC(bat->poll, ecore_poller_del); E_FREE_FUNC(bat->poll, ecore_poller_del);
E_FREE_FUNC(bat, free); E_FREE(bat);
} }
} }
@ -190,7 +190,7 @@ _batman_udev_battery_del(const char *syspath, Instance *inst)
eina_stringshare_del(bat->model); eina_stringshare_del(bat->model);
eina_stringshare_del(bat->vendor); eina_stringshare_del(bat->vendor);
E_FREE_FUNC(bat->poll, ecore_poller_del); E_FREE_FUNC(bat->poll, ecore_poller_del);
E_FREE_FUNC(bat, free); E_FREE(bat);
} }
} }
eina_stringshare_del(syspath); eina_stringshare_del(syspath);
@ -214,7 +214,7 @@ _batman_udev_ac_del(const char *syspath, Instance *inst)
{ {
batman_device_ac_adapters = eina_list_remove_list(batman_device_ac_adapters, l); batman_device_ac_adapters = eina_list_remove_list(batman_device_ac_adapters, l);
eina_stringshare_del(ac->udi); eina_stringshare_del(ac->udi);
E_FREE_FUNC(ac, free); E_FREE(ac);
} }
} }
eina_stringshare_del(syspath); eina_stringshare_del(syspath);

View File

@ -31,7 +31,7 @@ _battery_free(Battery *bat)
eina_stringshare_del(bat->model); eina_stringshare_del(bat->model);
if (bat->vendor) if (bat->vendor)
eina_stringshare_del(bat->vendor); eina_stringshare_del(bat->vendor);
free(bat); E_FREE(bat);
} }
static void static void
@ -43,7 +43,7 @@ _ac_free(Ac_Adapter *ac)
batman_device_ac_adapters = eina_list_remove(batman_device_ac_adapters, ac); batman_device_ac_adapters = eina_list_remove(batman_device_ac_adapters, ac);
eina_stringshare_del(ac->udi); eina_stringshare_del(ac->udi);
free(ac); E_FREE(ac);
} }
static void static void
@ -244,7 +244,7 @@ _device_type_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending E
else else
goto error; goto error;
free(ud); E_FREE(ud);
return; return;
@ -252,7 +252,7 @@ error:
obj = eldbus_proxy_object_get(ud->proxy); obj = eldbus_proxy_object_get(ud->proxy);
eldbus_proxy_unref(ud->proxy); eldbus_proxy_unref(ud->proxy);
eldbus_object_unref(obj); eldbus_object_unref(obj);
free(ud); E_FREE(ud);
return; return;
} }

View File

@ -44,16 +44,16 @@ _cpuclock_status_free(Cpu_Status *s)
{ {
Eina_List *l; Eina_List *l;
if (s->frequencies) eina_list_free(s->frequencies); if (eina_list_count(s->frequencies)) eina_list_free(s->frequencies);
if (s->governors) if (s->governors)
{ {
for (l = s->governors; l; l = l->next) for (l = s->governors; l; l = l->next)
E_FREE_FUNC(l->data, free); E_FREE(l->data);
eina_list_free(s->governors); eina_list_free(s->governors);
} }
E_FREE_FUNC(s->cur_governor, free); E_FREE(s->cur_governor);
if (s->orig_governor) eina_stringshare_del(s->orig_governor); if (s->orig_governor) eina_stringshare_del(s->orig_governor);
E_FREE_FUNC(s, free); E_FREE(s);
} }
static int static int
@ -370,7 +370,7 @@ _cpuclock_config_updated(Instance *inst)
for (l = inst->cfg->cpuclock.status->frequencies, i = 0; l; l = l->next, i++) for (l = inst->cfg->cpuclock.status->frequencies, i = 0; l; l = l->next, i++)
frequency_msg->val[i] = (long)l->data; frequency_msg->val[i] = (long)l->data;
edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_INT_SET, 1, frequency_msg); edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_INT_SET, 1, frequency_msg);
free(frequency_msg); E_FREE(frequency_msg);
} }
if (inst->cfg->cpuclock.status->governors) if (inst->cfg->cpuclock.status->governors)
@ -381,7 +381,7 @@ _cpuclock_config_updated(Instance *inst)
for (l = inst->cfg->cpuclock.status->governors, i = 0; l; l = l->next, i++) for (l = inst->cfg->cpuclock.status->governors, i = 0; l; l = l->next, i++)
governor_msg->str[i] = (char *)l->data; governor_msg->str[i] = (char *)l->data;
edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_STRING_SET, 2, governor_msg); edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_STRING_SET, 2, governor_msg);
free(governor_msg); E_FREE(governor_msg);
} }
_cpuclock_poll_interval_update(inst); _cpuclock_poll_interval_update(inst);
} }
@ -402,7 +402,7 @@ _cpuclock_face_update_current(Instance *inst)
frequency_msg->val[4] = 0; // pad frequency_msg->val[4] = 0; // pad
edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_INT_SET, 3, edje_object_message_send(elm_layout_edje_get(inst->cfg->cpuclock.o_gadget), EDJE_MESSAGE_INT_SET, 3,
frequency_msg); frequency_msg);
free(frequency_msg); E_FREE(frequency_msg);
/* BSD crashes here without the if-condition /* BSD crashes here without the if-condition
* since it has no governors (yet) */ * since it has no governors (yet) */
@ -499,7 +499,7 @@ _cpuclock_status_check_available(Cpu_Status *s)
if (s->governors) if (s->governors)
{ {
for (l = s->governors; l; l = l->next) for (l = s->governors; l; l = l->next)
free(l->data); E_FREE(l->data);
eina_list_free(s->governors); eina_list_free(s->governors);
s->governors = NULL; s->governors = NULL;
} }
@ -586,7 +586,7 @@ _cpuclock_status_check_available(Cpu_Status *s)
if (s->governors) if (s->governors)
{ {
for (l = s->governors; l; l = l->next) for (l = s->governors; l; l = l->next)
free(l->data); E_FREE(l->data);
eina_list_free(s->governors); eina_list_free(s->governors);
s->governors = NULL; s->governors = NULL;
} }
@ -749,7 +749,7 @@ _cpuclock_status_check_current(Cpu_Status *s)
{ {
ret = 1; ret = 1;
free(s->cur_governor); E_FREE(s->cur_governor);
s->cur_governor = strdup(buf); s->cur_governor = strdup(buf);
for (i = strlen(s->cur_governor) - 1; i >= 0; i--) for (i = strlen(s->cur_governor) - 1; i >= 0; i--)
@ -845,37 +845,36 @@ _cpuclock_cb_frequency_check_notify(void *data,
Eina_Bool freq_changed = EINA_FALSE; Eina_Bool freq_changed = EINA_FALSE;
Eina_Bool init_set = EINA_FALSE; Eina_Bool init_set = EINA_FALSE;
Thread_Config *thc = data; Thread_Config *thc = data;
Instance *inst = thc->inst;
if (!inst->cfg) return; if (!thc->inst && !thc->inst->cfg) return;
if (inst->cfg->esm != E_SYSINFO_MODULE_CPUCLOCK && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return; if (thc->inst->cfg->esm != E_SYSINFO_MODULE_CPUCLOCK && thc->inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
if ((inst->cfg->cpuclock.status) && (status) && if ((thc->inst->cfg->cpuclock.status) && (status) &&
( (
#if defined(__OpenBSD__) #if defined(__OpenBSD__)
(status->cur_percent != inst->cfg->cpuclock.status->cur_percent ) || (status->cur_percent != thc->inst->cfg->cpuclock.status->cur_percent ) ||
#endif #endif
(status->cur_frequency != inst->cfg->cpuclock.status->cur_frequency ) || (status->cur_frequency != thc->inst->cfg->cpuclock.status->cur_frequency ) ||
(status->cur_min_frequency != inst->cfg->cpuclock.status->cur_min_frequency) || (status->cur_min_frequency != thc->inst->cfg->cpuclock.status->cur_min_frequency) ||
(status->cur_max_frequency != inst->cfg->cpuclock.status->cur_max_frequency) || (status->cur_max_frequency != thc->inst->cfg->cpuclock.status->cur_max_frequency) ||
(status->can_set_frequency != inst->cfg->cpuclock.status->can_set_frequency))) (status->can_set_frequency != thc->inst->cfg->cpuclock.status->can_set_frequency)))
freq_changed = EINA_TRUE; freq_changed = EINA_TRUE;
E_FREE_FUNC(inst->cfg->cpuclock.status, _cpuclock_status_free); E_FREE_FUNC(thc->inst->cfg->cpuclock.status, _cpuclock_status_free);
inst->cfg->cpuclock.status = status; thc->inst->cfg->cpuclock.status = status;
if (freq_changed) if (freq_changed)
{ {
_cpuclock_face_update_current(inst); _cpuclock_face_update_current(thc->inst);
} }
if (inst->cfg->cpuclock.status->active == 0) if (thc->inst->cfg->cpuclock.status->active == 0)
elm_layout_signal_emit(inst->cfg->cpuclock.o_gadget, "e,state,disabled", "e"); elm_layout_signal_emit(thc->inst->cfg->cpuclock.o_gadget, "e,state,disabled", "e");
else if (inst->cfg->cpuclock.status->active == 1) else if (thc->inst->cfg->cpuclock.status->active == 1)
elm_layout_signal_emit(inst->cfg->cpuclock.o_gadget, "e,state,enabled", "e"); elm_layout_signal_emit(thc->inst->cfg->cpuclock.o_gadget, "e,state,enabled", "e");
if (!init_set) if (!init_set)
{ {
_cpuclock_set_pstate(inst->cfg->cpuclock.pstate_min - 1, _cpuclock_set_pstate(thc->inst->cfg->cpuclock.pstate_min - 1,
inst->cfg->cpuclock.pstate_max - 1, thc->inst->cfg->cpuclock.pstate_max - 1,
inst->cfg->cpuclock.status->pstate_turbo); thc->inst->cfg->cpuclock.status->pstate_turbo);
init_set = EINA_TRUE; init_set = EINA_TRUE;
} }
} }
@ -884,38 +883,9 @@ static void
_cpuclock_cb_frequency_check_end(void *data, Ecore_Thread *th EINA_UNUSED) _cpuclock_cb_frequency_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
{ {
Thread_Config *thc = data; Thread_Config *thc = data;
e_powersave_sleeper_free(thc->sleeper); e_powersave_sleeper_free(thc->sleeper);
if (thc->inst->cfg->cpuclock.defer) E_FREE(thc);
{
if (thc->inst->cfg->cpuclock.handler)
ecore_event_handler_del(thc->inst->cfg->cpuclock.handler);
if (thc->inst->cfg->cpuclock.governor)
eina_stringshare_del(thc->inst->cfg->cpuclock.governor);
E_FREE_FUNC(thc->inst->cfg->cpuclock.status, _cpuclock_status_free);
thc->inst->cfg->cpuclock.defer = EINA_FALSE;
thc->inst->cfg->cpuclock.done = EINA_TRUE;
if (thc->inst->cfg->esm == E_SYSINFO_MODULE_CPUCLOCK)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
else
{
if (thc->inst->cfg->memusage.done && thc->inst->cfg->thermal.done &&
thc->inst->cfg->netstatus.done && thc->inst->cfg->cpumonitor.done && thc->inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
}
}
E_FREE_FUNC(thc, free);
} }
EINTERN void EINTERN void
@ -987,13 +957,10 @@ _cpuclock_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
_cpuclock_removed_cb, inst); _cpuclock_removed_cb, inst);
if (inst->cfg->cpuclock.frequency_check_thread) if (inst->cfg->cpuclock.frequency_check_thread)
{ {
inst->cfg->cpuclock.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->cpuclock.frequency_check_thread); ecore_thread_cancel(inst->cfg->cpuclock.frequency_check_thread);
inst->cfg->cpuclock.frequency_check_thread = NULL; inst->cfg->cpuclock.frequency_check_thread = NULL;
return; return;
} }
if (inst->cfg->cpuclock.handler)
ecore_event_handler_del(inst->cfg->cpuclock.handler);
if (inst->cfg->cpuclock.governor) if (inst->cfg->cpuclock.governor)
eina_stringshare_del(inst->cfg->cpuclock.governor); eina_stringshare_del(inst->cfg->cpuclock.governor);
E_FREE_FUNC(inst->cfg->cpuclock.status, _cpuclock_status_free); E_FREE_FUNC(inst->cfg->cpuclock.status, _cpuclock_status_free);
@ -1021,31 +988,13 @@ sysinfo_cpuclock_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_U
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
if (inst->cfg->cpuclock.frequency_check_thread) if (inst->cfg->cpuclock.frequency_check_thread)
{ {
inst->cfg->cpuclock.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->cpuclock.frequency_check_thread); ecore_thread_cancel(inst->cfg->cpuclock.frequency_check_thread);
inst->cfg->cpuclock.frequency_check_thread = NULL; inst->cfg->cpuclock.frequency_check_thread = NULL;
return;
} }
if (inst->cfg->cpuclock.handler)
ecore_event_handler_del(inst->cfg->cpuclock.handler);
if (inst->cfg->cpuclock.governor) if (inst->cfg->cpuclock.governor)
eina_stringshare_del(inst->cfg->cpuclock.governor); eina_stringshare_del(inst->cfg->cpuclock.governor);
E_FREE_FUNC(inst->cfg->cpuclock.status, _cpuclock_status_free); E_FREE_FUNC(inst->cfg->cpuclock.status, _cpuclock_status_free);
inst->cfg->cpuclock.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->memusage.done && inst->cfg->thermal.done &&
inst->cfg->netstatus.done && inst->cfg->cpumonitor.done && inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
} }
static void static void
@ -1084,13 +1033,13 @@ _cpuclock_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED)
evas_object_show(inst->cfg->cpuclock.o_gadget); evas_object_show(inst->cfg->cpuclock.o_gadget);
evas_object_smart_callback_del_full(obj, "gadget_created", _cpuclock_created_cb, data); evas_object_smart_callback_del_full(obj, "gadget_created", _cpuclock_created_cb, data);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_ON, _screensaver_on, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_OFF, _screensaver_off, inst);
inst->cfg->cpuclock.status = _cpuclock_status_new(); inst->cfg->cpuclock.status = _cpuclock_status_new();
_cpuclock_status_check_available(inst->cfg->cpuclock.status); _cpuclock_status_check_available(inst->cfg->cpuclock.status);
inst->cfg->cpuclock.handler = ecore_event_handler_add(E_EVENT_POWERSAVE_UPDATE,
_cpuclock_event_cb_powersave, inst); E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_ON, _screensaver_on, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_OFF, _screensaver_off, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_POWERSAVE_UPDATE, _cpuclock_event_cb_powersave, inst);
_cpuclock_config_updated(inst); _cpuclock_config_updated(inst);
if ((inst->cfg->cpuclock.restore_governor) && (inst->cfg->cpuclock.governor)) if ((inst->cfg->cpuclock.restore_governor) && (inst->cfg->cpuclock.governor))
{ {
@ -1110,8 +1059,6 @@ sysinfo_cpuclock_create(Evas_Object *parent, Instance *inst)
{ {
Eina_List *l = NULL; Eina_List *l = NULL;
inst->cfg->cpuclock.defer = EINA_FALSE;
inst->cfg->cpuclock.done = EINA_FALSE;
if (inst->cfg->cpuclock.pstate_min == 0) inst->cfg->cpuclock.pstate_min = 1; if (inst->cfg->cpuclock.pstate_min == 0) inst->cfg->cpuclock.pstate_min = 1;
if (inst->cfg->cpuclock.pstate_max == 0) inst->cfg->cpuclock.pstate_max = 101; if (inst->cfg->cpuclock.pstate_max == 0) inst->cfg->cpuclock.pstate_max = 101;
@ -1132,13 +1079,13 @@ sysinfo_cpuclock_create(Evas_Object *parent, Instance *inst)
evas_object_event_callback_add(inst->cfg->cpuclock.o_gadget, EVAS_CALLBACK_RESIZE, _cpuclock_resize_cb, inst); evas_object_event_callback_add(inst->cfg->cpuclock.o_gadget, EVAS_CALLBACK_RESIZE, _cpuclock_resize_cb, inst);
evas_object_show(inst->cfg->cpuclock.o_gadget); evas_object_show(inst->cfg->cpuclock.o_gadget);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_ON, _screensaver_on, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_OFF, _screensaver_off, inst);
inst->cfg->cpuclock.status = _cpuclock_status_new(); inst->cfg->cpuclock.status = _cpuclock_status_new();
_cpuclock_status_check_available(inst->cfg->cpuclock.status); _cpuclock_status_check_available(inst->cfg->cpuclock.status);
inst->cfg->cpuclock.handler = ecore_event_handler_add(E_EVENT_POWERSAVE_UPDATE,
_cpuclock_event_cb_powersave, inst); E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_ON, _screensaver_on, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_SCREENSAVER_OFF, _screensaver_off, inst);
E_LIST_HANDLER_APPEND(inst->cfg->cpuclock.handlers, E_EVENT_POWERSAVE_UPDATE, _cpuclock_event_cb_powersave, inst);
_cpuclock_config_updated(inst); _cpuclock_config_updated(inst);
if ((inst->cfg->cpuclock.restore_governor) && (inst->cfg->cpuclock.governor)) if ((inst->cfg->cpuclock.restore_governor) && (inst->cfg->cpuclock.governor))
{ {
@ -1197,8 +1144,6 @@ cpuclock_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_U
inst = E_NEW(Instance, 1); inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id); inst->cfg = _conf_item_get(id);
*id = inst->cfg->id; *id = inst->cfg->id;
inst->cfg->cpuclock.defer = EINA_FALSE;
inst->cfg->cpuclock.done = EINA_FALSE;
inst->o_main = elm_box_add(parent); inst->o_main = elm_box_add(parent);
E_EXPAND(inst->o_main); E_EXPAND(inst->o_main);
evas_object_data_set(inst->o_main, "Instance", inst); evas_object_data_set(inst->o_main, "Instance", inst);

View File

@ -8,7 +8,7 @@ _config_close(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
E_FREE_FUNC(inst->cfg->cpuclock.configure, evas_object_del); E_FREE_FUNC(inst->cfg->cpuclock.configure, evas_object_del);
E_FREE_FUNC(cc->powersaves, eina_list_free); E_FREE_FUNC(cc->powersaves, eina_list_free);
E_FREE_FUNC(cc, free); E_FREE(cc);
e_config_save_queue(); e_config_save_queue();
} }

View File

@ -5,18 +5,22 @@ typedef struct _Thread_Config Thread_Config;
struct _Thread_Config struct _Thread_Config
{ {
int interval; int interval;
int cores; int num_cores;
int percent;
unsigned long total;
unsigned long idle;
Instance *inst; Instance *inst;
E_Powersave_Sleeper *sleeper; E_Powersave_Sleeper *sleeper;
Eina_List *cores;
}; };
static void static void
_cpumonitor_face_update(Instance *inst) _cpumonitor_face_update(Thread_Config *thc)
{ {
Eina_List *l; Eina_List *l;
CPU_Core *core; CPU_Core *core;
EINA_LIST_FOREACH(inst->cfg->cpumonitor.cores, l, core) EINA_LIST_FOREACH(thc->cores, l, core)
{ {
Edje_Message_Int_Set *usage_msg; Edje_Message_Int_Set *usage_msg;
usage_msg = malloc(sizeof(Edje_Message_Int_Set) + 1 * sizeof(int)); usage_msg = malloc(sizeof(Edje_Message_Int_Set) + 1 * sizeof(int));
@ -25,12 +29,12 @@ _cpumonitor_face_update(Instance *inst)
usage_msg->val[0] = core->percent; usage_msg->val[0] = core->percent;
edje_object_message_send(elm_layout_edje_get(core->layout), EDJE_MESSAGE_INT_SET, 1, edje_object_message_send(elm_layout_edje_get(core->layout), EDJE_MESSAGE_INT_SET, 1,
usage_msg); usage_msg);
free(usage_msg); E_FREE(usage_msg);
} }
if (inst->cfg->cpumonitor.popup) if (thc->inst->cfg->cpumonitor.popup)
{ {
elm_progressbar_value_set(inst->cfg->cpumonitor.popup_pbar, elm_progressbar_value_set(thc->inst->cfg->cpumonitor.popup_pbar,
(float)inst->cfg->cpumonitor.percent / 100); (float)thc->percent / 100);
} }
} }
@ -123,7 +127,7 @@ _cpumonitor_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *e
{ {
Evas_Coord w = 1, h = 1, sw, sh; Evas_Coord w = 1, h = 1, sw, sh;
Instance *inst = data; Instance *inst = data;
int num_cores = eina_list_count(inst->cfg->cpumonitor.cores); int num_cores = inst->cfg->cpumonitor.cores;
if (!num_cores || !inst->o_main) return; if (!num_cores || !inst->o_main) return;
@ -164,9 +168,9 @@ _cpumonitor_cb_usage_check_main(void *data, Ecore_Thread *th)
{ {
if (ecore_thread_check(th)) break; if (ecore_thread_check(th)) break;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
_cpumonitor_sysctl_getusage(thc->inst); _cpumonitor_sysctl_getusage(&thc->total, &thc->idle, &thc->percent, thc->cores);
#else #else
_cpumonitor_proc_getusage(thc->inst); _cpumonitor_proc_getusage(&thc->total, &thc->idle, &thc->percent, thc->cores);
#endif #endif
ecore_thread_feedback(th, NULL); ecore_thread_feedback(th, NULL);
if (ecore_thread_check(th)) break; if (ecore_thread_check(th)) break;
@ -185,12 +189,11 @@ _cpumonitor_cb_usage_check_notify(void *data,
void *msg EINA_UNUSED) void *msg EINA_UNUSED)
{ {
Thread_Config *thc = data; Thread_Config *thc = data;
Instance *inst = thc->inst;
if (!inst->cfg) return; if (!thc->inst || !thc->inst->cfg) return;
if (inst->cfg->esm != E_SYSINFO_MODULE_CPUMONITOR && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return; if (thc->inst->cfg->esm != E_SYSINFO_MODULE_CPUMONITOR && thc->inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
thc->inst->cfg->cpumonitor.percent = thc->percent;
_cpumonitor_face_update(inst); _cpumonitor_face_update(thc);
} }
static void static void
@ -200,37 +203,12 @@ _cpumonitor_cb_usage_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
CPU_Core *core; CPU_Core *core;
e_powersave_sleeper_free(thc->sleeper); e_powersave_sleeper_free(thc->sleeper);
if (thc->inst->cfg->cpumonitor.defer) EINA_LIST_FREE(thc->cores, core)
{ {
EINA_LIST_FREE(thc->inst->cfg->cpumonitor.cores, core) evas_object_del(core->layout);
{ E_FREE(core);
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
thc->inst->cfg->cpumonitor.defer = EINA_FALSE;
thc->inst->cfg->cpumonitor.done = EINA_TRUE;
if (thc->inst->cfg->esm == E_SYSINFO_MODULE_CPUMONITOR)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
else
{
if (thc->inst->cfg->memusage.done && thc->inst->cfg->thermal.done &&
thc->inst->cfg->netstatus.done && thc->inst->cfg->cpuclock.done && thc->inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
}
} }
E_FREE_FUNC(thc, free); E_FREE(thc);
} }
Evas_Object * Evas_Object *
@ -259,15 +237,9 @@ static Eina_Bool
_screensaver_on(void *data) _screensaver_on(void *data)
{ {
Instance *inst = data; Instance *inst = data;
CPU_Core *core;
if (inst->cfg->cpumonitor.usage_check_thread) if (inst->cfg->cpumonitor.usage_check_thread)
{ {
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread); ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
inst->cfg->cpumonitor.usage_check_thread = NULL; inst->cfg->cpumonitor.usage_check_thread = NULL;
} }
@ -293,11 +265,6 @@ _cpumonitor_config_updated(Instance *inst)
if (inst->cfg->cpumonitor.usage_check_thread) if (inst->cfg->cpumonitor.usage_check_thread)
{ {
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread); ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
inst->cfg->cpumonitor.usage_check_thread = NULL; inst->cfg->cpumonitor.usage_check_thread = NULL;
} }
@ -305,14 +272,17 @@ _cpumonitor_config_updated(Instance *inst)
if (thc) if (thc)
{ {
thc->inst = inst; thc->inst = inst;
thc->total = 0;
thc->idle = 0;
thc->percent = 0;
thc->interval = inst->cfg->cpumonitor.poll_interval; thc->interval = inst->cfg->cpumonitor.poll_interval;
thc->sleeper = e_powersave_sleeper_new(); thc->sleeper = e_powersave_sleeper_new();
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
thc->cores = _cpumonitor_sysctl_getcores(); thc->num_cores = _cpumonitor_sysctl_getcores();
#else #else
thc->cores = _cpumonitor_proc_getcores(); thc->num_cores = _cpumonitor_proc_getcores();
#endif #endif
for (i = 0; i < thc->cores; i++) for (i = 0; i < thc->num_cores; i++)
{ {
core = E_NEW(CPU_Core, 1); core = E_NEW(CPU_Core, 1);
core->layout = _cpumonitor_add_layout(inst); core->layout = _cpumonitor_add_layout(inst);
@ -321,7 +291,7 @@ _cpumonitor_config_updated(Instance *inst)
core->percent = 0; core->percent = 0;
core->total = 0; core->total = 0;
core->idle = 0; core->idle = 0;
inst->cfg->cpumonitor.cores = eina_list_append(inst->cfg->cpumonitor.cores, core); thc->cores = eina_list_append(thc->cores, core);
} }
inst->cfg->cpumonitor.usage_check_thread = inst->cfg->cpumonitor.usage_check_thread =
ecore_thread_feedback_run(_cpumonitor_cb_usage_check_main, ecore_thread_feedback_run(_cpumonitor_cb_usage_check_main,
@ -336,7 +306,6 @@ static void
_cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data) _cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
{ {
Instance *inst = data; Instance *inst = data;
CPU_Core *core;
Ecore_Event_Handler *handler; Ecore_Event_Handler *handler;
if (inst->o_main != event_data) return; if (inst->o_main != event_data) return;
@ -347,23 +316,14 @@ _cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_dat
E_FREE_FUNC(inst->cfg->cpumonitor.configure, evas_object_del); E_FREE_FUNC(inst->cfg->cpumonitor.configure, evas_object_del);
EINA_LIST_FREE(inst->cfg->cpumonitor.handlers, handler) EINA_LIST_FREE(inst->cfg->cpumonitor.handlers, handler)
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
evas_object_smart_callback_del_full(e_gadget_site_get(inst->o_main), "gadget_removed", evas_object_smart_callback_del_full(e_gadget_site_get(inst->o_main), "gadget_removed",
_cpumonitor_removed_cb, inst); _cpumonitor_removed_cb, inst);
evas_object_event_callback_del_full(inst->o_main, EVAS_CALLBACK_DEL, sysinfo_cpumonitor_remove, data); evas_object_event_callback_del_full(inst->o_main, EVAS_CALLBACK_DEL, sysinfo_cpumonitor_remove, data);
if (inst->cfg->cpumonitor.usage_check_thread) if (inst->cfg->cpumonitor.usage_check_thread)
{ {
inst->cfg->cpumonitor.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread); ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
inst->cfg->cpumonitor.usage_check_thread = NULL; inst->cfg->cpumonitor.usage_check_thread = NULL;
return;
} }
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg); sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0) if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst); sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
@ -375,7 +335,6 @@ void
sysinfo_cpumonitor_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_data EINA_UNUSED) sysinfo_cpumonitor_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_data EINA_UNUSED)
{ {
Instance *inst = data; Instance *inst = data;
CPU_Core *core;
Ecore_Event_Handler *handler; Ecore_Event_Handler *handler;
if (inst->cfg->cpumonitor.popup) if (inst->cfg->cpumonitor.popup)
@ -386,28 +345,8 @@ sysinfo_cpumonitor_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
if (inst->cfg->cpumonitor.usage_check_thread) if (inst->cfg->cpumonitor.usage_check_thread)
{ {
inst->cfg->cpumonitor.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread); ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
inst->cfg->cpumonitor.usage_check_thread = NULL; inst->cfg->cpumonitor.usage_check_thread = NULL;
return;
}
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
{
evas_object_del(core->layout);
E_FREE_FUNC(core, free);
}
inst->cfg->cpumonitor.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->memusage.done && inst->cfg->thermal.done &&
inst->cfg->netstatus.done && inst->cfg->cpuclock.done && inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
} }
} }
@ -455,10 +394,6 @@ _cpumonitor_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSE
Evas_Object * Evas_Object *
sysinfo_cpumonitor_create(Evas_Object *parent, Instance *inst) sysinfo_cpumonitor_create(Evas_Object *parent, Instance *inst)
{ {
inst->cfg->cpumonitor.defer = EINA_FALSE;
inst->cfg->cpumonitor.done = EINA_FALSE;
inst->cfg->cpumonitor.total = 0;
inst->cfg->cpumonitor.idle = 0;
inst->cfg->cpumonitor.percent = 0; inst->cfg->cpumonitor.percent = 0;
inst->cfg->cpumonitor.popup = NULL; inst->cfg->cpumonitor.popup = NULL;
inst->cfg->cpumonitor.configure = NULL; inst->cfg->cpumonitor.configure = NULL;
@ -514,9 +449,6 @@ _conf_item_get(int *id)
ci->esm = E_SYSINFO_MODULE_CPUMONITOR; ci->esm = E_SYSINFO_MODULE_CPUMONITOR;
ci->cpumonitor.poll_interval = 32; ci->cpumonitor.poll_interval = 32;
ci->cpumonitor.total = 0;
ci->cpumonitor.percent = 0;
ci->cpumonitor.idle = 0;
ci->cpumonitor.popup = NULL; ci->cpumonitor.popup = NULL;
ci->cpumonitor.configure = NULL; ci->cpumonitor.configure = NULL;
sysinfo_config->items = eina_list_append(sysinfo_config->items, ci); sysinfo_config->items = eina_list_append(sysinfo_config->items, ci);
@ -532,11 +464,6 @@ cpumonitor_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA
inst = E_NEW(Instance, 1); inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id); inst->cfg = _conf_item_get(id);
*id = inst->cfg->id; *id = inst->cfg->id;
inst->cfg->cpumonitor.defer = EINA_FALSE;
inst->cfg->cpumonitor.done = EINA_FALSE;
inst->cfg->cpumonitor.total = 0;
inst->cfg->cpumonitor.idle = 0;
inst->cfg->cpumonitor.percent = 0;
inst->cfg->cpumonitor.popup = NULL; inst->cfg->cpumonitor.popup = NULL;
inst->cfg->cpumonitor.configure = NULL; inst->cfg->cpumonitor.configure = NULL;
inst->o_main = elm_box_add(parent); inst->o_main = elm_box_add(parent);

View File

@ -5,8 +5,8 @@
EINTERN void _cpumonitor_config_updated(Instance *inst); EINTERN void _cpumonitor_config_updated(Instance *inst);
EINTERN int _cpumonitor_proc_getcores(void); EINTERN int _cpumonitor_proc_getcores(void);
EINTERN void _cpumonitor_proc_getusage(Instance *inst); EINTERN void _cpumonitor_proc_getusage(unsigned long *prev_total, unsigned long *prev_idle, int *prev_precent, Eina_List *cores);
EINTERN int _cpumonitor_sysctl_getcores(void); EINTERN int _cpumonitor_sysctl_getcores(unsigned long *prev_total, unsigned long *prev_idle, int *prev_precent, Eina_List *cores);
EINTERN void _cpumonitor_sysctl_getusage(Instance *inst); EINTERN void _cpumonitor_sysctl_getusage(Instance *inst);
EINTERN Evas_Object *cpumonitor_configure(Instance *inst); EINTERN Evas_Object *cpumonitor_configure(Instance *inst);
#endif #endif

View File

@ -28,7 +28,10 @@ _cpumonitor_proc_getcores(void)
} }
void void
_cpumonitor_proc_getusage(Instance *inst) _cpumonitor_proc_getusage(unsigned long *prev_total,
unsigned long *prev_idle,
int *prev_percent,
Eina_List *cores)
{ {
int k = 0, j = 0; int k = 0, j = 0;
char buf[4096]; char buf[4096];
@ -42,7 +45,7 @@ _cpumonitor_proc_getusage(Instance *inst)
{ {
if (k == 0) if (k == 0)
{ {
long total = 0, idle = 0, use = 0, total_change = 0, idle_change = 0; unsigned long total = 0, idle = 0, use = 0, total_change = 0, idle_change = 0;
int percent = 0; int percent = 0;
char *line, *tok; char *line, *tok;
int i = 0; int i = 0;
@ -58,19 +61,19 @@ _cpumonitor_proc_getusage(Instance *inst)
idle = use; idle = use;
tok = strtok(NULL, " "); tok = strtok(NULL, " ");
} }
total_change = total - inst->cfg->cpumonitor.total; total_change = total - *prev_total;
idle_change = idle - inst->cfg->cpumonitor.idle; idle_change = idle - *prev_idle;
if (total_change != 0) if (total_change != 0)
percent = 100 * (1 - ((float)idle_change / (float)total_change)); percent = 100 * (1 - ((float)idle_change / (float)total_change));
if (percent > 100) percent = 100; if (percent > 100) percent = 100;
else if (percent < 0) percent = 0; else if (percent < 0) percent = 0;
inst->cfg->cpumonitor.total = total; *prev_total = total;
inst->cfg->cpumonitor.idle = idle; *prev_idle = idle;
inst->cfg->cpumonitor.percent = percent; *prev_percent = percent;
} }
if (k > 0) if (k > 0)
{ {
long total = 0, idle = 0, use = 0, total_change = 0, idle_change = 0; unsigned long total = 0, idle = 0, use = 0, total_change = 0, idle_change = 0;
int percent = 0; int percent = 0;
if (!strncmp(buf, "cpu", 3)) if (!strncmp(buf, "cpu", 3))
{ {
@ -89,7 +92,7 @@ _cpumonitor_proc_getusage(Instance *inst)
} }
} }
else break; else break;
core = eina_list_nth(inst->cfg->cpumonitor.cores, j); core = eina_list_nth(cores, j);
total_change = total - core->total; total_change = total - core->total;
idle_change = idle - core->idle; idle_change = idle - core->idle;
if (total_change != 0) if (total_change != 0)

View File

@ -27,7 +27,7 @@ _cpumonitor_sysctl_getcores(void)
void void
_cpumonitor_sysctl_getusage(Instance *inst) _cpumonitor_sysctl_getusage(unsigned long *prev_total, unsigned long *prev_idle, int *prev_precent, Eina_List *cores)
{ {
CPU_Core *core; CPU_Core *core;
size_t size; size_t size;
@ -36,21 +36,21 @@ _cpumonitor_sysctl_getusage(Instance *inst)
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
int ncpu = _cpumonitor_sysctl_getcores(); int ncpu = _cpumonitor_sysctl_getcores();
if (!ncpu) return; if (!ncpu) return;
size = sizeof(long) * (CPU_STATES * ncpu); size = sizeof(unsigned long) * (CPU_STATES * ncpu);
long cpu_times[ncpu][CPU_STATES]; unsigned long cpu_times[ncpu][CPU_STATES];
if (sysctlbyname("kern.cp_times", cpu_times, &size, NULL, 0) < 0) if (sysctlbyname("kern.cp_times", cpu_times, &size, NULL, 0) < 0)
return; return;
for (i = 0; i < ncpu; i++) for (i = 0; i < ncpu; i++)
{ {
long *cpu = cpu_times[i]; unsigned long *cpu = cpu_times[i];
double total = 0; double total = 0;
for (j = 0; j < CPU_STATES; j++) for (j = 0; j < CPU_STATES; j++)
total += cpu[j]; total += cpu[j];
core = eina_list_nth(inst->cfg->cpumonitor.cores, i); core = eina_list_nth(cores, i);
int diff_total = total - core->total; int diff_total = total - core->total;
int diff_idle = cpu[4] - core->idle; int diff_idle = cpu[4] - core->idle;
@ -58,7 +58,7 @@ _cpumonitor_sysctl_getusage(Instance *inst)
if (diff_total == 0) diff_total = 1; if (diff_total == 0) diff_total = 1;
double ratio = diff_total / 100.0; double ratio = diff_total / 100.0;
long used = diff_total - diff_idle; unsigned long used = diff_total - diff_idle;
int percent = used / ratio; int percent = used / ratio;
if (percent > 100) if (percent > 100)
@ -74,59 +74,59 @@ _cpumonitor_sysctl_getusage(Instance *inst)
total_all += total; total_all += total;
idle_all += core->idle; idle_all += core->idle;
} }
inst->cfg->cpumonitor.total = total_all / ncpu; *prev_total = total_all / ncpu;
inst->cfg->cpumonitor.idle = idle_all / ncpu; *prev_idle = idle_all / ncpu;
inst->cfg->cpumonitor.percent = (int) (percent_all / ncpu); *prev_percent = (int) (percent_all / ncpu);
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
int ncpu = _cpumonitor_sysctl_getcores(); int ncpu = _cpumonitor_sysctl_getcores();
if (!ncpu) return; if (!ncpu) return;
if (ncpu == 1) if (ncpu == 1)
{ {
long cpu_times[CPU_STATES]; unsigned long cpu_times[CPU_STATES];
int cpu_time_mib[] = { CTL_KERN, KERN_CPTIME }; int cpu_time_mib[] = { CTL_KERN, KERN_CPTIME };
size = CPU_STATES * sizeof(long); size = CPU_STATES * sizeof(unsigned long);
if (sysctl(cpu_time_mib, 2, &cpu_times, &size, NULL, 0) < 0) if (sysctl(cpu_time_mib, 2, &cpu_times, &size, NULL, 0) < 0)
return; return;
long total = 0; unsigned long total = 0;
for (j = 0; j < CPU_STATES; j++) for (j = 0; j < CPU_STATES; j++)
total += cpu_times[j]; total += cpu_times[j];
long idle = cpu_times[4]; unsigned long idle = cpu_times[4];
int diff_total = total - inst->cfg->cpumonitor.total; int diff_total = total - *prev_total;
int diff_idle = idle - inst->cfg->cpumonitor.idle; int diff_idle = idle - *prev_idle;
if (diff_total == 0) diff_total = 1; if (diff_total == 0) diff_total = 1;
double ratio = diff_total / 100.0; double ratio = diff_total / 100.0;
long used = diff_total - diff_idle; unsigned long used = diff_total - diff_idle;
int percent = used / ratio; int percent = used / ratio;
if (percent > 100) if (percent > 100)
percent = 100; percent = 100;
else if (percent < 0) else if (percent < 0)
percent = 0; percent = 0;
inst->cfg->cpumonitor.total = total; *prev_total = total;
inst->cfg->cpumonitor.idle = idle; // cpu_times[3]; *prev_idle = idle; // cpu_times[3];
inst->cfg->cpumonitor.percent = (int) percent; *prev_percent = (int) percent;
} }
else if (ncpu > 1) else if (ncpu > 1)
{ {
for (i = 0; i < ncpu; i++) for (i = 0; i < ncpu; i++)
{ {
long cpu_times[CPU_STATES]; unsigned long cpu_times[CPU_STATES];
size = CPU_STATES * sizeof(long); size = CPU_STATES * sizeof(unsigned long);
int cpu_time_mib[] = { CTL_KERN, KERN_CPTIME2, 0 }; int cpu_time_mib[] = { CTL_KERN, KERN_CPTIME2, 0 };
cpu_time_mib[2] = i; cpu_time_mib[2] = i;
if (sysctl(cpu_time_mib, 3, &cpu_times, &size, NULL, 0) < 0) if (sysctl(cpu_time_mib, 3, &cpu_times, &size, NULL, 0) < 0)
return; return;
long total = 0; unsigned long total = 0;
for (j = 0; j < CPU_STATES - 1; j++) for (j = 0; j < CPU_STATES - 1; j++)
total += cpu_times[j]; total += cpu_times[j];
core = eina_list_nth(inst->cfg->cpumonitor.cores, i); core = eina_list_nth(cores, i);
int diff_total = total - core->total; int diff_total = total - core->total;
int diff_idle = cpu_times[4] - core->idle; int diff_idle = cpu_times[4] - core->idle;
@ -135,7 +135,7 @@ _cpumonitor_sysctl_getusage(Instance *inst)
if (diff_total == 0) diff_total = 1; if (diff_total == 0) diff_total = 1;
double ratio = diff_total / 100; double ratio = diff_total / 100;
long used = diff_total - diff_idle; unsigned long used = diff_total - diff_idle;
int percent = used / ratio; int percent = used / ratio;
core->percent = percent; core->percent = percent;
@ -145,9 +145,9 @@ _cpumonitor_sysctl_getusage(Instance *inst)
idle_all += core->idle; idle_all += core->idle;
} }
inst->cfg->cpumonitor.total = (total_all / ncpu); *prev_total = (total_all / ncpu);
inst->cfg->cpumonitor.idle = (idle_all / ncpu); *prev_idle = (idle_all / ncpu);
inst->cfg->cpumonitor.percent = (percent_all / ncpu) + (percent_all % ncpu); *prev_percent = (percent_all / ncpu) + (percent_all % ncpu);
} }
#endif #endif
} }

View File

@ -94,7 +94,7 @@ _memusage_face_update(Instance *inst)
msg->val[8] = inst->cfg->memusage.swp_used; msg->val[8] = inst->cfg->memusage.swp_used;
edje_object_message_send(elm_layout_edje_get(inst->cfg->memusage.o_gadget), edje_object_message_send(elm_layout_edje_get(inst->cfg->memusage.o_gadget),
EDJE_MESSAGE_INT_SET, 1, msg); EDJE_MESSAGE_INT_SET, 1, msg);
free(msg); E_FREE(msg);
if (inst->cfg->memusage.popup) if (inst->cfg->memusage.popup)
_memusage_popup_update(inst); _memusage_popup_update(inst);
@ -308,32 +308,7 @@ _memusage_cb_usage_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
{ {
Thread_Config *thc = data; Thread_Config *thc = data;
e_powersave_sleeper_free(thc->sleeper); e_powersave_sleeper_free(thc->sleeper);
if (thc->inst->cfg->memusage.defer) E_FREE(thc);
{
thc->inst->cfg->memusage.defer = EINA_FALSE;
thc->inst->cfg->memusage.done = EINA_TRUE;
if (thc->inst->cfg->esm == E_SYSINFO_MODULE_MEMUSAGE)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
else
{
if (thc->inst->cfg->cpumonitor.done && thc->inst->cfg->thermal.done &&
thc->inst->cfg->netstatus.done && thc->inst->cfg->cpuclock.done && thc->inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
}
}
E_FREE_FUNC(thc, free);
} }
static void static void
@ -342,22 +317,21 @@ _memusage_cb_usage_check_notify(void *data,
void *msg EINA_UNUSED) void *msg EINA_UNUSED)
{ {
Thread_Config *thc = data; Thread_Config *thc = data;
Instance *inst = thc->inst;
if (!inst->cfg) return; if (!thc->inst->cfg) return;
if (inst->cfg->esm != E_SYSINFO_MODULE_MEMUSAGE && if (thc->inst->cfg->esm != E_SYSINFO_MODULE_MEMUSAGE &&
inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return; thc->inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
inst->cfg->memusage.mem_percent = thc->mem_percent; thc->inst->cfg->memusage.mem_percent = thc->mem_percent;
inst->cfg->memusage.swp_percent = thc->swp_percent; thc->inst->cfg->memusage.swp_percent = thc->swp_percent;
inst->cfg->memusage.mem_total = thc->mem_total; thc->inst->cfg->memusage.mem_total = thc->mem_total;
inst->cfg->memusage.mem_used = thc->mem_used; thc->inst->cfg->memusage.mem_used = thc->mem_used;
inst->cfg->memusage.mem_cached = thc->mem_cached; thc->inst->cfg->memusage.mem_cached = thc->mem_cached;
inst->cfg->memusage.mem_buffers = thc->mem_buffers; thc->inst->cfg->memusage.mem_buffers = thc->mem_buffers;
inst->cfg->memusage.mem_shared = thc->mem_shared; thc->inst->cfg->memusage.mem_shared = thc->mem_shared;
inst->cfg->memusage.swp_total = thc->swp_total; thc->inst->cfg->memusage.swp_total = thc->swp_total;
inst->cfg->memusage.swp_used = thc->swp_used; thc->inst->cfg->memusage.swp_used = thc->swp_used;
_memusage_face_update(inst); _memusage_face_update(thc->inst);
} }
static Eina_Bool static Eina_Bool
@ -431,10 +405,8 @@ _memusage_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
if (inst->cfg->memusage.usage_check_thread) if (inst->cfg->memusage.usage_check_thread)
{ {
inst->cfg->memusage.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->memusage.usage_check_thread); ecore_thread_cancel(inst->cfg->memusage.usage_check_thread);
inst->cfg->memusage.usage_check_thread = NULL; inst->cfg->memusage.usage_check_thread = NULL;
return;
} }
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg); sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0) if (inst->cfg->id >= 0)
@ -455,26 +427,11 @@ sysinfo_memusage_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_U
E_FREE_FUNC(inst->cfg->memusage.configure, evas_object_del); E_FREE_FUNC(inst->cfg->memusage.configure, evas_object_del);
if (inst->cfg->memusage.usage_check_thread) if (inst->cfg->memusage.usage_check_thread)
{ {
inst->cfg->memusage.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->memusage.usage_check_thread); ecore_thread_cancel(inst->cfg->memusage.usage_check_thread);
inst->cfg->memusage.usage_check_thread = NULL; inst->cfg->memusage.usage_check_thread = NULL;
return;
} }
EINA_LIST_FREE(inst->cfg->memusage.handlers, handler) EINA_LIST_FREE(inst->cfg->memusage.handlers, handler)
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
inst->cfg->memusage.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->thermal.done && inst->cfg->cpumonitor.done &&
inst->cfg->netstatus.done && inst->cfg->cpuclock.done && inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
} }
static void static void
@ -517,8 +474,6 @@ _memusage_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED)
Evas_Object * Evas_Object *
sysinfo_memusage_create(Evas_Object *parent, Instance *inst) sysinfo_memusage_create(Evas_Object *parent, Instance *inst)
{ {
inst->cfg->memusage.defer = EINA_FALSE;
inst->cfg->memusage.done = EINA_FALSE;
inst->cfg->memusage.mem_percent = 0; inst->cfg->memusage.mem_percent = 0;
inst->cfg->memusage.swp_percent = 0; inst->cfg->memusage.swp_percent = 0;
inst->cfg->memusage.mem_total = 0; inst->cfg->memusage.mem_total = 0;
@ -599,8 +554,6 @@ memusage_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_U
inst = E_NEW(Instance, 1); inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id); inst->cfg = _conf_item_get(id);
*id = inst->cfg->id; *id = inst->cfg->id;
inst->cfg->memusage.defer = EINA_FALSE;
inst->cfg->memusage.done = EINA_FALSE;
inst->cfg->memusage.mem_percent = 0; inst->cfg->memusage.mem_percent = 0;
inst->cfg->memusage.swp_percent = 0; inst->cfg->memusage.swp_percent = 0;
inst->cfg->memusage.mem_total = 0; inst->cfg->memusage.mem_total = 0;

View File

@ -104,7 +104,7 @@ void _memusage_sysctl_getusage(unsigned long *mem_total,
*swp_used >>= 10; *swp_used >>= 10;
free(mib); E_FREE(mib);
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
static int mib[] = { CTL_HW, HW_PHYSMEM64 }; static int mib[] = { CTL_HW, HW_PHYSMEM64 };
static int bcstats_mib[] = { CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT }; static int bcstats_mib[] = { CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT };
@ -145,7 +145,7 @@ void _memusage_sysctl_getusage(unsigned long *mem_total,
} }
} }
swap_out: swap_out:
if (swdev) free(swdev); if (swdev) E_FREE(swdev);
*mem_total /= 1024; *mem_total /= 1024;

View File

@ -50,8 +50,8 @@ sysinfo_init(void)
E_CONFIG_VAL(D, T, netstatus.poll_interval, INT); E_CONFIG_VAL(D, T, netstatus.poll_interval, INT);
E_CONFIG_VAL(D, T, netstatus.automax, INT); E_CONFIG_VAL(D, T, netstatus.automax, INT);
E_CONFIG_VAL(D, T, netstatus.inmax, INT); E_CONFIG_VAL(D, T, netstatus.inmax, INT);
E_CONFIG_VAL(D, T, netstatus.receive_units, INT);
E_CONFIG_VAL(D, T, netstatus.outmax, INT); E_CONFIG_VAL(D, T, netstatus.outmax, INT);
E_CONFIG_VAL(D, T, netstatus.receive_units, INT);
E_CONFIG_VAL(D, T, netstatus.send_units, INT); E_CONFIG_VAL(D, T, netstatus.send_units, INT);
conf_edd = E_CONFIG_DD_NEW("Sysinfo_Config", Config); conf_edd = E_CONFIG_DD_NEW("Sysinfo_Config", Config);
@ -82,7 +82,7 @@ sysinfo_init(void)
ci->batman.time_left = -2; ci->batman.time_left = -2;
ci->batman.have_battery = -2; ci->batman.have_battery = -2;
ci->batman.have_power = -2; ci->batman.have_power = -2;
#if defined(HAVE_EEZ)E || defined(__OpenBSD__) || defined(__NetBSD__) #if defined(HAVE_EEZE) || defined(__OpenBSD__) || defined(__NetBSD__)
ci->batman.fuzzy = 0; ci->batman.fuzzy = 0;
#endif #endif
ci->batman.desktop_notifications = 0; ci->batman.desktop_notifications = 0;
@ -98,8 +98,6 @@ sysinfo_init(void)
ci->thermal.units = CELSIUS; ci->thermal.units = CELSIUS;
ci->thermal.popup = NULL; ci->thermal.popup = NULL;
ci->thermal.configure = NULL; ci->thermal.configure = NULL;
ci->thermal.defer = EINA_FALSE;
ci->thermal.done = EINA_FALSE;
ci->cpuclock.poll_interval = 32; ci->cpuclock.poll_interval = 32;
ci->cpuclock.restore_governor = 0; ci->cpuclock.restore_governor = 0;
ci->cpuclock.auto_powersave = 1; ci->cpuclock.auto_powersave = 1;
@ -109,41 +107,25 @@ sysinfo_init(void)
ci->cpuclock.pstate_max = 101; ci->cpuclock.pstate_max = 101;
ci->cpuclock.popup = NULL; ci->cpuclock.popup = NULL;
ci->cpuclock.configure = NULL; ci->cpuclock.configure = NULL;
ci->cpuclock.defer = EINA_FALSE;
ci->cpuclock.done = EINA_FALSE;
ci->cpumonitor.poll_interval = 32; ci->cpumonitor.poll_interval = 32;
ci->cpumonitor.total = 0;
ci->cpumonitor.idle = 0;
ci->cpumonitor.percent = 0; ci->cpumonitor.percent = 0;
ci->cpumonitor.popup = NULL; ci->cpumonitor.popup = NULL;
ci->cpumonitor.configure = NULL; ci->cpumonitor.configure = NULL;
ci->cpumonitor.defer = EINA_FALSE;
ci->cpumonitor.done = EINA_FALSE;
ci->memusage.poll_interval = 32; ci->memusage.poll_interval = 32;
ci->memusage.mem_percent = 0; ci->memusage.mem_percent = 0;
ci->memusage.swp_percent = 0; ci->memusage.swp_percent = 0;
ci->memusage.popup = NULL; ci->memusage.popup = NULL;
ci->memusage.configure = NULL; ci->memusage.configure = NULL;
ci->memusage.defer = EINA_FALSE;
ci->memusage.done = EINA_FALSE;
ci->netstatus.poll_interval = 32; ci->netstatus.poll_interval = 32;
ci->netstatus.automax = EINA_TRUE; ci->netstatus.automax = EINA_TRUE;
ci->netstatus.receive_units = NETSTATUS_UNIT_BYTES;
ci->netstatus.send_units = NETSTATUS_UNIT_BYTES;
ci->netstatus.in = 0;
ci->netstatus.out = 0;
ci->netstatus.inmax = 0; ci->netstatus.inmax = 0;
ci->netstatus.outmax = 0; ci->netstatus.outmax = 0;
ci->netstatus.incurrent = 0; ci->netstatus.receive_units = NETSTATUS_UNIT_BYTES;
ci->netstatus.outcurrent = 0; ci->netstatus.send_units = NETSTATUS_UNIT_BYTES;
ci->netstatus.inpercent = 0;
ci->netstatus.outpercent = 0;
ci->netstatus.instring = NULL; ci->netstatus.instring = NULL;
ci->netstatus.outstring = NULL; ci->netstatus.outstring = NULL;
ci->netstatus.popup = NULL; ci->netstatus.popup = NULL;
ci->netstatus.configure = NULL; ci->netstatus.configure = NULL;
ci->netstatus.defer = EINA_FALSE;
ci->netstatus.done = EINA_FALSE;
E_CONFIG_LIMIT(ci->batman.poll_interval, 4, 4096); E_CONFIG_LIMIT(ci->batman.poll_interval, 4, 4096);
E_CONFIG_LIMIT(ci->batman.alert, 0, 60); E_CONFIG_LIMIT(ci->batman.alert, 0, 60);
@ -193,7 +175,7 @@ sysinfo_shutdown(void)
Config_Item *ci; Config_Item *ci;
EINA_LIST_FREE(sysinfo_config->items, ci) EINA_LIST_FREE(sysinfo_config->items, ci)
{ {
free(ci); E_FREE(ci);
} }
E_FREE(sysinfo_config); E_FREE(sysinfo_config);
} }

View File

@ -6,34 +6,43 @@ struct _Thread_Config
{ {
int interval; int interval;
Instance *inst; Instance *inst;
int percent; Eina_Bool automax;
long current; int inpercent;
unsigned long in;
unsigned long incurrent;
unsigned long inmax;
Eina_Stringshare *instring;
int outpercent;
unsigned long out;
unsigned long outcurrent;
unsigned long outmax;
Eina_Stringshare *outstring;
E_Powersave_Sleeper *sleeper; E_Powersave_Sleeper *sleeper;
}; };
static void static void
_netstatus_face_update(Instance *inst) _netstatus_face_update(Thread_Config *thc)
{ {
Edje_Message_Int_Set *msg; Edje_Message_Int_Set *msg;
msg = malloc(sizeof(Edje_Message_Int_Set) + 6 * sizeof(int)); msg = malloc(sizeof(Edje_Message_Int_Set) + 6 * sizeof(int));
EINA_SAFETY_ON_NULL_RETURN(msg); EINA_SAFETY_ON_NULL_RETURN(msg);
msg->count = 6; msg->count = 6;
msg->val[0] = inst->cfg->netstatus.incurrent; msg->val[0] = thc->incurrent;
msg->val[1] = inst->cfg->netstatus.inpercent; msg->val[1] = thc->inpercent;
msg->val[2] = inst->cfg->netstatus.inmax; msg->val[2] = thc->inmax;
msg->val[3] = inst->cfg->netstatus.outcurrent; msg->val[3] = thc->outcurrent;
msg->val[4] = inst->cfg->netstatus.outpercent; msg->val[4] = thc->outpercent;
msg->val[5] = inst->cfg->netstatus.outmax; msg->val[5] = thc->outmax;
edje_object_message_send(elm_layout_edje_get(inst->cfg->netstatus.o_gadget), edje_object_message_send(elm_layout_edje_get(thc->inst->cfg->netstatus.o_gadget),
EDJE_MESSAGE_INT_SET, 1, msg); EDJE_MESSAGE_INT_SET, 1, msg);
free(msg); E_FREE(msg);
if (inst->cfg->netstatus.popup) if (thc->inst->cfg->netstatus.popup)
{ {
char text[4096]; char text[4096];
snprintf(text, sizeof(text), "%s<br>%s", inst->cfg->netstatus.instring, inst->cfg->netstatus.outstring); snprintf(text, sizeof(text), "%s<br>%s", thc->instring, thc->outstring);
elm_object_text_set(inst->cfg->netstatus.popup_label, text); elm_object_text_set(thc->inst->cfg->netstatus.popup_label, text);
} }
} }
@ -130,15 +139,45 @@ _netstatus_cb_usage_check_main(void *data, Ecore_Thread *th)
Thread_Config *thc = data; Thread_Config *thc = data;
for (;;) for (;;)
{ {
char rin[4096], rout[4096];
if (ecore_thread_check(th)) break; if (ecore_thread_check(th)) break;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
_netstatus_sysctl_getrstatus(thc->inst); _netstatus_sysctl_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->inpercent);
_netstatus_sysctl_gettstatus(thc->inst); _netstatus_sysctl_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outpercent);
#else #else
_netstatus_proc_getrstatus(thc->inst); _netstatus_proc_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->inpercent);
_netstatus_proc_gettstatus(thc->inst); _netstatus_proc_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outpercent);
#endif #endif
ecore_thread_feedback(th, NULL); if (!thc->incurrent)
{
snprintf(rin, sizeof(rin), "%s: 0 B/s", _("Receiving"));
}
else
{
if (thc->incurrent > 1048576)
snprintf(rin, sizeof(rin), "%s: %.2f MB/s", _("Receiving"), ((float)thc->incurrent / 1048576));
else if ((thc->incurrent > 1024) && (thc->incurrent < 1048576))
snprintf(rin, sizeof(rin), "%s: %lu KB/s", _("Receiving"), (thc->incurrent / 1024));
else
snprintf(rin, sizeof(rin), "%s: %lu B/s", _("Receiving"), thc->incurrent);
}
eina_stringshare_replace(&thc->instring, rin);
if (!thc->outcurrent)
{
snprintf(rout, sizeof(rout), "%s: 0 B/s", _("Receiving"));
}
else
{
if (thc->outcurrent > 1048576)
snprintf(rout, sizeof(rout), "%s: %.2f MB/s", _("Receiving"), ((float)thc->outcurrent / 1048576));
else if ((thc->outcurrent > 1024) && (thc->outcurrent < 1048576))
snprintf(rout, sizeof(rout), "%s: %lu KB/s", _("Receiving"), (thc->outcurrent / 1024));
else
snprintf(rout, sizeof(rout), "%s: %lu B/s", _("Receiving"), thc->outcurrent);
}
eina_stringshare_replace(&thc->outstring, rout);
ecore_thread_feedback(th, NULL);
if (ecore_thread_check(th)) break; if (ecore_thread_check(th)) break;
e_powersave_sleeper_sleep(thc->sleeper, thc->interval); e_powersave_sleeper_sleep(thc->sleeper, thc->interval);
if (e_powersave_mode_get() == E_POWERSAVE_MODE_FREEZE) if (e_powersave_mode_get() == E_POWERSAVE_MODE_FREEZE)
@ -155,12 +194,13 @@ _netstatus_cb_usage_check_notify(void *data,
void *msg EINA_UNUSED) void *msg EINA_UNUSED)
{ {
Thread_Config *thc = data; Thread_Config *thc = data;
Instance *inst = thc->inst;
if (!inst->cfg) return; if (!thc->inst->cfg) return;
if (inst->cfg->esm != E_SYSINFO_MODULE_NETSTATUS && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return; if (thc->inst->cfg->esm != E_SYSINFO_MODULE_NETSTATUS && thc->inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
_netstatus_face_update(inst); eina_stringshare_replace(&thc->inst->cfg->netstatus.instring, thc->instring);
eina_stringshare_replace(&thc->inst->cfg->netstatus.outstring, thc->outstring);
_netstatus_face_update(thc);
} }
static void static void
@ -168,34 +208,9 @@ _netstatus_cb_usage_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
{ {
Thread_Config *thc = data; Thread_Config *thc = data;
e_powersave_sleeper_free(thc->sleeper); e_powersave_sleeper_free(thc->sleeper);
if (thc->inst->cfg->netstatus.defer) E_FREE_FUNC(thc->instring, eina_stringshare_del);
{ E_FREE_FUNC(thc->outstring, eina_stringshare_del);
E_FREE_FUNC(thc->inst->cfg->netstatus.instring, eina_stringshare_del); E_FREE(thc);
E_FREE_FUNC(thc->inst->cfg->netstatus.outstring, eina_stringshare_del);
thc->inst->cfg->netstatus.defer = EINA_FALSE;
thc->inst->cfg->netstatus.done = EINA_TRUE;
if (thc->inst->cfg->esm == E_SYSINFO_MODULE_NETSTATUS)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
else
{
if (thc->inst->cfg->memusage.done && thc->inst->cfg->thermal.done &&
thc->inst->cfg->cpumonitor.done && thc->inst->cfg->cpuclock.done && thc->inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, thc->inst->cfg);
if (thc->inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, thc->inst);
E_FREE(thc->inst->cfg);
E_FREE(thc->inst);
}
}
}
E_FREE_FUNC(thc, free);
} }
static Eina_Bool static Eina_Bool
@ -237,7 +252,18 @@ _netstatus_config_updated(Instance *inst)
thc->inst = inst; thc->inst = inst;
thc->sleeper = e_powersave_sleeper_new(); thc->sleeper = e_powersave_sleeper_new();
thc->interval = inst->cfg->netstatus.poll_interval; thc->interval = inst->cfg->netstatus.poll_interval;
inst->cfg->netstatus.usage_check_thread = thc->in = 0;
thc->inmax = inst->cfg->netstatus.inmax;
thc->incurrent = 0;
thc->inpercent = 0;
thc->instring = NULL;
thc->out = 0;
thc->outmax = inst->cfg->netstatus.outmax;
thc->outcurrent = 0;
thc->outpercent = 0;
thc->outstring = NULL;
thc->automax = inst->cfg->netstatus.automax;
inst->cfg->netstatus.usage_check_thread =
ecore_thread_feedback_run(_netstatus_cb_usage_check_main, ecore_thread_feedback_run(_netstatus_cb_usage_check_main,
_netstatus_cb_usage_check_notify, _netstatus_cb_usage_check_notify,
_netstatus_cb_usage_check_end, _netstatus_cb_usage_check_end,
@ -265,10 +291,8 @@ _netstatus_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
if (inst->cfg->netstatus.usage_check_thread) if (inst->cfg->netstatus.usage_check_thread)
{ {
inst->cfg->netstatus.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->netstatus.usage_check_thread); ecore_thread_cancel(inst->cfg->netstatus.usage_check_thread);
inst->cfg->netstatus.usage_check_thread = NULL; inst->cfg->netstatus.usage_check_thread = NULL;
return;
} }
E_FREE_FUNC(inst->cfg->netstatus.instring, eina_stringshare_del); E_FREE_FUNC(inst->cfg->netstatus.instring, eina_stringshare_del);
E_FREE_FUNC(inst->cfg->netstatus.outstring, eina_stringshare_del); E_FREE_FUNC(inst->cfg->netstatus.outstring, eina_stringshare_del);
@ -294,26 +318,12 @@ sysinfo_netstatus_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
if (inst->cfg->netstatus.usage_check_thread) if (inst->cfg->netstatus.usage_check_thread)
{ {
inst->cfg->netstatus.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->netstatus.usage_check_thread); ecore_thread_cancel(inst->cfg->netstatus.usage_check_thread);
inst->cfg->netstatus.usage_check_thread = NULL; inst->cfg->netstatus.usage_check_thread = NULL;
return; return;
} }
E_FREE_FUNC(inst->cfg->netstatus.instring, eina_stringshare_del); E_FREE_FUNC(inst->cfg->netstatus.instring, eina_stringshare_del);
E_FREE_FUNC(inst->cfg->netstatus.outstring, eina_stringshare_del); E_FREE_FUNC(inst->cfg->netstatus.outstring, eina_stringshare_del);
inst->cfg->netstatus.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->memusage.done && inst->cfg->thermal.done &&
inst->cfg->cpumonitor.done && inst->cfg->cpuclock.done && inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
} }
static void static void
@ -324,6 +334,9 @@ _netstatus_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED
e_gadget_configure_cb_set(inst->o_main, _netstatus_configure_cb); e_gadget_configure_cb_set(inst->o_main, _netstatus_configure_cb);
inst->cfg->netstatus.instring = NULL;
inst->cfg->netstatus.outstring = NULL;
inst->cfg->netstatus.o_gadget = elm_layout_add(inst->o_main); inst->cfg->netstatus.o_gadget = elm_layout_add(inst->o_main);
if (orient == E_GADGET_SITE_ORIENT_VERTICAL) if (orient == E_GADGET_SITE_ORIENT_VERTICAL)
e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, e_theme_edje_object_set(inst->cfg->netstatus.o_gadget,
@ -349,17 +362,9 @@ _netstatus_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED
Evas_Object * Evas_Object *
sysinfo_netstatus_create(Evas_Object *parent, Instance *inst) sysinfo_netstatus_create(Evas_Object *parent, Instance *inst)
{ {
inst->cfg->netstatus.defer = EINA_FALSE; inst->cfg->netstatus.popup = NULL;
inst->cfg->netstatus.done = EINA_FALSE;
inst->cfg->netstatus.in = 0;
inst->cfg->netstatus.out = 0;
inst->cfg->netstatus.incurrent = 0;
inst->cfg->netstatus.outcurrent = 0;
inst->cfg->netstatus.inpercent = 0;
inst->cfg->netstatus.outpercent = 0;
inst->cfg->netstatus.instring = NULL; inst->cfg->netstatus.instring = NULL;
inst->cfg->netstatus.outstring = NULL; inst->cfg->netstatus.outstring = NULL;
inst->cfg->netstatus.popup = NULL;
inst->cfg->netstatus.o_gadget = elm_layout_add(parent); inst->cfg->netstatus.o_gadget = elm_layout_add(parent);
e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/gadget/netstatus", e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/gadget/netstatus",
"e/gadget/netstatus/main"); "e/gadget/netstatus/main");
@ -399,16 +404,8 @@ _conf_item_get(int *id)
ci->esm = E_SYSINFO_MODULE_NETSTATUS; ci->esm = E_SYSINFO_MODULE_NETSTATUS;
ci->netstatus.poll_interval = 32; ci->netstatus.poll_interval = 32;
ci->netstatus.automax = EINA_TRUE; ci->netstatus.automax = EINA_TRUE;
ci->netstatus.inmax = 0;
ci->netstatus.outmax = 0;
ci->netstatus.receive_units = NETSTATUS_UNIT_BYTES; ci->netstatus.receive_units = NETSTATUS_UNIT_BYTES;
ci->netstatus.send_units = NETSTATUS_UNIT_BYTES; ci->netstatus.send_units = NETSTATUS_UNIT_BYTES;
ci->netstatus.in = 0;
ci->netstatus.out = 0;
ci->netstatus.incurrent = 0;
ci->netstatus.outcurrent = 0;
ci->netstatus.inpercent = 0;
ci->netstatus.outpercent = 0;
ci->netstatus.instring = NULL; ci->netstatus.instring = NULL;
ci->netstatus.outstring = NULL; ci->netstatus.outstring = NULL;
ci->netstatus.popup = NULL; ci->netstatus.popup = NULL;
@ -426,14 +423,6 @@ netstatus_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_
inst = E_NEW(Instance, 1); inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id); inst->cfg = _conf_item_get(id);
*id = inst->cfg->id; *id = inst->cfg->id;
inst->cfg->netstatus.defer = EINA_FALSE;
inst->cfg->netstatus.done = EINA_FALSE;
inst->cfg->netstatus.in = 0;
inst->cfg->netstatus.out = 0;
inst->cfg->netstatus.incurrent = 0;
inst->cfg->netstatus.outcurrent = 0;
inst->cfg->netstatus.inpercent = 0;
inst->cfg->netstatus.outpercent = 0;
inst->cfg->netstatus.instring = NULL; inst->cfg->netstatus.instring = NULL;
inst->cfg->netstatus.outstring = NULL; inst->cfg->netstatus.outstring = NULL;
inst->cfg->netstatus.popup = NULL; inst->cfg->netstatus.popup = NULL;

View File

@ -17,9 +17,9 @@ struct _Netstatus_Config
}; };
EINTERN void _netstatus_config_updated(Instance *inst); EINTERN void _netstatus_config_updated(Instance *inst);
EINTERN void _netstatus_proc_getrstatus(Instance *inst); EINTERN void _netstatus_proc_getrstatus(Eina_Bool automax, unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, int *prev_inpercent);
EINTERN void _netstatus_proc_gettstatus(Instance *inst); EINTERN void _netstatus_proc_gettstatus(Eina_Bool automax, unsigned long *prev_out, unsigned long *prev_outcurrent, unsigned long *prev_outmax, int *prev_outpercent);
EINTERN void _netstatus_sysctl_getrstatus(Instance *inst); EINTERN void _netstatus_sysctl_getrstatus(Eina_Bool automax, unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, int *prev_inpercent);
EINTERN void _netstatus_sysctl_gettstatus(Instance *inst); EINTERN void _netstatus_sysctl_gettstatus(Eina_Bool automax, unsigned long *prev_out, unsigned long *prev_outcurrent, unsigned long *prev_outmax, int *prev_outpercent);
EINTERN Evas_Object *netstatus_configure(Instance *inst); EINTERN Evas_Object *netstatus_configure(Instance *inst);
#endif #endif

View File

@ -7,7 +7,7 @@ _config_close(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
Instance *inst = nc->inst; Instance *inst = nc->inst;
E_FREE_FUNC(inst->cfg->netstatus.configure, evas_object_del); E_FREE_FUNC(inst->cfg->netstatus.configure, evas_object_del);
E_FREE_FUNC(nc, free); E_FREE(nc);
e_config_save_queue(); e_config_save_queue();
} }

View File

@ -1,12 +1,16 @@
#include "netstatus.h" #include "netstatus.h"
void void
_netstatus_proc_getrstatus(Instance *inst) _netstatus_proc_getrstatus(Eina_Bool automax,
unsigned long *prev_in,
unsigned long *prev_incurrent,
unsigned long *prev_inmax,
int *prev_inpercent)
{ {
long in, dummy, tot_in = 0; unsigned long in, dummy, tot_in = 0;
long diffin; unsigned long diffin;
int percent = 0; int percent = 0;
char buf[4096], rin[4096], dummys[64]; char buf[4096], dummys[64];
FILE *f; FILE *f;
f = fopen("/proc/net/dev", "r"); f = fopen("/proc/net/dev", "r");
@ -23,47 +27,37 @@ _netstatus_proc_getrstatus(Instance *inst)
} }
fclose(f); fclose(f);
} }
diffin = tot_in - inst->cfg->netstatus.in; diffin = tot_in - *prev_in;
if (!inst->cfg->netstatus.in) if (!*prev_in)
inst->cfg->netstatus.in = tot_in; *prev_in = tot_in;
else else
{ {
inst->cfg->netstatus.in = tot_in; *prev_in = tot_in;
if (inst->cfg->netstatus.automax) if (automax)
{ {
if (diffin > inst->cfg->netstatus.inmax) if (diffin > *prev_inmax)
inst->cfg->netstatus.inmax = diffin; *prev_inmax = diffin;
} }
inst->cfg->netstatus.incurrent = diffin; *prev_incurrent = diffin;
if (inst->cfg->netstatus.inmax > 0) if (*prev_inmax > 0)
percent = 100 * ((float)inst->cfg->netstatus.incurrent / (float)inst->cfg->netstatus.inmax); percent = 100 * ((float)*prev_incurrent / (float)*prev_inmax);
if (percent > 100) percent = 100; if (percent > 100) percent = 100;
else if (percent < 0) percent = 0; else if (percent < 0) percent = 0;
inst->cfg->netstatus.inpercent = percent; *prev_inpercent = percent;
} }
if (!diffin)
{
snprintf(rin, sizeof(rin), "%s: 0 B/s", _("Receiving"));
}
else
{
if (diffin > 1048576)
snprintf(rin, sizeof(rin), "%s: %.2f MB/s", _("Receiving"), ((float)diffin / 1048576));
else if ((diffin > 1024) && (diffin < 1048576))
snprintf(rin, sizeof(rin), "%s: %lu KB/s", _("Receiving"), (diffin / 1024));
else
snprintf(rin, sizeof(rin), "%s: %lu B/s", _("Receiving"), diffin);
}
eina_stringshare_replace(&inst->cfg->netstatus.instring, rin);
} }
void void
_netstatus_proc_gettstatus(Instance *inst) _netstatus_proc_gettstatus(Eina_Bool automax,
unsigned long *prev_out,
unsigned long *prev_outcurrent,
unsigned long *prev_outmax,
int *prev_outpercent)
{ {
long out, dummy, tot_out = 0; unsigned long out, dummy, tot_out = 0;
long diffout; unsigned long diffout;
int percent = 0; int percent = 0;
char buf[4096], rout[4096], dummys[64]; char buf[4096], dummys[64];
FILE *f; FILE *f;
f = fopen("/proc/net/dev", "r"); f = fopen("/proc/net/dev", "r");
@ -80,37 +74,23 @@ _netstatus_proc_gettstatus(Instance *inst)
} }
fclose(f); fclose(f);
} }
diffout = tot_out - inst->cfg->netstatus.out; diffout = tot_out - *prev_out;
if (!inst->cfg->netstatus.out) if (!*prev_out)
inst->cfg->netstatus.out = tot_out; *prev_out = tot_out;
else else
{ {
inst->cfg->netstatus.out = tot_out; *prev_out = tot_out;
if (inst->cfg->netstatus.automax) if (automax)
{ {
if (diffout > inst->cfg->netstatus.outmax) if (diffout > *prev_outmax)
inst->cfg->netstatus.outmax = diffout; *prev_outmax = diffout;
} }
inst->cfg->netstatus.outcurrent = diffout; *prev_outcurrent = diffout;
if (inst->cfg->netstatus.outcurrent > 0) if (*prev_outcurrent > 0)
percent = 100 * ((float)inst->cfg->netstatus.outcurrent / (float)inst->cfg->netstatus.outmax); percent = 100 * ((float)*prev_outcurrent / (float)*prev_outmax);
if (percent > 100) percent = 100; if (percent > 100) percent = 100;
else if (percent < 0) percent = 0; else if (percent < 0) percent = 0;
inst->cfg->netstatus.outpercent = percent; *prev_outpercent = percent;
} }
if (!diffout)
{
snprintf(rout, sizeof(rout), "%s: 0 B/s", _("Sending"));
}
else
{
if (diffout > 1048576)
snprintf(rout, sizeof(rout), "%s: %.2f MB/s", _("Sending"), ((float)diffout / 1048576));
else if ((diffout > 1024) && (diffout < 1048576))
snprintf(rout, sizeof(rout), "%s: %lu KB/s", _("Sending"), (diffout / 1024));
else
snprintf(rout, sizeof(rout), "%s: %lu B/s", _("Sending"), diffout);
}
eina_stringshare_replace(&inst->cfg->netstatus.outstring, rout);
} }

View File

@ -106,10 +106,13 @@ _openbsd_generic_network_status(unsigned long int *in, unsigned long int *out)
#endif #endif
void void
_netstatus_sysctl_getrstatus(Instance *inst) _netstatus_sysctl_getrstatus(Eina_Bool automax,
unsigned long *prev_in,
unsigned long *prev_incurrent,
unsigned long *prev_inmax,
int *prev_inpercent)
{ {
char rin[256]; unsigned long tot_in = 0, diffin;
long tot_in = 0, diffin;
int percent = 0; int percent = 0;
unsigned long int incoming = 0, outgoing = 0; unsigned long int incoming = 0, outgoing = 0;
#if defined(__OpenBSD__) #if defined(__OpenBSD__)
@ -119,45 +122,34 @@ _netstatus_sysctl_getrstatus(Instance *inst)
#endif #endif
tot_in = incoming; tot_in = incoming;
diffin = tot_in - inst->cfg->netstatus.in; diffin = tot_in - *prev_in;
if (!inst->cfg->netstatus.in) if (!*prev_in)
inst->cfg->netstatus.in = tot_in; *prev_in = tot_in;
else else
{ {
inst->cfg->netstatus.in = tot_in; *prev_in = tot_in;
if (inst->cfg->netstatus.automax) if (automax)
{ {
if (diffin > inst->cfg->netstatus.inmax) if (diffin > *prev_inmax)
inst->cfg->netstatus.inmax = diffin; *prev_inmax = diffin;
} }
inst->cfg->netstatus.incurrent = diffin; *prev_incurrent = diffin;
if (inst->cfg->netstatus.inmax > 0) if (*prev_inmax > 0)
percent = 100 * ((float)inst->cfg->netstatus.incurrent / (float)inst->cfg->netstatus.inmax); percent = 100 * ((float)*prev_incurrent / (float)*prev_inmax);
if (percent > 100) percent = 100; if (percent > 100) percent = 100;
else if (percent < 0) percent = 0; else if (percent < 0) percent = 0;
inst->cfg->netstatus.inpercent = percent; *prev_inpercent = percent;
} }
if (!diffin)
{
snprintf(rin, sizeof(rin), "%s: 0 B/s", _("Receiving"));
}
else
{
if (diffin > 1048576)
snprintf(rin, sizeof(rin), "%s: %.2f MB/s", _("Receiving"), ((float)diffin / 1048576));
else if ((diffin > 1024) && (diffin < 1048576))
snprintf(rin, sizeof(rin), "%s: %lu KB/s", _("Receiving"), (diffin / 1024));
else
snprintf(rin, sizeof(rin), "%s: %lu B/s", _("Receiving"), diffin);
}
eina_stringshare_replace(&inst->cfg->netstatus.instring, rin);
} }
void void
_netstatus_sysctl_gettstatus(Instance *inst) _netstatus_sysctl_gettstatus(Eina_Bool automax,
unsigned long *prev_out,
unsigned long *prev_outcurrent,
unsigned long *prev_outmax,
int *prev_outpercent)
{ {
char rout[256]; unsigned long tot_out = 0, diffout;
long tot_out = 0, diffout;
int percent = 0; int percent = 0;
unsigned long int incoming = 0, outgoing = 0; unsigned long int incoming = 0, outgoing = 0;
#if defined(__OpenBSD__) #if defined(__OpenBSD__)
@ -167,37 +159,23 @@ _netstatus_sysctl_gettstatus(Instance *inst)
#endif #endif
tot_out = outgoing; tot_out = outgoing;
diffout = tot_out - inst->cfg->netstatus.out; diffout = tot_out - *prev_out;
if (!inst->cfg->netstatus.out) if (!*prev_out)
inst->cfg->netstatus.out = tot_out; *prev_out = tot_out;
else else
{ {
inst->cfg->netstatus.out = tot_out; *prev_out = tot_out;
if (inst->cfg->netstatus.automax) if (automax)
{ {
if (diffout > inst->cfg->netstatus.outmax) if (diffout > *prev_outmax)
inst->cfg->netstatus.outmax = diffout; *prev_outmax = diffout;
} }
inst->cfg->netstatus.outcurrent = diffout; *prev_outcurrent = diffout;
if (inst->cfg->netstatus.outcurrent > 0) if (*prev_outcurrent > 0)
percent = 100 * ((float)inst->cfg->netstatus.outcurrent / (float)inst->cfg->netstatus.outmax); percent = 100 * ((float)*prev_outcurrent / (float)*prev_outmax);
if (percent > 100) percent = 100; if (percent > 100) percent = 100;
else if (percent < 0) percent = 0; else if (percent < 0) percent = 0;
inst->cfg->netstatus.outpercent = percent; *prev_outpercent = percent;
} }
if (!diffout)
{
snprintf(rout, sizeof(rout), "%s: 0 B/s", _("Sending"));
}
else
{
if (diffout > 1048576)
snprintf(rout, sizeof(rout), "%s: %.2f MB/s", _("Sending"), ((float)diffout / 1048576));
else if ((diffout > 1024) && (diffout < 1048576))
snprintf(rout, sizeof(rout), "%s: %lu KB/s", _("Sending"), (diffout / 1024));
else
snprintf(rout, sizeof(rout), "%s: %lu B/s", _("Sending"), diffout);
}
eina_stringshare_replace(&inst->cfg->netstatus.outstring, rout);
} }

View File

@ -19,15 +19,11 @@ _sysinfo_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
evas_object_event_callback_del_full(inst->o_main, EVAS_CALLBACK_DEL, _sysinfo_deleted_cb, data); evas_object_event_callback_del_full(inst->o_main, EVAS_CALLBACK_DEL, _sysinfo_deleted_cb, data);
if (inst && inst->cfg) if (inst && inst->cfg)
{ {
if (inst->cfg->batman.done && inst->cfg->memusage.done && inst->cfg->thermal.done && sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
inst->cfg->cpumonitor.done && inst->cfg->cpuclock.done && inst->cfg->netstatus.done) if (inst->cfg->id >= 0)
{ sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg); E_FREE(inst->cfg);
if (inst->cfg->id >= 0) E_FREE(inst);
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
} }
} }
@ -107,7 +103,6 @@ _conf_item_get(int *id)
ci->batman.desktop_notifications = 0; ci->batman.desktop_notifications = 0;
ci->batman.popup = NULL; ci->batman.popup = NULL;
ci->batman.configure = NULL; ci->batman.configure = NULL;
ci->batman.done = EINA_FALSE;
ci->thermal.poll_interval = 128; ci->thermal.poll_interval = 128;
ci->thermal.low = 30; ci->thermal.low = 30;
ci->thermal.high = 80; ci->thermal.high = 80;
@ -116,8 +111,6 @@ _conf_item_get(int *id)
ci->thermal.units = CELSIUS; ci->thermal.units = CELSIUS;
ci->thermal.popup = NULL; ci->thermal.popup = NULL;
ci->thermal.configure = NULL; ci->thermal.configure = NULL;
ci->thermal.done = EINA_FALSE;
ci->thermal.defer = EINA_FALSE;
ci->cpuclock.poll_interval = 32; ci->cpuclock.poll_interval = 32;
ci->cpuclock.restore_governor = 0; ci->cpuclock.restore_governor = 0;
ci->cpuclock.auto_powersave = 1; ci->cpuclock.auto_powersave = 1;
@ -127,13 +120,7 @@ _conf_item_get(int *id)
ci->cpuclock.pstate_max = 101; ci->cpuclock.pstate_max = 101;
ci->cpuclock.popup = NULL; ci->cpuclock.popup = NULL;
ci->cpuclock.configure = NULL; ci->cpuclock.configure = NULL;
ci->cpuclock.done = EINA_FALSE;
ci->cpuclock.defer = EINA_FALSE;
ci->cpumonitor.done = EINA_FALSE;
ci->cpumonitor.defer = EINA_FALSE;
ci->cpumonitor.poll_interval = 32; ci->cpumonitor.poll_interval = 32;
ci->cpumonitor.total = 0;
ci->cpumonitor.idle = 0;
ci->cpumonitor.percent = 0; ci->cpumonitor.percent = 0;
ci->cpumonitor.popup = NULL; ci->cpumonitor.popup = NULL;
ci->cpumonitor.configure = NULL; ci->cpumonitor.configure = NULL;
@ -142,17 +129,7 @@ _conf_item_get(int *id)
ci->memusage.swp_percent = 0; ci->memusage.swp_percent = 0;
ci->memusage.popup = NULL; ci->memusage.popup = NULL;
ci->memusage.configure = NULL; ci->memusage.configure = NULL;
ci->memusage.done = EINA_FALSE;
ci->memusage.defer = EINA_FALSE;
ci->netstatus.poll_interval = 32; ci->netstatus.poll_interval = 32;
ci->netstatus.in = 0;
ci->netstatus.out = 0;
ci->netstatus.inmax = 0;
ci->netstatus.outmax = 0;
ci->netstatus.incurrent = 0;
ci->netstatus.outcurrent = 0;
ci->netstatus.inpercent = 0;
ci->netstatus.outpercent = 0;
ci->netstatus.instring = NULL; ci->netstatus.instring = NULL;
ci->netstatus.outstring = NULL; ci->netstatus.outstring = NULL;
ci->netstatus.popup = NULL; ci->netstatus.popup = NULL;
@ -162,8 +139,6 @@ _conf_item_get(int *id)
ci->netstatus.outmax = 0; ci->netstatus.outmax = 0;
ci->netstatus.receive_units = NETSTATUS_UNIT_BYTES; ci->netstatus.receive_units = NETSTATUS_UNIT_BYTES;
ci->netstatus.send_units = NETSTATUS_UNIT_BYTES; ci->netstatus.send_units = NETSTATUS_UNIT_BYTES;
ci->netstatus.done = EINA_FALSE;
ci->netstatus.defer = EINA_FALSE;
sysinfo_config->items = eina_list_append(sysinfo_config->items, ci); sysinfo_config->items = eina_list_append(sysinfo_config->items, ci);

View File

@ -193,10 +193,7 @@ struct _Config_Item
int pstate_max; int pstate_max;
Cpu_Status *status; Cpu_Status *status;
Ecore_Thread *frequency_check_thread; Ecore_Thread *frequency_check_thread;
Ecore_Event_Handler *handler;
Eina_List *handlers; Eina_List *handlers;
Eina_Bool defer;
Eina_Bool done;
} cpuclock; } cpuclock;
struct struct
{ {
@ -208,14 +205,10 @@ struct _Config_Item
Evas_Object *configure; Evas_Object *configure;
int poll_interval; int poll_interval;
int percent; int percent;
long total; int cores;
long idle;
Ecore_Thread *usage_check_thread; Ecore_Thread *usage_check_thread;
Eina_List *cores;
Eina_List *handlers; Eina_List *handlers;
Eina_Bool defer;
Eina_Bool done;
} cpumonitor; } cpumonitor;
struct struct
{ {
@ -234,8 +227,6 @@ struct _Config_Item
unsigned long swp_used; unsigned long swp_used;
Ecore_Thread *usage_check_thread; Ecore_Thread *usage_check_thread;
Eina_List *handlers; Eina_List *handlers;
Eina_Bool defer;
Eina_Bool done;
} memusage; } memusage;
struct struct
{ {
@ -247,20 +238,12 @@ struct _Config_Item
Netstatus_Unit receive_units; Netstatus_Unit receive_units;
Netstatus_Unit send_units; Netstatus_Unit send_units;
int poll_interval; int poll_interval;
long in; unsigned long inmax;
long out; unsigned long outmax;
long incurrent;
long outcurrent;
long inmax;
long outmax;
int inpercent;
int outpercent;
Eina_Stringshare *instring;
Eina_Stringshare *outstring;
Ecore_Thread *usage_check_thread; Ecore_Thread *usage_check_thread;
Eina_List *handlers; Eina_List *handlers;
Eina_Bool defer; Eina_Stringshare *instring;
Eina_Bool done; Eina_Stringshare *outstring;
} netstatus; } netstatus;
struct { struct {
Evas_Object *o_batman; Evas_Object *o_batman;

View File

@ -14,8 +14,8 @@ _thermal_thread_free(Tempthread *tth)
EINA_LIST_FREE(tth->tempdevs, s) eina_stringshare_del(s); EINA_LIST_FREE(tth->tempdevs, s) eina_stringshare_del(s);
#endif #endif
e_powersave_sleeper_free(tth->sleeper); e_powersave_sleeper_free(tth->sleeper);
free(tth->extn); E_FREE(tth->extn);
free(tth); E_FREE(tth);
} }
static void static void
@ -134,44 +134,17 @@ static void
_thermal_check_notify(void *data, Ecore_Thread *th, void *msg) _thermal_check_notify(void *data, Ecore_Thread *th, void *msg)
{ {
Tempthread *tth = data; Tempthread *tth = data;
Instance *inst = tth->inst;
int temp = (int)((long)msg); int temp = (int)((long)msg);
if (th != inst->cfg->thermal.th) return; if (th != tth->inst->cfg->thermal.th) return;
_thermal_apply(inst, temp); _thermal_apply(tth->inst, temp);
} }
static void static void
_thermal_check_done(void *data, Ecore_Thread *th EINA_UNUSED) _thermal_check_done(void *data, Ecore_Thread *th EINA_UNUSED)
{ {
Tempthread *tth = data; Tempthread *tth = data;
Instance *inst = tth->inst; _thermal_thread_free(tth);
if (inst->cfg->thermal.defer)
{
_thermal_thread_free(tth);
inst->cfg->thermal.defer = EINA_FALSE;
inst->cfg->thermal.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_THERMAL)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
else
{
if (inst->cfg->memusage.done && inst->cfg->cpumonitor.done &&
inst->cfg->netstatus.done && inst->cfg->cpuclock.done && inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
}
} }
#endif #endif
@ -373,10 +346,8 @@ _thermal_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
_thermal_removed_cb, inst); _thermal_removed_cb, inst);
if (inst->cfg->thermal.th) if (inst->cfg->thermal.th)
{ {
inst->cfg->thermal.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->thermal.th); ecore_thread_cancel(inst->cfg->thermal.th);
inst->cfg->thermal.th = NULL; inst->cfg->thermal.th = NULL;
return;
} }
_thermal_face_shutdown(inst); _thermal_face_shutdown(inst);
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg); sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
@ -402,25 +373,10 @@ sysinfo_thermal_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UN
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
if (inst->cfg->thermal.th) if (inst->cfg->thermal.th)
{ {
inst->cfg->thermal.defer = EINA_TRUE;
ecore_thread_cancel(inst->cfg->thermal.th); ecore_thread_cancel(inst->cfg->thermal.th);
inst->cfg->thermal.th = NULL; inst->cfg->thermal.th = NULL;
return;
} }
_thermal_face_shutdown(inst); _thermal_face_shutdown(inst);
inst->cfg->thermal.done = EINA_TRUE;
if (inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
if (inst->cfg->memusage.done && inst->cfg->cpumonitor.done &&
inst->cfg->netstatus.done && inst->cfg->cpuclock.done && inst->cfg->batman.done)
{
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
if (inst->cfg->id >= 0)
sysinfo_instances = eina_list_remove(sysinfo_instances, inst);
E_FREE(inst->cfg);
E_FREE(inst);
}
}
} }
static void static void
@ -433,8 +389,6 @@ _thermal_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED)
inst->cfg->thermal.temp = 900; inst->cfg->thermal.temp = 900;
inst->cfg->thermal.have_temp = EINA_FALSE; inst->cfg->thermal.have_temp = EINA_FALSE;
inst->cfg->thermal.defer = EINA_FALSE;
inst->cfg->thermal.done = EINA_FALSE;
inst->cfg->thermal.o_gadget = elm_layout_add(inst->o_main); inst->cfg->thermal.o_gadget = elm_layout_add(inst->o_main);
if (orient == E_GADGET_SITE_ORIENT_VERTICAL) if (orient == E_GADGET_SITE_ORIENT_VERTICAL)
@ -465,8 +419,6 @@ sysinfo_thermal_create(Evas_Object *parent, Instance *inst)
{ {
inst->cfg->thermal.temp = 900; inst->cfg->thermal.temp = 900;
inst->cfg->thermal.have_temp = EINA_FALSE; inst->cfg->thermal.have_temp = EINA_FALSE;
inst->cfg->thermal.defer = EINA_FALSE;
inst->cfg->thermal.done = EINA_FALSE;
inst->cfg->thermal.o_gadget = elm_layout_add(parent); inst->cfg->thermal.o_gadget = elm_layout_add(parent);
e_theme_edje_object_set(inst->cfg->thermal.o_gadget, "base/theme/gadget/thermal", e_theme_edje_object_set(inst->cfg->thermal.o_gadget, "base/theme/gadget/thermal",
@ -528,8 +480,6 @@ thermal_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_UN
inst = E_NEW(Instance, 1); inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id); inst->cfg = _conf_item_get(id);
*id = inst->cfg->id; *id = inst->cfg->id;
inst->cfg->thermal.defer = EINA_FALSE;
inst->cfg->thermal.done = EINA_FALSE;
inst->o_main = elm_box_add(parent); inst->o_main = elm_box_add(parent);
E_EXPAND(inst->o_main); E_EXPAND(inst->o_main);
evas_object_data_set(inst->o_main, "Instance", inst); evas_object_data_set(inst->o_main, "Instance", inst);

View File

@ -10,7 +10,7 @@ _config_close(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
Instance *inst = tc->inst; Instance *inst = tc->inst;
E_FREE_FUNC(inst->cfg->thermal.configure, evas_object_del); E_FREE_FUNC(inst->cfg->thermal.configure, evas_object_del);
E_FREE_FUNC(tc, free); E_FREE(tc);
e_config_save_queue(); e_config_save_queue();
} }

View File

@ -42,9 +42,9 @@ temperature_get_bus_files(const char *bus)
f = strdup(path); f = strdup(path);
if (f) result = eina_list_append(result, f); if (f) result = eina_list_append(result, f);
} }
free(file); E_FREE(file);
} }
free(name); E_FREE(name);
} }
return result; return result;
} }
@ -228,7 +228,7 @@ init(Tempthread *tth)
* one for the default. */ * one for the default. */
break; break;
} }
free(name); E_FREE(name);
} }
break; break;
@ -247,7 +247,7 @@ init(Tempthread *tth)
* one for the default. */ * one for the default. */
break; break;
} }
free(name); E_FREE(name);
} }
break; break;