$search
00001 #include "Consumer.hpp" 00002 #include <sys/types.h> 00003 #include <sys/stat.h> 00004 #include <fcntl.h> 00005 #include <iostream> 00006 #include <boost/lexical_cast.hpp> 00007 #include <rtt/extras/FileDescriptorActivity.hpp> 00008 00009 using namespace std; 00010 using namespace fd; 00011 00012 Consumer::Consumer(std::string const& name) 00013 : ConsumerBase(name) 00014 , m_fd(-1) 00015 { 00016 // The test suite must create a pipe and give us the FD for the read side 00017 // through the FD_DRIVEN_TEST_FILE environment variable. 00018 char const* fd = getenv("FD_DRIVEN_TEST_FILE"); 00019 if (fd) 00020 m_fd = boost::lexical_cast<int>(fd); 00021 else 00022 std::cerr << "FD_DRIVEN_TEST_FILE is not set" << std::endl; 00023 } 00024 00025 Consumer::~Consumer() 00026 { 00027 close(m_fd); 00028 } 00029 00031 // hooks defined by Orocos::RTT. See Consumer.hpp for more detailed 00032 // documentation about them. 00033 00034 bool Consumer::configureHook() { 00035 if (m_fd != -1) 00036 getActivity<RTT::extras::FileDescriptorActivity>()->watch(m_fd); 00037 return TaskContext::configureHook(); 00038 } 00039 00040 void Consumer::updateHook() 00041 { 00042 static int idx = 'A'; 00043 00044 // We should have one byte on stdin 00045 char byte; 00046 if (read(m_fd, &byte, 1) != 1) 00047 { 00048 cerr << "ERROR: error reading input" << endl; 00049 exit(1); 00050 } 00051 if (byte != idx) 00052 { 00053 cerr << "ERROR: expected " << (char)idx << ", got " << byte << endl; 00054 exit(1); 00055 } 00056 ++idx; 00057 } 00058 00059 // void Consumer::errorHook() {} 00060 // void Consumer::stopHook() {} 00061 // void Consumer::cleanupHook() {} 00062