From e0c416a6f247992089663095f29a9e50cef2ef99 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Mon, 26 Sep 2016 12:40:29 -0700 Subject: [PATCH 1/2] nfc: reflect style guide. Test: make android.hardware.nfc@1.0 Change-Id: I60c1589492752753c362dc9766ebc7776b5e6e6e --- nfc/1.0/Android.mk | 58 +++++++--------------------------- nfc/1.0/INfc.hal | 30 +++++++++--------- nfc/1.0/INfcClientCallback.hal | 4 +-- nfc/1.0/types.hal | 32 +++++++++---------- 4 files changed, 44 insertions(+), 80 deletions(-) diff --git a/nfc/1.0/Android.mk b/nfc/1.0/Android.mk index b6840bc97a..07775e9ae6 100644 --- a/nfc/1.0/Android.mk +++ b/nfc/1.0/Android.mk @@ -13,9 +13,9 @@ intermediates := $(local-generated-sources-dir) HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX) # -# Build types.hal (nfc_data_t) +# Build types.hal (NfcEvent) # -GEN := $(intermediates)/android/hardware/nfc/1.0/nfc_data_t.java +GEN := $(intermediates)/android/hardware/nfc/1.0/NfcEvent.java $(GEN): $(HIDL) $(GEN): PRIVATE_HIDL := $(HIDL) $(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal @@ -23,16 +23,16 @@ $(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) $(GEN): PRIVATE_CUSTOM_TOOL = \ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ -Ljava -randroid.hardware:hardware/interfaces \ - android.hardware.nfc@1.0::types.nfc_data_t + android.hardware.nfc@1.0::types.NfcEvent $(GEN): $(LOCAL_PATH)/types.hal $(transform-generated-source) LOCAL_GENERATED_SOURCES += $(GEN) # -# Build types.hal (nfc_event_t) +# Build types.hal (NfcStatus) # -GEN := $(intermediates)/android/hardware/nfc/1.0/nfc_event_t.java +GEN := $(intermediates)/android/hardware/nfc/1.0/NfcStatus.java $(GEN): $(HIDL) $(GEN): PRIVATE_HIDL := $(HIDL) $(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal @@ -40,24 +40,7 @@ $(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) $(GEN): PRIVATE_CUSTOM_TOOL = \ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ -Ljava -randroid.hardware:hardware/interfaces \ - android.hardware.nfc@1.0::types.nfc_event_t - -$(GEN): $(LOCAL_PATH)/types.hal - $(transform-generated-source) -LOCAL_GENERATED_SOURCES += $(GEN) - -# -# Build types.hal (nfc_status_t) -# -GEN := $(intermediates)/android/hardware/nfc/1.0/nfc_status_t.java -$(GEN): $(HIDL) -$(GEN): PRIVATE_HIDL := $(HIDL) -$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal -$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) -$(GEN): PRIVATE_CUSTOM_TOOL = \ - $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ - -Ljava -randroid.hardware:hardware/interfaces \ - android.hardware.nfc@1.0::types.nfc_status_t + android.hardware.nfc@1.0::types.NfcStatus $(GEN): $(LOCAL_PATH)/types.hal $(transform-generated-source) @@ -116,9 +99,9 @@ intermediates := $(local-generated-sources-dir) HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX) # -# Build types.hal (nfc_data_t) +# Build types.hal (NfcEvent) # -GEN := $(intermediates)/android/hardware/nfc/1.0/nfc_data_t.java +GEN := $(intermediates)/android/hardware/nfc/1.0/NfcEvent.java $(GEN): $(HIDL) $(GEN): PRIVATE_HIDL := $(HIDL) $(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal @@ -126,16 +109,16 @@ $(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) $(GEN): PRIVATE_CUSTOM_TOOL = \ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ -Ljava -randroid.hardware:hardware/interfaces \ - android.hardware.nfc@1.0::types.nfc_data_t + android.hardware.nfc@1.0::types.NfcEvent $(GEN): $(LOCAL_PATH)/types.hal $(transform-generated-source) LOCAL_GENERATED_SOURCES += $(GEN) # -# Build types.hal (nfc_event_t) +# Build types.hal (NfcStatus) # -GEN := $(intermediates)/android/hardware/nfc/1.0/nfc_event_t.java +GEN := $(intermediates)/android/hardware/nfc/1.0/NfcStatus.java $(GEN): $(HIDL) $(GEN): PRIVATE_HIDL := $(HIDL) $(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal @@ -143,24 +126,7 @@ $(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) $(GEN): PRIVATE_CUSTOM_TOOL = \ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ -Ljava -randroid.hardware:hardware/interfaces \ - android.hardware.nfc@1.0::types.nfc_event_t - -$(GEN): $(LOCAL_PATH)/types.hal - $(transform-generated-source) -LOCAL_GENERATED_SOURCES += $(GEN) - -# -# Build types.hal (nfc_status_t) -# -GEN := $(intermediates)/android/hardware/nfc/1.0/nfc_status_t.java -$(GEN): $(HIDL) -$(GEN): PRIVATE_HIDL := $(HIDL) -$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal -$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates) -$(GEN): PRIVATE_CUSTOM_TOOL = \ - $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \ - -Ljava -randroid.hardware:hardware/interfaces \ - android.hardware.nfc@1.0::types.nfc_status_t + android.hardware.nfc@1.0::types.NfcStatus $(GEN): $(LOCAL_PATH)/types.hal $(transform-generated-source) diff --git a/nfc/1.0/INfc.hal b/nfc/1.0/INfc.hal index 88fd39a447..f003b2caf5 100644 --- a/nfc/1.0/INfc.hal +++ b/nfc/1.0/INfc.hal @@ -27,7 +27,7 @@ interface INfc { * NCI initialization - ie accept CORE_RESET and subsequent commands through * the write() call. * - * If open() returns 0, the NCI stack will wait for a HAL_NFC_OPEN_CPLT_EVT + * If open() returns 0, the NCI stack will wait for a NfcEvent.OPEN_CPLT * before continuing. * * If open() returns any other value, the NCI stack will stop. @@ -41,32 +41,32 @@ interface INfc { * This method may queue writes and return immediately. The only * requirement is that the writes are executed in order. */ - write(nfc_data_t data) generates (int32_t retval); + write(NfcData data) generates (int32_t retval); /* - * core_initialized() is called after the CORE_INIT_RSP is received from the NFCC. + * coreInitialized() is called after the CORE_INIT_RSP is received from the NFCC. * At this time, the HAL can do any chip-specific configuration. * - * If core_initialized() returns 0, the NCI stack will wait for a HAL_NFC_POST_INIT_CPLT_EVT + * If coreInitialized() returns 0, the NCI stack will wait for a NfcEvent.POST_INIT_CPLT * before continuing. * - * If core_initialized() returns any other value, the NCI stack will continue + * If coreInitialized() returns any other value, the NCI stack will continue * immediately. */ - core_initialized(vec data) generates (int32_t retval); + coreInitialized(NfcData data) generates (int32_t retval); /* - * pre_discover is called every time before starting RF discovery. + * prediscover is called every time before starting RF discovery. * It is a good place to do vendor-specific configuration that must be * performed every time RF discovery is about to be started. * - * If pre_discover() returns 0, the NCI stack will wait for a HAL_NFC_PRE_DISCOVER_CPLT_EVT + * If prediscover() returns 0, the NCI stack will wait for a NfcEvent.PREDISCOVER_CPLT * before continuing. * - * If pre_discover() returns any other value, the NCI stack will start + * If prediscover() returns any other value, the NCI stack will start * RF discovery immediately. */ - pre_discover() generates (int32_t retval); + prediscover() generates (int32_t retval); /* * Close the NFC controller. Should free all resources. @@ -75,15 +75,15 @@ interface INfc { /* * Grant HAL the exclusive control to send NCI commands. - * Called in response to HAL_REQUEST_CONTROL_EVT. + * Called in response to NfcEvent.REQUEST_CONTROL. * Must only be called when there are no NCI commands pending. - * HAL_RELEASE_CONTROL_EVT will notify when HAL no longer needs exclusive control. + * NfcEvent.RELEASE_CONTROL will notify when HAL no longer needs exclusive control. */ - control_granted() generates (int32_t retval); + controlGranted() generates (int32_t retval); /* * Restart controller by power cyle; - * HAL_OPEN_CPLT_EVT will notify when operation is complete. + * NfcEvent.OPEN_CPLT will notify when operation is complete. */ - power_cycle() generates (int32_t retval); + powerCycle() generates (int32_t retval); }; diff --git a/nfc/1.0/INfcClientCallback.hal b/nfc/1.0/INfcClientCallback.hal index f10062ef1e..a56cc0998c 100644 --- a/nfc/1.0/INfcClientCallback.hal +++ b/nfc/1.0/INfcClientCallback.hal @@ -21,11 +21,11 @@ interface INfcClientCallback { * The callback passed in from the NFC stack that the HAL * can use to pass events back to the stack. */ - sendEvent(nfc_event_t event, nfc_status_t event_status); + sendEvent(NfcEvent event, NfcStatus status); /* * The callback passed in from the NFC stack that the HAL * can use to pass incomming data to the stack. */ - sendData(nfc_data_t data); + sendData(NfcData data); }; diff --git a/nfc/1.0/types.hal b/nfc/1.0/types.hal index 738dfd96bb..a2661783dd 100644 --- a/nfc/1.0/types.hal +++ b/nfc/1.0/types.hal @@ -16,24 +16,22 @@ package android.hardware.nfc@1.0; -enum nfc_event_t : uint32_t { - HAL_NFC_OPEN_CPLT_EVT = 0, - HAL_NFC_CLOSE_CPLT_EVT = 1, - HAL_NFC_POST_INIT_CPLT_EVT = 2, - HAL_NFC_PRE_DISCOVER_CPLT_EVT = 3, - HAL_NFC_REQUEST_CONTROL_EVT = 4, - HAL_NFC_RELEASE_CONTROL_EVT = 5, - HAL_NFC_ERROR_EVT = 6 +enum NfcEvent : uint32_t { + OPEN_CPLT = 0, + CLOSE_CPLT = 1, + POST_INIT_CPLT = 2, + PRE_DISCOVER_CPLT = 3, + REQUEST_CONTROL = 4, + RELEASE_CONTROL = 5, + ERROR = 6 }; -enum nfc_status_t : uint32_t { - HAL_NFC_STATUS_OK = 0, - HAL_NFC_STATUS_FAILED = 1, - HAL_NFC_STATUS_ERR_TRANSPORT = 2, - HAL_NFC_STATUS_ERR_CMD_TIMEOUT = 3, - HAL_NFC_STATUS_REFUSED = 4 +enum NfcStatus : uint32_t { + OK = 0, + FAILED = 1, + ERR_TRANSPORT = 2, + ERR_CMD_TIMEOUT = 3, + REFUSED = 4 }; -struct nfc_data_t { - vec data; -}; +typedef vec NfcData; From 6b6381cb58aba593951f0718f9beecef0b49e284 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Mon, 26 Sep 2016 12:41:23 -0700 Subject: [PATCH 2/2] nfc: update default implementation to match style. Test: make android.hardware.nfc@1.0-impl Change-Id: Ib76d663fcf28816bd2ba57f5fbd5ae0033b620f5 --- nfc/1.0/default/Nfc.cpp | 14 +++++++------- nfc/1.0/default/Nfc.h | 23 +++++++++++------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/nfc/1.0/default/Nfc.cpp b/nfc/1.0/default/Nfc.cpp index b836adad8a..d3868c1309 100644 --- a/nfc/1.0/default/Nfc.cpp +++ b/nfc/1.0/default/Nfc.cpp @@ -19,19 +19,19 @@ Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) { // Methods from ::android::hardware::nfc::V1_0::INfc follow. ::android::hardware::Return Nfc::open(const sp& clientCallback) { mCallback = clientCallback; - return mDevice->open(mDevice, event_callback, data_callback); + return mDevice->open(mDevice, eventCallback, dataCallback); } -::android::hardware::Return Nfc::write(const nfc_data_t& data) { - return mDevice->write(mDevice, data.data.size(), &data.data[0]); +::android::hardware::Return Nfc::write(const hidl_vec& data) { + return mDevice->write(mDevice, data.size(), &data[0]); } -::android::hardware::Return Nfc::core_initialized(const hidl_vec& data) { +::android::hardware::Return Nfc::coreInitialized(const hidl_vec& data) { hidl_vec copy = data; return mDevice->core_initialized(mDevice, ©[0]); } -::android::hardware::Return Nfc::pre_discover() { +::android::hardware::Return Nfc::prediscover() { return mDevice->pre_discover(mDevice); } @@ -39,11 +39,11 @@ Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) { return mDevice->close(mDevice); } -::android::hardware::Return Nfc::control_granted() { +::android::hardware::Return Nfc::controlGranted() { return mDevice->control_granted(mDevice); } -::android::hardware::Return Nfc::power_cycle() { +::android::hardware::Return Nfc::powerCycle() { return mDevice->power_cycle(mDevice); } diff --git a/nfc/1.0/default/Nfc.h b/nfc/1.0/default/Nfc.h index 98cd57e8eb..e596495c36 100644 --- a/nfc/1.0/default/Nfc.h +++ b/nfc/1.0/default/Nfc.h @@ -13,7 +13,6 @@ namespace implementation { using ::android::hardware::nfc::V1_0::INfc; using ::android::hardware::nfc::V1_0::INfcClientCallback; -using ::android::hardware::nfc::V1_0::nfc_data_t; using ::android::hardware::Return; using ::android::hardware::Void; using ::android::hardware::hidl_vec; @@ -23,23 +22,23 @@ using ::android::sp; struct Nfc : public INfc { Nfc(nfc_nci_device_t* device); ::android::hardware::Return open(const sp& clientCallback) override; - ::android::hardware::Return write(const nfc_data_t& data) override; - ::android::hardware::Return core_initialized(const hidl_vec& data) override; - ::android::hardware::Return pre_discover() override; + ::android::hardware::Return write(const hidl_vec& data) override; + ::android::hardware::Return coreInitialized(const hidl_vec& data) override; + ::android::hardware::Return prediscover() override; ::android::hardware::Return close() override; - ::android::hardware::Return control_granted() override; - ::android::hardware::Return power_cycle() override; + ::android::hardware::Return controlGranted() override; + ::android::hardware::Return powerCycle() override; - static void event_callback(uint8_t event, uint8_t status) { + static void eventCallback(uint8_t event, uint8_t status) { if (mCallback != nullptr) { mCallback->sendEvent( - (::android::hardware::nfc::V1_0::nfc_event_t) event, - (::android::hardware::nfc::V1_0::nfc_status_t) status); + (::android::hardware::nfc::V1_0::NfcEvent) event, + (::android::hardware::nfc::V1_0::NfcStatus) status); } } - static void data_callback(uint16_t data_len, uint8_t* p_data) { - nfc_data_t data; - data.data.setToExternal(p_data, data_len); + static void dataCallback(uint16_t data_len, uint8_t* p_data) { + hidl_vec data; + data.setToExternal(p_data, data_len); if (mCallback != nullptr) { mCallback->sendData(data); }