e5b27cbbbec634de5e579f6db4ccf5addb696dcc
[platform/upstream/libzypp.git] / zypp / ServiceInfo.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ServiceInfo.h
10  *
11  */
12 #ifndef ZYPP_SERVICE_H
13 #define ZYPP_SERVICE_H
14
15 #include <set>
16 #include <string>
17
18 #include "zypp/Url.h"
19
20 #include "zypp/base/Iterable.h"
21 #include "zypp/repo/ServiceType.h"
22 #include "zypp/RepoInfo.h"
23 #include "zypp/Date.h"
24
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28
29   ///////////////////////////////////////////////////////////////////
30   /// \class ServiceInfo
31   /// \brief Service data
32   ///
33   /// \note Name and Url are subject to repo variable replacement
34   /// (\see \ref RepoVariablesStringReplacer).
35   ///
36   class ServiceInfo : public repo::RepoInfoBase
37   {
38   public:
39     /** Default ctor creates \ref noService.*/
40     ServiceInfo();
41
42     /**
43      *  Creates ServiceInfo with specified alias.
44      *
45      * \param alias unique short name of service
46      */
47     ServiceInfo( const std::string & alias );
48
49     /**
50      * ServiceInfo with alias and its URL
51      *
52      * \param alias unique shortname of service
53      * \param url url to service
54      */
55     ServiceInfo( const std::string & alias, const Url& url );
56
57     virtual ~ServiceInfo();
58
59   public:
60     /** Represents an empty service. */
61     static const ServiceInfo noService;
62
63   public:
64
65     /** The service url */
66     Url url() const;
67
68     /** The service raw url (no variables replaced) */
69     Url rawUrl() const;
70
71     /** Set the service url (raw value) */
72     void setUrl( const Url& url );
73
74
75     /** Service type */
76     repo::ServiceType type() const;
77
78     /** Set service type */
79     void setType( const repo::ServiceType & type );
80
81     /** Lazy init service type */
82     void setProbedType( const repo::ServiceType & t ) const;
83
84     /** \name Housekeeping data
85      * You don't want to use the setters unless you are a \ref RepoManager.
86      */
87     //@{
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.
91      */
92     Date::Duration ttl() const;
93
94     /** Set sugested TTL. */
95     void setTtl( Date::Duration ttl_r );
96
97     /** Lazy init sugested TTL. */
98     void setProbedTtl( Date::Duration ttl_r ) const;
99
100     /** Date of last refresh (if known). */
101     Date lrf() const;
102
103     /** Set date of last refresh. */
104     void setLrf( Date lrf_r );
105     //@}
106     //
107     /** \name Set of repos (repository aliases) to enable on next refresh.
108      *
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.
112      */
113     //@{
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() ); }
122
123     /** Whether \c alias_r is mentioned in ReposToEnable. */
124     bool repoToEnableFind( const std::string & alias_r ) const;
125
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();
132     //@}
133
134     /** \name Set of repos (repository aliases) to disable on next refresh.
135      *
136      * Repositories mentioned here will be disabled on the next refresh, in case they
137      * still exist. Afterwards they get removed from the list.
138      */
139     //@{
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() ); }
148
149     /** Whether \c alias_r is mentioned in ReposToDisable. */
150     bool repoToDisableFind( const std::string & alias_r ) const;
151
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();
158     //@}
159
160     /** \name The original repo state as defined by the repoindex.xml upon last refresh.
161      *
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.
165      */
166     //@{
167     struct RepoState
168     {
169       bool      enabled;
170       bool      autorefresh;
171       unsigned  priority;
172
173       RepoState()
174         : enabled( false ), autorefresh( true ), priority( RepoInfo::defaultPriority() )
175       {}
176       RepoState( const RepoInfo & repo_r )
177         : enabled( repo_r.enabled() ), autorefresh( repo_r.autorefresh() ), priority( repo_r.priority() )
178       {}
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 );
184     };
185     typedef std::map<std::string,RepoState> RepoStates;
186
187     /** Access the remembered repository states. */
188     const RepoStates & repoStates() const;
189
190     /** Remember a new set of repository states. */
191     void setRepoStates( RepoStates newStates_r );
192     //@}
193
194   public:
195     /**
196      * Writes ServiceInfo to stream in ".service" format
197      *
198      * \param str stream where serialized version service is written
199      */
200     virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
201
202     /**
203      * Write an XML representation of this ServiceInfo object.
204      *
205      * \param str
206      * \param content if not empty, produces <service ...>content</service>
207      *                otherwise <service .../>
208      */
209     virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
210
211     class Impl;
212
213   private:
214       RWCOW_pointer<Impl> _pimpl;
215   };
216   ///////////////////////////////////////////////////////////////////
217
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;
224
225   /** \relates ServiceInfo Stream output */
226   std::ostream & operator<<( std::ostream & str, const ServiceInfo & obj );
227
228
229     /////////////////////////////////////////////////////////////////
230 } // namespace zypp
231 ///////////////////////////////////////////////////////////////////
232 #endif // ZYPP_SAT_REPOSITORY_H