CArchLogWindows.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2002 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "CArchLogWindows.h"
00016 #include "CArchMiscWindows.h"
00017 #include <string.h>
00018 
00019 //
00020 // CArchLogWindows
00021 //
00022 
00023 CArchLogWindows::CArchLogWindows() : m_eventLog(NULL)
00024 {
00025     // do nothing
00026 }
00027 
00028 CArchLogWindows::~CArchLogWindows()
00029 {
00030     // do nothing
00031 }
00032 
00033 void
00034 CArchLogWindows::openLog(const char* name)
00035 {
00036     if (m_eventLog == NULL && !CArchMiscWindows::isWindows95Family()) {
00037         m_eventLog = RegisterEventSource(NULL, name);
00038     }
00039 }
00040 
00041 void
00042 CArchLogWindows::closeLog()
00043 {
00044     if (m_eventLog != NULL) {
00045         DeregisterEventSource(m_eventLog);
00046         m_eventLog = NULL;
00047     }
00048 }
00049 
00050 void
00051 CArchLogWindows::showLog(bool)
00052 {
00053     // do nothing
00054 }
00055 
00056 void
00057 CArchLogWindows::writeLog(ELevel level, const char* msg)
00058 {
00059     if (m_eventLog != NULL) {
00060         // convert priority
00061         WORD type;
00062         switch (level) {
00063         case kERROR:
00064             type = EVENTLOG_ERROR_TYPE;
00065             break;
00066 
00067         case kWARNING:
00068             type = EVENTLOG_WARNING_TYPE;
00069             break;
00070 
00071         default:
00072             type = EVENTLOG_INFORMATION_TYPE;
00073             break;
00074         }
00075 
00076         // log it
00077         // FIXME -- win32 wants to use a message table to look up event
00078         // strings.  log messages aren't organized that way so we'll
00079         // just dump our string into the raw data section of the event
00080         // so users can at least see the message.  note that we use our
00081         // level as the event category.
00082         ReportEvent(m_eventLog, type, static_cast<WORD>(level),
00083                                 0,                  // event ID
00084                                 NULL,
00085                                 0,
00086                                 strlen(msg) + 1,    // raw data size
00087                                 NULL,
00088                                 const_cast<char*>(msg));// raw data
00089     }
00090 }

Generated on Fri Nov 6 00:18:44 2009 for synergy-plus by  doxygen 1.4.7