Refactor services into classes (#183)

This commit is contained in:
Ken Van Hoeylandt
2025-01-24 18:21:47 +01:00
committed by GitHub
parent bb7e79886f
commit 3be251d8fb
20 changed files with 382 additions and 373 deletions
+21 -17
View File
@@ -295,31 +295,35 @@ static void stopAppInternal() {
// region AppManifest
static void loader_start(TT_UNUSED ServiceContext& service) {
tt_check(loader_singleton == nullptr);
loader_singleton = loader_alloc();
loader_singleton->dispatcherThread->start();
}
class LoaderService final : public Service {
static void loader_stop(TT_UNUSED ServiceContext& service) {
tt_check(loader_singleton != nullptr);
public:
// Send stop signal to thread and wait for thread to finish
if (!loader_singleton->mutex.lock(2000 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "loader_stop");
void onStart(TT_UNUSED ServiceContext& service) final {
tt_check(loader_singleton == nullptr);
loader_singleton = loader_alloc();
loader_singleton->dispatcherThread->start();
}
loader_singleton->dispatcherThread->stop();
loader_singleton->mutex.unlock();
void onStop(TT_UNUSED ServiceContext& service) final {
tt_check(loader_singleton != nullptr);
loader_free();
loader_singleton = nullptr;
}
// Send stop signal to thread and wait for thread to finish
if (!loader_singleton->mutex.lock(2000 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "loader_stop");
}
loader_singleton->dispatcherThread->stop();
loader_singleton->mutex.unlock();
loader_free();
loader_singleton = nullptr;
}
};
extern const ServiceManifest manifest = {
.id = "Loader",
.onStart = &loader_start,
.onStop = &loader_stop
.createService = create<LoaderService>
};
// endregion