mirror of
https://github.com/microsoft/WSL.git
synced 2025-12-10 00:44:55 -06:00
Add new files
This commit is contained in:
parent
2a4f8d0bdd
commit
9dd34f230d
61
src/windows/common/WSLAContainerLauncher.cpp
Normal file
61
src/windows/common/WSLAContainerLauncher.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "WSLAContainerLauncher.h"
|
||||
|
||||
using wsl::windows::common::ClientRunningWSLAProcess;
|
||||
using wsl::windows::common::RunningWSLAContainer;
|
||||
using wsl::windows::common::WSLAContainerLauncher;
|
||||
|
||||
RunningWSLAContainer::RunningWSLAContainer(wil::com_ptr<IWSLAContainer>&& Container, std::vector<WSLA_PROCESS_FD>&& fds) :
|
||||
m_container(std::move(Container)), m_fds(std::move(fds))
|
||||
{
|
||||
}
|
||||
|
||||
IWSLAContainer& RunningWSLAContainer::Get()
|
||||
{
|
||||
return *m_container;
|
||||
}
|
||||
|
||||
WSLA_CONTAINER_STATE RunningWSLAContainer::State()
|
||||
{
|
||||
WSLA_CONTAINER_STATE state{};
|
||||
THROW_IF_FAILED(m_container->GetState(&state));
|
||||
return state;
|
||||
}
|
||||
|
||||
ClientRunningWSLAProcess RunningWSLAContainer::GetInitProcess()
|
||||
{
|
||||
wil::com_ptr<IWSLAProcess> process;
|
||||
THROW_IF_FAILED(m_container->GetInitProcess(&process));
|
||||
|
||||
return ClientRunningWSLAProcess{std::move(process), std::move(m_fds)};
|
||||
}
|
||||
|
||||
WSLAContainerLauncher::WSLAContainerLauncher(
|
||||
const std::string& Image,
|
||||
const std::string& Name,
|
||||
const std::string& EntryPoint,
|
||||
const std::vector<std::string>& Arguments,
|
||||
const std::vector<std::string>& Environment,
|
||||
ProcessFlags Flags) :
|
||||
WSLAProcessLauncher(EntryPoint, Arguments, Environment, Flags), m_image(Image), m_name(Name)
|
||||
{
|
||||
}
|
||||
|
||||
RunningWSLAContainer WSLAContainerLauncher::Launch(IWSLASession& Session)
|
||||
{
|
||||
WSLA_CONTAINER_OPTIONS options{};
|
||||
options.Image = m_image.c_str();
|
||||
options.Name = m_name.c_str();
|
||||
auto [processOptions, commandLinePtrs, environmentPtrs] = CreateProcessOptions();
|
||||
options.InitProcessOptions = processOptions;
|
||||
|
||||
if (m_executable.empty())
|
||||
{
|
||||
options.InitProcessOptions.Executable = nullptr;
|
||||
}
|
||||
|
||||
// TODO: Support volumes, ports, flags, shm size, etc.
|
||||
wil::com_ptr<IWSLAContainer> container;
|
||||
THROW_IF_FAILED(Session.CreateContainer(&options, &container));
|
||||
|
||||
return RunningWSLAContainer{std::move(container), std::move(m_fds)};
|
||||
}
|
||||
44
src/windows/common/WSLAContainerLauncher.h
Normal file
44
src/windows/common/WSLAContainerLauncher.h
Normal file
@ -0,0 +1,44 @@
|
||||
#include "WSLAprocessLauncher.h"
|
||||
|
||||
namespace wsl::windows::common {
|
||||
|
||||
class RunningWSLAContainer
|
||||
{
|
||||
public:
|
||||
NON_COPYABLE(RunningWSLAContainer);
|
||||
DEFAULT_MOVABLE(RunningWSLAContainer);
|
||||
RunningWSLAContainer(wil::com_ptr<IWSLAContainer>&& Container, std::vector<WSLA_PROCESS_FD>&& fds);
|
||||
IWSLAContainer& Get();
|
||||
|
||||
WSLA_CONTAINER_STATE State();
|
||||
ClientRunningWSLAProcess GetInitProcess();
|
||||
|
||||
private:
|
||||
wil::com_ptr<IWSLAContainer> m_container;
|
||||
std::vector<WSLA_PROCESS_FD> m_fds;
|
||||
};
|
||||
|
||||
class WSLAContainerLauncher : public WSLAProcessLauncher
|
||||
{
|
||||
public:
|
||||
NON_COPYABLE(WSLAContainerLauncher);
|
||||
NON_MOVABLE(WSLAContainerLauncher);
|
||||
|
||||
WSLAContainerLauncher(
|
||||
const std::string& Image,
|
||||
const std::string& Name,
|
||||
const std::string& EntryPoint = "",
|
||||
const std::vector<std::string>& Arguments = {},
|
||||
const std::vector<std::string>& Environment = {},
|
||||
ProcessFlags Flags = ProcessFlags::Stdout | ProcessFlags::Stderr);
|
||||
|
||||
void AddVolume(const std::string& HostPath, const std::string& ContainerPath, bool ReadOnly);
|
||||
void AddPort(uint16_t WindowsPort, uint16_t ContainerPort, int Family);
|
||||
|
||||
RunningWSLAContainer Launch(IWSLASession& Session);
|
||||
|
||||
private:
|
||||
std::string m_image;
|
||||
std::string m_name;
|
||||
};
|
||||
} // namespace wsl::windows::common
|
||||
Loading…
x
Reference in New Issue
Block a user