Show
Ignore:
Timestamp:
08/29/07 14:17:58 (17 years ago)
Author:
wagi
Message:

Instead of static compiled in vendor/model table use configuration files.

Maybe needs some more cleanup but I wanted to check in this baby before
someone else screws me up with some majors changes in the repos :)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/genericavc/avc_avdevice.cpp

    r589 r599  
    3535#include "debugmodule/debugmodule.h" 
    3636 
     37#include "config.h" 
     38 
    3739#include <string> 
    3840#include <stdint.h> 
     
    5052IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_VERBOSE ); 
    5153 
    52 // to define the supported devices 
    53 static VendorModelEntry supportedDeviceList[] = 
    54 { 
    55  
    56 }; 
    5754 
    5855AvDevice::AvDevice( Ieee1394Service& ieee1394Service, 
     
    7875    unsigned int modelId = configRom.getModelId(); 
    7976 
    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 ); 
    9081    } 
    9182 
     
    239230{ 
    240231    FFADODevice::showDevice(); 
    241      
     232 
    242233    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()); 
    244235 
    245236    AVC::Unit::show(); 
     
    418409                ); 
    419410                break; 
    420                  
     411 
    421412            case ExtendedPlugInfoClusterInfoSpecificData::ePT_NoType: 
    422413            default: 
  • trunk/libffado/src/genericavc/avc_vendormodel.cpp

    r558 r599  
    2828#include <iostream> 
    2929#include <iterator> 
     30#include <cerrno> 
     31#include <functional> 
     32#include <algorithm> 
    3033 
    3134using namespace std; 
     
    5255} 
    5356 
     57//------------------------------------------------- 
     58 
     59GenericAVC::VendorModelEntry::VendorModelEntry() 
     60    : vendor_id( 0 ) 
     61    , model_id( 0 ) 
     62{ 
     63} 
     64 
     65GenericAVC::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 
     73GenericAVC::VendorModelEntry& 
     74GenericAVC::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 
     87GenericAVC::VendorModelEntry::~VendorModelEntry() 
     88{ 
     89} 
     90 
    5491GenericAVC::VendorModel::VendorModel( const char* filename ) 
    55 
    56     ifstream in ( filename ); 
     92    : m_filename( filename ) 
     93
     94
     95 
     96GenericAVC::VendorModel::~VendorModel() 
     97
     98
     99 
     100 
     101bool 
     102GenericAVC::VendorModel::parse() 
     103
     104    ifstream in ( m_filename.c_str() ); 
    57105 
    58106    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 
    64111    string line; 
    65112    while ( !getline( in,  line ).eof() ) { 
    66113        string::size_type i = line.find_first_not_of( " \t\n\v" ); 
    67114        if ( i != string::npos && line[i] == '#' ) 
     115            // this line starts with a '#' -> comment 
    68116            continue; 
    69117 
     
    71119        tokenize( line, tokens, "," ); 
    72120 
    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 ); 
    83144    } 
    84145 
    85146    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 
     154bool 
     155GenericAVC::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(); 
    93160          it != m_vendorModelEntries.end(); 
    94161          ++it ) 
    95162    { 
    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 
     171bool 
     172GenericAVC::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 
     180class is_same : public unary_function<GenericAVC::VendorModelEntry, bool> { 
     181public: 
     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 
     191private: 
     192    unsigned int m_vendor_id; 
     193    unsigned int m_model_id; 
     194}; 
     195 
     196GenericAVC::VendorModelEntry* 
     197GenericAVC::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; 
    98207} 
    99208 
  • trunk/libffado/src/genericavc/avc_vendormodel.h

    r557 r599  
    2525#define GENERICAVC_VENDORMODEL_H 
    2626 
     27#include <string> 
    2728#include <vector> 
    2829 
     
    3132// struct to define the supported devices 
    3233struct VendorModelEntry { 
     34    VendorModelEntry(); 
     35    VendorModelEntry(const VendorModelEntry& rhs); 
     36    VendorModelEntry& operator = (const VendorModelEntry& rhs); 
     37    virtual ~VendorModelEntry(); 
     38 
    3339    unsigned int vendor_id; 
    3440    unsigned int model_id; 
    35     char *vendor_name; 
    36     char *model_name; 
     41    std::string vendor_name; 
     42    std::string model_name; 
    3743}; 
    3844 
    39 typedef std::vector<VendorModelEntry*> VendorModelEntryVector; 
     45typedef std::vector<VendorModelEntry> VendorModelEntryVector; 
    4046 
    4147class VendorModel { 
    4248public: 
    4349    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 ); 
    4559 
    4660    const VendorModelEntryVector& getVendorModelEntries() const; 
    4761private: 
     62    std::string m_filename; 
    4863    VendorModelEntryVector m_vendorModelEntries; 
    4964};