master
cpp 103 lines 2.45 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 ContainerNamedVolume.cpp
8
9 Abstract:
10
11 This file contains the implementation of the WinRT wrapper for the WSLC SDK ContainerNamedVolume class.
12
13 --*/
14
15 #include "precomp.h"
16 #include "ContainerNamedVolume.h"
17 #include "Microsoft.WSL.Containers.ContainerNamedVolume.g.cpp"
18
19 namespace winrt::Microsoft::WSL::Containers::implementation {
20
21 ContainerNamedVolume::ContainerNamedVolume(hstring const& name, hstring const& containerPath, bool readOnly) :
22 m_name(winrt::to_string(name)), m_containerPath(winrt::to_string(containerPath)), m_readOnly(readOnly)
23 {
24 if (name.empty())
25 {
26 throw hresult_invalid_argument(L"Volume name cannot be empty");
27 }
28
29 if (containerPath.empty())
30 {
31 throw hresult_invalid_argument(L"Container path cannot be empty");
32 }
33 }
34
35 hstring ContainerNamedVolume::Name()
36 {
37 return winrt::to_hstring(m_name);
38 }
39
40 void ContainerNamedVolume::Name(hstring const& value)
41 {
42 if (m_containerNamedVolume)
43 {
44 throw hresult_illegal_state_change(L"Cannot change value after options have been applied");
45 }
46
47 if (value.empty())
48 {
49 throw hresult_invalid_argument(L"Volume name cannot be empty");
50 }
51
52 m_name = winrt::to_string(value);
53 }
54
55 hstring ContainerNamedVolume::ContainerPath()
56 {
57 return winrt::to_hstring(m_containerPath);
58 }
59
60 void ContainerNamedVolume::ContainerPath(hstring const& value)
61 {
62 if (m_containerNamedVolume)
63 {
64 throw hresult_illegal_state_change(L"Cannot change value after options have been applied");
65 }
66
67 if (value.empty())
68 {
69 throw hresult_invalid_argument(L"Container path cannot be empty");
70 }
71
72 m_containerPath = winrt::to_string(value);
73 }
74
75 bool ContainerNamedVolume::ReadOnly()
76 {
77 return m_readOnly;
78 }
79
80 void ContainerNamedVolume::ReadOnly(bool value)
81 {
82 if (m_containerNamedVolume)
83 {
84 throw hresult_illegal_state_change(L"Cannot change value after options have been applied");
85 }
86
87 m_readOnly = value;
88 }
89
90 WslcContainerNamedVolume ContainerNamedVolume::ToStruct()
91 {
92 if (!m_containerNamedVolume)
93 {
94 m_containerNamedVolume = std::make_unique<WslcContainerNamedVolume>();
95 m_containerNamedVolume->name = m_name.c_str();
96 m_containerNamedVolume->containerPath = m_containerPath.c_str();
97 m_containerNamedVolume->readOnly = m_readOnly;
98 }
99
100 return *m_containerNamedVolume;
101 }
102
103 } // namespace winrt::Microsoft::WSL::Containers::implementation