From 995368cffa1147ba6dd0fe93ecea90d89acfc524 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 5 Dec 2012 02:02:24 +0100 Subject: [PATCH] Update quick_start_examples --- examples/doc/quick_start_example1.c | 17 +++++++++++++---- examples/doc/quick_start_example2.c | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/examples/doc/quick_start_example1.c b/examples/doc/quick_start_example1.c index 54d09d0..531f710 100644 --- a/examples/doc/quick_start_example1.c +++ b/examples/doc/quick_start_example1.c @@ -31,14 +31,22 @@ main(int argc, const char *argv[]) nfc_device *pnd; nfc_target nt; - nfc_init(NULL); + // Allocate only a pointer to nfc_context + nfc_context *context; + + // Initialize libnfc and set the nfc_context + nfc_init(&context); // Display libnfc version const char *acLibnfcVersion = nfc_version(); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); - // Open, using the first available NFC device - pnd = nfc_open(NULL, NULL); + // Open, using the first available NFC device which can be in order of selection: + // - default device specified using environment variable or + // - first specified device in libnfc.conf (/etc/nfc) or + // - first specified device in device-configuration directory (/etc/nfc/devices.d) or + // - first auto-detected (if feature is not disabled in libnfc.conf) device + pnd = nfc_open(context, NULL); if (pnd == NULL) { warnx("ERROR: %s", "Unable to open NFC device."); @@ -72,6 +80,7 @@ main(int argc, const char *argv[]) } // Close NFC device nfc_close(pnd); - nfc_exit(NULL); + // Release the context + nfc_exit(context); return EXIT_SUCCESS; } diff --git a/examples/doc/quick_start_example2.c b/examples/doc/quick_start_example2.c index cc16eec..d98d62e 100644 --- a/examples/doc/quick_start_example2.c +++ b/examples/doc/quick_start_example2.c @@ -23,14 +23,22 @@ main(int argc, const char *argv[]) nfc_device *pnd; nfc_target nt; - nfc_init(NULL); + // Allocate only a pointer to nfc_context + nfc_context *context; + + // Initialize libnfc and set the nfc_context + nfc_init(&context); // Display libnfc version const char *acLibnfcVersion = nfc_version(); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); - // Open, using the first available NFC device - pnd = nfc_open(NULL, NULL); + // Open, using the first available NFC device which can be in order of selection: + // - default device specified using environment variable or + // - first specified device in libnfc.conf (/etc/nfc) or + // - first specified device in device-configuration directory (/etc/nfc/devices.d) or + // - first auto-detected (if feature is not disabled in libnfc.conf) device + pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("%s", "Unable to open NFC device."); @@ -64,6 +72,7 @@ main(int argc, const char *argv[]) } // Close NFC device nfc_close(pnd); - nfc_exit(NULL); + // Release the context + nfc_exit(context); return EXIT_SUCCESS; }