• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_SERVICE_H
17 #define OHOS_DISTRIBUTED_HARDWARE_SERVICE_H
18 
19 #include "event_handler.h"
20 #include "ipc_object_stub.h"
21 #include "system_ability.h"
22 
23 #include "distributed_hardware_fwk_kit.h"
24 #include "distributed_hardware_fwk_kit_paras.h"
25 #include "distributed_hardware_stub.h"
26 #include "single_instance.h"
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 enum class ServiceRunningState {
31     STATE_NOT_START,
32     STATE_RUNNING
33 };
34 
35 class DistributedHardwareService : public SystemAbility, public DistributedHardwareStub {
36 DECLARE_SYSTEM_ABILITY(DistributedHardwareService);
37 public:
38     DistributedHardwareService(int32_t saId, bool runOnCreate);
39     ~DistributedHardwareService() = default;
40     int32_t RegisterPublisherListener(const DHTopic topic, const sptr<IPublisherListener> listener) override;
41     int32_t UnregisterPublisherListener(const DHTopic topic, const sptr<IPublisherListener> listener) override;
42     int32_t PublishMessage(const DHTopic topic, const std::string &msg) override;
43     std::string QueryLocalSysSpec(const QueryLocalSysSpecType spec) override;
44     int Dump(int32_t fd, const std::vector<std::u16string>& args) override;
45 
46     int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId) override;
47     int32_t ReleaseAVCenter(int32_t engineId) override;
48     int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId) override;
49     int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event) override;
50     int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr<IAvTransControlCenterCallback> callback) override;
51     int32_t NotifySourceRemoteSinkStarted(std::string &deviceId) override;
52     int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId) override;
53     int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId) override;
54     int32_t StopDistributedHardware(DHType dhType, const std::string &networkId) override;
55     int32_t GetDistributedHardware(const std::string &networkId, EnableStep enableStep,
56         const sptr<IGetDhDescriptorsCallback> callback) override;
57     int32_t RegisterDHStatusListener(sptr<IHDSinkStatusListener> listener) override;
58     int32_t UnregisterDHStatusListener(sptr<IHDSinkStatusListener> listener) override;
59     int32_t RegisterDHStatusListener(const std::string &networkId, sptr<IHDSourceStatusListener> listener) override;
60     int32_t UnregisterDHStatusListener(const std::string &networkId, sptr<IHDSourceStatusListener> listener) override;
61     int32_t EnableSink(const std::vector<DHDescriptor> &descriptors) override;
62     int32_t DisableSink(const std::vector<DHDescriptor> &descriptors) override;
63     int32_t EnableSource(const std::string &networkId, const std::vector<DHDescriptor> &descriptors) override;
64     int32_t DisableSource(const std::string &networkId, const std::vector<DHDescriptor> &descriptors) override;
65     int32_t LoadDistributedHDF(const DHType dhType) override;
66     int32_t UnLoadDistributedHDF(const DHType dhType) override;
67 
68 protected:
69     void OnStart() override;
70     void OnStop() override;
71     int32_t OnIdle(const SystemAbilityOnDemandReason& idleReason) override;
72 
73 private:
74     bool Init();
75     std::string QueryDhSysSpec(const std::string &targetKey, std::string &attrs);
76     void InitLocalDevInfo();
77     bool DoBusinessInit();
78     bool IsDepSAStart();
79 
80 private:
81     bool registerToService_ = false;
82     ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
83     std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_ = nullptr;
84 };
85 } // namespace DistributedHardware
86 } // namespace OHOS
87 #endif