mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps] Apps are not allocated on the heap anymore but in a union hold by
the AppsContainerStorage
This commit is contained in:
@@ -3,11 +3,11 @@ include apps/home/Makefile
|
||||
include apps/on_boarding/Makefile
|
||||
include apps/hardware_test/Makefile
|
||||
include apps/usb/Makefile
|
||||
snapshots =
|
||||
apps =
|
||||
|
||||
# All selected apps are included. Each Makefile below is responsible for setting
|
||||
# the $snapshots variable (name of the snapshot class) and the $snapshot_headers
|
||||
# (path to the snapshot header).
|
||||
# the $apps variable (name of the app class) and the $app_headers
|
||||
# (path to the apps header).
|
||||
$(foreach i,${EPSILON_APPS},$(eval include apps/$(i)/Makefile))
|
||||
|
||||
app_objs += $(addprefix apps/,\
|
||||
@@ -33,14 +33,15 @@ app_objs += $(addprefix apps/,\
|
||||
variable_box_leaf_cell.o\
|
||||
)
|
||||
|
||||
snapshots_declaration = $(foreach i,$(snapshots),$(i) m_snapshot$(subst :,,$(i));)
|
||||
snapshots_construction = $(foreach i,$(snapshots),,m_snapshot$(subst :,,$(i))())
|
||||
snapshots_list = $(foreach i,$(snapshots),,&m_snapshot$(subst :,,$(i)))
|
||||
snapshots_count = $(words $(snapshots))
|
||||
snapshot_includes = $(foreach i,$(snapshot_headers),-include $(i) )
|
||||
snapshots_declaration = $(foreach i,$(apps),$(i)::Snapshot m_snapshot$(subst :,,$(i))Snapshot;)
|
||||
apps_declaration = $(foreach i,$(apps),$(i) m_$(subst :,,$(i));)
|
||||
snapshots_construction = $(foreach i,$(apps),,m_snapshot$(subst :,,$(i))Snapshot())
|
||||
snapshots_list = $(foreach i,$(apps),,&m_snapshot$(subst :,,$(i))Snapshot)
|
||||
snapshots_count = $(words $(apps))
|
||||
snapshot_includes = $(foreach i,$(app_headers),-include $(i) )
|
||||
epsilon_app_names = '$(foreach i,${EPSILON_APPS},"$(i)", )'
|
||||
|
||||
apps/apps_container_storage.o apps/main.o: CXXFLAGS += $(snapshot_includes) -DAPPS_CONTAINER_SNAPSHOT_DECLARATIONS="$(snapshots_declaration)" -DAPPS_CONTAINER_SNAPSHOT_CONSTRUCTORS="$(snapshots_construction)" -DAPPS_CONTAINER_SNAPSHOT_LIST="$(snapshots_list)" -DAPPS_CONTAINER_SNAPSHOT_COUNT=$(snapshots_count) -DEPSILON_APPS_NAMES=$(epsilon_app_names)
|
||||
apps/apps_container_storage.o apps/main.o: CXXFLAGS += $(snapshot_includes) -DAPPS_CONTAINER_APPS_DECLARATION="$(apps_declaration)" -DAPPS_CONTAINER_SNAPSHOT_DECLARATIONS="$(snapshots_declaration)" -DAPPS_CONTAINER_SNAPSHOT_CONSTRUCTORS="$(snapshots_construction)" -DAPPS_CONTAINER_SNAPSHOT_LIST="$(snapshots_list)" -DAPPS_CONTAINER_SNAPSHOT_COUNT=$(snapshots_count) -DEPSILON_APPS_NAMES=$(epsilon_app_names)
|
||||
|
||||
|
||||
i18n_files += $(addprefix apps/language_,$(addsuffix .universal.i18n, $(EPSILON_I18N)))
|
||||
|
||||
@@ -13,7 +13,18 @@ public:
|
||||
AppsContainerStorage();
|
||||
int numberOfApps() override;
|
||||
App::Snapshot * appSnapshotAtIndex(int index) override;
|
||||
void * currentAppBuffer() override { return &m_apps; };
|
||||
private:
|
||||
union Apps {
|
||||
public:
|
||||
/* Enforce a trivial constructor and destructor that just leave the memory
|
||||
* unmodified. This way, m_apps can be trivially destructed. */
|
||||
Apps() {};
|
||||
~Apps() {};
|
||||
private:
|
||||
APPS_CONTAINER_APPS_DECLARATION
|
||||
};
|
||||
Apps m_apps;
|
||||
APPS_CONTAINER_SNAPSHOT_DECLARATIONS
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Calculation::App::Snapshot
|
||||
snapshot_headers += apps/calculation/app.h
|
||||
apps += Calculation::App
|
||||
app_headers += apps/calculation/app.h
|
||||
|
||||
app_objs += $(addprefix apps/calculation/,\
|
||||
app.o\
|
||||
|
||||
@@ -23,7 +23,7 @@ const Image * App::Descriptor::icon() {
|
||||
}
|
||||
|
||||
App * App::Snapshot::unpack(Container * container) {
|
||||
return new App(container, this);
|
||||
return new (container->currentAppBuffer()) App(container, this);
|
||||
}
|
||||
|
||||
void App::Snapshot::reset() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Code::App::Snapshot
|
||||
snapshot_headers += apps/code/app.h
|
||||
apps += Code::App
|
||||
app_headers += apps/code/app.h
|
||||
|
||||
app_objs += $(addprefix apps/code/,\
|
||||
app.o\
|
||||
|
||||
@@ -27,7 +27,7 @@ App::Snapshot::Snapshot() :
|
||||
}
|
||||
|
||||
App * App::Snapshot::unpack(Container * container) {
|
||||
return new App(container, this);
|
||||
return new (container->currentAppBuffer()) App(container, this);
|
||||
}
|
||||
|
||||
void App::Snapshot::reset() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Graph::App::Snapshot
|
||||
snapshot_headers += apps/graph/app.h
|
||||
apps += Graph::App
|
||||
app_headers += apps/graph/app.h
|
||||
|
||||
app_objs += $(addprefix apps/graph/,\
|
||||
app.o\
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Probability::App::Snapshot
|
||||
snapshot_headers += apps/probability/app.h
|
||||
apps += Probability::App
|
||||
app_headers += apps/probability/app.h
|
||||
|
||||
app_objs += $(addprefix apps/probability/,\
|
||||
app.o\
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Regression::App::Snapshot
|
||||
snapshot_headers += apps/regression/app.h
|
||||
apps += Regression::App
|
||||
app_headers += apps/regression/app.h
|
||||
|
||||
app_objs += $(addprefix apps/regression/,\
|
||||
app.o\
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Sequence::App::Snapshot
|
||||
snapshot_headers += apps/sequence/app.h
|
||||
apps += Sequence::App
|
||||
app_headers += apps/sequence/app.h
|
||||
|
||||
app_objs += $(addprefix apps/sequence/,\
|
||||
app.o\
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Settings::App::Snapshot
|
||||
snapshot_headers += apps/settings/app.h
|
||||
apps += Settings::App
|
||||
app_headers += apps/settings/app.h
|
||||
|
||||
app_objs += $(addprefix apps/settings/,\
|
||||
app.o\
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Solver::App::Snapshot
|
||||
snapshot_headers += apps/solver/app.h
|
||||
apps += Solver::App
|
||||
app_headers += apps/solver/app.h
|
||||
|
||||
app_objs += $(addprefix apps/solver/,\
|
||||
app.o\
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
snapshots += Statistics::App::Snapshot
|
||||
snapshot_headers += apps/statistics/app.h
|
||||
apps += Statistics::App
|
||||
app_headers += apps/statistics/app.h
|
||||
|
||||
app_objs += $(addprefix apps/statistics/,\
|
||||
app.o\
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
/* tidy clean all dynamically-allocated data */
|
||||
virtual void tidy();
|
||||
};
|
||||
/* The destructor has to be virtual. Otherwise calling a destructor on an
|
||||
* App * pointing to a Derived App would have undefined behaviour. */
|
||||
virtual ~App() = default;
|
||||
constexpr static uint8_t Magic = 0xA8;
|
||||
Snapshot * snapshot();
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
Container(Container&& other) = delete;
|
||||
Container& operator=(const Container& other) = delete;
|
||||
Container& operator=(Container&& other) = delete;
|
||||
virtual void * currentAppBuffer() = 0;
|
||||
virtual void run();
|
||||
App * activeApp();
|
||||
virtual bool dispatchEvent(Ion::Events::Event event) override;
|
||||
|
||||
@@ -18,7 +18,7 @@ const Image * App::Descriptor::icon() {
|
||||
|
||||
void App::Snapshot::pack(App * app) {
|
||||
tidy();
|
||||
delete app;
|
||||
app->~App();
|
||||
}
|
||||
|
||||
void App::Snapshot::reset() {
|
||||
|
||||
Reference in New Issue
Block a user