supla-device
Loading...
Searching...
No Matches
command_processor.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_DEBUG_COMMAND_PROCESSOR_H_
5#define SRC_SUPLA_DEBUG_COMMAND_PROCESSOR_H_
6
7#include <stddef.h>
8#include <stdint.h>
9
10#if SUPLA_TEST
11#include <supla-common/proto.h>
12#endif
13
14#include <supla/debug/debug_config.h>
15
17
18namespace Supla {
19namespace Debug {
20
22 public:
23 virtual ~ResponseWriter() = default;
24 virtual void write(const char *text) = 0;
25};
26
28 public:
29 explicit CommandProcessor(SuplaDeviceClass *device);
30
31#if SUPLA_TEST
32 using TestCalcfgHandler = int (*)(void *context,
36 TestCalcfgHandler testCalcfgHandler,
37 void *testCalcfgContext);
38#endif
39
40 bool processLine(const char *line, ResponseWriter *writer);
41
42 private:
43 struct Command;
44
45 bool parseCommand(const char *json, Command *command);
46 void processCommand(const Command &command, ResponseWriter *writer);
47 void processDirectCommandJson(const char *line, ResponseWriter *writer);
48
49 void sendError(ResponseWriter *writer, const char *error);
50 void sendDone(ResponseWriter *writer, bool ok);
51 void sendText(ResponseWriter *writer, const char *text);
52 void sendJsonString(ResponseWriter *writer,
53 const char *prefix,
54 const char *value,
55 const char *suffix);
56
57 uint32_t nextSessionId();
58
59 SuplaDeviceClass *device = nullptr;
60 uint32_t sessionCounter = 1;
61#if SUPLA_TEST
62 TestCalcfgHandler testCalcfgHandler = nullptr;
63 void *testCalcfgContext = nullptr;
64#endif
65};
66
67} // namespace Debug
68} // namespace Supla
69
70#endif // SRC_SUPLA_DEBUG_COMMAND_PROCESSOR_H_
Definition SuplaDevice.h:167
Definition command_processor.h:27
Definition command_processor.h:21
Definition proto.h:2325
Definition proto.h:2315