• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 COMMANDLINE_H
17 #define COMMANDLINE_H
18 
19 #include <json.h>
20 #include <set>
21 #include <vector>
22 
23 #include "LocalSocket.h"
24 
25 class CommandLine {
26 public:
27     enum class CommandType { SET = 0, GET, ACTION, INVALID };
28 
29     CommandLine(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
30     virtual ~CommandLine();
31     void CheckAndRun();
32     void SetCommandResult(const std::string& type, const Json::Value& resultContent);
33     void SetResultToManager(const std::string& type, const Json::Value& resultContent, const std::string& messageType);
34     void RunAndSendResultToManager();
35     void SendResultToManager();
36     void SendResult();
RunSet()37     virtual void RunSet() {}
38     bool IsArgValid() const;
39     uint8_t ToUint8(std::string str) const;
40     void SetCommandName(std::string command);
41 
42 protected:
43     Json::Value args;
44     const LocalSocket& cliSocket;
45     Json::Value commandResult;
46     Json::Value commandResultToManager;
47     CommandType type;
48     std::string commandName;
49     const std::vector<std::string> liteSupportedLanguages = {"zh-CN", "en-US"};
50     const std::vector<std::string> richSupportedLanguages = {
51         "zh_CN", "zh_HK", "zh_TW", "en_US", "en_GB", "ar_AE", "bg_BG", "bo_CN", "cs_CZ", "da_DK",
52         "de_DE", "el_GR", "en_PH", "es_ES", "es_LA", "fi_FI", "fr_FR", "he_IL", "hi_IN", "hu_HU",
53         "id_ID", "it_IT", "ja_JP", "kk_KZ", "ms_MY", "nl_NL", "no_NO", "pl_PL", "pt_BR", "pt_PT",
54         "ro_RO", "ru_RU", "sr_RS", "sv_SE", "th_TH", "tr_TR", "ug_CN", "uk_UA", "vi_VN"
55     };
56     const std::vector<std::string> LoadDocDevs = {"phone", "tablet", "wearable", "car", "tv", "2in1", "default"};
57     const int maxWidth = 3000;
58     const int minWidth = 50;
59     const int maxDpi = 640;
60     const int minDpi = 120;
61     const int maxKeyVal = 2119;
62     const int minKeyVal = 2000;
63     const int maxActionVal = 2;
64     const int minActionVal = 0;
65     const int maxLoadDocWidth = 3000;
66     const int minLoadDocWidth = 20;
67 
IsSetArgValid()68     virtual bool IsSetArgValid() const
69     {
70         return true;
71     }
IsGetArgValid()72     virtual bool IsGetArgValid() const
73     {
74         return true;
75     }
IsActionArgValid()76     virtual bool IsActionArgValid() const
77     {
78         return true;
79     }
RunGet()80     virtual void RunGet() {}
RunAction()81     virtual void RunAction() {}
82 
83     bool IsBoolType(std::string arg) const;
84     bool IsIntType(std::string arg) const;
85     bool IsOneDigitFloatType(std::string arg, bool allowNegativeNumber) const;
86 
87 private:
88     void Run();
89 };
90 
91 class TouchAndMouseCommand {
92 protected:
93     struct EventParams {
94         double x;
95         double y;
96         int type;
97         int button;
98         int action;
99         int sourceType;
100         int sourceTool;
101         std::set<int> pressedBtnsVec;
102         std::vector<double> axisVec; // 13 is array size
103         std::string name;
104     };
105     void SetEventParams(EventParams& params);
106 };
107 
108 class TouchPressCommand : public CommandLine, public TouchAndMouseCommand {
109 public:
110     TouchPressCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~TouchPressCommand()111     ~TouchPressCommand() override {}
112 
113 protected:
114     void RunAction() override;
115     bool IsActionArgValid() const override;
116 };
117 
118 class TouchMoveCommand : public CommandLine, public TouchAndMouseCommand {
119 public:
120     TouchMoveCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~TouchMoveCommand()121     ~TouchMoveCommand() override {}
122 
123 protected:
124     void RunAction() override;
125     bool IsActionArgValid() const override;
126 };
127 
128 class TouchReleaseCommand : public CommandLine, public TouchAndMouseCommand {
129 public:
130     TouchReleaseCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~TouchReleaseCommand()131     ~TouchReleaseCommand() override {}
132 
133 protected:
134     void RunAction() override;
135 };
136 
137 class MouseWheelCommand : public CommandLine {
138 public:
139     MouseWheelCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~MouseWheelCommand()140     ~MouseWheelCommand() override {}
141 
142 protected:
143     void RunAction() override;
144     bool IsActionArgValid() const override;
145 };
146 
147 class BackClickedCommand : public CommandLine {
148 public:
149     BackClickedCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~BackClickedCommand()150     ~BackClickedCommand() override {}
151 
152 protected:
153     void RunAction() override;
154 };
155 
156 class RestartCommand : public CommandLine {
157 public:
158     RestartCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~RestartCommand()159     ~RestartCommand() override {}
160 
161 protected:
162     void RunAction() override;
163 };
164 
165 class PowerCommand : public CommandLine {
166 public:
167     PowerCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~PowerCommand()168     ~PowerCommand() override {}
169     void RunSet() override;
170 
171 protected:
172     void RunGet() override;
173     bool IsSetArgValid() const override;
174 };
175 
176 class VolumeCommand : public CommandLine {
177 public:
178     VolumeCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~VolumeCommand()179     ~VolumeCommand() override {}
180     void RunSet() override;
181 
182 protected:
183     void RunGet() override;
184     bool IsSetArgValid() const override;
185 };
186 
187 class BarometerCommand : public CommandLine {
188 public:
189     BarometerCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~BarometerCommand()190     ~BarometerCommand() override {}
191     void RunSet() override;
192 
193 protected:
194     void RunGet() override;
195     bool IsSetArgValid() const override;
196 };
197 
198 class ResolutionSwitchCommand : public CommandLine {
199 public:
200     ResolutionSwitchCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~ResolutionSwitchCommand()201     ~ResolutionSwitchCommand() override {}
202     void RunSet() override;
203 
204 protected:
205     bool IsSetArgValid() const override;
206     bool IsIntValValid(const Json::Value& args) const;
207 };
208 
209 class OrientationCommand : public CommandLine {
210 public:
211     OrientationCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~OrientationCommand()212     ~OrientationCommand() override {}
213     void RunSet() override;
214 
215 protected:
216     bool IsSetArgValid() const override;
217 };
218 
219 class ColorModeCommand : public CommandLine {
220 public:
221     ColorModeCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~ColorModeCommand()222     ~ColorModeCommand() override {}
223     void RunSet() override;
224 
225 protected:
226     bool IsSetArgValid() const override;
227 };
228 
229 class LanguageCommand : public CommandLine {
230 public:
231     LanguageCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~LanguageCommand()232     ~LanguageCommand() override {}
233     void RunSet() override;
234 
235 protected:
236     void RunGet() override;
237     bool IsSetArgValid() const override;
238 };
239 
240 class FontSelectCommand : public CommandLine {
241 public:
242     FontSelectCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~FontSelectCommand()243     ~FontSelectCommand() override {}
244     void RunSet() override;
245 
246 protected:
247     bool IsSetArgValid() const override;
248 };
249 
250 class MemoryRefreshCommand : public CommandLine {
251 public:
252     MemoryRefreshCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~MemoryRefreshCommand()253     ~MemoryRefreshCommand() override {}
254     void RunSet() override;
255 
256 protected:
257     bool IsSetArgValid() const override;
258 };
259 
260 class LoadDocumentCommand : public CommandLine {
261 public:
262     LoadDocumentCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~LoadDocumentCommand()263     ~LoadDocumentCommand() override {}
264     void RunSet() override;
265 
266 protected:
267     bool IsSetArgValid() const override;
268     bool IsIntValValid(const Json::Value& previewParam) const;
269     bool IsStrValVailid(const Json::Value& previewParam) const;
270 };
271 
272 class ReloadRuntimePageCommand : public CommandLine {
273 public:
274     ReloadRuntimePageCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~ReloadRuntimePageCommand()275     ~ReloadRuntimePageCommand() override {}
276     void RunSet() override;
277 
278 protected:
279     bool IsSetArgValid() const override;
280 };
281 
282 class CurrentRouterCommand : public CommandLine {
283 public:
284     CurrentRouterCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~CurrentRouterCommand()285     ~CurrentRouterCommand() override {}
286 
287 protected:
288     void RunGet() override;
289 };
290 
291 class LoadContentCommand : public CommandLine {
292 public:
293     LoadContentCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~LoadContentCommand()294     ~LoadContentCommand() override {}
295 
296 protected:
297     void RunGet() override;
298 };
299 
300 class SupportedLanguagesCommand : public CommandLine {
301 public:
302     SupportedLanguagesCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~SupportedLanguagesCommand()303     ~SupportedLanguagesCommand() override {}
304 
305 protected:
306     void RunGet() override;
307 };
308 
309 class LocationCommand : public CommandLine {
310 public:
311     LocationCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~LocationCommand()312     ~LocationCommand() override {}
313     void RunSet() override;
314 
315 protected:
316     void RunGet() override;
317     bool IsSetArgValid() const override;
318 };
319 
320 class DistributedCommunicationsCommand : public CommandLine {
321 public:
322     DistributedCommunicationsCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~DistributedCommunicationsCommand()323     ~DistributedCommunicationsCommand() override {}
324 
325 protected:
326     void RunAction() override;
327     bool IsActionArgValid() const override;
328     std::vector<char> StringToCharVector(std::string str) const;
329 };
330 
331 class KeepScreenOnStateCommand : public CommandLine {
332 public:
333     KeepScreenOnStateCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~KeepScreenOnStateCommand()334     ~KeepScreenOnStateCommand() override {}
335     void RunSet() override;
336 
337 protected:
338     void RunGet() override;
339     bool IsSetArgValid() const override;
340 };
341 
342 class WearingStateCommand : public CommandLine {
343 public:
344     WearingStateCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~WearingStateCommand()345     ~WearingStateCommand() override {}
346     void RunSet() override;
347 
348 protected:
349     void RunGet() override;
350     bool IsSetArgValid() const override;
351 };
352 
353 class BrightnessModeCommand : public CommandLine {
354 public:
355     BrightnessModeCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~BrightnessModeCommand()356     ~BrightnessModeCommand() override {}
357     void RunSet() override;
358 
359 protected:
360     void RunGet() override;
361     bool IsSetArgValid() const override;
362 };
363 
364 class ChargeModeCommand : public CommandLine {
365 public:
366     ChargeModeCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~ChargeModeCommand()367     ~ChargeModeCommand() override {}
368     void RunSet() override;
369 
370 protected:
371     void RunGet() override;
372     bool IsSetArgValid() const override;
373 };
374 
375 class BrightnessCommand : public CommandLine {
376 public:
377     BrightnessCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~BrightnessCommand()378     ~BrightnessCommand() override {}
379     void RunSet() override;
380 
381 protected:
382     void RunGet() override;
383     bool IsSetArgValid() const override;
384 };
385 
386 class HeartRateCommand : public CommandLine {
387 public:
388     HeartRateCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~HeartRateCommand()389     ~HeartRateCommand() override {}
390     void RunSet() override;
391 
392 protected:
393     void RunGet() override;
394     bool IsSetArgValid() const override;
395 };
396 
397 class StepCountCommand : public CommandLine {
398 public:
399     StepCountCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~StepCountCommand()400     ~StepCountCommand() override {}
401     void RunSet() override;
402 
403 protected:
404     void RunGet() override;
405     bool IsSetArgValid() const override;
406 };
407 
408 class ExitCommand : public CommandLine {
409 public:
410     ExitCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~ExitCommand()411     ~ExitCommand() override {}
412 
413 protected:
414     void RunAction() override;
415 };
416 
417 class InspectorJSONTree : public CommandLine {
418 public:
419     InspectorJSONTree(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~InspectorJSONTree()420     ~InspectorJSONTree() override {}
421 
422 protected:
423     void RunAction() override;
424 };
425 
426 class InspectorDefault : public CommandLine {
427 public:
428     InspectorDefault(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~InspectorDefault()429     ~InspectorDefault() override {}
430 
431 protected:
432     void RunAction() override;
433 };
434 
435 class DeviceTypeCommand : public CommandLine {
436 public:
437     DeviceTypeCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~DeviceTypeCommand()438     ~DeviceTypeCommand() override {}
439 
440 protected:
441     void RunSet() override;
442 };
443 
444 class ResolutionCommand : public CommandLine {
445 public:
446     ResolutionCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~ResolutionCommand()447     ~ResolutionCommand() override {}
448 
449 protected:
450     void RunSet() override;
451 };
452 
453 class FastPreviewMsgCommand : public CommandLine {
454 public:
455     FastPreviewMsgCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~FastPreviewMsgCommand()456     ~FastPreviewMsgCommand() override {}
457 
458 protected:
459     void RunGet() override;
460 };
461 
462 class DropFrameCommand : public CommandLine {
463 public:
464     DropFrameCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~DropFrameCommand()465     ~DropFrameCommand() override {}
466     void RunSet() override;
467 
468 protected:
469     bool IsSetArgValid() const override;
470 };
471 
472 class KeyPressCommand : public CommandLine {
473 public:
474     KeyPressCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~KeyPressCommand()475     ~KeyPressCommand() override {}
476 
477 protected:
478     void RunAction() override;
479     bool IsActionArgValid() const override;
480     bool IsImeArgsValid() const;
481     bool IsKeyArgsValid() const;
482 };
483 
484 class PointEventCommand : public CommandLine, public TouchAndMouseCommand {
485 public:
486     PointEventCommand(CommandType commandType, const Json::Value& arg, const LocalSocket& socket);
~PointEventCommand()487     ~PointEventCommand() override {}
488 
489 protected:
490     void RunAction() override;
491     bool IsActionArgValid() const override;
492     bool IsArgsExist() const;
493     bool IsArgsValid() const;
494 };
495 #endif // COMMANDLINE_H
496