add catalogsToDisable to service
[platform/upstream/libzypp.git] / zypp / ServiceInfo.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ServiceInfo.cc
10  *
11  */
12 #include <ostream>
13 #include <iostream>
14
15 #include "zypp/base/String.h"
16 #include "zypp/parser/xml/XmlEscape.h"
17
18 #include "zypp/RepoInfo.h"
19 #include "zypp/parser/RepoindexFileReader.h"
20 #include "zypp/repo/RepoInfoBaseImpl.h"
21
22 #include "zypp/ServiceInfo.h"
23
24 using namespace std;
25 using zypp::xml::escape;
26
27 ///////////////////////////////////////////////////////////////////////////////
28 namespace zypp
29 {//////////////////////////////////////////////////////////////////////////////
30
31
32   struct RepoInfoCollector
33   {
34     vector<RepoInfo> repos;
35     bool collect(const RepoInfo & info)
36     {
37       repos.push_back(info);
38       return true;
39     }
40   };
41
42   ///////////////////////////////////////////////////////////////////
43   //
44   //  CLASS NAME : ServiceInfo::Impl
45   //
46   struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
47   {
48     typedef ServiceInfo::CatalogsToEnable CatalogsToEnable;
49     typedef ServiceInfo::CatalogsToDisable CatalogsToDisable;
50
51   public:
52     Url url;
53     CatalogsToEnable  catalogsToEnable;
54     CatalogsToDisable catalogsToDisable;
55
56   public:
57     Impl() : repo::RepoInfoBase::Impl() {}
58
59     Impl(const Url & url_) : url(url_) {}
60
61   private:
62     friend Impl * rwcowClone<Impl>( const Impl * rhs );
63
64     /** clone for RWCOW_pointer */
65     Impl * clone() const
66     { return new Impl( *this ); }
67   };
68   ///////////////////////////////////////////////////////////////////
69
70
71   ///////////////////////////////////////////////////////////////////
72   //
73   //  CLASS NAME : ServiceInfo::Impl
74   //
75   ///////////////////////////////////////////////////////////////////
76
77   const ServiceInfo ServiceInfo::noService;
78
79   ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
80
81   ServiceInfo::ServiceInfo(const string & alias)
82     : repo::RepoInfoBase(alias), _pimpl( new Impl() )
83   {}
84
85   ServiceInfo::ServiceInfo(const string & alias, const Url & url)
86     : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
87   {}
88
89   Url ServiceInfo::url() const { return _pimpl->url; }
90   void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
91
92
93   bool ServiceInfo::catalogsToEnableEmpty() const
94   { return _pimpl->catalogsToEnable.empty(); }
95
96   ServiceInfo::CatalogsToEnable::size_type ServiceInfo::catalogsToEnableSize() const
97   { return _pimpl->catalogsToEnable.size(); }
98
99   ServiceInfo::CatalogsToEnable::const_iterator ServiceInfo::catalogsToEnableBegin() const
100   { return _pimpl->catalogsToEnable.begin(); }
101
102   ServiceInfo::CatalogsToEnable::const_iterator ServiceInfo::catalogsToEnableEnd() const
103   { return _pimpl->catalogsToEnable.end(); }
104
105   bool ServiceInfo::catalogToEnableFind( const std::string & alias_r ) const
106   { return( _pimpl->catalogsToEnable.find( alias_r ) != _pimpl->catalogsToEnable.end() ); }
107
108   void ServiceInfo::addCatalogToEnable( const std::string & alias_r )
109   { _pimpl->catalogsToEnable.insert( alias_r ); }
110
111   void ServiceInfo::delCatalogToEnable( const std::string & alias_r )
112   { _pimpl->catalogsToEnable.erase( alias_r ); }
113
114
115   bool ServiceInfo::catalogsToDisableEmpty() const
116   { return _pimpl->catalogsToDisable.empty(); }
117
118   ServiceInfo::CatalogsToDisable::size_type ServiceInfo::catalogsToDisableSize() const
119   { return _pimpl->catalogsToDisable.size(); }
120
121   ServiceInfo::CatalogsToDisable::const_iterator ServiceInfo::catalogsToDisableBegin() const
122   { return _pimpl->catalogsToDisable.begin(); }
123
124   ServiceInfo::CatalogsToDisable::const_iterator ServiceInfo::catalogsToDisableEnd() const
125   { return _pimpl->catalogsToDisable.end(); }
126
127   bool ServiceInfo::catalogToDisableFind( const std::string & alias_r ) const
128   { return( _pimpl->catalogsToDisable.find( alias_r ) != _pimpl->catalogsToDisable.end() ); }
129
130   void ServiceInfo::addCatalogToDisable( const std::string & alias_r )
131   { _pimpl->catalogsToDisable.insert( alias_r ); }
132
133   void ServiceInfo::delCatalogToDisable( const std::string & alias_r )
134   { _pimpl->catalogsToDisable.erase( alias_r ); }
135
136
137   std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
138   {
139     RepoInfoBase::dumpAsIniOn(str) << "url = " << url() << endl;
140     if ( ! catalogsToEnableEmpty() )
141       str << "catalogstoenable = " << str::joinEscaped( catalogsToEnableBegin(), catalogsToEnableEnd() ) << endl;
142     if ( ! catalogsToDisableEmpty() )
143       str << "catalogstodisable = " << str::joinEscaped( catalogsToDisableBegin(), catalogsToDisableEnd() ) << endl;
144     return str;
145   }
146
147   std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
148   { return dumpAsXMLOn(str, ""); }
149
150   ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
151   {
152     str
153       << "<service"
154       << " alias=\"" << escape(alias()) << "\""
155       << " name=\"" << escape(name()) << "\""
156       << " enabled=\"" << enabled() << "\""
157       << " autorefresh=\"" << autorefresh() << "\""
158       << " url=\"" << escape(url().asString()) << "\"";
159
160     if (content.empty())
161       str << "/>" << endl;
162     else
163       str << ">" << endl << content << "</service>" << endl;
164
165     return str;
166   }
167
168
169   std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
170   {
171     return obj.dumpAsIniOn(str);
172   }
173
174
175 ///////////////////////////////////////////////////////////////////////////////
176 } //namespace zypp
177 ///////////////////////////////////////////////////////////////////////////////