master
h 46 lines 1.49 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2
3 #pragma once
4
5 #include <wil/resource.h>
6 #include "SocketChannel.h"
7 #include "hns_schema.h"
8
9 namespace wsl::core {
10
11 // This class manages the hvsocket channel between wslservice and the gns process inside the VM.
12 // This channel is used for network configuration inside the guest.
13 class GnsChannel
14 {
15 public:
16 GnsChannel(wil::unique_socket&& Socket);
17
18 GnsChannel(const GnsChannel&) = delete;
19
20 GnsChannel& operator=(const GnsChannel&) = delete;
21
22 GnsChannel(GnsChannel&&) = default;
23
24 GnsChannel& operator=(GnsChannel&&) = default;
25
26 void SendEndpointState(const wsl::shared::hns::HNSEndpoint& Notification);
27
28 void SendHnsNotification(LPCWSTR Notification, const GUID& AdapterId);
29
30 void SendNetworkDeviceMessage(LX_MESSAGE_TYPE MessageType, LPCWSTR MessageContent);
31 int SendNetworkDeviceMessageReturnResult(LX_MESSAGE_TYPE MessageType, LPCWSTR MessageContent);
32
33 void Stop() const;
34
35 private:
36 template <typename T>
37 int MessageReturnResult(LX_MESSAGE_TYPE Type, const std::string& Content, const std::function<void(T&)>& BuildMessage = [](auto&) {});
38
39 template <typename T>
40 void Message(LX_MESSAGE_TYPE Type, const std::string& Content, const std::function<void(T&)>& BuildMessage = [](auto&) {});
41
42 // m_channel depends on m_stopEvent, so m_channel needs to be destroyed first.
43 wil::unique_event m_stopEvent{wil::EventOptions::ManualReset};
44 wsl::shared::SocketChannel m_channel;
45 };
46 } // namespace wsl::core