-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathEventLoggingBase.h
64 lines (50 loc) · 1.86 KB
/
EventLoggingBase.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "stdafx.h"
#pragma warning(push)
#pragma warning(disable: 4995) // disable so that memcpy can be used
#include <atlsync.h>
#include <queue>
#pragma warning(pop)
#include "../Common.Headers/tstring.h"
#include "../Common.Headers/CriticalSectionHolder.h"
namespace CommonLib
{
struct EventLogItem
{
EventLogItem(WORD wType, const tstring& tsLog)
: wEventType(wType), tsEventLog(tsLog)
{
}
WORD wEventType;
tstring tsEventLog;
};
class CEventLoggingBase
{
private:
// critical section which protects the shared buffer for reads/writes
CCriticalSection m_cs;
std::queue<EventLogItem> m_eventQueue;
size_t m_eventQueueLength;
CEvent m_hEventQueueProcessEvent;
CHandle m_hEventQueueThread;
HANDLE m_hEventSource; // Not relying on RAII; this handle should be closed by DeregisterEventSource call.
bool m_isShutdown;
protected:
// Registers the EventSource with the given name and sets m_hEventQueueThread handle.
HRESULT InitializeEventSource(_In_ LPCWSTR wszEventSourceName);
// Deregisters the m_hEventSource handle.
HRESULT TerminateEventSource();
// The COM-initialized thread that m_hEventQueueThread holds; polls the queue for event logs to report.
static DWORD WINAPI LogEventThreadProc(_In_ LPVOID lpParam);
void LogEvent(_In_ const tstring& tsEntry);
// Conducts ReportEvent invocation.
virtual void LogEvent(_In_ const EventLogItem& tsEntry);
// Adds the eventlog and type to the queue.
HRESULT AppendToQueue(_In_ WORD wEventType, _In_ tstring wsEventLog);
public:
CEventLoggingBase();
~CEventLoggingBase();
};
}