1 /* 2 * Copyright (c) 2022 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_SA_MANAGER_H 16 #define NFC_SA_MANAGER_H 17 #include "iservice_registry.h" 18 #include "nfc_controller_impl.h" 19 #include "nfc_event_handler.h" 20 #include "nfc_service.h" 21 #include "singleton.h" 22 #include "system_ability.h" 23 24 namespace OHOS { 25 namespace NFC { 26 enum class ServiceRunningState { 27 STATE_NOT_START, 28 STATE_RUNNING 29 }; 30 31 class NfcSaManager : public SystemAbility { 32 DECLARE_DELAYED_SINGLETON(NfcSaManager) 33 DECLARE_SYSTEM_ABILITY(NfcSaManager); // necessary 34 public: 35 DISALLOW_COPY_AND_MOVE(NfcSaManager); 36 37 /* Nfc open or close operations */ 38 void OnStart() override; 39 void OnStop() override; 40 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 41 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 42 43 /* query service state */ QueryServiceState()44 ServiceRunningState QueryServiceState() const 45 { 46 return state_; 47 } 48 49 private: 50 bool Init(); 51 bool registerToService_ = false; 52 ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; 53 54 std::shared_ptr<NfcService> nfcService_; 55 sptr<NfcControllerImpl> nfcControllerImpl_; 56 std::mutex initMutex_ {}; 57 }; 58 } // namespace NFC 59 } // namespace OHOS 60 #endif // NFC_SA_MANAGER_H 61