Skip to content

Commit

Permalink
refactor: Refactor handleJson function parameters in NetworkManager code
Browse files Browse the repository at this point in the history
- stop passing JsonVariant by ref
  • Loading branch information
ZanzyTHEbar committed Apr 6, 2024
1 parent 2541372 commit 46e6513
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NetworkManager/examples/customHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void setupServer() {
// made to /api/customJson
async_server.server.addHandler(new AsyncCallbackJsonWebHandler(
"/api/customJson",
[&](AsyncWebServerRequest* request, JsonVariant& json) {
[&](AsyncWebServerRequest* request, JsonVariant json) {
JsonDocument doc;
doc["hello"] = "world";
doc["number"] = 42;
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager/examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void setupServer() {

async_server.server.addHandler(new AsyncCallbackJsonWebHandler(
"/api/customJson",
[&](AsyncWebServerRequest* request, JsonVariant& json) {
[&](AsyncWebServerRequest* request, JsonVariant json) {
JsonDocument doc;
doc["hello"] = "world";
doc["number"] = 42;
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager/include/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BaseAPI : public API_Utilities {
void save(AsyncWebServerRequest* request);
void rssi(AsyncWebServerRequest* request);

void handleJson(AsyncWebServerRequest* request, JsonVariant& jsonData);
void handleJson(AsyncWebServerRequest* request, JsonVariant jsonData);

using route_method = void (BaseAPI::*)(AsyncWebServerRequest*);
using route_t = std::unordered_map<std::string, route_method>;
Expand Down
3 changes: 1 addition & 2 deletions NetworkManager/src/api/base_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ void BaseAPI::setWiFiTXPower(AsyncWebServerRequest* request) {
}
}

void BaseAPI::handleJson(AsyncWebServerRequest* request,
JsonVariant& jsonData) {
void BaseAPI::handleJson(AsyncWebServerRequest* request, JsonVariant jsonData) {
switch (_networkMethodsMap_enum[request->method()]) {
case POST: {
auto jsonObj = jsonData.as<JsonObject>();
Expand Down
4 changes: 2 additions & 2 deletions NetworkManager/src/api/rest_api_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

APIServer::APIServer(ProjectConfig& configManager, AsyncServer_t& async_server,
AsyncOTA* async_ota)
: BaseAPI(configManager), async_ota(nullptr), async_server(async_server) {
: BaseAPI(configManager), async_server(async_server), async_ota(nullptr) {
if (async_ota != nullptr) {
this->async_ota = async_ota;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ void APIServer::begin() {

async_server.server.addHandler(new AsyncCallbackJsonWebHandler(
json_url.c_str(),
[&](AsyncWebServerRequest* request, JsonVariant& json) {
[&](AsyncWebServerRequest* request, JsonVariant json) {
handleJson(request, json);
}));

Expand Down
4 changes: 2 additions & 2 deletions NetworkManager/wokwi.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[wokwi]
version = 1
elf = ".pio/build/esp32s3_debug/EasyNetworkManager-v5.4.0-esp32s3_debug-1b133b5-main.elf"
firmware = ".pio/build/esp32s3_debug/EasyNetworkManager-v5.4.0-esp32s3_debug-1b133b5-main.bin"
elf = ".pio/build/esp32s3_debug/EasyNetworkManager-v5.4.1-esp32s3_debug-2541372-main.elf"
firmware = ".pio/build/esp32s3_debug/EasyNetworkManager-v5.4.1-esp32s3_debug-2541372-main.bin"
[[net.forward]]
from = "localhost:8180"
to = "target:80"

0 comments on commit 46e6513

Please sign in to comment.