Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RedirectionCommPort Class Reference

Allows you to recombine the input/output of other CommPorts in various ways. More...

#include <RedirectionCommPort.h>

Inheritance diagram for RedirectionCommPort:

Detailed Description

Allows you to recombine the input/output of other CommPorts in various ways.

This will take input from one CommPort, and can send output to a different CommPort. It's not a 'pipe' from the input to the output, it just changes where the inputs and outputs are coming from.

Definition at line 11 of file RedirectionCommPort.h.

List of all members.

Classes

class  invalid_streambuf
 std::streambuf uses a protected constructor, so we have to inherit to make an empty streambuf for invalid More...

Public Member Functions

 RedirectionCommPort (const std::string &name)
 constructor
virtual ~RedirectionCommPort ()
 destructor, checks that the file descriptor has already been closed
virtual std::string getClassName () const
 Returns the name of the class (aka its type).
virtual streambufgetReadStreambuf ()
 Returns a std::basic_streambuf, which is expected to implement the actual work.
virtual streambufgetWriteStreambuf ()
 Returns a std::basic_streambuf, which is expected to implement the actual work.
virtual bool isReadable ()
 Allows you to check whether the reference from getReadStreambuf() is currently functional (if checking is supported!).
virtual bool isWriteable ()
 Allows you to check whether the reference from getWriteStreambuf() is currently functional (if checking is supported!).
virtual bool open ()
 Called when communication is about to begin, should handle recursive open/close calls.
virtual bool close ()
 Called when communication is complete, should handle recursive open/close calls.
virtual void plistValueChanged (const plist::PrimitiveBase &pl)
 watches input and output, triggers a close() and re-open() as needed

Public Attributes

plist::Primitive< std::string > input
 Name of comm port from which to get input.
plist::Primitive< std::string > output
 Name of comm port into which to send output.

Protected Member Functions

CommPortgetInputCP ()
 convenience function to lookup the current input comm port instance
CommPortgetOutputCP ()
 convenience function to lookup the current output comm port instance

Protected Attributes

std::string curin
 name of the current input comm port (stored separately from input so if that changes, we can close the old one)
std::string curout
 name of the current output comm port (stored separately from output so if that changes, we can close the old one)
unsigned int openedCnt
 open() call depth, tracks multiple usage

Static Protected Attributes

static invalid_streambuf invalid
 needed so we have something to return when the RedirectionCommPort doesn't have a valid external comm port to take a streambuf from
static const std::string autoRegisterRedirectionCommPort = CommPort::getRegistry().registerType<RedirectionCommPort>("RedirectionCommPort")
 holds the class name, set via registration with the CommPort registry

Constructor & Destructor Documentation

RedirectionCommPort ( const std::string &  name  )  [explicit]

constructor

Definition at line 14 of file RedirectionCommPort.h.

virtual ~RedirectionCommPort (  )  [virtual]

destructor, checks that the file descriptor has already been closed

Definition at line 22 of file RedirectionCommPort.h.


Member Function Documentation

bool close (  )  [virtual]

Called when communication is complete, should handle recursive open/close calls.

Returns:
true if successful, false if still open (in use elsewhere)

Implements CommPort.

Definition at line 24 of file RedirectionCommPort.cc.

virtual std::string getClassName (  )  const [virtual]

Returns the name of the class (aka its type).

Suggested implementation is to declare a static string member, set it to the result of calling the registry's registerType, and then return that member here

Implements CommPort.

Definition at line 27 of file RedirectionCommPort.h.

Referenced by plistValueChanged().

CommPort* getInputCP (  )  [protected]

convenience function to lookup the current input comm port instance

Definition at line 45 of file RedirectionCommPort.h.

Referenced by close(), getReadStreambuf(), isReadable(), open(), and plistValueChanged().

CommPort* getOutputCP (  )  [protected]

convenience function to lookup the current output comm port instance

Definition at line 47 of file RedirectionCommPort.h.

Referenced by close(), getWriteStreambuf(), isWriteable(), open(), and plistValueChanged().

