refactor app code (#93)
This commit is contained in:
committed by
GitHub
parent
a312bd5527
commit
d7b151ab88
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/App.h"
|
||||
#include "app/Manifest.h"
|
||||
#include "Bundle.h"
|
||||
#include "Mutex.h"
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
typedef enum {
|
||||
StateInitial, // App is being activated in loader
|
||||
StateStarted, // App is in memory
|
||||
StateShowing, // App view is created
|
||||
StateHiding, // App view is destroyed
|
||||
StateStopped // App is not in memory
|
||||
} State;
|
||||
|
||||
/**
|
||||
* Thread-safe app instance.
|
||||
*/
|
||||
class AppInstance : public App {
|
||||
|
||||
private:
|
||||
|
||||
Mutex mutex = Mutex(MutexTypeNormal);
|
||||
const Manifest& manifest;
|
||||
State state = StateInitial;
|
||||
Flags flags = { .showStatusbar = true };
|
||||
/** @brief Optional parameters to start the app with
|
||||
* When these are stored in the app struct, the struct takes ownership.
|
||||
* Do not mutate after app creation.
|
||||
*/
|
||||
tt::Bundle parameters;
|
||||
/** @brief @brief Contextual data related to the running app's instance
|
||||
* The app can attach its data to this.
|
||||
* The lifecycle is determined by the on_start and on_stop methods in the AppManifest.
|
||||
* These manifest methods can optionally allocate/free data that is attached here.
|
||||
*/
|
||||
void* _Nullable data = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
AppInstance(const Manifest& manifest) :
|
||||
manifest(manifest) {}
|
||||
|
||||
AppInstance(const Manifest& manifest, const Bundle& parameters) :
|
||||
manifest(manifest),
|
||||
parameters(parameters) {}
|
||||
|
||||
~AppInstance() {}
|
||||
|
||||
void setState(State state);
|
||||
State getState() const;
|
||||
|
||||
const Manifest& getManifest() const;
|
||||
|
||||
Flags getFlags() const;
|
||||
void setFlags(Flags flags);
|
||||
|
||||
_Nullable void* getData() const;
|
||||
void setData(void* data);
|
||||
|
||||
const Bundle& getParameters() const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/Manifest.h"
|
||||
#include "app/AppInstance.h"
|
||||
#include "MessageQueue.h"
|
||||
#include "Pubsub.h"
|
||||
#include "Thread.h"
|
||||
#include "service/gui/ViewPort.h"
|
||||
#include "service/loader/Loader.h"
|
||||
#include <stack>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@@ -108,8 +110,7 @@ struct Loader {
|
||||
PubSub* pubsub_external;
|
||||
MessageQueue queue = MessageQueue(1, sizeof(LoaderMessage));
|
||||
Mutex* mutex;
|
||||
int8_t app_stack_index;
|
||||
app::App app_stack[APP_STACK_SIZE];
|
||||
std::stack<app::AppInstance*> app_stack;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user