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