Generic hardware access library
/home/cschwick/hal/generic/src/common/CommandSequencer.cc
Go to the documentation of this file.
00001 #include "hal/CommandSequencer.hh"
00002 
00003 
00004 void HAL::CommandSequencer::registerSequence( HAL::CommandSequence& sequence ) {
00005   sequenceMap[ sequence.getName() ] = &sequence;
00006 }
00007 
00008 void HAL::CommandSequencer::run( std::string sequenceName,
00009                             const HAL::HardwareDeviceInterface& device ) const
00010   throw( HAL::IllegalValueException, 
00011          HAL::SequencerSyntaxError,
00012          HAL::IllegalOperationException,
00013          HAL::BusAdapterException,
00014          HAL::MaskBoundaryException,
00015          HAL::TimeoutException ) {
00016   std::map<std::string, HAL::CommandSequence*>::const_iterator it;
00017   if ( (it = sequenceMap.find( sequenceName )) == sequenceMap.end() ) {
00018     std::string text = "No such Sequence registered : " + sequenceName +
00019       "\n    (HAL::CommandSequencer::registerSequence)";
00020     throw( HAL::IllegalValueException( text, __FILE__, __LINE__, __FUNCTION__ ) );
00021   }
00022   (*it).second->run( device );
00023 }
00024 
00025 std::vector<std::string> HAL::CommandSequencer::getNameVector() const {
00026   std::vector<std::string> nameVector;
00027   std::map< std::string, HAL::CommandSequence* >::const_iterator it;
00028   for ( it=sequenceMap.begin(); it != sequenceMap.end(); it++ ) {
00029     nameVector.push_back( (*it).first );
00030   }
00031   return nameVector;
00032 }
00033 
00034 void HAL::CommandSequencer::deleteSequence( std::string sequenceName) 
00035   throw( HAL::IllegalValueException ) {
00036   std::map< std::string, HAL::CommandSequence* >::iterator it;
00037   if ( (it=sequenceMap.find( sequenceName )) == sequenceMap.end() ) {
00038     std::string text = "No such Sequence registered : " + sequenceName +
00039       "\n    (HAL::CommandSequencer::registerSequence)";
00040     throw( HAL::IllegalValueException( text, __FILE__, __LINE__, __FUNCTION__ ) );
00041   }
00042   delete( (*it).second );
00043   sequenceMap.erase(it);
00044 }
00045 
00046 void HAL::CommandSequencer::deleteSequences() {
00047   std::map< std::string, HAL::CommandSequence* >::iterator it;
00048   for ( it=sequenceMap.begin(); it != sequenceMap.end(); it++ ) {
00049     delete( (*it).second );
00050     sequenceMap.erase(it);
00051   }  
00052 }
00053 
00054 void HAL::CommandSequencer::rescan( std::string sequenceName )
00055   throw (HAL::IllegalValueException,
00056          HAL::NoSuchItemException,
00057          HAL::SequencerSyntaxError ) {
00058   if ( sequenceMap.find( sequenceName ) == sequenceMap.end() ) {
00059     std::string text = "No such Sequence registered : " + sequenceName +
00060       "\n    (HAL::CommandSequencer::rescan)";
00061     throw( HAL::IllegalValueException( text, __FILE__, __LINE__, __FUNCTION__ ) );
00062   }
00063   sequenceMap[ sequenceName ]->rescan();
00064 }
00065 
00066 
00067 HAL::CommandSequence& HAL::CommandSequencer::getSequence( std::string sequenceName) 
00068   throw( HAL::IllegalValueException ) {
00069     std::map< std::string, HAL::CommandSequence* >::iterator it;
00070     if ( (it=sequenceMap.find( sequenceName )) == sequenceMap.end() ) {
00071       std::string text = "No such Sequence registered : " + sequenceName +
00072         "\n    (HAL::CommandSequencer::registerSequence)";
00073       throw( HAL::IllegalValueException( text, __FILE__, __LINE__, __FUNCTION__ ) );
00074     }
00075     return *sequenceMap[ sequenceName ];
00076 }