Improved trace logging.

This commit is contained in:
Jason Watkins
2015-05-12 15:47:55 -07:00
parent 8e46a90557
commit bd0c15bede
3 changed files with 23 additions and 27 deletions

View File

@@ -38,6 +38,8 @@ namespace XPC
void DataManager::Initialize() void DataManager::Initialize()
{ {
Log::WriteLine(LOG_TRACE, "DMAN", "Initializing drefs");
drefs.insert(make_pair(DREF_None, XPLMFindDataRef("sim/test/test_float"))); drefs.insert(make_pair(DREF_None, XPLMFindDataRef("sim/test/test_float")));
drefs.insert(make_pair(DREF_Pause, XPLMFindDataRef("sim/operation/override/override_planepath"))); drefs.insert(make_pair(DREF_Pause, XPLMFindDataRef("sim/operation/override/override_planepath")));

View File

@@ -13,46 +13,44 @@ namespace XPC
Message Message::ReadFrom(const UDPSocket& sock) Message Message::ReadFrom(const UDPSocket& sock)
{ {
Log::WriteLine(LOG_TRACE, "MESG", "Reading Message");
Message m; Message m;
int len = sock.Read(m.buffer, bufferSize, &m.source); int len = sock.Read(m.buffer, bufferSize, &m.source);
m.size = len < 0 ? 0 : len; m.size = len < 0 ? 0 : len;
Log::FormatLine(LOG_TRACE, "MESG", "Read result: %i", len);
return m; return m;
} }
unsigned long Message::GetMagicNumber() const unsigned long Message::GetMagicNumber() const
{ {
if (size < 4) unsigned long val = size < 4 ? 0 : *((unsigned long*)buffer);
{ Log::FormatLine(LOG_TRACE, "MESG", "Gettting magic number 0x%lX for message 0x%zX", val, this);
return 0; return val;
}
return *((unsigned long*)buffer);
} }
std::string Message::GetHead() const std::string Message::GetHead() const
{ {
if (size < 4) std::string val = size < 4 ? "" : std::string((char*)buffer, 4);
{ Log::FormatLine(LOG_TRACE, "MESG", "Getting head %s for message 0x%zX", val, this);
return ""; return val;
}
return std::string((char*)buffer, 4);
} }
const unsigned char* Message::GetBuffer() const const unsigned char* Message::GetBuffer() const
{ {
if (size == 0) const unsigned char* val = size == 0 ? NULL : buffer;
{ Log::FormatLine(LOG_TRACE, "MESG", "Returning buffer 0x%lX for message 0x%zX", val, this);
return NULL; return val;
}
return buffer;
} }
std::size_t Message::GetSize() const std::size_t Message::GetSize() const
{ {
Log::FormatLine(LOG_TRACE, "MESG", "Returning size %zu for message 0x%zX", size, this);
return size; return size;
} }
struct sockaddr Message::GetSource() const struct sockaddr Message::GetSource() const
{ {
Log::FormatLine(LOG_TRACE, "MESG", "Returning source for message 0x%zX", this);
return source; return source;
} }

View File

@@ -35,6 +35,7 @@ namespace XPC
void MessageHandlers::SetSocket(UDPSocket* socket) void MessageHandlers::SetSocket(UDPSocket* socket)
{ {
Log::WriteLine(LOG_TRACE, "MSGH", "Setting socket");
MessageHandlers::sock = socket; MessageHandlers::sock = socket;
} }
@@ -42,6 +43,7 @@ namespace XPC
{ {
if (handlers.size() == 0) if (handlers.size() == 0)
{ {
Log::WriteLine(LOG_TRACE, "MSGH", "Initializing handlers");
// Common messages // Common messages
handlers.insert(std::make_pair("CONN", MessageHandlers::HandleConn)); handlers.insert(std::make_pair("CONN", MessageHandlers::HandleConn));
handlers.insert(std::make_pair("CTRL", MessageHandlers::HandleCtrl)); handlers.insert(std::make_pair("CTRL", MessageHandlers::HandleCtrl));
@@ -99,13 +101,13 @@ namespace XPC
connection.addr = sourceaddr; connection.addr = sourceaddr;
connection.getdCount = 0; connection.getdCount = 0;
connections[connectionKey] = connection; connections[connectionKey] = connection;
Log::FormatLine(LOG_TRACE, "MSGH", "New connection. ID=%u, Remote=%s", Log::FormatLine(LOG_DEBUG, "MSGH", "New connection. ID=%u, Remote=%s",
connection.id, connectionKey); connection.id, connectionKey);
} }
else else
{ {
connection = (*conn).second; connection = (*conn).second;
Log::FormatLine(LOG_TRACE, "MSGH", "Existing connection. ID=%u, Remote=%s", Log::FormatLine(LOG_DEBUG, "MSGH", "Existing connection. ID=%u, Remote=%s",
connection.id, connectionKey); connection.id, connectionKey);
} }
@@ -392,9 +394,7 @@ namespace XPC
void MessageHandlers::HandleDref(const Message& msg) void MessageHandlers::HandleDref(const Message& msg)
{ {
#if LOG_VERBOSITY >= 3 Log::FormatLine(LOG_TRACE, "DREF", "Request to set DREF value received (Conn %i)", connection.id);
Log::FormatLine("[DREF] Request to set DREF value received (Conn %i)", connection.id);
#endif
const unsigned char* buffer = msg.GetBuffer(); const unsigned char* buffer = msg.GetBuffer();
std::size_t size = msg.GetSize(); std::size_t size = msg.GetSize();
std::size_t pos = 5; std::size_t pos = 5;
@@ -417,16 +417,12 @@ namespace XPC
pos += 4 * valueCount; pos += 4 * valueCount;
DataManager::Set(dref, values, valueCount); DataManager::Set(dref, values, valueCount);
#if LOG_VERBOSITY >= 4 Log::FormatLine(LOG_DEBUG, "DREF", "Set %d values for %s", valueCount, dref);
Log::FormatLine("[DREF] Set %d values for %s", valueCount, dref.c_str());
#endif
} }
#if LOG_VERBOSITY >= 2
if (pos != size) if (pos != size)
{ {
Log::WriteLine("[DREF] Error: Command did not terminate at the expected position."); Log::WriteLine(LOG_ERROR, "DREF", "ERROR: Command did not terminate at the expected position.");
} }
#endif
} }
void MessageHandlers::HandleGetD(const Message& msg) void MessageHandlers::HandleGetD(const Message& msg)
@@ -556,7 +552,7 @@ namespace XPC
Log::WriteLine(LOG_INFO, "SIMU", "Simulation paused"); Log::WriteLine(LOG_INFO, "SIMU", "Simulation paused");
break; break;
case 2: case 2:
Log::WriteLine(LOG_INFO, "SIMU", "Simulation switched"); Log::FormatLine(LOG_INFO, "SIMU", "Simulation switched to %i", value[0]);
break; break;
} }
} }