Refactored app registration (#362)

`AppManifest` is renamed to `AppRegistration` because it was confusing with the actual app manifest (as in: the properties file).
Instead of passing a pointer, we're now passing the struct by value.
I also moved some files around in `TactilityC/`.
This commit is contained in:
Ken Van Hoeylandt 2025-10-05 21:02:34 +02:00 committed by GitHub
parent 2cb413c3d1
commit 1e4234d895
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 61 additions and 83 deletions

View File

@ -1,9 +1,11 @@
#pragma once #pragma once
#include <tt_bundle.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include "tt_app_manifest.h" #include <lvgl.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -11,6 +13,44 @@ extern "C" {
typedef void* AppHandle; typedef void* AppHandle;
/** Important: These values must map to tt::app::Result values exactly */
typedef enum {
APP_RESULT_OK = 0,
APP_RESULT_CANCELLED = 1,
APP_RESULT_ERROR = 2
} AppResult;
typedef unsigned int AppLaunchId;
/** Important: These function types must map to t::app types exactly */
typedef void* (*AppCreateData)();
typedef void (*AppDestroyData)(void* data);
typedef void (*AppOnCreate)(AppHandle app, void* _Nullable data);
typedef void (*AppOnDestroy)(AppHandle app, void* _Nullable data);
typedef void (*AppOnShow)(AppHandle app, void* _Nullable data, lv_obj_t* parent);
typedef void (*AppOnHide)(AppHandle app, void* _Nullable data);
typedef void (*AppOnResult)(AppHandle app, void* _Nullable data, AppLaunchId launchId, AppResult result, BundleHandle resultData);
typedef struct {
/** The application can allocate data to re-use later (e.g. struct with state) */
AppCreateData _Nullable createData;
/** If createData is specified, this one must be specified too */
AppDestroyData _Nullable destroyData;
/** Called when the app is launched (started) */
AppOnCreate _Nullable onCreate;
/** Called when the app is exited (stopped) */
AppOnDestroy _Nullable onDestroy;
/** Called when the app is about to be shown to the user (app becomes visible) */
AppOnShow _Nullable onShow;
/** Called when the app is about to be invisible to the user (e.g. other app was launched by this app, and this app goes to the background) */
AppOnHide _Nullable onHide;
/** Called when the app receives a result after launching another app */
AppOnResult _Nullable onResult;
} AppRegistration;
/** This is used to register the manifest of an external app. */
void tt_app_register(const AppRegistration app);
/** @return the bundle that belongs to this application, or null if it wasn't started with parameters. */ /** @return the bundle that belongs to this application, or null if it wasn't started with parameters. */
BundleHandle _Nullable tt_app_get_parameters(AppHandle handle); BundleHandle _Nullable tt_app_get_parameters(AppHandle handle);

View File

@ -1,52 +0,0 @@
#pragma once
#include "tt_bundle.h"
#include <lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Important: These values must map to tt::app::Result values exactly */
typedef enum {
APP_RESULT_OK = 0,
APP_RESULT_CANCELLED = 1,
APP_RESULT_ERROR = 2
} AppResult;
typedef void* AppHandle;
typedef unsigned int AppLaunchId;
/** Important: These function types must map to t::app types exactly */
typedef void* (*AppCreateData)();
typedef void (*AppDestroyData)(void* data);
typedef void (*AppOnCreate)(AppHandle app, void* _Nullable data);
typedef void (*AppOnDestroy)(AppHandle app, void* _Nullable data);
typedef void (*AppOnShow)(AppHandle app, void* _Nullable data, lv_obj_t* parent);
typedef void (*AppOnHide)(AppHandle app, void* _Nullable data);
typedef void (*AppOnResult)(AppHandle app, void* _Nullable data, AppLaunchId launchId, AppResult result, BundleHandle resultData);
typedef struct {
/** The application can allocate data to re-use later (e.g. struct with state) */
AppCreateData _Nullable createData;
/** If createData is specified, this one must be specified too */
AppDestroyData _Nullable destroyData;
/** Called when the app is launched (started) */
AppOnCreate _Nullable onCreate;
/** Called when the app is exited (stopped) */
AppOnDestroy _Nullable onDestroy;
/** Called when the app is about to be shown to the user (app becomes visible) */
AppOnShow _Nullable onShow;
/** Called when the app is about to be invisible to the user (e.g. other app was launched by this app, and this app goes to the background) */
AppOnHide _Nullable onHide;
/** Called when the app receives a result after launching another app */
AppOnResult _Nullable onResult;
} ExternalAppManifest;
/** This is used to register the manifest of an external app. */
void tt_app_register(const ExternalAppManifest* manifest);
#ifdef __cplusplus
}
#endif

View File

@ -2,6 +2,7 @@
#include <Tactility/app/App.h> #include <Tactility/app/App.h>
#include <Tactility/app/AppPaths.h> #include <Tactility/app/AppPaths.h>
#include <Tactility/app/AppContext.h> #include <Tactility/app/AppContext.h>
#include <Tactility/app/ElfApp.h>
#include <Tactility/file/FileLock.h> #include <Tactility/file/FileLock.h>
extern "C" { extern "C" {
@ -10,6 +11,25 @@ constexpr auto* TAG = "tt_app";
#define HANDLE_AS_APP_CONTEXT(handle) ((tt::app::AppContext*)(handle)) #define HANDLE_AS_APP_CONTEXT(handle) ((tt::app::AppContext*)(handle))
void tt_app_register(
const AppRegistration appRegistration
) {
#ifdef ESP_PLATFORM
assert((appRegistration.createData == nullptr) == (appRegistration.destroyData == nullptr));
tt::app::setElfAppParameters(
appRegistration.createData,
appRegistration.destroyData,
appRegistration.onCreate,
appRegistration.onDestroy,
appRegistration.onShow,
appRegistration.onHide,
reinterpret_cast<tt::app::OnResult>(appRegistration.onResult)
);
#else
tt_crash("TactilityC is not intended for PC/Simulator");
#endif
}
BundleHandle _Nullable tt_app_get_parameters(AppHandle handle) { BundleHandle _Nullable tt_app_get_parameters(AppHandle handle) {
return (BundleHandle)HANDLE_AS_APP_CONTEXT(handle)->getParameters().get(); return (BundleHandle)HANDLE_AS_APP_CONTEXT(handle)->getParameters().get();
} }

View File

@ -1,29 +0,0 @@
#include "tt_app_manifest.h"
#include <Tactility/Check.h>
#include <Tactility/app/ElfApp.h>
extern "C" {
constexpr auto TAG = "tt_app";
void tt_app_register(
const ExternalAppManifest* manifest
) {
#ifdef ESP_PLATFORM
assert((manifest->createData == nullptr) == (manifest->destroyData == nullptr));
tt::app::setElfAppParameters(
manifest->createData,
manifest->destroyData,
manifest->onCreate,
manifest->onDestroy,
manifest->onShow,
manifest->onHide,
reinterpret_cast<tt::app::OnResult>(manifest->onResult)
);
#else
tt_crash("TactilityC is not intended for PC/Simulator");
#endif
}
}

View File

@ -2,7 +2,6 @@
#include "tt_app.h" #include "tt_app.h"
#include "tt_app_alertdialog.h" #include "tt_app_alertdialog.h"
#include "tt_app_manifest.h"
#include "tt_app_selectiondialog.h" #include "tt_app_selectiondialog.h"
#include "tt_bundle.h" #include "tt_bundle.h"
#include "tt_file.h" #include "tt_file.h"