65 lines
1.3 KiB
C++
Executable File
65 lines
1.3 KiB
C++
Executable File
#pragma once
|
|
|
|
#include <Core/core_dtc.h>
|
|
|
|
#include <QSet>
|
|
#include <QString>
|
|
|
|
|
|
namespace DDSConnector
|
|
{
|
|
class DdsConnector;
|
|
}
|
|
|
|
namespace Core
|
|
{
|
|
|
|
struct key
|
|
{
|
|
inline key() = default;
|
|
inline key(int64_t id, int exId, const QString &name)
|
|
: entityTypeName(name)
|
|
, entityId(id)
|
|
, exerciseId(exId)
|
|
{}
|
|
|
|
inline bool operator==(const key &o) const
|
|
{
|
|
return entityId == o.entityId &&
|
|
exerciseId == o.exerciseId &&
|
|
entityTypeName == o.entityTypeName;
|
|
}
|
|
|
|
QString entityTypeName;
|
|
int64_t entityId = 0;
|
|
int exerciseId = 0;
|
|
};
|
|
|
|
inline uint qHash(const Core::key &k, uint seed = 0)
|
|
{
|
|
return ::qHash(k.entityTypeName, seed) ^ ::qHash(k.entityId, seed) ^ ::qHash(k.exerciseId, seed);
|
|
}
|
|
|
|
class CORE_CLIENT_EXPORT TopicLockMaster : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit TopicLockMaster(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector);
|
|
~TopicLockMaster();
|
|
|
|
bool init(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector);
|
|
|
|
template<typename E>
|
|
bool isLocked(const E &data, int exerciseId)
|
|
{
|
|
auto it = m_lockedEntitys.constFind(key(data.id(), exerciseId, QString::fromStdString(typeid(E).name())));
|
|
return !(it == m_lockedEntitys.cend());
|
|
}
|
|
|
|
private:
|
|
QSet<key> m_lockedEntitys;
|
|
std::shared_ptr<Core::Interface::Dtc> m_coreDtc;
|
|
};
|
|
|
|
}
|