From 9e19f6b8573ec81e48d8350cab7b6cf6ecf97202 Mon Sep 17 00:00:00 2001 From: Chris Mizerak Date: Fri, 3 Jun 2022 13:54:30 -0700 Subject: [PATCH] Bug fix: UDP output threads may not send queued packets during a period of time when the thread is starting up - Added dark mode title bar on Windows - Print incoming/outgoing non-OSC packets --- OSCRouter/MainWindow.cpp | 2 +- OSCRouter/OSCRouter.vcxproj | 18 ++++++++ OSCRouter/OSCRouter.vcxproj.filters | 6 +++ OSCRouter/Router.cpp | 65 ++++++++++++++++++++++++----- OSCRouter/Router.h | 2 + OSCRouter/qt.conf | 2 + OSCRouter/qt.qrc | 5 +++ 7 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 OSCRouter/qt.conf create mode 100644 OSCRouter/qt.qrc diff --git a/OSCRouter/MainWindow.cpp b/OSCRouter/MainWindow.cpp index 52aea49..cf19b95 100644 --- a/OSCRouter/MainWindow.cpp +++ b/OSCRouter/MainWindow.cpp @@ -33,7 +33,7 @@ //////////////////////////////////////////////////////////////////////////////// -#define APP_VERSION "0.13" +#define APP_VERSION "0.14" #define SETTING_LOG_DEPTH "LogDepth" #define SETTING_FILE_DEPTH "FileDepth" #define SETTING_LAST_FILE "LastFile" diff --git a/OSCRouter/OSCRouter.vcxproj b/OSCRouter/OSCRouter.vcxproj index 6a9a4fb..a6ff3b0 100644 --- a/OSCRouter/OSCRouter.vcxproj +++ b/OSCRouter/OSCRouter.vcxproj @@ -53,6 +53,7 @@ ..\..\EosSyncLib\EosSyncLib;$(QTOSCROUTER)\include;%(AdditionalIncludeDirectories) 4127;4996;4512 WIN32;NOMINMAX;%(PreprocessorDefinitions) + 4715 true @@ -74,6 +75,7 @@ ..\..\EosSyncLib\EosSyncLib;$(QTOSCROUTER)\include;%(AdditionalIncludeDirectories) 4127;4996;4512 WIN32;NOMINMAX;%(PreprocessorDefinitions) + 4715 true @@ -139,6 +141,22 @@ + + + Document + $(QTOSCROUTER)\bin\rcc.exe -no-compress %(Filename)%(Extension) -o %(Filename)%(Extension).cpp + $(QTOSCROUTER)\bin\rcc.exe -no-compress %(Filename)%(Extension) -o %(Filename)%(Extension).cpp + rcc'ing %(Filename)%(Extension) + %(Filename)%(Extension).cpp + $(QTOSCROUTER)\bin\rcc.exe + rcc'ing %(Filename)%(Extension) + %(Filename)%(Extension).cpp + $(QTOSCROUTER)\bin\rcc.exe + ClCompile + ClCompile + true + true + diff --git a/OSCRouter/OSCRouter.vcxproj.filters b/OSCRouter/OSCRouter.vcxproj.filters index 4ee8bf0..ea3dc6b 100644 --- a/OSCRouter/OSCRouter.vcxproj.filters +++ b/OSCRouter/OSCRouter.vcxproj.filters @@ -130,6 +130,9 @@ OSCRouter\Header Files + + Resource Files + @@ -140,5 +143,8 @@ Resource Files + + Resource Files + \ No newline at end of file diff --git a/OSCRouter/Router.cpp b/OSCRouter/Router.cpp index e3c6e55..fd40ff5 100644 --- a/OSCRouter/Router.cpp +++ b/OSCRouter/Router.cpp @@ -32,6 +32,9 @@ #include #endif +#include +#include + // must be last include #include "LeakWatcher.h" @@ -49,6 +52,36 @@ void PacketLogger::OSCParserClient_Log(const std::string &message) //////////////////////////////////////////////////////////////////////////////// +void PacketLogger::PrintPacket(OSCParser& oscParser, const char* packet, size_t size) +{ + if (packet == nullptr || size == 0) + return; + + if (OSCParser::IsOSCPacket(packet, size) && oscParser.PrintPacket(*this, packet, size)) + return; + + // not printed as an OSC packet, so print the raw hex contents + const size_t MaxPrintSize = 32; + size_t printSize = qMin(size, MaxPrintSize); + + std::stringstream ss; + ss << std::setfill('0') << std::setw(2) << std::hex; + for (size_t i = 0; i < printSize; ++i) + { + if (i != 0) + ss << ' '; + ss << static_cast(packet[i]); + } + + if (size > printSize) + ss << "..."; + + if (!ss.str().empty()) + OSCParserClient_Log(ss.str()); +} + +//////////////////////////////////////////////////////////////////////////////// + EosUdpInThread::EosUdpInThread() : m_Run(false) , m_Mutex(QMutex::Recursive) @@ -155,7 +188,7 @@ void EosUdpInThread::run() QHostAddress host( reinterpret_cast(&addr) ); logPrefix = QString("IN [%1:%2] ").arg( host.toString() ).arg(m_Addr.port).toUtf8().constData(); packetLogger.SetPrefix(logPrefix); - logParser.PrintPacket(packetLogger, data, static_cast(len)); + packetLogger.PrintPacket(logParser, data, static_cast(len)); unsigned int ip = static_cast( host.toIPv4Address() ); m_Mutex.lock(); m_Q.push_back( sRecvPacket(data,len,ip) ); @@ -208,6 +241,7 @@ EosUdpOutThread::EosUdpOutThread() , m_ItemStateTableId(ItemStateTable::sm_Invalid_Id) , m_State(ItemState::STATE_UNINITIALIZED) , m_ReconnectDelay(0) + , m_QEnabled(false) { } @@ -228,6 +262,7 @@ void EosUdpOutThread::Start(const EosAddr &addr, ItemStateTable::ID itemStateTab m_ItemStateTableId = itemStateTableId; m_ReconnectDelay = reconnectDelayMS; m_Run = true; + m_QEnabled = true; // q commands while on-demand thread is first starting start(); } @@ -244,7 +279,7 @@ void EosUdpOutThread::Stop() bool EosUdpOutThread::Send(const EosPacket &packet) { m_Mutex.lock(); - if(GetState() == ItemState::STATE_CONNECTED) + if(m_QEnabled) { m_Q.push_back(packet); m_Mutex.unlock(); @@ -279,7 +314,16 @@ ItemState::EnumState EosUdpOutThread::GetState() void EosUdpOutThread::SetState(ItemState::EnumState state) { m_Mutex.lock(); - m_State = state; + if (m_State != state) + { + m_State = state; + + switch (m_State) + { + case ItemState::STATE_CONNECTED: m_QEnabled = true; break; + case ItemState::STATE_NOT_CONNECTED: m_QEnabled = false; break; + } + } m_Mutex.unlock(); } @@ -294,7 +338,7 @@ void EosUdpOutThread::run() EosTimer reconnectTimer; // outer loop for auto-reconnect - while( m_Run ) + do { SetState(ItemState::STATE_CONNECTING); @@ -320,8 +364,8 @@ void EosUdpOutThread::run() { const char *buf = i->GetData(); int len = i->GetSize(); - if( udpOut->SendPacket(m_PrivateLog,buf,len) ) - logParser.PrintPacket(packetLogger,buf,static_cast(len)); + if (udpOut->SendPacket(m_PrivateLog, buf, len)) + packetLogger.PrintPacket(logParser, buf, static_cast(len)); } q.clear(); @@ -345,7 +389,7 @@ void EosUdpOutThread::run() reconnectTimer.Start(); while(m_Run && !reconnectTimer.GetExpired(m_ReconnectDelay)) msleep(10); - } + } while (m_Run); msg = QString("udp output %1:%2 thread ended").arg(m_Addr.ip).arg(m_Addr.port); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); @@ -546,7 +590,7 @@ void EosTcpClientThread::run() { if(frameSize != 0) { - logParser.PrintPacket(inPacketLogger, frame, frameSize); + inPacketLogger.PrintPacket(logParser, frame, frameSize); m_Mutex.lock(); m_RecvQ.push_back( EosUdpInThread::sRecvPacket(frame,static_cast(frameSize),ip) ); m_Mutex.unlock(); @@ -578,8 +622,8 @@ void EosTcpClientThread::run() char *frame = recvStream.GetNextFrame(frameSize); if( frame ) { - if(frameSize != 0) - logParser.PrintPacket(outPacketLogger, frame, frameSize); + if (frameSize != 0) + outPacketLogger.PrintPacket(logParser, frame, frameSize); delete[] frame; } else @@ -956,6 +1000,7 @@ EosUdpOutThread* RouterThread::CreateUdpOutThread(const EosAddr &addr, ItemState EosUdpOutThread *thread = new EosUdpOutThread(); udpOutThreads[addr] = thread; thread->Start(addr, itemStateTableId, m_ReconnectDelay); + return thread; } else return i->second; diff --git a/OSCRouter/Router.h b/OSCRouter/Router.h index 360a08e..2662f08 100644 --- a/OSCRouter/Router.h +++ b/OSCRouter/Router.h @@ -87,6 +87,7 @@ class PacketLogger virtual void SetPrefix(const std::string &prefix) {m_Prefix = prefix;} virtual void OSCParserClient_Log(const std::string &message); virtual void OSCParserClient_Send(const char *, size_t) {} + virtual void PrintPacket(OSCParser& oscParser, const char* packet, size_t size); protected: EosLog::EnumLogMsgType m_LogType; @@ -164,6 +165,7 @@ class EosUdpOutThread EosLog m_Log; EosLog m_PrivateLog; EosPacket::Q m_Q; + bool m_QEnabled; QMutex m_Mutex; virtual void run(); diff --git a/OSCRouter/qt.conf b/OSCRouter/qt.conf new file mode 100644 index 0000000..a980105 --- /dev/null +++ b/OSCRouter/qt.conf @@ -0,0 +1,2 @@ +[Platforms] +WindowsArguments = darkmode=1 \ No newline at end of file diff --git a/OSCRouter/qt.qrc b/OSCRouter/qt.qrc new file mode 100644 index 0000000..d76ca99 --- /dev/null +++ b/OSCRouter/qt.qrc @@ -0,0 +1,5 @@ + + + qt.conf + +