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