refs #179 sendCustomPacket slot and customPacketReceived signal

This commit is contained in:
Mathew Sutcliffe
2014-03-22 17:52:42 +00:00
parent fde307e661
commit da5a42c556
3 changed files with 69 additions and 0 deletions

View File

@@ -90,6 +90,7 @@ namespace BlackCore
m_net->InstallOnCloudDataReceivedEvent(onCloudDataReceived, this);
m_net->InstallOnPilotInfoRequestReceivedEvent(onPilotInfoRequestReceived, this);
m_net->InstallOnPilotInfoReceivedEvent(onPilotInfoReceived, this);
m_net->InstallOnCustomPilotPacketReceivedEvent(onCustomPacketReceived, this);
}
catch (...) { exceptionDispatcher(Q_FUNC_INFO); }
}
@@ -250,11 +251,47 @@ namespace BlackCore
return toFSD(callsign.getStringAsSet());
}
std::function<const char **()> CNetworkVatlib::toFSD(QStringList qstrList) const
{
struct Closure
{
QVector<QByteArray> m_bytesVec;
QVector<const char *> m_cstrVec;
Closure(QStringList qsl, const CNetworkVatlib *creator)
{
for (auto i = qsl.begin(); i != qsl.end(); ++i)
{
m_bytesVec.push_back(creator->toFSD(*i));
}
}
const char **operator ()()
{
Q_ASSERT(m_cstrVec.isEmpty());
for (auto i = m_bytesVec.begin(); i != m_bytesVec.end(); ++i)
{
m_cstrVec.push_back(i->constData());
}
return const_cast<const char **>(m_cstrVec.constData());
}
};
return Closure(qstrList, this);
}
QString CNetworkVatlib::fromFSD(const char *cstr) const
{
return m_fsdTextCodec->toUnicode(cstr);
}
QStringList CNetworkVatlib::fromFSD(const char **cstrArray, int size) const
{
QStringList qstrList;
for (int i = 0; i < size; ++i)
{
qstrList.push_back(fromFSD(cstrArray[i]));
}
return qstrList;
}
void exceptionDispatcher(const char *caller)
{
try
@@ -441,6 +478,17 @@ namespace BlackCore
catch (...) { exceptionDispatcher(Q_FUNC_INFO); }
}
void CNetworkVatlib::sendCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data)
{
Q_ASSERT_X(isConnected(), "CNetworkVatlib", "Can't send to server when disconnected");
try
{
m_net->SendCustomPilotPacket(toFSD(callsign), toFSD(packetId), toFSD(data)(), data.size());
}
catch (...) { exceptionDispatcher(Q_FUNC_INFO); }
}
void CNetworkVatlib::sendIpQuery()
{
Q_ASSERT_X(isConnected(), "CNetworkVatlib", "Can't send to server when disconnected");
@@ -763,6 +811,11 @@ namespace BlackCore
emit cbvar_cast(cbvar)->pongReceived(cbvar_cast(cbvar)->fromFSD(callsign), CTime(elapsedTime, CTimeUnit::s()));
}
void CNetworkVatlib::onCustomPacketReceived(Cvatlib_Network *, const char *callsign, const char *packetId, const char **data, INT dataSize, void *cbvar)
{
emit cbvar_cast(cbvar)->customPacketReceived(cbvar_cast(cbvar)->fromFSD(callsign), cbvar_cast(cbvar)->fromFSD(packetId), cbvar_cast(cbvar)->fromFSD(data, dataSize));
}
void CNetworkVatlib::onMetarReceived(Cvatlib_Network *, const char *data, void *cbvar)
{
emit cbvar_cast(cbvar)->metarReplyReceived(cbvar_cast(cbvar)->fromFSD(data));