From 287eeb06149861d8a56de73b2c897ebac95e48b0 Mon Sep 17 00:00:00 2001 From: info-cppsp Date: Sat, 18 Nov 2017 16:22:23 +0100 Subject: Fix indents 05 --- sensors-applet/sensors-applet-plugin.h | 10 +- sensors-applet/sensors-applet-plugins.c | 215 +++++++++++++++----------------- sensors-applet/sensors-applet-plugins.h | 4 +- 3 files changed, 105 insertions(+), 124 deletions(-) (limited to 'sensors-applet') diff --git a/sensors-applet/sensors-applet-plugin.h b/sensors-applet/sensors-applet-plugin.h index 131a4ef..6d7bcdf 100644 --- a/sensors-applet/sensors-applet-plugin.h +++ b/sensors-applet/sensors-applet-plugin.h @@ -32,8 +32,8 @@ GQuark sensors_applet_plugin_error_quark(void); * structs to create the sensors for this plugin from */ GList *sensors_applet_plugin_init(void); -gdouble sensors_applet_plugin_get_sensor_value(const gchar *path, - const gchar *id, +gdouble sensors_applet_plugin_get_sensor_value(const gchar *path, + const gchar *id, SensorType type, GError **error); @@ -43,8 +43,8 @@ void sensors_applet_plugin_find_sensors(GList **sensors, const gchar *path, SensorsAppletPluginTestSensorFunc); -void sensors_applet_plugin_default_sensor_limits(SensorType type, - gdouble *low_value, +void sensors_applet_plugin_default_sensor_limits(SensorType type, + gdouble *low_value, gdouble *high_value); void sensors_applet_plugin_add_sensor(GList **sensors, @@ -56,7 +56,6 @@ void sensors_applet_plugin_add_sensor(GList **sensors, IconType icon, const gchar *graph_color); - void sensors_applet_plugin_add_sensor_with_limits(GList **sensors, const gchar *path, const gchar *id, @@ -68,5 +67,4 @@ void sensors_applet_plugin_add_sensor_with_limits(GList **sensors, IconType icon, const gchar *graph_color); - #endif // SENSORS_APPLET_PLUGIN_H diff --git a/sensors-applet/sensors-applet-plugins.c b/sensors-applet/sensors-applet-plugins.c index 94c7c69..e90895a 100644 --- a/sensors-applet/sensors-applet-plugins.c +++ b/sensors-applet/sensors-applet-plugins.c @@ -29,130 +29,113 @@ #define SENSORS_APPLET_USER_PLUGIN_DIR ".mate2/sensors-applet/plugins" -static void load_all_plugins(SensorsApplet *sensors_applet, - const gchar *path) -{ - if (g_file_test(path, - G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { - GDir *dir; - if ((dir = g_dir_open(path, 0, NULL)) != NULL) { - const gchar *file; - while ((file = g_dir_read_name(dir)) != NULL) { - // try and open plugin - gchar *plugin_file; - void *handle; - SensorsAppletPluginName name_fn; - SensorsAppletPluginInit init_fn; - SensorsAppletPluginGetSensorValue get_value_fn; - - plugin_file = g_strdup_printf("%s/%s", path, file); - g_debug("found %s in plugin directory", plugin_file); - if ((handle = dlopen(plugin_file, RTLD_NOW)) != NULL) { - - if ((name_fn = dlsym(handle, "sensors_applet_plugin_name")) != NULL && - (init_fn = dlsym(handle, "sensors_applet_plugin_init")) != NULL && - (get_value_fn = dlsym(handle, "sensors_applet_plugin_get_sensor_value")) != NULL) { - GList *sensors; - g_debug("calling init function for plugin file %s", plugin_file); - - if ((sensors = init_fn()) != NULL) { - GList *sensor; - - g_debug("registering plugin %s", name_fn()); - g_hash_table_insert(sensors_applet->plugins, - g_strdup(name_fn()), - get_value_fn); - for (sensor = g_list_first(sensors); - sensor != NULL; - sensor = g_list_next(sensor)) { - SensorsAppletSensorInfo *sensor_info = (SensorsAppletSensorInfo *)sensor->data; - sensors_applet_add_sensor(sensors_applet, - sensor_info->path, - sensor_info->id, - sensor_info->label, - name_fn(), - sensor_info->type, - sensor_info->enable, - sensor_info->low_value, - sensor_info->high_value, - FALSE, // ALARM OFF - "", // no alarm commands - "", // no alarm commands - 0, // alarm_timeout - sensor_info->multiplier, - sensor_info->offset, - sensor_info->icon, - sensor_info->graph_color); - - // sensors_applet_add_sensor() doesn't free strings, so free them here - g_free(sensor_info->path); - g_free(sensor_info->id); - g_free(sensor_info->label); - g_free(sensor_info->graph_color); - g_free(sensor_info); - } - g_list_free(sensors); - } else { - g_debug("plugin could not find any sensors"); - if (g_hash_table_lookup(sensors_applet->required_plugins, - name_fn())) - { - g_debug("plugin is required - registering even though no sensors detected"); - g_debug("registering plugin %s", name_fn()); - g_hash_table_insert(sensors_applet->plugins, - g_strdup(name_fn()), - get_value_fn); - } else { - g_debug("unloading plugin"); - } - } - - - - } else { - g_debug("plugin file %s does not contain the required interface", plugin_file); - if (dlclose(handle) != 0) { - g_debug("error closing plugin file %s", plugin_file); - } - } - } else { - g_debug("Could not dlopen: %s: %s", plugin_file, dlerror()); - } - g_free(plugin_file); +static void load_all_plugins(SensorsApplet *sensors_applet, const gchar *path) { + + if (g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + GDir *dir; + if ((dir = g_dir_open(path, 0, NULL)) != NULL) { + const gchar *file; + while ((file = g_dir_read_name(dir)) != NULL) { + /* try and open plugin */ + gchar *plugin_file; + void *handle; + SensorsAppletPluginName name_fn; + SensorsAppletPluginInit init_fn; + SensorsAppletPluginGetSensorValue get_value_fn; + + plugin_file = g_strdup_printf("%s/%s", path, file); + g_debug("found %s in plugin directory", plugin_file); + if ((handle = dlopen(plugin_file, RTLD_NOW)) != NULL) { + + if ((name_fn = dlsym(handle, "sensors_applet_plugin_name")) != NULL && + (init_fn = dlsym(handle, "sensors_applet_plugin_init")) != NULL && + (get_value_fn = dlsym(handle, "sensors_applet_plugin_get_sensor_value")) != NULL) { + + GList *sensors; + g_debug("calling init function for plugin file %s", plugin_file); + + if ((sensors = init_fn()) != NULL) { + GList *sensor; + + g_debug("registering plugin %s", name_fn()); + g_hash_table_insert(sensors_applet->plugins, g_strdup(name_fn()), get_value_fn); + + for (sensor = g_list_first(sensors); sensor != NULL; sensor = g_list_next(sensor)) { + + SensorsAppletSensorInfo *sensor_info = (SensorsAppletSensorInfo *)sensor->data; + sensors_applet_add_sensor(sensors_applet, + sensor_info->path, + sensor_info->id, + sensor_info->label, + name_fn(), + sensor_info->type, + sensor_info->enable, + sensor_info->low_value, + sensor_info->high_value, + FALSE, /* ALARM OFF */ + "", /* no alarm commands */ + "", /* no alarm commands */ + 0, /* alarm_timeout */ + sensor_info->multiplier, + sensor_info->offset, + sensor_info->icon, + sensor_info->graph_color); + + // sensors_applet_add_sensor() doesn't free strings, so free them here + g_free(sensor_info->path); + g_free(sensor_info->id); + g_free(sensor_info->label); + g_free(sensor_info->graph_color); + g_free(sensor_info); + } + g_list_free(sensors); + } else { + g_debug("plugin could not find any sensors"); + if (g_hash_table_lookup(sensors_applet->required_plugins, name_fn())) { + g_debug("plugin is required - registering even though no sensors detected"); + g_debug("registering plugin %s", name_fn()); + g_hash_table_insert(sensors_applet->plugins, g_strdup(name_fn()), get_value_fn); + } else { + g_debug("unloading plugin"); + } + } + + } else { + g_debug("plugin file %s does not contain the required interface", plugin_file); + if (dlclose(handle) != 0) { + g_debug("error closing plugin file %s", plugin_file); } - g_dir_close(dir); + } } else { - g_debug("error opening plugin dir %s", path); + g_debug("Could not dlopen: %s: %s", plugin_file, dlerror()); } + g_free(plugin_file); + } + g_dir_close(dir); } else { - g_debug("path %s is not a valid directory", path); + g_debug("error opening plugin dir %s", path); } + } else { + g_debug("path %s is not a valid directory", path); + } } -void sensors_applet_plugins_load_all(SensorsApplet *sensors_applet) -{ - const gchar *home; - - if ((home = g_get_home_dir()) != NULL) { - gchar *path; - path = g_build_filename(home, - SENSORS_APPLET_USER_PLUGIN_DIR, - NULL); - load_all_plugins(sensors_applet, path); - g_free(path); - } else { - g_warning("could not get home dir of user"); - } - - - load_all_plugins(sensors_applet, SENSORS_APPLET_PLUGIN_DIR); +void sensors_applet_plugins_load_all(SensorsApplet *sensors_applet) { + const gchar *home; + + if ((home = g_get_home_dir()) != NULL) { + gchar *path; + path = g_build_filename(home, SENSORS_APPLET_USER_PLUGIN_DIR, NULL); + load_all_plugins(sensors_applet, path); + g_free(path); + } else { + g_warning("could not get home dir of user"); + } + + load_all_plugins(sensors_applet, SENSORS_APPLET_PLUGIN_DIR); } -SensorsAppletPluginGetSensorValue sensors_applet_plugins_get_sensor_value_func(SensorsApplet *sensors_applet, - const gchar *plugin) -{ - return g_hash_table_lookup(sensors_applet->plugins, - plugin); +SensorsAppletPluginGetSensorValue sensors_applet_plugins_get_sensor_value_func(SensorsApplet *sensors_applet, const gchar *plugin) { + return g_hash_table_lookup(sensors_applet->plugins, plugin); } - diff --git a/sensors-applet/sensors-applet-plugins.h b/sensors-applet/sensors-applet-plugins.h index a77d0b2..14fd110 100644 --- a/sensors-applet/sensors-applet-plugins.h +++ b/sensors-applet/sensors-applet-plugins.h @@ -23,8 +23,8 @@ typedef const gchar *(*SensorsAppletPluginName)(void); typedef GList *(*SensorsAppletPluginInit)(void); -typedef gdouble (*SensorsAppletPluginGetSensorValue)(const gchar *path, - const gchar *id, +typedef gdouble (*SensorsAppletPluginGetSensorValue)(const gchar *path, + const gchar *id, SensorType type, GError **error); -- cgit v1.2.1