Tactiliest/Tactility/Source/AppManifestRegistry.cpp
Ken Van Hoeylandt 76c14a5f47
Sort apps on Desktop and Settings (#87)
- Sort apps by name
- Make manifest IDs consistent
- Updated screenshots
- Renamed Screenshot app so it always renders at the bottom of the app list
2024-11-24 22:16:43 +01:00

56 lines
1.5 KiB
C++

#include "AppManifestRegistry.h"
#include "Mutex.h"
#include "TactilityCore.h"
#include <unordered_map>
#define TAG "app_registry"
namespace tt {
typedef std::unordered_map<std::string, const AppManifest*> AppManifestMap;
static AppManifestMap app_manifest_map;
static Mutex* hash_mutex = nullptr;
static void app_registry_lock() {
tt_assert(hash_mutex != nullptr);
tt_mutex_acquire(hash_mutex, TtWaitForever);
}
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 AppManifest* manifest) {
TT_LOG_I(TAG, "adding %s", manifest->id.c_str());
app_registry_lock();
app_manifest_map[manifest->id] = manifest;
app_registry_unlock();
}
_Nullable const AppManifest * app_manifest_registry_find_by_id(const std::string& id) {
app_registry_lock();
auto iterator = app_manifest_map.find(id);
_Nullable const AppManifest* result = iterator != app_manifest_map.end() ? iterator->second : nullptr;
app_registry_unlock();
return result;
}
std::vector<const AppManifest*> app_manifest_registry_get() {
std::vector<const AppManifest*> manifests;
app_registry_lock();
for (const auto& item: app_manifest_map) {
manifests.push_back(item.second);
}
app_registry_unlock();
return manifests;
}
} // namespace