OpenShot Audio Library | OpenShotAudio: juce_InterprocessConnection.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_InterprocessConnection.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26class InterprocessConnectionServer;
27class MemoryBlock;
28
29
30//==============================================================================
53 class JUCE_API InterprocessConnection
54{
55public:
56 //==============================================================================
73 InterprocessConnection (bool callbacksOnMessageThread = true,
74 uint32 magicMessageHeaderNumber = 0xf2b49e2c);
75
77 virtual ~InterprocessConnection();
78
79 //==============================================================================
91 bool connectToSocket (const String& hostName,
92 int portNumber,
93 int timeOutMillisecs);
94
107 bool connectToPipe (const String& pipeName, int pipeReceiveMessageTimeoutMs);
108
121 bool createPipe (const String& pipeName, int pipeReceiveMessageTimeoutMs, bool mustNotExist = false);
122
124 enum class Notify { no, yes };
125
134 void disconnect (int timeoutMs = -1, Notify notify = Notify::yes);
135
137 bool isConnected() const;
138
140 StreamingSocket* getSocket() const noexcept { return socket.get(); }
141
143 NamedPipe* getPipe() const noexcept { return pipe.get(); }
144
148 String getConnectedHostName() const;
149
150 //==============================================================================
159 bool sendMessage (const MemoryBlock& message);
160
161 //==============================================================================
168 virtual void connectionMade() = 0;
169
176 virtual void connectionLost() = 0;
177
189 virtual void messageReceived (const MemoryBlock& message) = 0;
190
191
192private:
193 //==============================================================================
194 ReadWriteLock pipeAndSocketLock;
195 std::unique_ptr<StreamingSocket> socket;
196 std::unique_ptr<NamedPipe> pipe;
197 bool callbackConnectionState = false;
198 const bool useMessageThread;
199 const uint32 magicMessageHeader;
200 int pipeReceiveMessageTimeout = -1;
201
202 friend class InterprocessConnectionServer;
203 void initialise();
204 void initialiseWithSocket (std::unique_ptr<StreamingSocket>);
205 void initialiseWithPipe (std::unique_ptr<NamedPipe>);
206 void deletePipeAndSocket();
207 void connectionMadeInt();
208 void connectionLostInt();
209 void deliverDataInt (const MemoryBlock&);
210 bool readNextMessage();
211 int readData (void*, int);
212
213 struct ConnectionThread;
214 std::unique_ptr<ConnectionThread> thread;
215 std::atomic<bool> threadIsRunning { false };
216
217 class SafeAction;
218 std::shared_ptr<SafeAction> safeAction;
219
220 void runThread();
221 int writeData (void*, int);
222
223 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InterprocessConnection)
224};
225
226} // namespace juce
juce::InterprocessConnectionServer
Definition juce_InterprocessConnectionServer.h:40
juce::InterprocessConnection
Definition juce_InterprocessConnection.h:54
juce::InterprocessConnection::connectionMade
virtual void connectionMade()=0
juce::InterprocessConnection::messageReceived
virtual void messageReceived(const MemoryBlock &message)=0
juce::InterprocessConnection::getSocket
StreamingSocket * getSocket() const noexcept
Definition juce_InterprocessConnection.h:140
juce::InterprocessConnection::Notify
Notify
Definition juce_InterprocessConnection.h:124
juce::InterprocessConnection::connectionLost
virtual void connectionLost()=0
juce::InterprocessConnection::getPipe
NamedPipe * getPipe() const noexcept
Definition juce_InterprocessConnection.h:143
juce::MemoryBlock
Definition juce_MemoryBlock.h:33
juce::NamedPipe
Definition juce_NamedPipe.h:37
juce::ReadWriteLock
Definition juce_ReadWriteLock.h:48
juce::StreamingSocket
Definition juce_Socket.h:82
juce::String
Definition juce_String.h:53