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 16 #ifndef OHOS_DISTRIBUTED_HARDWARE_COMPONENT_MONITOR_H 17 #define OHOS_DISTRIBUTED_HARDWARE_COMPONENT_MONITOR_H 18 19 #include <cstdint> 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 #include <refbase.h> 24 25 #include "system_ability_status_change_stub.h" 26 27 #include "single_instance.h" 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 class ComponentMonitor { 32 REMOVE_NO_USE_CONSTRUCTOR(ComponentMonitor); 33 public: 34 explicit ComponentMonitor(); 35 ~ComponentMonitor(); 36 void AddSAMonitor(int32_t saId); 37 void RemoveSAMonitor(int32_t saId); 38 39 public: 40 class CompSystemAbilityListener : public SystemAbilityStatusChangeStub { 41 public: 42 ~CompSystemAbilityListener() = default; 43 void OnAddSystemAbility(int32_t saId, const std::string &deviceId) override; 44 void OnRemoveSystemAbility(int32_t saId, const std::string &deviceId) override; 45 }; 46 47 private: 48 std::mutex saListenersMtx_; 49 std::map<int32_t, sptr<SystemAbilityStatusChangeStub>> saListeners_; 50 }; 51 } // namespace DistributedHardware 52 } // namespace OHOS 53 #endif