21#undef ZYPP_BASE_LOGGER_LOGGROUP 
   22#define ZYPP_BASE_LOGGER_LOGGROUP "MODALIAS" 
   26#include <zypp-core/base/InputStream> 
   44      inline bool isBlackListed( 
const Pathname & dir_r, 
const char * file_r )
 
   46#define PATH_IS( D, F ) ( ::strcmp( file_r, F ) == 0 && ::strcmp( dir_r.c_str(), D ) == 0 ) 
   50            return PATH_IS( 
"/sys/devices/system", 
"memory" );   
 
   57      void foreach_file_recursive( 
const Pathname & dir_r, std::set<std::string> & arg_r )
 
   59        AutoDispose<DIR *> dir( ::opendir( dir_r.c_str() ), ::closedir );
 
   63        struct dirent * dirent = NULL;
 
   64        while ( (dirent = ::readdir(dir)) != NULL )
 
   66          if ( dirent->d_name[0] == 
'.' )
 
   69          if ( isBlackListed( dir_r, dirent->d_name ) )
 
   73          unsigned char d_type = dirent->d_type;
 
   74          if ( d_type == DT_UNKNOWN )
 
   76            path = dir_r/dirent->d_name;
 
   80            else if ( pi.isFile() )
 
   84          if ( d_type == DT_DIR )
 
   87              path = dir_r/dirent->d_name;
 
   88            foreach_file_recursive( path, arg_r );
 
   90          else if ( d_type == DT_REG && ::strcmp( dirent->d_name, 
"modalias" ) == 0 )
 
   93              path = dir_r/dirent->d_name;
 
   95            std::ifstream 
str( path.c_str() );
 
  106        std::set<std::string> arg;      
 
  107        foreach_file_recursive( dir_r, arg );
 
  108        arg_r.insert( arg_r.end(), arg.begin(), arg.end() );
 
  123        const char * dir = getenv(
"ZYPP_MODALIAS_SYSFS");
 
  132            DBG << 
"Using $ZYPP_MODALIAS_SYSFS modalias file: " << dir << endl;
 
  134                                [&]( 
int num_r, 
const std::string& line_r )->bool
 
  136                                  this->_modaliases.push_back( line_r );
 
  141          DBG << 
"Using $ZYPP_MODALIAS_SYSFS: " << dir << endl;
 
  146          DBG << 
"Using /sys directory." << endl;
 
 
  174      bool query( 
const char * cap_r )
 const 
  176        if ( cap_r && *cap_r )
 
  180            if ( fnmatch( cap_r, (*it).c_str(), 0 ) == 0 )
 
 
 
  230    { 
return _pimpl->query( cap_r ); }
 
 
  233    { 
return _pimpl->_modaliases; }
 
 
  236    { 
_pimpl->_modaliases.swap( newlist_r ); }
 
 
Wrapper class for stat/lstat.
const Pathname & path() const
Return current Pathname.
std::vector< std::string > ModaliasList
Modalias()
Singleton ctor.
bool query(IdString cap_r) const
Checks if a device on the system matches a modalias pattern.
static Modalias & instance()
Singleton access.
const ModaliasList & modaliasList() const
List of modaliases found on system.
RW_pointer< Impl > _pimpl
Pointer to implementation.
String related utilities and Regular expression matching.
int forEachLine(std::istream &str_r, const function< bool(int, std::string)> &consume_r)
Simple lineparser: Call functor consume_r for each line.
std::string getline(std::istream &str)
Read one line from stream.
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n  ", const std::string &sep="\n  ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Impl(const Impl &)=delete
bool query(const char *cap_r) const
std::ostream & operator<<(std::ostream &str, const Modalias::Impl &obj)
Stream output And maybe std::ostream & operator<< Modalias::Impl below too.
Impl & operator=(Impl &&)=delete
Impl & operator=(const Impl &)=delete
static shared_ptr< Impl > nullimpl()
Offer default Impl.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.