NanoOcp
Minimal AES70 / OCP.1 TCP client/server library for d&b Soundscape devices
Loading...
Searching...
No Matches
NanoOcp1::NanoOcp1Server Class Reference

OCP.1 TCP server that accepts a single incoming connection at a time. More...

#include <NanoOcp1.h>

+ Inheritance diagram for NanoOcp1::NanoOcp1Server:
+ Collaboration diagram for NanoOcp1::NanoOcp1Server:

Public Member Functions

 NanoOcp1Server (const bool callbacksOnMessageThread, const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal)
 Constructs a server without an initial bind address/port.
 
 NanoOcp1Server (const juce::String &address, const int port, const bool callbacksOnMessageThread, const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal)
 Constructs a server with bind address and port pre-configured.
 
 ~NanoOcp1Server () override
 
bool start () override
 Binds the socket and starts the accept loop thread.
 
bool stop () override
 Stops the accept loop and closes any active connection.
 
bool sendData (const ByteVector &data) override
 Sends serialized OCP.1 bytes to the currently connected peer. If no peer is connected, returns false.
 
- 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::Ocp1ConnectionServer
 Ocp1ConnectionServer (const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal)
 Constructs the server.
 
 ~Ocp1ConnectionServer () override
 
bool beginWaitingForSocket (int portNumber, const juce::String &bindAddress=juce::String())
 Binds a TCP socket to the given port and starts the accept-loop thread.
 
void stop ()
 Stops the accept-loop thread and closes the listening socket.
 
int getBoundPort () const noexcept
 Returns the port number the server is bound to, or -1 if not listening.
 

Protected Member Functions

Ocp1ConnectioncreateConnectionObject () override
 Factory method called by the accept loop — creates the NanoOcp1Client peer object for the newly accepted TCP connection.
 
- 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 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.
 

Detailed Description

OCP.1 TCP server that accepts a single incoming connection at a time.

Useful when the local application acts as an OCA device (or simulator) and a remote controller connects to it. For the more common case of controlling a hardware device, use NanoOcp1Client instead.

Internally wraps Ocp1ConnectionServer (accept loop) and creates a NanoOcp1Client peer object when a connection arrives. The same three callbacks (onDataReceived, onConnectionEstablished, onConnectionLost) are available and behave identically to NanoOcp1Client.

Only one simultaneous connection is supported. A new incoming connection while one is already active replaces the previous one.

Definition at line 320 of file NanoOcp1.h.

Constructor & Destructor Documentation

◆ NanoOcp1Server() [1/2]

NanoOcp1::NanoOcp1Server::NanoOcp1Server ( const bool  callbacksOnMessageThread,
const juce::Thread::Priority  threadPriority = juce::Thread::Priority::normal 
)

Constructs a server without an initial bind address/port.

Parameters
callbacksOnMessageThreadSee NanoOcp1Client constructor.
threadPriorityOS thread priority for the accept thread.

Definition at line 149 of file NanoOcp1.cpp.

◆ NanoOcp1Server() [2/2]

NanoOcp1::NanoOcp1Server::NanoOcp1Server ( const juce::String &  address,
const int  port,
const bool  callbacksOnMessageThread,
const juce::Thread::Priority  threadPriority = juce::Thread::Priority::normal 
)

Constructs a server with bind address and port pre-configured.

Parameters
addressLocal address to bind to (empty = all interfaces).
portTCP port to listen on.
callbacksOnMessageThreadSee NanoOcp1Client constructor.
threadPrioritySee other constructor.

Definition at line 154 of file NanoOcp1.cpp.

◆ ~NanoOcp1Server()

NanoOcp1::NanoOcp1Server::~NanoOcp1Server ( )
override

Definition at line 159 of file NanoOcp1.cpp.

References stop().

Member Function Documentation

◆ createConnectionObject()

Ocp1Connection * NanoOcp1::NanoOcp1Server::createConnectionObject ( )
overrideprotectedvirtual

Factory method called by the accept loop — creates the NanoOcp1Client peer object for the newly accepted TCP connection.

Implements NanoOcp1::Ocp1ConnectionServer.

Definition at line 188 of file NanoOcp1.cpp.

References NanoOcp1::NanoOcp1Base::onDataReceived.

◆ sendData()

bool NanoOcp1::NanoOcp1Server::sendData ( const ByteVector data)
overridevirtual

Sends serialized OCP.1 bytes to the currently connected peer. If no peer is connected, returns false.

Implements NanoOcp1::NanoOcp1Base.

Definition at line 180 of file NanoOcp1.cpp.

◆ start()

bool NanoOcp1::NanoOcp1Server::start ( )
overridevirtual

Binds the socket and starts the accept loop thread.

Returns
True if the socket was bound and the accept thread started.

Implements NanoOcp1::NanoOcp1Base.

Definition at line 164 of file NanoOcp1.cpp.

References NanoOcp1::Ocp1ConnectionServer::beginWaitingForSocket(), NanoOcp1::NanoOcp1Base::getAddress(), and NanoOcp1::NanoOcp1Base::getPort().

◆ stop()

bool NanoOcp1::NanoOcp1Server::stop ( )
overridevirtual

Stops the accept loop and closes any active connection.

Returns
True always.

Implements NanoOcp1::NanoOcp1Base.

Definition at line 169 of file NanoOcp1.cpp.

Referenced by ~NanoOcp1Server().


The documentation for this class was generated from the following files: