Ref T259, Ref T243 client provider used to share info about the other clients

Goal: this info can be used in interpolation to decide if ground flags, parts etc are available
This commit is contained in:
Klaus Basan
2018-03-08 18:51:42 +01:00
parent 42ef7c5633
commit f64a4c432b
5 changed files with 257 additions and 106 deletions

View File

@@ -0,0 +1,116 @@
/* Copyright (C) 2018
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_NETWORK_CLIENTPROVIDER_H
#define BLACKMISC_NETWORK_CLIENTPROVIDER_H
#include "clientlist.h"
#include "blackmisc/aviation/callsignset.h"
#include "blackmisc/provider.h"
#include <QReadWriteLock>
namespace BlackMisc
{
namespace Network
{
//! Direct in memory access to client (network client) data
class BLACKMISC_EXPORT IClientProvider : public IProvider
{
public:
//! Get other clients
//! \threadsafe
CClientList getClients() const;
//! Set other clients
//! \threadsafe
void setClients(const CClientList &clients);
//! Set other clients
//! \threadsafe
void clearClients();
//! Returns a list of other clients corresponding to the given callsigns
//! \threadsafe
BlackMisc::Network::CClientList getClientsForCallsigns(const Aviation::CCallsignSet &callsigns) const;
//! Other client for the given callsigns
//! \threadsafe
BlackMisc::Network::CClient getClientOrDefaultForCallsign(const Aviation::CCallsign &callsign) const;
//! Client info for given callsign?
//! \threadsafe
bool hasClientInfo(const Aviation::CCallsign &callsign) const;
//! Add a new client, if existing nothing will be added
//! \threadsafe
bool addNewClient(const CClient &client);
//! Update or add a client
//! \threadsafe
int updateOrAddClient(const Aviation::CCallsign &callsign, const CPropertyIndexVariantMap &vm, bool skipEqualValues = true);
//! Remove client
//! \threadsafe
int removeClient(const Aviation::CCallsign &callsign);
private:
CClientList m_clients;
mutable QReadWriteLock m_lockClient; //!< lock clients: m_clients
};
//! Class which can be directly used to access an \sa IClientProvider object
class BLACKMISC_EXPORT CClientAware : public IProviderAware<IClientProvider>
{
public:
//! \copydoc IClientProvider::getClients
CClientList getClients() const;
//! \copydoc IClientProvider::setClients
void setClients(const CClientList &clients);
//! \copydoc IClientProvider::clearClients
void clearClients();
//! \copydoc IClientProvider::getClientsForCallsigns
BlackMisc::Network::CClientList getClientsForCallsigns(const Aviation::CCallsignSet &callsigns) const;
//! \copydoc IClientProvider::getClientOrDefaultForCallsign
BlackMisc::Network::CClient getClientOrDefaultForCallsign(const Aviation::CCallsign &callsign) const;
//! \copydoc IClientProvider::hasClientInfo
bool hasClientInfo(const Aviation::CCallsign &callsign) const;
//! \copydoc IClientProvider::addNewClient
bool addNewClient(const CClient &client);
//! \copydoc IClientProvider::updateOrAddClient
int updateOrAddClient(const Aviation::CCallsign &callsign, const CPropertyIndexVariantMap &vm, bool skipEqualValues);
//! \copydoc IClientProvider::removeClient
int removeClient(const Aviation::CCallsign &callsign);
//! Provider
void setClientProvider(IClientProvider *provider) { this->setProvider(provider); }
protected:
//! Default constructor
CClientAware() {}
//! Constructor
CClientAware(IClientProvider *clientProvider) : m_clientProvider(clientProvider) { Q_ASSERT(clientProvider); }
IClientProvider *m_clientProvider = nullptr; //!< access to object
};
} // namespace
} // namespace
Q_DECLARE_INTERFACE(BlackMisc::Network::IClientProvider, "BlackMisc::Network::IClientProvider")
#endif // guard