libstorage-ng
Device.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2018] 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_DEVICE_H
25 #define STORAGE_DEVICE_H
26 
27 
28 #include <libxml/tree.h>
29 #include <string>
30 #include <vector>
31 #include <map>
32 #include <memory>
33 #include <boost/noncopyable.hpp>
34 
35 #include "storage/Utils/Exception.h"
36 
37 
39 namespace storage
40 {
41  class Devicegraph;
42  class Holder;
43  class ResizeInfo;
44 
45 
47  {
48  public:
49 
50  DeviceHasWrongType(const char* seen, const char* expected);
51  };
52 
53 
66  typedef unsigned int sid_t;
67 
68 
74 
75  class Device : private boost::noncopyable
76  {
77 
78  public:
79 
80  virtual ~Device();
81 
82  sid_t get_sid() const;
83 
84  bool operator==(const Device& rhs) const;
85  bool operator!=(const Device& rhs) const;
86 
99  Device* copy_to_devicegraph(Devicegraph* devicegraph) const;
100 
104  bool exists_in_devicegraph(const Devicegraph* devicegraph) const;
105 
109  bool exists_in_probed() const;
110 
114  bool exists_in_staging() const;
115 
119  bool exists_in_system() const;
120 
121  std::string get_displayname() const;
122 
131 
132  bool has_children() const;
133  size_t num_children() const;
134 
135  bool has_parents() const;
136  size_t num_parents() const;
137 
138  static std::vector<Device*> get_all(Devicegraph* devicegraph);
139  static std::vector<const Device*> get_all(const Devicegraph* devicegraph);
140 
141  // TODO check if we can somehow return a iterator. getting rid of the
142  // ptr would also allow to use references instead of pointer in the
143  // interface.
144 
145  std::vector<Device*> get_children();
146  std::vector<const Device*> get_children() const;
147 
148  std::vector<Device*> get_parents();
149  std::vector<const Device*> get_parents() const;
150 
151  std::vector<Device*> get_siblings(bool itself);
152  std::vector<const Device*> get_siblings(bool itself) const;
153 
154  std::vector<Device*> get_descendants(bool itself);
155  std::vector<const Device*> get_descendants(bool itself) const;
156 
157  std::vector<Device*> get_ancestors(bool itself);
158  std::vector<const Device*> get_ancestors(bool itself) const;
159 
160  std::vector<Device*> get_leaves(bool itself);
161  std::vector<const Device*> get_leaves(bool itself) const;
162 
163  std::vector<Device*> get_roots(bool itself);
164  std::vector<const Device*> get_roots(bool itself) const;
165 
166  std::vector<Holder*> get_in_holders();
167  std::vector<const Holder*> get_in_holders() const;
168 
169  std::vector<Holder*> get_out_holders();
170  std::vector<const Holder*> get_out_holders() const;
171 
172  void remove_descendants();
173 
174  const std::map<std::string, std::string>& get_userdata() const;
175  void set_userdata(const std::map<std::string, std::string>& userdata);
176 
177  friend std::ostream& operator<<(std::ostream& out, const Device& device);
178 
182  static bool compare_by_sid(const Device* lhs, const Device* rhs);
183 
197  static bool compare_by_name(const Device* lhs, const Device* rhs);
198 
199  Devicegraph* get_devicegraph();
200  const Devicegraph* get_devicegraph() const;
201 
202  public:
203 
204  class Impl;
205 
206  Impl& get_impl() { return *impl; }
207  const Impl& get_impl() const { return *impl; }
208 
209  virtual Device* clone() const = 0;
210 
211  void save(xmlNode* node) const;
212 
213  protected:
214 
215  Device(Impl* impl);
216 
217  void create(Devicegraph* devicegraph);
218  void load(Devicegraph* devicegraph);
219 
220  private:
221 
222  void add_to_devicegraph(Devicegraph* devicegraph);
223 
224  const std::unique_ptr<Impl> impl;
225 
226  };
227 
228 }
229 
230 #endif
ResizeInfo detect_resize_info() const
Detect the resize info of the device.
bool exists_in_probed() const
Checks if the device exists in the probed devicegraph.
The master container of the libstorage.
Definition: Devicegraph.h:153
static bool compare_by_sid(const Device *lhs, const Device *rhs)
Compare (less than) two Devices by sid.
bool exists_in_staging() const
Checks if the device exists in the staging devicegraph.
Device * copy_to_devicegraph(Devicegraph *devicegraph) const
Copies the device to the devicegraph.
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
bool exists_in_system() const
Checks if the device exists in the system devicegraph.
Definition: FreeInfo.h:178
static bool compare_by_name(const Device *lhs, const Device *rhs)
Compare (less than) two Devices by name.
Base class for storage exceptions.
Definition: Exception.h:113
The storage namespace.
Definition: Actiongraph.h:37
unsigned int sid_t
An integer storage ID.
Definition: Device.h:66
bool exists_in_devicegraph(const Devicegraph *devicegraph) const
Checks if the device exists in the devicegraph.
Definition: Device.h:46