RedirectionCommPort.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_RedirectionCommPort_h_
00003 #define INCLUDED_RedirectionCommPort_h_
00004
00005 #include "local/CommPort.h"
00006
00007
00008
00009
00010
00011 class RedirectionCommPort : public CommPort, public virtual plist::PrimitiveListener {
00012 public:
00013
00014 explicit RedirectionCommPort(const std::string& name)
00015 : CommPort(autoRegisterRedirectionCommPort,name), input(), output(), curin(), curout(), openedCnt(0)
00016 {
00017 addEntry("Input",input,"Name of comm port from which to get input");
00018 addEntry("Output",output,"Name of comm port into which to send output");
00019 }
00020
00021
00022 virtual ~RedirectionCommPort() {
00023 if(openedCnt>0)
00024 std::cerr << "Still open in RedirectionCommPort destructor" << std::endl;
00025 }
00026
00027 virtual std::string getClassName() const { return autoRegisterRedirectionCommPort; }
00028
00029 virtual streambuf& getReadStreambuf() { CommPort * cp=getInputCP(); return (cp!=NULL) ? cp->getReadStreambuf() : invalid; }
00030 virtual streambuf& getWriteStreambuf() { CommPort * cp=getOutputCP(); return (cp!=NULL) ? cp->getWriteStreambuf() : invalid; }
00031 virtual bool isReadable() { CommPort * cp=getInputCP(); return (cp!=NULL) ? cp->isReadable() : false; }
00032 virtual bool isWriteable() { CommPort * cp=getOutputCP(); return (cp!=NULL) ? cp->isWriteable() : false; }
00033
00034 virtual bool open();
00035 virtual bool close();
00036
00037
00038 virtual void plistValueChanged(const plist::PrimitiveBase& pl);
00039
00040 plist::Primitive<std::string> input;
00041 plist::Primitive<std::string> output;
00042
00043 protected:
00044
00045 CommPort * getInputCP() { return (curin.size()==0) ? NULL : CommPort::getRegistry().getInstance(curin); }
00046
00047 CommPort * getOutputCP() { return (curout.size()==0) ? NULL : CommPort::getRegistry().getInstance(curout); }
00048
00049 std::string curin;
00050 std::string curout;
00051 unsigned int openedCnt;
00052
00053
00054 class invalid_streambuf : public std::streambuf {};
00055
00056 static invalid_streambuf invalid;
00057
00058
00059 static const std::string autoRegisterRedirectionCommPort;
00060 };
00061
00062
00063
00064
00065
00066
00067 #endif