created ServiceManifest (#5)

based on AppManifest
This commit is contained in:
Ken Van Hoeylandt
2024-01-05 19:38:39 +01:00
committed by GitHub
parent 3b9986fcef
commit e842e30ab3
39 changed files with 134 additions and 352 deletions
@@ -1,13 +0,0 @@
#pragma once
#include "app_manifest.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const AppManifest desktop_app;
#ifdef __cplusplus
}
#endif
+44 -27
View File
@@ -4,52 +4,66 @@
#include "furi.h"
#include "graphics_i.h"
#include "partitions.h"
#include "apps/services/gui/gui.h"
#include "services/gui/gui.h"
#define TAG "nanobake"
Gui* gui_alloc();
// System services
extern const AppManifest gui_app;
extern const AppManifest loader_app;
// Desktop
extern const AppManifest desktop_app;
extern const ServiceManifest gui_service;
extern const ServiceManifest loader_service;
extern const ServiceManifest desktop_service;
// System apps
extern const AppManifest system_info_app;
void start_service(const AppManifest* _Nonnull manifest, void* _Nullable context) {
UNUSED(context);
FURI_LOG_I(TAG, "Starting service %s", manifest->name);
void start_service(const ServiceManifest* _Nonnull manifest) {
FURI_LOG_I(TAG, "Starting service %s", manifest->id);
furi_check(manifest->on_start, "service must define on_start");
manifest->on_start(NULL);
// TODO: keep track of running services
}
static void register_apps(Config* _Nonnull config) {
FURI_LOG_I(TAG, "Registering core apps");
app_manifest_registry_add(&gui_app);
app_manifest_registry_add(&desktop_app);
app_manifest_registry_add(&loader_app);
static void register_system_apps() {
FURI_LOG_I(TAG, "Registering default apps");
app_manifest_registry_add(&system_info_app);
}
static void register_user_apps(const Config* _Nonnull config) {
FURI_LOG_I(TAG, "Registering user apps");
for (size_t i = 0; i < config->apps_count; i++) {
app_manifest_registry_add(config->apps[i]);
for (size_t i = 0; i < CONFIG_APPS_LIMIT; i++) {
const AppManifest* manifest = config->apps[i];
if (manifest != NULL) {
app_manifest_registry_add(manifest);
} else {
// reached end of list
break;
}
}
}
static void start_services() {
FURI_LOG_I(TAG, "Starting services");
app_manifest_registry_for_each_of_type(AppTypeService, NULL, start_service);
FURI_LOG_I(TAG, "Startup complete");
static void start_system_services() {
FURI_LOG_I(TAG, "Starting system services");
start_service(&gui_service);
start_service(&loader_service);
start_service(&desktop_service);
FURI_LOG_I(TAG, "System services started");
}
static void start_desktop() {
FURI_LOG_I(TAG, "Starting desktop");
desktop_app.on_start(NULL);
FURI_LOG_I(TAG, "Startup complete");
static void start_user_services(const Config* _Nonnull config) {
FURI_LOG_I(TAG, "Starting user services");
for (size_t i = 0; i < CONFIG_SERVICES_LIMIT; i++) {
const ServiceManifest* manifest = config->services[i];
if (manifest != NULL) {
// TODO: keep track of running services
manifest->on_start(NULL);
} else {
// reached end of list
break;
}
}
FURI_LOG_I(TAG, "User services started");
}
__attribute__((unused)) extern void nanobake_start(const Config* _Nonnull config) {
@@ -60,8 +74,11 @@ __attribute__((unused)) extern void nanobake_start(const Config* _Nonnull config
Hardware hardware = nb_hardware_init(config->hardware);
/*NbLvgl lvgl =*/nb_graphics_init(&hardware);
register_apps(config);
// Register all apps
register_system_apps();
register_user_apps(config);
start_services();
start_desktop();
// Start all services
start_system_services();
start_user_services(config);
}
+6 -2
View File
@@ -3,11 +3,15 @@
#include "app_manifest.h"
#include "devices.h"
#include "furi_extra_defines.h"
#include "service_manifest.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CONFIG_APPS_LIMIT 32
#define CONFIG_SERVICES_LIMIT 32
// Forward declarations
typedef void* FuriThreadId;
typedef void (*Bootstrap)();
@@ -26,8 +30,8 @@ typedef struct {
typedef struct {
const HardwareConfig* hardware;
// List of user applications
const size_t apps_count;
const AppManifest* const apps[];
const AppManifest* const apps[CONFIG_APPS_LIMIT];
const ServiceManifest* const services[CONFIG_SERVICES_LIMIT];
} Config;
__attribute__((unused)) extern void nanobake_start(const Config _Nonnull* config);
@@ -1,10 +1,9 @@
#include "desktop.h"
#include "lvgl.h"
#include "check.h"
#include "apps/services/loader/loader.h"
#include "apps/services/gui/gui.h"
#include "apps/services/gui/view_port.h"
#include "app_manifest_registry.h"
#include "check.h"
#include "lvgl.h"
#include "services/gui/gui.h"
#include "services/gui/view_port.h"
#include "services/loader/loader.h"
static void on_open_app(lv_event_t* e) {
lv_event_code_t code = lv_event_get_code(e);
@@ -42,12 +41,8 @@ static void desktop_stop() {
furi_crash("desktop_stop is not implemented");
}
const AppManifest desktop_app = {
const ServiceManifest desktop_service = {
.id = "desktop",
.name = "Desktop",
.icon = NULL,
.type = AppTypeDesktop,
.on_start = &desktop_start,
.on_stop = &desktop_stop,
.on_show = NULL
.on_stop = &desktop_stop
};
@@ -3,7 +3,6 @@
#include "furi_extra_defines.h"
#include "gui_i.h"
#include "log.h"
#include "record.h"
#include "kernel.h"
#define TAG "gui"
@@ -21,7 +20,7 @@ Gui* gui_alloc() {
furi_check(instance != NULL);
instance->thread = furi_thread_alloc_ex(
"gui",
AppStackSizeLarge, // Last known minimum was 2800 for launching desktop
4096, // Last known minimum was 2800 for launching desktop
&gui_main,
NULL
);
@@ -165,14 +164,10 @@ static void gui_stop() {
gui_free(gui);
}
const AppManifest gui_app = {
const ServiceManifest gui_service = {
.id = "gui",
.name = "GUI",
.icon = NULL,
.type = AppTypeService,
.on_start = &gui_start,
.on_stop = &gui_stop,
.on_show = NULL
.on_stop = &gui_stop
};
// endregion
@@ -1,20 +1,18 @@
#pragma once
#include "app_manifest.h"
#include "service_manifest.h"
#include "view_port.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const AppManifest gui_app;
/** Gui layers */
typedef enum {
GuiLayerDesktop, /**< Desktop layer for internal use. Like fullscreen but with status bar */
GuiLayerWindow, /**< Window layer, status bar is shown */
GuiLayerDesktop, /**< Desktop layer for internal use. Like fullscreen but with status bar */
GuiLayerWindow, /**< Window layer, status bar is shown */
GuiLayerFullscreen, /**< Fullscreen layer, no status bar */
GuiLayerMAX /**< Don't use or move, special value */
GuiLayerMAX /**< Don't use or move, special value */
} GuiLayer;
typedef struct Gui Gui;
@@ -1,10 +1,9 @@
#include "check.h"
#include "esp_lvgl_port.h"
#include "gui_i.h"
#include "log.h"
#include "record.h"
#include "esp_lvgl_port.h"
#include "apps/services/gui/widgets/widgets.h"
#include "apps/services/loader/loader.h"
#include "services/gui/widgets/widgets.h"
#include "services/loader/loader.h"
#define TAG "gui"
@@ -1,8 +1,7 @@
#include "apps/services/gui/widgets/widgets.h"
#include "check.h"
#include "esp_lvgl_port.h"
#include "gui.h"
#include "gui_i.h"
#include "services/gui/widgets/widgets.h"
#include "view_port_i.h"
#define TAG "viewport"
@@ -1,7 +1,6 @@
#include "toolbar.h"
#include "record.h"
#include "apps/services/gui/widgets/widgets.h"
#include "apps/services/loader/loader.h"
#include "services/gui/widgets/widgets.h"
#include "services/loader/loader.h"
static void app_toolbar_close(lv_event_t* event) {
loader_stop_app();
@@ -19,7 +18,7 @@ void toolbar(lv_obj_t* parent, lv_coord_t offset_y, const AppManifest* manifest)
lv_obj_t* close_button = lv_btn_create(toolbar);
lv_obj_set_size(close_button, TOOLBAR_HEIGHT - 4, TOOLBAR_HEIGHT - 4);
lv_obj_set_style_no_padding(close_button);
lv_obj_add_event_cb(close_button, &app_toolbar_close,LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(close_button, &app_toolbar_close, LV_EVENT_CLICKED, NULL);
lv_obj_t* close_button_image = lv_img_create(close_button);
lv_img_set_src(close_button_image, LV_SYMBOL_CLOSE);
lv_obj_align(close_button_image, LV_ALIGN_CENTER, 0, 0);
@@ -1,12 +1,13 @@
#include "loader.h"
#include "app_i.h"
#include "app_manifest.h"
#include "app_manifest_registry.h"
#include "loader_i.h"
#include <sys/cdefs.h>
#include "esp_heap_caps.h"
#include "apps/services/gui/gui.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "loader_i.h"
#include "service_manifest.h"
#include "services/gui/gui.h"
#include <sys/cdefs.h>
#define TAG "Loader"
@@ -22,7 +23,7 @@ static Loader* loader_alloc() {
loader->queue = furi_message_queue_alloc(1, sizeof(LoaderMessage));
loader->thread = furi_thread_alloc_ex(
"loader",
AppStackSizeLarge, // Last known minimum was 2400 for starting Hello World app
4096, // Last known minimum was 2400 for starting Hello World app
&loader_main,
NULL
);
@@ -307,14 +308,10 @@ static void loader_stop() {
loader = NULL;
}
const AppManifest loader_app = {
const ServiceManifest loader_service = {
.id = "loader",
.name = "Loader",
.icon = NULL,
.type = AppTypeService,
.on_start = &loader_start,
.on_stop = &loader_stop,
.on_show = NULL
.on_stop = &loader_stop
};
// endregion
@@ -1,8 +1,9 @@
#pragma once
#include "app_manifest.h"
#include "furi_core.h"
#include "furi_string.h"
#include "pubsub.h"
#include "app_manifest.h"
#include "service_manifest.h"
#ifdef __cplusplus
extern "C" {
@@ -1,12 +1,13 @@
#pragma once
#include "api_lock.h"
#include "app_manifest.h"
#include "apps/services/gui/view_port.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "loader.h"
#include "message_queue.h"
#include "pubsub.h"
#include "services/gui/view_port.h"
#include "thread.h"
typedef struct {