libzypp 9.41.1

ServiceInfo.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <ostream>
00013 #include <iostream>
00014 
00015 #include "zypp/base/String.h"
00016 #include "zypp/parser/xml/XmlEscape.h"
00017 
00018 #include "zypp/RepoInfo.h"
00019 #include "zypp/repo/RepoInfoBaseImpl.h"
00020 
00021 #include "zypp/ServiceInfo.h"
00022 
00023 using namespace std;
00024 using zypp::xml::escape;
00025 
00027 namespace zypp
00028 {
00029 
00031   //
00032   //  CLASS NAME : ServiceInfo::Impl
00033   //
00034   struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
00035   {
00036     typedef ServiceInfo::ReposToEnable  ReposToEnable;
00037     typedef ServiceInfo::ReposToDisable ReposToDisable;
00038 
00039   public:
00040     Url url;
00041     repo::ServiceType type;
00042     ReposToEnable  reposToEnable;
00043     ReposToDisable reposToDisable;
00044     RepoStates     repoStates;
00045 
00046 
00047   public:
00048     Impl()
00049       : repo::RepoInfoBase::Impl()
00050       , type(repo::ServiceType::NONE_e)
00051     {}
00052 
00053     Impl(const Url & url_)
00054       : repo::RepoInfoBase::Impl()
00055       , url(url_)
00056       , type(repo::ServiceType::NONE_e)
00057     {}
00058 
00059     ~Impl()
00060     {}
00061 
00062     void setProbedType( const repo::ServiceType & t ) const
00063     {
00064       if ( type == repo::ServiceType::NONE
00065            && t != repo::ServiceType::NONE )
00066       {
00067         // lazy init!
00068         const_cast<Impl*>(this)->type = t;
00069       }
00070     }
00071 
00072   private:
00073     friend Impl * rwcowClone<Impl>( const Impl * rhs );
00074 
00076     Impl * clone() const
00077     { return new Impl( *this ); }
00078   };
00080 
00081 
00083   //
00084   //  CLASS NAME : ServiceInfo::Impl
00085   //
00087 
00088   const ServiceInfo ServiceInfo::noService;
00089 
00090   ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
00091 
00092   ServiceInfo::ServiceInfo(const string & alias)
00093     : repo::RepoInfoBase(alias), _pimpl( new Impl() )
00094   {}
00095 
00096   ServiceInfo::ServiceInfo(const string & alias, const Url & url)
00097     : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
00098   {}
00099 
00100   ServiceInfo::~ServiceInfo()
00101   {}
00102 
00103   Url ServiceInfo::url() const { return _pimpl->url; }
00104   void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
00105 
00106   repo::ServiceType ServiceInfo::type() const
00107   { return _pimpl->type; }
00108   void ServiceInfo::setType( const repo::ServiceType & type )
00109   { _pimpl->type = type; }
00110 
00111   void ServiceInfo::setProbedType( const repo::ServiceType &t ) const
00112   { _pimpl->setProbedType( t ); }
00113 
00114   bool ServiceInfo::reposToEnableEmpty() const
00115   { return _pimpl->reposToEnable.empty(); }
00116 
00117   ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const
00118   { return _pimpl->reposToEnable.size(); }
00119 
00120   ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
00121   { return _pimpl->reposToEnable.begin(); }
00122 
00123   ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
00124   { return _pimpl->reposToEnable.end(); }
00125 
00126   bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
00127   { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
00128 
00129   void ServiceInfo::addRepoToEnable( const std::string & alias_r )
00130   {
00131     _pimpl->reposToEnable.insert( alias_r );
00132     _pimpl->reposToDisable.erase( alias_r );
00133   }
00134 
00135   void ServiceInfo::delRepoToEnable( const std::string & alias_r )
00136   { _pimpl->reposToEnable.erase( alias_r ); }
00137 
00138   void ServiceInfo::clearReposToEnable()
00139   { _pimpl->reposToEnable.clear(); }
00140 
00141 
00142   bool ServiceInfo::reposToDisableEmpty() const
00143   { return _pimpl->reposToDisable.empty(); }
00144 
00145   ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const
00146   { return _pimpl->reposToDisable.size(); }
00147 
00148   ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
00149   { return _pimpl->reposToDisable.begin(); }
00150 
00151   ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
00152   { return _pimpl->reposToDisable.end(); }
00153 
00154   bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
00155   { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
00156 
00157   void ServiceInfo::addRepoToDisable( const std::string & alias_r )
00158   {
00159     _pimpl->reposToDisable.insert( alias_r );
00160     _pimpl->reposToEnable.erase( alias_r );
00161   }
00162 
00163   void ServiceInfo::delRepoToDisable( const std::string & alias_r )
00164   { _pimpl->reposToDisable.erase( alias_r ); }
00165 
00166   void ServiceInfo::clearReposToDisable()
00167   { _pimpl->reposToDisable.clear(); }
00168 
00169   const ServiceInfo::RepoStates & ServiceInfo::repoStates() const
00170   { return _pimpl->repoStates; }
00171 
00172   void ServiceInfo::setRepoStates( RepoStates newStates_r )
00173   { swap( _pimpl->repoStates, newStates_r ); }
00174 
00175   std::ostream & operator<<( std::ostream & str, const ServiceInfo::RepoState & obj )
00176   {
00177     return str
00178         << "enabled=" << obj.enabled << " "
00179         << "autorefresh=" << obj.autorefresh << " "
00180         << "priority=" << obj.priority;
00181   }
00182 
00183   std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
00184   {
00185     RepoInfoBase::dumpAsIniOn(str)
00186       << "url = " << url() << endl
00187       << "type = " << type() << endl;
00188 
00189     if ( ! repoStates().empty() )
00190     {
00191       unsigned cnt = 0U;
00192       for_( it, repoStates().begin(), repoStates().end() )
00193       {
00194         const RepoStates::value_type & el( *it );
00195 
00196         std::string tag( "repo_" );
00197         tag += str::numstring( ++cnt );
00198         const RepoState & state( el.second );
00199 
00200         str << tag << "=" << el.first << endl
00201             << tag << "_enabled=" << state.enabled << endl
00202             << tag << "_autorefresh=" << state.autorefresh << endl;
00203         if ( state.priority != RepoInfo::defaultPriority() )
00204           str
00205             << tag << "_priority=" << state.priority << endl;
00206       }
00207     }
00208 
00209     if ( ! reposToEnableEmpty() )
00210       str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
00211     if ( ! reposToDisableEmpty() )
00212       str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
00213     return str;
00214   }
00215 
00216   std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
00217   { return dumpAsXMLOn(str, ""); }
00218 
00219   ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
00220   {
00221     str
00222       << "<service"
00223       << " alias=\"" << escape(alias()) << "\""
00224       << " name=\"" << escape(name()) << "\""
00225       << " enabled=\"" << enabled() << "\""
00226       << " autorefresh=\"" << autorefresh() << "\""
00227       << " url=\"" << escape(url().asString()) << "\""
00228       << " type=\"" << type().asString() << "\"";
00229 
00230     if (content.empty())
00231       str << "/>" << endl;
00232     else
00233       str << ">" << endl << content << "</service>" << endl;
00234 
00235     return str;
00236   }
00237 
00238 
00239   std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
00240   {
00241     return obj.dumpAsIniOn(str);
00242   }
00243 
00244 
00246 } //namespace zypp