Merge develop into main (#312)
- Move various settings to `/data/settings` and `/sdcard/settings` - Fix for `Gui` and `Statusbar` errors on startup (LVGL start) - Implement Development service settings as properties file - Rename `service::findManifestId()` to `service::findManifestById()` - Renamed various classes like `BootProperties` to `BootSettings` - Renamed `settings.properties` to `system.properties`. Code was moved to `settings` namespace/folder - `DevelopmentSettings` is now in `settings` namespace/folder (moved from service)
This commit is contained in:
committed by
GitHub
parent
5dfc6d70da
commit
5cc5b50694
@@ -1,7 +1,7 @@
|
||||
#include "Tactility/service/ServiceRegistration.h"
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
#include "Tactility/service/ServiceInstance.h"
|
||||
#include "Tactility/service/ServiceManifest.h"
|
||||
#include <Tactility/service/ServiceInstance.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
|
||||
#include <Tactility/Mutex.h>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace tt::service {
|
||||
|
||||
#define TAG "service_registry"
|
||||
constexpr auto* TAG = "ServiceRegistry";
|
||||
|
||||
typedef std::unordered_map<std::string, std::shared_ptr<const ServiceManifest>> ManifestMap;
|
||||
typedef std::unordered_map<std::string, std::shared_ptr<ServiceInstance>> ServiceInstanceMap;
|
||||
@@ -44,7 +44,7 @@ void addService(const ServiceManifest& manifest, bool autoStart) {
|
||||
addService(std::make_shared<const ServiceManifest>(manifest), autoStart);
|
||||
}
|
||||
|
||||
std::shared_ptr<const ServiceManifest> _Nullable findManifestId(const std::string& id) {
|
||||
std::shared_ptr<const ServiceManifest> _Nullable findManifestById(const std::string& id) {
|
||||
manifest_mutex.lock();
|
||||
auto iterator = service_manifest_map.find(id);
|
||||
auto manifest = iterator != service_manifest_map.end() ? iterator->second : nullptr;
|
||||
@@ -63,7 +63,7 @@ static std::shared_ptr<ServiceInstance> _Nullable findServiceInstanceById(const
|
||||
// TODO: Return proper error/status instead of BOOL?
|
||||
bool startService(const std::string& id) {
|
||||
TT_LOG_I(TAG, "Starting %s", id.c_str());
|
||||
auto manifest = findManifestId(id);
|
||||
auto manifest = findManifestById(id);
|
||||
if (manifest == nullptr) {
|
||||
TT_LOG_E(TAG, "manifest not found for service %s", id.c_str());
|
||||
return false;
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "Tactility/service/development/DevelopmentService.h"
|
||||
#include <Tactility/service/development/DevelopmentService.h>
|
||||
|
||||
#include "Tactility/network/HttpdReq.h"
|
||||
#include "Tactility/network/Url.h"
|
||||
#include "Tactility/TactilityHeadless.h"
|
||||
#include "Tactility/service/ServiceManifest.h"
|
||||
#include "Tactility/service/ServiceRegistration.h"
|
||||
#include "Tactility/service/wifi/Wifi.h"
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/app/AppRegistration.h>
|
||||
#include <Tactility/app/ElfApp.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/network/HttpdReq.h>
|
||||
#include <Tactility/network/Url.h>
|
||||
#include <Tactility/service/development/DevelopmentSettings.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
#include <Tactility/TactilityHeadless.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <esp_wifi.h>
|
||||
#include <ranges>
|
||||
#include <sstream>
|
||||
#include <Tactility/Preferences.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/app/ElfApp.h>
|
||||
#include <Tactility/app/AppRegistration.h>
|
||||
#include <Tactility/file/File.h>
|
||||
|
||||
namespace tt::service::development {
|
||||
|
||||
@@ -39,7 +39,7 @@ void DevelopmentService::onStart(ServiceContext& service) {
|
||||
[this](kernel::SystemEvent) { onNetworkDisconnected(); }
|
||||
);
|
||||
|
||||
setEnabled(isEnabledOnStart());
|
||||
setEnabled(shouldEnableOnBoot());
|
||||
}
|
||||
|
||||
void DevelopmentService::onStop(ServiceContext& service) {
|
||||
@@ -76,18 +76,6 @@ bool DevelopmentService::isEnabled() const {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
bool DevelopmentService::isEnabledOnStart() const {
|
||||
Preferences preferences = Preferences(manifest.id.c_str());
|
||||
bool enabled_on_boot = false;
|
||||
preferences.optBool("enabledOnBoot", enabled_on_boot);
|
||||
return enabled_on_boot;
|
||||
}
|
||||
|
||||
void DevelopmentService::setEnabledOnStart(bool enabled) {
|
||||
Preferences preferences = Preferences(manifest.id.c_str());
|
||||
preferences.putBool("enabledOnBoot", enabled);
|
||||
}
|
||||
|
||||
// region Enable/disable
|
||||
|
||||
void DevelopmentService::startServer() {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/service/development/DevelopmentSettings.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace tt::service::development {
|
||||
|
||||
constexpr auto* TAG = "DevSettings";
|
||||
constexpr auto* SETTINGS_FILE = "/data/settings/development.properties";
|
||||
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
|
||||
|
||||
struct DevelopmentSettings {
|
||||
bool enableOnBoot;
|
||||
};
|
||||
|
||||
static bool load(DevelopmentSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!map.contains(SETTINGS_KEY_ENABLE_ON_BOOT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto enable_on_boot_string = map[SETTINGS_KEY_ENABLE_ON_BOOT];
|
||||
settings.enableOnBoot = (enable_on_boot_string == "true");
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool save(const DevelopmentSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
map[SETTINGS_KEY_ENABLE_ON_BOOT] = settings.enableOnBoot ? "true" : "false";
|
||||
return file::savePropertiesFile(SETTINGS_FILE, map);
|
||||
}
|
||||
|
||||
void setEnableOnBoot(bool enable) {
|
||||
DevelopmentSettings properties { .enableOnBoot = enable };
|
||||
if (!save(properties)) {
|
||||
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
bool shouldEnableOnBoot() {
|
||||
DevelopmentSettings settings;
|
||||
if (!load(settings)) {
|
||||
return false;
|
||||
}
|
||||
return settings.enableOnBoot;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -15,7 +15,7 @@ namespace tt::service::wifi::settings {
|
||||
|
||||
constexpr auto* TAG = "WifiApSettings";
|
||||
|
||||
constexpr auto* AP_SETTINGS_FORMAT = "/data/service/Wifi/{}.ap.properties";
|
||||
constexpr auto* AP_SETTINGS_FORMAT = "/data/settings/{}.ap.properties";
|
||||
|
||||
constexpr auto* AP_PROPERTIES_KEY_SSID = "ssid";
|
||||
constexpr auto* AP_PROPERTIES_KEY_PASSWORD = "password";
|
||||
|
||||
@@ -78,9 +78,9 @@ static void importWifiAp(const std::string& filePath) {
|
||||
}
|
||||
|
||||
static void importWifiApSettings(std::shared_ptr<hal::sdcard::SdCardDevice> sdcard) {
|
||||
// auto lock = sdcard->getLock()->asScopedLock();
|
||||
// lock.lock();
|
||||
auto path = sdcard->getMountPath();
|
||||
auto lock = sdcard->getLock()->asScopedLock();
|
||||
lock.lock();
|
||||
auto path = file::getChildPath(sdcard->getMountPath(), "settings");
|
||||
|
||||
std::vector<dirent> dirent_list;
|
||||
if (file::scandir(path, dirent_list, [](const dirent* entry) {
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
namespace tt::service::wifi::settings {
|
||||
|
||||
constexpr auto* TAG = "WifiSettings";
|
||||
constexpr auto* SETTINGS_FILE = "/data/service/Wifi/wifi.properties";
|
||||
constexpr auto* SETTINGS_FILE = "/data/settings/wifi.properties";
|
||||
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
|
||||
|
||||
struct WifiProperties {
|
||||
struct WifiSettings {
|
||||
bool enableOnBoot;
|
||||
};
|
||||
|
||||
static bool load(WifiProperties& properties) {
|
||||
static bool load(WifiSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
|
||||
return false;
|
||||
@@ -26,29 +26,29 @@ static bool load(WifiProperties& properties) {
|
||||
}
|
||||
|
||||
auto enable_on_boot_string = map[SETTINGS_KEY_ENABLE_ON_BOOT];
|
||||
properties.enableOnBoot = (enable_on_boot_string == "true");
|
||||
settings.enableOnBoot = (enable_on_boot_string == "true");
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool save(const WifiProperties& properties) {
|
||||
static bool save(const WifiSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
map[SETTINGS_KEY_ENABLE_ON_BOOT] = properties.enableOnBoot ? "true" : "false";
|
||||
map[SETTINGS_KEY_ENABLE_ON_BOOT] = settings.enableOnBoot ? "true" : "false";
|
||||
return file::savePropertiesFile(SETTINGS_FILE, map);
|
||||
}
|
||||
|
||||
void setEnableOnBoot(bool enable) {
|
||||
WifiProperties properties { .enableOnBoot = enable };
|
||||
if (!save(properties)) {
|
||||
WifiSettings settings { .enableOnBoot = enable };
|
||||
if (!save(settings)) {
|
||||
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
bool shouldEnableOnBoot() {
|
||||
WifiProperties properties;
|
||||
if (!load(properties)) {
|
||||
WifiSettings settings;
|
||||
if (!load(settings)) {
|
||||
return false;
|
||||
}
|
||||
return properties.enableOnBoot;
|
||||
return settings.enableOnBoot;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user