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