1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ServiceInfo.h
12 #ifndef ZYPP_SERVICE_H
13 #define ZYPP_SERVICE_H
20 #include "zypp/base/Iterable.h"
21 #include "zypp/repo/ServiceType.h"
22 #include "zypp/RepoInfo.h"
23 #include "zypp/Date.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
30 /// \class ServiceInfo
31 /// \brief Service data
33 /// \note Name and Url are subject to repo variable replacement
34 /// (\see \ref RepoVariablesStringReplacer).
36 class ServiceInfo : public repo::RepoInfoBase
39 /** Default ctor creates \ref noService.*/
43 * Creates ServiceInfo with specified alias.
45 * \param alias unique short name of service
47 ServiceInfo( const std::string & alias );
50 * ServiceInfo with alias and its URL
52 * \param alias unique shortname of service
53 * \param url url to service
55 ServiceInfo( const std::string & alias, const Url& url );
57 virtual ~ServiceInfo();
60 /** Represents an empty service. */
61 static const ServiceInfo noService;
65 /** The service url */
68 /** The service raw url (no variables replaced) */
71 /** Set the service url (raw value) */
72 void setUrl( const Url& url );
76 repo::ServiceType type() const;
78 /** Set service type */
79 void setType( const repo::ServiceType & type );
81 /** Lazy init service type */
82 void setProbedType( const repo::ServiceType & t ) const;
84 /** \name Housekeeping data
85 * You don't want to use the setters unless you are a \ref RepoManager.
88 /** Sugested TTL between two metadata auto-refreshs.
89 * The value (in seconds) may be provided in repoindex.xml:xpath:/repoindex@ttl.
90 * Default is \a 0 - perform each auto-refresh request.
92 Date::Duration ttl() const;
94 /** Set sugested TTL. */
95 void setTtl( Date::Duration ttl_r );
97 /** Lazy init sugested TTL. */
98 void setProbedTtl( Date::Duration ttl_r ) const;
100 /** Date of last refresh (if known). */
103 /** Set date of last refresh. */
104 void setLrf( Date lrf_r );
107 /** \name Set of repos (repository aliases) to enable on next refresh.
109 * Per default new repositories are created in disabled state. But repositories
110 * mentioned here will be created in enabled state on the next refresh.
111 * Afterwards they get removed from the list.
114 /** Container of repos. */
115 typedef std::set<std::string> ReposToEnable;
116 bool reposToEnableEmpty() const;
117 ReposToEnable::size_type reposToEnableSize() const;
118 ReposToEnable::const_iterator reposToEnableBegin() const;
119 ReposToEnable::const_iterator reposToEnableEnd() const;
120 Iterable<ReposToEnable::const_iterator> reposToEnable() const
121 { return makeIterable( reposToEnableBegin(), reposToEnableEnd() ); }
123 /** Whether \c alias_r is mentioned in ReposToEnable. */
124 bool repoToEnableFind( const std::string & alias_r ) const;
126 /** Add \c alias_r to the set of ReposToEnable. */
127 void addRepoToEnable( const std::string & alias_r );
128 /** Remove \c alias_r from the set of ReposToEnable. */
129 void delRepoToEnable( const std::string & alias_r );
130 /** Clear the set of ReposToEnable. */
131 void clearReposToEnable();
134 /** \name Set of repos (repository aliases) to disable on next refresh.
136 * Repositories mentioned here will be disabled on the next refresh, in case they
137 * still exist. Afterwards they get removed from the list.
140 /** Container of repos. */
141 typedef std::set<std::string> ReposToDisable;
142 bool reposToDisableEmpty() const;
143 ReposToDisable::size_type reposToDisableSize() const;
144 ReposToDisable::const_iterator reposToDisableBegin() const;
145 ReposToDisable::const_iterator reposToDisableEnd() const;
146 Iterable<ReposToDisable::const_iterator> reposToDisable() const
147 { return makeIterable( reposToDisableBegin(), reposToDisableEnd() ); }
149 /** Whether \c alias_r is mentioned in ReposToDisable. */
150 bool repoToDisableFind( const std::string & alias_r ) const;
152 /** Add \c alias_r to the set of ReposToDisable. */
153 void addRepoToDisable( const std::string & alias_r );
154 /** Remove \c alias_r from the set of ReposToDisable. */
155 void delRepoToDisable( const std::string & alias_r );
156 /** Clear the set of ReposToDisable. */
157 void clearReposToDisable();
160 /** \name The original repo state as defined by the repoindex.xml upon last refresh.
162 * This state is remembered to detect any user modifications applied to the repos.
163 * It may not be available for all repos or in plugin services. In this case all
164 * changes requested by a service refresh are applied unconditionally.
174 : enabled( false ), autorefresh( true ), priority( RepoInfo::defaultPriority() )
176 RepoState( const RepoInfo & repo_r )
177 : enabled( repo_r.enabled() ), autorefresh( repo_r.autorefresh() ), priority( repo_r.priority() )
179 bool operator==( const RepoState & rhs ) const
180 { return( enabled==rhs.enabled && autorefresh==rhs.autorefresh && priority==rhs.priority ); }
181 bool operator!=( const RepoState & rhs ) const
182 { return ! operator==( rhs ); }
183 friend std::ostream & operator<<( std::ostream & str, const RepoState & obj );
185 typedef std::map<std::string,RepoState> RepoStates;
187 /** Access the remembered repository states. */
188 const RepoStates & repoStates() const;
190 /** Remember a new set of repository states. */
191 void setRepoStates( RepoStates newStates_r );
196 * Writes ServiceInfo to stream in ".service" format
198 * \param str stream where serialized version service is written
200 virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
203 * Write an XML representation of this ServiceInfo object.
206 * \param content if not empty, produces <service ...>content</service>
207 * otherwise <service .../>
209 virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
214 RWCOW_pointer<Impl> _pimpl;
216 ///////////////////////////////////////////////////////////////////
218 /** \relates ServiceInfo */
219 typedef shared_ptr<ServiceInfo> ServiceInfo_Ptr;
220 /** \relates ServiceInfo */
221 typedef shared_ptr<const ServiceInfo> ServiceInfo_constPtr;
222 /** \relates ServiceInfo */
223 typedef std::list<ServiceInfo> ServiceInfoList;
225 /** \relates ServiceInfo Stream output */
226 std::ostream & operator<<( std::ostream & str, const ServiceInfo & obj );
229 /////////////////////////////////////////////////////////////////
231 ///////////////////////////////////////////////////////////////////
232 #endif // ZYPP_SAT_REPOSITORY_H