waterlinkedsonar
C++ client library for the Water Linked Sonar 3D-15
Loading...
Searching...
No Matches
Public Member Functions | List of all members
waterlinked::sonar::Receiver Class Reference

Owns the receive thread: reads datagrams from the injected socket, decodes them, and dispatches to the registered callbacks on that thread. More...

#include <waterlinkedsonar/receiver.hpp>

Public Member Functions

 Receiver (std::unique_ptr< UdpSocket > socket, ReceiverOptions options={})
 Takes ownership of an open socket; nothing is read until start().
 
 ~Receiver ()
 Stops the receive thread if it is running.
 
 Receiver (const Receiver &)=delete
 
Receiveroperator= (const Receiver &)=delete
 
void on_range_image (std::function< void(const RangeImageView &)> cb)
 Registers a callback for decoded RangeImage messages.
 
void on_bitmap_image (std::function< void(const BitmapImageView &)> cb)
 Registers a callback for decoded BitmapImage messages.
 
void on_imu_batch (std::function< void(const ImuBatchView &)> cb)
 Registers a callback for decoded ImuBatch messages.
 
void on_decode_error (std::function< void(rip::DecodeStatus)> cb)
 Registers a callback for datagrams that fail to decode.
 
void on_socket_error (std::function< void(const std::error_code &)> cb)
 Registers a callback for the unrecoverable socket error that ends the receive loop.
 
void start ()
 Starts the receive thread.
 
void stop ()
 Stops the receive thread.
 
bool running () const
 False before start, after stop, and after a socket error ends the receive loop on its own.
 
ReceiverStats stats () const
 Counter snapshot; callable from any thread.
 

Detailed Description

Owns the receive thread: reads datagrams from the injected socket, decodes them, and dispatches to the registered callbacks on that thread.

Callbacks run sequentially on the receive thread. The views they receive are valid for the duration of the callback: decode and dispatch share the one thread, so the storage behind a view is not reused until the callback returns. Copy any data kept beyond the callback.

Constructor & Destructor Documentation

◆ Receiver() [1/2]

waterlinked::sonar::Receiver::Receiver ( std::unique_ptr< UdpSocket socket,
ReceiverOptions  options = {} 
)
explicit

Takes ownership of an open socket; nothing is read until start().

Exceptions
std::invalid_argumentwhen socket is null.

◆ ~Receiver()

waterlinked::sonar::Receiver::~Receiver ( )

Stops the receive thread if it is running.

◆ Receiver() [2/2]

waterlinked::sonar::Receiver::Receiver ( const Receiver )
delete

Member Function Documentation

◆ on_bitmap_image()

void waterlinked::sonar::Receiver::on_bitmap_image ( std::function< void(const BitmapImageView &)>  cb)

Registers a callback for decoded BitmapImage messages.

Same registration and execution rules as on_range_image().

◆ on_decode_error()

void waterlinked::sonar::Receiver::on_decode_error ( std::function< void(rip::DecodeStatus)>  cb)

Registers a callback for datagrams that fail to decode.

Same registration and execution rules as on_range_image(). UNKNOWN_TYPE packets are counted, not reported here.

◆ on_imu_batch()

void waterlinked::sonar::Receiver::on_imu_batch ( std::function< void(const ImuBatchView &)>  cb)

Registers a callback for decoded ImuBatch messages.

Same registration and execution rules as on_range_image().

◆ on_range_image()

void waterlinked::sonar::Receiver::on_range_image ( std::function< void(const RangeImageView &)>  cb)

Registers a callback for decoded RangeImage messages.

Registration for any callback type is only valid before start() and throws std::logic_error afterwards; registering twice calls both. Callbacks run sequentially on the receive thread and must not block for long or throw.

◆ on_socket_error()

void waterlinked::sonar::Receiver::on_socket_error ( std::function< void(const std::error_code &)>  cb)

Registers a callback for the unrecoverable socket error that ends the receive loop.

Same registration and execution rules as on_range_image(). Invoked at most once, from the receive thread, just before running() becomes false.

◆ operator=()

Receiver & waterlinked::sonar::Receiver::operator= ( const Receiver )
delete

◆ running()

bool waterlinked::sonar::Receiver::running ( ) const

False before start, after stop, and after a socket error ends the receive loop on its own.

◆ start()

void waterlinked::sonar::Receiver::start ( )

Starts the receive thread.

One start()/stop() cycle per instance; construct a new Receiver with a fresh socket to restart.

Exceptions
std::logic_erroron a second start().

◆ stats()

ReceiverStats waterlinked::sonar::Receiver::stats ( ) const

Counter snapshot; callable from any thread.

◆ stop()

void waterlinked::sonar::Receiver::stop ( )

Stops the receive thread.

Idempotent.

Joins the thread, except when called from a callback on that thread; the loop then exits once the callback returns.


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