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