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(opened++>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   return ans;
00021 }
00022 
00023 bool RedirectionCommPort::close() {
00024   if(opened==0)
00025     std::cerr << "Warning: RedirectionCommPort close() without open()" << std::endl;
00026   if(--opened>0)
00027     return false;
00028   input.removePrimitiveListener(this);
00029   output.removePrimitiveListener(this);
00030   bool ans=true;
00031   if(CommPort * cur=getInputCP())
00032     ans&=cur->close();
00033   if(CommPort * cur=getOutputCP())
00034     ans&=cur->close();
00035   return ans;
00036 }
00037 
00038 void RedirectionCommPort::plistValueChanged(const plist::PrimitiveBase& pl) {
00039   if(&pl==&input) {
00040     if(CommPort * prev=getInputCP())
00041       prev->close();
00042     curin=input;
00043     if(CommPort * cur=getInputCP())
00044       cur->open();
00045   } else if(&pl==&output) {
00046     if(CommPort * prev=getOutputCP())
00047       prev->close();
00048     curout=output;
00049     if(CommPort * cur=getOutputCP())
00050       cur->open();
00051   } else {
00052     std::cerr << "Unhandled value change in " << getClassName() << ": " << pl.get() << std::endl;
00053   }
00054 }
00055 
00056 
00057 /*! @file
00058  * @brief 
00059  * @author Ethan Tira-Thompson (ejt) (Creator)
00060  *
00061  * $Author: ejt $
00062  * $Name: tekkotsu-4_0 $
00063  * $Revision: 1.1 $
00064  * $State: Exp $
00065  * $Date: 2007/06/03 17:03:36 $
00066  */

Tekkotsu Hardware Abstraction Layer 4.0
Generated Thu Nov 22 01:00:53 2007 by Doxygen 1.5.4