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