Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 1 | #include "interfaces/host_control.h"
|
| 2 |
|
| 3 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 4 | static const gchar* dbus_object_path = "/org/openbmc/control/Host";
|
| 5 | static const gchar* dbus_name = "org.openbmc.control.Host";
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 6 |
|
| 7 | static GDBusObjectManagerServer *manager = NULL;
|
| 8 | static HostControl *host_control = NULL;
|
| 9 |
|
| 10 | static guint gpio_fsiclk = 27;
|
| 11 | static guint gpio_fsidat = 28;
|
| 12 |
|
| 13 | static gboolean
|
| 14 | on_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 |
|
| 25 | static void
|
| 26 | on_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 James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 35 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 36 |
|
| 37 | gchar *s;
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 38 | s = g_strdup_printf ("%s/0",dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 39 | 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 |
|
| 59 | static void
|
| 60 | on_name_acquired (GDBusConnection *connection,
|
| 61 | const gchar *name,
|
| 62 | gpointer user_data)
|
| 63 | {
|
| 64 | g_print ("Acquired the name %s\n", name);
|
| 65 | }
|
| 66 |
|
| 67 | static void
|
| 68 | on_name_lost (GDBusConnection *connection,
|
| 69 | const gchar *name,
|
| 70 | gpointer user_data)
|
| 71 | {
|
| 72 | g_print ("Lost the name %s\n", name);
|
| 73 | }
|
| 74 |
|
| 75 | gint
|
| 76 | main (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 James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 85 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 86 | 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 | }
|