Home | History | Annotate | Download | only in default
      1 #ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H
      2 #define ANDROID_HARDWARE_NFC_V1_0_NFC_H
      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;
     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 
     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         }
     51     }
     52 
     53     virtual void serviceDied(uint64_t /*cookie*/,
     54                              const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
     55         close();
     56     }
     57 
     58    private:
     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 
     71 #endif  // ANDROID_HARDWARE_NFC_V1_0_NFC_H
     72