2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "arch/win32/ArchLogWindows.h"
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// ArchLogWindows
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
|
2025-04-27 19:39:23 +00:00
|
|
|
ArchLogWindows::ArchLogWindows() : m_eventLog(nullptr)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ArchLogWindows::openLog(const char *name)
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
if (m_eventLog == nullptr) {
|
|
|
|
|
m_eventLog = RegisterEventSource(nullptr, name);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ArchLogWindows::closeLog()
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
if (m_eventLog != nullptr) {
|
2024-07-02 19:07:06 +00:00
|
|
|
DeregisterEventSource(m_eventLog);
|
2025-04-27 19:39:23 +00:00
|
|
|
m_eventLog = nullptr;
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ArchLogWindows::showLog(bool)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-07-07 21:44:21 +00:00
|
|
|
void ArchLogWindows::writeLog(LogLevel level, const char *msg)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
if (m_eventLog != nullptr) {
|
2024-07-02 19:07:06 +00:00
|
|
|
// convert priority
|
|
|
|
|
WORD type;
|
|
|
|
|
switch (level) {
|
2025-07-07 21:44:21 +00:00
|
|
|
case LogLevel::Error:
|
2024-07-02 19:07:06 +00:00
|
|
|
type = EVENTLOG_ERROR_TYPE;
|
|
|
|
|
break;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-07-07 21:44:21 +00:00
|
|
|
case LogLevel::Warning:
|
2024-07-02 19:07:06 +00:00
|
|
|
type = EVENTLOG_WARNING_TYPE;
|
|
|
|
|
break;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
default:
|
|
|
|
|
type = EVENTLOG_INFORMATION_TYPE;
|
|
|
|
|
break;
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
// log it
|
|
|
|
|
// FIXME -- win32 wants to use a message table to look up event
|
|
|
|
|
// strings. log messages aren't organized that way so we'll
|
|
|
|
|
// just dump our string into the raw data section of the event
|
|
|
|
|
// so users can at least see the message. note that we use our
|
|
|
|
|
// level as the event category.
|
2024-07-16 13:36:44 +00:00
|
|
|
ReportEvent(
|
|
|
|
|
m_eventLog, type, static_cast<WORD>(level),
|
|
|
|
|
0, // event ID
|
2025-04-27 19:39:23 +00:00
|
|
|
nullptr, 0,
|
2024-07-16 13:36:44 +00:00
|
|
|
(DWORD)strlen(msg) + 1, // raw data size
|
2025-04-27 19:39:23 +00:00
|
|
|
nullptr,
|
2024-10-17 18:04:35 +00:00
|
|
|
const_cast<char *>(msg)
|
|
|
|
|
); // raw data
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|