| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | SessionService.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | This file contains the SessionService definition |
| 12 | |
| 13 | --*/ |
| 14 | #pragma once |
| 15 | |
| 16 | #include "SessionModel.h" |
| 17 | #include "Terminal.h" |
| 18 | #include <wslc.h> |
| 19 | |
| 20 | namespace wsl::windows::wslc::services { |
| 21 | struct SessionInformation |
| 22 | { |
| 23 | ULONG SessionId; |
| 24 | DWORD CreatorPid; |
| 25 | std::wstring DisplayName; |
| 26 | }; |
| 27 | |
| 28 | struct SessionService |
| 29 | { |
| 30 | static int Attach(Terminal& terminal, const wsl::windows::wslc::models::Session& session); |
| 31 | static int Enter(Terminal& terminal, const std::wstring& storagePath, const std::wstring& displayName); |
| 32 | static std::vector<SessionInformation> List(); |
| 33 | static WSLCVersion ManagerVersion(); |
| 34 | // Opens an existing session by name. Throws if not found. |
| 35 | static wsl::windows::wslc::models::Session OpenSession(const std::wstring& name); |
| 36 | // Opens the default session. Throws WSLC_E_SESSION_NOT_FOUND if no default session exists. |
| 37 | static wsl::windows::wslc::models::Session OpenDefaultSession(); |
| 38 | // Opens or creates the default session. |
| 39 | static wsl::windows::wslc::models::Session OpenOrCreateDefaultSession(Terminal& terminal); |
| 40 | // Runs the given command and arguments in a session without a TTY, resolving the executable from PATH. |
| 41 | static int Run(Terminal& terminal, const wsl::windows::wslc::models::Session& session, const std::vector<std::string>& arguments); |
| 42 | static int TerminateSession(Terminal& terminal, const wsl::windows::wslc::models::Session& session); |
| 43 | |
| 44 | private: |
| 45 | // Common open-only session lookup with unified error handling. |
| 46 | static wsl::windows::wslc::models::Session OpenSessionByName(const wil::com_ptr<IWSLCSessionManager>& manager, LPCWSTR displayName); |
| 47 | }; |
| 48 | } // namespace wsl::windows::wslc::services |