| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | APICompat.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | API compatibility layer between the wslc.idl and wslccompat.idl. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #pragma once |
| 16 | |
| 17 | #include <vector> |
| 18 | #include <wrl/client.h> |
| 19 | #include "wslc.h" |
| 20 | #include "WSLCCompat.h" |
| 21 | |
| 22 | namespace wsl::windows::common::apicompat { |
| 23 | |
| 24 | // |
| 25 | // Struct conversions. |
| 26 | // |
| 27 | // Enums and flags are shared between wslc.idl and WSLCCompat.idl (see WSLCShared.idl), |
| 28 | // so they require no conversion. |
| 29 | // |
| 30 | |
| 31 | // Forward (WSLCCompat -> wslc.idl). |
| 32 | WSLCVersion Convert(const WSLCCompatVersion& Version); |
| 33 | WSLCHandle Convert(const WSLCCompatHandle& Handle); |
| 34 | WSLCStringArray Convert(const WSLCCompatStringArray& Array); |
| 35 | WSLCProcessOptions Convert(const WSLCCompatProcessOptions& Options); |
| 36 | KeyValuePair Convert(const WSLCCompatKeyValuePair& Pair); |
| 37 | WSLCVolume Convert(const WSLCCompatVolume& Volume); |
| 38 | WSLCNamedVolume Convert(const WSLCCompatNamedVolume& Volume); |
| 39 | WSLCPortMapping Convert(const WSLCCompatPortMapping& Port); |
| 40 | WSLCTmpfsMount Convert(const WSLCCompatTmpfsMount& Mount); |
| 41 | WSLCUlimit Convert(const WSLCCompatUlimit& Ulimit); |
| 42 | WSLCDeleteImageOptions Convert(const WSLCCompatDeleteImageOptions& Options); |
| 43 | WSLCTagImageOptions Convert(const WSLCCompatTagImageOptions& Options); |
| 44 | |
| 45 | // Reverse (wslc.idl -> WSLCCompat). |
| 46 | WSLCCompatVersion Convert(const WSLCVersion& Version); |
| 47 | WSLCCompatHandle Convert(const WSLCHandle& Handle); |
| 48 | WSLCCompatImageInformation Convert(const WSLCImageInformation& Image); |
| 49 | WSLCCompatDeletedImageInformation Convert(const WSLCDeletedImageInformation& Image); |
| 50 | WSLCCompatVolumeInformation Convert(const WSLCVolumeInformation& Volume); |
| 51 | |
| 52 | // |
| 53 | // Composite struct conversions. |
| 54 | // |
| 55 | |
| 56 | class ContainerOptionsConversion |
| 57 | { |
| 58 | public: |
| 59 | NON_COPYABLE(ContainerOptionsConversion); |
| 60 | DEFAULT_MOVABLE(ContainerOptionsConversion); |
| 61 | |
| 62 | explicit ContainerOptionsConversion(const WSLCCompatContainerOptions& Options); |
| 63 | |
| 64 | const WSLCContainerOptions* Get() const noexcept |
| 65 | { |
| 66 | return &m_value; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | WSLCContainerOptions m_value{}; |
| 71 | std::vector<WSLCVolume> m_volumes; |
| 72 | std::vector<WSLCPortMapping> m_ports; |
| 73 | std::vector<WSLCLabel> m_labels; |
| 74 | std::vector<WSLCTmpfsMount> m_tmpfs; |
| 75 | std::vector<WSLCNamedVolume> m_namedVolumes; |
| 76 | std::vector<WSLCUlimit> m_ulimits; |
| 77 | std::vector<WSLCNetworkConnection> m_networks; |
| 78 | std::vector<std::vector<KeyValuePair>> m_networkSettings; |
| 79 | }; |
| 80 | |
| 81 | class ListImagesOptionsConversion |
| 82 | { |
| 83 | public: |
| 84 | NON_COPYABLE(ListImagesOptionsConversion); |
| 85 | DEFAULT_MOVABLE(ListImagesOptionsConversion); |
| 86 | |
| 87 | explicit ListImagesOptionsConversion(const WSLCCompatListImagesOptions& Options); |
| 88 | |
| 89 | const WSLCListImagesOptions* Get() const noexcept |
| 90 | { |
| 91 | return &m_value; |
| 92 | } |
| 93 | |
| 94 | private: |
| 95 | WSLCListImagesOptions m_value{}; |
| 96 | std::vector<WSLCFilter> m_filters; |
| 97 | }; |
| 98 | |
| 99 | class VolumeOptionsConversion |
| 100 | { |
| 101 | public: |
| 102 | NON_COPYABLE(VolumeOptionsConversion); |
| 103 | DEFAULT_MOVABLE(VolumeOptionsConversion); |
| 104 | |
| 105 | explicit VolumeOptionsConversion(const WSLCCompatVolumeOptions& Options); |
| 106 | |
| 107 | const WSLCVolumeOptions* Get() const noexcept |
| 108 | { |
| 109 | return &m_value; |
| 110 | } |
| 111 | |
| 112 | private: |
| 113 | WSLCVolumeOptions m_value{}; |
| 114 | std::vector<WSLCDriverOption> m_driverOpts; |
| 115 | std::vector<WSLCLabel> m_labels; |
| 116 | }; |
| 117 | |
| 118 | class SessionSettingsConversion |
| 119 | { |
| 120 | public: |
| 121 | NON_COPYABLE(SessionSettingsConversion); |
| 122 | DEFAULT_MOVABLE(SessionSettingsConversion); |
| 123 | |
| 124 | explicit SessionSettingsConversion(const WSLCCompatSessionSettings& Settings); |
| 125 | |
| 126 | const WSLCSessionSettings* Get() const noexcept |
| 127 | { |
| 128 | return &m_value; |
| 129 | } |
| 130 | |
| 131 | private: |
| 132 | WSLCSessionSettings m_value{}; |
| 133 | }; |
| 134 | |
| 135 | inline ContainerOptionsConversion Convert(const WSLCCompatContainerOptions& Options) |
| 136 | { |
| 137 | return ContainerOptionsConversion(Options); |
| 138 | } |
| 139 | |
| 140 | inline ListImagesOptionsConversion Convert(const WSLCCompatListImagesOptions& Options) |
| 141 | { |
| 142 | return ListImagesOptionsConversion(Options); |
| 143 | } |
| 144 | |
| 145 | inline VolumeOptionsConversion Convert(const WSLCCompatVolumeOptions& Options) |
| 146 | { |
| 147 | return VolumeOptionsConversion(Options); |
| 148 | } |
| 149 | |
| 150 | inline SessionSettingsConversion Convert(const WSLCCompatSessionSettings& Settings) |
| 151 | { |
| 152 | return SessionSettingsConversion(Settings); |
| 153 | } |
| 154 | |
| 155 | // |
| 156 | // Callback conversions. |
| 157 | // |
| 158 | |
| 159 | Microsoft::WRL::ComPtr<ICrashDumpCallback> Convert(IWSLCCompatCrashDumpCallback* Callback); |
| 160 | Microsoft::WRL::ComPtr<IProgressCallback> Convert(IWSLCCompatProgressCallback* Callback); |
| 161 | Microsoft::WRL::ComPtr<IWarningCallback> Convert(IWSLCCompatWarningCallback* Callback); |
| 162 | |
| 163 | } // namespace wsl::windows::common::apicompat |