Generic hardware access library
/home/cschwick/hal/generic/src/common/CheckCommand.cc
Go to the documentation of this file.
00001 #include "hal/CheckCommand.hh"
00002 #include <sstream>
00003 #include <iomanip>
00004 
00005 HAL::CheckCommand::CheckCommand( std::string item, 
00006                                  HAL::CommandSequence& sequence )
00007   : sequence(sequence),
00008     item( item ) {
00009   offsetPtr = &offset;
00010   expectationPtr = &expectation;
00011   offset = 0;
00012 }
00013 
00014 void HAL::CheckCommand::excecute( const HAL::HardwareDeviceInterface& device ) const
00015   throw( HAL::IllegalOperationException,
00016          HAL::BusAdapterException ) {
00017   std::string failMessage = "";
00018   if ( failMessageList.size() > 0 ) {
00019     std::list< std::string >::const_iterator it;
00020     std::stringstream text;
00021     for ( it = failMessageList.begin(); it!=failMessageList.end(); it++ ) {
00022       if ( (*it)[0] == '$' ) {
00023         uint32_t value = sequence.getVariable(*it);
00024         text << value << " ";
00025       } else if ( (*it)[0] == '%' ) {
00026         if ( *it == "%hex" ) {
00027           text << std::hex << std::setw(8) << std::setfill('0');
00028         } else if ( *it == "%dec" ) {
00029           text << std::dec;
00030         } else {
00031           text << *it << " ";
00032         }
00033       } else {
00034         text << *it << " ";
00035       }
00036     }
00037     text << std::ends;
00038     failMessage = text.str();
00039   }
00040   device.check( item, *expectationPtr, failMessage, *offsetPtr );
00041 }
00042 
00043 void HAL::CheckCommand::setOffset( uint32_t offset ) {
00044   this->offset = offset;
00045 }
00046 
00047 void HAL::CheckCommand::setExpectation( uint32_t expectation ) {
00048   this->expectation = expectation;
00049 }
00050 
00051 void HAL::CheckCommand::setOffsetPointer( uint32_t* offsetPtr ) {
00052   this->offsetPtr = offsetPtr;
00053 }
00054 
00055 void HAL::CheckCommand::setExpectationPointer( uint32_t* expectationPtr ) {
00056   this->expectationPtr = expectationPtr;
00057 }
00058 
00059 void HAL::CheckCommand::setFailMessage( std::list<std::string>  failMessageList ) {
00060   this->failMessageList = failMessageList;
00061 }