ofxDepthStream
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions
depth::Receiver Class Reference

Network stream receiver class. More...

#include <Receiver.h>

Inheritance diagram for depth::Receiver:
depth::Buffer

Public Types

typedef std::function< void(const void *data, size_t size)> FrameCallback
 
- Public Types inherited from depth::Buffer
typedef std::function< void(const void *, size_t)> NewDataCallback
 A new data callback takes a void pointer to the memory block and a size_t with the number of bytes in the memory block. More...
 

Public Member Functions

 Receiver ()
 Default constructor; does not start a network client. More...
 
 Receiver (const std::string &host, int port)
 This constructor immediately starts the network client in a separate thread. More...
 
 ~Receiver ()
 
void start ()
 Starts network client, with host and port values provides in the constructor. More...
 
void start (const std::string &host, int port)
 Starts network client with the specified host and port values. More...
 
void stop (bool wait=false)
 Stops network client. More...
 
char * getData ()
 Provides a pointer to the incoming data memory block (never returns NULL) More...
 
int getSize () const
 The size (in number of bytes) of the last package that was received (excluding the 4-byte package header) More...
 
bool hasNew () const
 Whether a new package was received since the last call to reset() More...
 
void reset ()
 Resets the hasNew flag. More...
 
void setConnectAttemptInterval (unsigned int interval)
 Configures the network client to attempt reconnect at the specified interval. More...
 
void setVerbose (bool v)
 Enables/disables verbose logging output. More...
 
void setFrameCallback (FrameCallback func)
 Registers a custom callback for incoming frame-data DEPRECATED: use the inherited Buffer::setOutputTo method. More...
 
- Public Member Functions inherited from depth::Buffer
virtual FrameRef getRef ()
 
virtual void write (FrameRef f)
 Updates the buffer with a new frame (triggers the output callback) More...
 
virtual void write (const void *data, size_t size)
 Updates the buffer with a new frame (triggers the output callback) More...
 
void clear ()
 Clear the buffer (doesn't trigger the output callback) More...
 
void setOutputTo (Buffer *b)
 Registers an output callback that updates the given buffer with this buffer's data whenever this buffer is updated. More...
 

Static Public Member Functions

static ReceiverRef createAndStart (const std::string &host)
 Starts a Receiver instance which tries to connect to a server at the specified address, using the DEFAULT_PORT. More...
 
static ReceiverRef createAndStart (const std::string &host, int port)
 Starts a Receiver instance which tries to connect to a server at the specified address and port. More...
 

Static Public Attributes

static const int DEFAULT_PORT = 4445
 

Protected Member Functions

std::ostream & cout ()
 
std::ostream & cerr ()
 
void error (const char *msg)
 
void threadFunc ()
 
bool connectToServer (const std::string &address, int port)
 
void disconnect ()
 
bool receive (size_t size)
 
bool receive (char *buffer, size_t size)
 
bool receiveInt (int &target)
 
bool send_data (std::string data)
 

Additional Inherited Members

- Protected Attributes inherited from depth::Buffer
NewDataCallback newDataCallback =nullptr
 
FrameRef buffered =nullptr
 

Detailed Description

Network stream receiver class.

The receiver class runs a network client on separate thread, which receives a (compressed) stream of Frames (probably sent by a Transmitter instance). The Receiver class inherits from the Buffer class and thus lets you automatically redirect newly received data using the setOutputTo method.

Member Typedef Documentation

◆ FrameCallback

typedef std::function<void(const void* data, size_t size)> depth::Receiver::FrameCallback

Constructor & Destructor Documentation

◆ Receiver() [1/2]

depth::Receiver::Receiver ( )
inline

Default constructor; does not start a network client.

◆ Receiver() [2/2]

depth::Receiver::Receiver ( const std::string &  host,
int  port 
)
inline

This constructor immediately starts the network client in a separate thread.

◆ ~Receiver()

Receiver::~Receiver ( )

Member Function Documentation

◆ cerr()

std::ostream& depth::Receiver::cerr ( )
inlineprotected

◆ connectToServer()

bool Receiver::connectToServer ( const std::string &  address,
int  port 
)
protected

Referenced by threadFunc().

◆ cout()

std::ostream& depth::Receiver::cout ( )
inlineprotected

◆ createAndStart() [1/2]

static ReceiverRef depth::Receiver::createAndStart ( const std::string &  host)
inlinestatic

Starts a Receiver instance which tries to connect to a server at the specified address, using the DEFAULT_PORT.

◆ createAndStart() [2/2]

static ReceiverRef depth::Receiver::createAndStart ( const std::string &  host,
int  port 
)
inlinestatic

Starts a Receiver instance which tries to connect to a server at the specified address and port.

◆ disconnect()

void Receiver::disconnect ( )
protected

Referenced by stop(), and threadFunc().

◆ error()

void Receiver::error ( const char *  msg)
protected

Referenced by connectToServer().

◆ getData()

char* depth::Receiver::getData ( )
inline

Provides a pointer to the incoming data memory block (never returns NULL)

◆ getSize()

int depth::Receiver::getSize ( ) const
inline

The size (in number of bytes) of the last package that was received (excluding the 4-byte package header)

◆ hasNew()

bool depth::Receiver::hasNew ( ) const
inline

Whether a new package was received since the last call to reset()

◆ receive() [1/2]

bool Receiver::receive ( size_t  size)
protected

Referenced by receiveInt(), and threadFunc().

◆ receive() [2/2]

bool Receiver::receive ( char *  buffer,
size_t  size 
)
protected

◆ receiveInt()

bool Receiver::receiveInt ( int &  target)
protected

Referenced by threadFunc().

◆ reset()

void depth::Receiver::reset ( )
inline

Resets the hasNew flag.

◆ send_data()

bool Receiver::send_data ( std::string  data)
protected

◆ setConnectAttemptInterval()

void depth::Receiver::setConnectAttemptInterval ( unsigned int  interval)
inline

Configures the network client to attempt reconnect at the specified interval.

Parameters
intervalinterval in milliseconds, default is 5000

◆ setFrameCallback()

void depth::Receiver::setFrameCallback ( FrameCallback  func)
inline

Registers a custom callback for incoming frame-data DEPRECATED: use the inherited Buffer::setOutputTo method.

◆ setVerbose()

void depth::Receiver::setVerbose ( bool  v)
inline

Enables/disables verbose logging output.

Parameters
venable or disables

◆ start() [1/2]

void depth::Receiver::start ( )
inline

Starts network client, with host and port values provides in the constructor.

Referenced by Receiver().

◆ start() [2/2]

void Receiver::start ( const std::string &  host,
int  port 
)

Starts network client with the specified host and port values.

◆ stop()

void Receiver::stop ( bool  wait = false)

Stops network client.

Parameters
waitWhen true blocks until the network-client thread has finished. False by default.

Referenced by start(), and ~Receiver().

◆ threadFunc()

void Receiver::threadFunc ( )
protected

Referenced by start().

Field Documentation

◆ DEFAULT_PORT

const int depth::Receiver::DEFAULT_PORT = 4445
static

Referenced by createAndStart().


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