libzypp  11.13.5
ServiceInfo.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <ostream>
13 #include <iostream>
14 
15 #include "zypp/base/String.h"
17 
18 #include "zypp/RepoInfo.h"
20 
21 #include "zypp/ServiceInfo.h"
22 
23 using namespace std;
24 using zypp::xml::escape;
25 
27 namespace zypp
28 {
29 
31  //
32  // CLASS NAME : ServiceInfo::Impl
33  //
35  {
38 
39  public:
44 
45  public:
46  Impl()
47  : repo::RepoInfoBase::Impl()
48  , type(repo::ServiceType::NONE_e)
49  {}
50 
51  Impl(const Url & url_)
52  : repo::RepoInfoBase::Impl()
53  , url(url_)
54  , type(repo::ServiceType::NONE_e)
55  {}
56 
57  ~Impl()
58  {}
59 
60  void setProbedType( const repo::ServiceType & t ) const
61  {
62  if ( type == repo::ServiceType::NONE
63  && t != repo::ServiceType::NONE )
64  {
65  // lazy init!
66  const_cast<Impl*>(this)->type = t;
67  }
68  }
69 
70  private:
71  friend Impl * rwcowClone<Impl>( const Impl * rhs );
72 
74  Impl * clone() const
75  { return new Impl( *this ); }
76  };
78 
79 
81  //
82  // CLASS NAME : ServiceInfo::Impl
83  //
85 
86  const ServiceInfo ServiceInfo::noService;
87 
88  ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
89 
90  ServiceInfo::ServiceInfo(const string & alias)
91  : repo::RepoInfoBase(alias), _pimpl( new Impl() )
92  {}
93 
94  ServiceInfo::ServiceInfo(const string & alias, const Url & url)
95  : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
96  {}
97 
99  {}
100 
101  Url ServiceInfo::url() const { return _pimpl->url; }
102  void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
103 
105  { return _pimpl->type; }
107  { _pimpl->type = type; }
108 
110  { _pimpl->setProbedType( t ); }
111 
113  { return _pimpl->reposToEnable.empty(); }
114 
116  { return _pimpl->reposToEnable.size(); }
117 
118  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
119  { return _pimpl->reposToEnable.begin(); }
120 
121  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
122  { return _pimpl->reposToEnable.end(); }
123 
124  bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
125  { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
126 
127  void ServiceInfo::addRepoToEnable( const std::string & alias_r )
128  {
129  _pimpl->reposToEnable.insert( alias_r );
130  _pimpl->reposToDisable.erase( alias_r );
131  }
132 
133  void ServiceInfo::delRepoToEnable( const std::string & alias_r )
134  { _pimpl->reposToEnable.erase( alias_r ); }
135 
137  { _pimpl->reposToEnable.clear(); }
138 
139 
141  { return _pimpl->reposToDisable.empty(); }
142 
144  { return _pimpl->reposToDisable.size(); }
145 
146  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
147  { return _pimpl->reposToDisable.begin(); }
148 
149  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
150  { return _pimpl->reposToDisable.end(); }
151 
152  bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
153  { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
154 
155  void ServiceInfo::addRepoToDisable( const std::string & alias_r )
156  {
157  _pimpl->reposToDisable.insert( alias_r );
158  _pimpl->reposToEnable.erase( alias_r );
159  }
160 
161  void ServiceInfo::delRepoToDisable( const std::string & alias_r )
162  { _pimpl->reposToDisable.erase( alias_r ); }
163 
165  { _pimpl->reposToDisable.clear(); }
166 
167 
168  std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
169  {
171  << "url = " << url() << endl
172  << "type = " << type() << endl;
173 
174  if ( ! reposToEnableEmpty() )
175  str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
176  if ( ! reposToDisableEmpty() )
177  str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
178  return str;
179  }
180 
181  std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
182  { return dumpAsXMLOn(str, ""); }
183 
184  ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
185  {
186  str
187  << "<service"
188  << " alias=\"" << escape(alias()) << "\""
189  << " name=\"" << escape(name()) << "\""
190  << " enabled=\"" << enabled() << "\""
191  << " autorefresh=\"" << autorefresh() << "\""
192  << " url=\"" << escape(url().asString()) << "\""
193  << " type=\"" << type().asString() << "\"";
194 
195  if (content.empty())
196  str << "/>" << endl;
197  else
198  str << ">" << endl << content << "</service>" << endl;
199 
200  return str;
201  }
202 
203 
204  std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
205  {
206  return obj.dumpAsIniOn(str);
207  }
208 
209 
211 } //namespace zypp