Refactor app launching (#174)
- Refactor the way apps work: Instead of a C interface, they are now C++ classes. The main reasoning is that attaching data to an app was cumbersome. Having different implementations for different kinds of apps was cumbersome too. (3 or 4 layers of manifest nesting for the TactilityC project) - External apps are still written in C, but they get a createData/destroyData in their manifest, so: - External apps now have their own manifest. - All functions in the original AppManifest are removed and replaced by a single `createApp` function - External apps now automatically register (each app individually!) when they run the first time. As a side-effect they become visible in the `AppList` app! - Adapted all apps for the new interface. - Adapted all internal logic for these changes (Gui, ViewPort, Loader, AppContext, AppInstance, etc.) - Rewrote parts of Loader to use std::shared_ptr to make the code much safer. - Added a refcount check for the `AppInstance` and `App` at the end of their lifecycle. Show warning if refcount is too high.
This commit is contained in:
committed by
GitHub
parent
2bbd44a8b5
commit
c3bcf93698
@@ -1,105 +1,29 @@
|
||||
#include "tt_app_manifest.h"
|
||||
|
||||
#include <Check.h>
|
||||
#include <Log.h>
|
||||
#include <app/ElfApp.h>
|
||||
#include <app/AppCompatC.h>
|
||||
|
||||
#define TAG "tt_app"
|
||||
|
||||
AppOnStart elfOnStart = nullptr;
|
||||
AppOnStop elfOnStop = nullptr;
|
||||
AppOnShow elfOnShow = nullptr;
|
||||
AppOnHide elfOnHide = nullptr;
|
||||
AppOnResult elfOnResult = nullptr;
|
||||
|
||||
static void onStartWrapper(tt::app::AppContext& context) {
|
||||
if (elfOnStart != nullptr) {
|
||||
TT_LOG_I(TAG, "onStartWrapper");
|
||||
elfOnStart(&context);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "onStartWrapper not set");
|
||||
}
|
||||
}
|
||||
|
||||
static void onStopWrapper(tt::app::AppContext& context) {
|
||||
if (elfOnStop != nullptr) {
|
||||
TT_LOG_I(TAG, "onStopWrapper");
|
||||
elfOnStop(&context);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "onStopWrapper not set");
|
||||
}
|
||||
}
|
||||
|
||||
static void onShowWrapper(tt::app::AppContext& context, lv_obj_t* parent) {
|
||||
if (elfOnShow != nullptr) {
|
||||
TT_LOG_I(TAG, "onShowWrapper");
|
||||
elfOnShow(&context, parent);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "onShowWrapper not set");
|
||||
}
|
||||
}
|
||||
|
||||
static void onHideWrapper(tt::app::AppContext& context) {
|
||||
if (elfOnHide != nullptr) {
|
||||
TT_LOG_I(TAG, "onHideWrapper");
|
||||
elfOnHide(&context);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "onHideWrapper not set");
|
||||
}
|
||||
}
|
||||
|
||||
static void onResultWrapper(tt::app::AppContext& context, tt::app::Result result, const tt::Bundle& resultData) {
|
||||
if (elfOnResult != nullptr) {
|
||||
TT_LOG_I(TAG, "onResultWrapper");
|
||||
Result convertedResult = AppResultError;
|
||||
switch (result) {
|
||||
case tt::app::ResultOk:
|
||||
convertedResult = AppResultOk;
|
||||
break;
|
||||
case tt::app::ResultCancelled:
|
||||
convertedResult = AppResultCancelled;
|
||||
break;
|
||||
case tt::app::ResultError:
|
||||
convertedResult = AppResultError;
|
||||
break;
|
||||
}
|
||||
elfOnResult(&context, convertedResult, (BundleHandle)&resultData);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "onResultWrapper not set");
|
||||
}
|
||||
}
|
||||
|
||||
tt::app::AppManifest manifest = {
|
||||
.id = "ElfWrapperInTactilityC",
|
||||
.name = "",
|
||||
.icon = "",
|
||||
.onStart = onStartWrapper,
|
||||
.onStop = onStopWrapper,
|
||||
.onShow = onShowWrapper,
|
||||
.onHide = onHideWrapper,
|
||||
.onResult = onResultWrapper
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
void tt_set_app_manifest(
|
||||
const char* name,
|
||||
const char* _Nullable icon,
|
||||
AppOnStart onStart,
|
||||
AppOnStop _Nullable onStop,
|
||||
AppOnShow _Nullable onShow,
|
||||
AppOnHide _Nullable onHide,
|
||||
AppOnResult _Nullable onResult
|
||||
void tt_app_register(
|
||||
const ExternalAppManifest* manifest
|
||||
) {
|
||||
#ifdef ESP_PLATFORM
|
||||
manifest.name = name;
|
||||
manifest.icon = icon ? icon : "";
|
||||
elfOnStart = onStart;
|
||||
elfOnStop = onStop;
|
||||
elfOnShow = onShow;
|
||||
elfOnHide = onHide;
|
||||
elfOnResult = onResult;
|
||||
tt::app::setElfAppManifest(manifest);
|
||||
tt_assert((manifest->createData == nullptr) == (manifest->destroyData == nullptr));
|
||||
tt::app::setElfAppManifest(
|
||||
manifest->name,
|
||||
manifest->icon,
|
||||
(tt::app::CreateData)manifest->createData,
|
||||
(tt::app::DestroyData)manifest->destroyData,
|
||||
(tt::app::OnStart)manifest->onStart,
|
||||
(tt::app::OnStop)manifest->onStop,
|
||||
(tt::app::OnShow)manifest->onShow,
|
||||
(tt::app::OnHide)manifest->onHide,
|
||||
(tt::app::OnResult)manifest->onResult
|
||||
);
|
||||
#else
|
||||
tt_crash("TactilityC is intended for PC/Simulator");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user