summaryrefslogtreecommitdiffstats
path: root/src/nfc-binding.c
diff options
context:
space:
mode:
authorLoïc Collignon <loic.collignon@iot.bzh>2017-10-25 15:27:12 +0200
committerLoïc Collignon <loic.collignon@iot.bzh>2017-10-25 15:27:12 +0200
commit399800e461ad28e067a15c794f18843b48bfc919 (patch)
treed6937ebb192ee63de5f76e7cee7c3387a8c0215d /src/nfc-binding.c
parent7bf305f00355801356670f05a7043a08fe3bb555 (diff)
detect tag removing and raise an event
Change-Id: I812c4f0b86f2f65c0d7561af95e531fd596bd45b Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
Diffstat (limited to 'src/nfc-binding.c')
-rw-r--r--src/nfc-binding.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/nfc-binding.c b/src/nfc-binding.c
index 3d96cbb..56aa211 100644
--- a/src/nfc-binding.c
+++ b/src/nfc-binding.c
@@ -4,14 +4,16 @@
#include "libnfc_reader.h"
#endif
-struct afb_event on_nfc_read_event;
+struct afb_event on_nfc_target_add_event;
+struct afb_event on_nfc_target_remove_event;
/// @brief Binding's initialization.
/// @return Exit code, zero on success, non-zero otherwise.
int init()
{
- on_nfc_read_event = afb_daemon_make_event("on-nfc-read");
- if (!afb_event_is_valid(on_nfc_read_event))
+ on_nfc_target_add_event = afb_daemon_make_event("on-nfc-target-add");
+ on_nfc_target_remove_event = afb_daemon_make_event("on-nfc-target-remove");
+ if (!afb_event_is_valid(on_nfc_target_add_event) || !afb_event_is_valid(on_nfc_target_remove_event))
{
AFB_ERROR("Failed to create a valid event!");
return 1;
@@ -31,17 +33,34 @@ int init()
/// @brief Get a list of devices.
/// @param[in] req The query.
void verb_subscribe(struct afb_req req)
-{
- if (afb_req_subscribe(req, on_nfc_read_event)) afb_req_fail(req, NULL, "Subscription failure!");
- else afb_req_success(req, NULL, "Subscription success!");
+{
+ if (!afb_req_subscribe(req, on_nfc_target_remove_event))
+ {
+ if (!afb_req_subscribe(req, on_nfc_target_add_event))
+ {
+ afb_req_success(req, NULL, "Subscription success!");
+ return;
+ }
+ else afb_req_unsubscribe(req, on_nfc_target_remove_event);
+ }
+
+ afb_req_fail(req, NULL, "Subscription failure!");
}
/// @brief Get a list of devices.
/// @param[in] req The query.
void verb_unsubscribe(struct afb_req req)
{
- if (afb_req_unsubscribe(req, on_nfc_read_event)) afb_req_fail(req, NULL, "Unsubscription failure!");
- else afb_req_success(req, NULL, "Unsubscription success!");
+ if (!afb_req_unsubscribe(req, on_nfc_target_add_event))
+ {
+ if (!afb_req_unsubscribe(req, on_nfc_target_remove_event))
+ {
+ afb_req_success(req, NULL, "Unsubscription success!");
+ return;
+ }
+ }
+
+ afb_req_fail(req, NULL, "Unsubscription failure!");
}
/// @brief Get a list of devices.