| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | Container.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | This file contains the definition of the WinRT wrapper for the WSLC SDK Container class. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #pragma once |
| 16 | #include "Microsoft.WSL.Containers.Container.g.h" |
| 17 | #include "Helpers.h" |
| 18 | #include "Process.h" |
| 19 | |
| 20 | namespace winrt::Microsoft::WSL::Containers::implementation { |
| 21 | struct Container : ContainerT<Container> |
| 22 | { |
| 23 | Container() = default; |
| 24 | Container(WslcSession session, winrt::Microsoft::WSL::Containers::ContainerSettings const& settings); |
| 25 | // Package-internal: wraps an already-opened container handle (from WslcOpenContainer). |
| 26 | explicit Container(WslcContainer handle, winrt::Microsoft::WSL::Containers::ProcessOutputMode initProcessOutputMode); |
| 27 | |
| 28 | void Start(); |
| 29 | void Stop(winrt::Microsoft::WSL::Containers::Signal const& signal, winrt::Windows::Foundation::TimeSpan timeout); |
| 30 | void Delete(winrt::Microsoft::WSL::Containers::DeleteContainerOption const& flags); |
| 31 | winrt::Microsoft::WSL::Containers::Process CreateProcess(winrt::Microsoft::WSL::Containers::ProcessSettings const& newProcessSettings); |
| 32 | hstring Inspect(); |
| 33 | hstring Id(); |
| 34 | winrt::Microsoft::WSL::Containers::Process InitProcess(); |
| 35 | winrt::Microsoft::WSL::Containers::ContainerState State(); |
| 36 | |
| 37 | void Close(); |
| 38 | static void final_release(std::unique_ptr<Container> self); |
| 39 | |
| 40 | WslcContainer ToHandle(); |
| 41 | |
| 42 | private: |
| 43 | void EnsureNotClosed() const; |
| 44 | |
| 45 | winrt::com_ptr<implementation::Process> m_initProcess; |
| 46 | bool m_opened = false; |
| 47 | |
| 48 | // Releasing the container handle will end the processes and disconnect the callbacks. |
| 49 | // Keep this at the end so that it is released first, ensuring the init process' events aren't destroyed while they may still be signaled. |
| 50 | wil::unique_any<WslcContainer, decltype(&WslcReleaseContainer), &WslcReleaseContainer> m_container; |
| 51 | }; |
| 52 | |
| 53 | } // namespace winrt::Microsoft::WSL::Containers::implementation |
| 54 | |
| 55 | DEFINE_TYPE_HELPERS(Container); |