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