libzypp 17.37.10

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>
16#include <zypp-core/base/DefaultIntegral>
17#include <zypp/parser/xml/XmlEscape.h>
18
19#include <zypp/RepoInfo.h>
20#include <zypp/ServiceInfo.h>
21
22 using std::endl;
23 using zypp::xml::escape;
24
26 namespace zypp
27{
28
30 //
31 // CLASS NAME : ServiceInfo::Impl
32 //
33 struct ServiceInfo::Impl
34 {
35 using ReposToEnable = ServiceInfo::ReposToEnable;
36 using ReposToDisable = ServiceInfo::ReposToDisable;
37
38 public:
39 RepoVariablesReplacedUrl _url;
40 repo::ServiceType _type;
41 ReposToEnable _reposToEnable;
42 ReposToDisable _reposToDisable;
43 RepoStates _repoStates;
44 DefaultIntegral<Date::Duration,0> _ttl;
45 Date _lrf;
46
47 public:
48 Impl()
49 {}
50
51 Impl(const Url &url_r) : _url(url_r) {}
52
53 Impl(const Impl &) = default;
54 Impl(Impl &&) = delete;
55 Impl &operator=(const Impl &) = delete;
56 Impl &operator=(Impl &&) = delete;
57
58 ~Impl()
59 {}
60
61 void setProbedType( const repo::ServiceType & type_r ) const
62 {
63 if ( _type == repo::ServiceType::NONE
64 && type_r != repo::ServiceType::NONE )
65 {
66 // lazy init!
67 const_cast<Impl*>(this)->_type = type_r;
68 }
69 }
70
71 private:
72 friend Impl * rwcowClone<Impl>( const Impl * rhs );
73
75 Impl * clone() const
76 { return new Impl( *this ); }
77 };
78
79
80
82 //
83 // CLASS NAME : ServiceInfo::Impl
84 //
86
87 const ServiceInfo ServiceInfo::noService;
88
89 ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
90
91 ServiceInfo::ServiceInfo(const std::string & alias)
92 : repo::RepoInfoBase(alias), _pimpl( new Impl() )
93 {}
94
95 ServiceInfo::ServiceInfo(const std::string & alias, const Url & url)
96 : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
97 {}
98
99 ServiceInfo::~ServiceInfo()
100 {}
101
102 Url ServiceInfo::url() const // Variables replaced
103 { return _pimpl->_url.transformed(); }
104
105 Url ServiceInfo::rawUrl() const // Raw
106 { return _pimpl->_url.raw(); }
107
108 void ServiceInfo::setUrl( const Url& url ) // Raw
109 { _pimpl->_url.raw() = url; }
110
111 repo::ServiceType ServiceInfo::type() const { return _pimpl->_type; }
112 void ServiceInfo::setType( const repo::ServiceType & type ) { _pimpl->_type = type; }
113 void ServiceInfo::setProbedType( const repo::ServiceType &t ) const { _pimpl->setProbedType( t ); }
114
115 Date::Duration ServiceInfo::ttl() const { return _pimpl->_ttl; }
116 void ServiceInfo::setTtl( Date::Duration ttl_r ) { _pimpl->_ttl = ttl_r; }
117 void ServiceInfo::setProbedTtl( Date::Duration ttl_r ) const { const_cast<ServiceInfo*>(this)->setTtl( ttl_r ); }
118
119 Date ServiceInfo::lrf() const { return _pimpl->_lrf; }
120 void ServiceInfo::setLrf( Date lrf_r ) { _pimpl->_lrf = lrf_r; }
121
122 bool ServiceInfo::reposToEnableEmpty() const { return _pimpl->_reposToEnable.empty(); }
123 ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const { return _pimpl->_reposToEnable.size(); }
124 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const { return _pimpl->_reposToEnable.begin(); }
125 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const { return _pimpl->_reposToEnable.end(); }
126
127 bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
128 { return( _pimpl->_reposToEnable.find( alias_r ) != _pimpl->_reposToEnable.end() ); }
129
130 void ServiceInfo::addRepoToEnable( const std::string & alias_r )
131 {
132 _pimpl->_reposToEnable.insert( alias_r );
133 _pimpl->_reposToDisable.erase( alias_r );
134 }
135
136 void ServiceInfo::delRepoToEnable( const std::string & alias_r )
137 { _pimpl->_reposToEnable.erase( alias_r ); }
138
139 void ServiceInfo::clearReposToEnable()
140 { _pimpl->_reposToEnable.clear(); }
141
142
143 bool ServiceInfo::reposToDisableEmpty() const { return _pimpl->_reposToDisable.empty(); }
144 ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const { return _pimpl->_reposToDisable.size(); }
145 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const { return _pimpl->_reposToDisable.begin(); }
146 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const { return _pimpl->_reposToDisable.end(); }
147
148 bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
149 { return( _pimpl->_reposToDisable.find( alias_r ) != _pimpl->_reposToDisable.end() ); }
150
151 void ServiceInfo::addRepoToDisable( const std::string & alias_r )
152 {
153 _pimpl->_reposToDisable.insert( alias_r );
154 _pimpl->_reposToEnable.erase( alias_r );
155 }
156
157 void ServiceInfo::delRepoToDisable( const std::string & alias_r )
158 { _pimpl->_reposToDisable.erase( alias_r ); }
159
160 void ServiceInfo::clearReposToDisable()
161 { _pimpl->_reposToDisable.clear(); }
162
163
164 const ServiceInfo::RepoStates & ServiceInfo::repoStates() const { return _pimpl->_repoStates; }
165 void ServiceInfo::setRepoStates( RepoStates newStates_r ) { swap( _pimpl->_repoStates, newStates_r ); }
166
167
168 std::ostream & operator<<( std::ostream & str, const ServiceInfo::RepoState & obj )
169 {
170 return str
171 << "enabled=" << obj.enabled << " "
172 << "autorefresh=" << obj.autorefresh << " "
173 << "priority=" << obj.priority;
174 }
175
176 std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
177 {
178 RepoInfoBase::dumpAsIniOn(str)
179 << "url = " << hotfix1050625::asString( rawUrl() ) << endl
180 << "type = " << type() << endl;
181
182 if ( ttl() )
183 str << "ttl_sec = " << ttl() << endl;
184
185 if ( lrf() )
186 str << "lrf_dat = " << lrf().asSeconds() << endl;
187
188 if ( ! repoStates().empty() )
189 {
190 unsigned cnt = 0U;
191 for ( const auto & el : repoStates() )
192 {
193 std::string tag( "repo_" );
194 tag += str::numstring( ++cnt );
195 const RepoState & state( el.second );
196
197 str << tag << "=" << el.first << endl
198 << tag << "_enabled=" << state.enabled << endl
199 << tag << "_autorefresh=" << state.autorefresh << endl;
200 if ( state.priority != RepoInfo::defaultPriority() )
201 str
202 << tag << "_priority=" << state.priority << endl;
203 }
204 }
205
206 if ( ! reposToEnableEmpty() )
207 str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
208 if ( ! reposToDisableEmpty() )
209 str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
210 return str;
211 }
212
213 std::ostream & ServiceInfo::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
214 {
215 str
216 << "<service"
217 << " alias=\"" << escape(alias()) << "\""
218 << " name=\"" << escape(name()) << "\""
219 << " enabled=\"" << enabled() << "\""
220 << " autorefresh=\"" << autorefresh() << "\""
221 << " url=\"" << escape(url().asString()) << "\""
222 << " type=\"" << type().asString() << "\""
223 << " ttl_sec=\"" << ttl() << "\"";
224
225 if (content.empty())
226 str << "/>" << endl;
227 else
228 str << ">" << endl << content << "</service>" << endl;
229
230 return str;
231 }
232
233
234 std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
235 {
236 return obj.dumpAsIniOn(str);
237 }
238
239
241} //namespace zypp
escape
ZYPP_API detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
Definition XmlEscape.h:51
RepoInfo.h
RepoVariablesReplacedUrl
base::ValueTransform< Url, repo::RepoVariablesUrlReplacer > RepoVariablesReplacedUrl
Helper managing repo variables replaced urls.
Definition RepoVariables.h:133
ServiceInfo.h
zypp::Date
Store and operate on date (time_t).
Definition Date.h:33
zypp::Date::Duration
time_t Duration
Definition Date.h:39
zypp::Date::asSeconds
std::string asSeconds() const
Convert to string representation of calendar time in numeric form (like "1029255142").
Definition Date.h:126
zypp::DefaultIntegral
Integral type with defined initial value when default constructed.
Definition defaultintegral.h:42
zypp::RepoInfo::defaultPriority
static unsigned defaultPriority()
The default priority (99).
Definition RepoInfo.cc:512
zypp::ServiceInfo
Service data.
Definition ServiceInfo.h:37
zypp::ServiceInfo::setProbedTtl
void setProbedTtl(Date::Duration ttl_r) const
Lazy init sugested TTL.
Definition ServiceInfo.cc:117
zypp::ServiceInfo::reposToEnableSize
ReposToEnable::size_type reposToEnableSize() const
Definition ServiceInfo.cc:123
zypp::ServiceInfo::type
repo::ServiceType type() const
Service type.
Definition ServiceInfo.cc:111
zypp::ServiceInfo::reposToEnableBegin
ReposToEnable::const_iterator reposToEnableBegin() const
Definition ServiceInfo.cc:124
zypp::ServiceInfo::ttl
Date::Duration ttl() const
Sugested TTL between two metadata auto-refreshs.
Definition ServiceInfo.cc:115
zypp::ServiceInfo::setLrf
void setLrf(Date lrf_r)
Set date of last refresh.
Definition ServiceInfo.cc:120
zypp::ServiceInfo::setType
void setType(const repo::ServiceType &type)
Set service type.
Definition ServiceInfo.cc:112
zypp::ServiceInfo::lrf
Date lrf() const
Date of last refresh (if known).
Definition ServiceInfo.cc:119
zypp::ServiceInfo::repoToDisableFind
bool repoToDisableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToDisable.
Definition ServiceInfo.cc:148
zypp::ServiceInfo::repoToEnableFind
bool repoToEnableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToEnable.
Definition ServiceInfo.cc:127
zypp::ServiceInfo::~ServiceInfo
~ServiceInfo() override
Definition ServiceInfo.cc:99
zypp::ServiceInfo::repoStates
const RepoStates & repoStates() const
Access the remembered repository states.
Definition ServiceInfo.cc:164
zypp::ServiceInfo::reposToDisableEnd
ReposToDisable::const_iterator reposToDisableEnd() const
Definition ServiceInfo.cc:146
zypp::ServiceInfo::ServiceInfo
ServiceInfo()
Default ctor creates noService.
Definition ServiceInfo.cc:89
zypp::ServiceInfo::reposToEnableEnd
ReposToEnable::const_iterator reposToEnableEnd() const
Definition ServiceInfo.cc:125
zypp::ServiceInfo::ReposToDisable
std::set< std::string > ReposToDisable
Container of repos.
Definition ServiceInfo.h:141
zypp::ServiceInfo::RepoStates
std::map< std::string, RepoState > RepoStates
Definition ServiceInfo.h:185
zypp::ServiceInfo::addRepoToDisable
void addRepoToDisable(const std::string &alias_r)
Add alias_r to the set of ReposToDisable.
Definition ServiceInfo.cc:151
zypp::ServiceInfo::clearReposToEnable
void clearReposToEnable()
Clear the set of ReposToEnable.
Definition ServiceInfo.cc:139
zypp::ServiceInfo::delRepoToDisable
void delRepoToDisable(const std::string &alias_r)
Remove alias_r from the set of ReposToDisable.
Definition ServiceInfo.cc:157
zypp::ServiceInfo::reposToEnableEmpty
bool reposToEnableEmpty() const
Definition ServiceInfo.cc:122
zypp::ServiceInfo::url
Url url() const
The service url.
Definition ServiceInfo.cc:102
zypp::ServiceInfo::_pimpl
RWCOW_pointer< Impl > _pimpl
Definition ServiceInfo.h:214
zypp::ServiceInfo::dumpAsIniOn
std::ostream & dumpAsIniOn(std::ostream &str) const override
Writes ServiceInfo to stream in ".service" format.
Definition ServiceInfo.cc:176
zypp::ServiceInfo::setProbedType
void setProbedType(const repo::ServiceType &t) const
Lazy init service type.
Definition ServiceInfo.cc:113
zypp::ServiceInfo::setTtl
void setTtl(Date::Duration ttl_r)
Set sugested TTL.
Definition ServiceInfo.cc:116
zypp::ServiceInfo::rawUrl
Url rawUrl() const
The service raw url (no variables replaced)
Definition ServiceInfo.cc:105
zypp::ServiceInfo::addRepoToEnable
void addRepoToEnable(const std::string &alias_r)
Add alias_r to the set of ReposToEnable.
Definition ServiceInfo.cc:130
zypp::ServiceInfo::clearReposToDisable
void clearReposToDisable()
Clear the set of ReposToDisable.
Definition ServiceInfo.cc:160
zypp::ServiceInfo::ReposToEnable
std::set< std::string > ReposToEnable
Container of repos.
Definition ServiceInfo.h:115
zypp::ServiceInfo::setUrl
void setUrl(const Url &url)
Set the service url (raw value)
Definition ServiceInfo.cc:108
zypp::ServiceInfo::dumpAsXmlOn
std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const override
Write an XML representation of this ServiceInfo object.
Definition ServiceInfo.cc:213
zypp::ServiceInfo::reposToDisableBegin
ReposToDisable::const_iterator reposToDisableBegin() const
Definition ServiceInfo.cc:145
zypp::ServiceInfo::delRepoToEnable
void delRepoToEnable(const std::string &alias_r)
Remove alias_r from the set of ReposToEnable.
Definition ServiceInfo.cc:136
zypp::ServiceInfo::reposToDisableSize
ReposToDisable::size_type reposToDisableSize() const
Definition ServiceInfo.cc:144
zypp::ServiceInfo::setRepoStates
void setRepoStates(RepoStates newStates_r)
Remember a new set of repository states.
Definition ServiceInfo.cc:165
zypp::ServiceInfo::reposToDisableEmpty
bool reposToDisableEmpty() const
Definition ServiceInfo.cc:143
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::repo::RepoInfoBase::RepoInfoBase
RepoInfoBase()
Definition RepoInfoBase.cc:72
zypp::repo::RepoInfoBase::autorefresh
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
Definition RepoInfoBase.cc:101
zypp::repo::RepoInfoBase::name
std::string name() const
Repository name.
Definition RepoInfoBase.cc:110
zypp::repo::RepoInfoBase::enabled
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
Definition RepoInfoBase.cc:98
zypp::repo::RepoInfoBase::alias
std::string alias() const
unique identifier for this source.
Definition RepoInfoBase.cc:104
str
String related utilities and Regular expression matching.
zypp::hotfix1050625::asString
std::string asString(const Url &url_r)
Definition Url.cc:948
zypp::repo
Definition DeltaCandidates.cc:30
zypp::str::joinEscaped
std::string joinEscaped(TIterator begin, TIterator end, const char sep_r=' ')
Join strings using separator sep_r, quoting or escaping the values.
Definition String.h:868
zypp::str::numstring
std::string numstring(char n, int w=0)
Definition String.h:290
zypp::xml::escape
ZYPP_API detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
Definition XmlEscape.h:51
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
zypp::asString
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
zypp::ServiceInfo::Impl
Definition ServiceInfo.cc:34
zypp::ServiceInfo::Impl::ReposToDisable
ServiceInfo::ReposToDisable ReposToDisable
Definition ServiceInfo.cc:36
zypp::ServiceInfo::Impl::Impl
Impl(const Impl &)=default
zypp::ServiceInfo::Impl::operator=
Impl & operator=(Impl &&)=delete
zypp::ServiceInfo::Impl::operator=
Impl & operator=(const Impl &)=delete
zypp::ServiceInfo::Impl::_reposToDisable
ReposToDisable _reposToDisable
Definition ServiceInfo.cc:42
zypp::ServiceInfo::Impl::_type
repo::ServiceType _type
Definition ServiceInfo.cc:40
zypp::ServiceInfo::Impl::_ttl
DefaultIntegral< Date::Duration, 0 > _ttl
Definition ServiceInfo.cc:44
zypp::ServiceInfo::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::ServiceInfo::Impl::Impl
Impl(Impl &&)=delete
zypp::ServiceInfo::Impl::_url
RepoVariablesReplacedUrl _url
Definition ServiceInfo.cc:39
zypp::ServiceInfo::Impl::Impl
Impl()
Definition ServiceInfo.cc:48
zypp::ServiceInfo::Impl::setProbedType
void setProbedType(const repo::ServiceType &type_r) const
Definition ServiceInfo.cc:61
zypp::ServiceInfo::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition ServiceInfo.cc:75
zypp::ServiceInfo::Impl::ReposToEnable
ServiceInfo::ReposToEnable ReposToEnable
Definition ServiceInfo.cc:35
zypp::ServiceInfo::Impl::Impl
Impl(const Url &url_r)
Definition ServiceInfo.cc:51
zypp::ServiceInfo::Impl::_reposToEnable
ReposToEnable _reposToEnable
Definition ServiceInfo.cc:41
zypp::ServiceInfo::Impl::_repoStates
RepoStates _repoStates
Definition ServiceInfo.cc:43
zypp::ServiceInfo::Impl::~Impl
~Impl()
Definition ServiceInfo.cc:58
zypp::ServiceInfo::Impl::_lrf
Date _lrf
Definition ServiceInfo.cc:45
zypp::ServiceInfo::RepoState
Definition ServiceInfo.h:168
zypp::ServiceInfo::RepoState::priority
unsigned priority
Definition ServiceInfo.h:171
zypp::ServiceInfo::RepoState::autorefresh
bool autorefresh
Definition ServiceInfo.h:170
zypp::ServiceInfo::RepoState::enabled
bool enabled
Definition ServiceInfo.h:169
zypp::repo::ServiceType
Service type enumeration.
Definition ServiceType.h:27
zypp::repo::ServiceType::asString
const std::string & asString() const
Definition ServiceType.cc:55
String.h
XmlEscape.h