blob: 1b14534e1aee269152cb894f82a6d9e918082e22 [file] [log] [blame]
George Changdbc36e52021-10-20 11:13:18 +08001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <aidl/android/hardware/nfc/BnNfc.h>
20#include <aidl/android/hardware/nfc/INfcClientCallback.h>
21#include <android-base/logging.h>
22namespace aidl {
23namespace android {
24namespace hardware {
25namespace nfc {
26
27using ::aidl::android::hardware::nfc::NfcCloseType;
28using ::aidl::android::hardware::nfc::NfcConfig;
29using ::aidl::android::hardware::nfc::NfcStatus;
30
31// Default implementation that reports no support NFC.
32struct Nfc : public BnNfc {
33 public:
34 Nfc() = default;
35
36 ::ndk::ScopedAStatus open(const std::shared_ptr<INfcClientCallback>& clientCallback) override;
37 ::ndk::ScopedAStatus close(NfcCloseType type) override;
38 ::ndk::ScopedAStatus coreInitialized() override;
39 ::ndk::ScopedAStatus factoryReset() override;
40 ::ndk::ScopedAStatus getConfig(NfcConfig* _aidl_return) override;
41 ::ndk::ScopedAStatus powerCycle() override;
42 ::ndk::ScopedAStatus preDiscover() override;
43 ::ndk::ScopedAStatus write(const std::vector<uint8_t>& data, int32_t* _aidl_return) override;
44 ::ndk::ScopedAStatus setEnableVerboseLogging(bool enable) override;
45 ::ndk::ScopedAStatus isVerboseLoggingEnabled(bool* _aidl_return) override;
46
47 static void eventCallback(uint8_t event, uint8_t status) {
48 if (mCallback != nullptr) {
49 auto ret = mCallback->sendEvent((NfcEvent)event, (NfcStatus)status);
50 if (!ret.isOk()) {
51 LOG(ERROR) << "Failed to send event!";
52 }
53 }
54 }
55
56 static void dataCallback(uint16_t data_len, uint8_t* p_data) {
57 std::vector<uint8_t> data(p_data, p_data + data_len);
58 if (mCallback != nullptr) {
59 auto ret = mCallback->sendData(data);
60 if (!ret.isOk()) {
61 LOG(ERROR) << "Failed to send data!";
62 }
63 }
64 }
65
66 static std::shared_ptr<INfcClientCallback> mCallback;
67};
68
69} // namespace nfc
70} // namespace hardware
71} // namespace android
72} // namespace aidl