From 7bee1faa0f3c3e4af09e011227af2ccf560a32e4 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Fri, 22 Apr 2011 16:32:12 +0200 Subject: [PATCH] adapter: D-Bus interface skeleton --- include/dbus.h | 2 ++ src/adapter.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/dbus.h b/include/dbus.h index 298eb74..7afa7d5 100644 --- a/include/dbus.h +++ b/include/dbus.h @@ -29,6 +29,8 @@ #define NFC_MANAGER_INTERFACE NFC_SERVICE ".Manager" #define NFC_MANAGER_PATH "/" +#define NFC_ADAPTER_INTERFACE NFC_SERVICE ".Adapter" + typedef void (* near_dbus_append_cb_t) (DBusMessageIter *iter, void *user_data); diff --git a/src/adapter.c b/src/adapter.c index 3dbcc78..3d5232d 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -29,8 +29,12 @@ #include +#include + #include "near.h" +static DBusConnection *connection = NULL; + static GHashTable *adapter_hash; struct near_adapter { @@ -70,6 +74,41 @@ void __near_adapter_list(DBusMessageIter *iter, void *user_data) g_hash_table_foreach(adapter_hash, append_path, iter); } +static DBusMessage *get_properties(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + + DBG("conn %p", conn); + + reply = dbus_message_new_method_return(msg); + if (reply == NULL) + return NULL; + + return reply; +} + +static DBusMessage *set_property(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBG("conn %p", conn); + + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); +} + +static GDBusMethodTable adapter_methods[] = { + { "GetProperties", "", "a{sv}", get_properties }, + { "SetProperty", "sv", "", set_property }, + { }, +}; + +static GDBusSignalTable adapter_signals[] = { + { "PropertyChanged", "sv" }, + { "TargetFound", "o" }, + { "TargetLost", "o" }, + { } +}; + int __near_adapter_add(const char *name, guint32 idx, guint32 protocols) { struct near_adapter *adapter; @@ -96,11 +135,25 @@ int __near_adapter_add(const char *name, guint32 idx, guint32 protocols) g_hash_table_insert(adapter_hash, GINT_TO_POINTER(idx), adapter); + g_dbus_register_interface(connection, adapter->path, + NFC_ADAPTER_INTERFACE, + adapter_methods, adapter_signals, + NULL, adapter, NULL); + return 0; } void __near_adapter_remove(guint32 idx) { + struct near_adapter *adapter; + + adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx)); + if (adapter == NULL || adapter->path == NULL) + return; + + g_dbus_unregister_interface(connection, adapter->path, + NFC_ADAPTER_INTERFACE); + g_hash_table_remove(adapter_hash, GINT_TO_POINTER(idx)); } @@ -108,6 +161,8 @@ int __near_adapter_init(void) { DBG(""); + connection = near_dbus_get_connection(); + adapter_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_adapter); -- 2.7.4