Download Source/Plugin/InstanceRegistry.h from RAM2118/pluginbridge: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/RAM2118/pluginbridge/resolve/main/Source/Plugin/InstanceRegistry.h
- Command line
-
hf download hf://RAM2118/pluginbridge/Source/Plugin/InstanceRegistry.h
-
curl -L -o InstanceRegistry.h https://huggingface.co/RAM2118/pluginbridge/resolve/main/Source/Plugin/InstanceRegistry.h
2.11 kB
| // Header-only instance registry. | |
| // Stores {channelName: port} in a JSON file at /tmp/pluginbridge-registry.json | |
| // Multiple PluginBridge instances write to this file (one per track). | |
| // Atomic writes via write-to-temp + rename (POSIX rename is atomic on same filesystem). | |
| namespace InstanceRegistry { | |
| inline std::map<std::string, int> readAll() | |
| { | |
| std::map<std::string, int> result; | |
| std::ifstream file(PluginBridgeConstants::kRegistryPath); | |
| if (!file.is_open()) return result; | |
| try | |
| { | |
| nlohmann::json j; | |
| file >> j; | |
| for (auto& [key, val] : j.items()) | |
| { | |
| if (val.is_number_integer()) | |
| result[key] = val.get<int>(); | |
| } | |
| } | |
| catch (...) {} | |
| return result; | |
| } | |
| inline void registerInstance(const std::string& channelName, int port) | |
| { | |
| // Read existing | |
| auto registry = readAll(); | |
| // Update entry | |
| registry[channelName] = port; | |
| // Write to temp file, then atomic rename | |
| std::string tmpPath = std::string(PluginBridgeConstants::kRegistryPath) + ".tmp"; | |
| nlohmann::json j(registry); | |
| std::ofstream tmp(tmpPath); | |
| if (tmp.is_open()) | |
| { | |
| tmp << j.dump(2); | |
| tmp.close(); | |
| std::rename(tmpPath.c_str(), PluginBridgeConstants::kRegistryPath); | |
| } | |
| } | |
| inline void unregisterInstance(const std::string& channelName) | |
| { | |
| auto registry = readAll(); | |
| auto it = registry.find(channelName); | |
| if (it == registry.end()) return; | |
| registry.erase(it); | |
| std::string tmpPath = std::string(PluginBridgeConstants::kRegistryPath) + ".tmp"; | |
| if (registry.empty()) | |
| { | |
| // Remove the file entirely | |
| std::remove(PluginBridgeConstants::kRegistryPath); | |
| return; | |
| } | |
| nlohmann::json j(registry); | |
| std::ofstream tmp(tmpPath); | |
| if (tmp.is_open()) | |
| { | |
| tmp << j.dump(2); | |
| tmp.close(); | |
| std::rename(tmpPath.c_str(), PluginBridgeConstants::kRegistryPath); | |
| } | |
| } | |
| } // namespace InstanceRegistry | |