Skip to content

Commit ce07a78

Browse files
committed
Optimize string assignments and enable more warnings
1 parent 1e1e5fa commit ce07a78

File tree

7 files changed

+43
-21
lines changed

7 files changed

+43
-21
lines changed

include/config/Config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ namespace OpenShock::Config {
7171
bool RemoveWiFiCredentials(uint8_t id);
7272
bool ClearWiFiCredentials();
7373
bool GetWiFiHostname(std::string& out);
74-
bool SetWiFiHostname(std::string_view hostname);
74+
bool SetWiFiHostname(std::string hostname);
7575

7676
bool GetBackendDomain(std::string& out);
77-
bool SetBackendDomain(std::string_view domain);
77+
bool SetBackendDomain(std::string domain);
7878
bool HasBackendAuthToken();
7979
bool GetBackendAuthToken(std::string& out);
80-
bool SetBackendAuthToken(std::string_view token);
80+
bool SetBackendAuthToken(std::string token);
8181
bool ClearBackendAuthToken();
8282

8383
bool GetSerialInputConfigEchoEnabled(bool& out);

platformio.ini

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,36 @@
1212
platform = espressif32 @ 6.12.0
1313
board = az-delivery-devkit-v4 ; Overridden per board
1414
framework = arduino
15+
16+
; Most warnings here are commented out because the compiler detects warnings outside own code, if we can disable external files for warnings that would be amazing!
1517
build_flags =
1618
-std=c++2a
1719
-std=gnu++2a
1820
-Wall
1921
-Wextra
20-
;-Wpedantic ; This can't be enabled yet because it screams about "ISO C++ prohibits anonymous structs in C code"
22+
;-Wpedantic
23+
;-Wcast-align
24+
;-Wcast-qual
25+
;-Wctor-dtor-privacy
26+
-Wdisabled-optimization
27+
-Wformat=2
28+
-Winit-self
29+
-Wlogical-op
30+
;-Wmissing-declarations
31+
-Wmissing-include-dirs
32+
;-Wnoexcept
33+
;-Wold-style-cast
34+
;-Woverloaded-virtual
35+
;-Wredundant-decls
36+
;-Wshadow
37+
;-Wsign-conversion
38+
;-Wsign-promo
39+
;-Wstrict-null-sentinel
40+
;-Wstrict-overflow=5
41+
-Wswitch-default
42+
;-Wundef
43+
;-Werror
44+
-Wno-unused
2145
-Wno-unknown-pragmas
2246
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=256
2347
build_unflags =

src/GatewayConnectionManager.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,12 @@ AccountLinkResultCode GatewayConnectionManager::Link(std::string_view linkCode)
126126
return AccountLinkResultCode::InternalError;
127127
}
128128

