From fa54eaa58a70843563ec6e9877a3b575f9b00966 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 26 Jan 2025 00:48:37 +0100 Subject: [PATCH] TactilityC improvements for tt_app_ functions (#192) - Renamed `tt_app_context_*` to tt_app_*` - Renamed `AppContextHandle` to `AppHandle` - Created `tt_app_start()` and `tt_app_start_with_bundle()` --- ExternalApps/HelloWorld/main/Source/main.c | 4 +- .../Source/{tt_app_context.cpp => tt_app.cpp} | 20 +++++---- TactilityC/Source/tt_app.h | 41 +++++++++++++++++++ TactilityC/Source/tt_app_context.h | 31 -------------- TactilityC/Source/tt_app_manifest.h | 12 +++--- TactilityC/Source/tt_init.cpp | 10 ++--- TactilityC/Source/tt_lvgl_toolbar.cpp | 2 +- TactilityC/Source/tt_lvgl_toolbar.h | 4 +- TactilityC/Source/tt_service_loader.cpp | 2 +- TactilityC/Source/tt_service_loader.h | 4 +- 10 files changed, 72 insertions(+), 58 deletions(-) rename TactilityC/Source/{tt_app_context.cpp => tt_app.cpp} (51%) create mode 100644 TactilityC/Source/tt_app.h delete mode 100644 TactilityC/Source/tt_app_context.h diff --git a/ExternalApps/HelloWorld/main/Source/main.c b/ExternalApps/HelloWorld/main/Source/main.c index 70333274..6184c713 100644 --- a/ExternalApps/HelloWorld/main/Source/main.c +++ b/ExternalApps/HelloWorld/main/Source/main.c @@ -5,8 +5,8 @@ * Note: LVGL and Tactility methods need to be exposed manually from TactilityC/Source/tt_init.cpp * Only C is supported for now (C++ symbols fail to link) */ -static void onShow(AppContextHandle context, void* data, lv_obj_t* parent) { - lv_obj_t* toolbar = tt_lvgl_toolbar_create(parent, context); +static void onShow(AppHandle app, void* data, lv_obj_t* parent) { + lv_obj_t* toolbar = tt_lvgl_toolbar_create(parent, app); lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0); lv_obj_t* label = lv_label_create(parent); diff --git a/TactilityC/Source/tt_app_context.cpp b/TactilityC/Source/tt_app.cpp similarity index 51% rename from TactilityC/Source/tt_app_context.cpp rename to TactilityC/Source/tt_app.cpp index 16af1c27..801dd007 100644 --- a/TactilityC/Source/tt_app_context.cpp +++ b/TactilityC/Source/tt_app.cpp @@ -1,26 +1,30 @@ -#include "tt_app_context.h" +#include "tt_app.h" #include #include -struct AppContextDataWrapper { - void* _Nullable data; -}; - extern "C" { #define HANDLE_AS_APP_CONTEXT(handle) ((tt::app::AppContext*)(handle)) -BundleHandle _Nullable tt_app_context_get_parameters(AppContextHandle handle) { +BundleHandle _Nullable tt_app_get_parameters(AppHandle handle) { return (BundleHandle)HANDLE_AS_APP_CONTEXT(handle)->getParameters().get(); } -void tt_app_context_set_result(AppContextHandle handle, Result result, BundleHandle _Nullable bundle) { +void tt_app_set_result(AppHandle handle, Result result, BundleHandle _Nullable bundle) { auto shared_bundle = std::unique_ptr((tt::Bundle*)bundle); HANDLE_AS_APP_CONTEXT(handle)->getApp()->setResult((tt::app::Result)result, std::move(shared_bundle)); } -bool tt_app_context_has_result(AppContextHandle handle) { +bool tt_app_has_result(AppHandle handle) { return HANDLE_AS_APP_CONTEXT(handle)->getApp()->hasResult(); } +void tt_app_start(const char* appId) { + tt::app::start(appId); +} + +void tt_app_start_with_bundle(const char* appId, BundleHandle parameters) { + tt::app::start(appId, std::shared_ptr((tt::Bundle*)parameters)); +} + } \ No newline at end of file diff --git a/TactilityC/Source/tt_app.h b/TactilityC/Source/tt_app.h new file mode 100644 index 00000000..413bdfda --- /dev/null +++ b/TactilityC/Source/tt_app.h @@ -0,0 +1,41 @@ +#pragma once + +#include "tt_app_manifest.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void* AppHandle; + +/** @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); + +/** + * Set the result before closing an app. + * The result and bundle are passed along to the app that launched this app, when this app is closed. + * @param[in] handle the app context handle to set the result for + * @param[in] result the result state to set + * @param[in] bundle the result bundle to set + */ +void tt_app_set_result(AppHandle handle, Result result, BundleHandle _Nullable bundle); + +/** @return true if a result was set for this app context */ +bool tt_app_has_result(AppHandle handle); + +/** + * Start an app by id. + * @param[in] appId the app manifest id + */ +void tt_app_start(const char* appId); + +/** + * Start an app by id and bundle. + * @param[in] appId the app manifest id +* @param[in] parameters the parameters to pass onto the starting app + */ +void tt_app_start_with_bundle(const char* appId, BundleHandle parameters); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/TactilityC/Source/tt_app_context.h b/TactilityC/Source/tt_app_context.h deleted file mode 100644 index 9a9f0284..00000000 --- a/TactilityC/Source/tt_app_context.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "tt_app_manifest.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void* AppContextHandle; - -/** @return the data that was attached to this app context */ -void* _Nullable tt_app_context_get_data(AppContextHandle handle); - -/** @return the bundle that belongs to this application, or null */ -BundleHandle _Nullable tt_app_context_get_parameters(AppContextHandle handle); - -/** - * Set the result before closing an app. - * The result and bundle are passed along to the app that launched this app, when this app is closed. - * @param[in] handle the app context handle to set the result for - * @param[in] result the result state to set - * @param[in] bundle the result bundle to set - */ -void tt_app_context_set_result(AppContextHandle handle, Result result, BundleHandle _Nullable bundle); - -/** @return true if a result was set for this app context */ -bool tt_app_context_has_result(AppContextHandle handle); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/TactilityC/Source/tt_app_manifest.h b/TactilityC/Source/tt_app_manifest.h index 959e5e2b..e783da21 100644 --- a/TactilityC/Source/tt_app_manifest.h +++ b/TactilityC/Source/tt_app_manifest.h @@ -14,16 +14,16 @@ typedef enum { AppResultError = 2 } Result; -typedef void* AppContextHandle; +typedef void* AppHandle; /** Important: These function types must map to t::app types exactly */ typedef void* (*AppCreateData)(); typedef void (*AppDestroyData)(void* data); -typedef void (*AppOnStart)(AppContextHandle app, void* _Nullable data); -typedef void (*AppOnStop)(AppContextHandle app, void* _Nullable data); -typedef void (*AppOnShow)(AppContextHandle app, void* _Nullable data, lv_obj_t* parent); -typedef void (*AppOnHide)(AppContextHandle app, void* _Nullable data); -typedef void (*AppOnResult)(AppContextHandle app, void* _Nullable data, Result result, BundleHandle resultData); +typedef void (*AppOnStart)(AppHandle app, void* _Nullable data); +typedef void (*AppOnStop)(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, Result result, BundleHandle resultData); typedef struct { /** The application's human-readable name */ diff --git a/TactilityC/Source/tt_init.cpp b/TactilityC/Source/tt_init.cpp index efed1a5b..88ad6174 100644 --- a/TactilityC/Source/tt_init.cpp +++ b/TactilityC/Source/tt_init.cpp @@ -2,9 +2,9 @@ #include "elf_symbol.h" -#include "tt_app_context.h" -#include "tt_app_manifest.h" +#include "tt_app.h" #include "tt_app_alertdialog.h" +#include "tt_app_manifest.h" #include "tt_app_selectiondialog.h" #include "tt_bundle.h" #include "tt_hal_i2c.h" @@ -23,9 +23,9 @@ extern "C" { const struct esp_elfsym elf_symbols[] { // Tactility ESP_ELFSYM_EXPORT(tt_app_register), - ESP_ELFSYM_EXPORT(tt_app_context_get_parameters), - ESP_ELFSYM_EXPORT(tt_app_context_set_result), - ESP_ELFSYM_EXPORT(tt_app_context_has_result), + ESP_ELFSYM_EXPORT(tt_app_get_parameters), + ESP_ELFSYM_EXPORT(tt_app_set_result), + ESP_ELFSYM_EXPORT(tt_app_has_result), ESP_ELFSYM_EXPORT(tt_app_selectiondialog_start), ESP_ELFSYM_EXPORT(tt_app_selectiondialog_get_result_index), ESP_ELFSYM_EXPORT(tt_app_alertdialog_start), diff --git a/TactilityC/Source/tt_lvgl_toolbar.cpp b/TactilityC/Source/tt_lvgl_toolbar.cpp index b761ffbb..4bdd5d31 100644 --- a/TactilityC/Source/tt_lvgl_toolbar.cpp +++ b/TactilityC/Source/tt_lvgl_toolbar.cpp @@ -3,7 +3,7 @@ extern "C" { -lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppContextHandle context) { +lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppHandle context) { return tt::lvgl::toolbar_create(parent, *(tt::app::AppContext*)context); } diff --git a/TactilityC/Source/tt_lvgl_toolbar.h b/TactilityC/Source/tt_lvgl_toolbar.h index 65b11904..96543587 100644 --- a/TactilityC/Source/tt_lvgl_toolbar.h +++ b/TactilityC/Source/tt_lvgl_toolbar.h @@ -1,14 +1,14 @@ #pragma once +#include "tt_app.h" #include -#include "tt_app_context.h" #ifdef __cplusplus extern "C" { #endif /** Create a toolbar widget that shows the app name as title */ -lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppContextHandle context); +lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppHandle context); /** Create a toolbar widget with the provided title*/ lv_obj_t* tt_lvgl_toolbar_create_simple(lv_obj_t* parent, const char* title); diff --git a/TactilityC/Source/tt_service_loader.cpp b/TactilityC/Source/tt_service_loader.cpp index f3da55fc..8cb57f12 100644 --- a/TactilityC/Source/tt_service_loader.cpp +++ b/TactilityC/Source/tt_service_loader.cpp @@ -13,7 +13,7 @@ void tt_service_loader_stop_app() { tt::service::loader::stopApp(); } -AppContextHandle tt_service_loader_get_current_app() { +AppHandle tt_service_loader_get_current_app() { return tt::service::loader::getCurrentAppContext().get(); } diff --git a/TactilityC/Source/tt_service_loader.h b/TactilityC/Source/tt_service_loader.h index cbdd0bc6..688a2b68 100644 --- a/TactilityC/Source/tt_service_loader.h +++ b/TactilityC/Source/tt_service_loader.h @@ -1,7 +1,7 @@ #pragma once +#include "tt_app.h" #include "tt_bundle.h" -#include "tt_app_context.h" #ifdef __cplusplus extern "C" { @@ -26,7 +26,7 @@ void tt_service_loader_stop_app(); /** * Get the context handle of the app that is currently shown on the screen. */ -AppContextHandle tt_service_loader_get_current_app(); +AppHandle tt_service_loader_get_current_app(); #ifdef __cplusplus }