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::ReposToEnable ReposToEnable;
49 typedef ServiceInfo::ReposToDisable ReposToDisable;
53 repo::ServiceType type;
54 ReposToEnable reposToEnable;
55 ReposToDisable reposToDisable;
59 : repo::RepoInfoBase::Impl()
60 , type(repo::ServiceType::NONE_e)
63 Impl(const Url & url_)
64 : repo::RepoInfoBase::Impl()
66 , type(repo::ServiceType::NONE_e)
72 void setProbedType( const repo::ServiceType & t ) const
74 if ( type == repo::ServiceType::NONE
75 && t != repo::ServiceType::NONE )
78 const_cast<Impl*>(this)->type = t;
83 friend Impl * rwcowClone<Impl>( const Impl * rhs );
85 /** clone for RWCOW_pointer */
87 { return new Impl( *this ); }
89 ///////////////////////////////////////////////////////////////////
92 ///////////////////////////////////////////////////////////////////
94 // CLASS NAME : ServiceInfo::Impl
96 ///////////////////////////////////////////////////////////////////
98 const ServiceInfo ServiceInfo::noService;
100 ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
102 ServiceInfo::ServiceInfo(const string & alias)
103 : repo::RepoInfoBase(alias), _pimpl( new Impl() )
106 ServiceInfo::ServiceInfo(const string & alias, const Url & url)
107 : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
110 ServiceInfo::~ServiceInfo()
113 Url ServiceInfo::url() const { return _pimpl->url; }
114 void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
116 repo::ServiceType ServiceInfo::type() const
117 { return _pimpl->type; }
118 void ServiceInfo::setType( const repo::ServiceType & type )
119 { _pimpl->type = type; }
121 void ServiceInfo::setProbedType( const repo::ServiceType &t ) const
122 { _pimpl->setProbedType( t ); }
124 bool ServiceInfo::reposToEnableEmpty() const
125 { return _pimpl->reposToEnable.empty(); }
127 ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const
128 { return _pimpl->reposToEnable.size(); }
130 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
131 { return _pimpl->reposToEnable.begin(); }
133 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
134 { return _pimpl->reposToEnable.end(); }
136 bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
137 { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
139 void ServiceInfo::addRepoToEnable( const std::string & alias_r )
140 { _pimpl->reposToEnable.insert( alias_r ); }
142 void ServiceInfo::delRepoToEnable( const std::string & alias_r )
143 { _pimpl->reposToEnable.erase( alias_r ); }
146 bool ServiceInfo::reposToDisableEmpty() const
147 { return _pimpl->reposToDisable.empty(); }
149 ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const
150 { return _pimpl->reposToDisable.size(); }
152 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
153 { return _pimpl->reposToDisable.begin(); }
155 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
156 { return _pimpl->reposToDisable.end(); }
158 bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
159 { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
161 void ServiceInfo::addRepoToDisable( const std::string & alias_r )
162 { _pimpl->reposToDisable.insert( alias_r ); }
164 void ServiceInfo::delRepoToDisable( const std::string & alias_r )
165 { _pimpl->reposToDisable.erase( alias_r ); }
168 std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
170 RepoInfoBase::dumpAsIniOn(str)
171 << "url = " << url() << endl
172 << "type = " << type() << endl;
174 if ( ! reposToEnableEmpty() )
175 str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
176 if ( ! reposToDisableEmpty() )
177 str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
181 std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
182 { return dumpAsXMLOn(str, ""); }
184 ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
188 << " alias=\"" << escape(alias()) << "\""
189 << " name=\"" << escape(name()) << "\""
190 << " enabled=\"" << enabled() << "\""
191 << " autorefresh=\"" << autorefresh() << "\""
192 << " url=\"" << escape(url().asString()) << "\""
193 << " type=\"" << type().asString() << "\"";
198 str << ">" << endl << content << "</service>" << endl;
204 std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
206 return obj.dumpAsIniOn(str);
210 ///////////////////////////////////////////////////////////////////////////////
212 ///////////////////////////////////////////////////////////////////////////////