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,
35 using TestChannelValueHandler = int32_t (*)(
36 void *context, TSD_SuplaChannelNewValue *newValue);
37 using TestChannelConfigHandler = uint8_t (*)(
38 void *context, TSD_ChannelConfig *config, bool local);
40 TestCalcfgHandler testCalcfgHandler,
41 void *testCalcfgContext);
43 TestChannelValueHandler testChannelValueHandler,
44 void *testChannelValueContext);
46 TestChannelConfigHandler testChannelConfigHandler,
47 void *testChannelConfigContext);
48#endif
49
50 bool processLine(const char *line, ResponseWriter *writer);
51
52 private:
53 struct Command;
54
55 bool parseCommand(const char *json, Command *command);
56 void processCommand(const Command &command, ResponseWriter *writer);
57 void processDirectCommandJson(const char *line, ResponseWriter *writer);
58
59 void sendError(ResponseWriter *writer, const char *error);
60 void sendDone(ResponseWriter *writer, bool ok);
61 void sendText(ResponseWriter *writer, const char *text);
62 void sendJsonString(ResponseWriter *writer,
63 const char *prefix,
64 const char *value,
65 const char *suffix);
66
67 SuplaDeviceClass *device = nullptr;
68#if SUPLA_TEST
69 TestCalcfgHandler testCalcfgHandler = nullptr;
70 void *testCalcfgContext = nullptr;
71 TestChannelValueHandler testChannelValueHandler = nullptr;
72 void *testChannelValueContext = nullptr;
73 TestChannelConfigHandler testChannelConfigHandler = nullptr;
74 void *testChannelConfigContext = nullptr;
75#endif
76};
77
78} // namespace Debug
79} // namespace Supla
80
81#endif // SRC_SUPLA_DEBUG_COMMAND_PROCESSOR_H_
Definition SuplaDevice.h:167
Definition command_processor.h:27
Definition command_processor.h:21
Definition proto.h:2340
Definition proto.h:3176
Definition proto.h:2330
Definition proto.h:1243