Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 1 | #include "interfaces/button.h"
|
| 2 |
|
| 3 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 4 | static const gchar* dbus_object_path = "/org/openbmc/buttons/ButtonPower";
|
| 5 | static const gchar* dbus_name = "org.openbmc.buttons.ButtonPower";
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 6 |
|
| 7 | static GDBusObjectManagerServer *manager = NULL;
|
| 8 | static Button *button = NULL;
|
| 9 | static const int gpio = 12;
|
| 10 |
|
| 11 | static gboolean
|
| 12 | on_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 |
|
| 22 | static gboolean
|
| 23 | on_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 |
|
| 34 | static void
|
| 35 | on_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 James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 44 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 45 |
|
| 46 | gchar *s;
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 47 | s = g_strdup_printf ("%s/0",dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 48 | 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 |
|
| 74 | static void
|
| 75 | on_name_acquired (GDBusConnection *connection,
|
| 76 | const gchar *name,
|
| 77 | gpointer user_data)
|
| 78 | {
|
| 79 | g_print ("Acquired the name %s\n", name);
|
| 80 | }
|
| 81 |
|
| 82 | static void
|
| 83 | on_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 |
|
| 91 | gint
|
| 92 | main (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 James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 101 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 102 | 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 | }
|