Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved startup sequence #20

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions tactility/src/tactility.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,36 @@

#define TAG "tactility"

// System services
// region System services

extern const ServiceManifest gui_service;
extern const ServiceManifest loader_service;

// System apps
static const ServiceManifest* const system_services[] = {
&gui_service,
&loader_service // depends on gui service
};

// endregion

// region System apps

extern const AppManifest desktop_app;
extern const AppManifest system_info_app;

static const AppManifest* const system_apps[] = {
&desktop_app,
&system_info_app
};

// endregion

static void register_system_apps() {
TT_LOG_I(TAG, "Registering default apps");
tt_app_manifest_registry_add(&desktop_app);
tt_app_manifest_registry_add(&system_info_app);
int app_count = sizeof(system_apps) / sizeof(AppManifest*);
for (int i = 0; i < app_count; ++i) {
tt_app_manifest_registry_add(system_apps[i]);
}
}

static void register_user_apps(const AppManifest* const apps[TT_CONFIG_APPS_LIMIT]) {
Expand All @@ -34,16 +52,13 @@ static void register_user_apps(const AppManifest* const apps[TT_CONFIG_APPS_LIMI
}
}

static void register_system_services() {
TT_LOG_I(TAG, "Registering system services");
tt_service_registry_add(&gui_service);
tt_service_registry_add(&loader_service);
}

static void start_system_services() {
TT_LOG_I(TAG, "Starting system services");
tt_service_registry_start(gui_service.id);
tt_service_registry_start(loader_service.id);
static void register_and_start_system_services() {
TT_LOG_I(TAG, "Registering and starting system services");
int app_count = sizeof(system_services) / sizeof(ServiceManifest *);
for (int i = 0; i < app_count; ++i) {
tt_service_registry_add(system_services[i]);
tt_check(tt_service_registry_start(system_services[i]->id));
}
}

static void register_and_start_user_services(const ServiceManifest* const services[TT_CONFIG_SERVICES_LIMIT]) {
Expand All @@ -52,7 +67,7 @@ static void register_and_start_user_services(const ServiceManifest* const servic
const ServiceManifest* manifest = services[i];
if (manifest != NULL) {
tt_service_registry_add(manifest);
tt_service_registry_start(manifest->id);
tt_check(tt_service_registry_start(manifest->id));
} else {
// reached end of list
break;
Expand All @@ -68,21 +83,22 @@ TT_UNUSED void tt_init(const Config* config) {

tt_hardware_init(config->hardware);

// Register all apps
register_system_services();
// Note: the order of starting apps and services is critical!
// System services are registered first so they can be used by the apps
register_and_start_system_services();
// Then we register system apps. They are not used/started yet.
register_system_apps();
// TODO: move this after start_system_services, but desktop must subscribe to app registry events first.
register_user_apps(config->apps);

// Start all services
start_system_services();
// Then we register and start user services. They are started after system app
// registration just in case they want to figure out which system apps are installed.
register_and_start_user_services(config->services);
// Now we register the user apps, as they might rely on the user services.
register_user_apps(config->apps);

TT_LOG_I(TAG, "tt_init starting desktop app");
loader_start_app(desktop_app.id, true, NULL);

if (config->auto_start_app_id) {
TT_LOG_I(TAG, "tt_init aut-starting %s", config->auto_start_app_id);
TT_LOG_I(TAG, "tt_init auto-starting %s", config->auto_start_app_id);
loader_start_app(config->auto_start_app_id, true, NULL);
}

Expand Down
Loading