- Refactor the way apps work: Instead of a C interface, they are now C++ classes. The main reasoning is that attaching data to an app was cumbersome. Having different implementations for different kinds of apps was cumbersome too. (3 or 4 layers of manifest nesting for the TactilityC project) - External apps are still written in C, but they get a createData/destroyData in their manifest, so: - External apps now have their own manifest. - All functions in the original AppManifest are removed and replaced by a single `createApp` function - External apps now automatically register (each app individually!) when they run the first time. As a side-effect they become visible in the `AppList` app! - Adapted all apps for the new interface. - Adapted all internal logic for these changes (Gui, ViewPort, Loader, AppContext, AppInstance, etc.) - Rewrote parts of Loader to use std::shared_ptr to make the code much safer. - Added a refcount check for the `AppInstance` and `App` at the end of their lifecycle. Show warning if refcount is too high.
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#include "ManifestRegistry.h"
|
|
#include "Mutex.h"
|
|
#include "AppManifest.h"
|
|
#include <unordered_map>
|
|
|
|
#define TAG "app"
|
|
|
|
namespace tt::app {
|
|
|
|
typedef std::unordered_map<std::string, std::shared_ptr<AppManifest>> AppManifestMap;
|
|
|
|
static AppManifestMap app_manifest_map;
|
|
static Mutex hash_mutex(Mutex::Type::Normal);
|
|
|
|
void addApp(const AppManifest& manifest) {
|
|
TT_LOG_I(TAG, "Registering manifest %s", manifest.id.c_str());
|
|
|
|
hash_mutex.acquire(TtWaitForever);
|
|
|
|
if (!app_manifest_map.contains(manifest.id)) {
|
|
app_manifest_map[manifest.id] = std::make_shared<AppManifest>(manifest);
|
|
} else {
|
|
TT_LOG_E(TAG, "App id in use: %s", manifest.id.c_str());
|
|
}
|
|
|
|
hash_mutex.release();
|
|
}
|
|
|
|
_Nullable std::shared_ptr<AppManifest> findAppById(const std::string& id) {
|
|
hash_mutex.acquire(TtWaitForever);
|
|
auto result = app_manifest_map.find(id);
|
|
hash_mutex.release();
|
|
if (result != app_manifest_map.end()) {
|
|
return result->second;
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
std::vector<std::shared_ptr<AppManifest>> getApps() {
|
|
std::vector<std::shared_ptr<AppManifest>> manifests;
|
|
hash_mutex.acquire(TtWaitForever);
|
|
for (const auto& item: app_manifest_map) {
|
|
manifests.push_back(item.second);
|
|
}
|
|
hash_mutex.release();
|
|
return manifests;
|
|
}
|
|
|
|
} // namespace
|