1 /* 2 * Copyright (c) 2021-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_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 56 protected: 57 void OnStart() override; 58 void OnStop() override; 59 60 private: 61 bool Init(); 62 std::string QueryDhSysSpec(const std::string &targetKey, std::string &attrs); 63 void InitLocalDevInfo(); 64 bool DoBusinessInit(); 65 bool IsDepSAStart(); 66 67 private: 68 bool registerToService_ = false; 69 ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; 70 std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_ = nullptr; 71 }; 72 } // namespace DistributedHardware 73 } // namespace OHOS 74 #endif