refactor app code (#93)

This commit is contained in:
Ken Van Hoeylandt
2024-11-26 22:17:01 +01:00
committed by GitHub
parent a312bd5527
commit d7b151ab88
40 changed files with 367 additions and 439 deletions
+13 -83
View File
@@ -2,98 +2,28 @@
#include "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;
typedef union {
struct {
bool show_statusbar : 1;
bool showStatusbar : 1;
};
unsigned char flags;
} Flags;
class AppInstance {
private:
Mutex mutex = Mutex(MutexTypeNormal);
const Manifest& manifest;
State state = StateInitial;
Flags flags = { .show_statusbar = 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;
/**
* A limited representation of the application instance.
* Do not store references or pointers to these!
*/
class App {
public:
AppInstance(const Manifest& manifest) :
manifest(manifest) {}
AppInstance(const Manifest& manifest, const Bundle& parameters) :
manifest(manifest),
parameters(parameters) {}
void setState(State state);
State getState();
const Manifest& getManifest();
Flags getFlags();
void setFlags(Flags flags);
_Nullable void* getData();
void setData(void* data);
const Bundle& getParameters();
virtual ~App() {};
virtual const Manifest& getManifest() const = 0;
virtual _Nullable void* getData() const = 0;
virtual void setData(void* data) = 0;
virtual const Bundle& getParameters() const = 0;
virtual Flags getFlags() const = 0;
};
/** @brief Create an app
* @param manifest
* @param parameters optional bundle. memory ownership is transferred to App
* @return
*/
[[deprecated("use class")]]
App tt_app_alloc(const Manifest& manifest, const Bundle& parameters);
[[deprecated("use class")]]
void tt_app_free(App app);
[[deprecated("use class")]]
void tt_app_set_state(App app, State state);
[[deprecated("use class")]]
State tt_app_get_state(App app);
[[deprecated("use class")]]
const Manifest& tt_app_get_manifest(App app);
[[deprecated("use class")]]
Flags tt_app_get_flags(App app);
[[deprecated("use class")]]
void tt_app_set_flags(App app, Flags flags);
[[deprecated("use class")]]
void* _Nullable tt_app_get_data(App app);
[[deprecated("use class")]]
void tt_app_set_data(App app, void* data);
[[deprecated("use class")]]
const Bundle& tt_app_get_parameters(App app);
} // namespace
}