libstorage-ng
 All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
Device.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) 2016 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 
46  struct DeviceHasWrongType : public Exception
47  {
48  DeviceHasWrongType(const char* seen, const char* expected);
49  };
50 
51 
64  typedef unsigned int sid_t;
65 
66 
72 
73  class Device : private boost::noncopyable
74  {
75 
76  public:
77 
78  virtual ~Device();
79 
80  sid_t get_sid() const;
81 
82  bool operator==(const Device& rhs) const;
83  bool operator!=(const Device& rhs) const;
84 
88  bool exists_in_devicegraph(const Devicegraph* devicegraph) const;
89 
93  bool exists_in_probed() const;
94 
98  bool exists_in_staging() const;
99 
100  std::string get_displayname() const;
101 
102  virtual ResizeInfo detect_resize_info() const;
103 
104  bool has_children() const;
105  size_t num_children() const;
106 
107  bool has_parents() const;
108  size_t num_parents() const;
109 
110  // TODO check if we can somehow return a iterator. getting rid of the
111  // ptr would also allow to use references instead of pointer in the
112  // interface.
113 
114  std::vector<Device*> get_children();
115  std::vector<const Device*> get_children() const;
116 
117  std::vector<Device*> get_parents();
118  std::vector<const Device*> get_parents() const;
119 
120  std::vector<Device*> get_siblings(bool itself);
121  std::vector<const Device*> get_siblings(bool itself) const;
122 
123  std::vector<Device*> get_descendants(bool itself);
124  std::vector<const Device*> get_descendants(bool itself) const;
125 
126  std::vector<Device*> get_ancestors(bool itself);
127  std::vector<const Device*> get_ancestors(bool itself) const;
128 
129  std::vector<Device*> get_leaves(bool itself);
130  std::vector<const Device*> get_leaves(bool itself) const;
131 
132  std::vector<Device*> get_roots(bool itself);
133  std::vector<const Device*> get_roots(bool itself) const;
134 
135  std::vector<Holder*> get_in_holders();
136  std::vector<const Holder*> get_in_holders() const;
137 
138  std::vector<Holder*> get_out_holders();
139  std::vector<const Holder*> get_out_holders() const;
140 
141  void remove_descendants();
142 
143  const std::map<std::string, std::string>& get_userdata() const;
144  void set_userdata(const std::map<std::string, std::string>& userdata);
145 
146  friend std::ostream& operator<<(std::ostream& out, const Device& device);
147 
148  public:
149 
150  class Impl;
151 
152  Impl& get_impl() { return *impl; }
153  const Impl& get_impl() const { return *impl; }
154 
155  virtual Device* clone() const = 0;
156 
157  void save(xmlNode* node) const;
158 
159  protected:
160 
161  Device(Impl* impl);
162 
163  void create(Devicegraph* devicegraph);
164  void load(Devicegraph* devicegraph);
165 
166  private:
167 
168  void add_to_devicegraph(Devicegraph* devicegraph);
169 
170  const std::unique_ptr<Impl> impl;
171 
172  };
173 
174 }
175 
176 #endif
bool exists_in_probed() const
Checks if the device exists in the probed devicegraph.
Definition: Device.h:46
The master container of the libstorage.
Definition: Devicegraph.h:133
bool exists_in_staging() const
Checks if the device exists in the staging devicegraph.
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:73
Base class for storage exceptions.
Definition: Exception.h:113
The storage namespace.
Definition: Actiongraph.h:36
unsigned int sid_t
An integer storage ID.
Definition: Device.h:64
bool exists_in_devicegraph(const Devicegraph *devicegraph) const
Checks if the device exists in the devicegraph.