Added more debug levels and moved some annoying debug messages

to those levels.  Default log level is now DEBUG for debug
builds and INFO for release builds.
This commit is contained in:
crs 2002-04-27 18:49:03 +00:00
parent 9ac0473d5a
commit d1ca5295d1
12 changed files with 133 additions and 125 deletions

View File

@ -18,6 +18,8 @@ static const char* g_priority[] = {
"NOTE",
"INFO",
"DEBUG",
"DEBUG1",
"DEBUG2"
};
static const int g_numPriority = (int)(sizeof(g_priority) /
sizeof(g_priority[0]));
@ -108,7 +110,11 @@ void CLog::output(int priority, char* msg)
assert(msg != 0);
if (g_maxPriority == -1) {
g_maxPriority = g_numPriority - 1;
#if defined(NDEBUG)
g_maxPriority = 4;
#else
g_maxPriority = 5;
#endif
const char* priEnv = getenv("SYN_LOG_PRI");
if (priEnv != NULL) {
for (int i = 0; i < g_numPriority; ++i)

View File

@ -40,5 +40,7 @@ class CLog {
#define CLOG_NOTE CLOG_TRACE "%z\063"
#define CLOG_INFO CLOG_TRACE "%z\064"
#define CLOG_DEBUG CLOG_TRACE "%z\065"
#define CLOG_DEBUG1 CLOG_TRACE "%z\066"
#define CLOG_DEBUG2 CLOG_TRACE "%z\067"
#endif

View File

@ -58,7 +58,7 @@ void CClient::run(const CNetworkAddress& serverAddress)
m_screen->run();
// clean up
log((CLOG_DEBUG "stopping client"));
log((CLOG_NOTE "stopping client"));
thread->cancel();
thread->wait();
delete thread;
@ -109,7 +109,7 @@ void CClient::runSession(void*)
CTimerThread timer(30.0); // FIXME -- timeout in member
// create socket and attempt to connect to server
log((CLOG_DEBUG "connecting to server"));
log((CLOG_DEBUG1 "connecting to server"));
assign(socket, new CTCPSocket(), ISocket); // FIXME -- use factory
socket->connect(*m_serverAddress);
log((CLOG_INFO "connected to server"));
@ -135,19 +135,19 @@ void CClient::runSession(void*)
assign(output, new COutputPacketStream(srcOutput, own), IOutputStream);
// wait for hello from server
log((CLOG_DEBUG "wait for hello"));
SInt32 major, minor;
log((CLOG_DEBUG1 "wait for hello"));
SInt16 major, minor;
CProtocolUtil::readf(input.get(), "Synergy%2i%2i", &major, &minor);
// check versions
log((CLOG_DEBUG "got hello version %d.%d", major, minor));
log((CLOG_DEBUG1 "got hello version %d.%d", major, minor));
if (major < kMajorVersion ||
(major == kMajorVersion && minor < kMinorVersion)) {
throw XIncompatibleClient(major, minor);
}
// say hello back
log((CLOG_DEBUG "say hello version %d.%d", kMajorVersion, kMinorVersion));
log((CLOG_DEBUG1 "say hello version %d.%d", kMajorVersion, kMinorVersion));
CProtocolUtil::writef(output.get(), "Synergy%2i%2i%s",
kMajorVersion, kMinorVersion, &m_name);
@ -176,7 +176,7 @@ void CClient::runSession(void*)
// handle messages from server
for (;;) {
// wait for reply
log((CLOG_DEBUG "waiting for message"));
log((CLOG_DEBUG1 "waiting for message"));
UInt8 code[4];
UInt32 n = input->read(code, 4);
@ -193,7 +193,7 @@ void CClient::runSession(void*)
}
// parse message
log((CLOG_DEBUG "msg from server: %c%c%c%c", code[0], code[1], code[2], code[3]));
log((CLOG_DEBUG2 "msg from server: %c%c%c%c", code[0], code[1], code[2], code[3]));
if (memcmp(code, kMsgDMouseMove, 4) == 0) {
onMouseMove();
}
@ -272,13 +272,13 @@ void CClient::openSecondaryScreen()
assert(m_screen == NULL);
// open screen
log((CLOG_DEBUG "creating secondary screen"));
log((CLOG_DEBUG1 "creating secondary screen"));
#if defined(CONFIG_PLATFORM_WIN32)
m_screen = new CMSWindowsSecondaryScreen;
#elif defined(CONFIG_PLATFORM_UNIX)
m_screen = new CXWindowsSecondaryScreen;
#endif
log((CLOG_DEBUG "opening secondary screen"));
log((CLOG_DEBUG1 "opening secondary screen"));
m_screen->open(this);
}
@ -288,7 +288,7 @@ void CClient::closeSecondaryScreen()
// close the secondary screen
try {
log((CLOG_DEBUG "closing secondary screen"));
log((CLOG_DEBUG1 "closing secondary screen"));
m_screen->close();
}
catch (...) {
@ -296,7 +296,7 @@ void CClient::closeSecondaryScreen()
}
// clean up
log((CLOG_DEBUG "destroying secondary screen"));
log((CLOG_DEBUG1 "destroying secondary screen"));
delete m_screen;
m_screen = NULL;
}
@ -342,7 +342,7 @@ void CClient::onQueryInfo()
m_screen->getSize(&w, &h);
SInt32 zoneSize = m_screen->getJumpZoneSize();
log((CLOG_DEBUG "sending info size=%d,%d zone=%d", w, h, zoneSize));
log((CLOG_DEBUG1 "sending info size=%d,%d zone=%d", w, h, zoneSize));
CLock lock(&m_mutex);
CProtocolUtil::writef(m_output, kMsgDInfo, w, h, zoneSize);
}

