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 VIRTUAL_MOUSE_BUILDER_H
17 #define VIRTUAL_MOUSE_BUILDER_H
18 
19 #include <memory>
20 
21 #include <nlohmann/json.hpp>
22 
23 #include "virtual_device_builder.h"
24 
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28 class VirtualMouseBuilder final : public VirtualDeviceBuilder {
29 public:
30     VirtualMouseBuilder();
31     ~VirtualMouseBuilder() = default;
32     DISALLOW_COPY_AND_MOVE(VirtualMouseBuilder);
33 
34     static std::string GetDeviceName();
35     static void ShowUsage();
36     static void Mount();
37     static void Unmount();
38     static void Clone();
39     static void Monitor();
40     static void Act(int32_t argc, char *argv[]);
41 
42 private:
43     static void ReadActions(const char *path);
44     static void ReadModel(const nlohmann::json &model, int32_t level);
45     static void ReadDownAction();
46     static void ReadMoveAction(int32_t argc, char *argv[]);
47     static void ReadMoveToAction(int32_t argc, char *argv[]);
48     static void ReadDragToAction(int32_t argc, char *argv[]);
49     static void ReadUpAction();
50     static void ReadScrollAction();
51     static void ReadAction(const nlohmann::json &model);
52     static void HandleDown(const nlohmann::json &model);
53     static void HandleMove(const nlohmann::json &model);
54     static void HandleUp(const nlohmann::json &model);
55     static void HandleScroll(const nlohmann::json &model);
56     static void HandleWait(const nlohmann::json &model);
57     static void ReadRawInput(const char *path);
58     static void ReadRawModel(const nlohmann::json &model, int32_t level);
59     static void ReadRawData(const nlohmann::json &model);
60 
61     using InterfaceParameterLess = void(*)();
62     using InterfaceParameterOne = void(*)(const char*);
63     using InterfaceParameterTwo = void(*)(int32_t, char**);
64     inline static std::map<const char, InterfaceParameterLess> ruleMouseActions_ {
65         { 'd', &ReadDownAction }, { 'u', &ReadUpAction }, { 's', &ReadScrollAction }
66     };
67     inline static std::map<const char, InterfaceParameterOne> readMouseActions_ {
68         { 'f', &ReadActions }, { 'r', &ReadRawInput}
69     };
70     inline static std::map<const char, InterfaceParameterTwo>  moveMouseActions_{
71         { 'm', &ReadMoveAction }, { 'M', &ReadMoveToAction }, { 'D', &ReadDragToAction }
72     };
73 };
74 } // namespace DeviceStatus
75 } // namespace Msdp
76 } // namespace OHOS
77 #endif // VIRTUAL_MOUSE_BUILDER_H