| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | WSLCSessionReference.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | IWSLCSessionReference implementation. |
| 12 | |
| 13 | This object lives in the per-user COM server process and holds a weak |
| 14 | reference to the WSLCSession. The SYSTEM service holds these references |
| 15 | to track active sessions without preventing session cleanup when clients |
| 16 | release their references. |
| 17 | |
| 18 | When OpenSession() is called: |
| 19 | - If the session is still alive, it returns S_OK with a strong reference |
| 20 | - If the session has been released, it returns ERROR_OBJECT_NO_LONGER_EXISTS |
| 21 | - If the session has been terminated, it returns ERROR_INVALID_STATE |
| 22 | |
| 23 | --*/ |
| 24 | |
| 25 | #pragma once |
| 26 | #include "wslc.h" |
| 27 | #include <wrl/implements.h> |
| 28 | #include <wil/com.h> |
| 29 | |
| 30 | namespace wsl::windows::service::wslc { |
| 31 | |
| 32 | class WSLCSession; |
| 33 | |
| 34 | class WSLCSessionReference |
| 35 | : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWSLCSessionReference, IFastRundown, Microsoft::WRL::FtmBase> |
| 36 | { |
| 37 | public: |
| 38 | NON_COPYABLE(WSLCSessionReference); |
| 39 | NON_MOVABLE(WSLCSessionReference); |
| 40 | |
| 41 | WSLCSessionReference(_In_ WSLCSession* Session); |
| 42 | |
| 43 | ~WSLCSessionReference(); |
| 44 | |
| 45 | // IWSLCSessionReference |
| 46 | IFACEMETHOD(OpenSession)(_Out_ IWSLCSession** Session) override; |
| 47 | IFACEMETHOD(Terminate)() override; |
| 48 | |
| 49 | private: |
| 50 | Microsoft::WRL::ComPtr<IWeakReference> m_weakSession; |
| 51 | }; |
| 52 | |
| 53 | } // namespace wsl::windows::service::wslc |