Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 1 | #include "interfaces/led.h"
|
| 2 |
|
| 3 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame^] | 4 | static const gchar* dbus_object_path = "/org/openbmc/control/ChassisControl";
|
| 5 | static const gchar* dbus_name = "org.openbmc.control.ChassisControl";
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 6 |
|
| 7 | static GDBusObjectManagerServer *manager = NULL;
|
| 8 | //static Led *led = NULL;
|
| 9 | static uint gpio = 12;
|
| 10 |
|
| 11 | static gboolean
|
| 12 | on_set_on (Led *led,
|
| 13 | GDBusMethodInvocation *invocation,
|
| 14 | gpointer user_data)
|
| 15 | {
|
| 16 | g_print("Turn on chassis identify led\n");
|
| 17 | //TODO: implement in hardware
|
| 18 | led_complete_set_on(led,invocation);
|
| 19 | return TRUE;
|
| 20 |
|
| 21 | }
|
| 22 |
|
| 23 | static gboolean
|
| 24 | on_set_off (Led *led,
|
| 25 | GDBusMethodInvocation *invocation,
|
| 26 | gpointer user_data)
|
| 27 | {
|
| 28 | g_print("Turn off chassis identify led\n");
|
| 29 | //TODO: implement in hardware
|
| 30 | led_complete_set_off(led,invocation);
|
| 31 | return TRUE;
|
| 32 | }
|
| 33 |
|
| 34 | static void
|
| 35 | on_bus_acquired (GDBusConnection *connection,
|
| 36 | const gchar *name,
|
| 37 | gpointer user_data)
|
| 38 | {
|
| 39 | ObjectSkeleton *object;
|
| 40 | Led *led;
|
| 41 | guint n;
|
| 42 |
|
| 43 | g_print ("Acquired a message bus connection: %s\n",name);
|
| 44 |
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame^] | 45 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 46 |
|
| 47 | gchar *s;
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame^] | 48 | s = g_strdup_printf ("%s/0",dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 49 | object = object_skeleton_new (s);
|
| 50 | g_free (s);
|
| 51 |
|
| 52 | led = led_skeleton_new ();
|
| 53 | object_skeleton_set_led (object, led);
|
| 54 | g_object_unref (led);
|
| 55 |
|
| 56 | //define method callbacks
|
| 57 | g_signal_connect (led,
|
| 58 | "handle-set-on",
|
| 59 | G_CALLBACK (on_set_on),
|
| 60 | NULL); /* user_data */
|
| 61 | g_signal_connect (led,
|
| 62 | "handle-set-off",
|
| 63 | G_CALLBACK (on_set_off),
|
| 64 | NULL);
|
| 65 |
|
| 66 | led_set_color(led,0);
|
| 67 | led_set_function(led,"CHASSIS_IDENTIFY");
|
| 68 |
|
| 69 | /* Export the object (@manager takes its own reference to @object) */
|
| 70 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 71 | g_object_unref (object);
|
| 72 |
|
| 73 | /* Export all objects */
|
| 74 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 75 | }
|
| 76 |
|
| 77 | static void
|
| 78 | on_name_acquired (GDBusConnection *connection,
|
| 79 | const gchar *name,
|
| 80 | gpointer user_data)
|
| 81 | {
|
| 82 | g_print ("Acquired the name %s\n", name);
|
| 83 | }
|
| 84 |
|
| 85 | static void
|
| 86 | on_name_lost (GDBusConnection *connection,
|
| 87 | const gchar *name,
|
| 88 | gpointer user_data)
|
| 89 | {
|
| 90 | g_print ("Lost the name %s\n", name);
|
| 91 | }
|
| 92 |
|
| 93 |
|
| 94 | gint
|
| 95 | main (gint argc, gchar *argv[])
|
| 96 | {
|
| 97 | GMainLoop *loop;
|
| 98 |
|
| 99 | guint id;
|
| 100 | //g_type_init ();
|
| 101 | loop = g_main_loop_new (NULL, FALSE);
|
| 102 |
|
| 103 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame^] | 104 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 105 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 106 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 107 | on_bus_acquired,
|
| 108 | on_name_acquired,
|
| 109 | on_name_lost,
|
| 110 | loop,
|
| 111 | NULL);
|
| 112 |
|
| 113 | g_main_loop_run (loop);
|
| 114 |
|
| 115 | g_bus_unown_name (id);
|
| 116 | g_main_loop_unref (loop);
|
| 117 | return 0;
|
| 118 | }
|