blob: 98916dc0c6f210a35acea088f069eed810a38330 [file] [log] [blame]
Norman Jamese2765102015-08-19 22:00:55 -05001#include "interfaces/button.h"
2
3/* ---------------------------------------------------------------------------------------------------- */
Norman James26072c02015-08-25 07:14:29 -05004static const gchar* dbus_object_path = "/org/openbmc/buttons/ButtonPower";
5static const gchar* dbus_name = "org.openbmc.buttons.ButtonPower";
Norman Jamese2765102015-08-19 22:00:55 -05006
7static GDBusObjectManagerServer *manager = NULL;
8static Button *button = NULL;
9static const int gpio = 12;
10
11static gboolean
12on_is_on (Button *btn,
13 GDBusMethodInvocation *invocation,
14 gpointer user_data)
15{
16 gboolean btn_state=button_get_state(btn);
17 button_complete_is_on(btn,invocation,btn_state);
18 return TRUE;
19
20}
21
22static gboolean
23on_sim_button_press (Button *btn,
24 GDBusMethodInvocation *invocation,
25 gpointer user_data)
26{
27 g_print("Simulating button pressed\n");
28 button_emit_button_pressed(btn);
29 button_complete_sim_button_press(btn,invocation);
30 return TRUE;
31
32}
33
34static void
35on_bus_acquired (GDBusConnection *connection,
36 const gchar *name,
37 gpointer user_data)
38{
39 ObjectSkeleton *object;
40 guint n;
41
42 g_print ("Acquired a message bus connection: %s\n",name);
43
Norman James26072c02015-08-25 07:14:29 -050044 manager = g_dbus_object_manager_server_new (dbus_object_path);
Norman Jamese2765102015-08-19 22:00:55 -050045
46 gchar *s;
Norman James26072c02015-08-25 07:14:29 -050047 s = g_strdup_printf ("%s/0",dbus_object_path);
Norman Jamese2765102015-08-19 22:00:55 -050048 object = object_skeleton_new (s);
49 g_free (s);
50
51 button = button_skeleton_new ();
52 object_skeleton_set_button (object, button);
53 g_object_unref (button);
54
55 //define method callbacks
56 g_signal_connect (button,
57 "handle-is-on",
58 G_CALLBACK (on_is_on),
59 NULL); /* user_data */
60 g_signal_connect (button,
61 "handle-sim-button-press",
62 G_CALLBACK (on_sim_button_press),
63 NULL); /* user_data */
64
65
66 /* Export the object (@manager takes its own reference to @object) */
67 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
68 g_object_unref (object);
69
70 /* Export all objects */
71 g_dbus_object_manager_server_set_connection (manager, connection);
72}
73
74static void
75on_name_acquired (GDBusConnection *connection,
76 const gchar *name,
77 gpointer user_data)
78{
79 g_print ("Acquired the name %s\n", name);
80}
81
82static void
83on_name_lost (GDBusConnection *connection,
84 const gchar *name,
85 gpointer user_data)
86{
87 g_print ("Lost the name %s\n", name);
88}
89
90
91gint
92main (gint argc, gchar *argv[])
93{
94 GMainLoop *loop;
95
96 guint id;
97 //g_type_init ();
98 loop = g_main_loop_new (NULL, FALSE);
99
100 id = g_bus_own_name (G_BUS_TYPE_SESSION,
Norman James26072c02015-08-25 07:14:29 -0500101 dbus_name,
Norman Jamese2765102015-08-19 22:00:55 -0500102 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
103 G_BUS_NAME_OWNER_FLAGS_REPLACE,
104 on_bus_acquired,
105 on_name_acquired,
106 on_name_lost,
107 loop,
108 NULL);
109
110 g_main_loop_run (loop);
111
112 g_bus_unown_name (id);
113 g_main_loop_unref (loop);
114 return 0;
115}