master
h 77 lines 2.63 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 PluginManager.h
8
9 Abstract:
10
11 This file contains the PluginManager class definition.
12
13 --*/
14
15 #pragma once
16
17 #include <wil/resource.h>
18 #include <string>
19 #include <vector>
20 #include "WslPluginApi.h"
21
22 namespace wsl::windows::service {
23 class PluginManager
24 {
25 public:
26 struct PluginError
27 {
28 std::wstring plugin;
29 HRESULT error;
30 };
31
32 PluginManager() = default;
33
34 PluginManager(const PluginManager&) = delete;
35 PluginManager& operator=(const PluginManager&) = delete;
36 PluginManager(PluginManager&&) = delete;
37 PluginManager& operator=(PluginManager&&) = delete;
38
39 void LoadPlugins();
40 void OnVmStarted(const WSLSessionInformation* Session, const WSLVmCreationSettings* Settings);
41 void OnVmStopping(const WSLSessionInformation* Session) const;
42 void OnDistributionStarted(const WSLSessionInformation* Session, const WSLDistributionInformation* distro);
43 void OnDistributionStopping(const WSLSessionInformation* Session, const WSLDistributionInformation* distro) const;
44 void OnDistributionRegistered(const WSLSessionInformation* Session, const WslOfflineDistributionInformation* distro) const;
45 void OnDistributionUnregistered(const WSLSessionInformation* Session, const WslOfflineDistributionInformation* distro) const;
46
47 // WSLC notifications. Returning failure from OnSessionCreated/OnContainerStarted causes the
48 // corresponding operation to be aborted. Other notifications log errors and continue.
49 void OnWslcSessionCreated(const WSLCSessionInformation* Session);
50 void OnWslcSessionStopping(const WSLCSessionInformation* Session) const;
51 HRESULT OnWslcContainerStarted(const WSLCSessionInformation* Session, LPCSTR InspectJson) const;
52 void OnWslcContainerStopping(const WSLCSessionInformation* Session, LPCSTR ContainerId) const;
53 void OnWslcImageCreated(const WSLCSessionInformation* Session, LPCSTR InspectJson) const;
54 void OnWslcImageDeleted(const WSLCSessionInformation* Session, LPCSTR ImageId) const;
55 void OnWslcVmStarted(const WSLCSessionInformation* Session) const;
56 void OnWslcVmStopping(const WSLCSessionInformation* Session) const;
57
58 static bool IsInWslcNotification() noexcept;
59
60 void ThrowIfFatalPluginError() const;
61
62 private:
63 void LoadPlugin(LPCWSTR Name, LPCWSTR Path);
64 static void ThrowIfPluginError(HRESULT Result, LPCWSTR Plugin);
65
66 struct LoadedPlugin
67 {
68 wil::unique_hmodule module;
69 std::wstring name;
70 WSLPluginHooksV1 hooks{};
71 };
72
73 std::vector<LoadedPlugin> m_plugins;
74 std::optional<PluginError> m_pluginError;
75 };
76
77 } // namespace wsl::windows::service