1 /*
2  * Copyright (c) 2022-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 
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     private:
46         std::map<int32_t, std::string> saIdProcessNameMap_ {
47             {4803, "dcamera"},
48             {4804, "dcamera"},
49             {4805, "daudio"},
50             {4806, "daudio"},
51             {4807, "dscreen"},
52             {4808, "dscreen"},
53             {4809, "dinput"},
54             {4810, "dinput"},
55             {66198, "dmodem"},
56         };
57     };
58 
59 private:
60     std::mutex saListenersMtx_;
61     std::map<int32_t, sptr<SystemAbilityStatusChangeStub>> saListeners_;
62 };
63 } // namespace DistributedHardware
64 } // namespace OHOS
65 #endif