Steven Moreland | 33e87b8 | 2016-11-22 15:34:39 -0800 | [diff] [blame] | 1 | #ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H |
| 2 | #define ANDROID_HARDWARE_NFC_V1_0_NFC_H |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 3 | |
| 4 | #include <android/hardware/nfc/1.0/INfc.h> |
| 5 | #include <hidl/Status.h> |
| 6 | #include <hardware/hardware.h> |
| 7 | #include <hardware/nfc.h> |
| 8 | namespace android { |
| 9 | namespace hardware { |
| 10 | namespace nfc { |
| 11 | namespace V1_0 { |
| 12 | namespace implementation { |
| 13 | |
| 14 | using ::android::hardware::nfc::V1_0::INfc; |
| 15 | using ::android::hardware::nfc::V1_0::INfcClientCallback; |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 16 | using ::android::hardware::Return; |
| 17 | using ::android::hardware::Void; |
| 18 | using ::android::hardware::hidl_vec; |
| 19 | using ::android::hardware::hidl_string; |
| 20 | using ::android::sp; |
| 21 | |
Martijn Coenen | 85ca130 | 2017-02-23 17:24:20 +0100 | [diff] [blame] | 22 | struct NfcDeathRecipient : hidl_death_recipient { |
| 23 | NfcDeathRecipient(const sp<INfc> nfc) : mNfc(nfc) { |
| 24 | } |
| 25 | |
| 26 | virtual void serviceDied(uint64_t /*cookie*/, const wp<::android::hidl::base::V1_0::IBase>& /*who*/) { |
| 27 | mNfc->close(); |
| 28 | } |
| 29 | sp<INfc> mNfc; |
| 30 | }; |
| 31 | |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 32 | struct Nfc : public INfc { |
| 33 | Nfc(nfc_nci_device_t* device); |
Ruchi Kandoi | 51068e0 | 2016-11-18 14:11:33 -0800 | [diff] [blame] | 34 | ::android::hardware::Return<NfcStatus> open(const sp<INfcClientCallback>& clientCallback) override; |
| 35 | ::android::hardware::Return<uint32_t> write(const hidl_vec<uint8_t>& data) override; |
| 36 | ::android::hardware::Return<NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override; |
| 37 | ::android::hardware::Return<NfcStatus> prediscover() override; |
| 38 | ::android::hardware::Return<NfcStatus> close() override; |
| 39 | ::android::hardware::Return<NfcStatus> controlGranted() override; |
| 40 | ::android::hardware::Return<NfcStatus> powerCycle() override; |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 41 | |
Steven Moreland | a74426d | 2016-09-26 12:41:23 -0700 | [diff] [blame] | 42 | static void eventCallback(uint8_t event, uint8_t status) { |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 43 | if (mCallback != nullptr) { |
Martijn Coenen | 85ca130 | 2017-02-23 17:24:20 +0100 | [diff] [blame] | 44 | auto ret = mCallback->sendEvent( |
Steven Moreland | a74426d | 2016-09-26 12:41:23 -0700 | [diff] [blame] | 45 | (::android::hardware::nfc::V1_0::NfcEvent) event, |
| 46 | (::android::hardware::nfc::V1_0::NfcStatus) status); |
Martijn Coenen | 85ca130 | 2017-02-23 17:24:20 +0100 | [diff] [blame] | 47 | if (!ret.isOk()) { |
| 48 | ALOGW("Failed to call back into NFC process."); |
| 49 | } |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 50 | } |
| 51 | } |
Steven Moreland | a74426d | 2016-09-26 12:41:23 -0700 | [diff] [blame] | 52 | static void dataCallback(uint16_t data_len, uint8_t* p_data) { |
| 53 | hidl_vec<uint8_t> data; |
| 54 | data.setToExternal(p_data, data_len); |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 55 | if (mCallback != nullptr) { |
Martijn Coenen | 85ca130 | 2017-02-23 17:24:20 +0100 | [diff] [blame] | 56 | auto ret = mCallback->sendData(data); |
| 57 | if (!ret.isOk()) { |
| 58 | ALOGW("Failed to call back into NFC process."); |
| 59 | } |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | private: |
| 63 | static sp<INfcClientCallback> mCallback; |
| 64 | const nfc_nci_device_t* mDevice; |
Martijn Coenen | 85ca130 | 2017-02-23 17:24:20 +0100 | [diff] [blame] | 65 | sp<NfcDeathRecipient> mDeathRecipient; |
Iliyan Malchev | 678fa1f | 2016-09-22 15:53:53 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | extern "C" INfc* HIDL_FETCH_INfc(const char* name); |
| 69 | |
| 70 | } // namespace implementation |
| 71 | } // namespace V1_0 |
| 72 | } // namespace nfc |
| 73 | } // namespace hardware |
| 74 | } // namespace android |
| 75 | |
Steven Moreland | 33e87b8 | 2016-11-22 15:34:39 -0800 | [diff] [blame] | 76 | #endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H |