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