1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ServiceInfo.cc
15 #include <zypp/base/String.h>
16 #include <zypp/base/DefaultIntegral.h>
17 #include <zypp/parser/xml/XmlEscape.h>
19 #include <zypp/RepoInfo.h>
20 #include <zypp/ServiceInfo.h>
23 using zypp::xml::escape;
25 ///////////////////////////////////////////////////////////////////////////////
27 {//////////////////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : ServiceInfo::Impl
33 struct ServiceInfo::Impl
35 typedef ServiceInfo::ReposToEnable ReposToEnable;
36 typedef ServiceInfo::ReposToDisable ReposToDisable;
39 RepoVariablesReplacedUrl _url;
40 repo::ServiceType _type;
41 ReposToEnable _reposToEnable;
42 ReposToDisable _reposToDisable;
43 RepoStates _repoStates;
44 DefaultIntegral<Date::Duration,0> _ttl;
51 Impl( const Url & url_r )
58 void setProbedType( const repo::ServiceType & type_r ) const
60 if ( _type == repo::ServiceType::NONE
61 && type_r != repo::ServiceType::NONE )
64 const_cast<Impl*>(this)->_type = type_r;
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 std::string & alias)
89 : repo::RepoInfoBase(alias), _pimpl( new Impl() )
92 ServiceInfo::ServiceInfo(const std::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 { return _pimpl->_type; }
109 void ServiceInfo::setType( const repo::ServiceType & type ) { _pimpl->_type = type; }
110 void ServiceInfo::setProbedType( const repo::ServiceType &t ) const { _pimpl->setProbedType( t ); }
112 Date::Duration ServiceInfo::ttl() const { return _pimpl->_ttl; }
113 void ServiceInfo::setTtl( Date::Duration ttl_r ) { _pimpl->_ttl = ttl_r; }
114 void ServiceInfo::setProbedTtl( Date::Duration ttl_r ) const { const_cast<ServiceInfo*>(this)->setTtl( ttl_r ); }
116 Date ServiceInfo::lrf() const { return _pimpl->_lrf; }
117 void ServiceInfo::setLrf( Date lrf_r ) { _pimpl->_lrf = lrf_r; }
119 bool ServiceInfo::reposToEnableEmpty() const { return _pimpl->_reposToEnable.empty(); }
120 ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const { return _pimpl->_reposToEnable.size(); }
121 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const { return _pimpl->_reposToEnable.begin(); }
122 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const { return _pimpl->_reposToEnable.end(); }
124 bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
125 { return( _pimpl->_reposToEnable.find( alias_r ) != _pimpl->_reposToEnable.end() ); }
127 void ServiceInfo::addRepoToEnable( const std::string & alias_r )
129 _pimpl->_reposToEnable.insert( alias_r );
130 _pimpl->_reposToDisable.erase( alias_r );
133 void ServiceInfo::delRepoToEnable( const std::string & alias_r )
134 { _pimpl->_reposToEnable.erase( alias_r ); }
136 void ServiceInfo::clearReposToEnable()
137 { _pimpl->_reposToEnable.clear(); }
140 bool ServiceInfo::reposToDisableEmpty() const { return _pimpl->_reposToDisable.empty(); }
141 ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const { return _pimpl->_reposToDisable.size(); }
142 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const { return _pimpl->_reposToDisable.begin(); }
143 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const { return _pimpl->_reposToDisable.end(); }
145 bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
146 { return( _pimpl->_reposToDisable.find( alias_r ) != _pimpl->_reposToDisable.end() ); }
148 void ServiceInfo::addRepoToDisable( const std::string & alias_r )
150 _pimpl->_reposToDisable.insert( alias_r );
151 _pimpl->_reposToEnable.erase( alias_r );
154 void ServiceInfo::delRepoToDisable( const std::string & alias_r )
155 { _pimpl->_reposToDisable.erase( alias_r ); }
157 void ServiceInfo::clearReposToDisable()
158 { _pimpl->_reposToDisable.clear(); }
161 const ServiceInfo::RepoStates & ServiceInfo::repoStates() const { return _pimpl->_repoStates; }
162 void ServiceInfo::setRepoStates( RepoStates newStates_r ) { swap( _pimpl->_repoStates, newStates_r ); }
165 std::ostream & operator<<( std::ostream & str, const ServiceInfo::RepoState & obj )
168 << "enabled=" << obj.enabled << " "
169 << "autorefresh=" << obj.autorefresh << " "
170 << "priority=" << obj.priority;
173 std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
175 RepoInfoBase::dumpAsIniOn(str)
176 << "url = " << hotfix1050625::asString( rawUrl() ) << endl
177 << "type = " << type() << endl;
180 str << "ttl_sec = " << ttl() << endl;
183 str << "lrf_dat = " << lrf().asSeconds() << endl;
185 if ( ! repoStates().empty() )
188 for ( const auto & el : repoStates() )
190 std::string tag( "repo_" );
191 tag += str::numstring( ++cnt );
192 const RepoState & state( el.second );
194 str << tag << "=" << el.first << endl
195 << tag << "_enabled=" << state.enabled << endl
196 << tag << "_autorefresh=" << state.autorefresh << endl;
197 if ( state.priority != RepoInfo::defaultPriority() )
199 << tag << "_priority=" << state.priority << endl;
203 if ( ! reposToEnableEmpty() )
204 str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
205 if ( ! reposToDisableEmpty() )
206 str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
210 std::ostream & ServiceInfo::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
214 << " alias=\"" << escape(alias()) << "\""
215 << " name=\"" << escape(name()) << "\""
216 << " enabled=\"" << enabled() << "\""
217 << " autorefresh=\"" << autorefresh() << "\""
218 << " url=\"" << escape(url().asString()) << "\""
219 << " type=\"" << type().asString() << "\""
220 << " ttl_sec=\"" << ttl() << "\"";
225 str << ">" << endl << content << "</service>" << endl;
231 std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
233 return obj.dumpAsIniOn(str);
237 ///////////////////////////////////////////////////////////////////////////////
239 ///////////////////////////////////////////////////////////////////////////////