ModaliasCap.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014 #include "zypp/base/String.h"
00015 
00016 #include "zypp/capability/ModaliasCap.h"
00017 #include "zypp/target/modalias/Modalias.h"
00018 
00019 using namespace std;
00020 
00022 namespace zypp
00023 { 
00024 
00025   namespace capability
00026   { 
00027 
00029     inline void modsplit( std::string & name_r, std::string & pkgname_r )
00030     {
00031       std::string::size_type pos1( name_r.find_first_of( ":" ) );
00032       std::string::size_type pos2( name_r.find_last_of( ":" ) );
00033       if ( pos1 != pos2 )
00034         {
00035           pkgname_r = name_r.substr( 0, pos1 );
00036           name_r.erase( 0, pos1+1 );
00037         }
00038     }
00039 
00041     ModaliasCap::ModaliasCap( const Resolvable::Kind & refers_r,
00042                               const std::string & name_r )
00043     : CapabilityImpl( refers_r )
00044     , _name( name_r )
00045     { modsplit( _name, _pkgname ); }
00046 
00048     ModaliasCap::ModaliasCap( const Resolvable::Kind & refers_r,
00049                               const std::string & name_r,
00050                               Rel op_r,
00051                               const std::string & value_r )
00052     : CapabilityImpl( refers_r )
00053     , _name( name_r )
00054     , _op( op_r )
00055     , _value( value_r )
00056     { modsplit( _name, _pkgname ); }
00057 
00058     const CapabilityImpl::Kind & ModaliasCap::kind() const
00059     { return CapTraits<Self>::kind; }
00060 
00061     CapMatch ModaliasCap::matches( const constPtr & rhs ) const
00062     {
00063       if ( sameKindAndRefers( rhs ) )
00064         {
00065           intrusive_ptr<const Self> modaliasrhs( asKind<Self>(rhs) );
00066           if ( isEvalCmd() == modaliasrhs->isEvalCmd() )
00067             return CapMatch::irrelevant;
00068 
00069           return( isEvalCmd() ? modaliasrhs->evaluate() : evaluate() );
00070         }
00071       return false;
00072     }
00073 
00074     std::string ModaliasCap::encode() const
00075     {
00076       std::string ret( "modalias(" );
00077       if ( !_pkgname.empty() )
00078         {
00079           ret += _pkgname;
00080           ret += ":";
00081         }
00082       ret += _name;
00083       ret += ")";
00084       if ( _op != Rel::ANY )
00085         {
00086           ret += " ";
00087           ret += _op.asString();
00088           ret += " ";
00089           ret += _value;
00090         }
00091       return ret;
00092     }
00093 
00094     std::string ModaliasCap::index() const
00095     {
00096       return "modalias()";
00097     }
00098 
00099     std::string ModaliasCap::indexname() const
00100     {
00101       std::string ret( "modalias(" );
00102       if ( !_pkgname.empty() )
00103         {
00104           ret += _pkgname;
00105           ret += ":";
00106         }
00107       ret += _name;
00108       ret += ")";
00109       return ret;
00110     }
00111 
00112     bool ModaliasCap::isEvalCmd() const
00113     { return _name.empty(); }
00114 
00115     bool ModaliasCap::evaluate() const
00116     {
00117       return target::modalias::Modalias::instance().query( str::hexdecode(_name), _op, _value );
00118     }
00119 
00121   } // namespace capability
00124 } // namespace zypp

Generated on Sat Sep 5 12:40:16 2009 for zypp by  doxygen 1.4.6