master
cpp 78 lines 1.82 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 PullImageOptions.cpp
8
9 Abstract:
10
11 This file contains the implementation of the WinRT wrapper for the WSLC SDK PullImageOptions class.
12
13 --*/
14
15 #include "precomp.h"
16 #include "PullImageOptions.h"
17 #include "Microsoft.WSL.Containers.PullImageOptions.g.cpp"
18
19 namespace winrt::Microsoft::WSL::Containers::implementation {
20
21 PullImageOptions::PullImageOptions(hstring const& uri) : m_uri(winrt::to_string(uri))
22 {
23 if (uri.empty())
24 {
25 throw hresult_invalid_argument(L"URI cannot be empty");
26 }
27 }
28
29 hstring PullImageOptions::Uri()
30 {
31 return winrt::to_hstring(m_uri);
32 }
33
34 void PullImageOptions::Uri(hstring const& value)
35 {
36 if (m_pullImageOptions)
37 {
38 throw hresult_illegal_state_change(L"Cannot change value after options have been applied");
39 }
40
41 if (value.empty())
42 {
43 throw hresult_invalid_argument(L"URI cannot be empty");
44 }
45
46 m_uri = winrt::to_string(value);
47 }
48
49 hstring PullImageOptions::RegistryAuth()
50 {
51 return winrt::to_hstring(m_registryAuth);
52 }
53
54 void PullImageOptions::RegistryAuth(hstring const& value)
55 {
56 if (m_pullImageOptions)
57 {
58 throw hresult_illegal_state_change(L"Cannot change value after options have been applied");
59 }
60
61 m_registryAuth = winrt::to_string(value);
62 }
63
64 WslcPullImageOptions PullImageOptions::ToStruct()
65 {
66 if (!m_pullImageOptions)
67 {
68 m_pullImageOptions = std::make_unique<WslcPullImageOptions>();
69 m_pullImageOptions->uri = m_uri.c_str();
70 m_pullImageOptions->registryAuth = m_registryAuth.empty() ? nullptr : m_registryAuth.c_str();
71 m_pullImageOptions->progressCallback = nullptr;
72 m_pullImageOptions->progressCallbackContext = nullptr;
73 }
74
75 return *m_pullImageOptions;
76 }
77
78 } // namespace winrt::Microsoft::WSL::Containers::implementation