OpenShot Audio Library | OpenShotAudio 0.3.2
|
#include <juce_InterprocessConnection.h>
Inherited by juce::ChildProcessMaster::Connection, and juce::ChildProcessSlave::Connection.
Public Member Functions | |
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) |
void | disconnect () |
bool | isConnected () const |
StreamingSocket * | getSocket () const noexcept |
NamedPipe * | getPipe () const noexcept |
String | getConnectedHostName () const |
bool | sendMessage (const MemoryBlock &message) |
virtual void | connectionMade ()=0 |
virtual void | connectionLost ()=0 |
virtual void | messageReceived (const MemoryBlock &message)=0 |
Manages a simple two-way messaging connection to another process, using either a socket or a named pipe as the transport medium.
To connect to a waiting socket or an open pipe, use the connectToSocket() or connectToPipe() methods. If this succeeds, messages can be sent to the other end, and incoming messages will result in a callback via the messageReceived() method.
To open a pipe and wait for another client to connect to it, use the createPipe() method.
To act as a socket server and create connections for one or more client, see the InterprocessConnectionServer class.
Definition at line 50 of file juce_InterprocessConnection.h.
juce::InterprocessConnection::InterprocessConnection | ( | bool | callbacksOnMessageThread = true , |
uint32 | magicMessageHeaderNumber = 0xf2b49e2c |
||
) |
Creates a connection.
Connections are created manually, connecting them with the connectToSocket() or connectToPipe() methods, or they are created automatically by a InterprocessConnectionServer when a client wants to connect.
callbacksOnMessageThread | if true, callbacks to the connectionMade(), connectionLost() and messageReceived() methods will always be made using the message thread; if false, these will be called immediately on the connection's own thread. |
magicMessageHeaderNumber | a magic number to use in the header to check the validity of the data blocks being sent and received. This can be any number, but the sender and receiver must obviously use matching values or they won't recognise each other. |
Definition at line 36 of file juce_InterprocessConnection.cpp.
|
virtual |
Destructor.
Definition at line 43 of file juce_InterprocessConnection.cpp.
Called when the connection is broken.
If the connection was created with the callbacksOnMessageThread flag set, then this will be called on the message thread; otherwise it will be called on a server thread.
Called when the connection is first connected.
If the connection was created with the callbacksOnMessageThread flag set, then this will be called on the message thread; otherwise it will be called on a server thread.
bool juce::InterprocessConnection::connectToPipe | ( | const String & | pipeName, |
int | pipeReceiveMessageTimeoutMs | ||
) |
Tries to connect the object to an existing named pipe.
For this to work, another process on the same computer must already have opened an InterprocessConnection object and used createPipe() to create a pipe for this to connect to.
pipeName | the name to use for the pipe - this should be unique to your app |
pipeReceiveMessageTimeoutMs | a timeout length to be used when reading or writing to the pipe, or -1 for an infinite timeout. |
Definition at line 72 of file juce_InterprocessConnection.cpp.
bool juce::InterprocessConnection::connectToSocket | ( | const String & | hostName, |
int | portNumber, | ||
int | timeOutMillisecs | ||
) |
Tries to connect this object to a socket.
For this to work, the machine on the other end needs to have a InterprocessConnectionServer object waiting to receive client connections on this port number.
hostName | the host computer, either a network address or name |
portNumber | the socket port number to try to connect to |
timeOutMillisecs | how long to keep trying before giving up |
Definition at line 52 of file juce_InterprocessConnection.cpp.
bool juce::InterprocessConnection::createPipe | ( | const String & | pipeName, |
int | pipeReceiveMessageTimeoutMs, | ||
bool | mustNotExist = false |
||
) |
Tries to create a new pipe for other processes to connect to.
This creates a pipe with the given name, so that other processes can use connectToPipe() to connect to the other end.
pipeName | the name to use for the pipe - this should be unique to your app |
pipeReceiveMessageTimeoutMs | a timeout length to be used when reading or writing to the pipe, or -1 for an infinite timeout |
mustNotExist | if set to true, the method will fail if the pipe already exists |
Definition at line 89 of file juce_InterprocessConnection.cpp.
void juce::InterprocessConnection::disconnect | ( | ) |
Disconnects and closes any currently-open sockets or pipes.
Definition at line 106 of file juce_InterprocessConnection.cpp.
Referenced by connectToPipe(), connectToSocket(), createPipe(), and ~InterprocessConnection().
String juce::InterprocessConnection::getConnectedHostName | ( | ) | const |
Returns the name of the machine at the other end of this connection. This may return an empty string if the name is unknown.
Definition at line 137 of file juce_InterprocessConnection.cpp.
|
inlinenoexcept |
Returns the pipe that this connection is using (or nullptr if it uses a socket).
Definition at line 130 of file juce_InterprocessConnection.h.
|
inlinenoexcept |
Returns the socket that this connection is using (or nullptr if it uses a pipe).
Definition at line 127 of file juce_InterprocessConnection.h.
bool juce::InterprocessConnection::isConnected | ( | ) | const |
True if a socket or pipe is currently active.
Definition at line 128 of file juce_InterprocessConnection.cpp.
|
pure virtual |
Called when a message arrives.
When the object at the other end of this connection sends us a message with sendMessage(), this callback is used to deliver it to us.
If the connection was created with the callbacksOnMessageThread flag set, then this will be called on the message thread; otherwise it will be called on a server thread.
bool juce::InterprocessConnection::sendMessage | ( | const MemoryBlock & | message | ) |
Tries to send a message to the other end of this connection.
This will fail if it's not connected, or if there's some kind of write error. If it succeeds, the connection object at the other end will receive the message by a callback to its messageReceived() method.
Definition at line 153 of file juce_InterprocessConnection.cpp.