blob: 014fe920d4bd03ed0d440d633545c2b61bce41db [file] [log] [blame]
Norman Jamese2765102015-08-19 22:00:55 -05001#include "interfaces/host_control.h"
2
3/* ---------------------------------------------------------------------------------------------------- */
Norman James26072c02015-08-25 07:14:29 -05004static const gchar* dbus_object_path = "/org/openbmc/control/Host";
5static const gchar* dbus_name = "org.openbmc.control.Host";
Norman Jamese2765102015-08-19 22:00:55 -05006
7static GDBusObjectManagerServer *manager = NULL;
8static HostControl *host_control = NULL;
9
10static guint gpio_fsiclk = 27;
11static guint gpio_fsidat = 28;
12
13static gboolean
14on_boot (HostControl *host,
15 GDBusMethodInvocation *invocation,
16 gpointer user_data)
17{
18 // TODO: Implement gpio toggling
19 g_print("Boot");
20 host_control_complete_boot(host,invocation);
21 host_control_emit_booted(host);
22 return TRUE;
23}
24
25static void
26on_bus_acquired (GDBusConnection *connection,
27 const gchar *name,
28 gpointer user_data)
29{
30 ObjectSkeleton *object;
31 guint n;
32
33 g_print ("Acquired a message bus connection: %s\n",name);
34
Norman James26072c02015-08-25 07:14:29 -050035 manager = g_dbus_object_manager_server_new (dbus_object_path);
Norman Jamese2765102015-08-19 22:00:55 -050036
37 gchar *s;
Norman James26072c02015-08-25 07:14:29 -050038 s = g_strdup_printf ("%s/0",dbus_object_path);
Norman Jamese2765102015-08-19 22:00:55 -050039 object = object_skeleton_new (s);
40 g_free (s);
41 host_control = host_control_skeleton_new ();
42 object_skeleton_set_host_control (object, host_control);
43 g_object_unref (host_control);
44
45 //define method callbacks here
46 g_signal_connect (host_control,
47 "handle-boot",
48 G_CALLBACK (on_boot),
49 NULL); /* user_data */
50
51 /* Export the object (@manager takes its own reference to @object) */
52 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
53 g_object_unref (object);
54
55 /* Export all objects */
56 g_dbus_object_manager_server_set_connection (manager, connection);
57}
58
59static void
60on_name_acquired (GDBusConnection *connection,
61 const gchar *name,
62 gpointer user_data)
63{
64 g_print ("Acquired the name %s\n", name);
65}
66
67static void
68on_name_lost (GDBusConnection *connection,
69 const gchar *name,
70 gpointer user_data)
71{
72 g_print ("Lost the name %s\n", name);
73}
74
75gint
76main (gint argc, gchar *argv[])
77{
78 GMainLoop *loop;
79
80 guint id;
81 //g_type_init ();
82 loop = g_main_loop_new (NULL, FALSE);
83
84 id = g_bus_own_name (G_BUS_TYPE_SESSION,
Norman James26072c02015-08-25 07:14:29 -050085 dbus_name,
Norman Jamese2765102015-08-19 22:00:55 -050086 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
87 G_BUS_NAME_OWNER_FLAGS_REPLACE,
88 on_bus_acquired,
89 on_name_acquired,
90 on_name_lost,
91 loop,
92 NULL);
93
94 g_main_loop_run (loop);
95
96 g_bus_unown_name (id);
97 g_main_loop_unref (loop);
98 return 0;
99}