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