blob: a747d36e868b8ba4d29e7545c58497bfbe5804c3 [file] [log] [blame]
Norman James362a80f2015-09-14 14:04:39 -05001#include "interfaces/openbmc_intf.h"
Norman James10ff6a32015-08-27 14:24:17 -05002#include "openbmc.h"
3#include "gpio.h"
Norman Jamese2765102015-08-19 22:00:55 -05004
5/* ---------------------------------------------------------------------------------------------------- */
Norman James362a80f2015-09-14 14:04:39 -05006static const gchar* dbus_object_path = "/org/openbmc/leds";
Norman James3f97c5d2015-08-26 17:44:14 -05007static const gchar* dbus_name = "org.openbmc.leds.ChassisIdentify";
Norman Jamese2765102015-08-19 22:00:55 -05008
9static GDBusObjectManagerServer *manager = NULL;
Norman James10ff6a32015-08-27 14:24:17 -050010
11GPIO led_gpio = (GPIO){"IDENTIFY"};
Norman Jamese2765102015-08-19 22:00:55 -050012
13static gboolean
14on_set_on (Led *led,
15 GDBusMethodInvocation *invocation,
16 gpointer user_data)
17{
Norman James10ff6a32015-08-27 14:24:17 -050018 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 Jamese2765102015-08-19 22:00:55 -050025
26}
27
28static gboolean
29on_set_off (Led *led,
30 GDBusMethodInvocation *invocation,
31 gpointer user_data)
32{
Norman James10ff6a32015-08-27 14:24:17 -050033 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 Jamese2765102015-08-19 22:00:55 -050040}
41
42static void
43on_bus_acquired (GDBusConnection *connection,
44 const gchar *name,
45 gpointer user_data)
46{
Norman James10ff6a32015-08-27 14:24:17 -050047 ObjectSkeleton *object;
Norman Jamese2765102015-08-19 22:00:55 -050048
Norman James362a80f2015-09-14 14:04:39 -050049 //g_print ("Acquired a message bus connection: %s\n",name);
Norman James10ff6a32015-08-27 14:24:17 -050050 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 Jamese2765102015-08-19 22:00:55 -050056
Norman James10ff6a32015-08-27 14:24:17 -050057 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 Jamese2765102015-08-19 22:00:55 -050065
Norman James10ff6a32015-08-27 14:24:17 -050066 Led *led = led_skeleton_new ();
67 object_skeleton_set_led (object, led);
68 g_object_unref (led);
Norman Jamese2765102015-08-19 22:00:55 -050069
Norman James10ff6a32015-08-27 14:24:17 -050070 //define method callbacks
71 g_signal_connect (led,
Norman Jamese2765102015-08-19 22:00:55 -050072 "handle-set-on",
73 G_CALLBACK (on_set_on),
74 NULL); /* user_data */
Norman James10ff6a32015-08-27 14:24:17 -050075 g_signal_connect (led,
Norman Jamese2765102015-08-19 22:00:55 -050076 "handle-set-off",
77 G_CALLBACK (on_set_off),
78 NULL);
79
Norman James10ff6a32015-08-27 14:24:17 -050080 led_set_color(led,0);
81 led_set_function(led,"CHASSIS_IDENTIFY");
Norman Jamese2765102015-08-19 22:00:55 -050082
Norman James10ff6a32015-08-27 14:24:17 -050083 /* 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 Jamese2765102015-08-19 22:00:55 -050090
Norman Jamese2765102015-08-19 22:00:55 -050091}
92
93static void
94on_name_acquired (GDBusConnection *connection,
95 const gchar *name,
96 gpointer user_data)
97{
Norman James362a80f2015-09-14 14:04:39 -050098 //g_print ("Acquired the name %s\n", name);
Norman Jamese2765102015-08-19 22:00:55 -050099}
100
101static void
102on_name_lost (GDBusConnection *connection,
103 const gchar *name,
104 gpointer user_data)
105{
Norman James362a80f2015-09-14 14:04:39 -0500106 // g_print ("Lost the name %s\n", name);
Norman Jamese2765102015-08-19 22:00:55 -0500107}
108
109
110gint
111main (gint argc, gchar *argv[])
112{
113 GMainLoop *loop;
Norman James952b38d2015-08-27 21:30:06 -0500114 cmdline cmd;
115 cmd.argc = argc;
116 cmd.argv = argv;
Norman Jamese2765102015-08-19 22:00:55 -0500117
118 guint id;
Norman Jamese2765102015-08-19 22:00:55 -0500119 loop = g_main_loop_new (NULL, FALSE);
120
121 id = g_bus_own_name (G_BUS_TYPE_SESSION,
Norman James26072c02015-08-25 07:14:29 -0500122 dbus_name,
Norman Jamese2765102015-08-19 22:00:55 -0500123 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 James952b38d2015-08-27 21:30:06 -0500128 &cmd,
Norman Jamese2765102015-08-19 22:00:55 -0500129 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}