| 1 | /*
|
|---|
| 2 | * synergy -- mouse and keyboard sharing utility
|
|---|
| 3 | * Copyright (C) 2002 Chris Schoeneman
|
|---|
| 4 | *
|
|---|
| 5 | * This package is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * found in the file COPYING that should have accompanied this file.
|
|---|
| 8 | *
|
|---|
| 9 | * This package is distributed in the hope that it will be useful,
|
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | * GNU General Public License for more details.
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | #include "CArchLogWindows.h"
|
|---|
| 16 | #include "CArchMiscWindows.h"
|
|---|
| 17 | #include <string.h>
|
|---|
| 18 |
|
|---|
| 19 | //
|
|---|
| 20 | // CArchLogWindows
|
|---|
| 21 | //
|
|---|
| 22 |
|
|---|
| 23 | CArchLogWindows::CArchLogWindows() : m_eventLog(NULL)
|
|---|
| 24 | {
|
|---|
| 25 | // do nothing
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | CArchLogWindows::~CArchLogWindows()
|
|---|
| 29 | {
|
|---|
| 30 | // do nothing
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | void
|
|---|
| 34 | CArchLogWindows::openLog(const char* name)
|
|---|
| 35 | {
|
|---|
| 36 | if (m_eventLog == NULL && !CArchMiscWindows::isWindows95Family()) {
|
|---|
| 37 | m_eventLog = RegisterEventSource(NULL, name);
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | void
|
|---|
| 42 | CArchLogWindows::closeLog()
|
|---|
| 43 | {
|
|---|
| 44 | if (m_eventLog != NULL) {
|
|---|
| 45 | DeregisterEventSource(m_eventLog);
|
|---|
| 46 | m_eventLog = NULL;
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | void
|
|---|
| 51 | CArchLogWindows::showLog(bool)
|
|---|
| 52 | {
|
|---|
| 53 | // do nothing
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | void
|
|---|
| 57 | CArchLogWindows::writeLog(ELevel level, const char* msg)
|
|---|
| 58 | {
|
|---|
| 59 | if (m_eventLog != NULL) {
|
|---|
| 60 | // convert priority
|
|---|
| 61 | WORD type;
|
|---|
| 62 | switch (level) {
|
|---|
| 63 | case kERROR:
|
|---|
| 64 | type = EVENTLOG_ERROR_TYPE;
|
|---|
| 65 | break;
|
|---|
| 66 |
|
|---|
| 67 | case kWARNING:
|
|---|
| 68 | type = EVENTLOG_WARNING_TYPE;
|
|---|
| 69 | break;
|
|---|
| 70 |
|
|---|
| 71 | default:
|
|---|
| 72 | type = EVENTLOG_INFORMATION_TYPE;
|
|---|
| 73 | break;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | // log it
|
|---|
| 77 | // FIXME -- win32 wants to use a message table to look up event
|
|---|
| 78 | // strings. log messages aren't organized that way so we'll
|
|---|
| 79 | // just dump our string into the raw data section of the event
|
|---|
| 80 | // so users can at least see the message. note that we use our
|
|---|
| 81 | // level as the event category.
|
|---|
| 82 | ReportEvent(m_eventLog, type, static_cast<WORD>(level),
|
|---|
| 83 | 0, // event ID
|
|---|
| 84 | NULL,
|
|---|
| 85 | 0,
|
|---|
| 86 | strlen(msg) + 1, // raw data size
|
|---|
| 87 | NULL,
|
|---|
| 88 | const_cast<char*>(msg));// raw data
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|