Regilo
A simple C++ library for controlling the Neato XV robot and the Hokuyo scanner.
regilo::StreamController< StreamT > Class Template Reference

The StreamController class is used to communicate with a device. More...

#include <controller.hpp>

Inheritance diagram for regilo::StreamController< StreamT >:
regilo::IController

Public Types

typedef StreamT Stream
 The stream type for this Controller.
 

Public Member Functions

 StreamController ()
 Default constructor.
 
 StreamController (const std::string &logPath)
 Controller with a log file specified by a path. More...
 
 StreamController (std::iostream &logStream)
 Controller with a log specified by a stream. More...
 
virtual ~StreamController ()
 Default destructor.
 
virtual bool isConnected () const override
 Test if the controller is connected. More...
 
virtual std::shared_ptr< ILoggetLog () override
 Get the current Log. More...
 
virtual std::shared_ptr< const ILoggetLog () const override
 Get the current Log (a const variant). More...
 
virtual void setLog (std::shared_ptr< ILog > log) override
 Set a Log (it can be shared between more controllers). More...
 
virtual std::string sendCommand (const std::string &command) final override
 Send a command to the device. More...
 
template<typename Response = void, typename Command >
Response sendCommand (const Command &command)
 Send a command to the device. More...
 
template<typename Response = void, typename Command , typename... Args>
Response sendCommand (const Command &command, const Args &...params)
 Send a command to the device. More...
 
template<typename Response = void, typename... Args>
Response sendFormattedCommand (const std::string &commandFormat, Args...params)
 Create a command with the specified parameters (printf formatting is used) and send it to the device. More...
 
template<typename... Args>
std::string createFormattedCommand (const std::string &commandFormat, Args...params) const
 Create a command with the specified parameters (printf formatting is used). More...
 
- Public Member Functions inherited from regilo::IController
virtual ~IController ()=default
 Default destructor.
 
virtual void connect (const std::string &endpoint)=0
 Connect the controller to a device. More...
 
virtual std::string getEndpoint () const =0
 Get the endpoint of device. More...
 

Public Attributes

std::string REQUEST_END = "\n"
 A string that the request ends with.
 
std::string RESPONSE_END = "\n"
 A string that the response ends with.
 
bool readResponse = true
 If true the sendCommand method reads a response.
 
bool readCommand = true
 If true the input command is read from the response at first.
 

Protected Member Functions

template<typename Response = void, typename std::enable_if< std::is_void< Response >::value >::type * = nullptr>
void sendCommand ()
 Send a command from the device input to the device.
 
template<typename Response , typename std::enable_if<!std::is_void< Response >::value >::type * = nullptr>
Response sendCommand ()
 Send a command from the device input to the device. More...
 

Protected Attributes

std::istringstream deviceOutput
 A buffer for the device output.
 
std::ostringstream deviceInput
 A buffer for the device input.
 
ba::io_service ioService
 The Boost IO service.
 
StreamT stream
 A stream (TCP, socket, etc.) that is used for read/write operations.
 
std::shared_ptr< Loglog
 A log that is connected to the controller.
 

Detailed Description

template<typename StreamT>
class regilo::StreamController< StreamT >

The StreamController class is used to communicate with a device.

Constructor & Destructor Documentation

template<typename StreamT >
regilo::StreamController< StreamT >::StreamController ( const std::string &  logPath)

Controller with a log file specified by a path.

Parameters
logPathPath to the log file.
template<typename StreamT >
regilo::StreamController< StreamT >::StreamController ( std::iostream &  logStream)

Controller with a log specified by a stream.

Parameters
logStreamThe log stream.

Member Function Documentation

template<typename StreamT >
template<typename... Args>
std::string regilo::StreamController< StreamT >::createFormattedCommand ( const std::string &  commandFormat,
Args...  params 
) const

Create a command with the specified parameters (printf formatting is used).

Parameters
commandFormatA command format without parameters.
paramsParameters that will be inserted into the command.
Returns
The command with the parameters.
template<typename StreamT>
virtual std::shared_ptr<ILog> regilo::StreamController< StreamT >::getLog ( )
inlineoverridevirtual

Get the current Log.

Returns
The Log or empty std::shared_ptr.

Implements regilo::IController.

template<typename StreamT>
virtual std::shared_ptr<const ILog> regilo::StreamController< StreamT >::getLog ( ) const
inlineoverridevirtual

Get the current Log (a const variant).

Returns
The Log or empty std::shared_ptr.

Implements regilo::IController.

template<typename StreamT>
virtual bool regilo::StreamController< StreamT >::isConnected ( ) const
inlineoverridevirtual

Test if the controller is connected.

Returns
True if connected.

Implements regilo::IController.

template<typename StreamT >
template<typename Response , typename std::enable_if<!std::is_void< Response >::value >::type * >
Response regilo::StreamController< StreamT >::sendCommand ( )
protected

Send a command from the device input to the device.

Returns
A response to the command.
template<typename StreamT >
std::string regilo::StreamController< StreamT >::sendCommand ( const std::string &  command)
finaloverridevirtual

Send a command to the device.

Parameters
commandA command with all parameters.
Returns
A string with a whole response to the command.

Implements regilo::IController.

template<typename StreamT >
template<typename Response , typename Command >
Response regilo::StreamController< StreamT >::sendCommand ( const Command &  command)

Send a command to the device.

Parameters
commandA command with all parameters.
Returns
A response to the command.
template<typename StreamT >
template<typename Response , typename Command , typename... Args>
Response regilo::StreamController< StreamT >::sendCommand ( const Command &  command,
const Args &...  params 
)

Send a command to the device.

Parameters
commandA command without parameters.
paramsParameters that will be inserted into the command (separated by space).
Returns
A response to the command.
template<typename StreamT >
template<typename Response , typename... Args>
Response regilo::StreamController< StreamT >::sendFormattedCommand ( const std::string &  commandFormat,
Args...  params 
)

Create a command with the specified parameters (printf formatting is used) and send it to the device.

Parameters
commandFormatA command format without parameters.
paramsParameters that will be inserted into the command.
Returns
A response to the command.
template<typename StreamT >
void regilo::StreamController< StreamT >::setLog ( std::shared_ptr< ILog log)
overridevirtual

Set a Log (it can be shared between more controllers).

Parameters
logSmart pointer to the Log.

Implements regilo::IController.


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