Fix spec and makefiles
[platform/upstream/libzypp.git] / zypp / Locks.h
1 #ifndef ZYPP_LOCKS_H
2 #define ZYPP_LOCKS_H
3
4 #include "zypp/ResPool.h"
5 #include "zypp/Pathname.h"
6 #include "zypp/PoolQuery.h"
7 #include "zypp/ZConfig.h"
8  
9 namespace zypp
10 {
11   /** \name Locks */
12   //@{
13   /**
14    * Singleton class which manipulate with locks file and apply locks on pool.
15    * for user information about locksfile and its format see 
16    * <a>http://en.opensuse.org/Libzypp/Locksfile</a>
17    */
18   class Locks
19   {
20   public:
21     typedef std::list<PoolQuery> LockList;
22     typedef LockList::const_iterator const_iterator;
23     typedef LockList::size_type size_type;
24   public:
25     class Impl;
26
27     /**
28      * Gets instance of this class.
29      * Singleton method.
30      */
31     static Locks& instance();
32
33     const_iterator begin() const;
34     const_iterator end() const;
35     LockList::size_type size() const;
36     bool empty() const;
37
38     /**
39      * TODO add:
40      * toBeAdded{Begin,End,Size,Empty}
41      * toBeRemoved{Begin,End,Size,Empty}
42      */
43
44     /**
45      * locks result of query and add this lock as toAdd
46      */
47     void addLock( const PoolQuery& query );
48
49     /**
50      * add lock by identifier (e.g. Selectable->ident()
51      * and add this lock as toAdd
52      */
53     void addLock( const IdString& ident_r );
54
55     /**
56      * add lock by name and kind and
57      * add this lock as toAdd
58      */ 
59     void addLock( const ResKind& kind_r, const IdString& name_r );
60
61     /**
62      * add lock by name and kind and
63      * add this lock as toAdd
64      */ 
65     void addLock( const ResKind& kind_r, const C_Str& name_r );
66
67     /**
68      * unlocks by result of query and add to toRemove.
69      *
70      * If unlock non-saved lock (so he is in toAdd list) then both is deleted 
71      * and nathing happen during save
72      */
73     void removeLock( const PoolQuery& query );
74
75     /**
76      * remove lock by identifier (e.g. Selectable->ident()
77      *
78      * If unlock non-saved lock (so he is in toAdd list) then both is deleted 
79      * and nathing happen during save
80      */
81     void removeLock( const IdString& ident_r );
82
83     /**
84      * remove lock by name and kind
85      *
86      * If unlock non-saved lock (so he is in toAdd list) then both is deleted 
87      * and nathing happen during save
88      */
89     void removeLock( const ResKind& kind_r, const IdString& name_r );
90     void removeLock( const ResKind& kind_r, const C_Str & name_r );
91
92     /**
93      * Optimalized version of read and apply.
94      * \see read
95      * \see apply
96      */
97     void readAndApply( const Pathname& file = ZConfig::instance().locksFile() );
98
99     /**
100      * Read locks from file to list of stable locks (locks which is not changed
101      * during session)
102      */
103     void read( const Pathname& file = ZConfig::instance().locksFile() );
104
105     /**
106      * Applies locks in stable list (locks which is not changed during session).
107      */
108     void apply() const;
109
110     /**
111      * Merges toAdd and ToRemove list to stable list and
112      * save that stable list to file.
113      * \see SavingLocksReport
114      */
115     void save( const Pathname& file = ZConfig::instance().locksFile() );
116
117     /**
118      * Merges toAdd and ToRemove list to stable list.
119      * \note Can call callback if problem during merging occure
120      * \see SavingLocksReport
121      */
122     void merge();
123     
124     /**
125      * Gets true if some lock doesn't lock any object in pool
126      * This can happen e.g. if package is removed or
127      * due to user bad definition of lock
128      */
129     bool existEmpty() const;
130
131     /**
132      * Call callback for each empty lock.
133      * \see existEmpty
134      * \see CleanEmptyLocksReport
135      * \note you must call \a save to write cleaned locks to file
136      */
137     void removeEmpty();
138
139     /**
140      * Delete all query duplicate in loaded locks.
141      * \note you must call \a save to write cleaned locks to file
142      */
143     void removeDuplicates();
144     //@}
145   private:
146     Locks();
147     
148     RW_pointer<Impl, rw_pointer::Scoped<Impl> > _pimpl;
149
150   };
151 }
152     
153 #endif