Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 1 | #include "interfaces/sensor.h"
|
| 2 |
|
| 3 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 4 | static const gchar* dbus_object_path = "/org/openbmc/sensors/HostStatus";
|
| 5 | static const gchar* dbus_name = "org.openbmc.sensors.HostStatus";
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 6 |
|
| 7 | static GDBusObjectManagerServer *manager = NULL;
|
| 8 | static SensorIntegerSettable *sensor = NULL;
|
| 9 |
|
| 10 | static gboolean
|
| 11 | on_get_units (SensorIntegerSettable *sen,
|
| 12 | GDBusMethodInvocation *invocation,
|
| 13 | gpointer user_data)
|
| 14 | {
|
| 15 | const gchar* val = sensor_integer_settable_get_units(sen);
|
| 16 | sensor_integer_settable_complete_get_units(sen,invocation,val);
|
| 17 | return TRUE;
|
| 18 | }
|
| 19 |
|
| 20 | static gboolean
|
| 21 | on_get (SensorIntegerSettable *sen,
|
| 22 | GDBusMethodInvocation *invocation,
|
| 23 | gpointer user_data)
|
| 24 | {
|
| 25 | guint val = sensor_integer_settable_get_value(sen);
|
| 26 | sensor_integer_settable_complete_get_value(sen,invocation,val);
|
| 27 | return TRUE;
|
| 28 | }
|
| 29 | static gboolean
|
| 30 | on_set (SensorIntegerSettable *sen,
|
| 31 | GDBusMethodInvocation *invocation,
|
| 32 | guint value,
|
| 33 | gpointer user_data)
|
| 34 | {
|
| 35 | sensor_integer_settable_set_value(sen,value);
|
| 36 | sensor_integer_settable_complete_set_value(sen,invocation);
|
| 37 | sensor_integer_settable_emit_changed(sen,value);
|
| 38 | return TRUE;
|
| 39 | }
|
| 40 |
|
| 41 | static void
|
| 42 | on_bus_acquired (GDBusConnection *connection,
|
| 43 | const gchar *name,
|
| 44 | gpointer user_data)
|
| 45 | {
|
| 46 | ObjectSkeleton *object;
|
| 47 | guint n;
|
| 48 |
|
| 49 | g_print ("Acquired a message bus connection: %s\n",name);
|
| 50 |
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 51 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 52 |
|
| 53 | gchar *s;
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 54 | s = g_strdup_printf ("%s/0",dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 55 | object = object_skeleton_new (s);
|
| 56 | g_free (s);
|
| 57 |
|
| 58 | sensor = sensor_integer_settable_skeleton_new ();
|
| 59 | object_skeleton_set_sensor_integer_settable (object, sensor);
|
| 60 | g_object_unref (sensor);
|
| 61 |
|
| 62 | //define method callbacks here
|
| 63 | g_signal_connect (sensor,
|
| 64 | "handle-get-value",
|
| 65 | G_CALLBACK (on_get),
|
| 66 | NULL); /* user_data */
|
| 67 | g_signal_connect (sensor,
|
| 68 | "handle-set-value",
|
| 69 | G_CALLBACK (on_set),
|
| 70 | NULL); /* user_data */
|
| 71 | g_signal_connect (sensor,
|
| 72 | "handle-get-units",
|
| 73 | G_CALLBACK (on_get_units),
|
| 74 | NULL); /* user_data */
|
| 75 |
|
| 76 | sensor_integer_settable_set_units(sensor,"");
|
| 77 | /* Export the object (@manager takes its own reference to @object) */
|
| 78 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 79 | g_object_unref (object);
|
| 80 |
|
| 81 | /* Export all objects */
|
| 82 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 83 | }
|
| 84 |
|
| 85 | static void
|
| 86 | on_name_acquired (GDBusConnection *connection,
|
| 87 | const gchar *name,
|
| 88 | gpointer user_data)
|
| 89 | {
|
| 90 | g_print ("Acquired the name %s\n", name);
|
| 91 | }
|
| 92 |
|
| 93 | static void
|
| 94 | on_name_lost (GDBusConnection *connection,
|
| 95 | const gchar *name,
|
| 96 | gpointer user_data)
|
| 97 | {
|
| 98 | g_print ("Lost the name %s\n", name);
|
| 99 | }
|
| 100 |
|
| 101 | gint
|
| 102 | main (gint argc, gchar *argv[])
|
| 103 | {
|
| 104 | GMainLoop *loop;
|
| 105 |
|
| 106 | guint id;
|
| 107 | //g_type_init ();
|
| 108 | loop = g_main_loop_new (NULL, FALSE);
|
| 109 |
|
| 110 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 111 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 112 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 113 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 114 | on_bus_acquired,
|
| 115 | on_name_acquired,
|
| 116 | on_name_lost,
|
| 117 | loop,
|
| 118 | NULL);
|
| 119 | g_main_loop_run (loop);
|
| 120 |
|
| 121 | g_bus_unown_name (id);
|
| 122 | g_main_loop_unref (loop);
|
| 123 | return 0;
|
| 124 | }
|