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 | #include "gpio.h"
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 4 |
|
| 5 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 6 | static const gchar* dbus_object_path = "/org/openbmc/leds";
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 7 | static const gchar* dbus_name = "org.openbmc.leds.ChassisIdentify";
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 8 |
|
| 9 | static GDBusObjectManagerServer *manager = NULL;
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 10 |
|
| 11 | GPIO led_gpio = (GPIO){"IDENTIFY"};
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 12 |
|
| 13 | static gboolean
|
| 14 | on_set_on (Led *led,
|
| 15 | GDBusMethodInvocation *invocation,
|
| 16 | gpointer user_data)
|
| 17 | {
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 18 | g_print("Turn on chassis identify led\n");
|
| 19 | led_complete_set_on(led,invocation);
|
| 20 | gpio_open(&led_gpio);
|
| 21 | gpio_write(&led_gpio,1);
|
| 22 | gpio_close(&led_gpio);
|
| 23 |
|
| 24 | return TRUE;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 25 |
|
| 26 | }
|
| 27 |
|
| 28 | static gboolean
|
| 29 | on_set_off (Led *led,
|
| 30 | GDBusMethodInvocation *invocation,
|
| 31 | gpointer user_data)
|
| 32 | {
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 33 | g_print("Turn off chassis identify led\n");
|
| 34 | led_complete_set_off(led,invocation);
|
| 35 | gpio_open(&led_gpio);
|
| 36 | gpio_write(&led_gpio,0);
|
| 37 | gpio_close(&led_gpio);
|
| 38 |
|
| 39 | return TRUE;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 40 | }
|
| 41 |
|
| 42 | static void
|
| 43 | on_bus_acquired (GDBusConnection *connection,
|
| 44 | const gchar *name,
|
| 45 | gpointer user_data)
|
| 46 | {
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 47 | ObjectSkeleton *object;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 48 |
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 49 | //g_print ("Acquired a message bus connection: %s\n",name);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 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 | }
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 56 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 57 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
| 58 | int i = 0;
|
| 59 | for (i=1;i<cmd->argc;i++)
|
| 60 | {
|
| 61 | gchar *s;
|
| 62 | s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
|
| 63 | object = object_skeleton_new (s);
|
| 64 | g_free (s);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 65 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 66 | Led *led = led_skeleton_new ();
|
| 67 | object_skeleton_set_led (object, led);
|
| 68 | g_object_unref (led);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 69 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 70 | //define method callbacks
|
| 71 | g_signal_connect (led,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 72 | "handle-set-on",
|
| 73 | G_CALLBACK (on_set_on),
|
| 74 | NULL); /* user_data */
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 75 | g_signal_connect (led,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 76 | "handle-set-off",
|
| 77 | G_CALLBACK (on_set_off),
|
| 78 | NULL);
|
| 79 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 80 | led_set_color(led,0);
|
| 81 | led_set_function(led,"CHASSIS_IDENTIFY");
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 82 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 83 | /* Export the object (@manager takes its own reference to @object) */
|
| 84 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 85 | g_object_unref (object);
|
| 86 | }
|
| 87 | /* Export all objects */
|
| 88 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 89 | gpio_init(connection,&led_gpio);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 90 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 91 | }
|
| 92 |
|
| 93 | static void
|
| 94 | on_name_acquired (GDBusConnection *connection,
|
| 95 | const gchar *name,
|
| 96 | gpointer user_data)
|
| 97 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 98 | //g_print ("Acquired the name %s\n", name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 99 | }
|
| 100 |
|
| 101 | static void
|
| 102 | on_name_lost (GDBusConnection *connection,
|
| 103 | const gchar *name,
|
| 104 | gpointer user_data)
|
| 105 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 106 | // g_print ("Lost the name %s\n", name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 107 | }
|
| 108 |
|
| 109 |
|
| 110 | gint
|
| 111 | main (gint argc, gchar *argv[])
|
| 112 | {
|
| 113 | GMainLoop *loop;
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 114 | cmdline cmd;
|
| 115 | cmd.argc = argc;
|
| 116 | cmd.argv = argv;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 117 |
|
| 118 | guint id;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 119 | loop = g_main_loop_new (NULL, FALSE);
|
| 120 |
|
| 121 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 122 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 123 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 124 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 125 | on_bus_acquired,
|
| 126 | on_name_acquired,
|
| 127 | on_name_lost,
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 128 | &cmd,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 129 | NULL);
|
| 130 |
|
| 131 | g_main_loop_run (loop);
|
| 132 |
|
| 133 | g_bus_unown_name (id);
|
| 134 | g_main_loop_unref (loop);
|
| 135 | return 0;
|
| 136 | }
|