Loading...
Searching...
No Matches
juce_InterprocessConnection.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
class InterprocessConnectionServer;
class MemoryBlock;
//==============================================================================
class JUCE_API InterprocessConnection
{
public:
//==============================================================================
InterprocessConnection (bool callbacksOnMessageThread = true,
uint32 magicMessageHeaderNumber = 0xf2b49e2c);
virtual ~InterprocessConnection();
//==============================================================================
bool connectToSocket (const String& hostName,
int portNumber,
int timeOutMillisecs);
bool connectToPipe (const String& pipeName, int pipeReceiveMessageTimeoutMs);
bool createPipe (const String& pipeName, int pipeReceiveMessageTimeoutMs, bool mustNotExist = false);
enum class Notify { no, yes };
void disconnect (int timeoutMs = -1, Notify notify = Notify::yes);
bool isConnected() const;
StreamingSocket* getSocket() const noexcept { return socket.get(); }
NamedPipe* getPipe() const noexcept { return pipe.get(); }
String getConnectedHostName() const;
//==============================================================================
bool sendMessage (const MemoryBlock& message);
//==============================================================================
virtual void connectionMade() = 0;
virtual void connectionLost() = 0;
virtual void messageReceived (const MemoryBlock& message) = 0;
private:
//==============================================================================
ReadWriteLock pipeAndSocketLock;
std::unique_ptr<StreamingSocket> socket;
std::unique_ptr<NamedPipe> pipe;
bool callbackConnectionState = false;
const bool useMessageThread;
const uint32 magicMessageHeader;
int pipeReceiveMessageTimeout = -1;
friend class InterprocessConnectionServer;
void initialise();
void initialiseWithSocket (std::unique_ptr<StreamingSocket>);
void initialiseWithPipe (std::unique_ptr<NamedPipe>);
void deletePipeAndSocket();
void connectionMadeInt();
void connectionLostInt();
void deliverDataInt (const MemoryBlock&);
bool readNextMessage();
int readData (void*, int);
struct ConnectionThread;
std::unique_ptr<ConnectionThread> thread;
std::atomic<bool> threadIsRunning { false };
class SafeAction;
std::shared_ptr<SafeAction> safeAction;
void runThread();
int writeData (void*, int);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InterprocessConnection)
};
} // 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::InterprocessConnection
InterprocessConnection(bool callbacksOnMessageThread=true, uint32 magicMessageHeaderNumber=0xf2b49e2c)
Definition juce_InterprocessConnection.cpp:74
juce::InterprocessConnection::createPipe
bool createPipe(const String &pipeName, int pipeReceiveMessageTimeoutMs, bool mustNotExist=false)
Definition juce_InterprocessConnection.cpp:131
juce::InterprocessConnection::connectToPipe
bool connectToPipe(const String &pipeName, int pipeReceiveMessageTimeoutMs)
Definition juce_InterprocessConnection.cpp:114
juce::InterprocessConnection::Notify
Notify
Definition juce_InterprocessConnection.h:124
juce::InterprocessConnection::connectionLost
virtual void connectionLost()=0
juce::InterprocessConnection::connectToSocket
bool connectToSocket(const String &hostName, int portNumber, int timeOutMillisecs)
Definition juce_InterprocessConnection.cpp:97
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