LMMS
Loading...
Searching...
No Matches
juce_InterprocessConnection.h
Go to the documentation of this file.
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//==============================================================================
54{
55public:
56 //==============================================================================
73 InterprocessConnection (bool callbacksOnMessageThread = true,
74 uint32 magicMessageHeaderNumber = 0xf2b49e2c);
75
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
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 //==============================================================================
195 std::unique_ptr<StreamingSocket> socket;
196 std::unique_ptr<NamedPipe> pipe;
201
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
224};
225
226} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
static void message(int level, const char *fmt,...)
Definition adplugdb.cpp:120
virtual void connectionMade()=0
const uint32 magicMessageHeader
Definition juce_InterprocessConnection.h:199
int readData(void *, int)
Definition juce_InterprocessConnection.cpp:327
void initialiseWithPipe(std::unique_ptr< NamedPipe >)
Definition juce_InterprocessConnection.cpp:241
virtual void messageReceived(const MemoryBlock &message)=0
StreamingSocket * getSocket() const noexcept
Definition juce_InterprocessConnection.h:140
const bool useMessageThread
Definition juce_InterprocessConnection.h:198
void deletePipeAndSocket()
Definition juce_InterprocessConnection.cpp:168
std::unique_ptr< ConnectionThread > thread
Definition juce_InterprocessConnection.h:214
std::atomic< bool > threadIsRunning
Definition juce_InterprocessConnection.h:215
void initialiseWithSocket(std::unique_ptr< StreamingSocket >)
Definition juce_InterprocessConnection.cpp:234
std::shared_ptr< SafeAction > safeAction
Definition juce_InterprocessConnection.h:218
friend class InterprocessConnectionServer
Definition juce_InterprocessConnection.h:202
std::unique_ptr< StreamingSocket > socket
Definition juce_InterprocessConnection.h:195
InterprocessConnection(bool callbacksOnMessageThread=true, uint32 magicMessageHeaderNumber=0xf2b49e2c)
Definition juce_InterprocessConnection.cpp:74
void connectionLostInt()
Definition juce_InterprocessConnection.cpp:285
bool createPipe(const String &pipeName, int pipeReceiveMessageTimeoutMs, bool mustNotExist=false)
Definition juce_InterprocessConnection.cpp:131
bool connectToPipe(const String &pipeName, int pipeReceiveMessageTimeoutMs)
Definition juce_InterprocessConnection.cpp:114
int pipeReceiveMessageTimeout
Definition juce_InterprocessConnection.h:200
ReadWriteLock pipeAndSocketLock
Definition juce_InterprocessConnection.h:194
std::unique_ptr< NamedPipe > pipe
Definition juce_InterprocessConnection.h:196
int writeData(void *, int)
Definition juce_InterprocessConnection.cpp:212
void deliverDataInt(const MemoryBlock &)
Definition juce_InterprocessConnection.cpp:316
bool callbackConnectionState
Definition juce_InterprocessConnection.h:197
Notify
Definition juce_InterprocessConnection.h:124
void connectionMadeInt()
Definition juce_InterprocessConnection.cpp:272
void initialise()
Definition juce_InterprocessConnection.cpp:226
void runThread()
Definition juce_InterprocessConnection.cpp:389
virtual void connectionLost()=0
bool readNextMessage()
Definition juce_InterprocessConnection.cpp:341
bool connectToSocket(const String &hostName, int portNumber, int timeOutMillisecs)
Definition juce_InterprocessConnection.cpp:97
NamedPipe * getPipe() const noexcept
Definition juce_InterprocessConnection.h:143
Definition juce_MemoryBlock.h:33
Definition juce_NamedPipe.h:37
Definition juce_ReadWriteLock.h:48
Definition juce_Socket.h:38
Definition juce_String.h:53
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
@ no
Definition juce_AlertWindow.cpp:567
@ yes
Definition juce_AlertWindow.cpp:567
unsigned int uint32
Definition juce_MathsFunctions.h:45
Definition juce_InterprocessConnection.cpp:27
#define const
Definition zconf.h:137