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