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_DSCREEN_MGR_V1_0_H 17 #define OHOS_DSCREEN_MGR_V1_0_H 18 19 #include "distributed_hardware_fwk_kit.h" 20 #include "dm_common.h" 21 #include "single_instance.h" 22 #include "screen_manager.h" 23 24 #include "dscreen.h" 25 #include "dscreen_maprelation.h" 26 #include "idistributed_hardware_source.h" 27 #include "idscreen_sink.h" 28 #include "idscreen_source_callback.h" 29 #include "video_param.h" 30 31 namespace OHOS { 32 namespace DistributedHardware { 33 namespace V1_0 { 34 class DScreenCallback : public IDScreenCallback { 35 public: 36 void OnRegResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 37 const int32_t status, const std::string &data) override; 38 void OnUnregResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 39 const int32_t status, const std::string &data) override; 40 }; 41 42 class DScreenGroupListener : public Rosen::ScreenManager::IScreenGroupListener { 43 public: 44 void OnChange(const std::vector<uint64_t> &screenIds, Rosen::ScreenGroupChangeEvent event) override; 45 }; 46 47 class DScreenManager { 48 DECLARE_SINGLE_INSTANCE_BASE(DScreenManager); 49 public: 50 void OnRegResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 51 const int32_t status, const std::string &data); 52 void OnUnregResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 53 const int32_t status, const std::string &data); 54 55 int32_t Init(); 56 int32_t UnInit(); 57 int32_t EnableDistributedScreen(const std::string &devId, const std::string &dhId, const EnableParam ¶m, 58 const std::string &reqId); 59 int32_t DisableDistributedScreen(const std::string &devId, const std::string &dhId, const std::string &reqId); 60 void HandleDScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent); 61 void RegisterDScreenCallback(const sptr<IDScreenSourceCallback> &callback); 62 void HandleScreenChange(const std::shared_ptr<DScreen> &changedScreen, Rosen::ScreenGroupChangeEvent event); 63 std::shared_ptr<DScreen> FindDScreenByScreenId(uint64_t screenId); 64 int32_t AddToGroup(const std::shared_ptr<DScreen> &changedScreen, uint64_t screenId); 65 int32_t RemoveFromGroup(const std::shared_ptr<DScreen> &changedScreen, uint64_t screenId); 66 void GetScreenDumpInfo(std::string &result); 67 void PublishMessage(const DHTopic topic, const std::shared_ptr<DScreen> &dScreen); 68 69 private: 70 ~DScreenManager(); 71 DScreenManager(); 72 std::mutex dScreenMapMtx_; 73 std::mutex dScreenMapRelationMtx_; 74 std::mutex dScreenCallbackMtx_; 75 std::map<uint64_t, std::shared_ptr<DScreenMapRelation>> mapRelations_; 76 std::map<std::string, std::shared_ptr<DScreen>> dScreens_; 77 sptr<IDScreenSourceCallback> dScreenSourceCallbackProxy_ = nullptr; 78 sptr<DScreenGroupListener> dScreenGroupListener_ = nullptr; 79 std::shared_ptr<IDScreenCallback> dScreenCallback_ = nullptr; 80 std::string localDevId_; 81 82 sptr<IDScreenSink> GetDScreenSinkSA(const std::string &devId); 83 int32_t NotifyRemoteScreenService(const std::string &devId, int32_t eventCode, const std::string &eventContent); 84 void NotifyRemoteSinkSetUp(const std::shared_ptr<DScreen> &dScreen); 85 bool CheckContent(json &eventContent); 86 void HandleNotifySetUpResult(const std::string &remoteDevId, const std::string &eventContent); 87 }; 88 } // namespace V1_0 89 } // namespace DistributedHardware 90 } // namespace OHOS 91 #endif