blob: a4bc7352af580346ecee38cfb0ca18a18e3346ce [file] [log] [blame]
Norman Jamese2765102015-08-19 22:00:55 -05001#include "interfaces/led.h"
2
3/* ---------------------------------------------------------------------------------------------------- */
4
5static GDBusObjectManagerServer *manager = NULL;
6//static Led *led = NULL;
7static uint gpio = 12;
8
9static gboolean
10on_set_on (Led *led,
11 GDBusMethodInvocation *invocation,
12 gpointer user_data)
13{
14 g_print("Turn on chassis identify led\n");
15 //TODO: implement in hardware
16 led_complete_set_on(led,invocation);
17 return TRUE;
18
19}
20
21static gboolean
22on_set_off (Led *led,
23 GDBusMethodInvocation *invocation,
24 gpointer user_data)
25{
26 g_print("Turn off chassis identify led\n");
27 //TODO: implement in hardware
28 led_complete_set_off(led,invocation);
29 return TRUE;
30}
31
32static void
33on_bus_acquired (GDBusConnection *connection,
34 const gchar *name,
35 gpointer user_data)
36{
37 ObjectSkeleton *object;
38 Led *led;
39 guint n;
40
41 g_print ("Acquired a message bus connection: %s\n",name);
42
43 manager = g_dbus_object_manager_server_new ("/org/openbmc/ChassisIdentify");
44
45 gchar *s;
46 s = g_strdup_printf ("/org/openbmc/ChassisIdentify/0");
47 object = object_skeleton_new (s);
48 g_free (s);
49
50 led = led_skeleton_new ();
51 object_skeleton_set_led (object, led);
52 g_object_unref (led);
53
54 //define method callbacks
55 g_signal_connect (led,
56 "handle-set-on",
57 G_CALLBACK (on_set_on),
58 NULL); /* user_data */
59 g_signal_connect (led,
60 "handle-set-off",
61 G_CALLBACK (on_set_off),
62 NULL);
63
64 led_set_color(led,0);
65 led_set_function(led,"CHASSIS_IDENTIFY");
66
67 /* Export the object (@manager takes its own reference to @object) */
68 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
69 g_object_unref (object);
70
71 /* Export all objects */
72 g_dbus_object_manager_server_set_connection (manager, connection);
73}
74
75static void
76on_name_acquired (GDBusConnection *connection,
77 const gchar *name,
78 gpointer user_data)
79{
80 g_print ("Acquired the name %s\n", name);
81}
82
83static void
84on_name_lost (GDBusConnection *connection,
85 const gchar *name,
86 gpointer user_data)
87{
88 g_print ("Lost the name %s\n", name);
89}
90
91
92gint
93main (gint argc, gchar *argv[])
94{
95 GMainLoop *loop;
96
97 guint id;
98 //g_type_init ();
99 loop = g_main_loop_new (NULL, FALSE);
100
101 id = g_bus_own_name (G_BUS_TYPE_SESSION,
102 "org.openbmc.ChassisIdentify",
103 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
104 G_BUS_NAME_OWNER_FLAGS_REPLACE,
105 on_bus_acquired,
106 on_name_acquired,
107 on_name_lost,
108 loop,
109 NULL);
110
111 g_main_loop_run (loop);
112
113 g_bus_unown_name (id);
114 g_main_loop_unref (loop);
115 return 0;
116}