| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | ProgressCallback.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | Header for a type that implements IWSLCCompatProgressCallback. |
| 12 | |
| 13 | --*/ |
| 14 | #pragma once |
| 15 | #include "WSLCCompat.h" |
| 16 | #include "wslcsdkprivate.h" |
| 17 | #include <winrt/base.h> |
| 18 | |
| 19 | struct ProgressCallback : public winrt::implements<ProgressCallback, IWSLCCompatProgressCallback> |
| 20 | { |
| 21 | ProgressCallback(WslcContainerImageProgressCallback callback, PVOID context); |
| 22 | |
| 23 | // IWSLCCompatProgressCallback |
| 24 | HRESULT STDMETHODCALLTYPE OnProgress(LPCSTR Status, LPCSTR Id, ULONGLONG Current, ULONGLONG Total) override; |
| 25 | |
| 26 | // Creates a ProgressCallback if the options provides a callback. |
| 27 | template <typename Options> |
| 28 | static winrt::com_ptr<ProgressCallback> CreateIf(const Options* options) |
| 29 | { |
| 30 | if (options && options->progressCallback) |
| 31 | { |
| 32 | return winrt::make_self<ProgressCallback>(options->progressCallback, options->progressCallbackContext); |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | return nullptr; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | WslcContainerImageProgressCallback m_callback = nullptr; |
| 42 | PVOID m_context = nullptr; |
| 43 | }; |