OpenSRX 0.1.0
C++ library for interfacing with Keyence SR series barcode readers
Loading...
Searching...
No Matches
OpenSRX::AsioInterface< StreamT > Class Template Reference

Templated base class for Asio-based communication interfaces. More...

#include <AsioInterface.hpp>

Inheritance diagram for OpenSRX::AsioInterface< StreamT >:
OpenSRX::ICommInterface

Public Member Functions

 ~AsioInterface () override=default
 
std::string sendCommand (const std::string &command) override
 Sends a command over the Asio stream and reads the response.
 
std::string sendCommandUnlocked (const std::string &command) override
 Sends a command without acquiring the communication mutex.
 
- Public Member Functions inherited from OpenSRX::ICommInterface
virtual ~ICommInterface ()=default
 
virtual std::string describe () const =0
 Return a human-readable description of this interface.
 
void setCommFormat (CommFormat format)
 Set the communication framing format.
 
CommFormat getCommFormat ()
 Get the current communication framing format.
 

Protected Member Functions

template<typename... Args>
 AsioInterface (Args &&... args)
 Construct an AsioInterface, forwarding arguments to the stream.
 

Protected Attributes

asio::io_context ioContext
 
StreamT stream
 
- Protected Attributes inherited from OpenSRX::ICommInterface
std::mutex commMutex
 Mutex to ensure thread-safe access to the communixcation interface.
 

Detailed Description

template<typename StreamT>
class OpenSRX::AsioInterface< StreamT >

Templated base class for Asio-based communication interfaces.

Provides the shared sendCommand implementation for any Asio stream type (e.g. asio::ip::tcp::socket, asio::serial_port). Subclasses only need to construct the stream and implement describe().

Template Parameters
StreamTAn Asio SyncReadStream & SyncWriteStream type.

Constructor & Destructor Documentation

◆ ~AsioInterface()

template<typename StreamT>
OpenSRX::AsioInterface< StreamT >::~AsioInterface ( )
overridedefault

◆ AsioInterface()

template<typename StreamT>
template<typename... Args>
OpenSRX::AsioInterface< StreamT >::AsioInterface ( Args &&... args)
inlineexplicitprotected

Construct an AsioInterface, forwarding arguments to the stream.

Template Parameters
ArgsArgument types forwarded to the StreamT constructor.
Parameters
argsArguments forwarded to the StreamT constructor.

Member Function Documentation

◆ sendCommand()

template<typename StreamT>
std::string OpenSRX::AsioInterface< StreamT >::sendCommand ( const std::string & command)
overridevirtual

Sends a command over the Asio stream and reads the response.

This method acquires the communication mutex before sending, so it can be safely called from multiple threads. For blocking commands, sendCommandUnlocked() can be used to allow concurrent cancellation commands from another thread.

Parameters
commandThe command string to send (without header/terminator).
Returns
The parsed response string.

Implements OpenSRX::ICommInterface.

◆ sendCommandUnlocked()

template<typename StreamT>
std::string OpenSRX::AsioInterface< StreamT >::sendCommandUnlocked ( const std::string & command)
overridevirtual

Sends a command without acquiring the communication mutex.

Parameters
commandThe command string to send (without header/terminator).
Returns
The parsed response string.

Implements OpenSRX::ICommInterface.

Member Data Documentation

◆ ioContext

template<typename StreamT>
asio::io_context OpenSRX::AsioInterface< StreamT >::ioContext
protected

◆ stream

template<typename StreamT>
StreamT OpenSRX::AsioInterface< StreamT >::stream
protected

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