|
NanoOcp
Minimal AES70 / OCP.1 TCP client/server library for d&b Soundscape devices
|
OCP.1 TCP client with automatic reconnection. More...
#include <NanoOcp1.h>
Inheritance diagram for NanoOcp1::NanoOcp1Client:
Collaboration diagram for NanoOcp1::NanoOcp1Client:Public Member Functions | |
| NanoOcp1Client (const bool callbacksOnMessageThread, const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal) | |
Constructs a client without an initial address/port. Call setAddress() and setPort() before start(). | |
| NanoOcp1Client (const juce::String &address, const int port, const bool callbacksOnMessageThread, const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal) | |
| Constructs a client with address and port pre-configured. | |
| ~NanoOcp1Client () override | |
| bool | start () override |
| Starts the reconnect timer and begins attempting to connect. | |
| bool | stop () override |
| Stops the reconnect timer and closes the TCP socket. | |
| bool | isRunning () |
Returns true if start() has been called and stop() has not. | |
| bool | sendData (const ByteVector &data) override |
Sends serialized OCP.1 bytes over the active TCP connection. The bytes must be a complete, framed OCP.1 message as produced by Ocp1Message::GetSerializedData(). | |
| void | connectionMade () override |
Called by Ocp1Connection when TCP connect succeeds — invokes onConnectionEstablished. | |
| void | connectionLost () override |
Called by Ocp1Connection when TCP connection is lost — invokes onConnectionLost. | |
| void | messageReceived (const ByteVector &message) override |
Called by Ocp1Connection for each received OCP.1 frame — invokes onDataReceived. | |
Public Member Functions inherited from NanoOcp1::NanoOcp1Base | |
| NanoOcp1Base (const juce::String &address, const int port) | |
| virtual | ~NanoOcp1Base () |
| void | setAddress (const juce::String &address) |
| Sets the IP address or hostname of the remote OCA device. | |
| const juce::String & | getAddress () |
| Returns the current target address. | |
| void | setPort (const int port) |
| Sets the TCP port number of the remote OCA device. DS100 default: 50014. | |
| const int | getPort () |
| Returns the current target port number. | |
Public Member Functions inherited from NanoOcp1::Ocp1Connection | |
| Ocp1Connection (bool callbacksOnMessageThread=true, const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal) | |
| Constructs the connection object. | |
| virtual | ~Ocp1Connection () |
| bool | connectToSocket (const juce::String &hostName, int portNumber, int timeOutMillisecs) |
| Attempts a TCP connection to the given host and port. Spawns the read thread on success. | |
| void | disconnect (int timeoutMs=0, Notify notify=Notify::yes) |
| Closes the TCP socket and stops the read thread. | |
| bool | isConnected () const |
| Returns true if the TCP socket is currently open. | |
| juce::StreamingSocket * | getSocket () const noexcept |
| Returns the underlying JUCE socket (for diagnostics). | |
| juce::String | getConnectedHostName () const |
| Returns the hostname of the currently connected remote peer, or an empty string. | |
| bool | sendMessage (const ByteVector &message) |
| Sends a complete OCP.1 frame over the TCP socket. Acquires the write lock, then writes all bytes in one blocking call. | |
Protected Member Functions | |
| void | timerCallback () override |
Timer callback — attempts connectToSocket() when not yet connected. | |
Protected Member Functions inherited from NanoOcp1::NanoOcp1Base | |
| bool | processReceivedData (const ByteVector &data) |
Called by derived classes when bytes arrive from the socket. Invokes onDataReceived if set; the frame has already been delimited by Ocp1Connection::readNextMessage(). | |
Additional Inherited Members | |
Public Types inherited from NanoOcp1::Ocp1Connection | |
| enum class | Notify { no , yes } |
Controls whether connectionLost() is called when disconnect() is invoked. Use Notify::no when shutting down deliberately so the application does not treat an intentional disconnect as an error. More... | |
Public Attributes inherited from NanoOcp1::NanoOcp1Base | |
| std::function< bool(const ByteVector &)> | onDataReceived |
| Fired when a complete OCP.1 frame is received. | |
| std::function< void()> | onConnectionEstablished |
| Fired once after a successful TCP connection is established. | |
| std::function< void()> | onConnectionLost |
| Fired when the TCP connection is dropped or a connect attempt fails. | |
OCP.1 TCP client with automatic reconnection.
Inherits socket I/O from Ocp1Connection and reconnect timing from juce::Timer. When start() is called, a juce::Timer fires periodically and attempts connectToSocket() until it succeeds. Once connected, connectionMade() calls onConnectionEstablished. On disconnect (detected by the read thread), connectionLost() calls onConnectionLost and the timer resumes retrying.
DeviceController creates a NanoOcp1Client with callbacksOnMessageThread=false so that OCP.1 parsing runs on the socket thread, avoiding latency on the JUCE message thread. Parsed RemoteObject values are then posted to the message thread via juce::MessageListener.
Definition at line 237 of file NanoOcp1.h.
| NanoOcp1::NanoOcp1Client::NanoOcp1Client | ( | const bool | callbacksOnMessageThread, |
| const juce::Thread::Priority | threadPriority = juce::Thread::Priority::normal |
||
| ) |
Constructs a client without an initial address/port. Call setAddress() and setPort() before start().
| callbacksOnMessageThread | If true, all three callbacks are marshaled to the JUCE message thread. If false, they fire on the socket thread (lower latency, but you must be thread-safe in the callbacks). |
| threadPriority | OS thread priority for the socket I/O thread. |
Definition at line 66 of file NanoOcp1.cpp.
| NanoOcp1::NanoOcp1Client::NanoOcp1Client | ( | const juce::String & | address, |
| const int | port, | ||
| const bool | callbacksOnMessageThread, | ||
| const juce::Thread::Priority | threadPriority = juce::Thread::Priority::normal |
||
| ) |
Constructs a client with address and port pre-configured.
| address | IP address or hostname of the OCA device. |
| port | TCP port number (DS100 default: 50014). |
| callbacksOnMessageThread | See other constructor. |
| threadPriority | See other constructor. |
Definition at line 71 of file NanoOcp1.cpp.
|
override |
Definition at line 76 of file NanoOcp1.cpp.
References stop().
|
overridevirtual |
Called by Ocp1Connection when TCP connection is lost — invokes onConnectionLost.
Implements NanoOcp1::Ocp1Connection.
Definition at line 128 of file NanoOcp1.cpp.
References NanoOcp1::NanoOcp1Base::onConnectionLost.
|
overridevirtual |
Called by Ocp1Connection when TCP connect succeeds — invokes onConnectionEstablished.
Implements NanoOcp1::Ocp1Connection.
Definition at line 120 of file NanoOcp1.cpp.
References NanoOcp1::NanoOcp1Base::onConnectionEstablished.
| bool NanoOcp1::NanoOcp1Client::isRunning | ( | ) |
Returns true if start() has been called and stop() has not.
Definition at line 107 of file NanoOcp1.cpp.
|
overridevirtual |
Called by Ocp1Connection for each received OCP.1 frame — invokes onDataReceived.
Implements NanoOcp1::Ocp1Connection.
Definition at line 137 of file NanoOcp1.cpp.
References NanoOcp1::NanoOcp1Base::processReceivedData().
|
overridevirtual |
Sends serialized OCP.1 bytes over the active TCP connection. The bytes must be a complete, framed OCP.1 message as produced by Ocp1Message::GetSerializedData().
Implements NanoOcp1::NanoOcp1Base.
Definition at line 112 of file NanoOcp1.cpp.
References NanoOcp1::Ocp1Connection::isConnected(), and NanoOcp1::Ocp1Connection::sendMessage().
|
overridevirtual |
Starts the reconnect timer and begins attempting to connect.
onConnectionEstablished. Implements NanoOcp1::NanoOcp1Base.
Definition at line 81 of file NanoOcp1.cpp.
References NanoOcp1::Ocp1Connection::connectToSocket(), NanoOcp1::NanoOcp1Base::getAddress(), and NanoOcp1::NanoOcp1Base::getPort().
|
overridevirtual |
Stops the reconnect timer and closes the TCP socket.
Implements NanoOcp1::NanoOcp1Base.
Definition at line 93 of file NanoOcp1.cpp.
References NanoOcp1::Ocp1Connection::disconnect(), NanoOcp1::Ocp1Connection::isConnected(), and NanoOcp1::NanoOcp1Base::onConnectionLost.
Referenced by ~NanoOcp1Client().
|
overrideprotected |
Timer callback — attempts connectToSocket() when not yet connected.
Definition at line 142 of file NanoOcp1.cpp.
References NanoOcp1::Ocp1Connection::connectToSocket(), NanoOcp1::NanoOcp1Base::getAddress(), and NanoOcp1::NanoOcp1Base::getPort().