mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-01 09:10:18 -06:00
Move presync callback functionality from SkyBrowserModule to ServerModule in order to expose the functionality to other topics as well
This commit is contained in:
@@ -50,6 +50,15 @@ ServerModule::ServerModule()
|
||||
, _interfaceOwner({"Interfaces", "Interfaces", "Server Interfaces"})
|
||||
{
|
||||
addPropertySubOwner(_interfaceOwner);
|
||||
|
||||
global::callback::preSync->emplace_back([this]() {
|
||||
// Trigger callbacks
|
||||
using K = CallbackHandle;
|
||||
using V = CallbackFunction;
|
||||
for (const std::pair<const K, V>& it : _preSyncCallbacks) {
|
||||
it.second(); // call function
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ServerModule::~ServerModule() {
|
||||
@@ -233,4 +242,28 @@ void ServerModule::consumeMessages() {
|
||||
}
|
||||
}
|
||||
|
||||
ServerModule::CallbackHandle ServerModule::addPreSyncCallback(CallbackFunction cb)
|
||||
{
|
||||
CallbackHandle handle = _nextCallbackHandle++;
|
||||
_preSyncCallbacks.emplace_back(handle, std::move(cb));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void ServerModule::removePreSyncCallback(CallbackHandle handle) {
|
||||
const auto it = std::find_if(
|
||||
_preSyncCallbacks.begin(),
|
||||
_preSyncCallbacks.end(),
|
||||
[handle](const std::pair<CallbackHandle, CallbackFunction>& cb) {
|
||||
return cb.first == handle;
|
||||
}
|
||||
);
|
||||
|
||||
ghoul_assert(
|
||||
it != _preSyncCallbacks.end(),
|
||||
"handle must be a valid callback handle"
|
||||
);
|
||||
|
||||
_preSyncCallbacks.erase(it);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user