libzypp 17.31.23
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
22using std::endl;
24
26namespace zypp
27{
28
30 //
31 // CLASS NAME : ServiceInfo::Impl
32 //
34 {
37
38 public:
46
47 public:
49 {}
50
51 Impl( const Url & url_r )
52 : _url( url_r )
53 {}
54
56 {}
57
58 void setProbedType( const repo::ServiceType & type_r ) const
59 {
61 && type_r != repo::ServiceType::NONE )
62 {
63 // lazy init!
64 const_cast<Impl*>(this)->_type = type_r;
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
85
86 ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
87
88 ServiceInfo::ServiceInfo(const std::string & alias)
89 : repo::RepoInfoBase(alias), _pimpl( new Impl() )
90 {}
91
92 ServiceInfo::ServiceInfo(const std::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
103 { return _pimpl->_url.raw(); }
104
105 void ServiceInfo::setUrl( const Url& url ) // Raw
106 { _pimpl->_url.raw() = url; }
107
108 repo::ServiceType ServiceInfo::type() const { return _pimpl->_type; }
109 void ServiceInfo::setType( const repo::ServiceType & type ) { _pimpl->_type = type; }
110 void ServiceInfo::setProbedType( const repo::ServiceType &t ) const { _pimpl->setProbedType( t ); }
111
112 Date::Duration ServiceInfo::ttl() const { return _pimpl->_ttl; }
113 void ServiceInfo::setTtl( Date::Duration ttl_r ) { _pimpl->_ttl = ttl_r; }
114 void ServiceInfo::setProbedTtl( Date::Duration ttl_r ) const { const_cast<ServiceInfo*>(this)->setTtl( ttl_r ); }
115
116 Date ServiceInfo::lrf() const { return _pimpl->_lrf; }
117 void ServiceInfo::setLrf( Date lrf_r ) { _pimpl->_lrf = lrf_r; }
118
119 bool ServiceInfo::reposToEnableEmpty() const { return _pimpl->_reposToEnable.empty(); }
120 ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const { return _pimpl->_reposToEnable.size(); }
121 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const { return _pimpl->_reposToEnable.begin(); }
122 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const { 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
140 bool ServiceInfo::reposToDisableEmpty() const { return _pimpl->_reposToDisable.empty(); }
141 ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const { return _pimpl->_reposToDisable.size(); }
142 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const { return _pimpl->_reposToDisable.begin(); }
143 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const { return _pimpl->_reposToDisable.end(); }
144
145 bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
146 { return( _pimpl->_reposToDisable.find( alias_r ) != _pimpl->_reposToDisable.end() ); }
147
148 void ServiceInfo::addRepoToDisable( const std::string & alias_r )
149 {
150 _pimpl->_reposToDisable.insert( alias_r );
151 _pimpl->_reposToEnable.erase( alias_r );
152 }
153
154 void ServiceInfo::delRepoToDisable( const std::string & alias_r )
155 { _pimpl->_reposToDisable.erase( alias_r ); }
156
158 { _pimpl->_reposToDisable.clear(); }
159
160
161 const ServiceInfo::RepoStates & ServiceInfo::repoStates() const { return _pimpl->_repoStates; }
162 void ServiceInfo::setRepoStates( RepoStates newStates_r ) { swap( _pimpl->_repoStates, newStates_r ); }
163
164
165 std::ostream & operator<<( std::ostream & str, const ServiceInfo::RepoState & obj )
166 {
167 return str
168 << "enabled=" << obj.enabled << " "
169 << "autorefresh=" << obj.autorefresh << " "
170 << "priority=" << obj.priority;
171 }
172
173 std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
174 {
175 RepoInfoBase::dumpAsIniOn(str)
176 << "url = " << hotfix1050625::asString( rawUrl() ) << endl
177 << "type = " << type() << endl;
178
179 if ( ttl() )
180 str << "ttl_sec = " << ttl() << endl;
181
182 if ( lrf() )
183 str << "lrf_dat = " << lrf().asSeconds() << 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 std::ostream & ServiceInfo::dumpAsXmlOn( std::ostream & str, const std::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 << " ttl_sec=\"" << ttl() << "\"";
221
222 if (content.empty())
223 str << "/>" << endl;
224 else
225 str << ">" << endl << content << "</service>" << endl;
226
227 return str;
228 }
229
230
231 std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
232 {
233 return obj.dumpAsIniOn(str);
234 }
235
236
238} //namespace zypp
base::ValueTransform< Url, repo::RepoVariablesUrlReplacer > RepoVariablesReplacedUrl
Helper managing repo variables replaced urls.
Store and operate on date (time_t).
Definition: Date.h:33
time_t Duration
Definition: Date.h:39
std::string asSeconds() const
Convert to string representation of calendar time in numeric form (like "1029255142").
Definition: Date.h:126
Integral type with defined initial value when default constructed.
static unsigned defaultPriority()
The default priority (99).
Definition: RepoInfo.cc:394
Service data.
Definition: ServiceInfo.h:37
void setProbedTtl(Date::Duration ttl_r) const
Lazy init sugested TTL.
Definition: ServiceInfo.cc:114
ReposToEnable::size_type reposToEnableSize() const
Definition: ServiceInfo.cc:120
repo::ServiceType type() const
Service type.
Definition: ServiceInfo.cc:108
ReposToEnable::const_iterator reposToEnableBegin() const
Definition: ServiceInfo.cc:121
Date::Duration ttl() const
Sugested TTL between two metadata auto-refreshs.
Definition: ServiceInfo.cc:112
void setLrf(Date lrf_r)
Set date of last refresh.
Definition: ServiceInfo.cc:117
void setType(const repo::ServiceType &type)
Set service type.
Definition: ServiceInfo.cc:109
Date lrf() const
Date of last refresh (if known).
Definition: ServiceInfo.cc:116
bool repoToDisableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToDisable.
Definition: ServiceInfo.cc:145
bool repoToEnableFind(const std::string &alias_r) const
Whether alias_r is mentioned in ReposToEnable.
Definition: ServiceInfo.cc:124
virtual ~ServiceInfo()
Definition: ServiceInfo.cc:96
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this ServiceInfo object.
Definition: ServiceInfo.cc:210
const RepoStates & repoStates() const
Access the remembered repository states.
Definition: ServiceInfo.cc:161
ReposToDisable::const_iterator reposToDisableEnd() const
Definition: ServiceInfo.cc:143
ServiceInfo()
Default ctor creates noService.
Definition: ServiceInfo.cc:86
ReposToEnable::const_iterator reposToEnableEnd() const
Definition: ServiceInfo.cc:122
void addRepoToDisable(const std::string &alias_r)
Add alias_r to the set of ReposToDisable.
Definition: ServiceInfo.cc:148
void clearReposToEnable()
Clear the set of ReposToEnable.
Definition: ServiceInfo.cc:136
std::set< std::string > ReposToDisable
Container of repos.
Definition: ServiceInfo.h:141
void delRepoToDisable(const std::string &alias_r)
Remove alias_r from the set of ReposToDisable.
Definition: ServiceInfo.cc:154
bool reposToEnableEmpty() const
Definition: ServiceInfo.cc:119
Url url() const
The service url.
Definition: ServiceInfo.cc:99
RWCOW_pointer< Impl > _pimpl
Definition: ServiceInfo.h:214
std::set< std::string > ReposToEnable
Container of repos.
Definition: ServiceInfo.h:115
void setProbedType(const repo::ServiceType &t) const
Lazy init service type.
Definition: ServiceInfo.cc:110
void setTtl(Date::Duration ttl_r)
Set sugested TTL.
Definition: ServiceInfo.cc:113
std::map< std::string, RepoState > RepoStates
Definition: ServiceInfo.h:185
Url rawUrl() const
The service raw url (no variables replaced)
Definition: ServiceInfo.cc:102
void addRepoToEnable(const std::string &alias_r)
Add alias_r to the set of ReposToEnable.
Definition: ServiceInfo.cc:127
void clearReposToDisable()
Clear the set of ReposToDisable.
Definition: ServiceInfo.cc:157
void setUrl(const Url &url)
Set the service url (raw value)
Definition: ServiceInfo.cc:105
ReposToDisable::const_iterator reposToDisableBegin() const
Definition: ServiceInfo.cc:142
void delRepoToEnable(const std::string &alias_r)
Remove alias_r from the set of ReposToEnable.
Definition: ServiceInfo.cc:133
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Writes ServiceInfo to stream in ".service" format.
Definition: ServiceInfo.cc:173
ReposToDisable::size_type reposToDisableSize() const
Definition: ServiceInfo.cc:141
void setRepoStates(RepoStates newStates_r)
Remember a new set of repository states.
Definition: ServiceInfo.cc:162
static const ServiceInfo noService
Represents an empty service.
Definition: ServiceInfo.h:61
bool reposToDisableEmpty() const
Definition: ServiceInfo.cc:140
Url manipulation class.
Definition: Url.h:92
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
std::string name() const
Repository name.
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
std::string alias() const
unique identifier for this source.
String related utilities and Regular expression matching.
std::string asString(const Url &url_r)
Definition: Url.cc:886
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:798
std::string numstring(char n, int w=0)
Definition: String.h:289
detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
Definition: XmlEscape.h:51
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
ReposToDisable _reposToDisable
Definition: ServiceInfo.cc:42
repo::ServiceType _type
Definition: ServiceInfo.cc:40
DefaultIntegral< Date::Duration, 0 > _ttl
Definition: ServiceInfo.cc:44
RepoVariablesReplacedUrl _url
Definition: ServiceInfo.cc:39
void setProbedType(const repo::ServiceType &type_r) const
Definition: ServiceInfo.cc:58
Impl * clone() const
clone for RWCOW_pointer
Definition: ServiceInfo.cc:72
ServiceInfo::ReposToEnable ReposToEnable
Definition: ServiceInfo.cc:35
Impl(const Url &url_r)
Definition: ServiceInfo.cc:51
ReposToEnable _reposToEnable
Definition: ServiceInfo.cc:41
ServiceInfo::ReposToDisable ReposToDisable
Definition: ServiceInfo.cc:36
Service type enumeration.
Definition: ServiceType.h:27
static const ServiceType NONE
No service set.
Definition: ServiceType.h:34
const std::string & asString() const
Definition: ServiceType.cc:56