libzypp  14.29.1
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"
19 #include "zypp/ServiceInfo.h"
20 
21 using namespace std;
22 using zypp::xml::escape;
23 
25 namespace zypp
26 {
27 
29  //
30  // CLASS NAME : ServiceInfo::Impl
31  //
33  {
36 
37  public:
40  ReposToEnable reposToEnable;
41  ReposToDisable reposToDisable;
43 
44 
45  public:
46  Impl()
47  : type(repo::ServiceType::NONE_e)
48  {}
49 
50  Impl(const Url & url_)
51  : url(url_)
52  , type(repo::ServiceType::NONE_e)
53  {}
54 
56  {}
57 
58  void setProbedType( const repo::ServiceType & t ) const
59  {
60  if ( type == repo::ServiceType::NONE
61  && t != repo::ServiceType::NONE )
62  {
63  // lazy init!
64  const_cast<Impl*>(this)->type = t;
65  }
66  }
67 
68  private:
69  friend Impl * rwcowClone<Impl>( const Impl * rhs );
70 
72  Impl * clone() const
73  { return new Impl( *this ); }
74  };
76 
77 
79  //
80  // CLASS NAME : ServiceInfo::Impl
81  //
83 
84  const ServiceInfo ServiceInfo::noService;
85 
86  ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
87 
88  ServiceInfo::ServiceInfo(const string & alias)
89  : repo::RepoInfoBase(alias), _pimpl( new Impl() )
90  {}
91 
92  ServiceInfo::ServiceInfo(const string & alias, const Url & url)
93  : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
94  {}
95 
97  {}
98 
99  Url ServiceInfo::url() const { return _pimpl->url; }
100  void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
101 
103  { return _pimpl->type; }
105  { _pimpl->type = type; }
106 
108  { _pimpl->setProbedType( t ); }
109 
111  { return _pimpl->reposToEnable.empty(); }
112 
114  { return _pimpl->reposToEnable.size(); }
115 
116  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
117  { return _pimpl->reposToEnable.begin(); }
118 
119  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
120  { return _pimpl->reposToEnable.end(); }
121 
122  bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
123  { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
124 
125  void ServiceInfo::addRepoToEnable( const std::string & alias_r )
126  {
127  _pimpl->reposToEnable.insert( alias_r );
128  _pimpl->reposToDisable.erase( alias_r );
129  }
130 
131  void ServiceInfo::delRepoToEnable( const std::string & alias_r )
132  { _pimpl->reposToEnable.erase( alias_r ); }
133 
135  { _pimpl->reposToEnable.clear(); }
136 
137 
139  { return _pimpl->reposToDisable.empty(); }
140 
142  { return _pimpl->reposToDisable.size(); }
143 
144  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
145  { return _pimpl->reposToDisable.begin(); }
146 
147  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
148  { return _pimpl->reposToDisable.end(); }
149 
150  bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
151  { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
152 
153  void ServiceInfo::addRepoToDisable( const std::string & alias_r )
154  {
155  _pimpl->reposToDisable.insert( alias_r );
156  _pimpl->reposToEnable.erase( alias_r );
157  }
158 
159  void ServiceInfo::delRepoToDisable( const std::string & alias_r )
160  { _pimpl->reposToDisable.erase( alias_r ); }
161 
163  { _pimpl->reposToDisable.clear(); }
164 
166  { return _pimpl->repoStates; }
167 
169  { swap( _pimpl->repoStates, newStates_r ); }
170 
171  std::ostream & operator<<( std::ostream & str, const ServiceInfo::RepoState & obj )
172  {
173  return str
174  << "enabled=" << obj.enabled << " "
175  << "autorefresh=" << obj.autorefresh << " "
176  << "priority=" << obj.priority;
177  }
178 
179  std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
180  {
181  RepoInfoBase::dumpAsIniOn(str)
182  << "url = " << url() << endl
183  << "type = " << type() << endl;
184 
185  if ( ! repoStates().empty() )
186  {
187  unsigned cnt = 0U;
188  for ( const auto & el : repoStates() )
189  {
190  std::string tag( "repo_" );
191  tag += str::numstring( ++cnt );
192  const RepoState & state( el.second );
193 
194  str << tag << "=" << el.first << endl
195  << tag << "_enabled=" << state.enabled << endl
196  << tag << "_autorefresh=" << state.autorefresh << endl;
197  if ( state.priority != RepoInfo::defaultPriority() )
198  str
199  << tag << "_priority=" << state.priority << endl;
200  }
201  }
202 
203  if ( ! reposToEnableEmpty() )
204  str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
205  if ( ! reposToDisableEmpty() )
206  str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
207  return str;
208  }
209 
210  ostream & ServiceInfo::dumpAsXmlOn( ostream & str, const string & content ) const
211  {
212  str
213  << "<service"
214  << " alias=\"" << escape(alias()) << "\""
215  << " name=\"" << escape(name()) << "\""
216  << " enabled=\"" << enabled() << "\""
217  << " autorefresh=\"" << autorefresh() << "\""
218  << " url=\"" << escape(url().asString()) << "\""
219  << " type=\"" << type().asString() << "\"";
220 
221  if (content.empty())
222  str << "/>" << endl;
223  else
224  str << ">" << endl << content << "</service>" << endl;
225 
226  return str;
227  }
228 
229 
230  std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
231  {
232  return obj.dumpAsIniOn(str);
233  }
234 
235 
237 } //namespace zypp
std::string name() const
Repository short label.
ReposToDisable reposToDisable
Definition: ServiceInfo.cc:41
static unsigned defaultPriority()
The default priority (99).
Definition: RepoInfo.cc:216
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:141
ReposToEnable::const_iterator reposToEnableBegin() const
Definition: ServiceInfo.cc:116
repo::ServiceType type
Definition: ServiceInfo.cc:39
void clearReposToEnable()
Clear the set of ReposToEnable.
Definition: ServiceInfo.cc:134
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
Definition: String.cc:339
String related utilities and Regular expression matching.
ServiceInfo::ReposToDisable ReposToDisable
Definition: ServiceInfo.cc:35
void addRepoToEnable(const std::string &alias_r)
Add alias_r to the set of ReposToEnable.
Definition: ServiceInfo.cc:125
Definition: Arch.h:330
ReposToEnable reposToEnable
Definition: ServiceInfo.cc:40
const std::string & asString() const
Definition: ServiceType.cc:56
const RepoStates & repoStates() const
Access the remembered repository states.
Definition: ServiceInfo.cc:165
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:147
void setType(const repo::ServiceType &type)
Set service type.
Definition: ServiceInfo.cc:104
Impl * clone() const
clone for RWCOW_pointer
Definition: ServiceInfo.cc:72
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:733
RWCOW_pointer< Impl > _pimpl
Definition: ServiceInfo.h:194
ReposToDisable::const_iterator reposToDisableBegin() const
Definition: ServiceInfo.cc:144
std::map< std::string, RepoState > RepoStates
Definition: ServiceInfo.h:165
void clearReposToDisable()
Clear the set of ReposToDisable.
Definition: ServiceInfo.cc:162
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
Service type enumeration.
Definition: ServiceType.h:26
void setRepoStates(RepoStates newStates_r)
Remember a new set of repository states.
Definition: ServiceInfo.cc:168
void setProbedType(const repo::ServiceType &t) const
Definition: ServiceInfo.cc:58
bool reposToEnableEmpty() const
Definition: ServiceInfo.cc:110
zypp::Url url
Definition: MediaCurl.cc:193
ServiceInfo()
Default ctor creates noService.
Definition: ServiceInfo.cc:86
void delRepoToEnable(const std::string &alias_r)
Remove alias_r from the set of ReposToEnable.
Definition: ServiceInfo.cc:131
std::string numstring(char n, int w=0)
Definition: String.h:266
bool reposToDisableEmpty() const
Definition: ServiceInfo.cc:138
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this ServiceInfo object.
Definition: ServiceInfo.cc:210
virtual ~ServiceInfo()
Definition: ServiceInfo.cc:96
SolvableIdType size_type
Definition: PoolMember.h:99
std::string asString(const Patch::SeverityFlag &obj)
Definition: Patch.cc:166
void setUrl(const Url &url)
Sets url for this service.
Definition: ServiceInfo.cc:100
ServiceInfo::ReposToEnable ReposToEnable
Definition: ServiceInfo.cc:34
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:50
bool repoToDisableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToDisable.
Definition: ServiceInfo.cc:150
void delRepoToDisable(const std::string &alias_r)
Remove alias_r from the set of ReposToDisable.
Definition: ServiceInfo.cc:159
void addRepoToDisable(const std::string &alias_r)
Add alias_r to the set of ReposToDisable.
Definition: ServiceInfo.cc:153
bool repoToEnableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToEnable.
Definition: ServiceInfo.cc:122
ReposToEnable::const_iterator reposToEnableEnd() const
Definition: ServiceInfo.cc:119
ReposToEnable::size_type reposToEnableSize() const
Definition: ServiceInfo.cc:113
Url url() const
Gets url to service.
Definition: ServiceInfo.cc:99
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
void setProbedType(const repo::ServiceType &t) const
Definition: ServiceInfo.cc:107
Url manipulation class.
Definition: Url.h:87
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Writes ServiceInfo to stream in ".service" format.
Definition: ServiceInfo.cc:179
repo::ServiceType type() const
Definition: ServiceInfo.cc:102
detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
Definition: XmlEscape.h:51