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