From cd4d1ca0f47d934b683a0246163ef486cbb61ace Mon Sep 17 00:00:00 2001
From: Matt Ranostay <matt.ranostay@konsulko.com>
Date: Wed, 17 Oct 2018 11:41:13 +0200
Subject: binding: identity: update event processing for nfc binding data

Switch from old NFC binding event data to new format in the binding
rewrite.

Change-Id: Ie7669f2a3e8005c10e680b2d4f821fc96d4a421d
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
---
 src/agl-identity-binding.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

(limited to 'src')

diff --git a/src/agl-identity-binding.c b/src/agl-identity-binding.c
index 9bbe629..20a9384 100644
--- a/src/agl-identity-binding.c
+++ b/src/agl-identity-binding.c
@@ -217,17 +217,10 @@ static void on_nfc_subscribed(void *closure, int status, struct json_object *res
 		AFB_ERROR("Failed to subscribe to nfc events.");
 }
 
-static void on_nfc_started(void *closure, int status, struct json_object *result)
-{
-	if (!status) {
-		afb_service_call("nfc", "subscribe", NULL, on_nfc_subscribed, NULL);
-	}
-	else
-		AFB_ERROR("Failed to start nfc polling.");
-}
-
 static int service_init()
 {
+	struct json_object *jrequest = NULL;
+
 	agl_forgerock_setcb(on_forgerock_data);
 	event = afb_daemon_make_event("event");
 	if (!afb_event_is_valid(event))
@@ -241,7 +234,10 @@ static int service_init()
 	if (afb_daemon_require_api("persistence", 1))
 		return -1;
 
-	afb_service_call("nfc", "start", NULL, on_nfc_started, NULL);
+	jrequest = json_object_new_object();
+	json_object_object_add(jrequest, "value", json_object_new_string("presence"));
+
+	afb_service_call("nfc", "subscribe", jrequest, on_nfc_subscribed, NULL);
 
 	return 0;
 }
@@ -251,7 +247,7 @@ static void on_nfc_target_add(struct json_object *object)
 	struct json_object * json_uid;
 	const char *uid;
 
-	if (json_object_object_get_ex(object, "UID", &json_uid))
+	if (json_object_object_get_ex(object, "uid", &json_uid))
 	{
 		uid = json_object_get_string(json_uid);
 		AFB_NOTICE("nfc tag detected, call forgerock with vincode=%s and key=%s", vin ? vin : default_vin, uid);
@@ -264,7 +260,7 @@ static void on_nfc_target_add(struct json_object *object)
 static void onevent(const char *event, struct json_object *object)
 {
 	AFB_NOTICE("Received event: %s", event);
-	if (!strcmp("nfc/on-nfc-target-add", event))
+	if (!strcmp("nfc/presence", event))
 	{
 		on_nfc_target_add(object);
 		return;
-- 
cgit