libstorage-ng
Holder.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2017-2019] 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 
34 
35 namespace storage
36 {
37  class Devicegraph;
38  class Device;
39 
40 
42  {
43  public:
44 
45  HolderHasWrongType(const char* seen, const char* expected);
46  };
47 
48 
49  // abstract class
50 
51  class Holder : private boost::noncopyable
52  {
53  public:
54 
55  virtual ~Holder();
56 
57  Device* get_source();
58  const Device* get_source() const;
59 
60  sid_t get_source_sid() const;
61 
62  Device* get_target();
63  const Device* get_target() const;
64 
65  sid_t get_target_sid() const;
66 
67  bool operator==(const Holder& rhs) const;
68  bool operator!=(const Holder& rhs) const;
69 
83  Holder* copy_to_devicegraph(Devicegraph* devicegraph) 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 
103  bool exists_in_system() const;
104 
105  public:
106 
107  class Impl;
108 
109  Impl& get_impl() { return *impl; }
110  const Impl& get_impl() const { return *impl; }
111 
112  virtual Holder* clone() const = 0;
113 
114  void save(xmlNode* node) const;
115 
116  friend std::ostream& operator<<(std::ostream& out, const Holder& holder);
117 
118  protected:
119 
120  Holder(Impl* impl);
121 
122  void create(Devicegraph* devicegraph, const Device* source, const Device* target);
123  void load(Devicegraph* devicegraph, const xmlNode* node);
124 
125  private:
126 
127  void add_to_devicegraph(Devicegraph* devicegraph, const Device* source,
128  const Device* target);
129 
130  const std::unique_ptr<Impl> impl;
131 
132  };
133 
134 }
135 
136 #endif
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.
bool exists_in_system() const
Checks if the holder exists in the system devicegraph.
Definition: Holder.h:41
The master container of the libstorage.
Definition: Devicegraph.h:153
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
Definition: Holder.h:51
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:37
unsigned int sid_t
An integer storage ID.
Definition: Device.h:66