master
cpp 51 lines 1.07 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 WslInstallerFactory.cpp
8
9 Abstract:
10
11 This file contains the WslInstallerFactory class implementation.
12
13 --*/
14
15 #include "precomp.h"
16
17 #include "WslInstallerFactory.h"
18
19 CoCreatableClassWithFactory(WslInstaller, WslInstallerFactory);
20
21 static std::vector<std::shared_ptr<WslInstaller>> g_sessions;
22 static wil::srwlock g_mutex;
23 extern wil::unique_event g_stopEvent;
24
25 void ClearSessions()
26 {
27 auto lock = g_mutex.lock_exclusive();
28 g_sessions.clear();
29 }
30
31 HRESULT WslInstallerFactory::CreateInstance(_In_ IUnknown* pUnkOuter, _In_ REFIID riid, _Out_ void** ppCreated)
32 {
33 RETURN_HR_IF_NULL(E_POINTER, ppCreated);
34 *ppCreated = nullptr;
35
36 RETURN_HR_IF(CLASS_E_NOAGGREGATION, pUnkOuter != nullptr);
37
38 WSL_LOG("WslInstallerCreateInstance", TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
39
40 auto lock = g_mutex.lock_exclusive();
41
42 if (g_stopEvent.is_signaled())
43 {
44 return S_FALSE;
45 }
46
47 const auto instance = wil::MakeOrThrow<WslInstaller>();
48 instance.CopyTo(riid, ppCreated);
49
50 return S_OK;
51 }