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 
66 
70  const Device* get_source() const;
71 
82  void set_source(const Device* source);
83 
91  void set_target(const Device* target);
92 
99 
104 
108  const Device* get_target() const;
109 
116 
117  bool operator==(const Holder& rhs) const;
118  bool operator!=(const Holder& rhs) const;
119 
133  Holder* copy_to_devicegraph(Devicegraph* devicegraph) const;
134 
138  bool exists_in_devicegraph(const Devicegraph* devicegraph) const;
139 
143  bool exists_in_probed() const;
144 
148  bool exists_in_staging() const;
149 
153  bool exists_in_system() const;
154 
158  const std::map<std::string, std::string>& get_userdata() const;
159 
163  void set_userdata(const std::map<std::string, std::string>& userdata);
164 
165  friend std::ostream& operator<<(std::ostream& out, const Holder& holder);
166 
171 
175  const Devicegraph* get_devicegraph() const;
176 
177  public:
178 
179  class Impl;
180 
181  Impl& get_impl() { return *impl; }
182  const Impl& get_impl() const { return *impl; }
183 
184  virtual Holder* clone() const = 0;
185 
186  void save(xmlNode* node) const ST_DEPRECATED;
187 
188  protected:
189 
190  Holder(Impl* impl);
191 
200  void create(Devicegraph* devicegraph, const Device* source, const Device* target);
201 
202  void load(Devicegraph* devicegraph, const xmlNode* node);
203 
204  private:
205 
206  void add_to_devicegraph(Devicegraph* devicegraph, const Device* source,
207  const Device* target);
208 
209  const std::unique_ptr<Impl> impl;
210 
211  };
212 
213 }
214 
215 #endif
An abstract base class for storage devices.
Definition: Device.h:82
The main container of the libstorage-ng.
Definition: Devicegraph.h:170
Base class for storage exceptions.
Definition: Exception.h:114
Definition: Holder.h:43
An abstract base class for storage holders.
Definition: Holder.h:57
void create(Devicegraph *devicegraph, const Device *source, const Device *target)
Create a holder between source and target in the devicegraph.
bool exists_in_staging() const
Checks if the holder exists in the staging devicegraph.
void set_target(const Device *target)
Set the target device of the holder.
bool exists_in_devicegraph(const Devicegraph *devicegraph) const
Checks if the holder exists in the devicegraph.
const Device * get_source() const
Get the source device of the holder.
Devicegraph * get_devicegraph()
Return the devicegraph the holder belongs to.
sid_t get_source_sid() const
Return the storage id (sid) of the source of the holder.
const Devicegraph * get_devicegraph() const
Return the devicegraph the holder belongs to.
bool exists_in_probed() const
Checks if the holder exists in the probed devicegraph.
const std::map< std::string, std::string > & get_userdata() const
Return the userdata of the holder.
bool exists_in_system() const
Checks if the holder exists in the system devicegraph.
sid_t get_target_sid() const
Return the storage id (sid) of the target of the holder.
Device * get_source()
Get the source device of the holder.
void set_userdata(const std::map< std::string, std::string > &userdata)
Set the userdata of the holder.
Holder * copy_to_devicegraph(Devicegraph *devicegraph) const
Copies the holder to the devicegraph.
Device * get_target()
Get the target device of the holder.
void set_source(const Device *source)
Set the source device of the holder.
const Device * get_target() const
Get the target device of the holder.
The storage namespace.
Definition: Actiongraph.h:39
unsigned int sid_t
An integer storage ID.
Definition: Device.h:67