97 lines
2.5 KiB
C++
97 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "RuntimeJson.h"
|
|
#include "ShaderTypes.h"
|
|
|
|
#include <atomic>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
class ControlServer;
|
|
class OpenGLComposite;
|
|
class OscServer;
|
|
class RuntimeHost;
|
|
class RuntimeStore;
|
|
|
|
struct RuntimePollEvents
|
|
{
|
|
bool registryChanged = false;
|
|
bool reloadRequested = false;
|
|
bool failed = false;
|
|
std::string error;
|
|
};
|
|
|
|
class ControlServices
|
|
{
|
|
public:
|
|
struct AppliedOscUpdate
|
|
{
|
|
std::string routeKey;
|
|
std::string layerKey;
|
|
std::string parameterKey;
|
|
JsonValue targetValue;
|
|
};
|
|
|
|
struct CompletedOscCommit
|
|
{
|
|
std::string routeKey;
|
|
uint64_t generation = 0;
|
|
};
|
|
|
|
ControlServices();
|
|
~ControlServices();
|
|
|
|
bool Start(OpenGLComposite& composite, RuntimeHost& runtimeHost, std::string& error);
|
|
void BeginPolling(RuntimeHost& runtimeHost, RuntimeStore& runtimeStore);
|
|
void Stop();
|
|
void BroadcastState();
|
|
void RequestBroadcastState();
|
|
bool QueueOscUpdate(const std::string& layerKey, const std::string& parameterKey, const std::string& valueJson, std::string& error);
|
|
bool ApplyPendingOscUpdates(std::vector<AppliedOscUpdate>& appliedUpdates, std::string& error);
|
|
bool QueueOscCommit(const std::string& routeKey, const std::string& layerKey, const std::string& parameterKey, const JsonValue& value, uint64_t generation, std::string& error);
|
|
void ClearOscState();
|
|
void ConsumeCompletedOscCommits(std::vector<CompletedOscCommit>& completedCommits);
|
|
RuntimePollEvents ConsumePollEvents();
|
|
|
|
private:
|
|
struct PendingOscUpdate
|
|
{
|
|
std::string layerKey;
|
|
std::string parameterKey;
|
|
std::string valueJson;
|
|
};
|
|
|
|
struct PendingOscCommit
|
|
{
|
|
std::string routeKey;
|
|
std::string layerKey;
|
|
std::string parameterKey;
|
|
JsonValue value;
|
|
uint64_t generation = 0;
|
|
};
|
|
|
|
void StartPolling(RuntimeHost& runtimeHost, RuntimeStore& runtimeStore);
|
|
void StopPolling();
|
|
void PollLoop(RuntimeHost& runtimeHost, RuntimeStore& runtimeStore);
|
|
|
|
std::unique_ptr<ControlServer> mControlServer;
|
|
std::unique_ptr<OscServer> mOscServer;
|
|
std::thread mPollThread;
|
|
std::atomic<bool> mPollRunning;
|
|
std::atomic<bool> mRegistryChanged;
|
|
std::atomic<bool> mReloadRequested;
|
|
std::atomic<bool> mPollFailed;
|
|
std::mutex mPollErrorMutex;
|
|
std::string mPollError;
|
|
std::mutex mPendingOscMutex;
|
|
std::map<std::string, PendingOscUpdate> mPendingOscUpdates;
|
|
std::mutex mPendingOscCommitMutex;
|
|
std::map<std::string, PendingOscCommit> mPendingOscCommits;
|
|
std::mutex mCompletedOscCommitMutex;
|
|
std::vector<CompletedOscCommit> mCompletedOscCommits;
|
|
};
|