virthttp  0.0
libvirt http interface
StorageVol.hpp
Go to the documentation of this file.
1 #ifndef VIRTPP_IMPL_STORAGEVOL_HPP
2 #define VIRTPP_IMPL_STORAGEVOL_HPP
3 
4 #include <utility>
5 #include <libvirt/libvirt.h>
6 #include "../StorageVol.hpp"
7 #include "../Stream.hpp"
8 
9 namespace virt {
10 
11 inline StorageVol::StorageVol(StorageVol&& oth) noexcept : underlying(oth.underlying) { oth.underlying = nullptr; }
12 inline StorageVol& StorageVol::operator=(StorageVol&& oth) noexcept {
13  std::swap(underlying, oth.underlying);
14  return *this;
15 }
16 inline StorageVol::~StorageVol() noexcept { virStorageVolFree(underlying); }
17 
18 constexpr inline StorageVol::operator bool() const noexcept { return underlying != nullptr; }
19 
20 inline bool StorageVol::delete_(DeleteFlag flags) noexcept { return virStorageVolDelete(underlying, to_integral(flags)) == 0; }
21 inline bool StorageVol::download(Stream& strm, unsigned long long offset, unsigned long long length, DownloadFlag flags) noexcept {
22  return virStorageVolDownload(underlying, strm.underlying, offset, length, to_integral(flags));
23 }
24 inline Connection StorageVol::getConnect() const noexcept {
25  const auto res = virStorageVolGetConnect(underlying);
26  if (res)
27  virConnectRef(res);
28  return Connection{res};
29 }
30 
31 inline auto StorageVol::getInfo() const noexcept -> std::optional<Info> {
32  std::optional<Info> ret;
33  return (virStorageVolGetInfo(underlying, &ret.emplace()) == 0) ? ret : std::nullopt;
34 }
35 inline auto StorageVol::getInfo(InfoFlag flags) const noexcept -> std::optional<Info> {
36  std::optional<Info> ret;
37  return (virStorageVolGetInfoFlags(underlying, &ret.emplace(), to_integral(flags)) == 0) ? ret : std::nullopt;
38 }
39 
40 inline passive<gsl::czstring<>> StorageVol::getKey() const noexcept { return virStorageVolGetKey(underlying); }
41 inline passive<gsl::czstring<>> StorageVol::getName() const noexcept { return virStorageVolGetName(underlying); }
42 inline UniqueZstring StorageVol::getPath() const noexcept { return UniqueZstring{virStorageVolGetPath(underlying)}; }
43 inline StoragePool StorageVol::getPool() const noexcept { return StoragePool{virStoragePoolLookupByVolume(underlying)}; }
44 inline UniqueZstring StorageVol::getXMLDesc() const noexcept { return UniqueZstring{virStorageVolGetXMLDesc(underlying, 0)}; }
45 inline bool StorageVol::resize(unsigned long long capacity, ResizeFlag flags) noexcept {
46  return virStorageVolResize(underlying, capacity, to_integral(flags)) == 0;
47 }
48 inline bool StorageVol::upload(Stream& stream, unsigned long long offset, unsigned long long length, UploadFlag flags) noexcept {
49  return virStorageVolUpload(underlying, stream.underlying, offset, length, to_integral(flags)) == 0;
50 }
51 inline bool StorageVol::wipe() noexcept { return virStorageVolWipe(underlying, 0) == 0; }
52 inline bool StorageVol::wipePattern(WipeAlgorithm algorithm) noexcept { return virStorageVolWipePattern(underlying, to_integral(algorithm), 0) == 0; }
53 
54 inline StorageVol StorageVol::createXML(StoragePool& pool, gsl::czstring<> xmlDesc, CreateFlag flags) noexcept {
55  return StorageVol{virStorageVolCreateXML(pool.underlying, xmlDesc, to_integral(flags))};
56 }
57 inline StorageVol StorageVol::createXMLFrom(StoragePool& pool, gsl::czstring<> xmlDesc, const StorageVol& clonevol, CreateFlag flags) noexcept {
58  return StorageVol{virStorageVolCreateXMLFrom(pool.underlying, xmlDesc, clonevol.underlying, to_integral(flags))};
59 }
60 
61 } // namespace virt
62 
63 #endif
Definition: Stream.hpp:10
constexpr auto to_integral(E e) noexcept
Definition: Base.hpp:32
~StorageVol() noexcept
Definition: StorageVol.hpp:16
Definition: VolCreateFlag.hpp:10
StoragePool getPool() const noexcept
Definition: StorageVol.hpp:43
STL namespace.
Definition: Connection.hpp:47
bool download(Stream &strm, unsigned long long offset, unsigned long long length, DownloadFlag flags) noexcept
Definition: StorageVol.hpp:21
T passive
Definition: utility.hpp:48
bool wipe() noexcept
Definition: StorageVol.hpp:51
bool resize(unsigned long long capacity, ResizeFlag flags) noexcept
Definition: StorageVol.hpp:45
Definition: VolWipeAlgorithm.hpp:10
Definition: VolDeleteFlag.hpp:10
passive< gsl::czstring<> > getName() const noexcept
Definition: StorageVol.hpp:41
auto getInfo() const noexcept-> std::optional< Info >
Definition: StorageVol.hpp:31
Definition: VolUploadFlag.hpp:10
passive< gsl::czstring<> > getKey() const noexcept
Definition: StorageVol.hpp:40
Definition: utility.hpp:122
Definition: AdminConnection.hpp:11
constexpr StorageVol() noexcept=default
bool upload(Stream &stream, unsigned long long offset, unsigned long long length, UploadFlag flags) noexcept
Definition: StorageVol.hpp:48
static StorageVol createXML(StoragePool &pool, gsl::czstring<> xmlDesc, CreateFlag flags) noexcept
Definition: StorageVol.hpp:54
Definition: StoragePool.hpp:11
static StorageVol createXMLFrom(StoragePool &pool, gsl::czstring<> xmlDesc, const StorageVol &clonevol, CreateFlag flags) noexcept
Definition: StorageVol.hpp:57
Definition: StorageVol.hpp:10
Definition: VolInfoFlag.hpp:10
UniqueZstring getXMLDesc() const noexcept
Definition: StorageVol.hpp:44
bool delete_(DeleteFlag flags) noexcept
Definition: StorageVol.hpp:20
Definition: VolResizeFlag.hpp:10
Definition: StorageVol.hpp:64
Connection getConnect() const noexcept
Definition: StorageVol.hpp:24
constexpr StorageVol & operator=(const StorageVol &) noexcept=delete
Definition: VolDownloadFlag.hpp:10
UniqueZstring getPath() const noexcept
Definition: StorageVol.hpp:42
bool wipePattern(WipeAlgorithm algorithm) noexcept
Definition: StorageVol.hpp:52