Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RedirectionCommPort.cc

Go to the documentation of this file.
00001 #include "RedirectionCommPort.h"
00002 
00003 using namespace std; 
00004 
00005 RedirectionCommPort::invalid_streambuf RedirectionCommPort::invalid;
00006 const std::string RedirectionCommPort::autoRegisterRedirectionCommPort = CommPort::getRegistry().registerType<RedirectionCommPort>("RedirectionCommPort");
00007 
00008 bool RedirectionCommPort::open() {
00009   if(openedCnt++>0)
00010     return true;
00011   input.addPrimitiveListener(this);
00012   output.addPrimitiveListener(this);
00013   curin=input;
00014   curout=output;
00015   bool ans=true;
00016   if(CommPort * cur=getInputCP())
00017     ans&=cur->open();
00018   if(CommPort * cur=getOutputCP())
00019     ans&=cur->open();
00020   opened();
00021   return ans;
00022 }
00023 
00024 bool RedirectionCommPort::close() {
00025   if(openedCnt==0)
00026     std::cerr << "Warning: RedirectionCommPort close() without open()" << std::endl;
00027   if(--openedCnt>0)
00028     return false;
00029   closing();
00030   input.removePrimitiveListener(this);
00031   output.removePrimitiveListener(this);
00032   bool ans=true;
00033   if(CommPort * cur=getInputCP())
00034     ans&=cur->close();
00035   if(CommPort * cur=getOutputCP())
00036     ans&=cur->close();
00037   return ans;
00038 }
00039 
00040 void RedirectionCommPort::plistValueChanged(const plist::PrimitiveBase& pl) {
00041   if(&pl==&input) {
00042     if(CommPort * prev=getInputCP())
00043       prev->close();
00044     curin=input;
00045     if(CommPort * cur=getInputCP())
00046       cur->open();
00047   } else if(&pl==&output) {
00048     if(CommPort * prev=getOutputCP())
00049       prev->close();
00050     curout=output;
00051     if(CommPort * cur=getOutputCP())
00052       cur->open();
00053   } else {
00054     std::cerr << "Unhandled value change in " << getClassName() << ": " << pl.get() << std::endl;
00055   }
00056 }
00057 
00058 
00059 /*! @file
00060  * @brief 
00061  * @author Ethan Tira-Thompson (ejt) (Creator)
00062  */

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