summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/api.c8
-rw-r--r--src/libnfc_reader.c28
-rw-r--r--src/nfc-binding.c6
-rw-r--r--src/nfc-binding.h4
4 files changed, 27 insertions, 19 deletions
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);