Project restructuring (fixes macOS builds) (#198)

- Create `Include/` folder for all main projects
- Fix some issues here and there (found while moving things)
- All includes are now in `Tactility/` subfolder and must be included with that prefix. This fixes issues with clashing POSIX headers (e.g. `<semaphore.h>` versus Tactility's `Semaphore.h`)
This commit is contained in:
Ken Van Hoeylandt
2025-02-01 18:13:20 +01:00
committed by GitHub
parent 7856827ecf
commit c87200a80d
350 changed files with 967 additions and 870 deletions
@@ -1,24 +0,0 @@
#pragma once
#include <memory>
namespace tt::service {
// Forward declaration
class ServiceContext;
class Service {
public:
Service() = default;
virtual ~Service() = default;
virtual void onStart(ServiceContext& serviceContext) {}
virtual void onStop(ServiceContext& serviceContext) {}
};
template<typename T>
std::shared_ptr<Service> create() { return std::shared_ptr<T>(new T); }
}
@@ -1,91 +0,0 @@
#pragma once
#include "Mutex.h"
#include "ServiceManifest.h"
#include <memory>
namespace tt::service {
class Paths;
/**
* The public representation of a service instance.
* @warning Do not store references or pointers to these! You can retrieve them via the Loader service.
*/
class ServiceContext {
protected:
virtual ~ServiceContext() = default;
public:
/** @return a reference ot the service's manifest */
virtual const service::ServiceManifest& getManifest() const = 0;
/** Retrieve the paths that are relevant to this service */
virtual std::unique_ptr<Paths> getPaths() const = 0;
};
class Paths {
public:
Paths() = default;
virtual ~Paths() = default;
/**
* Returns the directory path for the data location for a service.
* The data directory is intended to survive OS upgrades.
* The path will not end with a "/".
*/
virtual std::string getDataDirectory() const = 0;
/**
* @see getDataDirectory(), but with LVGL prefix.
*/
virtual std::string getDataDirectoryLvgl() const = 0;
/**
* Returns the full path for an entry inside the data location for a service.
* The data directory is intended to survive OS upgrades.
* Configuration data should be stored here.
* @param[in] childPath the path without a "/" prefix
*/
virtual std::string getDataPath(const std::string& childPath) const = 0;
/**
* @see getDataPath(), but with LVGL prefix.
*/
virtual std::string getDataPathLvgl(const std::string& childPath) const = 0;
/**
* Returns the directory path for the system location for a service.
* The system directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* The path will not end with a "/".
* This is mainly used for core services.
*/
virtual std::string getSystemDirectory() const = 0;
/**
* @see getSystemDirectory(), but with LVGL prefix.
*/
virtual std::string getSystemDirectoryLvgl() const = 0;
/**
* Returns the full path for an entry inside the system location for an app.
* The data directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* This is mainly used for core apps (system/boot/settings type).
* @param[in] childPath the path without a "/" prefix
*/
virtual std::string getSystemPath(const std::string& childPath) const = 0;
/**
* @see getSystemPath(), but with LVGL prefix.
*/
virtual std::string getSystemPathLvgl(const std::string& childPath) const = 0;
};
} // namespace
@@ -1,5 +1,5 @@
#include "service/ServiceInstance.h"
#include "service/ServiceInstancePaths.h"
#include "Tactility/service/ServiceInstance.h"
#include "Tactility/service/ServiceInstancePaths.h"
namespace tt::service {
@@ -1,5 +1,6 @@
#include "service/ServiceInstancePaths.h"
#include "Partitions.h"
#include "Tactility/service/ServiceInstancePaths.h"
#include "Tactility/Partitions.h"
#define LVGL_PATH_PREFIX std::string("A:/")
#ifdef ESP_PLATFORM
@@ -1,22 +0,0 @@
#pragma once
#include "service/Service.h"
#include <string>
namespace tt::service {
// Forward declarations
class ServiceContext;
typedef std::shared_ptr<Service>(*CreateService)();
/** A ledger that describes the main parts of a service. */
struct ServiceManifest {
/** The identifier by which the app is launched by the system and other apps. */
std::string id {};
/** Create the instance of the app */
CreateService createService = nullptr;
};
} // namespace
@@ -1,8 +1,10 @@
#include "ServiceRegistry.h"
#include "Tactility/service/ServiceRegistry.h"
#include "Tactility/service/ServiceInstance.h"
#include "Tactility/service/ServiceManifest.h"
#include <Tactility/Mutex.h>
#include "Mutex.h"
#include "service/ServiceInstance.h"
#include "service/ServiceManifest.h"
#include <string>
#include <unordered_map>
@@ -1,58 +0,0 @@
#pragma once
#include "service/ServiceManifest.h"
#include "service/Service.h"
#include <memory>
namespace tt::service {
/** Register a service.
* @param[in] the service manifest
*/
void addService(std::shared_ptr<const ServiceManifest> manifest, bool autoStart = true);
/** Register a service.
* @param[in] the service manifest
*/
void addService(const ServiceManifest& manifest, bool autoStart = true);
/** Start a service.
* @param[in] the service id as defined in its manifest
* @return true on success
*/
bool startService(const std::string& id);
/** Stop a service.
* @param[in] the service id as defined in its manifest
* @return true on success or false when service wasn't running.
*/
bool stopService(const std::string& id);
/** Find a service manifest by its id.
* @param[in] id the id as defined in the manifest
* @return the matching manifest or nullptr when it wasn't found
*/
std::shared_ptr<const ServiceManifest> _Nullable findManifestId(const std::string& id);
/** Find a ServiceContext by its manifest id.
* @param[in] id the id as defined in the manifest
* @return the service context or nullptr when it wasn't found
*/
std::shared_ptr<ServiceContext> _Nullable findServiceContextById(const std::string& id);
/** Find a Service by its manifest id.
* @param[in] id the id as defined in the manifest
* @return the service context or nullptr when it wasn't found
*/
std::shared_ptr<Service> _Nullable findServiceById(const std::string& id);
/** Find a Service by its manifest id.
* @param[in] id the id as defined in the manifest
* @return the service context or nullptr when it wasn't found
*/
template <typename T>
std::shared_ptr<T> _Nullable findServiceById(const std::string& id) {
return std::static_pointer_cast<T>(findServiceById(id));
}
} // namespace
@@ -1,9 +1,9 @@
#include "Mutex.h"
#include "Timer.h"
#include "Tactility/service/ServiceContext.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/service/ServiceRegistry.h"
#include "service/ServiceContext.h"
#include "TactilityHeadless.h"
#include "service/ServiceRegistry.h"
#include <Tactility/Mutex.h>
#include <Tactility/Timer.h>
#define TAG "sdcard_service"
@@ -1,4 +1,4 @@
#include "./Wifi.h"
#include "Tactility/service/wifi/Wifi.h"
namespace tt::service::wifi {
@@ -1,131 +0,0 @@
#pragma once
#include "PubSub.h"
#include "WifiGlobals.h"
#include "WifiSettings.h"
#include <cstdio>
#include <string>
#include <vector>
#ifdef ESP_PLATFORM
#include "esp_wifi.h"
#include "WifiSettings.h"
#else
#include <cstdint>
// From esp_wifi_types.h in ESP-IDF 5.2
typedef enum {
WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */
WIFI_AUTH_WEP, /**< authenticate mode : WEP */
WIFI_AUTH_WPA_PSK, /**< authenticate mode : WPA_PSK */
WIFI_AUTH_WPA2_PSK, /**< authenticate mode : WPA2_PSK */
WIFI_AUTH_WPA_WPA2_PSK, /**< authenticate mode : WPA_WPA2_PSK */
WIFI_AUTH_ENTERPRISE, /**< authenticate mode : WiFi EAP security */
WIFI_AUTH_WPA2_ENTERPRISE = WIFI_AUTH_ENTERPRISE, /**< authenticate mode : WiFi EAP security */
WIFI_AUTH_WPA3_PSK, /**< authenticate mode : WPA3_PSK */
WIFI_AUTH_WPA2_WPA3_PSK, /**< authenticate mode : WPA2_WPA3_PSK */
WIFI_AUTH_WAPI_PSK, /**< authenticate mode : WAPI_PSK */
WIFI_AUTH_OWE, /**< authenticate mode : OWE */
WIFI_AUTH_WPA3_ENT_192, /**< authenticate mode : WPA3_ENT_SUITE_B_192_BIT */
WIFI_AUTH_WPA3_EXT_PSK, /**< authenticate mode : WPA3_PSK_EXT_KEY */
WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE, /**< authenticate mode: WPA3_PSK + WPA3_PSK_EXT_KEY */
WIFI_AUTH_MAX
} wifi_auth_mode_t;
#endif
namespace tt::service::wifi {
enum class EventType {
/** Radio was turned on */
RadioStateOn,
/** Radio is turning on. */
RadioStateOnPending,
/** Radio is turned off */
RadioStateOff,
/** Radio is turning off */
RadioStateOffPending,
/** Started scanning for access points */
ScanStarted,
/** Finished scanning for access points */ // TODO: 1 second validity
ScanFinished,
Disconnected,
ConnectionPending,
ConnectionSuccess,
ConnectionFailed
};
enum class RadioState {
OnPending,
On,
ConnectionPending,
ConnectionActive,
OffPending,
Off,
};
struct Event {
EventType type;
};
struct ApRecord {
std::string ssid;
int8_t rssi;
int32_t channel;
wifi_auth_mode_t auth_mode;
};
/**
* @brief Get wifi pubsub
* @return PubSub
*/
std::shared_ptr<PubSub> getPubsub();
/** @return Get the current radio state */
RadioState getRadioState();
/** For logging purposes */
const char* radioStateToString(RadioState state);
/**
* @brief Request scanning update. Returns immediately. Results are through pubsub.
*/
void scan();
/** @return true if wifi is actively scanning */
bool isScanning();
/** @return true the ssid name or empty string */
std::string getConnectionTarget();
/** @return the access points from the last scan (if any). It only contains public APs. */
std::vector<ApRecord> getScanResults();
/**
* @brief Overrides the default scan result size of 16.
* @param[in] records the record limit for the scan result (84 bytes per record!)
*/
void setScanRecords(uint16_t records);
/**
* @brief Enable/disable the radio. Ignores input if desired state matches current state.
* @param[in] enabled
*/
void setEnabled(bool enabled);
/**
* @brief Connect to a network. Disconnects any existing connection.
* Returns immediately but runs in the background. Results are through pubsub.
* @param[in] ap
* @param[in] remember whether to save the ap data to the settings upon successful connection
*/
void connect(const settings::WifiApSettings* ap, bool remember);
/** @brief Disconnect from the access point. Doesn't have any effect when not connected. */
void disconnect();
/** @return true if the connection isn't unencrypted. */
bool isConnectionSecure();
/** @return the RSSI value (negative number) or return 1 when not connected. */
int getRssi();
} // namespace
@@ -1,13 +1,14 @@
#ifdef ESP_PLATFORM
#include "Wifi.h"
#include "Tactility/service/wifi/Wifi.h"
#include "TactilityHeadless.h"
#include "Timer.h"
#include "service/ServiceContext.h"
#include "WifiSettings.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/service/ServiceContext.h"
#include "Tactility/service/wifi/WifiSettings.h"
#include "freertos/FreeRTOS.h"
#include <Tactility/Timer.h>
#include <freertos/FreeRTOS.h>
#include <atomic>
#include <cstring>
@@ -1,8 +0,0 @@
#pragma once
#define TT_WIFI_AUTO_CONNECT true // Default setting for new Wi-Fi entries
#define TT_WIFI_SCAN_RECORD_LIMIT 16 // default, can be overridden
#define TT_WIFI_SSID_LIMIT 32 // 32 characters/octets, according to IEEE 802.11-2020 spec
#define TT_WIFI_CREDENTIALS_PASSWORD_LIMIT 64 // 64 characters/octets, according to IEEE 802.11-2020 spec
@@ -1,13 +1,13 @@
#include "Wifi.h"
#include "Tactility/service/wifi/Wifi.h"
#ifndef ESP_PLATFORM
#include "Check.h"
#include "Log.h"
#include "MessageQueue.h"
#include "Mutex.h"
#include "PubSub.h"
#include "service/ServiceContext.h"
#include "Tactility/service/ServiceContext.h"
#include <Tactility/Check.h>
#include <Tactility/Log.h>
#include <Tactility/Mutex.h>
#include <Tactility/PubSub.h>
namespace tt::service::wifi {
@@ -1,4 +1,4 @@
#include "Preferences.h"
#include "Tactility/Preferences.h"
#define WIFI_PREFERENCES_NAMESPACE "wifi"
#define WIFI_PREFERENCES_KEY_ENABLE_ON_BOOT "enable_on_boot"
@@ -1,33 +0,0 @@
#pragma once
#include "WifiGlobals.h"
#include <cstdint>
namespace tt::service::wifi::settings {
/**
* This struct is stored as-is into NVS flash.
*
* The SSID and secret are increased by 1 byte to facilitate string null termination.
* This makes it easier to use the char array as a string in various places.
*/
struct WifiApSettings {
char ssid[TT_WIFI_SSID_LIMIT + 1] = { 0 };
char password[TT_WIFI_CREDENTIALS_PASSWORD_LIMIT + 1] = { 0 };
int32_t channel = 0;
bool auto_connect = true;
};
bool contains(const char* ssid);
bool load(const char* ssid, WifiApSettings* settings);
bool save(const WifiApSettings* settings);
bool remove(const char* ssid);
void setEnableOnBoot(bool enable);
bool shouldEnableOnBoot();
} // namespace
@@ -1,13 +1,14 @@
#ifdef ESP_PLATFORM
#include "WifiGlobals.h"
#include "WifiSettings.h"
#include <cstring>
#include "Tactility/service/wifi/WifiGlobals.h"
#include "Tactility/service/wifi/WifiSettings.h"
#include "nvs_flash.h"
#include "Log.h"
#include "crypt/Hash.h"
#include "crypt/Crypt.h"
#include <Tactility/Log.h>
#include <Tactility/crypt/Hash.h>
#include <Tactility/crypt/Crypt.h>
#include <nvs_flash.h>
#include <cstring>
#define TAG "wifi_settings"
#define TT_NVS_NAMESPACE "wifi_settings" // limited by NVS_KEY_NAME_MAX_SIZE
@@ -1,7 +1,6 @@
#ifndef ESP_PLATFORM
#include "WifiSettings.h"
#include "Log.h"
#include "Tactility/service/wifi/WifiSettings.h"
namespace tt::service::wifi::settings {