/****************************************************************************** * * Copyright 2018 NXP * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #ifndef ANDROID_HARDWARE_NFC_V1_1_NFC_H #define ANDROID_HARDWARE_NFC_V1_1_NFC_H #include #include #include #include #include namespace android { namespace hardware { namespace nfc { namespace V1_1 { namespace implementation { using ::android::sp; using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; using ::android::hardware::nfc::V1_1::INfc; using ::android::hidl::base::V1_0::IBase; struct Nfc : public V1_1::INfc, public hidl_death_recipient { public: // Methods from ::android::hardware::nfc::V1_0::INfc follow. Return open( const sp& clientCallback) override; Return open_1_1( const sp& clientCallback) override; Return write(const hidl_vec& data) override; Return coreInitialized( const hidl_vec& data) override; Return prediscover() override; Return close() override; Return controlGranted() override; Return powerCycle() override; // Methods from ::android::hardware::nfc::V1_1::INfc follow. Return factoryReset(); Return closeForPowerOffCase(); Return getConfig(getConfig_cb config); // Methods from ::android::hidl::base::V1_0::IBase follow. static void eventCallback(uint8_t event, uint8_t status) { if (mCallbackV1_1 != nullptr) { auto ret = mCallbackV1_1->sendEvent_1_1((V1_1::NfcEvent)event, (V1_0::NfcStatus)status); if (!ret.isOk()) { ALOGW("failed to send event!!!"); } } else if (mCallbackV1_0 != nullptr) { auto ret = mCallbackV1_0->sendEvent((V1_0::NfcEvent)event, (V1_0::NfcStatus)status); if (!ret.isOk()) { ALOGE("failed to send event!!!"); } } } static void dataCallback(uint16_t data_len, uint8_t* p_data) { hidl_vec data; data.setToExternal(p_data, data_len); if (mCallbackV1_1 != nullptr) { auto ret = mCallbackV1_1->sendData(data); if (!ret.isOk()) { ALOGW("failed to send data!!!"); } } else if (mCallbackV1_0 != nullptr) { auto ret = mCallbackV1_0->sendData(data); if (!ret.isOk()) { ALOGE("failed to send data!!!"); } } } virtual void serviceDied(uint64_t /*cookie*/, const wp& /*who*/) { close(); } private: static sp mCallbackV1_1; static sp mCallbackV1_0; }; } // namespace implementation } // namespace V1_1 } // namespace nfc } // namespace hardware } // namespace android #endif // ANDROID_HARDWARE_NFC_V1_1_NFC_H