Generic hardware access library
|
00001 #include "hal/AddressTable.hh" 00002 #include <sstream> 00003 00004 HAL::AddressTable::AddressTable( std::string name ) 00005 : name(name) { 00006 } 00007 00008 HAL::AddressTable::AddressTable( const HAL::AddressTable& original ) { 00009 __gnu_cxx::hash_map< std::string, HAL::AddressTableItem*, HAL::HalHash<std::string> >::const_iterator it; 00010 for ( it = original.itemMap.begin(); it != original.itemMap.end(); it++ ) { 00011 std::string key = (*it).first; 00012 HAL::AddressTableItem* itemPtr = (*it).second; 00013 HAL::AddressTableItem* clonePtr = new HAL::AddressTableItem( *itemPtr ); 00014 this->itemMap[key] = clonePtr; 00015 } 00016 } 00017 00018 HAL::AddressTable::~AddressTable() { 00019 __gnu_cxx::hash_map< std::string, HAL::AddressTableItem*, HAL::HalHash<std::string> >::iterator it; 00020 for ( it = itemMap.begin(); it != itemMap.end(); it++ ) { 00021 delete (*it).second; 00022 } 00023 } 00024 00025 const HAL::GeneralHardwareAddress& 00026 HAL::AddressTable::getGeneralHardwareAddress( std::string item ) const 00027 throw( HAL::NoSuchItemException ){ 00028 return checkItem( item ).getGeneralHardwareAddress(); 00029 } 00030 00031 const HAL::GeneralHardwareAddress& 00032 HAL::AddressTable::getWritableHardwareAddress( std::string item ) const 00033 throw (HAL::NoSuchItemException, HAL::IllegalOperationException) { 00034 const HAL::AddressTableItem& addressItem = 00035 checkItem( item ); 00036 if (! addressItem.isWritable() ) { 00037 std::stringstream text; 00038 text << "Try to write to non writable item!" 00039 << "\n TableName : " << getName() 00040 << "\n Item : " << item 00041 << "\n (HAL::HardwareDevice::getWritableHardwareAddress)" << std::ends; 00042 std::string textStr = text.str(); 00043 throw (HAL::IllegalOperationException( textStr, __FILE__, __LINE__, __FUNCTION__ )); 00044 } 00045 return addressItem.getGeneralHardwareAddress(); 00046 } 00047 00048 const HAL::GeneralHardwareAddress& 00049 HAL::AddressTable::getReadableHardwareAddress( std::string item ) const 00050 throw (HAL::NoSuchItemException, HAL::IllegalOperationException) { 00051 const HAL::AddressTableItem& addressItem = 00052 checkItem( item ); 00053 if (! addressItem.isReadable() ) { 00054 std::stringstream text; 00055 text << "Try to read from non readable item!" 00056 << "\n TableName : " << getName() 00057 << "\n Item : " << item 00058 << "\n (HAL::HardwareDevice::getReadableHardwareAddress)" << std::ends; 00059 std::string textStr = text.str(); 00060 throw (HAL::IllegalOperationException( textStr, __FILE__, __LINE__, __FUNCTION__ )); 00061 } 00062 return addressItem.getGeneralHardwareAddress(); 00063 } 00064 00065 std::string HAL::AddressTable::getDescription( std::string item ) const 00066 throw (HAL::NoSuchItemException) { 00067 return checkItem( item ).getDescription(); 00068 } 00069 00070 bool HAL::AddressTable::isReadable( std::string item ) const 00071 throw (HAL::NoSuchItemException) { 00072 return checkItem( item ).isReadable(); 00073 } 00074 00075 bool HAL::AddressTable::isWritable( std::string item ) const 00076 throw( HAL::NoSuchItemException ) { 00077 return checkItem( item ).isWritable(); 00078 } 00079 00080 uint32_t HAL::AddressTable::getMask( std::string item ) const 00081 throw( HAL::NoSuchItemException ) { 00082 return checkItem( item ).getMask(); 00083 } 00084 00085 bool HAL::AddressTable::isBit( std::string item ) const 00086 throw( HAL::NoSuchItemException ) { 00087 return checkItem( item ).isBit(); 00088 } 00089 00090 bool HAL::AddressTable::exists( std::string item ) const { 00091 if ( itemMap.count(item) != 0 ) { 00092 return true; 00093 } else { 00094 return false; 00095 } 00096 } 00097 00098 const HAL::AddressTableItem& HAL::AddressTable::checkItem( std::string item ) const 00099 throw( HAL::NoSuchItemException ) { 00100 __gnu_cxx::hash_map< std::string, HAL::AddressTableItem*, HAL::HalHash<std::string> >::const_iterator it; 00101 if ( (it = itemMap.find(item)) == itemMap.end() ) { 00102 std::string text = "Item \"" + item + "\" not found.\n (HAL::AddressTable::checkItem)"; 00103 throw (HAL::NoSuchItemException(text, __FILE__, __LINE__, __FUNCTION__ )) ; 00104 } 00105 return(*((*it).second) ); 00106 } 00107 00108 __gnu_cxx::hash_map<std::string, HAL::AddressTableItem*, HAL::HalHash<std::string> >::const_iterator 00109 HAL::AddressTable::getItemListBegin() const { 00110 __gnu_cxx::hash_map< std::string, HAL::AddressTableItem*, HAL::HalHash<std::string> >::const_iterator it; 00111 it = itemMap.begin(); 00112 return it; 00113 } 00114 00115 __gnu_cxx::hash_map<std::string, HAL::AddressTableItem*, HAL::HalHash<std::string> >::const_iterator 00116 HAL::AddressTable::getItemListEnd() const { 00117 __gnu_cxx::hash_map< std::string, HAL::AddressTableItem*, HAL::HalHash<std::string> >::const_iterator it; 00118 it = itemMap.end(); 00119 return it; 00120 } 00121 00122 uint32_t HAL::AddressTable::applyToMask( std::string item, 00123 uint32_t data, 00124 bool MaskBoundaryCheck ) const 00125 throw( HAL::NoSuchItemException, HAL::MaskBoundaryException ) { 00126 return checkItem( item ).applyToMask( data, MaskBoundaryCheck ); 00127 } 00128 00129 uint32_t HAL::AddressTable::applyFromMask( std::string item, 00130 uint32_t data, 00131 bool MaskBoundaryCheck ) const 00132 throw( HAL::NoSuchItemException, HAL::MaskBoundaryException ) { 00133 return checkItem( item ).applyFromMask( data, MaskBoundaryCheck ); 00134 }