1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ServiceInfo.cc
15 #include "zypp/base/String.h"
16 #include "zypp/parser/xml/XmlEscape.h"
18 #include "zypp/RepoInfo.h"
19 #include "zypp/ServiceInfo.h"
22 using zypp::xml::escape;
24 ///////////////////////////////////////////////////////////////////////////////
26 {//////////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 // CLASS NAME : ServiceInfo::Impl
32 struct ServiceInfo::Impl
34 typedef ServiceInfo::ReposToEnable ReposToEnable;
35 typedef ServiceInfo::ReposToDisable ReposToDisable;
38 RepoVariablesReplacedUrl url;
39 repo::ServiceType type;
40 ReposToEnable reposToEnable;
41 ReposToDisable reposToDisable;
42 RepoStates repoStates;
47 : type(repo::ServiceType::NONE_e)
50 Impl(const Url & url_)
52 , type(repo::ServiceType::NONE_e)
58 void setProbedType( const repo::ServiceType & t ) const
60 if ( type == repo::ServiceType::NONE
61 && t != repo::ServiceType::NONE )
64 const_cast<Impl*>(this)->type = t;
69 friend Impl * rwcowClone<Impl>( const Impl * rhs );
71 /** clone for RWCOW_pointer */
73 { return new Impl( *this ); }
75 ///////////////////////////////////////////////////////////////////
78 ///////////////////////////////////////////////////////////////////
80 // CLASS NAME : ServiceInfo::Impl
82 ///////////////////////////////////////////////////////////////////
84 const ServiceInfo ServiceInfo::noService;
86 ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
88 ServiceInfo::ServiceInfo(const string & alias)
89 : repo::RepoInfoBase(alias), _pimpl( new Impl() )
92 ServiceInfo::ServiceInfo(const string & alias, const Url & url)
93 : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
96 ServiceInfo::~ServiceInfo()
99 Url ServiceInfo::url() const // Variables replaced
100 { return _pimpl->url.transformed(); }
102 Url ServiceInfo::rawUrl() const // Raw
103 { return _pimpl->url.raw(); }
105 void ServiceInfo::setUrl( const Url& url ) // Raw
106 { _pimpl->url.raw() = url; }
108 repo::ServiceType ServiceInfo::type() const
109 { return _pimpl->type; }
110 void ServiceInfo::setType( const repo::ServiceType & type )
111 { _pimpl->type = type; }
113 void ServiceInfo::setProbedType( const repo::ServiceType &t ) const
114 { _pimpl->setProbedType( t ); }
116 bool ServiceInfo::reposToEnableEmpty() const
117 { return _pimpl->reposToEnable.empty(); }
119 ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const
120 { return _pimpl->reposToEnable.size(); }
122 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
123 { return _pimpl->reposToEnable.begin(); }
125 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
126 { return _pimpl->reposToEnable.end(); }
128 bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
129 { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
131 void ServiceInfo::addRepoToEnable( const std::string & alias_r )
133 _pimpl->reposToEnable.insert( alias_r );
134 _pimpl->reposToDisable.erase( alias_r );
137 void ServiceInfo::delRepoToEnable( const std::string & alias_r )
138 { _pimpl->reposToEnable.erase( alias_r ); }
140 void ServiceInfo::clearReposToEnable()
141 { _pimpl->reposToEnable.clear(); }
144 bool ServiceInfo::reposToDisableEmpty() const
145 { return _pimpl->reposToDisable.empty(); }
147 ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const
148 { return _pimpl->reposToDisable.size(); }
150 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
151 { return _pimpl->reposToDisable.begin(); }
153 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
154 { return _pimpl->reposToDisable.end(); }
156 bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
157 { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
159 void ServiceInfo::addRepoToDisable( const std::string & alias_r )
161 _pimpl->reposToDisable.insert( alias_r );
162 _pimpl->reposToEnable.erase( alias_r );
165 void ServiceInfo::delRepoToDisable( const std::string & alias_r )
166 { _pimpl->reposToDisable.erase( alias_r ); }
168 void ServiceInfo::clearReposToDisable()
169 { _pimpl->reposToDisable.clear(); }
171 const ServiceInfo::RepoStates & ServiceInfo::repoStates() const
172 { return _pimpl->repoStates; }
174 void ServiceInfo::setRepoStates( RepoStates newStates_r )
175 { swap( _pimpl->repoStates, newStates_r ); }
177 std::ostream & operator<<( std::ostream & str, const ServiceInfo::RepoState & obj )
180 << "enabled=" << obj.enabled << " "
181 << "autorefresh=" << obj.autorefresh << " "
182 << "priority=" << obj.priority;
185 std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
187 RepoInfoBase::dumpAsIniOn(str)
188 << "url = " << rawUrl() << endl
189 << "type = " << type() << endl;
191 if ( ! repoStates().empty() )
194 for ( const auto & el : repoStates() )
196 std::string tag( "repo_" );
197 tag += str::numstring( ++cnt );
198 const RepoState & state( el.second );
200 str << tag << "=" << el.first << endl
201 << tag << "_enabled=" << state.enabled << endl
202 << tag << "_autorefresh=" << state.autorefresh << endl;
203 if ( state.priority != RepoInfo::defaultPriority() )
205 << tag << "_priority=" << state.priority << endl;
209 if ( ! reposToEnableEmpty() )
210 str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
211 if ( ! reposToDisableEmpty() )
212 str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
216 ostream & ServiceInfo::dumpAsXmlOn( ostream & str, const string & content ) const
220 << " alias=\"" << escape(alias()) << "\""
221 << " name=\"" << escape(name()) << "\""
222 << " enabled=\"" << enabled() << "\""
223 << " autorefresh=\"" << autorefresh() << "\""
224 << " url=\"" << escape(url().asString()) << "\""
225 << " type=\"" << type().asString() << "\"";
230 str << ">" << endl << content << "</service>" << endl;
236 std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
238 return obj.dumpAsIniOn(str);
242 ///////////////////////////////////////////////////////////////////////////////
244 ///////////////////////////////////////////////////////////////////////////////