forked from microsoft/WSL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressCallback.cpp
More file actions
74 lines (58 loc) · 2.27 KB
/
Copy pathProgressCallback.cpp
File metadata and controls
74 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
ProgressCallback.cpp
Abstract:
Implementation of a type that implements IProgressCallback.
--*/
#include "precomp.h"
#include "ProgressCallback.h"
using namespace std::string_view_literals;
namespace {
WslcImageProgressStatus ConvertStatus(LPCSTR Status)
{
#define WSLC_STRING_TO_STATUS_MAPPING(_status_, _string_) \
if (_string_##sv == Status) \
{ \
return _status_; \
}
// TODO: Mapping engine strings to status values seems fragile.
// WSLA is intentionally avoiding this kind of thing for localization of engine strings, which amounts to the same
// thing. If we keep this, a test should be added to explicitly validate that each status is returned properly.
WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_PULLING, "Pulling fs layer");
WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_WAITING, "Waiting");
WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_DOWNLOADING, "Downloading");
WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_VERIFYING, "Verifying Checksum");
WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_EXTRACTING, "Extracting");
WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_COMPLETE, "Pull complete");
return WSLC_IMAGE_PROGRESS_STATUS_UNKNOWN;
}
} // namespace
ProgressCallback::ProgressCallback(WslcContainerImageProgressCallback callback, PVOID context) :
m_callback(callback), m_context(context)
{
}
HRESULT STDMETHODCALLTYPE ProgressCallback::OnProgress(LPCSTR Status, LPCSTR Id, ULONGLONG Current, ULONGLONG Total)
{
if (m_callback)
{
WslcImageProgressMessage message{};
message.id = Id;
message.status = ConvertStatus(Status);
message.detail.current = Current;
message.detail.total = Total;
m_callback(&message, m_context);
}
return S_OK;
}
winrt::com_ptr<ProgressCallback> ProgressCallback::CreateIf(const WslcPullImageOptions* options)
{
if (options->progressCallback)
{
return winrt::make_self<ProgressCallback>(options->progressCallback, options->progressCallbackContext);
}
else
{
return nullptr;
}
}