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