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/parser/RepoindexFileReader.h"
20 #include "zypp/repo/RepoInfoBaseImpl.h"
22 #include "zypp/ServiceInfo.h"
25 using zypp::xml::escape;
27 ///////////////////////////////////////////////////////////////////////////////
29 {//////////////////////////////////////////////////////////////////////////////
32 struct RepoInfoCollector
34 vector<RepoInfo> repos;
35 bool collect(const RepoInfo & info)
37 repos.push_back(info);
42 ///////////////////////////////////////////////////////////////////
44 // CLASS NAME : ServiceInfo::Impl
46 struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
48 typedef ServiceInfo::CatalogsToEnable CatalogsToEnable;
49 typedef ServiceInfo::CatalogsToDisable CatalogsToDisable;
53 repo::ServiceType type;
54 CatalogsToEnable catalogsToEnable;
55 CatalogsToDisable catalogsToDisable;
58 Impl() : repo::RepoInfoBase::Impl() {}
60 Impl(const Url & url_) : url(url_) {}
62 void setProbedType( const repo::ServiceType & t ) const
64 if ( type == repo::ServiceType::NONE
65 && t != repo::ServiceType::NONE )
68 const_cast<Impl*>(this)->type = t;
73 friend Impl * rwcowClone<Impl>( const Impl * rhs );
75 /** clone for RWCOW_pointer */
77 { return new Impl( *this ); }
79 ///////////////////////////////////////////////////////////////////
82 ///////////////////////////////////////////////////////////////////
84 // CLASS NAME : ServiceInfo::Impl
86 ///////////////////////////////////////////////////////////////////
88 const ServiceInfo ServiceInfo::noService;
90 ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
92 ServiceInfo::ServiceInfo(const string & alias)
93 : repo::RepoInfoBase(alias), _pimpl( new Impl() )
96 ServiceInfo::ServiceInfo(const string & alias, const Url & url)
97 : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
100 Url ServiceInfo::url() const { return _pimpl->url; }
101 void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
103 repo::ServiceType ServiceInfo::type() const
104 { return _pimpl->type; }
105 void ServiceInfo::setType( const repo::ServiceType & type )
106 { _pimpl->type = type; }
108 void ServiceInfo::setProbedType( const repo::ServiceType &t ) const
109 { _pimpl->setProbedType( t ); }
111 bool ServiceInfo::catalogsToEnableEmpty() const
112 { return _pimpl->catalogsToEnable.empty(); }
114 ServiceInfo::CatalogsToEnable::size_type ServiceInfo::catalogsToEnableSize() const
115 { return _pimpl->catalogsToEnable.size(); }
117 ServiceInfo::CatalogsToEnable::const_iterator ServiceInfo::catalogsToEnableBegin() const
118 { return _pimpl->catalogsToEnable.begin(); }
120 ServiceInfo::CatalogsToEnable::const_iterator ServiceInfo::catalogsToEnableEnd() const
121 { return _pimpl->catalogsToEnable.end(); }
123 bool ServiceInfo::catalogToEnableFind( const std::string & alias_r ) const
124 { return( _pimpl->catalogsToEnable.find( alias_r ) != _pimpl->catalogsToEnable.end() ); }
126 void ServiceInfo::addCatalogToEnable( const std::string & alias_r )
127 { _pimpl->catalogsToEnable.insert( alias_r ); }
129 void ServiceInfo::delCatalogToEnable( const std::string & alias_r )
130 { _pimpl->catalogsToEnable.erase( alias_r ); }
133 bool ServiceInfo::catalogsToDisableEmpty() const
134 { return _pimpl->catalogsToDisable.empty(); }
136 ServiceInfo::CatalogsToDisable::size_type ServiceInfo::catalogsToDisableSize() const
137 { return _pimpl->catalogsToDisable.size(); }
139 ServiceInfo::CatalogsToDisable::const_iterator ServiceInfo::catalogsToDisableBegin() const
140 { return _pimpl->catalogsToDisable.begin(); }
142 ServiceInfo::CatalogsToDisable::const_iterator ServiceInfo::catalogsToDisableEnd() const
143 { return _pimpl->catalogsToDisable.end(); }
145 bool ServiceInfo::catalogToDisableFind( const std::string & alias_r ) const
146 { return( _pimpl->catalogsToDisable.find( alias_r ) != _pimpl->catalogsToDisable.end() ); }
148 void ServiceInfo::addCatalogToDisable( const std::string & alias_r )
149 { _pimpl->catalogsToDisable.insert( alias_r ); }
151 void ServiceInfo::delCatalogToDisable( const std::string & alias_r )
152 { _pimpl->catalogsToDisable.erase( alias_r ); }
155 std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
157 RepoInfoBase::dumpAsIniOn(str)
158 << "url = " << url() << endl
159 << "type = " << type() << endl;
161 if ( ! catalogsToEnableEmpty() )
162 str << "catalogstoenable = " << str::joinEscaped( catalogsToEnableBegin(), catalogsToEnableEnd() ) << endl;
163 if ( ! catalogsToDisableEmpty() )
164 str << "catalogstodisable = " << str::joinEscaped( catalogsToDisableBegin(), catalogsToDisableEnd() ) << endl;
168 std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
169 { return dumpAsXMLOn(str, ""); }
171 ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
175 << " alias=\"" << escape(alias()) << "\""
176 << " name=\"" << escape(name()) << "\""
177 << " enabled=\"" << enabled() << "\""
178 << " autorefresh=\"" << autorefresh() << "\""
179 << " url=\"" << escape(url().asString()) << "\""
180 << " type=\"" << type().asString() << "\"";
185 str << ">" << endl << content << "</service>" << endl;
191 std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
193 return obj.dumpAsIniOn(str);
197 ///////////////////////////////////////////////////////////////////////////////
199 ///////////////////////////////////////////////////////////////////////////////