-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathLoggingWrapper.h
104 lines (84 loc) · 2.54 KB
/
LoggingWrapper.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "stdafx.h"
namespace MicrosoftInstrumentationEngine
{
class CLoggingWrapper :
public IProfilerManagerLogging,
public CModuleRefCount
{
private:
CInitOnce m_initialize;
public:
CLoggingWrapper() :
m_initialize([=]() { return InitializeCore(); })
{
}
~CLoggingWrapper()
{
if (m_initialize.IsSuccessful())
{
CLogging::Shutdown();
}
}
// IUnknown Members
public:
DEFINE_DELEGATED_REFCOUNT_ADDREF(CLoggingWrapper);
DEFINE_DELEGATED_REFCOUNT_RELEASE(CLoggingWrapper);
STDMETHOD(QueryInterface)(_In_ REFIID riid, _Out_ void **ppvObject) override
{
return ImplQueryInterface(
static_cast<IProfilerManagerLogging*>(this),
riid,
ppvObject
);
}
// IProfilerManagerLogging Members
public:
STDMETHOD(LogMessage)(_In_ const WCHAR* wszMessage) override
{
IfNotInitRetUnexpected(m_initialize);
CLogging::LogMessage(wszMessage);
return S_OK;
}
STDMETHOD(LogError)(_In_ const WCHAR* wszError) override
{
IfNotInitRetUnexpected(m_initialize);
CLogging::LogError(wszError);
return S_OK;
}
STDMETHOD(LogDumpMessage)(_In_ const WCHAR* wszMessage) override
{
IfNotInitRetUnexpected(m_initialize);
CLogging::LogDumpMessage(wszMessage);
return S_OK;
}
STDMETHOD(EnableDiagnosticLogToDebugPort)(_In_ BOOL enable) override
{
IfNotInitRetUnexpected(m_initialize);
CLogging::SetLogToDebugPort(enable != 0);
return S_OK;
}
STDMETHOD(GetLoggingFlags)(_Out_ LoggingFlags* pLoggingFlags) override
{
IfNotInitRetUnexpected(m_initialize);
return CLogging::GetLoggingFlags(pLoggingFlags);
}
STDMETHOD(SetLoggingFlags)(_In_ LoggingFlags loggingFlags) override
{
IfNotInitRetUnexpected(m_initialize);
return CLogging::SetLoggingFlags(loggingFlags);
}
public:
HRESULT Initialize()
{
return m_initialize.Get();
}
private:
static HRESULT InitializeCore()
{
return CLogging::Initialize();
}
};
}