Tactiliest/Tactility/Source/app/ManifestRegistry.cpp
Ken Van Hoeylandt 49bf8e824c
Various improvements and fixes (#128)
- Fix for display orientation assumption in Display app
- Update logo (added colours)
- Fix for double stopping the Files app
- Deny registration of apps and services that are already registered
- Updated `ideas.md` for these changes
- Other cleanup
2024-12-15 21:15:54 +01:00

47 lines
1.2 KiB
C++

#include "ManifestRegistry.h"
#include "Mutex.h"
#include "TactilityCore.h"
#include <unordered_map>
#define TAG "app"
namespace tt::app {
typedef std::unordered_map<std::string, const AppManifest*> AppManifestMap;
static AppManifestMap app_manifest_map;
static Mutex hash_mutex(Mutex::TypeNormal);
void addApp(const AppManifest* manifest) {
TT_LOG_I(TAG, "Registering manifest %s", manifest->id.c_str());
hash_mutex.acquire(TtWaitForever);
if (app_manifest_map[manifest->id] == nullptr) {
app_manifest_map[manifest->id] = manifest;
} else {
TT_LOG_E(TAG, "App id in use: %s", manifest->id.c_str());
}
hash_mutex.release();
}
_Nullable const AppManifest * findAppById(const std::string& id) {
hash_mutex.acquire(TtWaitForever);
_Nullable const AppManifest* result = app_manifest_map[id.c_str()];
hash_mutex.release();
return result;
}
std::vector<const AppManifest*> getApps() {
std::vector<const AppManifest*> manifests;
hash_mutex.acquire(TtWaitForever);
for (const auto& item: app_manifest_map) {
manifests.push_back(item.second);
}
hash_mutex.release();
return manifests;
}
} // namespace