1 /* 2 * Copyright (c) 2023 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 COOPERATE_CONTEXT_H 17 #define COOPERATE_CONTEXT_H 18 19 #include <memory> 20 21 #include "nocopyable.h" 22 23 #include "cooperate_events.h" 24 #include "dsoftbus_handler.h" 25 #include "event_manager.h" 26 #include "input_device_manager.h" 27 #include "i_context.h" 28 #include "i_ddm_adapter.h" 29 #include "i_ddp_adapter.h" 30 31 namespace OHOS { 32 namespace Msdp { 33 namespace DeviceStatus { 34 namespace Cooperate { 35 class Context final { 36 public: 37 Context(IContext *env); 38 ~Context() = default; 39 DISALLOW_COPY_AND_MOVE(Context); 40 41 void AttachSender(Channel<CooperateEvent>::Sender sender); 42 void Enable(); 43 void Disable(); 44 45 Channel<CooperateEvent>::Sender Sender() const; 46 std::string Origin() const; 47 std::string Peer() const; 48 std::string StartDeviceDhid() const; 49 int32_t StartDeviceId() const; 50 std::vector<std::string> CooperateDhids() const; 51 Coordinate CursorPosition() const; 52 53 bool IsPeer(const std::string &networkId) const; 54 55 void StartCooperate(const StartCooperateEvent &event); 56 void RemoteStart(const DSoftbusStartCooperate &event); 57 void RemoteStartSuccess(const DSoftbusStartCooperateFinished &event); 58 59 std::shared_ptr<InputDeviceManager> devMgr_; 60 std::shared_ptr<IDDMAdapter> ddm_; 61 std::shared_ptr<IDDPAdapter> ddp_; 62 std::shared_ptr<DSoftbusHandler> dsoftbus_; 63 EventManager eventMgr_; 64 65 private: 66 int32_t EnableDevMgr(); 67 void DisableDevMgr(); 68 int32_t EnableDSoftbus(); 69 void DisableDSoftbus(); 70 int32_t EnableDDM(); 71 void DisableDDM(); 72 int32_t EnableDDP(); 73 void DisableDDP(); 74 void SetCursorPosition(const DSoftbusStartCooperateFinished &event); 75 76 Channel<CooperateEvent>::Sender sender_; 77 std::string originNetworkId_; 78 std::string remoteNetworkId_; 79 std::string startDeviceDhid_; 80 int32_t startDeviceId_ { -1 }; 81 Coordinate cursorPos_ {}; 82 std::shared_ptr<IBoardObserver> boardObserver_; 83 std::shared_ptr<IDeviceProfileObserver> dpObserver_; 84 }; 85 Sender()86inline Channel<CooperateEvent>::Sender Context::Sender() const 87 { 88 return sender_; 89 } 90 Origin()91inline std::string Context::Origin() const 92 { 93 return originNetworkId_; 94 } 95 Peer()96inline std::string Context::Peer() const 97 { 98 return remoteNetworkId_; 99 } 100 StartDeviceDhid()101inline std::string Context::StartDeviceDhid() const 102 { 103 return startDeviceDhid_; 104 } 105 StartDeviceId()106inline int32_t Context::StartDeviceId() const 107 { 108 return startDeviceId_; 109 } 110 CooperateDhids()111inline std::vector<std::string> Context::CooperateDhids() const 112 { 113 return devMgr_->GetCooperateDhids(startDeviceId_); 114 } 115 CursorPosition()116inline Coordinate Context::CursorPosition() const 117 { 118 return cursorPos_; 119 } 120 IsPeer(const std::string & networkId)121inline bool Context::IsPeer(const std::string &networkId) const 122 { 123 return (networkId == remoteNetworkId_); 124 } 125 } // namespace Cooperate 126 } // namespace DeviceStatus 127 } // namespace Msdp 128 } // namespace OHOS 129 #endif // COOPERATE_CONTEXT_H 130