/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef COOPERATE_INPUT_DEVICE_MANAGER_H #define COOPERATE_INPUT_DEVICE_MANAGER_H #include #include #include #include #include "nocopyable.h" #include "channel.h" #include "cooperate_events.h" #include "i_context.h" #include "net_packet.h" namespace OHOS { namespace Msdp { namespace DeviceStatus { namespace Cooperate { class InputDeviceMgr { public: InputDeviceMgr(IContext *context); ~InputDeviceMgr() = default; DISALLOW_COPY_AND_MOVE(InputDeviceMgr); public: void Enable(); void Disable(); void OnSoftbusSessionOpened(const DSoftbusSessionOpened ¬ice); void OnSoftbusSessionClosed(const DSoftbusSessionClosed ¬ice); void OnLocalHotPlug(const InputHotplugEvent ¬ice); void AddVirtualInputDevice(const std::string &networkId); void RemoveVirtualInputDevice(const std::string &networkId); void HandleRemoteHotPlug(const DSoftbusHotPlugEvent ¬ice); void OnRemoteInputDevice(const DSoftbusSyncInputDevice ¬ice); void OnRemoteHotPlug(const DSoftbusHotPlugEvent ¬ice); private: void NotifyInputDeviceToRemote(const std::string &remoteNetworkId); void BroadcastHotPlugToRemote(const InputHotplugEvent ¬ice); void AddRemoteInputDevice(const std::string &networkId, std::shared_ptr device); void RemoveRemoteInputDevice(const std::string &networkId, std::shared_ptr device); void RemoveAllRemoteInputDevice(const std::string &networkId); void DumpRemoteInputDevice(const std::string &networkId); int32_t SerializeDevice(std::shared_ptr device, NetPacket &packet); std::shared_ptr Transform(std::shared_ptr device); void AddVirtualInputDevice(const std::string &networkId, int32_t remoteDeviceId); void RemoveVirtualInputDevice(const std::string &networkId, int32_t remoteDeviceId); void DispDeviceInfo(std::shared_ptr device); std::shared_ptr GetRemoteDeviceById(const std::string &networkId, int32_t remoteDeviceId); private: bool enable_ { false }; IContext *env_ { nullptr }; struct IDeviceCmp { bool operator()(const std::shared_ptr &one, const std::shared_ptr &other) const { return one->GetId() < other->GetId(); } }; std::unordered_map, IDeviceCmp>> remoteDevices_; std::unordered_map> virtualInputDevicesAdded_; std::unordered_map remote2VirtualIds_; }; } // namespace Cooperate } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS #endif // COOPERATE_INPUT_DEVICE_MANAGER_H