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
99 lines (81 loc) · 2.79 KB
/
Copy pathCustomOperation.cpp
File metadata and controls
99 lines (81 loc) · 2.79 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
92
93
94
95
96
97
98
99
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
#include <ArduinoOcpp/Operations/CustomOperation.h>
using ArduinoOcpp::Ocpp16::CustomOperation;
CustomOperation::CustomOperation(const char *operationType,
std::function<std::unique_ptr<DynamicJsonDocument> ()> fn_createReq,
std::function<void (JsonObject)> fn_processConf,
std::function<bool (const char*, const char*, JsonObject)> fn_processErr,
std::function<void (StoredOperationHandler*)> fn_initiate,
std::function<bool (StoredOperationHandler*)> fn_restore) :
operationType{operationType},
fn_initiate{fn_initiate},
fn_restore{fn_restore},
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<DynamicJsonDocument> ()> fn_createConf,
std::function<const char* ()> fn_getErrorCode,
std::function<const char* ()> fn_getErrorDescription,
std::function<std::unique_ptr<DynamicJsonDocument> ()> fn_getErrorDetails) :
operationType{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();
}
void CustomOperation::initiate(StoredOperationHandler *opStore) {
if (fn_initiate) {
fn_initiate(opStore);
}
}
bool CustomOperation::restore(StoredOperationHandler *opStore) {
if (fn_restore) {
return fn_restore(opStore);
} else {
return false;
}
}
std::unique_ptr<DynamicJsonDocument> CustomOperation::createReq() {
return fn_createReq();
}
void CustomOperation::processConf(JsonObject payload) {
return fn_processConf(payload);
}
void CustomOperation::processReq(JsonObject payload) {
return fn_processReq(payload);
}
std::unique_ptr<DynamicJsonDocument> 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<DynamicJsonDocument> CustomOperation::getErrorDetails() {
if (fn_getErrorDetails) {
return fn_getErrorDetails();
} else {
return createEmptyDocument();
}
}