blob: 33cd466c207801e106af35ac20a97b808d2e4ed9 [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 "gpio.h"
3#include "openbmc.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/buttons";
7static const gchar* dbus_name = "org.openbmc.buttons.Power";
Norman Jamese2765102015-08-19 22:00:55 -05008
9static GDBusObjectManagerServer *manager = NULL;
Norman Jamese2765102015-08-19 22:00:55 -050010
Norman James19e45912015-10-04 20:19:41 -050011//This object will use these GPIOs
12GPIO button = (GPIO){ "POWER_BUTTON" };
13
Norman Jamese2765102015-08-19 22:00:55 -050014static gboolean
15on_is_on (Button *btn,
16 GDBusMethodInvocation *invocation,
17 gpointer user_data)
18{
19 gboolean btn_state=button_get_state(btn);
20 button_complete_is_on(btn,invocation,btn_state);
21 return TRUE;
22
23}
24
25static gboolean
Norman James19e45912015-10-04 20:19:41 -050026on_button_press (Button *btn,
Norman Jamese2765102015-08-19 22:00:55 -050027 GDBusMethodInvocation *invocation,
28 gpointer user_data)
29{
Norman James19e45912015-10-04 20:19:41 -050030 button_emit_button_pressed(btn);
31 button_complete_sim_button_press(btn,invocation);
32 return TRUE;
Norman Jamese2765102015-08-19 22:00:55 -050033}
34
35static void
36on_bus_acquired (GDBusConnection *connection,
37 const gchar *name,
38 gpointer user_data)
39{
Norman James10ff6a32015-08-27 14:24:17 -050040 ObjectSkeleton *object;
Norman James362a80f2015-09-14 14:04:39 -050041 //g_print ("Acquired a message bus connection: %s\n",name);
Norman James10ff6a32015-08-27 14:24:17 -050042 cmdline *cmd = user_data;
43 if (cmd->argc < 2)
44 {
45 g_print("No objects created. Put object name(s) on command line\n");
46 return;
47 }
48 manager = g_dbus_object_manager_server_new (dbus_object_path);
49 int i=0;
50 for (i=1;i<cmd->argc;i++)
51 {
52 gchar *s;
53 s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
54 object = object_skeleton_new (s);
55 g_free (s);
Norman Jamese2765102015-08-19 22:00:55 -050056
Norman James10ff6a32015-08-27 14:24:17 -050057 Button* button = button_skeleton_new ();
58 object_skeleton_set_button (object, button);
59 g_object_unref (button);
Norman Jamese2765102015-08-19 22:00:55 -050060
Norman James10ff6a32015-08-27 14:24:17 -050061 //define method callbacks
62 g_signal_connect (button,
Norman Jamese2765102015-08-19 22:00:55 -050063 "handle-is-on",
64 G_CALLBACK (on_is_on),
65 NULL); /* user_data */
Norman James10ff6a32015-08-27 14:24:17 -050066 g_signal_connect (button,
Norman Jamese2765102015-08-19 22:00:55 -050067 "handle-sim-button-press",
Norman James19e45912015-10-04 20:19:41 -050068 G_CALLBACK (on_button_press),
Norman Jamese2765102015-08-19 22:00:55 -050069 NULL); /* user_data */
70
Norman James19e45912015-10-04 20:19:41 -050071
72
Norman James10ff6a32015-08-27 14:24:17 -050073 /* Export the object (@manager takes its own reference to @object) */
74 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
75 g_object_unref (object);
Norman Jamese2765102015-08-19 22:00:55 -050076
Norman James10ff6a32015-08-27 14:24:17 -050077 }
78 /* Export all objects */
79 g_dbus_object_manager_server_set_connection (manager, connection);
Norman Jamese2765102015-08-19 22:00:55 -050080}
81
82static void
83on_name_acquired (GDBusConnection *connection,
84 const gchar *name,
85 gpointer user_data)
86{
Norman James362a80f2015-09-14 14:04:39 -050087// g_print ("Acquired the name %s\n", name);
Norman Jamese2765102015-08-19 22:00:55 -050088}
89
90static void
91on_name_lost (GDBusConnection *connection,
92 const gchar *name,
93 gpointer user_data)
94{
Norman James362a80f2015-09-14 14:04:39 -050095 // g_print ("Lost the name %s\n", name);
Norman Jamese2765102015-08-19 22:00:55 -050096}
97
98
99gint
100main (gint argc, gchar *argv[])
101{
102 GMainLoop *loop;
103
Norman James952b38d2015-08-27 21:30:06 -0500104 cmdline cmd;
105 cmd.argc = argc;
106 cmd.argv = argv;
107
Norman Jamese2765102015-08-19 22:00:55 -0500108 guint id;
Norman Jamese2765102015-08-19 22:00:55 -0500109 loop = g_main_loop_new (NULL, FALSE);
110
111 id = g_bus_own_name (G_BUS_TYPE_SESSION,
Norman James26072c02015-08-25 07:14:29 -0500112 dbus_name,
Norman Jamese2765102015-08-19 22:00:55 -0500113 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
114 G_BUS_NAME_OWNER_FLAGS_REPLACE,
115 on_bus_acquired,
116 on_name_acquired,
117 on_name_lost,
Norman James952b38d2015-08-27 21:30:06 -0500118 &cmd,
Norman Jamese2765102015-08-19 22:00:55 -0500119 NULL);
120
121 g_main_loop_run (loop);
122
123 g_bus_unown_name (id);
124 g_main_loop_unref (loop);
125 return 0;
126}