supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
debug
command_processor.h
1
/*
2
Copyright (C) AC SOFTWARE SP. Z O.O.
3
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
*/
18
19
#ifndef SRC_SUPLA_DEBUG_COMMAND_PROCESSOR_H_
20
#define SRC_SUPLA_DEBUG_COMMAND_PROCESSOR_H_
21
22
#include <stddef.h>
23
#include <stdint.h>
24
25
#if SUPLA_TEST
26
#include <supla-common/proto.h>
27
#endif
28
29
#include <supla/debug/debug_config.h>
30
31
class
SuplaDeviceClass
;
32
33
namespace
Supla {
34
namespace
Debug {
35
36
class
ResponseWriter
{
37
public
:
38
virtual
~ResponseWriter
() =
default
;
39
virtual
void
write(
const
char
*text) = 0;
40
};
41
42
class
CommandProcessor {
43
public
:
44
explicit
CommandProcessor(
SuplaDeviceClass
*device);
45
46
#if SUPLA_TEST
47
using
TestCalcfgHandler = int (*)(
void
*context,
48
TSD_DeviceCalCfgRequest
*request,
49
TDS_DeviceCalCfgResult
*result);
50
CommandProcessor(
SuplaDeviceClass
*device,
51
TestCalcfgHandler testCalcfgHandler,
52
void
*testCalcfgContext);
53
#endif
54
55
bool
processLine(
const
char
*line,
ResponseWriter
*writer);
56
57
private
:
58
struct
Command;
59
60
bool
parseCommand(
const
char
*json, Command *command);
61
void
processCommand(
const
Command &command,
ResponseWriter
*writer);
62
void
processDirectCommandJson(
const
char
*line,
ResponseWriter
*writer);
63
64
void
sendError(
ResponseWriter
*writer,
const
char
*error);
65
void
sendDone(
ResponseWriter
*writer,
bool
ok);
66
void
sendText(
ResponseWriter
*writer,
const
char
*text);
67
void
sendJsonString(
ResponseWriter
*writer,
68
const
char
*prefix,
69
const
char
*value,
70
const
char
*suffix);
71
72
uint32_t nextSessionId();
73
74
SuplaDeviceClass
*device =
nullptr
;
75
uint32_t sessionCounter = 1;
76
#if SUPLA_TEST
77
TestCalcfgHandler testCalcfgHandler =
nullptr
;
78
void
*testCalcfgContext =
nullptr
;
79
#endif
80
};
81
82
}
// namespace Debug
83
}
// namespace Supla
84
85
#endif
// SRC_SUPLA_DEBUG_COMMAND_PROCESSOR_H_
SuplaDeviceClass
Definition
SuplaDevice.h:177
Supla::Debug::ResponseWriter
Definition
command_processor.h:36
TDS_DeviceCalCfgResult
Definition
proto.h:2603
TSD_DeviceCalCfgRequest
Definition
proto.h:2593
Generated by
1.17.0