2 #include "e_mod_main.h"
6 #include <sys/sysctl.h>
10 #include <sys/types.h>
11 #include <sys/sysctl.h>
12 #include <sys/sensors.h>
16 /* gadcon requirements */
17 static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
18 static void _gc_shutdown(E_Gadcon_Client *gcc);
19 static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
20 static const char *_gc_label(E_Gadcon_Client_Class *client_class);
21 static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas);
22 static const char *_gc_id_new(E_Gadcon_Client_Class *client_class);
23 /* and actually define the gadcon class that this module provides (just 1) */
24 static const E_Gadcon_Client_Class _gadcon_class =
26 GADCON_CLIENT_CLASS_VERSION, "temperature",
28 _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL,
29 e_gadcon_site_is_not_toolbar
31 E_GADCON_CLIENT_STYLE_PLAIN
34 /* actual module specifics */
36 static void _temperature_face_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
37 static void _temperature_face_cb_post_menu(void *data, E_Menu *m);
39 static void _temperature_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi);
41 static Eina_Bool _temperature_face_shutdown(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *hdata, void *fdata __UNUSED__);
42 static Eina_Bool _temperature_face_id_max(const Eina_Hash *hash __UNUSED__, const void *key, void *hdata __UNUSED__, void *fdata);
44 static E_Config_DD *conf_edd = NULL;
45 static E_Config_DD *conf_face_edd = NULL;
49 static Config *temperature_config = NULL;
51 static E_Gadcon_Client *
52 _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
58 inst = eina_hash_find(temperature_config->faces, id);
61 inst = E_NEW(Config_Face, 1);
62 inst->id = eina_stringshare_add(id);
63 inst->poll_interval = 128;
66 inst->sensor_type = SENSOR_TYPE_NONE;
67 inst->sensor_name = NULL;
68 inst->units = CELCIUS;
72 if (!temperature_config->faces)
73 temperature_config->faces = eina_hash_string_superfast_new(NULL);
74 eina_hash_direct_add(temperature_config->faces, inst->id, inst);
76 if (!inst->id) inst->id = eina_stringshare_add(id);
77 E_CONFIG_LIMIT(inst->poll_interval, 1, 1024);
78 E_CONFIG_LIMIT(inst->low, 0, 100);
79 E_CONFIG_LIMIT(inst->high, 0, 220);
80 E_CONFIG_LIMIT(inst->units, CELCIUS, FAHRENHEIT);
82 E_CONFIG_LIMIT(inst->backend, TEMPGET, UDEV);
85 o = edje_object_add(gc->evas);
86 e_theme_edje_object_set(o, "base/theme/modules/temperature",
87 "e/modules/temperature/main");
89 gcc = e_gadcon_client_new(gc, name, id, style, o);
94 inst->module = temperature_config->module;
97 if (inst->backend == TEMPGET)
99 inst->tempget_data_handler =
100 ecore_event_handler_add(ECORE_EXE_EVENT_DATA,
101 _temperature_cb_exe_data, inst);
102 inst->tempget_del_handler =
103 ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
104 _temperature_cb_exe_del, inst);
110 ecore_poller_add(ECORE_POLLER_CORE, inst->poll_interval,
111 temperature_udev_update_poll, inst);
112 temperature_udev_update(inst);
115 inst->tempget_data_handler =
116 ecore_event_handler_add(ECORE_EXE_EVENT_DATA,
117 _temperature_cb_exe_data, inst);
118 inst->tempget_del_handler =
119 ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
120 _temperature_cb_exe_del, inst);
123 temperature_face_update_config(inst);
125 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
126 _temperature_face_cb_mouse_down, inst);
131 _gc_shutdown(E_Gadcon_Client *gcc)
137 if (inst->tempget_exe)
139 ecore_exe_terminate(inst->tempget_exe);
140 ecore_exe_free(inst->tempget_exe);
141 inst->tempget_exe = NULL;
143 if (inst->tempget_data_handler)
145 ecore_event_handler_del(inst->tempget_data_handler);
146 inst->tempget_data_handler = NULL;
148 if (inst->tempget_del_handler)
150 ecore_event_handler_del(inst->tempget_del_handler);
151 inst->tempget_del_handler = NULL;
153 #ifdef HAVE_EEEZ_UDEV
154 if (inst->temp_poller)
155 ecore_poller_del(inst->temp_poller);
158 if (inst->o_temp) evas_object_del(inst->o_temp);
160 if (inst->config_dialog) e_object_del(E_OBJECT(inst->config_dialog));
161 inst->config_dialog = NULL;
162 if (inst->menu) e_object_del(E_OBJECT(inst->menu));
167 _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__)
169 e_gadcon_client_aspect_set(gcc, 16, 16);
170 e_gadcon_client_min_size_set(gcc, 16, 16);
174 _gc_label(E_Gadcon_Client_Class *client_class __UNUSED__)
176 return _("Temperature");
180 _gc_icon(E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas)
185 o = edje_object_add(evas);
186 snprintf(buf, sizeof(buf), "%s/e-module-temperature.edj",
187 e_module_dir_get(temperature_config->module));
188 edje_object_file_set(o, buf, "icon");
193 _gc_id_new(E_Gadcon_Client_Class *client_class __UNUSED__)
198 snprintf(id, sizeof(id), "%s.%d", _gadcon_class.name, ++uuid);
200 inst = E_NEW(Config_Face, 1);
201 inst->id = eina_stringshare_add(id);
202 inst->poll_interval = 128;
205 inst->sensor_type = SENSOR_TYPE_NONE;
206 inst->sensor_name = NULL;
207 inst->units = CELCIUS;
209 inst->backend = TEMPGET;
211 if (!temperature_config->faces)
212 temperature_config->faces = eina_hash_string_superfast_new(NULL);
213 eina_hash_direct_add(temperature_config->faces, inst->id, inst);
218 _temperature_face_cb_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
221 Evas_Event_Mouse_Down *ev;
225 if ((ev->button == 3) && (!inst->menu))
232 mi = e_menu_item_new(m);
233 e_menu_item_label_set(mi, _("Settings"));
234 e_util_menu_item_theme_icon_set(mi, "configure");
235 e_menu_item_callback_set(mi, _temperature_face_cb_menu_configure, inst);
237 m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
238 e_menu_post_deactivate_callback_set(m, _temperature_face_cb_post_menu, inst);
241 e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon,
242 &cx, &cy, NULL, NULL);
243 e_menu_activate_mouse(m,
244 e_util_zone_current_get(e_manager_current_get()),
245 cx + ev->output.x, cy + ev->output.y, 1, 1,
246 E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
251 _temperature_face_cb_post_menu(void *data, E_Menu *m __UNUSED__)
256 if (!inst->menu) return;
257 e_object_del(E_OBJECT(inst->menu));
262 _temperature_face_level_set(Config_Face *inst, double level)
264 Edje_Message_Float msg;
266 if (level < 0.0) level = 0.0;
267 else if (level > 1.0) level = 1.0;
269 edje_object_message_send(inst->o_temp, EDJE_MESSAGE_FLOAT, 1, &msg);
273 _temperature_face_cb_menu_configure(void *data, E_Menu *m __UNUSED__, E_Menu_Item *mi __UNUSED__)
278 if (inst->config_dialog) return;
279 config_temperature_module(inst);
283 _temperature_face_shutdown(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *hdata, void *fdata __UNUSED__)
288 if (inst->sensor_name) eina_stringshare_del(inst->sensor_name);
289 if (inst->id) eina_stringshare_del(inst->id);
295 EINA_LIST_FREE(inst->tempdevs, s)
296 eina_stringshare_del(s);
304 _temperature_face_id_max(const Eina_Hash *hash __UNUSED__, const void *key, void *hdata __UNUSED__, void *fdata)
311 p = strrchr(key, '.');
312 if (p) num = atoi(p + 1);
313 if (num > *max) *max = num;
318 temperature_face_update_config(Config_Face *inst)
322 if (inst->tempget_exe)
324 ecore_exe_terminate(inst->tempget_exe);
325 ecore_exe_free(inst->tempget_exe);
326 inst->tempget_exe = NULL;
330 if (inst->backend == TEMPGET)
332 if (inst->temp_poller)
334 ecore_poller_del(inst->temp_poller);
335 inst->temp_poller = NULL;
337 if (!inst->tempget_exe)
339 snprintf(buf, sizeof(buf),
340 "%s/%s/tempget %i \"%s\" %i",
341 e_module_dir_get(temperature_config->module), MODULE_ARCH,
343 (inst->sensor_name ? inst->sensor_name : "(null)"),
344 inst->poll_interval);
346 ecore_exe_pipe_run(buf, ECORE_EXE_PIPE_READ |
347 ECORE_EXE_PIPE_READ_LINE_BUFFERED |
348 ECORE_EXE_NOT_LEADER, inst);
351 else if (inst->backend == UDEV)
353 /*avoid creating a new poller if possible*/
354 if (inst->temp_poller)
355 ecore_poller_poller_interval_set(inst->temp_poller,
356 inst->poll_interval);
360 ecore_poller_add(ECORE_POLLER_CORE, inst->poll_interval,
361 temperature_udev_update_poll, inst);
365 if (!inst->tempget_exe)
367 snprintf(buf, sizeof(buf),
368 "%s/%s/tempget %i \"%s\" %i",
369 e_module_dir_get(temperature_config->module), MODULE_ARCH,
371 (inst->sensor_name ? inst->sensor_name : "(null)"),
372 inst->poll_interval);
374 ecore_exe_pipe_run(buf, ECORE_EXE_PIPE_READ |
375 ECORE_EXE_PIPE_READ_LINE_BUFFERED |
376 ECORE_EXE_NOT_LEADER, inst);
382 temperature_get_bus_files(const char* bus)
384 Eina_List *result, *therms;
386 char busdir[PATH_MAX];
391 snprintf(busdir, sizeof(busdir), "/sys/bus/%s/devices", bus);
392 /* Look through all the devices for the given bus. */
393 therms = ecore_file_ls(busdir);
398 EINA_LIST_FREE(therms, name)
403 /* Search each device for temp*_input, these should be
404 * temperature devices. */
405 snprintf(path, sizeof(path), "%s/%s", busdir, name);
406 files = ecore_file_ls(path);
407 EINA_LIST_FREE(files, file)
409 if ((!strncmp("temp", file, 4)) &&
410 (!strcmp("_input", &file[strlen(file) - 6])))
414 snprintf(path, sizeof(path),
415 "%s/%s/%s", busdir, name, file);
417 if (f) result = eina_list_append(result, f);
429 EAPI E_Module_Api e_modapi =
431 E_MODULE_API_VERSION,
436 e_modapi_init(E_Module *m)
438 conf_face_edd = E_CONFIG_DD_NEW("Temperature_Config_Face", Config_Face);
441 #define T Config_Face
442 #define D conf_face_edd
443 E_CONFIG_VAL(D, T, id, STR);
444 E_CONFIG_VAL(D, T, poll_interval, INT);
445 E_CONFIG_VAL(D, T, low, INT);
446 E_CONFIG_VAL(D, T, high, INT);
447 E_CONFIG_VAL(D, T, sensor_type, INT);
449 E_CONFIG_VAL(D, T, backend, INT);
451 E_CONFIG_VAL(D, T, sensor_name, STR);
452 E_CONFIG_VAL(D, T, units, INT);
454 conf_edd = E_CONFIG_DD_NEW("Temperature_Config", Config);
459 E_CONFIG_HASH(D, T, faces, conf_face_edd);
461 temperature_config = e_config_domain_load("module.temperature", conf_edd);
462 if (!temperature_config)
463 temperature_config = E_NEW(Config, 1);
465 eina_hash_foreach(temperature_config->faces, _temperature_face_id_max, &uuid);
466 temperature_config->module = m;
468 e_gadcon_provider_register(&_gadcon_class);
473 e_modapi_shutdown(E_Module *m __UNUSED__)
475 e_gadcon_provider_unregister(&_gadcon_class);
476 eina_hash_foreach(temperature_config->faces, _temperature_face_shutdown, NULL);
477 eina_hash_free(temperature_config->faces);
478 free(temperature_config);
479 temperature_config = NULL;
480 E_CONFIG_DD_FREE(conf_face_edd);
481 E_CONFIG_DD_FREE(conf_edd);
486 e_modapi_save(E_Module *m __UNUSED__)
488 e_config_domain_save("module.temperature", conf_edd, temperature_config);