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 
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 
00028     inline void modsplit( std::string & name_r, std::string & pkgname_r )
00029     {
00030       std::string::size_type pos1( name_r.find_first_of( ":" ) );
00031       std::string::size_type pos2( name_r.find_last_of( ":" ) );
00032       if ( pos1 != pos2 )
00033         {
00034           pkgname_r = name_r.substr( 0, pos1 );
00035           name_r.erase( 0, pos1+1 );
00036         }
00037     }
00038 
00040     ModaliasCap::ModaliasCap( const Resolvable::Kind & refers_r,
00041                               const std::string & name_r )
00042     : CapabilityImpl( refers_r )
00043     , _name( name_r )
00044     { modsplit( _name, _pkgname ); }
00045 
00047     ModaliasCap::ModaliasCap( const Resolvable::Kind & refers_r,
00048                               const std::string & name_r,
00049                               Rel op_r,
00050                               const std::string & value_r )
00051     : CapabilityImpl( refers_r )
00052     , _name( name_r )
00053     , _op( op_r )
00054     , _value( value_r )
00055     { modsplit( _name, _pkgname ); }
00056 
00057     const CapabilityImpl::Kind & ModaliasCap::kind() const
00058     { return CapTraits<Self>::kind; }
00059 
00060     CapMatch ModaliasCap::matches( const constPtr & rhs ) const
00061     {
00062       if ( sameKindAndRefers( rhs ) )
00063         {
00064           intrusive_ptr<const Self> modaliasrhs( asKind<Self>(rhs) );
00065           if ( isEvalCmd() == modaliasrhs->isEvalCmd() )
00066             return CapMatch::irrelevant;
00067 
00068           return( isEvalCmd() ? modaliasrhs->evaluate() : evaluate() );
00069         }
00070       return false;
00071     }
00072 
00073     std::string ModaliasCap::encode() const
00074     {
00075       std::string ret( "modalias(" );
00076       if ( !_pkgname.empty() )
00077         {
00078           ret += _pkgname;
00079           ret += ":";
00080         }
00081       ret += _name;
00082       ret += ")";
00083       if ( _op != Rel::ANY )
00084         {
00085           ret += " ";
00086           ret += _op.asString();
00087           ret += " ";
00088           ret += _value;
00089         }
00090       return ret;
00091     }
00092 
00093     std::string ModaliasCap::index() const
00094     {
00095       return "modalias()";
00096     }
00097 
00098     bool ModaliasCap::isEvalCmd() const
00099     { return _name.empty(); }
00100 
00101     bool ModaliasCap::evaluate() const
00102     {
00103       return target::modalias::Modalias::instance().query( _name, _op, _value );
00104     }
00105 
00107   } // namespace capability
00110 } // namespace zypp

Generated on Thu Jul 6 00:07:20 2006 for zypp by  doxygen 1.4.6