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
00017
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
00032
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
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 }
00057
00058
00059
00060
00061