Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FileSystemCommPort.cc

Go to the documentation of this file.
00001 #include "FileSystemCommPort.h"
00002 
00003 const std::string FileSystemCommPort::autoRegisterFileSystemCommPort = CommPort::getRegistry().registerType<FileSystemCommPort>("FileSystemCommPort");
00004 
00005 bool FileSystemCommPort::open() {
00006   if(opened++>0)
00007     return true;
00008   path.addPrimitiveListener(this);
00009   mode.addPrimitiveListener(this);
00010   curloc=path;
00011   curmode=static_cast<std::ios_base::openmode>((int)mode);
00012   bool ans=true;
00013   if(mode & std::ios_base::in) {
00014     if(rbuf.open(path.c_str(),curmode & ~(std::ios_base::out | std::ios_base::trunc))==NULL) {
00015       connectionError("Could not open file system path for reading "+path,true);
00016       ans=false;
00017     }
00018   }
00019   if(mode & std::ios_base::out) {
00020     if(wbuf.open(path.c_str(),curmode & ~std::ios_base::in)==NULL) {
00021       connectionError("Could not open file system path for writing "+path,true);
00022       ans=false;
00023     }
00024   }
00025   return ans;
00026 }
00027 
00028 bool FileSystemCommPort::close() {
00029   if(opened==0)
00030     std::cerr << "Warning: FileSystemCommPort close() without open()" << std::endl;
00031   if(--opened>0)
00032     return false;
00033   path.removePrimitiveListener(this);
00034   mode.removePrimitiveListener(this);
00035   bool rc = (rbuf.close()!=NULL);
00036   bool wc = (wbuf.close()!=NULL);
00037   return rc && wc;
00038 }
00039 
00040 void FileSystemCommPort::plistValueChanged(const plist::PrimitiveBase& pl) {
00041   if(&pl==&path) {
00042     if(path!=curloc) {
00043       unsigned int ref=opened;
00044       while(opened)
00045         close();
00046       while(opened<ref)
00047         open();
00048     }
00049   } else if(&pl==&mode) {
00050     if(mode!=curmode) {
00051       std::cerr << "Cannot change access mode while file is open" << std::endl;
00052     }
00053   } else {
00054     std::cerr << "Unhandled value change in " << getClassName() << ": " << pl.get() << std::endl;
00055   }
00056 }
00057 
00058 /*! @file
00059  * @brief 
00060  * @author Ethan Tira-Thompson (ejt) (Creator)
00061  *
00062  * $Author: ejt $
00063  * $Name: tekkotsu-4_0 $
00064  * $Revision: 1.2 $
00065  * $State: Exp $
00066  * $Date: 2007/06/18 21:47:20 $
00067  */

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