• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_MANAGER_H
17 #define OHOS_DISTRIBUTED_HARDWARE_COMPONENT_MANAGER_H
18 
19 #include <map>
20 #include <set>
21 #include <unordered_map>
22 #include <mutex>
23 #include <future>
24 
25 #include "single_instance.h"
26 #include "component_monitor.h"
27 #include "device_type.h"
28 #include "idistributed_hardware.h"
29 #include "idistributed_hardware_sink.h"
30 #include "idistributed_hardware_source.h"
31 #include "low_latency_listener.h"
32 #include "monitor_task_timer.h"
33 #include "version_info.h"
34 
35 namespace OHOS {
36 namespace DistributedHardware {
37 using ActionResult = std::unordered_map<DHType, std::shared_future<int32_t>>;
38 class ComponentManager {
39     DECLARE_SINGLE_INSTANCE_BASE(ComponentManager);
40 
41 public:
42     ComponentManager();
43     ~ComponentManager();
44 
45 public:
46     int32_t Init();
47     int32_t UnInit();
48     int32_t Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId,
49         const DHType dhType);
50     int32_t Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId,
51         const DHType dhType);
52 
53     void DumpLoadedComps(std::set<DHType> &compSourceType, std::set<DHType> &compSinkType);
54     void Recover(DHType dhType);
55 
56 private:
57     enum class Action : int32_t {
58         START_SOURCE,
59         START_SINK,
60         STOP_SOURCE,
61         STOP_SINK
62     };
63 
64     DHType GetDHType(const std::string &uuid, const std::string &dhId) const;
65     bool InitCompSource();
66     bool InitCompSink();
67     ActionResult StartSource();
68     ActionResult StartSource(DHType dhType);
69     ActionResult StopSource();
70     ActionResult StartSink();
71     ActionResult StartSink(DHType dhType);
72     ActionResult StopSink();
73     bool WaitForResult(const Action &action, ActionResult result);
74     int32_t GetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId,
75         DHType dhType, EnableParam &param);
76     int32_t GetSinkVersionFromVerMgr(const std::string &uuid, const DHType dhType,
77         std::string &sinkVersion);
78     int32_t GetSinkVersionFromVerInfoMgr(const std::string &uuid, const DHType dhType,
79         std::string &sinkVersion);
80     int32_t GetSinkVersion(const std::string &networkId, const std::string &uuid,
81         DHType dhType, std::string &sinkVersion);
82     void UpdateVersionCache(const std::string &uuid, const VersionInfo &versionInfo);
83 
84     void DoRecover(DHType dhType);
85     void ReStartSA(DHType dhType);
86     void RecoverDistributedHardware(DHType dhType);
87 
88 private:
89     std::map<DHType, IDistributedHardwareSource*> compSource_;
90     std::map<DHType, IDistributedHardwareSink*> compSink_;
91     std::map<DHType, int32_t> compSrcSaId_;
92     std::shared_ptr<ComponentMonitor> compMonitorPtr_ = nullptr;
93     sptr<LowLatencyListener> lowLatencyListener_ = nullptr;
94     std::shared_ptr<DHTimer> monitorTaskTimer_ = nullptr;
95 };
96 } // namespace DistributedHardware
97 } // namespace OHOS
98 #endif
99