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
+97
View File
@@ -0,0 +1,97 @@
#pragma once
#include "Tactility/app/AppContext.h"
#include <Tactility/Bundle.h>
#include <Tactility/Mutex.h>
#include <string>
// Forward declarations
typedef struct _lv_obj_t lv_obj_t;
namespace tt::app {
// Forward declarations
class AppContext;
enum class Result;
class App {
private:
Mutex mutex;
struct ResultHolder {
Result result;
std::unique_ptr<Bundle> resultData;
explicit ResultHolder(Result result) : result(result), resultData(nullptr) {}
ResultHolder(Result result, std::unique_ptr<Bundle> resultData) :
result(result),
resultData(std::move(resultData)) {}
};
std::unique_ptr<ResultHolder> resultHolder;
public:
App() = default;
virtual ~App() = default;
virtual void onCreate(AppContext& appContext) {}
virtual void onDestroy(AppContext& appContext) {}
virtual void onShow(AppContext& appContext, lv_obj_t* parent) {}
virtual void onHide(AppContext& appContext) {}
virtual void onResult(AppContext& appContext, Result result, std::unique_ptr<Bundle> _Nullable resultData) {}
Mutex& getMutex() { return mutex; }
bool hasResult() const { return resultHolder != nullptr; }
void setResult(Result result, std::unique_ptr<Bundle> resultData = nullptr) {
auto lockable = getMutex().scoped();
lockable->lock(portMAX_DELAY);
resultHolder = std::make_unique<ResultHolder>(result, std::move(resultData));
}
/**
* Used by system to extract the result data when this application is finished.
* Note that this removes the data from the class!
*/
bool moveResult(Result& outResult, std::unique_ptr<Bundle>& outBundle) {
auto lockable = getMutex().scoped();
lockable->lock(portMAX_DELAY);
if (resultHolder != nullptr) {
outResult = resultHolder->result;
outBundle = std::move(resultHolder->resultData);
resultHolder = nullptr;
return true;
} else {
return false;
}
}
};
template<typename T>
std::shared_ptr<App> create() { return std::shared_ptr<T>(new T); }
/**
* @brief Start an app
* @param[in] id application name or id
* @param[in] parameters optional parameters to pass onto the application
*/
void start(const std::string& id, std::shared_ptr<const Bundle> _Nullable parameters = nullptr);
/** @brief Stop the currently showing app. Show the previous app if any app was still running. */
void stop();
/** @return the currently running app context (it is only ever null before the splash screen is shown) */
std::shared_ptr<app::AppContext> _Nullable getCurrentAppContext();
/** @return the currently running app (it is only ever null before the splash screen is shown) */
std::shared_ptr<app::App> _Nullable getCurrentApp();
}
@@ -0,0 +1,101 @@
#pragma once
#include <Tactility/Bundle.h>
#include <memory>
namespace tt::app {
// Forward declarations
class App;
class Paths;
struct AppManifest;
enum class Result;
typedef union {
struct {
bool showStatusbar : 1;
};
unsigned char flags;
} Flags;
/**
* The public representation of an application instance.
* @warning Do not store references or pointers to these! You can retrieve them via the service registry.
*/
class AppContext {
protected:
virtual ~AppContext() = default;
public:
virtual const AppManifest& getManifest() const = 0;
virtual std::shared_ptr<const Bundle> getParameters() const = 0;
virtual std::unique_ptr<Paths> getPaths() const = 0;
virtual std::shared_ptr<App> getApp() const = 0;
};
class Paths {
public:
Paths() = default;
virtual ~Paths() = default;
/**
* Returns the directory path for the data location for an app.
* 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 an app.
* 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 an app.
* 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 apps (system/boot/settings type).
*/
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;
};
}
@@ -0,0 +1,88 @@
#pragma once
#include "Tactility/app/ManifestRegistry.h"
#include <Tactility/CoreDefines.h>
#include <Tactility/Bundle.h>
#include <string>
// Forward declarations
typedef struct _lv_obj_t lv_obj_t;
namespace tt::app {
class App;
class AppContext;
/** Application types */
enum class Type {
/** Boot screen, shown before desktop is launched. */
Boot,
/** A launcher app sits at the root of the app stack after the boot splash is finished */
Launcher,
/** Apps that generally aren't started from the desktop (e.g. image viewer) */
Hidden,
/** Standard apps, provided by the system. */
System,
/** The apps that are launched/shown by the Settings app. The Settings app itself is of type AppTypeSystem. */
Settings,
/** User-provided apps. */
User
};
/** Result status code for application result callback. */
enum class Result {
Ok = 0U,
Cancelled = 1U,
Error = 2U
};
class Location {
private:
std::string path;
Location() = default;
explicit Location(const std::string& path) : path(path) {}
public:
static Location internal() { return {}; }
static Location external(const std::string& path) {
return Location(path);
}
bool isInternal() const { return path.empty(); }
bool isExternal() const { return !path.empty(); }
const std::string& getPath() const { return path; }
};
typedef std::shared_ptr<App>(*CreateApp)();
struct AppManifest {
/** The identifier by which the app is launched by the system and other apps. */
std::string id = {};
/** The user-readable name of the app. Used in UI. */
std::string name = {};
/** Optional icon. */
std::string icon = {};
/** App type affects launch behaviour. */
Type type = Type::User;
/** Where the app is located */
Location location = Location::internal();
/** Create the instance of the app */
CreateApp createApp = nullptr;
};
struct {
bool operator()(const std::shared_ptr<AppManifest>& left, const std::shared_ptr<AppManifest>& right) const { return left->name < right->name; }
} SortAppManifestByName;
} // namespace
+42
View File
@@ -0,0 +1,42 @@
#pragma once
#include "AppManifest.h"
#ifdef ESP_PLATFORM
namespace tt::app {
typedef void* (*CreateData)();
typedef void (*DestroyData)(void* data);
typedef void (*OnCreate)(void* appContext, void* _Nullable data);
typedef void (*OnDestroy)(void* appContext, void* _Nullable data);
typedef void (*OnShow)(void* appContext, void* _Nullable data, lv_obj_t* parent);
typedef void (*OnHide)(void* appContext, void* _Nullable data);
typedef void (*OnResult)(void* appContext, void* _Nullable data, Result result, Bundle* resultData);
void setElfAppManifest(
const char* name,
const char* _Nullable icon,
CreateData _Nullable createData,
DestroyData _Nullable destroyData,
OnCreate _Nullable onCreate,
OnDestroy _Nullable onDestroy,
OnShow _Nullable onShow,
OnHide _Nullable onHide,
OnResult _Nullable onResult
);
/**
* @return the app ID based on the executable's file path.
*/
std::string getElfAppId(const std::string& filePath);
/**
* @return true when registration was done, false when app was already registered
*/
bool registerElfApp(const std::string& filePath);
std::shared_ptr<App> createElfApp(const std::shared_ptr<AppManifest>& manifest);
}
#endif // ESP_PLATFORM
@@ -0,0 +1,23 @@
#pragma once
#include "App.h"
#include <string>
#include <vector>
namespace tt::app {
struct AppManifest;
/** Register an application with its manifest */
void addApp(const AppManifest& manifest);
/** Find an application manifest by its id
* @param[in] id the manifest id
* @return the application manifest if it was found
*/
_Nullable std::shared_ptr<AppManifest> findAppById(const std::string& id);
/** @return a list of all registered apps. This includes user and system apps. */
std::vector<std::shared_ptr<AppManifest>> getApps();
} // namespace
@@ -0,0 +1,30 @@
#pragma once
#include <Tactility/Bundle.h>
#include <string>
#include <vector>
/**
* Start the app by its ID and provide:
* - a title
* - a text
* - 0, 1 or more buttons
*/
namespace tt::app::alertdialog {
/**
* Show a dialog with the provided title, message and 0, 1 or more buttons.
* @param[in] title the title to show in the toolbar
* @param[in] message the message to display
* @param[in] buttonLabels the buttons to show
*/
void start(const std::string& title, const std::string& message, const std::vector<std::string>& buttonLabels);
/**
* Get the index of the button that the user selected.
*
* @return a value greater than 0 when a selection was done, or -1 when the app was closed clicking one of the selection buttons.
*/
int32_t getResultIndex(const Bundle& bundle);
}
@@ -0,0 +1,12 @@
#pragma once
#include <src/display/lv_display.h>
namespace tt::app::display {
void setBacklightDuty(uint8_t value);
uint8_t getBacklightDuty();
void setRotation(lv_display_rotation_t rotation);
lv_display_rotation_t getRotation();
} // namespace
@@ -0,0 +1,15 @@
#pragma once
#include "app/files/View.h"
#include "app/files/State.h"
#include "app/AppManifest.h"
#include <lvgl.h>
#include <dirent.h>
#include <memory>
namespace tt::app::files {
void start();
} // namespace
@@ -0,0 +1,7 @@
#pragma once
namespace tt::app::imageviewer {
void start(const std::string& file);
};
@@ -0,0 +1,21 @@
#pragma once
#include <Tactility/Bundle.h>
#include <string>
#include <vector>
/**
* Start the app by its ID and provide:
* - a title
* - a text
*/
namespace tt::app::inputdialog {
void start(const std::string& title, const std::string& message, const std::string& prefilled = "");
/**
* @return the text that was in the field when OK was pressed, or otherwise empty string
*/
std::string getResult(const Bundle& bundle);
}
@@ -0,0 +1,26 @@
#pragma once
#include <Tactility/Bundle.h>
#include <string>
#include <vector>
/**
* Start the app by its ID and provide:
* - an optional title
* - 2 or more items
*
* If you provide 0 items, the app will auto-close.
* If you provide 1 item, the app will auto-close with result index 0
*/
namespace tt::app::selectiondialog {
void start(const std::string& title, const std::vector<std::string>& items);
/**
* Get the index of the item that the user selected.
*
* @return a value greater than 0 when a selection was done, or -1 when the app was closed without selecting an item.
*/
int32_t getResultIndex(const Bundle& bundle);
}
@@ -0,0 +1,7 @@
#pragma once
namespace tt::app::textviewer {
void start(const std::string& file);
}
@@ -0,0 +1,7 @@
#pragma once
namespace tt::app::wifimanage {
void start();
} // namespace