libzypp  13.10.6
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 
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  {
170  RepoInfoBase::dumpAsIniOn(str)
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
std::string name() const
Repository short label.
ReposToDisable reposToDisable
Definition: ServiceInfo.cc:43
std::string alias() const
unique identifier for this source.
std::set< std::string > ReposToEnable
Container of repos.
Definition: ServiceInfo.h:99
ReposToDisable::size_type reposToDisableSize() const
Definition: ServiceInfo.cc:143
virtual std::ostream & dumpAsXMLOn(std::ostream &str) const
Write an XML representation of this ServiceInfo object.
Definition: ServiceInfo.cc:181
ReposToEnable::const_iterator reposToEnableBegin() const
Definition: ServiceInfo.cc:118
repo::ServiceType type
Definition: ServiceInfo.cc:41
void clearReposToEnable()
Clear the set of ReposToEnable.
Definition: ServiceInfo.cc:136
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
Definition: String.cc:339
ServiceInfo::ReposToDisable ReposToDisable
Definition: ServiceInfo.cc:37
void addRepoToEnable(const std::string &alias_r)
Add alias_r to the set of ReposToEnable.
Definition: ServiceInfo.cc:127
ReposToEnable reposToEnable
Definition: ServiceInfo.cc:42
const std::string & asString() const
Definition: ServiceType.cc:56
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
ReposToDisable::const_iterator reposToDisableEnd() const
Definition: ServiceInfo.cc:149
void setType(const repo::ServiceType &type)
Set service type.
Definition: ServiceInfo.cc:106
Impl * clone() const
clone for RWCOW_pointer
Definition: ServiceInfo.cc:74
std::string joinEscaped(_Iterator begin, _Iterator end, const char sep_r= ' ')
Join strings using separator sep_r, quoting or escaping the values.
Definition: String.h:659
RWCOW_pointer< Impl > _pimpl
Definition: ServiceInfo.h:163
ReposToDisable::const_iterator reposToDisableBegin() const
Definition: ServiceInfo.cc:146
std::string escape(const std::string &in_r)
Escape xml special charaters (&amp; -&gt; &amp;; from IoBind library).
Definition: XmlEscape.cc:106
void clearReposToDisable()
Clear the set of ReposToDisable.
Definition: ServiceInfo.cc:164
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
Service type enumeration.
Definition: ServiceType.h:26
void setProbedType(const repo::ServiceType &t) const
Definition: ServiceInfo.cc:60
bool reposToEnableEmpty() const
Definition: ServiceInfo.cc:112
zypp::Url url
Definition: MediaCurl.cc:193
ServiceInfo()
Default ctor creates noService.
Definition: ServiceInfo.cc:88
void delRepoToEnable(const std::string &alias_r)
Remove alias_r from the set of ReposToEnable.
Definition: ServiceInfo.cc:133
bool reposToDisableEmpty() const
Definition: ServiceInfo.cc:140
virtual ~ServiceInfo()
Definition: ServiceInfo.cc:98
SolvableIdType size_type
Definition: PoolMember.h:99
std::string asString(const Patch::SeverityFlag &obj)
Definition: Patch.cc:149
void setUrl(const Url &url)
Sets url for this service.
Definition: ServiceInfo.cc:102
ServiceInfo::ReposToEnable ReposToEnable
Definition: ServiceInfo.cc:36
std::set< std::string > ReposToDisable
Container of repos.
Definition: ServiceInfo.h:123
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
Impl(const Url &url_)
Definition: ServiceInfo.cc:51
bool repoToDisableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToDisable.
Definition: ServiceInfo.cc:152
void delRepoToDisable(const std::string &alias_r)
Remove alias_r from the set of ReposToDisable.
Definition: ServiceInfo.cc:161
void addRepoToDisable(const std::string &alias_r)
Add alias_r to the set of ReposToDisable.
Definition: ServiceInfo.cc:155
bool repoToEnableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToEnable.
Definition: ServiceInfo.cc:124
ReposToEnable::const_iterator reposToEnableEnd() const
Definition: ServiceInfo.cc:121
ReposToEnable::size_type reposToEnableSize() const
Definition: ServiceInfo.cc:115
Url url() const
Gets url to service.
Definition: ServiceInfo.cc:101
void setProbedType(const repo::ServiceType &t) const
Definition: ServiceInfo.cc:109
Url manipulation class.
Definition: Url.h:87
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Writes ServiceInfo to stream in &quot;.service&quot; format.
Definition: ServiceInfo.cc:168
repo::ServiceType type() const
Definition: ServiceInfo.cc:104