libzypp  14.48.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"
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:
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 // Variables replaced
100  { return _pimpl->url.transformed(); }
101 
102  Url ServiceInfo::rawUrl() const // Raw
103  { return _pimpl->url.raw(); }
104 
105  void ServiceInfo::setUrl( const Url& url ) // Raw
106  { _pimpl->url.raw() = url; }
107 
109  { return _pimpl->type; }
111  { _pimpl->type = type; }
112 
114  { _pimpl->setProbedType( t ); }
115 
117  { return _pimpl->reposToEnable.empty(); }
118 
120  { return _pimpl->reposToEnable.size(); }
121 
122  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
123  { return _pimpl->reposToEnable.begin(); }
124 
125  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
126  { return _pimpl->reposToEnable.end(); }
127 
128  bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
129  { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
130 
131  void ServiceInfo::addRepoToEnable( const std::string & alias_r )
132  {
133  _pimpl->reposToEnable.insert( alias_r );
134  _pimpl->reposToDisable.erase( alias_r );
135  }
136 
137  void ServiceInfo::delRepoToEnable( const std::string & alias_r )
138  { _pimpl->reposToEnable.erase( alias_r ); }
139 
141  { _pimpl->reposToEnable.clear(); }
142 
143 
145  { return _pimpl->reposToDisable.empty(); }
146 
148  { return _pimpl->reposToDisable.size(); }
149 
150  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
151  { return _pimpl->reposToDisable.begin(); }
152 
153  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
154  { return _pimpl->reposToDisable.end(); }
155 
156  bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
157  { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
158 
159  void ServiceInfo::addRepoToDisable( const std::string & alias_r )
160  {
161  _pimpl->reposToDisable.insert( alias_r );
162  _pimpl->reposToEnable.erase( alias_r );
163  }
164 
165  void ServiceInfo::delRepoToDisable( const std::string & alias_r )
166  { _pimpl->reposToDisable.erase( alias_r ); }
167 
169  { _pimpl->reposToDisable.clear(); }
170 
172  { return _pimpl->repoStates; }
173 
175  { swap( _pimpl->repoStates, newStates_r ); }
176 
177  std::ostream & operator<<( std::ostream & str, const ServiceInfo::RepoState & obj )
178  {
179  return str
180  << "enabled=" << obj.enabled << " "
181  << "autorefresh=" << obj.autorefresh << " "
182  << "priority=" << obj.priority;
183  }
184 
185  std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
186  {
187  RepoInfoBase::dumpAsIniOn(str)
188  << "url = " << rawUrl() << endl
189  << "type = " << type() << endl;
190 
191  if ( ! repoStates().empty() )
192  {
193  unsigned cnt = 0U;
194  for ( const auto & el : repoStates() )
195  {
196  std::string tag( "repo_" );
197  tag += str::numstring( ++cnt );
198  const RepoState & state( el.second );
199 
200  str << tag << "=" << el.first << endl
201  << tag << "_enabled=" << state.enabled << endl
202  << tag << "_autorefresh=" << state.autorefresh << endl;
203  if ( state.priority != RepoInfo::defaultPriority() )
204  str
205  << tag << "_priority=" << state.priority << endl;
206  }
207  }
208 
209  if ( ! reposToEnableEmpty() )
210  str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
211  if ( ! reposToDisableEmpty() )
212  str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
213  return str;
214  }
215 
216  ostream & ServiceInfo::dumpAsXmlOn( ostream & str, const string & content ) const
217  {
218  str
219  << "<service"
220  << " alias=\"" << escape(alias()) << "\""
221  << " name=\"" << escape(name()) << "\""
222  << " enabled=\"" << enabled() << "\""
223  << " autorefresh=\"" << autorefresh() << "\""
224  << " url=\"" << escape(url().asString()) << "\""
225  << " type=\"" << type().asString() << "\"";
226 
227  if (content.empty())
228  str << "/>" << endl;
229  else
230  str << ">" << endl << content << "</service>" << endl;
231 
232  return str;
233  }
234 
235 
236  std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
237  {
238  return obj.dumpAsIniOn(str);
239  }
240 
241 
243 } //namespace zypp
std::string name() const
Repository name.
Service data.
Definition: ServiceInfo.h:35
ReposToDisable reposToDisable
Definition: ServiceInfo.cc:41
static unsigned defaultPriority()
The default priority (99).
Definition: RepoInfo.cc:299
std::string alias() const
unique identifier for this source.
std::set< std::string > ReposToEnable
Container of repos.
Definition: ServiceInfo.h:92
ReposToDisable::size_type reposToDisableSize() const
Definition: ServiceInfo.cc:147
ReposToEnable::const_iterator reposToEnableBegin() const
Definition: ServiceInfo.cc:122
repo::ServiceType type
Definition: ServiceInfo.cc:39
void clearReposToEnable()
Clear the set of ReposToEnable.
Definition: ServiceInfo.cc:140
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
Definition: String.cc:354
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:131
ReposToEnable reposToEnable
Definition: ServiceInfo.cc:40
const std::string & asString() const
Definition: ServiceType.cc:56
Url url
Definition: MediaCurl.cc:180
const RepoStates & repoStates() const
Access the remembered repository states.
Definition: ServiceInfo.cc:171
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:153
void setType(const repo::ServiceType &type)
Set service type.
Definition: ServiceInfo.cc:110
base::ValueTransform< Url, repo::RepoVariablesUrlReplacer > RepoVariablesReplacedUrl
RepoVariablesReplacedUrl url
Definition: ServiceInfo.cc:38
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:785
RWCOW_pointer< Impl > _pimpl
Definition: ServiceInfo.h:184
ReposToDisable::const_iterator reposToDisableBegin() const
Definition: ServiceInfo.cc:150
std::map< std::string, RepoState > RepoStates
Definition: ServiceInfo.h:158
void clearReposToDisable()
Clear the set of ReposToDisable.
Definition: ServiceInfo.cc:168
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:174
void setProbedType(const repo::ServiceType &t) const
Definition: ServiceInfo.cc:58
bool reposToEnableEmpty() const
Definition: ServiceInfo.cc:116
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:137
std::string numstring(char n, int w=0)
Definition: String.h:311
bool reposToDisableEmpty() const
Definition: ServiceInfo.cc:144
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this ServiceInfo object.
Definition: ServiceInfo.cc:216
virtual ~ServiceInfo()
Definition: ServiceInfo.cc:96
SolvableIdType size_type
Definition: PoolMember.h:147
std::string asString(const Patch::SeverityFlag &obj)
Definition: Patch.cc:166
void setUrl(const Url &url)
Set the service url (raw value)
Definition: ServiceInfo.cc:105
ServiceInfo::ReposToEnable ReposToEnable
Definition: ServiceInfo.cc:34
std::set< std::string > ReposToDisable
Container of repos.
Definition: ServiceInfo.h:116
Url rawUrl() const
The service raw url (no variables replaced)
Definition: ServiceInfo.cc:102
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:156
void delRepoToDisable(const std::string &alias_r)
Remove alias_r from the set of ReposToDisable.
Definition: ServiceInfo.cc:165
void addRepoToDisable(const std::string &alias_r)
Add alias_r to the set of ReposToDisable.
Definition: ServiceInfo.cc:159
bool repoToEnableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToEnable.
Definition: ServiceInfo.cc:128
ReposToEnable::const_iterator reposToEnableEnd() const
Definition: ServiceInfo.cc:125
ReposToEnable::size_type reposToEnableSize() const
Definition: ServiceInfo.cc:119
Url url() const
The service url.
Definition: ServiceInfo.cc:99
void setProbedType(const repo::ServiceType &t) const
Lazy init service type.
Definition: ServiceInfo.cc:113
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:185
repo::ServiceType type() const
Service type.
Definition: ServiceInfo.cc:108
detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
Definition: XmlEscape.h:51