mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
Ref T280, clients as callsign map as this is faster
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "clientlist.h"
|
#include "clientlist.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
namespace Network
|
namespace Network
|
||||||
@@ -28,5 +30,15 @@ namespace BlackMisc
|
|||||||
if (this->isEmpty()) { return static_cast<CClient::Capabilities>(CClient::None); }
|
if (this->isEmpty()) { return static_cast<CClient::Capabilities>(CClient::None); }
|
||||||
return this->findFirstByCallsign(callsign).getCapabilities();
|
return this->findFirstByCallsign(callsign).getCapabilities();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<CCallsign, CClient> CClientList::asMap() const
|
||||||
|
{
|
||||||
|
QMap<CCallsign, CClient> map;
|
||||||
|
for (const CClient &client : *this)
|
||||||
|
{
|
||||||
|
map.insert(client.getCallsign(), client);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "blackmisc/network/client.h"
|
#include "blackmisc/network/client.h"
|
||||||
#include "blackmisc/sequence.h"
|
#include "blackmisc/sequence.h"
|
||||||
#include "blackmisc/variant.h"
|
#include "blackmisc/variant.h"
|
||||||
|
#include <QMap>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
@@ -44,6 +45,9 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! Capabilities of client for callsign
|
//! Capabilities of client for callsign
|
||||||
CClient::Capabilities getCapabilities(const Aviation::CCallsign &callsign) const;
|
CClient::Capabilities getCapabilities(const Aviation::CCallsign &callsign) const;
|
||||||
|
|
||||||
|
//! As map
|
||||||
|
QMap<Aviation::CCallsign, CClient> asMap() const;
|
||||||
};
|
};
|
||||||
} //namespace
|
} //namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -17,15 +17,20 @@ namespace BlackMisc
|
|||||||
namespace Network
|
namespace Network
|
||||||
{
|
{
|
||||||
CClientList CClientProvider::getClients() const
|
CClientList CClientProvider::getClients() const
|
||||||
|
{
|
||||||
|
QList<CClient> clients;
|
||||||
{
|
{
|
||||||
QReadLocker l(&m_lockClient);
|
QReadLocker l(&m_lockClient);
|
||||||
return m_clients;
|
clients = m_clients.values();
|
||||||
|
}
|
||||||
|
return CClientList(clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClientProvider::setClients(const CClientList &clients)
|
void CClientProvider::setClients(const CClientList &clients)
|
||||||
{
|
{
|
||||||
|
const QMap<CCallsign, CClient> map = clients.asMap();
|
||||||
QWriteLocker l(&m_lockClient);
|
QWriteLocker l(&m_lockClient);
|
||||||
m_clients = clients;
|
m_clients = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClientProvider::clearClients()
|
void CClientProvider::clearClients()
|
||||||
@@ -41,20 +46,21 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CClient CClientProvider::getClientOrDefaultForCallsign(const CCallsign &callsign) const
|
CClient CClientProvider::getClientOrDefaultForCallsign(const CCallsign &callsign) const
|
||||||
{
|
{
|
||||||
const CClientList clients(this->getClients());
|
QReadLocker l(&m_lockClient);
|
||||||
return clients.findFirstByCallsign(callsign);
|
return m_clients.value(callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClientProvider::setOtherClient(const CClient &client)
|
bool CClientProvider::setOtherClient(const CClient &client)
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockClient);
|
QWriteLocker l(&m_lockClient);
|
||||||
m_clients.replaceOrAddObjectByCallsign(client);
|
m_clients[client.getCallsign()] = client;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClientProvider::hasClientInfo(const CCallsign &callsign) const
|
bool CClientProvider::hasClientInfo(const CCallsign &callsign) const
|
||||||
{
|
{
|
||||||
return this->getClients().containsCallsign(callsign);
|
QReadLocker l(&m_lockClient);
|
||||||
|
return m_clients.contains(callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClientProvider::addNewClient(const CClient &client)
|
bool CClientProvider::addNewClient(const CClient &client)
|
||||||
@@ -63,7 +69,7 @@ namespace BlackMisc
|
|||||||
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "invalid callsign");
|
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "invalid callsign");
|
||||||
if (this->hasClientInfo(callsign)) { return false; }
|
if (this->hasClientInfo(callsign)) { return false; }
|
||||||
QWriteLocker l(&m_lockClient);
|
QWriteLocker l(&m_lockClient);
|
||||||
m_clients.push_back(client);
|
m_clients[callsign] = client;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,16 +77,18 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing callsign");
|
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing callsign");
|
||||||
int c = 0;
|
int c = 0;
|
||||||
if (!this->hasClientInfo(callsign))
|
if (this->hasClientInfo(callsign))
|
||||||
{
|
{
|
||||||
CClient client(callsign);
|
QWriteLocker l(&m_lockClient);
|
||||||
c = client.apply(vm).size();
|
CClient &client = m_clients[callsign];
|
||||||
this->addNewClient(client);
|
c = client.apply(vm, skipEqualValues).size();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
CClient client(callsign);
|
||||||
|
c = client.apply(vm).size();
|
||||||
QWriteLocker l(&m_lockClient);
|
QWriteLocker l(&m_lockClient);
|
||||||
c = m_clients.applyIfCallsign(callsign, vm, skipEqualValues);
|
m_clients[callsign] = client;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -88,7 +96,7 @@ namespace BlackMisc
|
|||||||
int CClientProvider::removeClient(const CCallsign &callsign)
|
int CClientProvider::removeClient(const CCallsign &callsign)
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockClient);
|
QWriteLocker l(&m_lockClient);
|
||||||
return m_clients.removeByCallsign(callsign);
|
return m_clients.remove(callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClientProvider::autoAdjustCientGndCapability(const CAircraftSituation &situation)
|
bool CClientProvider::autoAdjustCientGndCapability(const CAircraftSituation &situation)
|
||||||
@@ -120,7 +128,7 @@ namespace BlackMisc
|
|||||||
client.removeCapability(CClient::FsdWithGroundFlag);
|
client.removeCapability(CClient::FsdWithGroundFlag);
|
||||||
}
|
}
|
||||||
QWriteLocker l(&m_lockClient);
|
QWriteLocker l(&m_lockClient);
|
||||||
m_clients.replaceOrAddObjectByCallsign(client);
|
m_clients[callsign] = client;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "blackmisc/aviation/callsignset.h"
|
#include "blackmisc/aviation/callsignset.h"
|
||||||
#include "blackmisc/provider.h"
|
#include "blackmisc/provider.h"
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -101,7 +102,7 @@ namespace BlackMisc
|
|||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CClientList m_clients;
|
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Network::CClient> m_clients;
|
||||||
mutable QReadWriteLock m_lockClient; //!< lock clients: m_clients
|
mutable QReadWriteLock m_lockClient; //!< lock clients: m_clients
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user