refactor app code (#93)

This commit is contained in:
Ken Van Hoeylandt
2024-11-26 22:17:01 +01:00
committed by GitHub
parent a312bd5527
commit d7b151ab88
40 changed files with 367 additions and 439 deletions
+12 -26
View File
@@ -3,52 +3,38 @@
#include "TactilityCore.h"
#include <unordered_map>
#define TAG "app_registry"
#define TAG "app"
namespace tt::app {
typedef std::unordered_map<std::string, const Manifest*> AppManifestMap;
static AppManifestMap app_manifest_map;
static Mutex* hash_mutex = nullptr;
static Mutex hash_mutex(MutexTypeNormal);
static void app_registry_lock() {
tt_assert(hash_mutex != nullptr);
tt_mutex_acquire(hash_mutex, TtWaitForever);
}
void addApp(const Manifest* manifest) {
TT_LOG_I(TAG, "Registering manifest %s", manifest->id.c_str());
static void app_registry_unlock() {
tt_assert(hash_mutex != nullptr);
tt_mutex_release(hash_mutex);
}
void app_manifest_registry_init() {
tt_assert(hash_mutex == nullptr);
hash_mutex = tt_mutex_alloc(MutexTypeNormal);
}
void app_manifest_registry_add(const Manifest* manifest) {
TT_LOG_I(TAG, "adding %s", manifest->id.c_str());
app_registry_lock();
hash_mutex.acquire(TtWaitForever);
app_manifest_map[manifest->id] = manifest;
app_registry_unlock();
hash_mutex.release();
}
_Nullable const Manifest * app_manifest_registry_find_by_id(const std::string& id) {
app_registry_lock();
_Nullable const Manifest * findAppById(const std::string& id) {
hash_mutex.acquire(TtWaitForever);
auto iterator = app_manifest_map.find(id);
_Nullable const Manifest* result = iterator != app_manifest_map.end() ? iterator->second : nullptr;
app_registry_unlock();
hash_mutex.release();
return result;
}
std::vector<const Manifest*> app_manifest_registry_get() {
std::vector<const Manifest*> getApps() {
std::vector<const Manifest*> manifests;
app_registry_lock();
hash_mutex.acquire(TtWaitForever);
for (const auto& item: app_manifest_map) {
manifests.push_back(item.second);
}
app_registry_unlock();
hash_mutex.release();
return manifests;
}