libstorage-ng
Holder.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2017-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_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 
85  public:
86 
87  class Impl;
88 
89  Impl& get_impl() { return *impl; }
90  const Impl& get_impl() const { return *impl; }
91 
92  virtual Holder* clone() const = 0;
93 
94  void save(xmlNode* node) const;
95 
96  friend std::ostream& operator<<(std::ostream& out, const Holder& holder);
97 
98  protected:
99 
100  Holder(Impl* impl);
101 
102  void create(Devicegraph* devicegraph, const Device* source, const Device* target);
103  void load(Devicegraph* devicegraph, const xmlNode* node);
104 
105  private:
106 
107  void add_to_devicegraph(Devicegraph* devicegraph, const Device* source,
108  const Device* target);
109 
110  const std::unique_ptr<Impl> impl;
111 
112  };
113 
114 }
115 
116 #endif
Holder * copy_to_devicegraph(Devicegraph *devicegraph) const
Copies the holder to the 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
The storage namespace.
Definition: Actiongraph.h:37
unsigned int sid_t
An integer storage ID.
Definition: Device.h:66