View File

@ -57,7 +57,7 @@ void CThread::sleep(double timeout)
void CThread::exit(void* result)
{
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
log((CLOG_DEBUG "throw exit on thread %p", currentRep.operator->()));
log((CLOG_DEBUG1 "throw exit on thread %p", currentRep.operator->()));
throw XThreadExit(result);
}

View File

@ -264,16 +264,16 @@ void CThreadRep::doThreadFunc()
catch (XThreadCancel&) {
// client called cancel()
log((CLOG_DEBUG "caught cancel on thread %p", this));
log((CLOG_DEBUG1 "caught cancel on thread %p", this));
}
catch (XThreadExit& e) {
// client called exit()
result = e.m_result;
log((CLOG_DEBUG "caught exit on thread %p", this));
log((CLOG_DEBUG1 "caught exit on thread %p", this));
}
catch (...) {
log((CLOG_DEBUG "exception on thread %p", this));
log((CLOG_DEBUG1 "exception on thread %p", this));
// note -- don't catch (...) to avoid masking bugs
delete m_job;
throw;
@ -331,7 +331,7 @@ void CThreadRep::cancel()
}
// break out of system calls
log((CLOG_DEBUG "cancel thread %p", this));
log((CLOG_DEBUG1 "cancel thread %p", this));
pthread_kill(m_thread, SIGWAKEUP);
}
@ -349,7 +349,7 @@ void CThreadRep::testCancel()
}
// start cancel
log((CLOG_DEBUG "throw cancel on thread %p", this));
log((CLOG_DEBUG1 "throw cancel on thread %p", this));
throw XThreadCancel();
}
@ -459,7 +459,7 @@ void CThreadRep::sleep(double timeout)
void CThreadRep::cancel()
{
log((CLOG_DEBUG "cancel thread %p", this));
log((CLOG_DEBUG1 "cancel thread %p", this));
SetEvent(m_cancel);
}
@ -482,7 +482,7 @@ void CThreadRep::testCancel()
}
// start cancel
log((CLOG_DEBUG "throw cancel on thread %p", this));
log((CLOG_DEBUG1 "throw cancel on thread %p", this));
throw XThreadCancel();
}

View File

@ -18,19 +18,19 @@ CTimerThread::CTimerThread(double timeout) : m_timeout(timeout)
CTimerThread::~CTimerThread()
{
log((CLOG_DEBUG "cancelling timeout"));
log((CLOG_DEBUG1 "cancelling timeout"));
m_timingThread->cancel();
m_timingThread->wait();
log((CLOG_DEBUG "cancelled timeout"));
log((CLOG_DEBUG1 "cancelled timeout"));
delete m_timingThread;
delete m_callingThread;
}
void CTimerThread::timer(void*)
{
log((CLOG_DEBUG "timeout in %f seconds", m_timeout));
log((CLOG_DEBUG1 "timeout in %f seconds", m_timeout));
CThread::sleep(m_timeout);
log((CLOG_DEBUG "timeout"));
log((CLOG_DEBUG1 "timeout"));
m_callingThread->cancel();
}

View File

@ -71,7 +71,7 @@ void CNetwork::init()
// try winsock 2
HMODULE module = (HMODULE)::LoadLibrary("ws2_32.dll");
if (module == NULL) {
log((CLOG_DEBUG "ws2_32.dll not found"));
log((CLOG_NOTE "ws2_32.dll not found"));
}
else {
try {
@ -79,14 +79,14 @@ void CNetwork::init()
return;
}
catch (XNetwork& e) {
log((CLOG_DEBUG "ws2_32.dll error: %s", e.what()));
log((CLOG_NOTE "ws2_32.dll error: %s", e.what()));
}
}
// try winsock 1
module = (HMODULE)::LoadLibrary("wsock32.dll");
if (module == NULL) {
log((CLOG_DEBUG "wsock32.dll not found"));
log((CLOG_NOTE "wsock32.dll not found"));
}
else {
try {
@ -94,7 +94,7 @@ void CNetwork::init()
return;
}
catch (XNetwork& e) {
log((CLOG_DEBUG "wsock32.dll error: %s", e.what()));
log((CLOG_NOTE "wsock32.dll error: %s", e.what()));
}
}

View File

