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