-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasycomm-command-callback-handler.h
54 lines (47 loc) · 2.25 KB
/
easycomm-command-callback-handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include "easycomm-parser.h"
typedef void (*EasycommCommandCallback)(const EasycommData *, void *);
/**
* Callback registry.
* Each entry describes command-id to callback mapping.
* NULL-callback entries are allowed but skipped.
*/
typedef struct EasycommCommandsCallback
{
EasycommCommandCallback registry[EasycommIdsCount];
} EasycommCommandsCallback;
/**
* Constructs a default callback registry with dummy callbacks for the respective easycomm standard.
* @param registry the callback registry to construct
* @param parser_standard describes which commands shall be registered to a dummy callback
*/
void easycommCommandsCallback(EasycommCommandsCallback *registry, EasycommParserStandard parser_standard);
/**
* Same as \see easycommCommandsCallback(EasycommCommandsCallback *, EasycommParserStandard) but with custom default callback.
* @param registry \see easycommCommandsCallback(EasycommCommandsCallback *, EasycommParserStandard )
* @param parser_standard \see easycommCommandsCallback(EasycommCommandsCallback *, EasycommParserStandard )
* @param custom_default_cb custom default callback
*/
void easycommCommandsCallbackCustomDefaultCb(EasycommCommandsCallback *registry,
EasycommParserStandard parser_standard,
EasycommCommandCallback custom_default_cb);
/**
* Invokes the parser and the resulting callback.
* If the parser fails the EasycommIdInvalid-callback is invoked.
* @param buffer data to parse from: trimmed, no whitespace, null terminated, without "\r" "\n"
* @param registry command-callback registry, NULL entries are allowed but skipped
* @param parser_standard easycomm standard for the parser
* @param custom_data pointer to custom data for the callback
* @return true if a callback was invoked
*/
bool easycommHandleCommand(const char *buffer,
EasycommCommandsCallback *registry,
EasycommParserStandard parser_standard,
void *custom_data);
#ifdef __cplusplus
}
#endif