Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 1 | #include "interfaces/sensor.h"
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 2 | #include "openbmc.h"
|
| 3 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 4 |
|
| 5 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 6 |
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 7 | static const gchar* dbus_object_path = "/org/openbmc/sensors/HostStatus";
|
| 8 | static const gchar* dbus_name = "org.openbmc.sensors.HostStatus";
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 9 | static const guint poll_interval = 3000;
|
| 10 | static guint heartbeat = 0;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 11 |
|
| 12 | static GDBusObjectManagerServer *manager = NULL;
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 13 | /*
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 14 | static gboolean
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 15 | on_get_units (SensorValue *sen,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 16 | GDBusMethodInvocation *invocation,
|
| 17 | gpointer user_data)
|
| 18 | {
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 19 | const gchar* val = sensor_value_get_units(sen);
|
| 20 | sensor_value_complete_get_units(sen,invocation,val);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 21 | return TRUE;
|
| 22 | }
|
| 23 |
|
| 24 | static gboolean
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 25 | on_get (SensorValue *sen,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 26 | GDBusMethodInvocation *invocation,
|
| 27 | gpointer user_data)
|
| 28 | {
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 29 | guint reading = sensor_value_get_value(sen);
|
| 30 | sensor_value_complete_get_value(sen,invocation,reading);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 31 | return TRUE;
|
| 32 | }
|
| 33 | static gboolean
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 34 | on_set (SensorValue *sen,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 35 | GDBusMethodInvocation *invocation,
|
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 36 | guint value,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 37 | gpointer user_data)
|
| 38 | {
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 39 | GVariant* v = NEW_VARIANT_U(value);
|
| 40 | sensor_value_set_value(sen,v);
|
| 41 | sensor_value_emit_changed(sen,v,sensor_value_get_units(sen));
|
| 42 | sensor_value_complete_set_value(sen,invocation);
|
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 43 | return TRUE;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 44 | }
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 45 | */
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 46 | static void
|
| 47 | on_bus_acquired (GDBusConnection *connection,
|
| 48 | const gchar *name,
|
| 49 | gpointer user_data)
|
| 50 | {
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 51 | g_print ("Acquired a message bus connection: %s\n",name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 52 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 53 | cmdline *cmd = user_data;
|
| 54 | if (cmd->argc < 2)
|
| 55 | {
|
| 56 | g_print("No objects created. Put object name(s) on command line\n");
|
| 57 | return;
|
| 58 | }
|
| 59 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
| 60 | int i=0;
|
| 61 | for (i=1;i<cmd->argc;i++)
|
| 62 | {
|
| 63 | gchar *s;
|
| 64 | s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
|
| 65 | ObjectSkeleton *object = object_skeleton_new (s);
|
| 66 | g_free (s);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 67 |
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 68 | SensorValue *sensor = sensor_value_skeleton_new ();
|
| 69 | object_skeleton_set_sensor_value (object, sensor);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 70 | g_object_unref (sensor);
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 71 |
|
| 72 | //must init variant
|
| 73 | GVariant* v = NEW_VARIANT_U(0);
|
| 74 | sensor_value_set_value(sensor,v);
|
| 75 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 76 | // set units
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 77 | sensor_value_set_units(sensor,"");
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 78 | //define method callbacks here
|
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame^] | 79 | //g_signal_connect (sensor,
|
| 80 | // "handle-get-value",
|
| 81 | // G_CALLBACK (on_get),
|
| 82 | // NULL); /* user_data */
|
| 83 | //g_signal_connect (sensor,
|
| 84 | // "handle-get-units",
|
| 85 | // G_CALLBACK (on_get_units),
|
| 86 | // NULL); /* user_data */
|
| 87 | //g_signal_connect (sensor,
|
| 88 | // "handle-set-value",
|
| 89 | // G_CALLBACK (on_set),
|
| 90 | // NULL); /* user_data */
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 91 |
|
| 92 | /* Export the object (@manager takes its own reference to @object) */
|
| 93 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 94 | g_object_unref (object);
|
| 95 | }
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 96 |
|
| 97 | /* Export all objects */
|
| 98 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 99 | }
|
| 100 |
|
| 101 | static void
|
| 102 | on_name_acquired (GDBusConnection *connection,
|
| 103 | const gchar *name,
|
| 104 | gpointer user_data)
|
| 105 | {
|
| 106 | g_print ("Acquired the name %s\n", name);
|
| 107 | }
|
| 108 |
|
| 109 | static void
|
| 110 | on_name_lost (GDBusConnection *connection,
|
| 111 | const gchar *name,
|
| 112 | gpointer user_data)
|
| 113 | {
|
| 114 | g_print ("Lost the name %s\n", name);
|
| 115 | }
|
| 116 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 117 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 118 | gint
|
| 119 | main (gint argc, gchar *argv[])
|
| 120 | {
|
| 121 | GMainLoop *loop;
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 122 | cmdline cmd;
|
| 123 | cmd.argc = argc;
|
| 124 | cmd.argv = argv;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 125 | guint id;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 126 | loop = g_main_loop_new (NULL, FALSE);
|
| 127 |
|
| 128 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 129 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 130 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 131 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 132 | on_bus_acquired,
|
| 133 | on_name_acquired,
|
| 134 | on_name_lost,
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 135 | &cmd,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 136 | NULL);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 137 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 138 | g_main_loop_run (loop);
|
| 139 |
|
| 140 | g_bus_unown_name (id);
|
| 141 | g_main_loop_unref (loop);
|
| 142 | return 0;
|
| 143 | }
|