diff --git a/xpcPlugin/DataManager.cpp b/xpcPlugin/DataManager.cpp index e18f3c0..45a4919 100644 --- a/xpcPlugin/DataManager.cpp +++ b/xpcPlugin/DataManager.cpp @@ -38,6 +38,8 @@ namespace XPC 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_Pause, XPLMFindDataRef("sim/operation/override/override_planepath"))); diff --git a/xpcPlugin/Message.cpp b/xpcPlugin/Message.cpp index 130c17a..f74329d 100644 --- a/xpcPlugin/Message.cpp +++ b/xpcPlugin/Message.cpp @@ -13,46 +13,44 @@ namespace XPC Message Message::ReadFrom(const UDPSocket& sock) { + Log::WriteLine(LOG_TRACE, "MESG", "Reading Message"); Message m; int len = sock.Read(m.buffer, bufferSize, &m.source); m.size = len < 0 ? 0 : len; + Log::FormatLine(LOG_TRACE, "MESG", "Read result: %i", len); return m; } unsigned long Message::GetMagicNumber() const { - if (size < 4) - { - return 0; - } - return *((unsigned long*)buffer); + 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 val; } std::string Message::GetHead() const { - if (size < 4) - { - return ""; - } - return std::string((char*)buffer, 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 val; } const unsigned char* Message::GetBuffer() const { - if (size == 0) - { - return NULL; - } - return buffer; + const unsigned char* val = size == 0 ? NULL : buffer; + Log::FormatLine(LOG_TRACE, "MESG", "Returning buffer 0x%lX for message 0x%zX", val, this); + return val; } std::size_t Message::GetSize() const { + Log::FormatLine(LOG_TRACE, "MESG", "Returning size %zu for message 0x%zX", size, this); return size; } struct sockaddr Message::GetSource() const { + Log::FormatLine(LOG_TRACE, "MESG", "Returning source for message 0x%zX", this); return source; } diff --git a/xpcPlugin/MessageHandlers.cpp b/xpcPlugin/MessageHandlers.cpp index e2f8e22..1688505 100644 --- a/xpcPlugin/MessageHandlers.cpp +++ b/xpcPlugin/MessageHandlers.cpp @@ -35,6 +35,7 @@ namespace XPC void MessageHandlers::SetSocket(UDPSocket* socket) { + Log::WriteLine(LOG_TRACE, "MSGH", "Setting socket"); MessageHandlers::sock = socket; } @@ -42,6 +43,7 @@ namespace XPC { if (handlers.size() == 0) { + Log::WriteLine(LOG_TRACE, "MSGH", "Initializing handlers"); // Common messages handlers.insert(std::make_pair("CONN", MessageHandlers::HandleConn)); handlers.insert(std::make_pair("CTRL", MessageHandlers::HandleCtrl)); @@ -99,13 +101,13 @@ namespace XPC connection.addr = sourceaddr; connection.getdCount = 0; 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); } else { 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); } @@ -392,9 +394,7 @@ namespace XPC void MessageHandlers::HandleDref(const Message& msg) { -#if LOG_VERBOSITY >= 3 - Log::FormatLine("[DREF] Request to set DREF value received (Conn %i)", connection.id); -#endif + Log::FormatLine(LOG_TRACE, "DREF", "Request to set DREF value received (Conn %i)", connection.id); const unsigned char* buffer = msg.GetBuffer(); std::size_t size = msg.GetSize(); std::size_t pos = 5; @@ -417,16 +417,12 @@ namespace XPC pos += 4 * valueCount; DataManager::Set(dref, values, valueCount); -#if LOG_VERBOSITY >= 4 - Log::FormatLine("[DREF] Set %d values for %s", valueCount, dref.c_str()); -#endif + Log::FormatLine(LOG_DEBUG, "DREF", "Set %d values for %s", valueCount, dref); } -#if LOG_VERBOSITY >= 2 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) @@ -556,7 +552,7 @@ namespace XPC Log::WriteLine(LOG_INFO, "SIMU", "Simulation paused"); break; case 2: - Log::WriteLine(LOG_INFO, "SIMU", "Simulation switched"); + Log::FormatLine(LOG_INFO, "SIMU", "Simulation switched to %i", value[0]); break; } }