Imported Upstream version 14.45.0
[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/repo/ServiceType.h"
21 #include "zypp/RepoInfo.h"
22
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27
28   ///////////////////////////////////////////////////////////////////
29   /// \class ServiceInfo
30   /// \brief Service data
31   ///
32   /// \note Name and Url are subject to repo variable replacement
33   /// (\see \ref RepoVariablesStringReplacer).
34   ///
35   class ServiceInfo : public repo::RepoInfoBase
36   {
37   public:
38     /** Default ctor creates \ref noService.*/
39     ServiceInfo();
40
41     /**
42      *  Creates ServiceInfo with specified alias.
43      *
44      * \param alias unique short name of service
45      */
46     ServiceInfo( const std::string & alias );
47
48     /**
49      * ServiceInfo with alias and its URL
50      *
51      * \param alias unique shortname of service
52      * \param url url to service
53      */
54     ServiceInfo( const std::string & alias, const Url& url );
55
56     virtual ~ServiceInfo();
57
58   public:
59     /** Represents an empty service. */
60     static const ServiceInfo noService;
61
62   public:
63
64     /** The service url */
65     Url url() const;
66
67     /** The service raw url (no variables replaced) */
68     Url rawUrl() const;
69
70     /** Set the service url (raw value) */
71     void setUrl( const Url& url );
72
73
74     /** Service type */
75     repo::ServiceType type() const;
76
77     /** Set service type */
78     void setType( const repo::ServiceType & type );
79
80     /** Lazy init service type */
81     void setProbedType( const repo::ServiceType & t ) const;
82
83
84     /** \name Set of repos (repository aliases) to enable on next refresh.
85      *
86      * Per default new repositories are created in disabled state. But repositories
87      * mentioned here will be created in enabled state on the next refresh.
88      * Afterwards they get removed from the list.
89      */
90     //@{
91     /** Container of repos. */
92     typedef std::set<std::string> ReposToEnable;
93     bool                          reposToEnableEmpty() const;
94     ReposToEnable::size_type      reposToEnableSize() const;
95     ReposToEnable::const_iterator reposToEnableBegin() const;
96     ReposToEnable::const_iterator reposToEnableEnd() const;
97
98     /** Whether \c alias_r is mentioned in ReposToEnable. */
99     bool repoToEnableFind( const std::string & alias_r ) const;
100
101     /** Add \c alias_r to the set of ReposToEnable. */
102     void addRepoToEnable( const std::string & alias_r );
103     /** Remove \c alias_r from the set of ReposToEnable. */
104     void delRepoToEnable( const std::string & alias_r );
105     /** Clear the set of ReposToEnable. */
106     void clearReposToEnable();
107     //@}
108
109     /** \name Set of repos (repository aliases) to disable on next refresh.
110      *
111      * Repositories mentioned here will be disabled on the next refresh, in case they
112      * still exist. Afterwards they get removed from the list.
113      */
114     //@{
115     /** Container of repos. */
116     typedef std::set<std::string>  ReposToDisable;
117     bool                           reposToDisableEmpty() const;
118     ReposToDisable::size_type      reposToDisableSize() const;
119     ReposToDisable::const_iterator reposToDisableBegin() const;
120     ReposToDisable::const_iterator reposToDisableEnd() const;
121
122     /** Whether \c alias_r is mentioned in ReposToDisable. */
123     bool repoToDisableFind( const std::string & alias_r ) const;
124
125     /** Add \c alias_r to the set of ReposToDisable. */
126     void addRepoToDisable( const std::string & alias_r );
127     /** Remove \c alias_r from the set of ReposToDisable. */
128     void delRepoToDisable( const std::string & alias_r );
129     /** Clear the set of ReposToDisable. */
130     void clearReposToDisable();
131     //@}
132
133     /** \name The original repo state as defined by the repoindex.xml upon last refresh.
134      *
135      * This state is remembered to detect any user modifications applied to the repos.
136      * It may not be available for all repos or in plugin services. In this case all
137      * changes requested by a service refresh are applied unconditionally.
138      */
139     //@{
140     struct RepoState
141     {
142       bool      enabled;
143       bool      autorefresh;
144       unsigned  priority;
145
146       RepoState()
147         : enabled( false ), autorefresh( true ), priority( RepoInfo::defaultPriority() )
148       {}
149       RepoState( const RepoInfo & repo_r )
150         : enabled( repo_r.enabled() ), autorefresh( repo_r.autorefresh() ), priority( repo_r.priority() )
151       {}
152       bool operator==( const RepoState & rhs ) const
153       { return( enabled==rhs.enabled && autorefresh==rhs.autorefresh && priority==rhs.priority ); }
154       bool operator!=( const RepoState & rhs ) const
155       { return ! operator==( rhs ); }
156       friend std::ostream & operator<<( std::ostream & str, const RepoState & obj );
157     };
158     typedef std::map<std::string,RepoState> RepoStates;
159
160     /** Access the remembered repository states. */
161     const RepoStates & repoStates() const;
162
163     /** Remember a new set of repository states. */
164     void setRepoStates( RepoStates newStates_r );
165     //@}
166
167   public:
168     /**
169      * Writes ServiceInfo to stream in ".service" format
170      *
171      * \param str stream where serialized version service is written
172      */
173     virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
174
175     /**
176      * Write an XML representation of this ServiceInfo object.
177      *
178      * \param str
179      * \param content if not empty, produces <service ...>content</service>
180      *                otherwise <service .../>
181      */
182     virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
183
184     class Impl;
185
186   private:
187       RWCOW_pointer<Impl> _pimpl;
188   };
189   ///////////////////////////////////////////////////////////////////
190
191   /** \relates ServiceInfo */
192   typedef shared_ptr<ServiceInfo> ServiceInfo_Ptr;
193   /** \relates ServiceInfo */
194   typedef shared_ptr<const ServiceInfo> ServiceInfo_constPtr;
195   /** \relates ServiceInfo */
196   typedef std::list<ServiceInfo> ServiceInfoList;
197
198   /** \relates ServiceInfo Stream output */
199   std::ostream & operator<<( std::ostream & str, const ServiceInfo & obj );
200
201
202     /////////////////////////////////////////////////////////////////
203 } // namespace zypp
204 ///////////////////////////////////////////////////////////////////
205 #endif // ZYPP_SAT_REPOSITORY_H