blob: 69ba7a7e3e3b975d57232399568e47d9f1683de2 [file] [log] [blame]
Norman Jamese2765102015-08-19 22:00:55 -05001#include "interfaces/led.h"
2
3/* ---------------------------------------------------------------------------------------------------- */
Norman James26072c02015-08-25 07:14:29 -05004static const gchar* dbus_object_path = "/org/openbmc/control/ChassisControl";
5static const gchar* dbus_name = "org.openbmc.control.ChassisControl";
Norman Jamese2765102015-08-19 22:00:55 -05006
7static GDBusObjectManagerServer *manager = NULL;
8//static Led *led = NULL;
9static uint gpio = 12;
10
11static gboolean
12on_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
23static gboolean
24on_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
34static void
35on_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 James26072c02015-08-25 07:14:29 -050045 manager = g_dbus_object_manager_server_new (dbus_object_path);
Norman Jamese2765102015-08-19 22:00:55 -050046
47 gchar *s;
Norman James26072c02015-08-25 07:14:29 -050048 s = g_strdup_printf ("%s/0",dbus_object_path);
Norman Jamese2765102015-08-19 22:00:55 -050049 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
77static void
78on_name_acquired (GDBusConnection *connection,
79 const gchar *name,
80 gpointer user_data)
81{
82 g_print ("Acquired the name %s\n", name);
83}
84
85static void
86on_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
94gint
95main (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 James26072c02015-08-25 07:14:29 -0500104 dbus_name,
Norman Jamese2765102015-08-19 22:00:55 -0500105 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}