RAM2118 commited on
Commit
8957da4
·
verified ·
1 Parent(s): eabb3b4

Out-of-process rebuild: Add Plugin/HelperConnection.h/.cpp — spawns helper, IPC, crash detection

Browse files
Files changed (1) hide show
  1. Source/Plugin/HelperConnection.h +68 -0
Source/Plugin/HelperConnection.h ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <juce_core/juce_core.h>
4
+ #include <string>
5
+ #include <thread>
6
+ #include <atomic>
7
+ #include <functional>
8
+ #include <mutex>
9
+
10
+ #include "../Shared/SharedAudioBuffer.h"
11
+ #include "../Shared/IPCProtocol.h"
12
+
13
+ class HelperConnection : private juce::Timer
14
+ {
15
+ public:
16
+ HelperConnection();
17
+ ~HelperConnection();
18
+
19
+ // Lifecycle
20
+ bool spawnHelper();
21
+ void killHelper();
22
+ bool isHelperRunning() const { return helperRunning.load(); }
23
+
24
+ // Audio bridge
25
+ SharedAudioBuffer& getSharedAudio() { return sharedAudio; }
26
+ SharedSemaphore& getInputSem() { return inputSem; }
27
+ SharedSemaphore& getOutputSem() { return outputSem; }
28
+
29
+ // Send commands (blocking — waits for response)
30
+ std::string sendCommand(const std::string& json);
31
+
32
+ // State
33
+ enum class State { Disconnected, Starting, Connected, Crashed };
34
+ State getState() const { return state.load(); }
35
+
36
+ // Callbacks
37
+ std::function<void()> onHelperReady;
38
+ std::function<void()> onHelperCrashed;
39
+ std::function<void(int, float)> onParamChanged;
40
+
41
+ private:
42
+ void timerCallback() override;
43
+ void ipcListenLoop();
44
+ void handleNotification(const std::string& json);
45
+
46
+ // Helper process
47
+ pid_t helperPid = 0;
48
+ std::atomic<bool> helperRunning{false};
49
+ std::atomic<State> state{State::Disconnected};
50
+
51
+ // Shared memory
52
+ SharedAudioBuffer sharedAudio;
53
+ SharedSemaphore inputSem;
54
+ SharedSemaphore outputSem;
55
+
56
+ // IPC socket (parent is server)
57
+ int serverSocketFd = -1;
58
+ int clientSocketFd = -1; // connection from helper
59
+ std::thread ipcThread;
60
+ std::atomic<bool> ipcRunning{false};
61
+
62
+ // Command/response synchronization
63
+ std::mutex commandMutex;
64
+ std::string lastResponse;
65
+ std::atomic<bool> responseReady{false};
66
+
67
+ int myPid;
68
+ };