mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
feat: Added basic network interface support
This commit is contained in:
2
lib/external/libwolv
vendored
2
lib/external/libwolv
vendored
Submodule lib/external/libwolv updated: 7b441291cd...6b02f52077
@@ -12,6 +12,7 @@
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -813,6 +814,35 @@ namespace hex {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace BackgroundServices {
|
||||
|
||||
namespace impl {
|
||||
using Callback = std::function<void()>;
|
||||
|
||||
struct Service {
|
||||
std::string name;
|
||||
std::jthread thread;
|
||||
};
|
||||
|
||||
std::vector<Service> &getServices();
|
||||
void stopServices();
|
||||
}
|
||||
|
||||
void registerService(const std::string &unlocalizedName, const impl::Callback &callback);
|
||||
}
|
||||
|
||||
namespace CommunicationInterface {
|
||||
|
||||
namespace impl {
|
||||
using NetworkCallback = std::function<nlohmann::json(const nlohmann::json &)>;
|
||||
|
||||
std::map<std::string, NetworkCallback> &getNetworkEndpoints();
|
||||
}
|
||||
|
||||
void registerNetworkEndpoint(const std::string &endpoint, const impl::NetworkCallback &callback);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <hex/data_processor/node.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -787,4 +788,62 @@ namespace hex {
|
||||
|
||||
}
|
||||
|
||||
namespace ContentRegistry::BackgroundServices {
|
||||
|
||||
namespace impl {
|
||||
|
||||
std::vector<Service> &getServices() {
|
||||
static std::vector<Service> services;
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
void stopServices() {
|
||||
for (auto &service : getServices()) {
|
||||
service.thread.request_stop();
|
||||
}
|
||||
|
||||
for (auto &service : getServices()) {
|
||||
service.thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void registerService(const std::string &unlocalizedName, const impl::Callback &callback) {
|
||||
log::debug("Registered new background service: {}", unlocalizedName);
|
||||
|
||||
impl::getServices().push_back(impl::Service {
|
||||
unlocalizedName,
|
||||
std::jthread([callback](const std::stop_token &stopToken){
|
||||
while (!stopToken.stop_requested()) {
|
||||
callback();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace ContentRegistry::CommunicationInterface {
|
||||
|
||||
namespace impl {
|
||||
|
||||
std::map<std::string, NetworkCallback> &getNetworkEndpoints() {
|
||||
static std::map<std::string, NetworkCallback> endpoints;
|
||||
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void registerNetworkEndpoint(const std::string &endpoint, const impl::NetworkCallback &callback) {
|
||||
log::debug("Registered new network endpoint: {}", endpoint);
|
||||
|
||||
impl::getNetworkEndpoints().insert({ endpoint, callback });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user