Changeset 607

Show
Ignore:
Timestamp:
08/31/07 01:56:53 (16 years ago)
Author:
ppalmers
Message:

- Fix file-based discovery. The previous code used a pointer to a

vendormodel entry. This pointer however pointed to a VendorModel?
object that was created on the stack of the discover function.
Hence the pointer becomes invalid when the discover function is
exited.

The changes incorporate using a VendorModelEntry? struct instead
of a pointer to it. So now the FFADODevice has it's own copy of
this struct, instead of a pointer to it.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/bebob/bebob_avdevice.cpp

    r599 r607  
    7979    if ( vendorModel.parse() ) { 
    8080        vendorModel.printTable(); 
    81         return vendorModel.find( vendorId, modelId ); 
     81        return vendorModel.isPresent( vendorId, modelId ); 
    8282    } 
    8383 
     
    121121    } 
    122122 
    123     if (m_model != NULL) { 
     123    if (GenericAVC::VendorModel::isValid(m_model)) { 
    124124        debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 
    125                      m_model->vendor_name.c_str(), 
    126                      m_model->model_name.c_str()); 
     125                     m_model.vendor_name.c_str(), 
     126                     m_model.model_name.c_str()); 
    127127    } else return false; 
    128128 
  • trunk/libffado/src/fireworks/fireworks_device.cpp

    r599 r607  
    6363    if ( vendorModel.parse() ) { 
    6464        vendorModel.printTable(); 
    65         return vendorModel.find( vendorId, modelId ); 
     65        return vendorModel.isPresent( vendorId, modelId ); 
    6666    } 
    6767 
     
    7575    unsigned int modelId = m_pConfigRom->getModelId(); 
    7676 
    77     GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_bebob.txt" ); 
     77    GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_fireworks.txt" ); 
    7878    if ( vendorModel.parse() ) { 
    7979        m_model = vendorModel.find( vendorId, modelId ); 
    8080    } 
    8181 
    82     if (m_model == NULL) { 
     82    if (!GenericAVC::VendorModel::isValid(m_model)) { 
    8383        return false; 
    8484    } 
    8585    debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 
    86             m_model->vendor_name.c_str(), m_model->model_name.c_str()); 
     86            m_model.vendor_name.c_str(), m_model.model_name.c_str()); 
    8787 
    8888    if ( !GenericAVC::AvDevice::discover() ) { 
  • trunk/libffado/src/genericavc/avc_avdevice.cpp

    r599 r607  
    5656                    std::auto_ptr<ConfigRom>( configRom )) 
    5757    : FFADODevice( ieee1394Service, configRom ) 
    58     , m_model( NULL ) 
    59  
    6058{ 
    6159    debugOutput( DEBUG_LEVEL_VERBOSE, "Created GenericAVC::AvDevice (NodeID %d)\n", 
     
    7876    if ( vendorModel.parse() ) { 
    7977        vendorModel.printTable(); 
    80         return vendorModel.find( vendorId, modelId ); 
     78        return vendorModel.isPresent( vendorId, modelId ); 
    8179    } 
    8280 
     
    9492AvDevice::discover() 
    9593{ 
     94    // check if we already have a valid VendorModel entry 
     95    // e.g. because a subclass called this function 
     96    if (!GenericAVC::VendorModel::isValid(m_model)) { 
     97        unsigned int vendorId = m_pConfigRom->getNodeVendorId(); 
     98        unsigned int modelId = m_pConfigRom->getModelId(); 
     99     
     100        GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_genericavc.txt" ); 
     101        if ( vendorModel.parse() ) { 
     102            m_model = vendorModel.find( vendorId, modelId ); 
     103        } 
     104     
     105        if (!GenericAVC::VendorModel::isValid(m_model)) { 
     106            return false; 
     107        } 
     108        debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 
     109                m_model.vendor_name.c_str(), m_model.model_name.c_str()); 
     110    } 
     111 
    96112    if ( !Unit::discover() ) { 
    97113        debugError( "Could not discover unit\n" ); 
     
    232248 
    233249    debugOutput(DEBUG_LEVEL_NORMAL, 
    234         "%s %s\n", m_model->vendor_name.c_str(), m_model->model_name.c_str()); 
     250        "%s %s\n", m_model.vendor_name.c_str(), m_model.model_name.c_str()); 
    235251 
    236252    AVC::Unit::show(); 
  • trunk/libffado/src/genericavc/avc_avdevice.h

    r583 r607  
    8585                                   AVC::ESamplingFrequency samplingFrequency );*/ 
    8686     
    87     struct VendorModelEntry *m_model; 
     87    struct VendorModelEntry m_model; 
    8888     
    8989    // streaming stuff 
  • trunk/libffado/src/genericavc/avc_vendormodel.cpp

    r599 r607  
    8383 
    8484    return *this; 
     85} 
     86 
     87bool 
     88GenericAVC::VendorModelEntry::operator == ( const VendorModelEntry& rhs ) const 
     89{ 
     90    bool equal=true; 
     91     
     92    equal &= (vendor_id   == rhs.vendor_id); 
     93    equal &= (model_id    == rhs.model_id); 
     94    equal &= (vendor_name == rhs.vendor_name); 
     95    equal &= (model_name  == rhs.model_name); 
     96 
     97    return equal; 
    8598} 
    8699 
     
    194207}; 
    195208 
    196 GenericAVC::VendorModelEntry* 
     209GenericAVC::VendorModelEntry 
    197210GenericAVC::VendorModel::find( unsigned int vendor_id, unsigned model_id ) 
    198211{ 
     
    202215                  is_same( vendor_id, model_id ) ); 
    203216    if ( it != m_vendorModelEntries.end() ) 
    204         return &*it; 
    205  
    206     return 0; 
     217        return *it; 
     218         
     219    struct VendorModelEntry invalid; 
     220    return invalid; 
     221
     222 
     223bool 
     224GenericAVC::VendorModel::isPresent( unsigned int vendor_id, unsigned model_id ) 
     225
     226    VendorModelEntryVector::iterator it = 
     227        find_if ( m_vendorModelEntries.begin(), 
     228                  m_vendorModelEntries.end(), 
     229                  is_same( vendor_id, model_id ) ); 
     230    if ( it != m_vendorModelEntries.end() ) 
     231        return true; 
     232 
     233    return false; 
     234
     235 
     236bool 
     237GenericAVC::VendorModel::isValid( const GenericAVC::VendorModelEntry& vme ) 
     238
     239    struct VendorModelEntry invalid; 
     240    return !(vme==invalid); 
    207241} 
    208242 
  • trunk/libffado/src/genericavc/avc_vendormodel.h

    r599 r607  
    3535    VendorModelEntry(const VendorModelEntry& rhs); 
    3636    VendorModelEntry& operator = (const VendorModelEntry& rhs); 
     37    bool operator == (const VendorModelEntry& rhs) const; 
    3738    virtual ~VendorModelEntry(); 
    3839 
     
    5657                                         std::vector<std::string>::const_iterator& b, 
    5758                                         std::vector<std::string>::const_iterator& e ); 
    58     VendorModelEntry* find( unsigned int vendor_id,  unsigned model_id ); 
     59    VendorModelEntry find( unsigned int vendor_id,  unsigned model_id ); 
     60    bool isPresent( unsigned int vendor_id,  unsigned model_id ); 
     61    static bool isValid( const VendorModelEntry& vme ); 
    5962 
    6063    const VendorModelEntryVector& getVendorModelEntries() const; 
     
    6265    std::string m_filename; 
    6366    VendorModelEntryVector m_vendorModelEntries; 
     67 
    6468}; 
    6569