@ -73,7 +73,7 @@ void CServer::run()
m_primary->run();
// clean up
log((CLOG_DEBUG "stopping server"));
log((CLOG_NOTE "stopping server"));
cleanupThreads();
closePrimaryScreen();
}
@ -248,7 +248,7 @@ bool CServer::onCommandKey(KeyID /*id*/,
void CServer::onKeyDown(KeyID id, KeyModifierMask mask)
{
log((CLOG_DEBUG "onKeyDown id=%d mask=0x%04x", id, mask));
log((CLOG_DEBUG1 "onKeyDown id=%d mask=0x%04x", id, mask));
assert(m_active != NULL);
// handle command keys
@ -264,7 +264,7 @@ void CServer::onKeyDown(KeyID id, KeyModifierMask mask)
void CServer::onKeyUp(KeyID id, KeyModifierMask mask)
{
log((CLOG_DEBUG "onKeyUp id=%d mask=0x%04x", id, mask));
log((CLOG_DEBUG1 "onKeyUp id=%d mask=0x%04x", id, mask));
assert(m_active != NULL);
// handle command keys
@ -281,7 +281,7 @@ void CServer::onKeyUp(KeyID id, KeyModifierMask mask)
void CServer::onKeyRepeat(
KeyID id, KeyModifierMask mask, SInt32 count)
{
log((CLOG_DEBUG "onKeyRepeat id=%d mask=0x%04x count=%d", id, mask, count));
log((CLOG_DEBUG1 "onKeyRepeat id=%d mask=0x%04x count=%d", id, mask, count));
assert(m_active != NULL);
// handle command keys
@ -298,7 +298,7 @@ void CServer::onKeyRepeat(
void CServer::onMouseDown(ButtonID id)
{
log((CLOG_DEBUG "onMouseDown id=%d", id));
log((CLOG_DEBUG1 "onMouseDown id=%d", id));
assert(m_active != NULL);
// relay
@ -309,7 +309,7 @@ void CServer::onMouseDown(ButtonID id)
void CServer::onMouseUp(ButtonID id)
{
log((CLOG_DEBUG "onMouseUp id=%d", id));
log((CLOG_DEBUG1 "onMouseUp id=%d", id));
assert(m_active != NULL);
// relay
@ -320,7 +320,7 @@ void CServer::onMouseUp(ButtonID id)
bool CServer::onMouseMovePrimary(SInt32 x, SInt32 y)
{
// log((CLOG_DEBUG "onMouseMovePrimary %d,%d", x, y));
log((CLOG_DEBUG2 "onMouseMovePrimary %d,%d", x, y));
// mouse move on primary (server's) screen
assert(m_active != NULL);
@ -336,22 +336,22 @@ bool CServer::onMouseMovePrimary(SInt32 x, SInt32 y)
if (x < m_active->m_zoneSize) {
x -= m_active->m_zoneSize;
dir = CScreenMap::kLeft;
log((CLOG_DEBUG "switch to left"));
log((CLOG_DEBUG1 "switch to left"));
}
else if (x >= m_active->m_width - m_active->m_zoneSize) {
x += m_active->m_zoneSize;
dir = CScreenMap::kRight;
log((CLOG_DEBUG "switch to right"));
log((CLOG_DEBUG1 "switch to right"));
}
else if (y < m_active->m_zoneSize) {
y -= m_active->m_zoneSize;
dir = CScreenMap::kTop;
log((CLOG_DEBUG "switch to top"));
log((CLOG_DEBUG1 "switch to top"));
}
else if (y >= m_active->m_height - m_active->m_zoneSize) {
y += m_active->m_zoneSize;
dir = CScreenMap::kBottom;
log((CLOG_DEBUG "switch to bottom"));
log((CLOG_DEBUG1 "switch to bottom"));
}
else {
// still on local screen
@ -376,7 +376,7 @@ bool CServer::onMouseMovePrimary(SInt32 x, SInt32 y)
void CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
{
log((CLOG_DEBUG "onMouseMoveSecondary %+d,%+d", dx, dy));
log((CLOG_DEBUG1 "onMouseMoveSecondary %+d,%+d", dx, dy));
// mouse move on secondary (client's) screen
assert(m_active != NULL);
@ -409,7 +409,7 @@ void CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
// get neighbor if we should switch
if (newScreen == NULL) {
log((CLOG_DEBUG "leave \"%s\" on %s", m_active->m_name.c_str(), CScreenMap::dirName(dir)));
log((CLOG_DEBUG1 "leave \"%s\" on %s", m_active->m_name.c_str(), CScreenMap::dirName(dir)));
SInt32 x = m_x, y = m_y;
newScreen = getNeighbor(m_active, dir, x, y);
@ -421,7 +421,7 @@ void CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
m_y = y;
}
else {
log((CLOG_DEBUG "no neighbor; clamping"));
log((CLOG_DEBUG1 "no neighbor; clamping"));
if (m_x < 0)
m_x = 0;
else if (m_x > m_active->m_width - 1)
@ -435,7 +435,7 @@ void CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
}
else {
// clamp to edge when locked
log((CLOG_DEBUG "clamp to \"%s\"", m_active->m_name.c_str()));
log((CLOG_DEBUG1 "clamp to \"%s\"", m_active->m_name.c_str()));
if (m_x < 0)
m_x = 0;
else if (m_x > m_active->m_width - 1)
@ -450,7 +450,7 @@ void CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
if (newScreen == NULL || newScreen == m_active) {
// do nothing if mouse didn't move
if (m_x != xOld || m_y != yOld) {
log((CLOG_DEBUG "move on %s to %d,%d", m_active->m_name.c_str(), m_x, m_y));
log((CLOG_DEBUG1 "move on %s to %d,%d", m_active->m_name.c_str(), m_x, m_y));
m_active->m_protocol->sendMouseMove(m_x, m_y);
}
}
@ -463,7 +463,7 @@ void CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
void CServer::onMouseWheel(SInt32 delta)
{
log((CLOG_DEBUG "onMouseWheel %+d", delta));
log((CLOG_DEBUG1 "onMouseWheel %+d", delta));
assert(m_active != NULL);
// relay
@ -547,14 +547,14 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
CString srcName = src->m_name;
assert(!srcName.empty());
log((CLOG_DEBUG "find neighbor on %s of \"%s\"", CScreenMap::dirName(dir), srcName.c_str()));
log((CLOG_DEBUG2 "find neighbor on %s of \"%s\"", CScreenMap::dirName(dir), srcName.c_str()));
for (;;) {
// look up name of neighbor
const CString dstName(m_screenMap.getNeighbor(srcName, dir));
// if nothing in that direction then return NULL
if (dstName.empty()) {
log((CLOG_DEBUG "no neighbor on %s of \"%s\"", CScreenMap::dirName(dir), srcName.c_str()));
log((CLOG_DEBUG2 "no neighbor on %s of \"%s\"", CScreenMap::dirName(dir), srcName.c_str()));
return NULL;
}
@ -563,11 +563,11 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
// screen.
CScreenList::const_iterator index = m_screens.find(dstName);
if (index != m_screens.end()) {
log((CLOG_DEBUG "\"%s\" is on %s of \"%s\"", dstName.c_str(), CScreenMap::dirName(dir), srcName.c_str()));
log((CLOG_DEBUG2 "\"%s\" is on %s of \"%s\"", dstName.c_str(), CScreenMap::dirName(dir), srcName.c_str()));
return index->second;
}
log((CLOG_DEBUG "ignored \"%s\" on %s of \"%s\"", dstName.c_str(), CScreenMap::dirName(dir), srcName.c_str()));
log((CLOG_DEBUG2 "ignored \"%s\" on %s of \"%s\"", dstName.c_str(), CScreenMap::dirName(dir), srcName.c_str()));
srcName = dstName;
}
}
@ -596,7 +596,7 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
if (x >= 0) {
break;
}
log((CLOG_DEBUG "skipping over screen %s", dst->m_name.c_str()));
log((CLOG_DEBUG2 "skipping over screen %s", dst->m_name.c_str()));
dst = getNeighbor(lastGoodScreen, srcSide);
}
break;
@ -610,7 +610,7 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
if (x < w) {
break;
}
log((CLOG_DEBUG "skipping over screen %s", dst->m_name.c_str()));
log((CLOG_DEBUG2 "skipping over screen %s", dst->m_name.c_str()));
dst = getNeighbor(lastGoodScreen, srcSide);
}
break;
@ -624,7 +624,7 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
if (y >= 0) {
break;
}
log((CLOG_DEBUG "skipping over screen %s", dst->m_name.c_str()));
log((CLOG_DEBUG2 "skipping over screen %s", dst->m_name.c_str()));
dst = getNeighbor(lastGoodScreen, srcSide);
}
break;
@ -638,7 +638,7 @@ CServer::CScreenInfo* CServer::getNeighbor(CScreenInfo* src,
if (y < h) {
break;
}
log((CLOG_DEBUG "skipping over screen %s", dst->m_name.c_str()));
log((CLOG_DEBUG2 "skipping over screen %s", dst->m_name.c_str()));
dst = getNeighbor(lastGoodScreen, srcSide);
}
break;
@ -725,7 +725,7 @@ void CServer::mapPosition(CScreenInfo* src,
#include "CTCPListenSocket.h"
void CServer::acceptClients(void*)
{
log((CLOG_DEBUG "starting to wait for clients"));
log((CLOG_DEBUG1 "starting to wait for clients"));
// add this thread to the list of threads to cancel. remove from
// list in d'tor.
@ -743,25 +743,25 @@ void CServer::acceptClients(void*)
CNetworkAddress addr(50001 /* FIXME -- m_port */);
for (;;) {
try {
log((CLOG_DEBUG "binding listen socket"));
log((CLOG_DEBUG1 "binding listen socket"));
listen->bind(addr);
break;
}
catch (XSocketAddressInUse&) {
// give up if we've waited too long
if (timer.getTime() >= m_bindTimeout) {
log((CLOG_DEBUG "waited too long to bind, giving up"));
log((CLOG_DEBUG1 "waited too long to bind, giving up"));
throw;
}
// wait a bit before retrying
log((CLOG_DEBUG "bind failed; waiting to retry"));
log((CLOG_DEBUG1 "bind failed; waiting to retry"));
CThread::sleep(5.0);
}
}
// accept connections and begin processing them
log((CLOG_DEBUG "waiting for client connections"));
log((CLOG_DEBUG1 "waiting for client connections"));
for (;;) {
// accept connection
CThread::testCancel();
@ -782,7 +782,7 @@ void CServer::acceptClients(void*)
void CServer::handshakeClient(void* vsocket)
{
log((CLOG_DEBUG "negotiating with new client"));
log((CLOG_DEBUG1 "negotiating with new client"));
// get the socket pointer from the argument
assert(vsocket != NULL);
@ -826,22 +826,22 @@ void CServer::handshakeClient(void* vsocket)
static const UInt32 maxHelloLen = 1024;
// say hello
log((CLOG_DEBUG "saying hello"));
log((CLOG_DEBUG1 "saying hello"));
CProtocolUtil::writef(output.get(), "Synergy%2i%2i",
kMajorVersion, kMinorVersion);
output->flush();
// wait for the reply
log((CLOG_DEBUG "waiting for hello reply"));
log((CLOG_DEBUG1 "waiting for hello reply"));
UInt32 n = input->getSize();
if (n > maxHelloLen) {
throw XBadClient();
}
// get and parse the reply to hello
SInt32 major, minor;
SInt16 major, minor;
try {
log((CLOG_DEBUG "parsing hello reply"));
log((CLOG_DEBUG1 "parsing hello reply"));
CProtocolUtil::readf(input.get(), "Synergy%2i%2i%s",
&major, &minor, &name);
}
@ -853,7 +853,7 @@ void CServer::handshakeClient(void* vsocket)
}
// create a protocol interpreter for the version
log((CLOG_DEBUG "creating interpreter for client %s version %d.%d", name.c_str(), major, minor));
log((CLOG_DEBUG1 "creating interpreter for client %s version %d.%d", name.c_str(), major, minor));
assign(protocol, CServerProtocol::create(major, minor,
this, name, input.get(), output.get()),
IServerProtocol);
@ -863,7 +863,7 @@ void CServer::handshakeClient(void* vsocket)
name, protocol.get()), CConnectionNote);
// ask and wait for the client's info
log((CLOG_DEBUG "waiting for info for client %s", name.c_str()));
log((CLOG_DEBUG1 "waiting for info for client %s", name.c_str()));
protocol->queryInfo();
}
@ -905,13 +905,13 @@ void CServer::openPrimaryScreen()
assert(m_primary == NULL);
// open screen
log((CLOG_DEBUG "creating primary screen"));
log((CLOG_DEBUG1 "creating primary screen"));
#if defined(CONFIG_PLATFORM_WIN32)
m_primary = new CMSWindowsPrimaryScreen;
#elif defined(CONFIG_PLATFORM_UNIX)
m_primary = new CXWindowsPrimaryScreen;
#endif
log((CLOG_DEBUG "opening primary screen"));
log((CLOG_DEBUG1 "opening primary screen"));
m_primary->open(this);
// add connection
@ -944,7 +944,7 @@ void CServer::closePrimaryScreen()
// close the primary screen
try {
log((CLOG_DEBUG "closing primary screen"));
log((CLOG_DEBUG1 "closing primary screen"));
m_primary->close();
}
catch (...) {
@ -952,7 +952,7 @@ void CServer::closePrimaryScreen()
}
// clean up
log((CLOG_DEBUG "destroying primary screen"));
log((CLOG_DEBUG1 "destroying primary screen"));
delete m_primary;
m_primary = NULL;
}
@ -979,7 +979,7 @@ void CServer::removeCleanupThread(const CThread& thread)
void CServer::cleanupThreads()
{
log((CLOG_DEBUG "cleaning up threads"));
log((CLOG_DEBUG1 "cleaning up threads"));
m_mutex.lock();
while (m_cleanupList.begin() != m_cleanupList.end()) {
// get the next thread and cancel it
@ -995,7 +995,7 @@ void CServer::cleanupThreads()
// FIXME -- delete remaining threads from list
m_mutex.unlock();
log((CLOG_DEBUG "cleaned up threads"));
log((CLOG_DEBUG1 "cleaned up threads"));
}
CServer::CScreenInfo* CServer::addConnection(

View File

@ -46,7 +46,7 @@ void CServerProtocol1_0::run()
}
// parse message
log((CLOG_DEBUG "msg from \"%s\": %c%c%c%c", getClient().c_str(), code[0], code[1], code[2], code[3]));
log((CLOG_DEBUG2 "msg from \"%s\": %c%c%c%c", getClient().c_str(), code[0], code[1], code[2], code[3]));
if (memcmp(code, kMsgDInfo, 4) == 0) {
recvInfo();
}
@ -68,7 +68,7 @@ void CServerProtocol1_0::run()
void CServerProtocol1_0::queryInfo()
{
log((CLOG_INFO "querying client \"%s\" info", getClient().c_str()));
log((CLOG_DEBUG1 "querying client \"%s\" info", getClient().c_str()));
// send request
CProtocolUtil::writef(getOutputStream(), kMsgQInfo);
@ -86,95 +86,95 @@ void CServerProtocol1_0::queryInfo()
void CServerProtocol1_0::sendClose()
{
log((CLOG_INFO "send close to \"%s\"", getClient().c_str()));
log((CLOG_DEBUG1 "send close to \"%s\"", getClient().c_str()));
CProtocolUtil::writef(getOutputStream(), kMsgCClose);
}
void CServerProtocol1_0::sendEnter(
SInt32 xAbs, SInt32 yAbs)
{
log((CLOG_INFO "send enter to \"%s\", %d,%d", getClient().c_str(), xAbs, yAbs));
log((CLOG_DEBUG1 "send enter to \"%s\", %d,%d", getClient().c_str(), xAbs, yAbs));
CProtocolUtil::writef(getOutputStream(), kMsgCEnter, xAbs, yAbs);
}
void CServerProtocol1_0::sendLeave()
{
log((CLOG_INFO "send leave to \"%s\"", getClient().c_str()));
log((CLOG_DEBUG1 "send leave to \"%s\"", getClient().c_str()));
CProtocolUtil::writef(getOutputStream(), kMsgCLeave);
}
void CServerProtocol1_0::sendClipboard(
ClipboardID id, const CString& data)
{
log((CLOG_INFO "send clipboard %d to \"%s\" size=%d", id, getClient().c_str(), data.size()));
log((CLOG_DEBUG "send clipboard %d to \"%s\" size=%d", id, getClient().c_str(), data.size()));
CProtocolUtil::writef(getOutputStream(), kMsgDClipboard, id, 0, &data);
}
void CServerProtocol1_0::sendGrabClipboard(ClipboardID id)
{
log((CLOG_INFO "send grab clipboard %d to \"%s\"", id, getClient().c_str()));
log((CLOG_DEBUG "send grab clipboard %d to \"%s\"", id, getClient().c_str()));
CProtocolUtil::writef(getOutputStream(), kMsgCClipboard, id);
}
void CServerProtocol1_0::sendQueryClipboard(
ClipboardID id, UInt32 seqNum)
{
log((CLOG_INFO "query clipboard %d to \"%s\"", id, getClient().c_str()));
log((CLOG_DEBUG "query clipboard %d to \"%s\"", id, getClient().c_str()));
CProtocolUtil::writef(getOutputStream(), kMsgQClipboard, id, seqNum);
}
void CServerProtocol1_0::sendScreenSaver(bool on)
{
log((CLOG_INFO "send screen saver to \"%s\"", getClient().c_str()));
log((CLOG_DEBUG1 "send screen saver to \"%s\"", getClient().c_str()));
CProtocolUtil::writef(getOutputStream(), kMsgCScreenSaver, on ? 1 : 0);
}
void CServerProtocol1_0::sendKeyDown(
KeyID key, KeyModifierMask mask)
{
log((CLOG_INFO "send key down to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
log((CLOG_DEBUG1 "send key down to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
CProtocolUtil::writef(getOutputStream(), kMsgDKeyDown, key, mask);
}
void CServerProtocol1_0::sendKeyRepeat(
KeyID key, KeyModifierMask mask, SInt32 count)
{
log((CLOG_INFO "send key repeat to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
log((CLOG_DEBUG1 "send key repeat to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
CProtocolUtil::writef(getOutputStream(), kMsgDKeyRepeat, key, mask, count);
}
void CServerProtocol1_0::sendKeyUp(
KeyID key, KeyModifierMask mask)
{
log((CLOG_INFO "send key up to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
log((CLOG_DEBUG1 "send key up to \"%s\" id=%d, mask=0x%04x", getClient().c_str(), key, mask));
CProtocolUtil::writef(getOutputStream(), kMsgDKeyUp, key, mask);
}
void CServerProtocol1_0::sendMouseDown(
ButtonID button)
{
log((CLOG_INFO "send mouse down to \"%s\" id=%d", getClient().c_str(), button));
log((CLOG_DEBUG1 "send mouse down to \"%s\" id=%d", getClient().c_str(), button));
CProtocolUtil::writef(getOutputStream(), kMsgDMouseDown, button);
}
void CServerProtocol1_0::sendMouseUp(
ButtonID button)
{
log((CLOG_INFO "send mouse up to \"%s\" id=%d", getClient().c_str(), button));
log((CLOG_DEBUG1 "send mouse up to \"%s\" id=%d", getClient().c_str(), button));
CProtocolUtil::writef(getOutputStream(), kMsgDMouseUp, button);
}
void CServerProtocol1_0::sendMouseMove(
SInt32 xAbs, SInt32 yAbs)
{
log((CLOG_INFO "send mouse move to \"%s\" %d,%d", getClient().c_str(), xAbs, yAbs));
log((CLOG_DEBUG2 "send mouse move to \"%s\" %d,%d", getClient().c_str(), xAbs, yAbs));
CProtocolUtil::writef(getOutputStream(), kMsgDMouseMove, xAbs, yAbs);
}
void CServerProtocol1_0::sendMouseWheel(
SInt32 delta)
{
log((CLOG_INFO "send mouse wheel to \"%s\" %+d", getClient().c_str(), delta));
log((CLOG_DEBUG1 "send mouse wheel to \"%s\" %+d", getClient().c_str(), delta));
CProtocolUtil::writef(getOutputStream(), kMsgDMouseWheel, delta);
}
@ -183,7 +183,7 @@ void CServerProtocol1_0::recvInfo()
// parse the message
SInt16 w, h, zoneInfo;
CProtocolUtil::readf(getInputStream(), kMsgDInfo + 4, &w, &h, &zoneInfo);
log((CLOG_INFO "received client \"%s\" info size=%dx%d, zone=%d", getClient().c_str(), w, h, zoneInfo));
log((CLOG_DEBUG "received client \"%s\" info size=%dx%d, zone=%d", getClient().c_str(), w, h, zoneInfo));
// validate
if (w == 0 || h == 0) {
@ -200,7 +200,7 @@ void CServerProtocol1_0::recvClipboard()
UInt32 seqNum;
CString data;
CProtocolUtil::readf(getInputStream(), kMsgDClipboard + 4, &id, &seqNum, &data);
log((CLOG_INFO "received client \"%s\" clipboard %d seqnum=%d, size=%d", getClient().c_str(), id, seqNum, data.size()));
log((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getClient().c_str(), id, seqNum, data.size()));
getServer()->setClipboard(id, seqNum, data);
}
@ -208,6 +208,6 @@ void CServerProtocol1_0::recvGrabClipboard()
{
ClipboardID id;
CProtocolUtil::readf(getInputStream(), kMsgCClipboard + 4, &id);
log((CLOG_INFO "received client \"%s\" grabbed clipboard %d", getClient().c_str(), id));
log((CLOG_DEBUG "received client \"%s\" grabbed clipboard %d", getClient().c_str(), id));
getServer()->grabClipboard(id, getClient());
}

View File

@ -51,7 +51,7 @@ void CXWindowsPrimaryScreen::run()
}
case KeyPress: {
log((CLOG_DEBUG "event: KeyPress code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
log((CLOG_DEBUG1 "event: KeyPress code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
const KeyID key = mapKey(&xevent.xkey);
if (key != kKeyNone) {
@ -65,7 +65,7 @@ void CXWindowsPrimaryScreen::run()
// FIXME -- simulate key repeat. X sends press/release for
// repeat. must detect auto repeat and use kKeyRepeat.
case KeyRelease: {
log((CLOG_DEBUG "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
log((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
const KeyID key = mapKey(&xevent.xkey);
if (key != kKeyNone) {
@ -77,7 +77,7 @@ void CXWindowsPrimaryScreen::run()
}
case ButtonPress: {
log((CLOG_DEBUG "event: ButtonPress button=%d", xevent.xbutton.button));
log((CLOG_DEBUG1 "event: ButtonPress button=%d", xevent.xbutton.button));
const ButtonID button = mapButton(xevent.xbutton.button);
if (button != kButtonNone) {
m_server->onMouseDown(button);
@ -86,7 +86,7 @@ void CXWindowsPrimaryScreen::run()
}
case ButtonRelease: {
log((CLOG_DEBUG "event: ButtonRelease button=%d", xevent.xbutton.button));
log((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button));
const ButtonID button = mapButton(xevent.xbutton.button);
if (button != kButtonNone) {
m_server->onMouseUp(button);
@ -95,7 +95,7 @@ void CXWindowsPrimaryScreen::run()
}
case MotionNotify: {
// log((CLOG_DEBUG "event: MotionNotify %d,%d", xevent.xmotion.x_root, xevent.xmotion.y_root));
log((CLOG_DEBUG2 "event: MotionNotify %d,%d", xevent.xmotion.x_root, xevent.xmotion.y_root));
SInt32 x, y;
if (!m_active) {
x = xevent.xmotion.x_root;
@ -270,11 +270,11 @@ void CXWindowsPrimaryScreen::leave()
m_window, None, CurrentTime);
assert(result != GrabNotViewable);
if (result != GrabSuccess) {
log((CLOG_DEBUG "waiting to grab pointer"));
log((CLOG_DEBUG2 "waiting to grab pointer"));
CThread::sleep(0.1);
}
} while (result != GrabSuccess);
log((CLOG_DEBUG "grabbed pointer"));
log((CLOG_DEBUG2 "grabbed pointer"));
// now the keyboard
result = XGrabKeyboard(display, m_window, True,
@ -283,11 +283,11 @@ void CXWindowsPrimaryScreen::leave()
if (result != GrabSuccess) {
// back off to avoid grab deadlock
XUngrabPointer(display, CurrentTime);
log((CLOG_DEBUG "ungrabbed pointer, waiting to grab keyboard"));
log((CLOG_DEBUG2 "ungrabbed pointer, waiting to grab keyboard"));
CThread::sleep(0.1);
}
} while (result != GrabSuccess);
log((CLOG_DEBUG "grabbed keyboard"));
log((CLOG_DEBUG1 "grabbed pointer and keyboard"));
// move the mouse to the center of grab window
SInt32 w, h;
@ -313,7 +313,7 @@ void CXWindowsPrimaryScreen::warpCursorNoLock(
// warp the mouse
XWarpPointer(display, None, getRoot(), 0, 0, 0, 0, x, y);
XSync(display, False);
log((CLOG_DEBUG "warped to %d,%d", x, y));
log((CLOG_DEBUG1 "warped to %d,%d", x, y));
// discard mouse events since we just added one we don't want
XEvent xevent;

View File

@ -15,7 +15,7 @@ void CProtocolUtil::writef(IOutputStream* stream,
{
assert(stream != NULL);
assert(fmt != NULL);
log((CLOG_DEBUG "writef(%s)", fmt));
log((CLOG_DEBUG2 "writef(%s)", fmt));
va_list args;
@ -39,7 +39,7 @@ void CProtocolUtil::writef(IOutputStream* stream,
UInt8* scan = buffer;
while (count > 0) {
const UInt32 n = stream->write(scan, count);
log((CLOG_DEBUG "wrote %d of %d bytes", n, count));
log((CLOG_DEBUG2 "wrote %d of %d bytes", n, count));
count -= n;
scan += n;
}
@ -52,7 +52,7 @@ void CProtocolUtil::readf(IInputStream* stream,
{
assert(stream != NULL);
assert(fmt != NULL);
log((CLOG_DEBUG "readf(%s)", fmt));
log((CLOG_DEBUG2 "readf(%s)", fmt));
va_list args;
va_start(args, fmt);
@ -78,7 +78,7 @@ void CProtocolUtil::readf(IInputStream* stream,
case 1:
// 1 byte integer
*reinterpret_cast<UInt8*>(v) = buffer[0];
log((CLOG_DEBUG "readf: read %d byte integer: %d (0x%x)", len, *reinterpret_cast<UInt8*>(v), *reinterpret_cast<UInt8*>(v)));
log((CLOG_DEBUG2 "readf: read %d byte integer: %d (0x%x)", len, *reinterpret_cast<UInt8*>(v), *reinterpret_cast<UInt8*>(v)));
break;
case 2:
@ -86,7 +86,7 @@ void CProtocolUtil::readf(IInputStream* stream,
*reinterpret_cast<UInt16*>(v) =
(static_cast<UInt16>(buffer[0]) << 8) |
static_cast<UInt16>(buffer[1]);
log((CLOG_DEBUG "readf: read %d byte integer: %d (0x%x)", len, *reinterpret_cast<UInt16*>(v), *reinterpret_cast<UInt16*>(v)));
log((CLOG_DEBUG2 "readf: read %d byte integer: %d (0x%x)", len, *reinterpret_cast<UInt16*>(v), *reinterpret_cast<UInt16*>(v)));
break;
case 4:
@ -96,7 +96,7 @@ void CProtocolUtil::readf(IInputStream* stream,
(static_cast<UInt32>(buffer[1]) << 16) |
(static_cast<UInt32>(buffer[2]) << 8) |
static_cast<UInt32>(buffer[3]);
log((CLOG_DEBUG "readf: read %d byte integer: %d (0x%x)", len, *reinterpret_cast<UInt32*>(v), *reinterpret_cast<UInt32*>(v)));
log((CLOG_DEBUG2 "readf: read %d byte integer: %d (0x%x)", len, *reinterpret_cast<UInt32*>(v), *reinterpret_cast<UInt32*>(v)));
break;
}
break;
@ -135,7 +135,7 @@ void CProtocolUtil::readf(IInputStream* stream,
}
throw;
}
log((CLOG_DEBUG "readf: read %d byte string: %.*s", len, len, sBuffer));
log((CLOG_DEBUG2 "readf: read %d byte string: %.*s", len, len, sBuffer));
// save the data
CString* dst = va_arg(args, CString*);
@ -166,7 +166,7 @@ void CProtocolUtil::readf(IInputStream* stream,
// verify match
if (buffer[0] != *fmt) {
log((CLOG_DEBUG "readf: format mismatch: %c vs %c", *fmt, buffer[0]));
log((CLOG_DEBUG2 "readf: format mismatch: %c vs %c", *fmt, buffer[0]));
throw XIOReadMismatch();
}
@ -351,7 +351,7 @@ void CProtocolUtil::read(IInputStream* stream,
// bail if stream has hungup
if (n == 0) {
log((CLOG_DEBUG "unexpected disconnect in readf(), %d bytes left", count));
log((CLOG_DEBUG2 "unexpected disconnect in readf(), %d bytes left", count));
throw XIOEndOfStream();
}

View File

@ -274,11 +274,11 @@ void CXWindowsScreen::getDisplayClipboard(
log((CLOG_INFO "getting selection with %d targets", numTargets));
for (SInt32 i = 0; i < numTargets; ++i) {
Atom format = targetAtoms[i];
log((CLOG_DEBUG " source target %d", format));
log((CLOG_DEBUG1 " source target %d", format));
// skip already handled targets
if (targets.count(format) > 0) {
log((CLOG_DEBUG " skipping handled target %d", format));
log((CLOG_DEBUG1 " skipping handled target %d", format));
continue;
}
@ -291,29 +291,29 @@ void CXWindowsScreen::getDisplayClipboard(
// if we can use the format and we haven't already retrieved
// it then get it
if (expectedFormat == IClipboard::kNumFormats) {
log((CLOG_DEBUG " no format for target", format));
log((CLOG_DEBUG1 " no format for target", format));
continue;
}
if (clipboardFormats.count(expectedFormat) > 0) {
log((CLOG_DEBUG " skipping handled format %d", expectedFormat));
log((CLOG_DEBUG1 " skipping handled format %d", expectedFormat));
continue;
}
CString data;
if (!getDisplayClipboard(selection, format,
requestor, timestamp, &format, &data)) {
log((CLOG_DEBUG " no data for target", format));
log((CLOG_DEBUG1 " no data for target", format));
continue;
}
// use the actual format, not the expected
IClipboard::EFormat actualFormat = getFormat(format);
if (actualFormat == IClipboard::kNumFormats) {
log((CLOG_DEBUG " no format for target", format));
log((CLOG_DEBUG1 " no format for target", format));
continue;
}
if (clipboardFormats.count(actualFormat) > 0) {
log((CLOG_DEBUG " skipping handled format %d", actualFormat));
log((CLOG_DEBUG1 " skipping handled format %d", actualFormat));
continue;
}
@ -326,7 +326,7 @@ void CXWindowsScreen::getDisplayClipboard(
else {
// non-ICCCM conforming selection owner. try TEXT format.
// FIXME
log((CLOG_DEBUG "selection doesn't support TARGETS, format is %d", format));
log((CLOG_DEBUG1 "selection doesn't support TARGETS, format is %d", format));
}
// done with clipboard
@ -386,7 +386,7 @@ bool CXWindowsScreen::getDisplayClipboard(
// handle INCR type specially. it means we'll be receiving the data
// piecemeal so we just loop until we've collected all the data.
if (*outputType == m_atomINCR) {
log((CLOG_DEBUG "selection data for format %d is incremental", type));
log((CLOG_DEBUG1 "selection data for format %d is incremental", type));
// the data is a lower bound on the amount of data to be
// transferred. use it as a hint to size our buffer.
UInt32 size;
@ -726,7 +726,7 @@ bool CXWindowsScreen::sendClipboardData(
}
if (data.size() > kMaxRequestSize) {
log((CLOG_DEBUG "handling clipboard request for %d as INCR", target));
log((CLOG_DEBUG1 "handling clipboard request for %d as INCR", target));
// get the appropriate list, creating it if necessary
CRequestList* list = m_clipboards[id].m_requests[requestor];
@ -763,7 +763,7 @@ bool CXWindowsScreen::sendClipboardData(
1);
}
else {
log((CLOG_DEBUG "handling clipboard request for %d", target));
log((CLOG_DEBUG1 "handling clipboard request for %d", target));
// FIXME -- handle Alloc errors (by returning false)
XChangeProperty(m_display, requestor, property,
@ -783,7 +783,7 @@ bool CXWindowsScreen::sendClipboardMultiple(
Window requestor,
Atom property, Time time)
{
log((CLOG_DEBUG "handling clipboard request for MULTIPLE"));
log((CLOG_DEBUG1 "handling clipboard request for MULTIPLE"));
// get the list of requested formats
Atom type;
@ -850,7 +850,7 @@ bool CXWindowsScreen::sendClipboardTargets(
Window requestor,
Atom property, Time /*time*/)
{
log((CLOG_DEBUG "handling request for TARGETS"));
log((CLOG_DEBUG1 "handling request for TARGETS"));
// count the number of targets, plus TARGETS and MULTIPLE
SInt32 numTargets = 2;
@ -888,7 +888,7 @@ bool CXWindowsScreen::sendClipboardTimestamp(
Window requestor,
Atom property, Time /*time*/)
{
log((CLOG_DEBUG "handling clipboard request for TIMESTAMP"));
log((CLOG_DEBUG1 "handling clipboard request for TIMESTAMP"));
// FIXME -- handle Alloc errors (by returning false)
XChangeProperty(m_display, requestor, property,