Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 1 | #include "interfaces/openbmc_intf.h"
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 2 | #include "openbmc.h"
|
| 3 |
|
| 4 |
|
| 5 | /* ---------------------------------------------------------------------------------------------------- */
|
| 6 |
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 7 | static const gchar* dbus_object_path = "/org/openbmc/control";
|
| 8 | static const gchar* dbus_name = "org.openbmc.control.Fan";
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 9 | static guint heartbeat = 0;
|
| 10 |
|
| 11 | static GDBusObjectManagerServer *manager = NULL;
|
| 12 |
|
| 13 | static gboolean
|
| 14 | poll_sensor(gpointer user_data)
|
| 15 | {
|
| 16 | //FruFan *fan = object_get_fan((Object*)user_data);
|
| 17 | return TRUE;
|
| 18 | }
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 | static gboolean
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 23 | on_set_speed (Fan *fan,
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 24 | GDBusMethodInvocation *invocation,
|
| 25 | guint speed,
|
| 26 | gpointer user_data)
|
| 27 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 28 | fan_set_speed(fan,speed);
|
| 29 | fan_complete_set_speed(fan,invocation);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 30 | return TRUE;
|
| 31 | }
|
| 32 |
|
| 33 | static gboolean
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 34 | on_get_speed (Fan *fan,
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 35 | GDBusMethodInvocation *invocation,
|
| 36 | gpointer user_data)
|
| 37 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 38 | guint reading = fan_get_speed(fan);
|
| 39 | fan_complete_get_speed(fan,invocation,reading);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 40 | return TRUE;
|
| 41 | }
|
| 42 |
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 43 | static void
|
| 44 | on_bus_acquired (GDBusConnection *connection,
|
| 45 | const gchar *name,
|
| 46 | gpointer user_data)
|
| 47 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 48 | //g_print ("Acquired a message bus connection: %s\n",name);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 49 |
|
| 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);
|
| 64 |
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 65 | Fan *fan = fan_skeleton_new ();
|
| 66 | object_skeleton_set_fan (object, fan);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 67 | g_object_unref (fan);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 68 |
|
| 69 | //define method callbacks here
|
| 70 | g_signal_connect (fan,
|
| 71 | "handle-get-speed",
|
| 72 | G_CALLBACK (on_get_speed),
|
| 73 | NULL); /* user_data */
|
| 74 | g_signal_connect (fan,
|
| 75 | "handle-set-speed",
|
| 76 | G_CALLBACK (on_set_speed),
|
| 77 | NULL); /* user_data */
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 78 |
|
| 79 | //g_timeout_add(poll_interval, poll_sensor, object);
|
| 80 |
|
| 81 | /* Export the object (@manager takes its own reference to @object) */
|
| 82 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 83 | g_object_unref (object);
|
| 84 | }
|
| 85 |
|
| 86 | /* Export all objects */
|
| 87 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 88 | }
|
| 89 |
|
| 90 | static void
|
| 91 | on_name_acquired (GDBusConnection *connection,
|
| 92 | const gchar *name,
|
| 93 | gpointer user_data)
|
| 94 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 95 | //g_print ("Acquired the name %s\n", name);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 96 | }
|
| 97 |
|
| 98 | static void
|
| 99 | on_name_lost (GDBusConnection *connection,
|
| 100 | const gchar *name,
|
| 101 | gpointer user_data)
|
| 102 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 103 | //g_print ("Lost the name %s\n", name);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 104 | }
|
| 105 |
|
| 106 |
|
| 107 | gint
|
| 108 | main (gint argc, gchar *argv[])
|
| 109 | {
|
| 110 | GMainLoop *loop;
|
| 111 | cmdline cmd;
|
| 112 | cmd.argc = argc;
|
| 113 | cmd.argv = argv;
|
| 114 | guint id;
|
| 115 | loop = g_main_loop_new (NULL, FALSE);
|
| 116 |
|
Norman James | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 117 | id = g_bus_own_name (DBUS_TYPE,
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 118 | dbus_name,
|
| 119 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 120 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 121 | on_bus_acquired,
|
| 122 | on_name_acquired,
|
| 123 | on_name_lost,
|
| 124 | &cmd,
|
| 125 | NULL);
|
| 126 |
|
| 127 | g_main_loop_run (loop);
|
| 128 |
|
| 129 | g_bus_unown_name (id);
|
| 130 | g_main_loop_unref (loop);
|
| 131 | return 0;
|
| 132 | }
|