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