libstorage-ng
 All Classes Namespaces Functions Typedefs Enumerations 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 
85  std::string get_displayname() const;
86 
87  virtual ResizeInfo detect_resize_info() const;
88 
89  bool has_children() const;
90  size_t num_children() const;
91 
92  bool has_parents() const;
93  size_t num_parents() const;
94 
95  // TODO check if we can somehow return a iterator. getting rid of the
96  // ptr would also allow to use references instead of pointer in the
97  // interface.
98 
99  std::vector<Device*> get_children();
100  std::vector<const Device*> get_children() const;
101 
102  std::vector<Device*> get_parents();
103  std::vector<const Device*> get_parents() const;
104 
105  std::vector<Device*> get_siblings(bool itself);
106  std::vector<const Device*> get_siblings(bool itself) const;
107 
108  std::vector<Device*> get_descendants(bool itself);
109  std::vector<const Device*> get_descendants(bool itself) const;
110 
111  std::vector<Device*> get_ancestors(bool itself);
112  std::vector<const Device*> get_ancestors(bool itself) const;
113 
114  std::vector<Device*> get_leaves(bool itself);
115  std::vector<const Device*> get_leaves(bool itself) const;
116 
117  std::vector<Device*> get_roots(bool itself);
118  std::vector<const Device*> get_roots(bool itself) const;
119 
120  std::vector<Holder*> get_in_holders();
121  std::vector<const Holder*> get_in_holders() const;
122 
123  std::vector<Holder*> get_out_holders();
124  std::vector<const Holder*> get_out_holders() const;
125 
126  void remove_descendants();
127 
128  const std::map<std::string, std::string>& get_userdata() const;
129  void set_userdata(const std::map<std::string, std::string>& userdata);
130 
131  friend std::ostream& operator<<(std::ostream& out, const Device& device);
132 
133  public:
134 
135  class Impl;
136 
137  Impl& get_impl() { return *impl; }
138  const Impl& get_impl() const { return *impl; }
139 
140  virtual Device* clone() const = 0;
141 
142  void save(xmlNode* node) const;
143 
144  protected:
145 
146  Device(Impl* impl);
147 
148  void create(Devicegraph* devicegraph);
149  void load(Devicegraph* devicegraph);
150 
151  private:
152 
153  void add_to_devicegraph(Devicegraph* devicegraph);
154 
155  const std::unique_ptr<Impl> impl;
156 
157  };
158 
159 }
160 
161 #endif
Definition: Device.h:46
The master container of the libstorage.
Definition: Devicegraph.h:133
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
unsigned int sid_t
An integer storage ID.
Definition: Device.h:64