diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2012-05-25 16:06:23 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-05-26 16:22:47 +0200 |
commit | 4e92706073a4eff5e39de81bd6ec7c298ef70aff (patch) | |
tree | 5c0cf3f342e6ec97ece3accee3ddff5b7192ef34 | |
parent | 8c31393aed8ad8b9548e6e9d95cbaf30881d4b9b (diff) | |
download | neard-4e92706073a4eff5e39de81bd6ec7c298ef70aff.tar.gz neard-4e92706073a4eff5e39de81bd6ec7c298ef70aff.tar.bz2 neard-4e92706073a4eff5e39de81bd6ec7c298ef70aff.zip |
adapter: Implement new polling loop D-Bus API
The simple StartPoll is replaced with a polling loop method, where polling
mode is specified. It can be Initiator, Target or both.
When starting the polling loop in Target mode an NFC device could
eventually activate us.
-rw-r--r-- | doc/adapter-api.txt | 21 | ||||
-rw-r--r-- | src/adapter.c | 41 | ||||
-rw-r--r-- | src/near.h | 3 | ||||
-rw-r--r-- | src/netlink.c | 10 | ||||
-rwxr-xr-x | test/start-poll | 11 | ||||
-rwxr-xr-x | test/stop-poll | 2 |
6 files changed, 66 insertions, 22 deletions
diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt index ecfde6c..239a89e 100644 --- a/doc/adapter-api.txt +++ b/doc/adapter-api.txt @@ -21,11 +21,15 @@ Methods: dict GetProperties() Possible Errors: org.neard.Error.DoesNotExist org.neard.Error.InvalidArguments - void StartPoll() + void StartPollLoop(string mode) - The adapter will start polling for targets when calling - this method. It is only valid when the adapter is in - initiator mode. + Starts the adapter polling loop. Depending on the mode, + the adapter will start polling for targets, listening + for NFC devices or both. + The mode parameter can have the following values: + "Initiator", "Target". For any other value, the adapter + will start the polling loop in both target and initiator + mode. This process will start emitting TagFound and PropertyChanged "Polling" signals. @@ -34,11 +38,9 @@ Methods: dict GetProperties() org.neard.Error.Failed org.neard.Error.NotSupported - void StopPoll() + void StopPollLoop() - The adapter will stop polling for targets when calling - this method. It is only available when the adapter is in - initiator mode. + The adapter polling loop will stop. Possible errors: org.neard.Error.NotReady org.neard.Error.Failed @@ -93,12 +95,11 @@ Signals PropertyChanged(string name, variant value) in sight, or when it's been de-activated. -Properties: string Mode [readwrite] +Properties: string Mode [readonly] The adapter mode. Valid types are "initiator" and "target". - The default value for the adapter mode is "initiator". boolean Powered [readwrite] diff --git a/src/adapter.c b/src/adapter.c index 02a0329..b5f3fde 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -42,12 +42,18 @@ static DBusConnection *connection = NULL; static GHashTable *adapter_hash; +#define NEAR_ADAPTER_MODE_INITIATOR 0x1 +#define NEAR_ADAPTER_MODE_TARGET 0x2 +#define NEAR_ADAPTER_MODE_DUAL 0x3 + struct near_adapter { char *path; char *name; uint32_t idx; uint32_t protocols; + uint32_t poll_mode; + uint32_t rf_mode; near_bool_t powered; near_bool_t polling; @@ -119,6 +125,7 @@ static void polling_changed(struct near_adapter *adapter) static int adapter_start_poll(struct near_adapter *adapter) { int err; + uint32_t im_protos, tm_protos; if (g_hash_table_size(adapter->tags) > 0) { DBG("Clearing tags"); @@ -134,7 +141,17 @@ static int adapter_start_poll(struct near_adapter *adapter) __near_adapter_devices_changed(adapter->idx); } - err = __near_netlink_start_poll(adapter->idx, adapter->protocols); + DBG("Poll mode 0x%x", adapter->poll_mode); + + im_protos = tm_protos = 0; + + if (adapter->poll_mode & NEAR_ADAPTER_MODE_INITIATOR) + im_protos = adapter->protocols; + + if (adapter->poll_mode & NEAR_ADAPTER_MODE_TARGET) + tm_protos = adapter->protocols; + + err = __near_netlink_start_poll(adapter->idx, im_protos, tm_protos); if (err < 0) return err; @@ -367,14 +384,27 @@ static DBusMessage *set_property(DBusConnection *conn, return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } -static DBusMessage *start_poll(DBusConnection *conn, +static DBusMessage *start_poll_loop(DBusConnection *conn, DBusMessage *msg, void *data) { struct near_adapter *adapter = data; + const char *dbus_mode; int err; DBG("conn %p", conn); + dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dbus_mode, + DBUS_TYPE_INVALID); + + DBG("Mode %s", dbus_mode); + + if (g_strcmp0(dbus_mode, "Initiator") == 0) + adapter->poll_mode = NEAR_ADAPTER_MODE_INITIATOR; + else if (g_strcmp0(dbus_mode, "Target") == 0) + adapter->poll_mode = NEAR_ADAPTER_MODE_TARGET; + else + adapter->poll_mode = NEAR_ADAPTER_MODE_DUAL; + err = adapter_start_poll(adapter); if (err < 0) return __near_error_failed(msg, -err); @@ -382,7 +412,7 @@ static DBusMessage *start_poll(DBusConnection *conn, return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } -static DBusMessage *stop_poll(DBusConnection *conn, +static DBusMessage *stop_poll_loop(DBusConnection *conn, DBusMessage *msg, void *data) { struct near_adapter *adapter = data; @@ -469,8 +499,9 @@ static const GDBusMethodTable adapter_methods[] = { { GDBUS_METHOD("SetProperty", GDBUS_ARGS({"name", "s"}, {"value", "v"}), NULL, set_property) }, - { GDBUS_METHOD("StartPoll", NULL, NULL, start_poll) }, - { GDBUS_METHOD("StopPoll", NULL, NULL, stop_poll) }, + { GDBUS_METHOD("StartPollLoop", GDBUS_ARGS({"name", "s"}), NULL, + start_poll_loop) }, + { GDBUS_METHOD("StopPollLoop", NULL, NULL, stop_poll_loop) }, { }, }; @@ -134,7 +134,8 @@ int __near_device_push(struct near_device *device, #include <near/tlv.h> int __near_netlink_get_adapters(void); -int __near_netlink_start_poll(int idx, uint32_t protocols); +int __near_netlink_start_poll(int idx, + uint32_t im_protocols, uint32_t tm_protocols); int __near_netlink_stop_poll(int idx); int __near_netlink_dep_link_up(uint32_t idx, uint32_t target_idx, uint8_t comm_mode, uint8_t rf_mode); diff --git a/src/netlink.c b/src/netlink.c index 141d511..b2822e0 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -217,13 +217,14 @@ out: return err; } -int __near_netlink_start_poll(int idx, uint32_t protocols) +int __near_netlink_start_poll(int idx, + uint32_t im_protocols, uint32_t tm_protocols) { struct nl_msg *msg; void *hdr; int family, err = 0; - DBG(""); + DBG("IM protos 0x%x TM protos 0x%x", im_protocols, tm_protocols); msg = nlmsg_alloc(); if (msg == NULL) @@ -239,7 +240,10 @@ int __near_netlink_start_poll(int idx, uint32_t protocols) } NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, idx); - NLA_PUT_U32(msg, NFC_ATTR_PROTOCOLS, protocols); + if (im_protocols != 0) + NLA_PUT_U32(msg, NFC_ATTR_IM_PROTOCOLS, im_protocols); + if (tm_protocols != 0) + NLA_PUT_U32(msg, NFC_ATTR_TM_PROTOCOLS, tm_protocols); err = nl_send_msg(nfc_state->nl_sock, msg, NULL, NULL); diff --git a/test/start-poll b/test/start-poll index 69431d5..61f9203 100755 --- a/test/start-poll +++ b/test/start-poll @@ -4,20 +4,27 @@ import sys import dbus if len(sys.argv) < 2: - print "Usage: %s <nfc device>" % (sys.argv[0]) + print "Usage: %s [nfc device] <polling mode>" % (sys.argv[0]) sys.exit(1) +if len(sys.argv) < 3: + mode = "" +else: + mode = sys.argv[2] + bus = dbus.SystemBus() manager = dbus.Interface(bus.get_object("org.neard", "/"), "org.neard.Manager") +print "Mode %s" % (mode) + path = "/org/neard/" + sys.argv[1] adapter = dbus.Interface(bus.get_object("org.neard", path), "org.neard.Adapter") try: - adapter.StartPoll() + adapter.StartPollLoop(mode) except dbus.DBusException, error: print "%s: %s" % (error._dbus_error_name, error.message) diff --git a/test/stop-poll b/test/stop-poll index 83a07f9..5ef2ef9 100755 --- a/test/stop-poll +++ b/test/stop-poll @@ -18,6 +18,6 @@ adapter = dbus.Interface(bus.get_object("org.neard", path), "org.neard.Adapter") try: - adapter.StopPoll() + adapter.StopPollLoop() except dbus.DBusException, error: print "%s: %s" % (error._dbus_error_name, error.message) |