aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/temperature/e_mod_main.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2008-01-11 07:33:57 +0000
committerCarsten Haitzler <raster@rasterman.com>2008-01-11 07:33:57 +0000
commitb70f5a0ecce6712de27fe17bec4aa03b980bd748 (patch)
tree6ff9f9a430efe076a442fc0482b9137374b612f1 /src/modules/temperature/e_mod_main.c
parentRemove unused variable. (diff)
downloadenlightenment-b70f5a0ecce6712de27fe17bec4aa03b980bd748.tar.gz
e:
1. configure/build changes to allow cross-compiling painlessly 2. pager module namespace changes - this was still dirty afdter the namespace cleanup, so clean it up 3. add a powersave subsystem - doesnt have an "automatic" way to turn on and off right now, this i think is best provided by modules (that do things like monitor acpi status's (eg close lid of laptop), AC power status etc. etc. this allows e to nicely defer "power" expensive actions to avoid disk spinups etc. 4. move to use the new ecore poller system - discussed long ago as part of power management/saving issues. now it exists 5. add a canvas idle flush call that helsp cope with the new shm greedy software x11 engine stuff 6. use the new powersave subsystem where appropriate 7. fix non-zeroed/initted memory access in e_fm_main 8. fix mem leak for e menus 9. remove ipc handlers for changed/removed config values 10. use animaotr not timer for menu scrolls - then menu scrolls obey the fps config 11. fix up timer/poll happienss of cursor idle stuff 12. remove avoid damage from popups for now - causing problems 13. change battery and temp readouts to b e shorter so they fit 14. pager can emit signals on focus change for mini-windows now 15. temperature module now uses a slave process and uses stdin/out to talk to it and get output - this makes e smoother as in my expereicne i found getting the temp on my laptop actually took like 200ms so e "hang" for 200ms while reading the acpi files - so now the subprocess does it and just writesa back to e when it gets it. ecore: 1. add ecore_pollers. see the documentation on them in doxygen comments :) 2. fix timers to only go off when they have to - bug there that made e's select time out a LOT more than it needed to. defensive coding hid the problem. now fixed. e should be much more power friendly now. 3. formatting/niceness in ecore_exe stuff 4. some comments on comments with SIGIO ideas vs. select 5. add call to be able to add an idle enterer at the start of the list of them, not just the end (as has been the default) 6. fix ecore_evas to support auto evas idler calls after 0.5 secs of idle in all canvases - and to do it right 7. if argb destination - set the shape EVENT shape (to mask out events in transparent regions much like shape does withotu translucency) 8. in ecore_x add support for the event shape evas: 1. fix cache to work properly and not just always fill up (as it seemed to like to think cahce useage dropped below 0 when it didnt and thus just over-fill) 2. software x11 engine now ONLY uses shm segments - no ximages over the socket. this ximage hack was there to avoid the 2 round trips involved in setting up an shm image - now i mitigated that wih an shm image cache pool. it keeps shm images around and repurposes them for new update regions if appropriate. this means many fewer shm creates (about 1/100th the number) and since we recycle the memory less 0 memory page filling by the kernel - in the end, i recorded about a 10-20% speedup over the old software x11 engine. simple tests i have seen up to 120% speedups. idle flush now does something - it frees all the cached shm segments. it has a hard-coded limit of 4mb worth of shm segments (or 32 segments - whichever comes first) to keep around. once can never complain much about speedups methinks :). also evas will defer sync until the NEXT frame is written - this means evas can calculate the next frame of data while x dma's/copies the images to the screen at the same time (if you hve a dual core or multi-cpu machnike or your xserver is able to use DMA to copy image data to the screen/video ram then this should see a decent speedup). SVN revision: 33448
Diffstat (limited to 'src/modules/temperature/e_mod_main.c')
-rw-r--r--src/modules/temperature/e_mod_main.c462
1 files changed, 133 insertions, 329 deletions
diff --git a/src/modules/temperature/e_mod_main.c b/src/modules/temperature/e_mod_main.c
index 75dd2db3b..4b63fe633 100644
--- a/src/modules/temperature/e_mod_main.c
+++ b/src/modules/temperature/e_mod_main.c
@@ -36,10 +36,10 @@ static const E_Gadcon_Client_Class _gadcon_class =
/**/
/* actual module specifics */
+static int _temperature_cb_exe_data(void *data, int type, void *event);
+static int _temperature_cb_exe_del(void *data, int type, void *event);
static void _temperature_face_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _temperature_face_cb_post_menu(void *data, E_Menu *m);
-static void _temperature_sensor_init(Config_Face *inst);
-static int _temperature_cb_check(void *data);
static void _temperature_face_level_set(Config_Face *inst, double level);
static void _temperature_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi);
@@ -59,23 +59,23 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
Evas_Object *o;
E_Gadcon_Client *gcc;
Config_Face *inst;
+ char buf[PATH_MAX];
inst = evas_hash_find(temperature_config->faces, id);
if (!inst)
{
inst = E_NEW(Config_Face, 1);
inst->id = evas_stringshare_add(id);
- inst->poll_time = 10.0;
+ inst->poll_interval = 128;
inst->low = 30;
inst->high = 80;
inst->sensor_type = SENSOR_TYPE_NONE;
inst->sensor_name = NULL;
- inst->sensor_path = NULL;
inst->units = CELCIUS;
temperature_config->faces = evas_hash_direct_add(temperature_config->faces, inst->id, inst);
}
if (!inst->id) evas_stringshare_add(id);
- E_CONFIG_LIMIT(inst->poll_time, 0.5, 1000.0);
+ E_CONFIG_LIMIT(inst->poll_interval, 1, 1024);
E_CONFIG_LIMIT(inst->low, 0, 100);
E_CONFIG_LIMIT(inst->high, 0, 220);
E_CONFIG_LIMIT(inst->units, CELCIUS, FAHRENHEIT);
@@ -91,14 +91,27 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
inst->o_temp = o;
inst->module = temperature_config->module;
inst->have_temp = -1;
- inst->temperature_check_timer =
- ecore_timer_add(inst->poll_time, _temperature_cb_check, inst);
-
+ snprintf(buf, sizeof(buf),
+ "%s/%s/tempget %i \"%s\" %i",
+ e_module_dir_get(temperature_config->module), MODULE_ARCH,
+ inst->sensor_type,
+ (inst->sensor_name != NULL ? inst->sensor_name : "(null)"),
+ inst->poll_interval);
+ inst->tempget_exe = ecore_exe_pipe_run(buf,
+ ECORE_EXE_PIPE_READ |
+ ECORE_EXE_PIPE_READ_LINE_BUFFERED,
+ inst);
+ inst->tempget_data_handler =
+ ecore_event_handler_add(ECORE_EXE_EVENT_DATA,
+ _temperature_cb_exe_data,
+ inst);
+ inst->tempget_del_handler =
+ ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
+ _temperature_cb_exe_del,
+ inst);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
_temperature_face_cb_mouse_down, inst);
- _temperature_sensor_init(inst);
- _temperature_cb_check(inst);
return gcc;
}
@@ -108,8 +121,22 @@ _gc_shutdown(E_Gadcon_Client *gcc)
Config_Face *inst;
inst = gcc->data;
- if (inst->temperature_check_timer) ecore_timer_del(inst->temperature_check_timer);
- inst->temperature_check_timer = NULL;
+ if (inst->tempget_exe)
+ {
+ ecore_exe_terminate(inst->tempget_exe);
+ ecore_exe_free(inst->tempget_exe);
+ inst->tempget_exe = NULL;
+ }
+ if (inst->tempget_data_handler)
+ {
+ ecore_event_handler_del(inst->tempget_data_handler);
+ inst->tempget_data_handler = NULL;
+ }
+ if (inst->tempget_del_handler)
+ {
+ ecore_event_handler_del(inst->tempget_del_handler);
+ inst->tempget_del_handler = NULL;
+ }
if (inst->o_temp) evas_object_del(inst->o_temp);
inst->o_temp = NULL;
if (inst->config_dialog) e_object_del(E_OBJECT(inst->config_dialog));
@@ -157,12 +184,11 @@ _gc_id_new(void)
inst = E_NEW(Config_Face, 1);
inst->id = evas_stringshare_add(id);
- inst->poll_time = 10.0;
+ inst->poll_interval = 128;
inst->low = 30;
inst->high = 80;
inst->sensor_type = SENSOR_TYPE_NONE;
inst->sensor_name = NULL;
- inst->sensor_path = NULL;
inst->units = CELCIUS;
temperature_config->faces = evas_hash_direct_add(temperature_config->faces, inst->id, inst);
return inst->id;
@@ -178,7 +204,6 @@ _gc_id_del(const char *id)
{
temperature_config->faces = evas_hash_del(temperature_config->faces, id, inst);
if (inst->sensor_name) evas_stringshare_del(inst->sensor_name);
- if (inst->sensor_path) evas_stringshare_del(inst->sensor_path);
free(inst);
}
}
@@ -188,6 +213,83 @@ _gc_id_del(const char *id)
/***************************************************************************/
/**/
+static int
+_temperature_cb_exe_data(void *data, int type, void *event)
+{
+ Ecore_Exe_Event_Data *ev;
+ Config_Face *inst;
+ int temp;
+
+ ev = event;
+ inst = data;
+ if (ev->exe != inst->tempget_exe) return 1;
+ temp = -999;
+ if ((ev->lines) && (ev->lines[0].line))
+ {
+ int i;
+
+ for (i = 0; ev->lines[i].line; i++)
+ {
+ if (!strcmp(ev->lines[i].line, "ERROR"))
+ temp = -999;
+ else
+ temp = atoi(ev->lines[i].line);
+ }
+ }
+ if (temp != -999)
+ {
+ char *utf8;
+ char buf[256];
+
+ if (inst->units == FAHRENHEIT)
+ temp = (temp * 9.0 / 5.0) + 32;
+
+ if (inst->have_temp != 1)
+ {
+ /* enable therm object */
+ edje_object_signal_emit(inst->o_temp, "e,state,known", "");
+ inst->have_temp = 1;
+ }
+
+ if (inst->units == FAHRENHEIT)
+ snprintf(buf, sizeof(buf), "%iF", temp);
+ else
+ snprintf(buf, sizeof(buf), "%iC", temp);
+ utf8 = ecore_txt_convert("iso-8859-1", "utf-8", buf);
+
+ _temperature_face_level_set(inst,
+ (double)(temp - inst->low) /
+ (double)(inst->high - inst->low));
+ edje_object_part_text_set(inst->o_temp, "e.text.reading", utf8);
+ free(utf8);
+ }
+ else
+ {
+ if (inst->have_temp != 0)
+ {
+ /* disable therm object */
+ edje_object_signal_emit(inst->o_temp, "e,state,unknown", "");
+ edje_object_part_text_set(inst->o_temp, "e.text.reading", "N/A");
+ _temperature_face_level_set(inst, 0.5);
+ inst->have_temp = 0;
+ }
+ }
+ return 0;
+}
+
+static int
+_temperature_cb_exe_del(void *data, int type, void *event)
+{
+ Ecore_Exe_Event_Del *ev;
+ Config_Face *inst;
+
+ ev = event;
+ inst = data;
+ if (ev->exe != inst->tempget_exe) return 1;
+ inst->tempget_exe = NULL;
+ return 0;
+}
+
static void
_temperature_face_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
@@ -237,309 +339,6 @@ _temperature_face_cb_post_menu(void *data, E_Menu *m)
}
static void
-_temperature_sensor_init(Config_Face *inst)
-{
- Ecore_List *therms;
- char path[PATH_MAX];
-#ifdef __FreeBSD__
- int len;
-#endif
-
- if ((!inst->sensor_type) || (!inst->sensor_name))
- {
- if (inst->sensor_name) evas_stringshare_del(inst->sensor_name);
- if (inst->sensor_path) evas_stringshare_del(inst->sensor_path);
- inst->sensor_path = NULL;
-#ifdef __FreeBSD__
- /* TODO: FreeBSD can also have more temperature sensors! */
- inst->sensor_type = SENSOR_TYPE_FREEBSD;
- inst->sensor_name = evas_stringshare_add("tz0");
-#else
- therms = ecore_file_ls("/proc/acpi/thermal_zone");
- if ((therms) && (!ecore_list_empty_is(therms)))
- {
- char *name;
-
- name = ecore_list_next(therms);
- inst->sensor_type = SENSOR_TYPE_LINUX_ACPI;
- inst->sensor_name = evas_stringshare_add(name);
-
- ecore_list_destroy(therms);
- }
- else
- {
- if (therms) ecore_list_destroy(therms);
-
- if (ecore_file_exists("/proc/omnibook/temperature"))
- {
- inst->sensor_type = SENSOR_TYPE_OMNIBOOK;
- inst->sensor_name = evas_stringshare_add("dummy");
- }
- else if (ecore_file_exists("/sys/devices/temperatures/sensor1_temperature"))
- {
- inst->sensor_type = SENSOR_TYPE_LINUX_PBOOK;
- inst->sensor_name = evas_stringshare_add("dummy");
- }
- else if (ecore_file_exists("/sys/devices/temperatures/cpu_temperature"))
- {
- inst->sensor_type = SENSOR_TYPE_LINUX_MACMINI;
- inst->sensor_name = evas_stringshare_add("dummy");
- }
- else if (ecore_file_exists("/sys/devices/platform/coretemp.0/temp1_input"))
- {
- inst->sensor_type = SENSOR_TYPE_LINUX_INTELCORETEMP;
- inst->sensor_name = evas_stringshare_add("dummy");
- }
- else
- {
- therms = temperature_get_i2c_files();
- if (therms)
- {
- char *name;
-
- if ((name = ecore_list_next(therms)))
- {
- if (ecore_file_exists(name))
- {
- int len;
-
- sprintf(path, "%s", ecore_file_file_get(name));
- len = strlen(path);
- if (len > 6)
- path[len - 6] = '\0';
- inst->sensor_type = SENSOR_TYPE_LINUX_I2C;
- inst->sensor_path = evas_stringshare_add(name);
- inst->sensor_name = evas_stringshare_add(path);
- }
- }
- ecore_list_destroy(therms);
- }
- }
- }
-#endif
- }
- if ((inst->sensor_type) &&
- (inst->sensor_name) &&
- (!inst->sensor_path))
- {
- switch (inst->sensor_type)
- {
- case SENSOR_TYPE_NONE:
- break;
- case SENSOR_TYPE_FREEBSD:
-#ifdef __FreeBSD__
- snprintf(path, sizeof(path), "hw.acpi.thermal.%s.temperature",
- inst->sensor_name);
- inst->sensor_path = evas_stringshare_add(path);
-
- len = 5;
- sysctlnametomib(inst->sensor_path, inst->mib, &len);
-#endif
- break;
- case SENSOR_TYPE_OMNIBOOK:
- inst->sensor_path = evas_stringshare_add("/proc/omnibook/temperature");
- break;
- case SENSOR_TYPE_LINUX_MACMINI:
- inst->sensor_path = evas_stringshare_add("/sys/devices/temperatures/cpu_temperature");
- break;
- case SENSOR_TYPE_LINUX_PBOOK:
- inst->sensor_path = evas_stringshare_add("/sys/devices/temperatures/sensor1_temperature");
- break;
- case SENSOR_TYPE_LINUX_INTELCORETEMP:
- inst->sensor_path = evas_stringshare_add("/sys/devices/platform/coretemp.0/temp1_input");
- break;
- case SENSOR_TYPE_LINUX_I2C:
- therms = ecore_file_ls("/sys/bus/i2c/devices");
- if (therms)
- {
- char *name;
-
- while ((name = ecore_list_next(therms)))
- {
- sprintf(path, "/sys/bus/i2c/devices/%s/%s_input",
- name, inst->sensor_name);
- if (ecore_file_exists(path))
- {
- inst->sensor_path = evas_stringshare_add(path);
- /* We really only care about the first one for the default. */
- break;
- }
- }
- ecore_list_destroy(therms);
- }
- break;
- case SENSOR_TYPE_LINUX_ACPI:
- snprintf(path, sizeof(path), "/proc/acpi/thermal_zone/%s/temperature",
- inst->sensor_name);
- inst->sensor_path = evas_stringshare_add(path);
- break;
- }
- }
-}
-
-static int
-_temperature_cb_check(void *data)
-{
- FILE *f;
- int ret = 0;
- Config_Face *inst;
- int temp = 0;
- char buf[4096];
-#ifdef __FreeBSD__
- int len;
-#endif
-
- inst = data;
-
- /* TODO: Make standard parser. Seems to be two types of temperature string:
- * - Somename: <temp> C
- * - <temp>
- */
- switch (inst->sensor_type)
- {
- case SENSOR_TYPE_NONE:
- /* TODO: Slow down timer? */
- break;
- case SENSOR_TYPE_FREEBSD:
-#ifdef __FreeBSD__
- len = sizeof(temp);
- if (sysctl(inst->mib, 5, &temp, &len, NULL, 0) != -1)
- {
- temp = (temp - 2732) / 10;
- ret = 1;
- }
- else
- goto error;
-#endif
- break;
- case SENSOR_TYPE_OMNIBOOK:
- f = fopen(inst->sensor_path, "r");
- if (f)
- {
- char dummy[4096];
-
- fgets(buf, sizeof(buf), f); buf[sizeof(buf) - 1] = 0;
- if (sscanf(buf, "%s %s %i", dummy, dummy, &temp) == 3)
- ret = 1;
- else
- goto error;
- fclose(f);
- }
- else
- goto error;
- break;
- case SENSOR_TYPE_LINUX_MACMINI:
- case SENSOR_TYPE_LINUX_PBOOK:
- f = fopen(inst->sensor_path, "rb");
- if (f)
- {
- fgets(buf, sizeof(buf), f); buf[sizeof(buf) - 1] = 0;
- if (sscanf(buf, "%i", &temp) == 1)
- ret = 1;
- else
- goto error;
- fclose(f);
- }
- else
- goto error;
- break;
- case SENSOR_TYPE_LINUX_INTELCORETEMP:
- case SENSOR_TYPE_LINUX_I2C:
- f = fopen(inst->sensor_path, "r");
- if (f)
- {
- fgets(buf, sizeof(buf), f);
- buf[sizeof(buf) - 1] = 0;
-
- /* actuallty read the temp */
- if (sscanf(buf, "%i", &temp) == 1)
- ret = 1;
- else
- goto error;
- /* Hack for temp */
- temp = temp / 1000;
- fclose(f);
- }
- else
- goto error;
- break;
- case SENSOR_TYPE_LINUX_ACPI:
- f = fopen(inst->sensor_path, "r");
- if (f)
- {
- char *p, *q;
- fgets(buf, sizeof(buf), f); buf[sizeof(buf) - 1] = 0;
- fclose(f);
- p = strchr(buf, ':');
- if (p)
- {
- p++;
- while (*p == ' ') p++;
- q = strchr(p, ' ');
- if (q) *q = 0;
- temp = atoi(p);
- ret = 1;
- }
- else
- goto error;
- }
- else
- goto error;
- break;
- }
-
- if (inst->units == FAHRENHEIT)
- temp = (temp * 9.0 / 5.0) + 32;
-
- if (ret)
- {
- char *utf8;
-
- if (inst->have_temp != 1)
- {
- /* enable therm object */
- edje_object_signal_emit(inst->o_temp, "e,state,known", "");
- inst->have_temp = 1;
- }
-
- if (inst->units == FAHRENHEIT)
- snprintf(buf, sizeof(buf), "%iF", temp);
- else
- snprintf(buf, sizeof(buf), "%iC", temp);
- utf8 = ecore_txt_convert("iso-8859-1", "utf-8", buf);
-
- _temperature_face_level_set(inst,
- (double)(temp - inst->low) /
- (double)(inst->high - inst->low));
- edje_object_part_text_set(inst->o_temp, "e.text.reading", utf8);
- free(utf8);
- }
- else
- {
- if (inst->have_temp != 0)
- {
- /* disable therm object */
- edje_object_signal_emit(inst->o_temp, "e,state,unknown", "");
- edje_object_part_text_set(inst->o_temp, "e.text.reading", "NO TEMP");
- _temperature_face_level_set(inst, 0.5);
- inst->have_temp = 0;
- }
- }
- return 1;
-
-error:
- /* TODO: Error count? Might be a temporary problem */
- /* TODO: Error dialog */
- /* TODO: This should be further up, so that it will affect the gadcon */
- inst->sensor_type = SENSOR_TYPE_NONE;
- if (inst->sensor_name) evas_stringshare_del(inst->sensor_name);
- inst->sensor_name = NULL;
- if (inst->sensor_path) evas_stringshare_del(inst->sensor_path);
- inst->sensor_path = NULL;
- return 1;
-}
-
-static void
_temperature_face_level_set(Config_Face *inst, double level)
{
Edje_Message_Float msg;
@@ -568,7 +367,6 @@ _temperature_face_shutdown(Evas_Hash *hash, const char *key, void *hdata, void *
inst = hdata;
if (inst->sensor_name) evas_stringshare_del(inst->sensor_name);
- if (inst->sensor_path) evas_stringshare_del(inst->sensor_path);
if (inst->id) evas_stringshare_del(inst->id);
free(inst);
return 1;
@@ -591,15 +389,21 @@ _temperature_face_id_max(Evas_Hash *hash, const char *key, void *hdata, void *fd
void
temperature_face_update_config(Config_Face *inst)
{
- if (inst->sensor_path)
- evas_stringshare_del(inst->sensor_path);
- inst->sensor_path = NULL;
-
- _temperature_sensor_init(inst);
-
- if (inst->temperature_check_timer) ecore_timer_del(inst->temperature_check_timer);
- inst->temperature_check_timer =
- ecore_timer_add(inst->poll_time, _temperature_cb_check, inst);
+ char buf[PATH_MAX];
+
+ ecore_exe_terminate(inst->tempget_exe);
+ ecore_exe_free(inst->tempget_exe);
+ inst->tempget_exe = NULL;
+ snprintf(buf, sizeof(buf),
+ "%s/%s/tempget %i \"%s\" %i",
+ e_module_dir_get(temperature_config->module), MODULE_ARCH,
+ inst->sensor_type,
+ (inst->sensor_name != NULL ? inst->sensor_name : "(null)"),
+ inst->poll_interval);
+ inst->tempget_exe = ecore_exe_pipe_run(buf,
+ ECORE_EXE_PIPE_READ |
+ ECORE_EXE_PIPE_READ_LINE_BUFFERED,
+ inst);
}
Ecore_List *
@@ -673,7 +477,7 @@ e_modapi_init(E_Module *m)
#define T Config_Face
#define D conf_face_edd
E_CONFIG_VAL(D, T, id, STR);
- E_CONFIG_VAL(D, T, poll_time, DOUBLE);
+ E_CONFIG_VAL(D, T, poll_interval, INT);
E_CONFIG_VAL(D, T, low, INT);
E_CONFIG_VAL(D, T, high, INT);
E_CONFIG_VAL(D, T, sensor_type, INT);