forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomOperation.cpp
More file actions
91 lines (74 loc) · 2.62 KB
/
CustomOperation.cpp
File metadata and controls
91 lines (74 loc) · 2.62 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/CustomOperation.h>
using MicroOcpp::Ocpp16::CustomOperation;
using MicroOcpp::JsonDoc;
CustomOperation::CustomOperation(const char *operationType,
std::function<std::unique_ptr<JsonDoc> ()> fn_createReq,
std::function<void (JsonObject)> fn_processConf,
std::function<bool (const char*, const char*, JsonObject)> fn_processErr) :
MemoryManaged("Operation.Custom.", operationType),
operationType{makeString(getMemoryTag(), operationType)},
fn_createReq{fn_createReq},
fn_processConf{fn_processConf},
fn_processErr{fn_processErr} {
}
CustomOperation::CustomOperation(const char *operationType,
std::function<void (JsonObject)> fn_processReq,
std::function<std::unique_ptr<JsonDoc> ()> fn_createConf,
std::function<const char* ()> fn_getErrorCode,
std::function<const char* ()> fn_getErrorDescription,
std::function<std::unique_ptr<JsonDoc> ()> fn_getErrorDetails) :
MemoryManaged("Operation.Custom.", operationType),
operationType{makeString(getMemoryTag(), operationType)},
fn_processReq{fn_processReq},
fn_createConf{fn_createConf},
fn_getErrorCode{fn_getErrorCode},
fn_getErrorDescription{fn_getErrorDescription},
fn_getErrorDetails{fn_getErrorDetails} {
}
CustomOperation::~CustomOperation() {
}
const char* CustomOperation::getOperationType() {
return operationType.c_str();
}
std::unique_ptr<JsonDoc> CustomOperation::createReq() {
return fn_createReq();
}
void CustomOperation::processConf(JsonObject payload) {
return fn_processConf(payload);
}
bool CustomOperation::processErr(const char *code, const char *description, JsonObject details) {
if (fn_processErr) {
return fn_processErr(code, description, details);
}
return true;
}
void CustomOperation::processReq(JsonObject payload) {
return fn_processReq(payload);
}
std::unique_ptr<JsonDoc> CustomOperation::createConf() {
return fn_createConf();
}
const char *CustomOperation::getErrorCode() {
if (fn_getErrorCode) {
return fn_getErrorCode();
} else {
return nullptr;
}
}
const char *CustomOperation::getErrorDescription() {
if (fn_getErrorDescription) {
return fn_getErrorDescription();
} else {
return "";
}
}
std::unique_ptr<JsonDoc> CustomOperation::getErrorDetails() {
if (fn_getErrorDetails) {
return fn_getErrorDetails();
} else {
return createEmptyDocument();
}
}