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