win32 changes. now including windows.h with WIN32_LEAN_AND_MEAN

to avoid including some stuff we don't want (like winsock).
This commit is contained in:
crs 2002-06-10 16:49:46 +00:00
parent 500990b153
commit 68940e58f3
12 changed files with 117 additions and 45 deletions

View File

@ -5,10 +5,12 @@
#include <assert.h> #include <assert.h>
#if defined(CONFIG_PLATFORM_WIN32) #if defined(CONFIG_PLATFORM_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif #endif
// names of priorities
static const char* g_priority[] = { static const char* g_priority[] = {
"FATAL", "FATAL",
"ERROR", "ERROR",
@ -19,17 +21,29 @@ static const char* g_priority[] = {
"DEBUG1", "DEBUG1",
"DEBUG2" "DEBUG2"
}; };
// number of priorities
static const int g_numPriority = (int)(sizeof(g_priority) / static const int g_numPriority = (int)(sizeof(g_priority) /
sizeof(g_priority[0])); sizeof(g_priority[0]));
// the default priority
#if defined(NDEBUG) #if defined(NDEBUG)
static const int g_defaultMaxPriority = 4; static const int g_defaultMaxPriority = 4;
#else #else
static const int g_defaultMaxPriority = 5; static const int g_defaultMaxPriority = 5;
#endif #endif
static const int g_maxPriorityLength = 7; // length of longest string
// length of longest string in g_priority
static const int g_maxPriorityLength = 7;
// length of suffix string (": ")
static const int g_prioritySuffixLength = 2; static const int g_prioritySuffixLength = 2;
// amount of padded required to fill in the priority prefix
static const int g_priorityPad = g_maxPriorityLength + static const int g_priorityPad = g_maxPriorityLength +
g_prioritySuffixLength; g_prioritySuffixLength;
// minimum length of a newline sequence
static const int g_newlineLength = 2; static const int g_newlineLength = 2;
// //
@ -40,7 +54,10 @@ CLog::Outputter CLog::s_outputter = NULL;
CLog::Lock CLog::s_lock = &CLog::dummyLock; CLog::Lock CLog::s_lock = &CLog::dummyLock;
int CLog::s_maxPriority = -1; int CLog::s_maxPriority = -1;
void CLog::print(const char* fmt, ...) void
CLog::print(
const char* fmt,
...)
{ {
// check if fmt begins with a priority argument // check if fmt begins with a priority argument
int priority = 4; int priority = 4;
@ -68,8 +85,12 @@ void CLog::print(const char* fmt, ...)
delete[] buffer; delete[] buffer;
} }
void CLog::printt(const char* file, int line, void
const char* fmt, ...) CLog::printt(
const char* file,
int line,
const char* fmt,
...)
{ {
// check if fmt begins with a priority argument // check if fmt begins with a priority argument
int priority = 4; int priority = 4;
@ -110,31 +131,39 @@ void CLog::printt(const char* file, int line,
delete[] buffer; delete[] buffer;
} }
void CLog::setOutputter(Outputter outputter) void
CLog::setOutputter(
Outputter outputter)
{ {
CHoldLock lock(s_lock); CHoldLock lock(s_lock);
s_outputter = outputter; s_outputter = outputter;
} }
CLog::Outputter CLog::getOutputter() CLog::Outputter
CLog::getOutputter()
{ {
CHoldLock lock(s_lock); CHoldLock lock(s_lock);
return s_outputter; return s_outputter;
} }
void CLog::setLock(Lock newLock) void
CLog::setLock(
Lock newLock)
{ {
CHoldLock lock(s_lock); CHoldLock lock(s_lock);
s_lock = (newLock == NULL) ? dummyLock : newLock; s_lock = (newLock == NULL) ? dummyLock : newLock;
} }
CLog::Lock CLog::getLock() CLog::Lock
CLog::getLock()
{ {
CHoldLock lock(s_lock); CHoldLock lock(s_lock);
return (s_lock == dummyLock) ? NULL : s_lock; return (s_lock == dummyLock) ? NULL : s_lock;
} }
bool CLog::setFilter(const char* maxPriority) bool
CLog::setFilter(
const char* maxPriority)
{ {
if (maxPriority != NULL) { if (maxPriority != NULL) {
for (int i = 0; i < g_numPriority; ++i) { for (int i = 0; i < g_numPriority; ++i) {
@ -148,24 +177,30 @@ bool CLog::setFilter(const char* maxPriority)
return true; return true;
} }
void CLog::setFilter(int maxPriority) void
CLog::setFilter(
int maxPriority)
{ {
CHoldLock lock(s_lock); CHoldLock lock(s_lock);
s_maxPriority = maxPriority; s_maxPriority = maxPriority;
} }
int CLog::getFilter() int
CLog::getFilter()
{ {
CHoldLock lock(s_lock); CHoldLock lock(s_lock);
return getMaxPriority(); return getMaxPriority();
} }
void CLog::dummyLock(bool) void
CLog::dummyLock(
bool)
{ {
// do nothing // do nothing
} }
int CLog::getMaxPriority() int
CLog::getMaxPriority()
{ {
CHoldLock lock(s_lock); CHoldLock lock(s_lock);
@ -177,7 +212,10 @@ int CLog::getMaxPriority()
return s_maxPriority; return s_maxPriority;
} }
void CLog::output(int priority, char* msg) void
CLog::output(
int priority,
char* msg)
{ {
assert(priority >= -1 && priority < g_numPriority); assert(priority >= -1 && priority < g_numPriority);
assert(msg != 0); assert(msg != 0);
@ -211,8 +249,13 @@ void CLog::output(int priority, char* msg)
} }
} }
char* CLog::vsprint(int pad, char* buffer, int len, char*
const char* fmt, va_list args) CLog::vsprint(
int pad,
char* buffer,
int len,
const char* fmt,
va_list args)
{ {
assert(len > 0); assert(len > 0);
@ -240,14 +283,17 @@ char* CLog::vsprint(int pad, char* buffer, int len,
static DWORD s_thread = 0; static DWORD s_thread = 0;
static BOOL WINAPI CLogSignalHandler(DWORD) static
BOOL WINAPI
CLogSignalHandler(DWORD)
{ {
// terminate cleanly and skip remaining handlers // terminate cleanly and skip remaining handlers
PostThreadMessage(s_thread, WM_QUIT, 0, 0); PostThreadMessage(s_thread, WM_QUIT, 0, 0);
return TRUE; return TRUE;
} }
void CLog::openConsole() void
CLog::openConsole()
{ {
static bool s_hasConsole = false; static bool s_hasConsole = false;

View File

@ -9,8 +9,9 @@ CStopwatch::CStopwatch(bool triggered) :
m_triggered(triggered), m_triggered(triggered),
m_stopped(triggered) m_stopped(triggered)
{ {
if (!triggered) if (!triggered) {
m_mark = getClock(); m_mark = getClock();
}
} }
CStopwatch::~CStopwatch() CStopwatch::~CStopwatch()
@ -18,7 +19,8 @@ CStopwatch::~CStopwatch()
// do nothing // do nothing
} }
double CStopwatch::reset() double
CStopwatch::reset()
{ {
if (m_stopped) { if (m_stopped) {
const double dt = m_mark; const double dt = m_mark;
@ -33,43 +35,52 @@ double CStopwatch::reset()
} }
} }
void CStopwatch::stop() void
CStopwatch::stop()
{ {
if (m_stopped) if (m_stopped) {
return; return;
}
// save the elapsed time // save the elapsed time
m_mark = getClock() - m_mark; m_mark = getClock() - m_mark;
m_stopped = true; m_stopped = true;
} }
void CStopwatch::start() void
CStopwatch::start()
{ {
m_triggered = false; m_triggered = false;
if (!m_stopped) if (!m_stopped) {
return; return;
}
// set the mark such that it reports the time elapsed at stop() // set the mark such that it reports the time elapsed at stop()
m_mark = getClock() - m_mark; m_mark = getClock() - m_mark;
m_stopped = false; m_stopped = false;
} }
void CStopwatch::setTrigger() void
CStopwatch::setTrigger()
{ {
stop(); stop();
m_triggered = true; m_triggered = true;
} }
double CStopwatch::getTime() double
CStopwatch::getTime()
{ {
if (m_triggered) { if (m_triggered) {
const double dt = m_mark; const double dt = m_mark;
start(); start();
return dt; return dt;
} }
if (m_stopped) else if (m_stopped) {
return m_mark; return m_mark;
}
else {
return getClock() - m_mark; return getClock() - m_mark;
}
} }
CStopwatch::operator double() CStopwatch::operator double()
@ -77,16 +88,21 @@ CStopwatch::operator double()
return getTime(); return getTime();
} }
bool CStopwatch::isStopped() const bool
CStopwatch::isStopped() const
{ {
return m_stopped; return m_stopped;
} }
double CStopwatch::getTime() const double
CStopwatch::getTime() const
{ {
if (m_stopped) if (m_stopped) {
return m_mark; return m_mark;
}
else {
return getClock() - m_mark; return getClock() - m_mark;
}
} }
CStopwatch::operator double() const CStopwatch::operator double() const
@ -98,7 +114,8 @@ CStopwatch::operator double() const
#include <sys/time.h> #include <sys/time.h>
double CStopwatch::getClock() const double
CStopwatch::getClock() const
{ {
struct timeval t; struct timeval t;
gettimeofday(&t, NULL); gettimeofday(&t, NULL);
@ -121,6 +138,7 @@ double CStopwatch::getClock() const
#define MMNOMMIO // Multimedia file I/O support #define MMNOMMIO // Multimedia file I/O support
#define MMNOMMSYSTEM // General MMSYSTEM functions #define MMNOMMSYSTEM // General MMSYSTEM functions
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
@ -150,18 +168,21 @@ CStopwatchInit::CStopwatchInit()
else { else {
// load winmm.dll and get timeGetTime // load winmm.dll and get timeGetTime
s_mmInstance = LoadLibrary("winmm"); s_mmInstance = LoadLibrary("winmm");
if (s_mmInstance) if (s_mmInstance) {
s_tgt = (PTimeGetTime)GetProcAddress(s_mmInstance, "timeGetTime"); s_tgt = (PTimeGetTime)GetProcAddress(s_mmInstance, "timeGetTime");
} }
}
} }
CStopwatchInit::~CStopwatchInit() CStopwatchInit::~CStopwatchInit()
{ {
if (s_mmInstance) if (s_mmInstance) {
FreeLibrary(reinterpret_cast<HMODULE>(s_mmInstance)); FreeLibrary(reinterpret_cast<HMODULE>(s_mmInstance));
}
} }
double CStopwatch::getClock() const double
CStopwatch::getClock() const
{ {
// get time. we try three ways, in order of descending precision // get time. we try three ways, in order of descending precision
if (s_freq != 0.0) { if (s_freq != 0.0) {

View File

@ -167,6 +167,7 @@ bool CCondVarBase::wait(
#include "CLock.h" #include "CLock.h"
#include "CThreadRep.h" #include "CThreadRep.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
// //

View File

@ -102,6 +102,7 @@ void CMutex::unlock() const
#if defined(CONFIG_PLATFORM_WIN32) #if defined(CONFIG_PLATFORM_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
void CMutex::init() void CMutex::init()

View File

@ -6,6 +6,7 @@
#if defined(CONFIG_PTHREADS) #if defined(CONFIG_PTHREADS)
#include <pthread.h> #include <pthread.h>
#elif defined(CONFIG_PLATFORM_WIN32) #elif defined(CONFIG_PLATFORM_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#endif #endif

View File

@ -125,8 +125,8 @@ UInt16 CNetwork::swaphtons(UInt16 v)
{ {
static const union { UInt16 s; UInt8 b[2]; } s_endian = { 0x1234 }; static const union { UInt16 s; UInt8 b[2]; } s_endian = { 0x1234 };
if (s_endian.b[0] == 0x34) if (s_endian.b[0] == 0x34)
return ((v & 0xff00u) >> 8) | return static_cast<UInt16>( ((v & 0xff00u) >> 8) |
((v & 0x00ffu) << 8); ((v & 0x00ffu) << 8));
else else
return v; return v;
} }

View File

@ -29,8 +29,6 @@ typedef int ssize_t;
# endif # endif
#endif #endif
// FIXME -- must handle htonl and ilk when defined as macros
class CNetwork { class CNetwork {
public: public:
#if defined(CONFIG_PLATFORM_WIN32) #if defined(CONFIG_PLATFORM_WIN32)

View File

@ -2,6 +2,7 @@
#define CMSWINDOWSCLIPBOARD_H #define CMSWINDOWSCLIPBOARD_H
#include "IClipboard.h" #include "IClipboard.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
class CMSWindowsClipboard : public IClipboard { class CMSWindowsClipboard : public IClipboard {

View File

@ -4,6 +4,7 @@
#include "CMutex.h" #include "CMutex.h"
#include "IClipboard.h" #include "IClipboard.h"
#include "BasicTypes.h" #include "BasicTypes.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
class CString; class CString;

View File

@ -4,6 +4,7 @@
#include "IPlatform.h" #include "IPlatform.h"
#include "CCondVar.h" #include "CCondVar.h"
#include "CMutex.h" #include "CMutex.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
class CWin32Platform : public IPlatform { class CWin32Platform : public IPlatform {

View File

@ -2,6 +2,7 @@
#define CSYNERGYHOOK_H #define CSYNERGYHOOK_H
#include "BasicTypes.h" #include "BasicTypes.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#if defined(CONFIG_PLATFORM_WIN32) #if defined(CONFIG_PLATFORM_WIN32)

View File

@ -42,7 +42,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "ReleaseHook" # PROP Intermediate_Dir "ReleaseHook"
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /YX /FD /c # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\base" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /FD /c # ADD CPP /nologo /MT /W4 /GX /O2 /I "..\base" /I "..\net" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /FD /c
# SUBTRACT CPP /YX # SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
@ -68,7 +68,7 @@ LINK32=link.exe
# PROP Intermediate_Dir "DebugHook" # PROP Intermediate_Dir "DebugHook"
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /YX /FD /GZ /c # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\base" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /FD /GZ /c # ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\base" /I "..\net" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /FD /GZ /c
# SUBTRACT CPP /YX # SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32