|
| 1 | +/* |
| 2 | + * Copyright (C) 2018 info-cppsp <info@cppsp.de> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | + */ |
| 18 | + |
| 19 | +/* Dummy plugin to be able to test msa in a VM */ |
| 20 | + |
| 21 | + |
| 22 | +#ifdef HAVE_CONFIG_H |
| 23 | +#include "config.h" |
| 24 | +#endif /* HAVE_CONFIG_H */ |
| 25 | + |
| 26 | +#include <time.h> |
| 27 | +#include <stdlib.h> |
| 28 | +#include "dummy-plugin.h" |
| 29 | + |
| 30 | + |
| 31 | +// remove // from next line for syslog debug |
| 32 | +//#define DPDBG 1 |
| 33 | + |
| 34 | +#ifdef DPDBG |
| 35 | +#include <syslog.h> |
| 36 | +#endif |
| 37 | + |
| 38 | + |
| 39 | +const gchar *plugin_name = "dummy"; |
| 40 | + |
| 41 | + |
| 42 | +static void dummy_plugin_get_sensors(GList **sensors) { |
| 43 | + |
| 44 | + /* dummy HDD temp sensor */ |
| 45 | + sensors_applet_plugin_add_sensor(sensors, |
| 46 | + "/sys/devices/platform/it87.656/hwmon/hwmon1/temp2_input", |
| 47 | + "temp2", |
| 48 | + "CPU", |
| 49 | + TEMP_SENSOR, |
| 50 | + TRUE, |
| 51 | + CPU_ICON, |
| 52 | + DEFAULT_GRAPH_COLOR); |
| 53 | + |
| 54 | + /* dummy HDD temp sensor */ |
| 55 | + sensors_applet_plugin_add_sensor(sensors, |
| 56 | + "/sys/devices/platform/it87.656/hwmon/hwmon1/fan1_input", |
| 57 | + "fan1", |
| 58 | + "fan1", |
| 59 | + FAN_SENSOR, |
| 60 | + TRUE, |
| 61 | + FAN_ICON, |
| 62 | + DEFAULT_GRAPH_COLOR); |
| 63 | + |
| 64 | + /* dummy HDD temp sensor */ |
| 65 | + sensors_applet_plugin_add_sensor(sensors, |
| 66 | + "HDD 2154884654-5648HG-546821", |
| 67 | + "Disk Temperature", |
| 68 | + "HDD 2154884654", |
| 69 | + TEMP_SENSOR, |
| 70 | + TRUE, |
| 71 | + HDD_ICON, |
| 72 | + DEFAULT_GRAPH_COLOR); |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | +/* this is the function called every refresh cycle */ |
| 77 | +static gdouble dummy_plugin_get_sensor_value(const gchar *path, |
| 78 | + const gchar *id, |
| 79 | + SensorType type, |
| 80 | + GError **error) { |
| 81 | + |
| 82 | + switch (type) { |
| 83 | + case TEMP_SENSOR: |
| 84 | + return (gdouble) (rand() % 40 + 20); |
| 85 | + break; |
| 86 | + |
| 87 | + case FAN_SENSOR: |
| 88 | + return (gdouble) (rand() % 3000); |
| 89 | + break; |
| 90 | + |
| 91 | + default: |
| 92 | + g_assert_not_reached(); |
| 93 | + } |
| 94 | + |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | +/* API functions */ |
| 99 | +const gchar *sensors_applet_plugin_name(void) { |
| 100 | + return plugin_name; |
| 101 | +} |
| 102 | + |
| 103 | +static GList *dummy_plugin_init(void) { |
| 104 | + GList *sensors = NULL; |
| 105 | + |
| 106 | + /* init random number generation */ |
| 107 | + srand(time(NULL)); |
| 108 | + |
| 109 | + dummy_plugin_get_sensors(&sensors); |
| 110 | + |
| 111 | + return sensors; |
| 112 | +} |
| 113 | + |
| 114 | +GList *sensors_applet_plugin_init(void) { |
| 115 | + return dummy_plugin_init(); |
| 116 | +} |
| 117 | + |
| 118 | +gdouble sensors_applet_plugin_get_sensor_value(const gchar *path, |
| 119 | + const gchar *id, |
| 120 | + SensorType type, |
| 121 | + GError **error) { |
| 122 | + |
| 123 | + return dummy_plugin_get_sensor_value(path, id, type, error); |
| 124 | +} |
0 commit comments