master
cpp 64 lines 1.62 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 LxssServerPort.cpp
8
9 Abstract:
10
11 This file contains a wrapper class for LxBus server ports.
12
13 --*/
14
15 #include "precomp.h"
16 #include "LxssServerPort.h"
17 #include "LxssMessagePort.h"
18
19 LxssServerPort::LxssServerPort()
20 {
21 }
22
23 LxssServerPort::LxssServerPort(_In_ wil::unique_handle&& ServerPortHandle) : m_serverPort(std::move(ServerPortHandle))
24 {
25 }
26
27 void LxssServerPort::RegisterLxBusServer(_In_ const wil::unique_handle& InstanceHandle, _In_ LPCSTR ServerName)
28 {
29 WI_ASSERT(!m_serverPort);
30
31 LXBUS_REGISTER_SERVER_PARAMETERS RegisterServer = {};
32 RegisterServer.Input.ServerName = ServerName;
33 THROW_IF_NTSTATUS_FAILED(LxBusClientRegisterServer(InstanceHandle.get(), &RegisterServer));
34
35 m_serverPort.reset(UlongToHandle(RegisterServer.Output.ServerPort));
36 }
37
38 HANDLE
39 LxssServerPort::ReleaseServerPort()
40 {
41 return m_serverPort.release();
42 }
43
44 std::unique_ptr<LxssMessagePort> LxssServerPort::WaitForConnection(_In_ ULONG TimeoutMs)
45 {
46 std::unique_ptr<LxssMessagePort> MessagePort;
47 THROW_IF_NTSTATUS_FAILED(WaitForConnectionNoThrow(&MessagePort, TimeoutMs));
48
49 return MessagePort;
50 }
51
52 NTSTATUS
53 LxssServerPort::WaitForConnectionNoThrow(_Out_ std::unique_ptr<LxssMessagePort>* MessagePort, _In_ ULONG TimeoutMs) const
54 {
55 LXBUS_IPC_SERVER_WAIT_FOR_CONNECTION_PARAMETERS Params = {};
56 Params.Input.TimeoutMs = TimeoutMs;
57 const NTSTATUS Status = LxBusClientWaitForConnection(m_serverPort.get(), &Params);
58 if (NT_SUCCESS(Status))
59 {
60 *MessagePort = std::make_unique<LxssMessagePort>(UlongToHandle(Params.Output.MessagePort));
61 }
62
63 return Status;
64 }