From 4e4d33a755f225554919ff9f4d9986605504ee43 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 10 Jul 2017 18:44:17 +0200 Subject: [PATCH] Ref T105, adjusted CDirectPlayPeer * log cats * and log messages --- src/plugins/simulator/fs9/directplaypeer.cpp | 40 +++++++++++--------- src/plugins/simulator/fs9/directplaypeer.h | 10 +++-- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/plugins/simulator/fs9/directplaypeer.cpp b/src/plugins/simulator/fs9/directplaypeer.cpp index 3164d0b1d..c4a53f862 100644 --- a/src/plugins/simulator/fs9/directplaypeer.cpp +++ b/src/plugins/simulator/fs9/directplaypeer.cpp @@ -25,13 +25,18 @@ namespace BlackSimPlugin { namespace Fs9 { + const CLogCategoryList &CDirectPlayPeer::getLogCategories() + { + static const BlackMisc::CLogCategoryList cats { CLogCategory::driver() }; + return cats; + } + CDirectPlayPeer::CDirectPlayPeer(QObject *owner, const BlackMisc::Aviation::CCallsign &callsign) : CContinuousWorker(owner, "peer_" + callsign.toQString()), m_callsign(callsign), m_mutexHostList(QMutex::Recursive), m_callbackWrapper(this, &CDirectPlayPeer::directPlayMessageHandler) - { - } + { } CDirectPlayPeer::~CDirectPlayPeer() { @@ -49,7 +54,7 @@ namespace BlackSimPlugin { switch (messageId) { - case DPN_MSGID_CREATE_PLAYER: + case DPN_MSGID_CREATE_PLAYER: { DPNMSG_CREATE_PLAYER *pCreatePlayerMsg = static_cast(msgBuffer); @@ -91,7 +96,7 @@ namespace BlackSimPlugin break; } - case DPN_MSGID_RECEIVE: + case DPN_MSGID_RECEIVE: { PDPNMSG_RECEIVE pReceiveMsg = static_cast(msgBuffer); @@ -99,13 +104,12 @@ namespace BlackSimPlugin if (pReceiveMsg->dpnidSender == m_playerUser) { QByteArray messageData = QByteArray((char *)pReceiveMsg->pReceiveData, pReceiveMsg->dwReceiveDataSize); - emit customPacketReceived(messageData); } break; } - case DPN_MSGID_ENUM_HOSTS_RESPONSE: + case DPN_MSGID_ENUM_HOSTS_RESPONSE: { PDPNMSG_ENUM_HOSTS_RESPONSE enumHostsResponseMsg = static_cast(msgBuffer); const DPN_APPLICATION_DESC *applicationDescription = enumHostsResponseMsg->pApplicationDescription; @@ -127,7 +131,7 @@ namespace BlackSimPlugin // Copy the Host Address if (FAILED(hr = enumHostsResponseMsg->pAddressSender->Duplicate(hostNode.getHostAddressPtr()))) { - qWarning() << "Failed to duplicate host address!"; + CLogMessage(this).warning("Failed to duplicate host address!"); return hr; } @@ -171,14 +175,14 @@ namespace BlackSimPlugin IID_IDirectPlay8Peer, reinterpret_cast(&m_directPlayPeer)))) { - qWarning() << "Failed to create DirectPlay8Peer object!"; + CLogMessage(this).warning("Failed to create DirectPlay8Peer object!"); return hr; } // Init DirectPlay if (FAILED(hr = m_directPlayPeer->Initialize(&m_callbackWrapper, m_callbackWrapper.messageHandler, 0))) { - qWarning() << "Failed to initialize directplay peer!"; + CLogMessage(this).warning("Failed to initialize directplay peer!"); return hr; } @@ -186,7 +190,7 @@ namespace BlackSimPlugin if (!isServiceProviderValid(&CLSID_DP8SP_TCPIP)) { hr = E_FAIL; - qWarning() << "Service provider is invalid!"; + CLogMessage(this).warning("Service provider is invalid!"); return hr; } @@ -203,7 +207,7 @@ namespace BlackSimPlugin if (hr != DPNERR_BUFFERTOOSMALL) { - qWarning() << "Failed to enumerate service providers!"; + CLogMessage(this).warning("Failed to enumerate service providers!"); return false; } @@ -214,7 +218,7 @@ namespace BlackSimPlugin if (FAILED(hr = m_directPlayPeer->EnumServiceProviders(&CLSID_DP8SP_TCPIP, nullptr, dpnSPInfo, &dwSize, &dwItems, 0))) { - qWarning() << "Failed to enumerate service providers!"; + CLogMessage(this).warning("Failed to enumerate service providers!"); return false; } @@ -235,14 +239,14 @@ namespace BlackSimPlugin IID_IDirectPlay8Address, reinterpret_cast(&m_deviceAddress)))) { - qWarning() << "Failed to create DirectPlay8Address instance!"; + CLogMessage(this).warning("Failed to create DirectPlay8Address instance!"); return hr; } // Set the SP for our Device Address if (FAILED(hr = m_deviceAddress->SetSP(&CLSID_DP8SP_TCPIP))) { - qWarning() << "Failed to set SP!"; + CLogMessage(this).warning("Failed to set SP!"); return hr; } @@ -276,6 +280,7 @@ namespace BlackSimPlugin if ((dpBufferDesc.dwBufferSize = message.size()) == 0) { return S_FALSE; } + //! \fixme KB 201707, style? pBufferData = const_cast(reinterpret_cast(message.data())); dpBufferDesc.pBufferData = (BYTE *)message.data(); // If m_playerUser is non zero, send it only to him @@ -285,8 +290,9 @@ namespace BlackSimPlugin nullptr, nullptr, DPNSEND_SYNC | DPNSEND_NOLOOPBACK))) { + const QString m(message); CLogMessage(this).warning("DirectPlay: Failed to send message!"); - qDebug() << message; + CLogMessage(this).debug() << m; } return hr; } @@ -295,5 +301,5 @@ namespace BlackSimPlugin { m_playerUser = 0; } - } -} + } // ns +} // ns diff --git a/src/plugins/simulator/fs9/directplaypeer.h b/src/plugins/simulator/fs9/directplaypeer.h index d85d00f94..d91a9ecf8 100644 --- a/src/plugins/simulator/fs9/directplaypeer.h +++ b/src/plugins/simulator/fs9/directplaypeer.h @@ -13,8 +13,9 @@ #include "fs9.h" #include "hostnode.h" #include "callbackwrapper.h" -#include "blackmisc/worker.h" #include "blackmisc/aviation/callsign.h" +#include "blackmisc/worker.h" +#include "blackmisc/logcategorylist.h" #include #include #include @@ -47,6 +48,9 @@ namespace BlackSimPlugin //! Sets users DirectPlay ID void setPlayerUserId(DPNID id) { m_playerUser = id; } + //! Log categories + static const BlackMisc::CLogCategoryList &getLogCategories(); + public slots: //! Send a custom DirectPlay message HRESULT sendMessage(const QByteArray &data); @@ -92,7 +96,7 @@ namespace BlackSimPlugin using TCallbackWrapper = CallbackWrapper; //!< DirectPlay peer message handler wrapper TCallbackWrapper m_callbackWrapper; //!< Callback wrapper }; - } -} + } // ns +} // ns #endif // guard