Skip to content

Commit 34bc99e

Browse files
info-cppsplukefromdc
authored andcommitted
Add dummy plugin
Allows testing in a virtual machine.
1 parent 78ab99a commit 34bc99e

5 files changed

Lines changed: 191 additions & 1 deletion

File tree

configure.ac

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ AC_SUBST(CAIRO_CFLAGS)
7070
AC_SUBST(CAIRO_LIBS)
7171

7272

73+
# enable dummy plugin for debug
74+
AC_ARG_ENABLE(dummyplugin,
75+
AS_HELP_STRING([--enable-dummyplugin],
76+
[Enable dummy plugin for debug.]),
77+
enable_dummyplugin=$enableval, enable_dummyplugin="no")
78+
79+
if test "x$enable_dummyplugin" = "xyes" ; then
80+
echo "Enabling dummy plugin support"
81+
fi
82+
83+
# use same test as above, because AM_CONDITIONAL may not be in if/else
84+
AM_CONDITIONAL(DUMMYPLUGIN, test "x$enable_dummyplugin" = "xyes")
85+
7386
# enable support for udisks2 (via dbus) by default if its available
7487
AC_ARG_ENABLE(udisks2,
7588
AS_HELP_STRING([--disable-udisks2],
@@ -80,7 +93,7 @@ if test "x$enable_udisks2" = "xno" ; then
8093
echo "Disabling udisks2 support"
8194
fi
8295

83-
# use same test as above, bc AM_CONDITIONAL may not be in if/else
96+
# use same test as above, because AM_CONDITIONAL may not be in if/else
8497
AM_CONDITIONAL(UDISKS2, test "x$enable_udisks2" = "xyes")
8598

8699
# support for libnotify
@@ -257,6 +270,7 @@ AC_CONFIG_FILES([
257270
lib/Makefile
258271
plugins/Makefile
259272
plugins/acpi/Makefile
273+
plugins/dummy/Makefile
260274
plugins/udisks2/Makefile
261275
plugins/hddtemp/Makefile
262276
plugins/i2c-proc/Makefile

plugins/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
DIST_SUBDIRS = \
22
acpi \
3+
dummy \
34
udisks2 \
45
hddtemp \
56
i2c-proc \
@@ -26,6 +27,10 @@ SUBDIRS = \
2627
smu-sys \
2728
sonypi
2829

30+
if DUMMYPLUGIN
31+
SUBDIRS += dummy
32+
endif
33+
2934
if UDISKS2
3035
SUBDIRS += udisks2
3136
endif

plugins/dummy/Makefile.am

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Dummy plugin
2+
plugindir = $(libdir)/mate-sensors-applet/plugins
3+
4+
AM_CPPFLAGS = -DMATELOCALEDIR=\""$(datadir)/locale/"\" \
5+
-DG_LOG_DOMAIN=\""Sensors Applet"\" \
6+
-DPIXMAPS_DIR=\""$(datadir)/pixmaps/$(PACKAGE)/"\" \
7+
-DDATADIR=\""$(datadir)"\" \
8+
-DLIBDIR=\""$(libdir)"\" \
9+
-DSYSCONFDIR=\""$(sysconfdir)"\" \
10+
-DPREFIX=\""$(prefix)"\" \
11+
-I$(top_srcdir) \
12+
$(GLIB_CFLAGS)
13+
14+
15+
plugin_LTLIBRARIES = libdummy.la
16+
17+
libdummy_la_SOURCES = \
18+
dummy-plugin.h \
19+
dummy-plugin.c
20+
21+
libdummy_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) $(GLIB_LIBS)
22+
23+
libdummy_la_LIBADD = $(top_builddir)/lib/libmate-sensors-applet-plugin.la

plugins/dummy/dummy-plugin.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
}

plugins/dummy/dummy-plugin.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
#ifndef DUMMY_PLUGIN_H
20+
#define DUMMY_PLUGIN_H
21+
22+
#include <sensors-applet/sensors-applet-plugin.h>
23+
24+
#endif /* DUMMY_PLUGIN_H */

0 commit comments

Comments
 (0)