forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClearCache.cpp
More file actions
43 lines (34 loc) · 1.27 KB
/
Copy pathClearCache.cpp
File metadata and controls
43 lines (34 loc) · 1.27 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
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
#include <ArduinoOcpp/Operations/ClearCache.h>
#include <ArduinoOcpp/Core/FilesystemUtils.h>
#include <ArduinoOcpp/Debug.h>
using ArduinoOcpp::Ocpp16::ClearCache;
ClearCache::ClearCache(std::shared_ptr<FilesystemAdapter> filesystem) : filesystem(filesystem) {
}
const char* ClearCache::getOperationType(){
return "ClearCache";
}
void ClearCache::processReq(JsonObject payload) {
AO_DBG_WARN("Clear transaction log (Authorization Cache not supported)");
if (!filesystem) {
//no persistency - nothing to do
return;
}
success = FilesystemUtils::remove_if(filesystem, [] (const char *fname) -> bool {
return !strncmp(fname, "sd", strlen("sd")) ||
!strncmp(fname, "tx", strlen("tx")) ||
!strncmp(fname, "op", strlen("op"));
});
}
std::unique_ptr<DynamicJsonDocument> ClearCache::createConf(){
auto doc = std::unique_ptr<DynamicJsonDocument>(new DynamicJsonDocument(JSON_OBJECT_SIZE(1)));
JsonObject payload = doc->to<JsonObject>();
if (success) {
payload["status"] = "Accepted"; //"Accepted", because the intended postcondition is true
} else {
payload["status"] = "Rejected";
}
return doc;
}