mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-22 13:15:39 +08:00
Ref T105, adjusted CDirectPlayPeer
* log cats * and log messages
This commit is contained in:
committed by
Mathew Sutcliffe
parent
18ab0e8459
commit
4e4d33a755
@@ -25,13 +25,18 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
namespace Fs9
|
namespace Fs9
|
||||||
{
|
{
|
||||||
|
const CLogCategoryList &CDirectPlayPeer::getLogCategories()
|
||||||
|
{
|
||||||
|
static const BlackMisc::CLogCategoryList cats { CLogCategory::driver() };
|
||||||
|
return cats;
|
||||||
|
}
|
||||||
|
|
||||||
CDirectPlayPeer::CDirectPlayPeer(QObject *owner, const BlackMisc::Aviation::CCallsign &callsign)
|
CDirectPlayPeer::CDirectPlayPeer(QObject *owner, const BlackMisc::Aviation::CCallsign &callsign)
|
||||||
: CContinuousWorker(owner, "peer_" + callsign.toQString()),
|
: CContinuousWorker(owner, "peer_" + callsign.toQString()),
|
||||||
m_callsign(callsign),
|
m_callsign(callsign),
|
||||||
m_mutexHostList(QMutex::Recursive),
|
m_mutexHostList(QMutex::Recursive),
|
||||||
m_callbackWrapper(this, &CDirectPlayPeer::directPlayMessageHandler)
|
m_callbackWrapper(this, &CDirectPlayPeer::directPlayMessageHandler)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
CDirectPlayPeer::~CDirectPlayPeer()
|
CDirectPlayPeer::~CDirectPlayPeer()
|
||||||
{
|
{
|
||||||
@@ -99,7 +104,6 @@ namespace BlackSimPlugin
|
|||||||
if (pReceiveMsg->dpnidSender == m_playerUser)
|
if (pReceiveMsg->dpnidSender == m_playerUser)
|
||||||
{
|
{
|
||||||
QByteArray messageData = QByteArray((char *)pReceiveMsg->pReceiveData, pReceiveMsg->dwReceiveDataSize);
|
QByteArray messageData = QByteArray((char *)pReceiveMsg->pReceiveData, pReceiveMsg->dwReceiveDataSize);
|
||||||
|
|
||||||
emit customPacketReceived(messageData);
|
emit customPacketReceived(messageData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -127,7 +131,7 @@ namespace BlackSimPlugin
|
|||||||
// Copy the Host Address
|
// Copy the Host Address
|
||||||
if (FAILED(hr = enumHostsResponseMsg->pAddressSender->Duplicate(hostNode.getHostAddressPtr())))
|
if (FAILED(hr = enumHostsResponseMsg->pAddressSender->Duplicate(hostNode.getHostAddressPtr())))
|
||||||
{
|
{
|
||||||
qWarning() << "Failed to duplicate host address!";
|
CLogMessage(this).warning("Failed to duplicate host address!");
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,14 +175,14 @@ namespace BlackSimPlugin
|
|||||||
IID_IDirectPlay8Peer,
|
IID_IDirectPlay8Peer,
|
||||||
reinterpret_cast<void **>(&m_directPlayPeer))))
|
reinterpret_cast<void **>(&m_directPlayPeer))))
|
||||||
{
|
{
|
||||||
qWarning() << "Failed to create DirectPlay8Peer object!";
|
CLogMessage(this).warning("Failed to create DirectPlay8Peer object!");
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init DirectPlay
|
// Init DirectPlay
|
||||||
if (FAILED(hr = m_directPlayPeer->Initialize(&m_callbackWrapper, m_callbackWrapper.messageHandler, 0)))
|
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;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +190,7 @@ namespace BlackSimPlugin
|
|||||||
if (!isServiceProviderValid(&CLSID_DP8SP_TCPIP))
|
if (!isServiceProviderValid(&CLSID_DP8SP_TCPIP))
|
||||||
{
|
{
|
||||||
hr = E_FAIL;
|
hr = E_FAIL;
|
||||||
qWarning() << "Service provider is invalid!";
|
CLogMessage(this).warning("Service provider is invalid!");
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +207,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
if (hr != DPNERR_BUFFERTOOSMALL)
|
if (hr != DPNERR_BUFFERTOOSMALL)
|
||||||
{
|
{
|
||||||
qWarning() << "Failed to enumerate service providers!";
|
CLogMessage(this).warning("Failed to enumerate service providers!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +218,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
if (FAILED(hr = m_directPlayPeer->EnumServiceProviders(&CLSID_DP8SP_TCPIP, nullptr, dpnSPInfo, &dwSize, &dwItems, 0)))
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,14 +239,14 @@ namespace BlackSimPlugin
|
|||||||
IID_IDirectPlay8Address,
|
IID_IDirectPlay8Address,
|
||||||
reinterpret_cast<void **>(&m_deviceAddress))))
|
reinterpret_cast<void **>(&m_deviceAddress))))
|
||||||
{
|
{
|
||||||
qWarning() << "Failed to create DirectPlay8Address instance!";
|
CLogMessage(this).warning("Failed to create DirectPlay8Address instance!");
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the SP for our Device Address
|
// Set the SP for our Device Address
|
||||||
if (FAILED(hr = m_deviceAddress->SetSP(&CLSID_DP8SP_TCPIP)))
|
if (FAILED(hr = m_deviceAddress->SetSP(&CLSID_DP8SP_TCPIP)))
|
||||||
{
|
{
|
||||||
qWarning() << "Failed to set SP!";
|
CLogMessage(this).warning("Failed to set SP!");
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +280,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
if ((dpBufferDesc.dwBufferSize = message.size()) == 0) { return S_FALSE; }
|
if ((dpBufferDesc.dwBufferSize = message.size()) == 0) { return S_FALSE; }
|
||||||
|
|
||||||
|
//! \fixme KB 201707, style? pBufferData = const_cast<BYTE *>(reinterpret_cast<const BYTE *>(message.data()));
|
||||||
dpBufferDesc.pBufferData = (BYTE *)message.data();
|
dpBufferDesc.pBufferData = (BYTE *)message.data();
|
||||||
|
|
||||||
// If m_playerUser is non zero, send it only to him
|
// If m_playerUser is non zero, send it only to him
|
||||||
@@ -285,8 +290,9 @@ namespace BlackSimPlugin
|
|||||||
nullptr, nullptr,
|
nullptr, nullptr,
|
||||||
DPNSEND_SYNC | DPNSEND_NOLOOPBACK)))
|
DPNSEND_SYNC | DPNSEND_NOLOOPBACK)))
|
||||||
{
|
{
|
||||||
|
const QString m(message);
|
||||||
CLogMessage(this).warning("DirectPlay: Failed to send message!");
|
CLogMessage(this).warning("DirectPlay: Failed to send message!");
|
||||||
qDebug() << message;
|
CLogMessage(this).debug() << m;
|
||||||
}
|
}
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@@ -295,5 +301,5 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
m_playerUser = 0;
|
m_playerUser = 0;
|
||||||
}
|
}
|
||||||
}
|
} // ns
|
||||||
}
|
} // ns
|
||||||
|
|||||||
@@ -13,8 +13,9 @@
|
|||||||
#include "fs9.h"
|
#include "fs9.h"
|
||||||
#include "hostnode.h"
|
#include "hostnode.h"
|
||||||
#include "callbackwrapper.h"
|
#include "callbackwrapper.h"
|
||||||
#include "blackmisc/worker.h"
|
|
||||||
#include "blackmisc/aviation/callsign.h"
|
#include "blackmisc/aviation/callsign.h"
|
||||||
|
#include "blackmisc/worker.h"
|
||||||
|
#include "blackmisc/logcategorylist.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
@@ -47,6 +48,9 @@ namespace BlackSimPlugin
|
|||||||
//! Sets users DirectPlay ID
|
//! Sets users DirectPlay ID
|
||||||
void setPlayerUserId(DPNID id) { m_playerUser = id; }
|
void setPlayerUserId(DPNID id) { m_playerUser = id; }
|
||||||
|
|
||||||
|
//! Log categories
|
||||||
|
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Send a custom DirectPlay message
|
//! Send a custom DirectPlay message
|
||||||
HRESULT sendMessage(const QByteArray &data);
|
HRESULT sendMessage(const QByteArray &data);
|
||||||
@@ -92,7 +96,7 @@ namespace BlackSimPlugin
|
|||||||
using TCallbackWrapper = CallbackWrapper<CDirectPlayPeer, HRESULT, DWORD, void *>; //!< DirectPlay peer message handler wrapper
|
using TCallbackWrapper = CallbackWrapper<CDirectPlayPeer, HRESULT, DWORD, void *>; //!< DirectPlay peer message handler wrapper
|
||||||
TCallbackWrapper m_callbackWrapper; //!< Callback wrapper
|
TCallbackWrapper m_callbackWrapper; //!< Callback wrapper
|
||||||
};
|
};
|
||||||
}
|
} // ns
|
||||||
}
|
} // ns
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user