129-
std::string_view authToken = response.data.authToken;
130-
131-
if (authToken.empty()) {
129+
if (response.data.authToken.empty()) {
132130
OS_LOGE(TAG, "Received empty auth token");
133131
return AccountLinkResultCode::InternalError;
134132
}
135133

136-
if (!Config::SetBackendAuthToken(authToken)) {
134+
if (!Config::SetBackendAuthToken(std::move(response.data.authToken))) {
137135
OS_LOGE(TAG, "Failed to save auth token");
138136
return AccountLinkResultCode::InternalError;
139137
}
@@ -168,7 +166,7 @@ bool GatewayConnectionManager::SendMessageBIN(tcb::span<const uint8_t> data)
168166
return s_wsClient->sendMessageBIN(data);
169167
}
170168

171-
bool FetchHubInfo(std::string_view authToken)
169+
bool FetchHubInfo(std::string authToken)
172170
{
173171
// TODO: this function is very slow, should be optimized!
174172
if ((s_flags & FLAG_HAS_IP) == 0) {
@@ -179,7 +177,7 @@ bool FetchHubInfo(std::string_view authToken)
179177
return false;
180178
}
181179

182-
auto response = HTTP::JsonAPI::GetHubInfo(authToken);
180+
auto response = HTTP::JsonAPI::GetHubInfo(std::move(authToken));
183181

184182
if (response.code == 401) {
185183
OS_LOGD(TAG, "Auth token is invalid, waiting 5 minutes before checking again");
@@ -243,7 +241,7 @@ bool StartConnectingToLCG()
243241
return false;
244242
}
245243

246-
auto response = HTTP::JsonAPI::AssignLcg(authToken);
244+
auto response = HTTP::JsonAPI::AssignLcg(std::move(authToken));
247245

248246
if (response.code == 401) {
249247
OS_LOGD(TAG, "Auth token is invalid, waiting 5 minutes before retrying");
@@ -285,7 +283,7 @@ void GatewayConnectionManager::Update()
285283
}
286284

287285
// Fetch hub info
288-
if (!FetchHubInfo(authToken.c_str())) {
286+
if (!FetchHubInfo(std::move(authToken))) {
289287
return;
290288
}
291289

src/config/Config.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,11 @@ bool Config::GetWiFiHostname(std::string& out)
575575
return true;
576576
}
577577

578-
bool Config::SetWiFiHostname(std::string_view hostname)
578+
bool Config::SetWiFiHostname(std::string hostname)
579579
{
580580
CONFIG_LOCK_WRITE(false);
581581

582-
_configData.wifi.hostname = std::string(hostname);
582+
_configData.wifi.hostname = std::move(hostname);
583583

584584
return _trySaveConfig();
585585
}
@@ -593,11 +593,11 @@ bool Config::GetBackendDomain(std::string& out)
593593
return true;
594594
}
595595

596-
bool Config::SetBackendDomain(std::string_view domain)
596+
bool Config::SetBackendDomain(std::string domain)
597597
{
598598
CONFIG_LOCK_WRITE(false);
599599

600-
_configData.backend.domain = std::string(domain);
600+
_configData.backend.domain = std::move(domain);
601601
return _trySaveConfig();
602602
}
603603

@@ -617,11 +617,11 @@ bool Config::GetBackendAuthToken(std::string& out)
617617
return true;
618618
}
619619

620-
bool Config::SetBackendAuthToken(std::string_view token)
620+
bool Config::SetBackendAuthToken(std::string token)
621621
{
622622
CONFIG_LOCK_WRITE(false);
623623

624-
_configData.backend.authToken = std::string(token);
624+
_configData.backend.authToken = std::move(token);
625625
return _trySaveConfig();
626626
}
627627

src/serial/command_handlers/authtoken.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void _handleAuthtokenCommand(std::string_view arg, bool isAutomated) {
2626

2727
// If we have some other kind of request fault just set it anyway, we probably arent connected to a network
2828

29-
bool result = OpenShock::Config::SetBackendAuthToken(arg);
29+
bool result = OpenShock::Config::SetBackendAuthToken(std::string(arg));
3030

3131
if (result) {
3232
SERPR_SUCCESS("Saved config");

src/serial/command_handlers/domain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void _handleDomainCommand(std::string_view arg, bool isAutomated) {
4949

5050
OS_LOGI(TAG, "Successfully connected to \"%.*s\", version: %s, commit: %s, current time: %s", arg.length(), arg.data(), resp.data.version.c_str(), resp.data.commit.c_str(), resp.data.currentTime.c_str());
5151

52-
bool result = OpenShock::Config::SetBackendDomain(arg);
52+
bool result = OpenShock::Config::SetBackendDomain(std::string(arg));
5353

5454
if (!result) {
5555
SERPR_ERROR("Failed to save config");

src/serial/command_handlers/hostname.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void _handleHostnameCommand(std::string_view arg, bool isAutomated) {
2020
return;
2121
}
2222

23-
bool result = OpenShock::Config::SetWiFiHostname(arg);
23+
bool result = OpenShock::Config::SetWiFiHostname(std::string(arg));
2424
if (result) {
2525
SERPR_SUCCESS("Saved config, restarting...");
2626
esp_restart();

0 commit comments

Comments
 (0)