| #pragma once |
|
|
| #include <juce_core/juce_core.h> |
| #include <juce_events/juce_events.h> |
| #include <string> |
| #include <thread> |
| #include <atomic> |
| #include <functional> |
| #include <mutex> |
|
|
| #include "SharedAudioBuffer.h" |
| #include "IPCProtocol.h" |
|
|
| class HelperConnection : private juce::Timer |
| { |
| public: |
| HelperConnection(); |
| ~HelperConnection(); |
|
|
| |
| bool spawnHelper(); |
| void killHelper(); |
| bool isHelperRunning() const { return helperRunning.load(); } |
|
|
| |
| SharedAudioBuffer& getSharedAudio() { return sharedAudio; } |
| SharedSemaphore& getInputSem() { return inputSem; } |
| SharedSemaphore& getOutputSem() { return outputSem; } |
|
|
| |
| std::string sendCommand(const std::string& json); |
|
|
| |
| enum class State { Disconnected, Starting, Connected, Crashed }; |
| State getState() const { return state.load(); } |
|
|
| |
| std::function<void()> onHelperReady; |
| std::function<void()> onHelperCrashed; |
| std::function<void(int, float)> onParamChanged; |
| std::function<void(const juce::String&, int, int)> onGuiReady; |
| std::function<void(int, int)> onGuiResized; |
|
|
| private: |
| void timerCallback() override; |
| void ipcListenLoop(); |
| void handleNotification(const std::string& json); |
|
|
| pid_t helperPid = 0; |
| std::atomic<bool> helperRunning{false}; |
| std::atomic<State> state{State::Disconnected}; |
|
|
| SharedAudioBuffer sharedAudio; |
| SharedSemaphore inputSem; |
| SharedSemaphore outputSem; |
|
|
| int serverSocketFd = -1; |
| int clientSocketFd = -1; |
| std::thread ipcThread; |
| std::atomic<bool> ipcRunning{false}; |
|
|
| std::mutex commandMutex; |
| std::string lastResponse; |
| std::atomic<bool> responseReady{false}; |
|
|
| int myPid; |
| }; |
|
|