nfc_nci_example: Switch to C++
Our custom UNUSED_ARGUMENT macro was redundant with the sys/defs.h
__unused macro, so it needed to be removed. But rather than
switch to __unused, we opt to switch this code to C++, so we can
comment out parameter names to silence compiler warnings about
unused arguments.
The switch to C++ requires casting the result of calloc. We
also change our function argument indentation per our C++
style rules while we're in here.
Test: Compiled and confirmed no compiler warnings.
Change-Id: Ibd0eef7787843597917c3e0e71bdd772f6e9e876
diff --git a/modules/nfc-nci/Android.bp b/modules/nfc-nci/Android.bp
index 90d2a28..f4ef64e 100644
--- a/modules/nfc-nci/Android.bp
+++ b/modules/nfc-nci/Android.bp
@@ -16,7 +16,7 @@
name: "nfc_nci.default",
relative_install_path: "hw",
proprietary: true,
- srcs: ["nfc_nci_example.c"],
+ srcs: ["nfc_nci_example.cpp"],
shared_libs: [
"liblog",
"libcutils",
diff --git a/modules/nfc-nci/nfc_nci_example.c b/modules/nfc-nci/nfc_nci_example.cpp
similarity index 68%
rename from modules/nfc-nci/nfc_nci_example.c
rename to modules/nfc-nci/nfc_nci_example.cpp
index f3f60f6..0471b6b 100644
--- a/modules/nfc-nci/nfc_nci_example.c
+++ b/modules/nfc-nci/nfc_nci_example.cpp
@@ -23,61 +23,45 @@
#include <hardware/nfc.h>
/*
- * We want to silence the "unused argument" that gcc and clang give.
- * Other compilers generating this warning will need to provide their
- * custom attribute to silence this.
- */
-#if defined(__GNUC__) || defined(__clang__)
-#define UNUSED_ARGUMENT __attribute((unused))
-#else
-#define UNUSED_ARGUMENT
-#endif
-
-/*
* NCI HAL method implementations. These must be overriden
*/
-static int hal_open(const struct nfc_nci_device *dev UNUSED_ARGUMENT,
- nfc_stack_callback_t *p_cback UNUSED_ARGUMENT,
- nfc_stack_data_callback_t *p_data_cback UNUSED_ARGUMENT) {
+static int hal_open(const struct nfc_nci_device* /*dev*/,
+ nfc_stack_callback_t* /*p_cback*/,
+ nfc_stack_data_callback_t* /*p_data_cback*/) {
ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
return 0;
}
-static int hal_write(const struct nfc_nci_device *dev UNUSED_ARGUMENT,
- uint16_t data_len UNUSED_ARGUMENT,
- const uint8_t *p_data UNUSED_ARGUMENT) {
+static int hal_write(const struct nfc_nci_device* /*dev*/,
+ uint16_t /*data_len*/, const uint8_t* /*p_data*/) {
ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
return 0;
}
-static int hal_core_initialized(
- const struct nfc_nci_device *dev UNUSED_ARGUMENT,
- uint8_t* p_core_init_rsp_params UNUSED_ARGUMENT) {
+static int hal_core_initialized(const struct nfc_nci_device* /*dev*/,
+ uint8_t* /*p_core_init_rsp_params*/) {
ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
return 0;
}
-static int hal_pre_discover(
- const struct nfc_nci_device *dev UNUSED_ARGUMENT) {
+static int hal_pre_discover(const struct nfc_nci_device* /*dev*/) {
ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
return 0;
}
-static int hal_close(const struct nfc_nci_device *dev UNUSED_ARGUMENT) {
+static int hal_close(const struct nfc_nci_device* /*dev*/) {
ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
return 0;
}
-static int hal_control_granted (
- const struct nfc_nci_device *p_dev UNUSED_ARGUMENT)
+static int hal_control_granted (const struct nfc_nci_device* /*p_dev*/)
{
ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
return 0;
}
-static int hal_power_cycle (
- const struct nfc_nci_device *p_dev UNUSED_ARGUMENT)
+static int hal_power_cycle (const struct nfc_nci_device* /*p_dev*/)
{
ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
return 0;
@@ -93,9 +77,10 @@
}
static int nfc_open(const hw_module_t* module, const char* name,
- hw_device_t** device) {
+ hw_device_t** device) {
if (strcmp(name, NFC_NCI_CONTROLLER) == 0) {
- nfc_nci_device_t *dev = calloc(1, sizeof(nfc_nci_device_t));
+ nfc_nci_device_t *dev = static_cast<nfc_nci_device_t*>(
+ calloc(1, sizeof(nfc_nci_device_t)));
dev->common.tag = HARDWARE_DEVICE_TAG;
dev->common.version = 0x00010000; // [31:16] major, [15:0] minor