da871c300fdeb47bf02aa6da24e6ef355e795c18
[platform/upstream/libzypp.git] / zypp / target / store / XMLFilesBackend.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       devel/devel.dmacvicar/XMLFilesBackend.h
10 *
11 */
12 #ifndef DEVEL_DEVEL_DMACVICAR_XMLFILESBACKEND_H
13 #define DEVEL_DEVEL_DMACVICAR_XMLFILESBACKEND_H
14
15 #include <iosfwd>
16
17
18 #include "zypp/Message.h"
19 #include "zypp/Patch.h"
20 #include "zypp/Script.h"
21 #include "zypp/Product.h"
22 #include "zypp/Selection.h"
23
24 #include "zypp/parser/yum/YUMParser.h"
25 #include "zypp/parser/yum/YUMParserData.h"
26 #include "zypp/base/PtrTypes.h"
27 #include "Backend.h"
28
29 using namespace zypp;
30 using namespace zypp::parser::yum;
31
32 ///////////////////////////////////////////////////////////////////
33 namespace zypp
34 { /////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////
36 namespace storage
37 { /////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////
39 //
40 //      CLASS NAME : XMLFilesBackend
41 //
42 /** */
43 class XMLFilesBackend : public Backend
44 {
45   friend std::ostream & operator<<( std::ostream & str, const XMLFilesBackend & obj );
46 public:
47   typedef intrusive_ptr<XMLFilesBackend> Ptr;
48   typedef intrusive_ptr<const XMLFilesBackend> constPtr;
49
50   public:
51   /** Default ctor */
52   XMLFilesBackend(const Pathname &root);
53   /** Dtor */
54   ~XMLFilesBackend();
55   void setRandomFileNameEnabled( bool enabled );
56   virtual void doTest();
57
58   /**
59     * is the storage backend initialized
60     */
61   virtual bool isBackendInitialized() const;
62   /**
63     * initialize the storage backend
64     */
65   virtual void initBackend();
66   /**
67     * Stores a Resolvable in the active backend.
68     */
69   virtual void storeObject( Resolvable::constPtr resolvable ) ;
70   /**
71     * Deletes a Resolvable from the active backend.
72     */
73   virtual void deleteObject( Resolvable::Ptr resolvable );
74   /**
75     * Deletes a Resolvable from the active backend.
76     */
77   virtual std::list<Resolvable::Ptr> storedObjects() const;
78    /**
79     * Query for installed Resolvables of a certain kind
80     */
81   virtual std::list<Resolvable::Ptr> storedObjects(const Resolvable::Kind) const;
82   /**
83     * Query for installed Resolvables of a certain kind by name
84     * \a partial_match allows for text search.
85     */
86   virtual std::list<Resolvable::Ptr> storedObjects(const Resolvable::Kind, const std::string & name, bool partial_match = false) const;
87
88   /////////////////////////////////////////////////////////
89   // SOURCES API
90   ////////////////////////////////////////////////////////
91   /**
92     * Query for installed Sources
93     */
94   virtual std::list<PersistentStorage::SourceData> storedSources() const;
95   /**
96     * Query for installed Sources
97     */
98   virtual void storeSource(const PersistentStorage::SourceData &data);
99   /**
100     * Query for installed Sources
101     */
102   virtual void deleteSource(const std::string &alias);
103   
104
105   protected:
106   std::string randomString(int length) const;
107   int random() const;
108
109   
110   /**
111     * Directory where the xml file is stored (for the given resolvable)
112     */
113   std::string dirForResolvable( Resolvable::constPtr resolvable ) const;
114   /**
115     * Directory where the xml file is stored (for the given resolvable kind)
116     */
117   std::string dirForResolvableKind( Resolvable::Kind kind ) const;
118   /**
119     * Full path to the xml file for a given resolvable
120     * Does not care if the resolvable is yet stored or not
121     */
122   std::string fullPathForResolvable( Resolvable::constPtr resolvable ) const;
123    /**
124     * Full path to the xml file for a given resolvable
125     * Does not care if the resolvable is yet stored or not
126     */
127   Resolvable::Ptr resolvableFromFile( std::string file_path, Resolvable::Kind kind ) const;
128
129   Patch::Ptr createPatch( const zypp::parser::yum::YUMPatchData & parsed ) const;
130   Message::Ptr createMessage( const zypp::parser::yum::YUMPatchMessage & parsed ) const;
131   Script::Ptr createScript(const zypp::parser::yum::YUMPatchScript & parsed ) const;
132   Product::Ptr createProduct( const zypp::parser::yum::YUMProductData & parsed ) const;
133   Selection::Ptr createSelection( const zypp::parser::yum::YUMGroupData & parsed ) const;
134
135
136   Dependencies createDependencies( const zypp::parser::yum::YUMObjectData & parsed, const Resolvable::Kind my_kind ) const;
137   Dependencies createGroupDependencies( const zypp::parser::yum::YUMGroupData & parsed ) const;
138   Dependencies createPatternDependencies( const zypp::parser::yum::YUMPatternData & parsed ) const;
139   Capability createCapability(const YUMDependency & dep, const Resolvable::Kind & my_kind) const;
140
141   private:
142   class Private;
143   Private *d;
144 };
145
146 ///////////////////////////////////////////////////////////////////
147 /** \relates XMLFilesBackend Stream output */
148 std::ostream & operator<<( std::ostream & str, const XMLFilesBackend & obj );
149 /////////////////////////////////////////////////////////////////
150 } // namespace devel.dmacvicar
151 ///////////////////////////////////////////////////////////////////
152 /////////////////////////////////////////////////////////////////
153 } // namespace devel
154 ///////////////////////////////////////////////////////////////////
155 #endif // DEVEL_DEVEL_DMACVICAR_SQLITEBACKEND_H