From aa5da1e1a47c4d8c6e3265e0d99335bebb28e378 Mon Sep 17 00:00:00 2001 From: Loïc Collignon Date: Thu, 9 Nov 2017 15:03:18 +0100 Subject: rename verbs to match the aia-binding expectations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic959f94f55cd3c010663369c54e63089725a8556 Signed-off-by: Loïc Collignon --- src/api.c | 8 ++++---- src/libnfc_reader.c | 28 +++++++++++++++++----------- src/nfc-binding.c | 6 ++++-- src/nfc-binding.h | 4 ++-- 4 files changed, 27 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/api.c b/src/api.c index e508e86..8e928fd 100644 --- a/src/api.c +++ b/src/api.c @@ -35,15 +35,15 @@ static const struct afb_verb_v2 nfc_verbs[] = { .session = AFB_SESSION_NONE_V2 }, { - .verb = "start-polling", - .callback = verb_start_polling, + .verb = "start", + .callback = verb_start, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE_V2 }, { - .verb = "stop-polling", - .callback = verb_stop_polling, + .verb = "stop", + .callback = verb_stop, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE_V2 diff --git a/src/libnfc_reader.c b/src/libnfc_reader.c index a5d5430..ca9ee9b 100644 --- a/src/libnfc_reader.c +++ b/src/libnfc_reader.c @@ -261,23 +261,28 @@ void* libnfc_reader_main(void* arg) return NULL; } -void sigterm_handler(int sig) +void exit_handler() { size_t i; nfc_device* dev; - if (sig == SIGTERM && libnfc.context && libnfc.devices_count) + for(i = 0; i < libnfc.devices_count; ++i) { - for(i = 0; i < libnfc.devices_count; ++i) + if (libnfc.devices[i].device) { - if (libnfc.devices[i].device) - { - dev = libnfc.devices[i].device; - libnfc.devices[i].device = NULL; - nfc_close(dev); - } + dev = libnfc.devices[i].device; + libnfc.devices[i].device = NULL; + nfc_close(dev); } - nfc_exit(libnfc.context); - libnfc.context = NULL; + } + nfc_exit(libnfc.context); + libnfc.context = NULL; +} + +void sigterm_handler(int sig) +{ + if (sig == SIGTERM && libnfc.context && libnfc.devices_count) + { + exit_handler(); } } @@ -293,6 +298,7 @@ int libnfc_init() size_t ref_device_count; size_t device_idx; + atexit(exit_handler); memset(&libnfc, 0, sizeof(libnfc_context)); diff --git a/src/nfc-binding.c b/src/nfc-binding.c index 56aa211..c5f14c6 100644 --- a/src/nfc-binding.c +++ b/src/nfc-binding.c @@ -106,7 +106,7 @@ void verb_list_devices_capabilities(struct afb_req req) /// @brief Start polling. /// @param[in] req The query. -void verb_start_polling(struct afb_req req) +void verb_start(struct afb_req req) { struct json_object* result; struct json_object* arg; @@ -126,7 +126,9 @@ void verb_start_polling(struct afb_req req) afb_req_success(req, result, NULL); } -void verb_stop_polling(struct afb_req req) +/// @brief Stop polling. +/// @param[in] req The query. +void verb_stop(struct afb_req req) { afb_req_fail(req, "Not implemented yet!", NULL); } diff --git a/src/nfc-binding.h b/src/nfc-binding.h index a4fcfb4..767a448 100644 --- a/src/nfc-binding.h +++ b/src/nfc-binding.h @@ -13,5 +13,5 @@ void verb_subscribe(struct afb_req req); void verb_unsubscribe(struct afb_req req); void verb_list_devices(struct afb_req req); void verb_list_devices_capabilities(struct afb_req req); -void verb_start_polling(struct afb_req req); -void verb_stop_polling(struct afb_req req); +void verb_start(struct afb_req req); +void verb_stop(struct afb_req req); -- cgit 1.2.3-korg