1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef NFC_CARDEMULATION_CONTROLLER_H 16 #define NFC_CARDEMULATION_CONTROLLER_H 17 18 #include <cstdint> 19 #include <functional> 20 #include <memory> 21 #include <mutex> 22 #include <vector> 23 24 namespace OHOS { 25 namespace NFC { 26 namespace KITS { 27 28 class CjNfcCardEmulationController { 29 public: 30 CjNfcCardEmulationController() = default; 31 ~CjNfcCardEmulationController() = default; 32 static std::shared_ptr<CjNfcCardEmulationController> GetInstance(); 33 int32_t Subscribe(int8_t type, int64_t id); 34 int32_t UnSubscribe(int8_t type); 35 void HceCmd(const std::vector<uint8_t>& data); 36 37 private: 38 void RegisterListener(int8_t type, int64_t id); 39 void UnRegisterListener(int8_t type); 40 void InitHceCmd(int64_t id); 41 std::recursive_mutex mutex_; 42 std::function<void(const uint8_t* head, int64_t size)> hceCmd_; 43 static std::mutex controllerMutex_; 44 static std::shared_ptr<CjNfcCardEmulationController> controller_; 45 }; 46 47 } // namespace KITS 48 } // namespace NFC 49 } // namespace OHOS 50 51 #endif