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
44 lines (35 loc) · 1.29 KB
/
ClearCache.cpp
File metadata and controls
44 lines (35 loc) · 1.29 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/ClearCache.h>
#include <MicroOcpp/Core/FilesystemUtils.h>
#include <MicroOcpp/Debug.h>
using MicroOcpp::Ocpp16::ClearCache;
using MicroOcpp::JsonDoc;
ClearCache::ClearCache(std::shared_ptr<FilesystemAdapter> filesystem) : MemoryManaged("v16.Operation.", "ClearCache"), filesystem(filesystem) {
}
const char* ClearCache::getOperationType(){
return "ClearCache";
}
void ClearCache::processReq(JsonObject payload) {
MO_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<JsonDoc> ClearCache::createConf(){
auto doc = makeJsonDoc(getMemoryTag(), 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;
}