Changeset 599 for trunk/libffado/src/genericavc
- Timestamp:
- 08/29/07 14:17:58 (17 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/src/genericavc/avc_avdevice.cpp
r589 r599 35 35 #include "debugmodule/debugmodule.h" 36 36 37 #include "config.h" 38 37 39 #include <string> 38 40 #include <stdint.h> … … 50 52 IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_VERBOSE ); 51 53 52 // to define the supported devices53 static VendorModelEntry supportedDeviceList[] =54 {55 56 };57 54 58 55 AvDevice::AvDevice( Ieee1394Service& ieee1394Service, … … 78 75 unsigned int modelId = configRom.getModelId(); 79 76 80 for ( unsigned int i = 0; 81 i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) ); 82 ++i ) 83 { 84 if ( ( supportedDeviceList[i].vendor_id == vendorId ) 85 && ( supportedDeviceList[i].model_id == modelId ) 86 ) 87 { 88 return true; 89 } 77 GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_genericavc.txt" ); 78 if ( vendorModel.parse() ) { 79 vendorModel.printTable(); 80 return vendorModel.find( vendorId, modelId ); 90 81 } 91 82 … … 239 230 { 240 231 FFADODevice::showDevice(); 241 232 242 233 debugOutput(DEBUG_LEVEL_NORMAL, 243 "%s %s\n", m_model->vendor_name , m_model->model_name);234 "%s %s\n", m_model->vendor_name.c_str(), m_model->model_name.c_str()); 244 235 245 236 AVC::Unit::show(); … … 418 409 ); 419 410 break; 420 411 421 412 case ExtendedPlugInfoClusterInfoSpecificData::ePT_NoType: 422 413 default: trunk/libffado/src/genericavc/avc_vendormodel.cpp
r558 r599 28 28 #include <iostream> 29 29 #include <iterator> 30 #include <cerrno> 31 #include <functional> 32 #include <algorithm> 30 33 31 34 using namespace std; … … 52 55 } 53 56 57 //------------------------------------------------- 58 59 GenericAVC::VendorModelEntry::VendorModelEntry() 60 : vendor_id( 0 ) 61 , model_id( 0 ) 62 { 63 } 64 65 GenericAVC::VendorModelEntry::VendorModelEntry( const VendorModelEntry& rhs ) 66 : vendor_id( rhs.vendor_id ) 67 , model_id( rhs.model_id ) 68 , vendor_name( rhs.vendor_name ) 69 , model_name( rhs.model_name ) 70 { 71 } 72 73 GenericAVC::VendorModelEntry& 74 GenericAVC::VendorModelEntry::operator = ( const VendorModelEntry& rhs ) 75 { 76 // check for assignment to self 77 if ( this == &rhs ) return *this; 78 79 vendor_id = rhs.vendor_id; 80 model_id = rhs.model_id; 81 vendor_name = rhs.vendor_name; 82 model_name = rhs.model_name; 83 84 return *this; 85 } 86 87 GenericAVC::VendorModelEntry::~VendorModelEntry() 88 { 89 } 90 54 91 GenericAVC::VendorModel::VendorModel( const char* filename ) 55 { 56 ifstream in ( filename ); 92 : m_filename( filename ) 93 { 94 } 95 96 GenericAVC::VendorModel::~VendorModel() 97 { 98 } 99 100 101 bool 102 GenericAVC::VendorModel::parse() 103 { 104 ifstream in ( m_filename.c_str() ); 57 105 58 106 if ( !in ) { 59 perror( filename ); 60 return; 61 } 62 63 cout << "vendorId\t\tmodelId\t\tvendorName\t\tmodelName" << endl; 107 perror( m_filename.c_str() ); 108 return false; 109 } 110 64 111 string line; 65 112 while ( !getline( in, line ).eof() ) { 66 113 string::size_type i = line.find_first_not_of( " \t\n\v" ); 67 114 if ( i != string::npos && line[i] == '#' ) 115 // this line starts with a '#' -> comment 68 116 continue; 69 117 … … 71 119 tokenize( line, tokens, "," ); 72 120 73 for ( vector<string>::iterator it = tokens.begin(); 74 it != tokens.end(); 75 ++it ) 76 { 77 string vendorId = *it++; 78 string modelId = *it++; 79 string vendorName = *it++; 80 string modelName= *it; 81 cout << vendorId << "\t" << modelId << "\t" <<vendorName << "\t" << modelName << endl; 82 } 121 if ( tokens.size() < 4 ) 122 // ignore this line, it has not all needed mandatory entries 123 continue; 124 125 VendorModelEntry vme; 126 vector<string>::const_iterator it = tokens.begin(); 127 char* tail; 128 129 errno = 0; 130 vme.vendor_id = strtol( it++->c_str(), &tail, 0 ); 131 vme.model_id = strtol( it++->c_str(), &tail, 0 ); 132 vme.vendor_name = *it++; 133 vme.model_name = *it++; 134 135 if ( errno ) 136 // string -> int conversion failed 137 continue; 138 139 vector<string>::const_iterator end = tokens.end(); 140 if ( it != end ) 141 handleAdditionalEntries( vme, tokens, it, end ); 142 143 m_vendorModelEntries.push_back( vme ); 83 144 } 84 145 85 146 if ( !in.eof() ) { 86 cout << "GenericAVC::VendorModel::VendorModel: error in parsing" << endl; 87 } 88 } 89 90 GenericAVC::VendorModel::~VendorModel() 91 { 92 for ( VendorModelEntryVector::iterator it = m_vendorModelEntries.begin(); 147 cerr << "GenericAVC::VendorModel::VendorModel: error in parsing" << endl; 148 return false; 149 } 150 151 return true; 152 } 153 154 bool 155 GenericAVC::VendorModel::printTable() const 156 { 157 // Some debug output 158 cout << "vendorId\t\tmodelId\t\tvendorName\t\t\t\tmodelName" << endl; 159 for ( VendorModelEntryVector::const_iterator it = m_vendorModelEntries.begin(); 93 160 it != m_vendorModelEntries.end(); 94 161 ++it ) 95 162 { 96 delete *it; 97 } 163 cout << it->vendor_id << "\t\t\t" 164 << it->model_id << "\t" 165 << it->vendor_name << "\t" 166 << it->model_name << endl; 167 } 168 return true; 169 } 170 171 bool 172 GenericAVC::VendorModel::handleAdditionalEntries(VendorModelEntry& vme, 173 vector<string>& v, 174 vector<string>::const_iterator& b, 175 vector<string>::const_iterator& e ) 176 { 177 return true; 178 } 179 180 class is_same : public unary_function<GenericAVC::VendorModelEntry, bool> { 181 public: 182 is_same( unsigned int vendor_id, unsigned model_id ) 183 : m_vendor_id( vendor_id ) 184 , m_model_id( model_id ) 185 {} 186 187 bool operator () ( const GenericAVC::VendorModelEntry& vme ) const { 188 return vme.vendor_id == m_vendor_id && vme.model_id == m_model_id; 189 } 190 191 private: 192 unsigned int m_vendor_id; 193 unsigned int m_model_id; 194 }; 195 196 GenericAVC::VendorModelEntry* 197 GenericAVC::VendorModel::find( unsigned int vendor_id, unsigned model_id ) 198 { 199 VendorModelEntryVector::iterator it = 200 find_if ( m_vendorModelEntries.begin(), 201 m_vendorModelEntries.end(), 202 is_same( vendor_id, model_id ) ); 203 if ( it != m_vendorModelEntries.end() ) 204 return &*it; 205 206 return 0; 98 207 } 99 208 trunk/libffado/src/genericavc/avc_vendormodel.h
r557 r599 25 25 #define GENERICAVC_VENDORMODEL_H 26 26 27 #include <string> 27 28 #include <vector> 28 29 … … 31 32 // struct to define the supported devices 32 33 struct VendorModelEntry { 34 VendorModelEntry(); 35 VendorModelEntry(const VendorModelEntry& rhs); 36 VendorModelEntry& operator = (const VendorModelEntry& rhs); 37 virtual ~VendorModelEntry(); 38 33 39 unsigned int vendor_id; 34 40 unsigned int model_id; 35 char *vendor_name;36 char *model_name;41 std::string vendor_name; 42 std::string model_name; 37 43 }; 38 44 39 typedef std::vector<VendorModelEntry *> VendorModelEntryVector;45 typedef std::vector<VendorModelEntry> VendorModelEntryVector; 40 46 41 47 class VendorModel { 42 48 public: 43 49 VendorModel( const char* filename ); 44 ~VendorModel(); 50 virtual ~VendorModel(); 51 52 virtual bool parse(); 53 virtual bool printTable() const; 54 virtual bool handleAdditionalEntries(VendorModelEntry& vme, 55 std::vector<std::string>& v, 56 std::vector<std::string>::const_iterator& b, 57 std::vector<std::string>::const_iterator& e ); 58 VendorModelEntry* find( unsigned int vendor_id, unsigned model_id ); 45 59 46 60 const VendorModelEntryVector& getVendorModelEntries() const; 47 61 private: 62 std::string m_filename; 48 63 VendorModelEntryVector m_vendorModelEntries; 49 64 };