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 INPUT_DISPLAY_BIND_HELPER_H 17 #define INPUT_DISPLAY_BIND_HELPER_H 18 19 #include <list> 20 #include <set> 21 22 #include "window_info.h" 23 24 namespace OHOS { 25 namespace MMI { 26 class BindInfo { 27 public: 28 int32_t GetInputDeviceId() const; 29 std::string GetInputNodeName() const; 30 std::string GetInputDeviceName() const; 31 int32_t GetDisplayId() const; 32 std::string GetDisplayName() const; 33 bool IsUnbind() const; 34 bool InputDeviceNotBind() const; 35 bool DisplayNotBind() const; 36 bool AddInputDevice(int32_t deviceId, const std::string &nodeName, const std::string &deviceName); 37 void RemoveInputDevice(); 38 bool AddDisplay(int32_t id, const std::string &name); 39 void RemoveDisplay(); 40 std::string GetDesc() const; 41 friend bool operator < (const BindInfo &l, const BindInfo &r); 42 friend std::ostream &operator << (std::ostream &os, const BindInfo &r); 43 friend std::istream &operator >> (std::istream &is, BindInfo &r); 44 45 private: 46 int32_t inputDeviceId_ { -1 }; 47 std::string inputNodeName_; 48 std::string inputDeviceName_; 49 int32_t displayId_ { -1 }; 50 std::string displayName_; 51 }; 52 class BindInfos { 53 public: 54 bool Add(const BindInfo &info); 55 void UnbindInputDevice(int32_t deviceId); 56 void UnbindDisplay(int32_t displayId); 57 BindInfo GetUnbindInputDevice(const std::string &displayName); 58 BindInfo GetUnbindDisplay(const std::string &inputDeviceName); 59 std::string GetDisplayNameByInputDevice(const std::string &name) const; 60 int32_t GetBindDisplayIdByInputDevice(int32_t inputDeviceId) const; 61 std::string GetBindDisplayNameByInputDevice(int32_t inputDeviceId) const; 62 std::string GetInputDeviceByDisplayName(const std::string &name) const; 63 std::string GetDesc() const; 64 const std::list<BindInfo> &GetInfos() const; 65 friend std::ostream &operator << (std::ostream &os, const BindInfos &r); 66 friend std::istream &operator >> (std::istream &is, BindInfos &r); 67 68 private: 69 BindInfo GetUnbindInputDevice(); 70 BindInfo GetUnbindDisplay(); 71 std::list<BindInfo> infos_; 72 }; 73 class InputDisplayBindHelper { 74 public: 75 InputDisplayBindHelper(const std::string bindCfgFile); 76 std::string GetBindDisplayNameByInputDevice(int32_t inputDeviceId) const; 77 void AddInputDevice(int32_t id, const std::string &name, const std::string &sysUid); 78 void RemoveInputDevice(int32_t id); 79 bool IsDisplayAdd(int32_t id, const std::string &name); 80 std::set<std::pair<uint64_t, std::string>> GetDisplayIdNames() const; 81 void AddDisplay(int32_t id, const std::string &name); 82 void AddLocalDisplay(int32_t id, const std::string &name); 83 void RemoveDisplay(int32_t id); 84 void Load(); 85 std::string Dumps() const; 86 void Store(); 87 int32_t GetDisplayBindInfo(DisplayBindInfos &infos); 88 int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); 89 90 std::string GetInputDeviceById(int32_t id); 91 std::string GetInputNodeNameByCfg(int32_t id); 92 std::string GetContent(const std::string &fileName); 93 std::string GetInputNode(const std::string &inputNodeName); 94 95 private: 96 const std::string fileName_; 97 std::shared_ptr<BindInfos> infos_; 98 std::shared_ptr<BindInfos> configFileInfos_; 99 }; 100 } // namespace MMI 101 } // namespace OHOS 102 #endif // INPUT_DISPLAY_BIND_HELPER_H 103