virtual streambuf& getReadStreambuf (  )  [virtual]

Returns a std::basic_streambuf, which is expected to implement the actual work.

You can pass this to an istream to use the nice C++ style input and output, or you can call the streambuf functions directly. However, if you're going the latter route, probably easier to just call CommPort's own read() and write().

Depending on implementation, the streambuf this returns might be a different instance than getWriteStreambuf. If they are the same instance, then you could use an iostream instead of separate istream and ostream.

Implements CommPort.

Definition at line 29 of file RedirectionCommPort.h.

virtual streambuf& getWriteStreambuf (  )  [virtual]

Returns a std::basic_streambuf, which is expected to implement the actual work.

You can pass this to an ostream to use the nice C++ style input and output, or you can call the streambuf functions directly. However, if you're going the latter route, probably easier to just call CommPort's own read() and write().

Depending on implementation, the streambuf this returns might be a different instance than getReadStreambuf. If they are the same instance, then you could use an iostream instead of separate istream and ostream.

Implements CommPort.

Definition at line 30 of file RedirectionCommPort.h.

virtual bool isReadable (  )  [virtual]

Allows you to check whether the reference from getReadStreambuf() is currently functional (if checking is supported!).

For streambufs which don't have a way to check this, always returns true.

Reimplemented from CommPort.

Definition at line 31 of file RedirectionCommPort.h.

virtual bool isWriteable (  )  [virtual]

Allows you to check whether the reference from getWriteStreambuf() is currently functional (if checking is supported!).

For streambufs which don't have a way to check this, always returns true.

Reimplemented from CommPort.

Definition at line 32 of file RedirectionCommPort.h.

bool open (  )  [virtual]

Called when communication is about to begin, should handle recursive open/close calls.

The subclass is expected to have its own configuration settings which define the parameters of what is to be "opened". Hence, no arguments are passed.

You should be able to handle recursive levels of open/close in case multiple drivers are using the same CommPort.

Returns:
true if successful (or already open)

Implements CommPort.

Definition at line 8 of file RedirectionCommPort.cc.

void plistValueChanged ( const plist::PrimitiveBase pl  )  [virtual]

watches input and output, triggers a close() and re-open() as needed

Implements PrimitiveListener.

Definition at line 40 of file RedirectionCommPort.cc.


Member Data Documentation

const std::string autoRegisterRedirectionCommPort = CommPort::getRegistry().registerType<RedirectionCommPort>("RedirectionCommPort") [static, protected]

holds the class name, set via registration with the CommPort registry

Definition at line 59 of file RedirectionCommPort.h.

Referenced by getClassName().

std::string curin [protected]

name of the current input comm port (stored separately from input so if that changes, we can close the old one)

Definition at line 49 of file RedirectionCommPort.h.

Referenced by getInputCP(), open(), and plistValueChanged().

std::string curout [protected]

name of the current output comm port (stored separately from output so if that changes, we can close the old one)

Definition at line 50 of file RedirectionCommPort.h.

Referenced by getOutputCP(), open(), and plistValueChanged().

plist::Primitive<std::string> input

Name of comm port from which to get input.

Definition at line 40 of file RedirectionCommPort.h.

Referenced by close(), open(), plistValueChanged(), and RedirectionCommPort().

needed so we have something to return when the RedirectionCommPort doesn't have a valid external comm port to take a streambuf from

Definition at line 56 of file RedirectionCommPort.h.

Referenced by getReadStreambuf(), and getWriteStreambuf().

unsigned int openedCnt [protected]

open() call depth, tracks multiple usage

Definition at line 51 of file RedirectionCommPort.h.

Referenced by close(), open(), and ~RedirectionCommPort().

plist::Primitive<std::string> output

Name of comm port into which to send output.

Definition at line 41 of file RedirectionCommPort.h.

Referenced by close(), open(), plistValueChanged(), and RedirectionCommPort().


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

Tekkotsu Hardware Abstraction Layer 5.1CVS
Generated Mon May 9 05:01:41 2016 by Doxygen 1.6.3