libstorage-ng
Holder.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2017-2021] SUSE LLC
4  *
5  * All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of version 2 of the GNU General Public License as published
9  * by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, contact Novell, Inc.
18  *
19  * To contact Novell about this file by physical or electronic mail, you may
20  * find current contact information at www.novell.com.
21  */
22 
23 
24 #ifndef STORAGE_HOLDER_H
25 #define STORAGE_HOLDER_H
26 
27 
28 #include <libxml/tree.h>
29 #include <memory>
30 #include <boost/noncopyable.hpp>
31 
32 #include "storage/Devices/Device.h"
33 #include "storage/Utils/Swig.h"
34 
35 
36 namespace storage
37 {
38  class Devicegraph;
39  class Device;
40 
41 
43  {
44  public:
45 
46  HolderHasWrongType(const char* seen, const char* expected);
47  };
48 
49 
56  class Holder : private boost::noncopyable
57  {
58  public:
59 
60  virtual ~Holder();
61 
65  Device* get_source();
66 
70  const Device* get_source() const;
71 
84  void set_source(const Device* source);
85 
95  void set_target(const Device* target);
96 
102  sid_t get_source_sid() const;
103 
107  Device* get_target();
108 
112  const Device* get_target() const;
113 
119  sid_t get_target_sid() const;
120 
121  bool operator==(const Holder& rhs) const;
122  bool operator!=(const Holder& rhs) const;
123 
137  Holder* copy_to_devicegraph(Devicegraph* devicegraph) const;
138 
142  bool exists_in_devicegraph(const Devicegraph* devicegraph) const;
143 
147  bool exists_in_probed() const;
148 
152  bool exists_in_staging() const;
153 
157  bool exists_in_system() const;
158 
162  const std::map<std::string, std::string>& get_userdata() const;
163 
167  void set_userdata(const std::map<std::string, std::string>& userdata);
168 
169  friend std::ostream& operator<<(std::ostream& out, const Holder& holder);
170 
175 
179  const Devicegraph* get_devicegraph() const;
180 
181  public:
182 
183  class Impl;
184 
185  Impl& get_impl() { return *impl; }
186  const Impl& get_impl() const { return *impl; }
187 
188  virtual Holder* clone() const = 0;
189 
190  void save(xmlNode* node) const ST_DEPRECATED;
191 
192  protected:
193 
194  Holder(Impl* impl);
195 
204  void create(Devicegraph* devicegraph, const Device* source, const Device* target);
205 
206  void load(Devicegraph* devicegraph, const xmlNode* node);
207 
208  private:
209 
210  void add_to_devicegraph(Devicegraph* devicegraph, const Device* source,
211  const Device* target);
212 
213  const std::unique_ptr<Impl> impl;
214 
215  };
216 
217 }
218 
219 #endif
void set_userdata(const std::map< std::string, std::string > &userdata)
Set the userdata of the holder.
const std::map< std::string, std::string > & get_userdata() const
Return the userdata of the holder.
sid_t get_target_sid() const
Return the storage id (sid) of the target of the holder.
Holder * copy_to_devicegraph(Devicegraph *devicegraph) const
Copies the holder to the devicegraph.
bool exists_in_probed() const
Checks if the holder exists in the probed devicegraph.
Devicegraph * get_devicegraph()
Return the devicegraph the holder belongs to.
void create(Devicegraph *devicegraph, const Device *source, const Device *target)
Create a holder between source and target in the devicegraph.
bool exists_in_system() const
Checks if the holder exists in the system devicegraph.
Definition: Holder.h:42
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
Device * get_target()
Get the target device of the holder.
An abstract base class for storage devices.
Definition: Device.h:81
An abstract base class for storage holders.
Definition: Holder.h:56
sid_t get_source_sid() const
Return the storage id (sid) of the source of the holder.
void set_target(const Device *target)
Set the target device of the holder.
Device * get_source()
Get the source device of the holder.
Base class for storage exceptions.
Definition: Exception.h:113
bool exists_in_devicegraph(const Devicegraph *devicegraph) const
Checks if the holder exists in the devicegraph.
bool exists_in_staging() const
Checks if the holder exists in the staging devicegraph.
The storage namespace.
Definition: Actiongraph.h:38
unsigned int sid_t
An integer storage ID.
Definition: Device.h:67
void set_source(const Device *source)
Set the source device of the holder.