forked from CobaltFusion/DebugViewPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBWinWriter.cpp
More file actions
38 lines (31 loc) · 1.19 KB
/
Copy pathDBWinWriter.cpp
File metadata and controls
38 lines (31 loc) · 1.19 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
// (C) Copyright Gert-Jan de Vos and Jan Wilmans 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <algorithm>
#include "DebugViewppLib/DBWinBuffer.h"
#include "DebugViewppLib/DBWinWriter.h"
namespace fusion {
namespace debugviewpp {
DBWinWriter::DBWinWriter() :
m_hBuffer(::OpenFileMapping(FILE_MAP_WRITE, 0, L"DBWIN_BUFFER")),
m_dbWinBufferReady(::OpenEvent(SYNCHRONIZE, 0, L"DBWIN_BUFFER_READY")),
m_dbWinDataReady(::OpenEvent(EVENT_MODIFY_STATE, 0, L"DBWIN_DATA_READY")),
m_dbWinView(m_hBuffer.get(), FILE_MAP_WRITE, 0, 0, sizeof(DbWinBuffer))
{
}
void DBWinWriter::Write(DWORD pid, const std::string& message)
{
if (!Win32::WaitForSingleObject(m_dbWinBufferReady.get(), 10000))
{
return;
}
auto pData = static_cast<DbWinBuffer*>(m_dbWinView.Ptr());
pData->processId = pid;
size_t length = std::min<size_t>(message.size(), sizeof(pData->data) - 1);
std::copy(message.data(), message.data() + length, pData->data);
pData->data[length] = '\0';
Win32::SetEvent(m_dbWinDataReady);
}
} // namespace debugviewpp
} // namespace fusion