Index: trunk/libffado/src/genericavc/avc_avdevice.cpp =================================================================== --- trunk/libffado/src/genericavc/avc_avdevice.cpp (revision 589) +++ trunk/libffado/src/genericavc/avc_avdevice.cpp (revision 599) @@ -35,4 +35,6 @@ #include "debugmodule/debugmodule.h" +#include "config.h" + #include #include @@ -50,9 +52,4 @@ IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_VERBOSE ); -// to define the supported devices -static VendorModelEntry supportedDeviceList[] = -{ - -}; AvDevice::AvDevice( Ieee1394Service& ieee1394Service, @@ -78,14 +75,8 @@ unsigned int modelId = configRom.getModelId(); - for ( unsigned int i = 0; - i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) ); - ++i ) - { - if ( ( supportedDeviceList[i].vendor_id == vendorId ) - && ( supportedDeviceList[i].model_id == modelId ) - ) - { - return true; - } + GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_genericavc.txt" ); + if ( vendorModel.parse() ) { + vendorModel.printTable(); + return vendorModel.find( vendorId, modelId ); } @@ -239,7 +230,7 @@ { FFADODevice::showDevice(); - + debugOutput(DEBUG_LEVEL_NORMAL, - "%s %s\n", m_model->vendor_name, m_model->model_name); + "%s %s\n", m_model->vendor_name.c_str(), m_model->model_name.c_str()); AVC::Unit::show(); @@ -418,5 +409,5 @@ ); break; - + case ExtendedPlugInfoClusterInfoSpecificData::ePT_NoType: default: Index: trunk/libffado/src/genericavc/avc_vendormodel.cpp =================================================================== --- trunk/libffado/src/genericavc/avc_vendormodel.cpp (revision 558) +++ trunk/libffado/src/genericavc/avc_vendormodel.cpp (revision 599) @@ -28,4 +28,7 @@ #include #include +#include +#include +#include using namespace std; @@ -52,18 +55,63 @@ } +//------------------------------------------------- + +GenericAVC::VendorModelEntry::VendorModelEntry() + : vendor_id( 0 ) + , model_id( 0 ) +{ +} + +GenericAVC::VendorModelEntry::VendorModelEntry( const VendorModelEntry& rhs ) + : vendor_id( rhs.vendor_id ) + , model_id( rhs.model_id ) + , vendor_name( rhs.vendor_name ) + , model_name( rhs.model_name ) +{ +} + +GenericAVC::VendorModelEntry& +GenericAVC::VendorModelEntry::operator = ( const VendorModelEntry& rhs ) +{ + // check for assignment to self + if ( this == &rhs ) return *this; + + vendor_id = rhs.vendor_id; + model_id = rhs.model_id; + vendor_name = rhs.vendor_name; + model_name = rhs.model_name; + + return *this; +} + +GenericAVC::VendorModelEntry::~VendorModelEntry() +{ +} + GenericAVC::VendorModel::VendorModel( const char* filename ) -{ - ifstream in ( filename ); + : m_filename( filename ) +{ +} + +GenericAVC::VendorModel::~VendorModel() +{ +} + + +bool +GenericAVC::VendorModel::parse() +{ + ifstream in ( m_filename.c_str() ); if ( !in ) { - perror( filename ); - return; - } - - cout << "vendorId\t\tmodelId\t\tvendorName\t\tmodelName" << endl; + perror( m_filename.c_str() ); + return false; + } + string line; while ( !getline( in, line ).eof() ) { string::size_type i = line.find_first_not_of( " \t\n\v" ); if ( i != string::npos && line[i] == '#' ) + // this line starts with a '#' -> comment continue; @@ -71,29 +119,90 @@ tokenize( line, tokens, "," ); - for ( vector::iterator it = tokens.begin(); - it != tokens.end(); - ++it ) - { - string vendorId = *it++; - string modelId = *it++; - string vendorName = *it++; - string modelName= *it; - cout << vendorId << "\t" << modelId << "\t" <::const_iterator it = tokens.begin(); + char* tail; + + errno = 0; + vme.vendor_id = strtol( it++->c_str(), &tail, 0 ); + vme.model_id = strtol( it++->c_str(), &tail, 0 ); + vme.vendor_name = *it++; + vme.model_name = *it++; + + if ( errno ) + // string -> int conversion failed + continue; + + vector::const_iterator end = tokens.end(); + if ( it != end ) + handleAdditionalEntries( vme, tokens, it, end ); + + m_vendorModelEntries.push_back( vme ); } if ( !in.eof() ) { - cout << "GenericAVC::VendorModel::VendorModel: error in parsing" << endl; - } -} - -GenericAVC::VendorModel::~VendorModel() -{ - for ( VendorModelEntryVector::iterator it = m_vendorModelEntries.begin(); + cerr << "GenericAVC::VendorModel::VendorModel: error in parsing" << endl; + return false; + } + + return true; +} + +bool +GenericAVC::VendorModel::printTable() const +{ + // Some debug output + cout << "vendorId\t\tmodelId\t\tvendorName\t\t\t\tmodelName" << endl; + for ( VendorModelEntryVector::const_iterator it = m_vendorModelEntries.begin(); it != m_vendorModelEntries.end(); ++it ) { - delete *it; - } + cout << it->vendor_id << "\t\t\t" + << it->model_id << "\t" + << it->vendor_name << "\t" + << it->model_name << endl; + } + return true; +} + +bool +GenericAVC::VendorModel::handleAdditionalEntries(VendorModelEntry& vme, + vector& v, + vector::const_iterator& b, + vector::const_iterator& e ) +{ + return true; +} + +class is_same : public unary_function { +public: + is_same( unsigned int vendor_id, unsigned model_id ) + : m_vendor_id( vendor_id ) + , m_model_id( model_id ) + {} + + bool operator () ( const GenericAVC::VendorModelEntry& vme ) const { + return vme.vendor_id == m_vendor_id && vme.model_id == m_model_id; + } + +private: + unsigned int m_vendor_id; + unsigned int m_model_id; +}; + +GenericAVC::VendorModelEntry* +GenericAVC::VendorModel::find( unsigned int vendor_id, unsigned model_id ) +{ + VendorModelEntryVector::iterator it = + find_if ( m_vendorModelEntries.begin(), + m_vendorModelEntries.end(), + is_same( vendor_id, model_id ) ); + if ( it != m_vendorModelEntries.end() ) + return &*it; + + return 0; } Index: trunk/libffado/src/genericavc/avc_vendormodel.h =================================================================== --- trunk/libffado/src/genericavc/avc_vendormodel.h (revision 557) +++ trunk/libffado/src/genericavc/avc_vendormodel.h (revision 599) @@ -25,4 +25,5 @@ #define GENERICAVC_VENDORMODEL_H +#include #include @@ -31,19 +32,33 @@ // struct to define the supported devices struct VendorModelEntry { + VendorModelEntry(); + VendorModelEntry(const VendorModelEntry& rhs); + VendorModelEntry& operator = (const VendorModelEntry& rhs); + virtual ~VendorModelEntry(); + unsigned int vendor_id; unsigned int model_id; - char *vendor_name; - char *model_name; + std::string vendor_name; + std::string model_name; }; -typedef std::vector VendorModelEntryVector; +typedef std::vector VendorModelEntryVector; class VendorModel { public: VendorModel( const char* filename ); - ~VendorModel(); + virtual ~VendorModel(); + + virtual bool parse(); + virtual bool printTable() const; + virtual bool handleAdditionalEntries(VendorModelEntry& vme, + std::vector& v, + std::vector::const_iterator& b, + std::vector::const_iterator& e ); + VendorModelEntry* find( unsigned int vendor_id, unsigned model_id ); const VendorModelEntryVector& getVendorModelEntries() const; private: + std::string m_filename; VendorModelEntryVector m_vendorModelEntries; };