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