Improved startup sequence (#20)

* Improved startup sequence

* updated comments/order
This commit is contained in:
Ken Van Hoeylandt 2024-01-27 16:28:48 +01:00 committed by GitHub
parent ccbe6b7ab8
commit a2f0399c9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,18 +7,36 @@
#define TAG "tactility" #define TAG "tactility"
// System services // region System services
extern const ServiceManifest gui_service; extern const ServiceManifest gui_service;
extern const ServiceManifest loader_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 desktop_app;
extern const AppManifest system_info_app; extern const AppManifest system_info_app;
static const AppManifest* const system_apps[] = {
&desktop_app,
&system_info_app
};
// endregion
static void register_system_apps() { static void register_system_apps() {
TT_LOG_I(TAG, "Registering default apps"); TT_LOG_I(TAG, "Registering default apps");
tt_app_manifest_registry_add(&desktop_app); int app_count = sizeof(system_apps) / sizeof(AppManifest*);
tt_app_manifest_registry_add(&system_info_app); 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]) { static void register_user_apps(const AppManifest* const apps[TT_CONFIG_APPS_LIMIT]) {
@ -34,16 +52,13 @@ static void register_user_apps(const AppManifest* const apps[TT_CONFIG_APPS_LIMI
} }
} }
static void register_system_services() { static void register_and_start_system_services() {
TT_LOG_I(TAG, "Registering system services"); TT_LOG_I(TAG, "Registering and starting system services");
tt_service_registry_add(&gui_service); int app_count = sizeof(system_services) / sizeof(ServiceManifest *);
tt_service_registry_add(&loader_service); 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 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_user_services(const ServiceManifest* const services[TT_CONFIG_SERVICES_LIMIT]) { static void register_and_start_user_services(const ServiceManifest* const services[TT_CONFIG_SERVICES_LIMIT]) {
@ -52,7 +67,7 @@ static void register_and_start_user_services(const ServiceManifest* const servic
const ServiceManifest* manifest = services[i]; const ServiceManifest* manifest = services[i];
if (manifest != NULL) { if (manifest != NULL) {
tt_service_registry_add(manifest); tt_service_registry_add(manifest);
tt_service_registry_start(manifest->id); tt_check(tt_service_registry_start(manifest->id));
} else { } else {
// reached end of list // reached end of list
break; break;
@ -68,21 +83,22 @@ TT_UNUSED void tt_init(const Config* config) {
tt_hardware_init(config->hardware); tt_hardware_init(config->hardware);
// Register all apps // Note: the order of starting apps and services is critical!
register_system_services(); // 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(); register_system_apps();
// TODO: move this after start_system_services, but desktop must subscribe to app registry events first. // Then we register and start user services. They are started after system app
register_user_apps(config->apps); // registration just in case they want to figure out which system apps are installed.
// Start all services
start_system_services();
register_and_start_user_services(config->services); 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"); TT_LOG_I(TAG, "tt_init starting desktop app");
loader_start_app(desktop_app.id, true, NULL); loader_start_app(desktop_app.id, true, NULL);
if (config->auto_start_app_id) { 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); loader_start_app(config->auto_start_app_id, true, NULL);
} }