kopia lustrzana https://gitlab.com/eliggett/wfview
156 wiersze
6.0 KiB
C++
156 wiersze
6.0 KiB
C++
#ifndef RIGSTATEH
|
|
#define RIGSTATEH
|
|
|
|
#include <QObject>
|
|
#include <QMutex>
|
|
#include <QDateTime>
|
|
#include <QVariant>
|
|
#include <QMap>
|
|
#include <QCache>
|
|
|
|
#include "rigcommander.h"
|
|
#include "rigidentities.h"
|
|
#include "wfviewtypes.h"
|
|
|
|
|
|
|
|
//* std::static_pointer_cast<unsigned char>(data)
|
|
struct value {
|
|
bool _valid = false;
|
|
bool _updated = false;
|
|
QDateTime _dateUpdated;
|
|
std::shared_ptr<void> _value = Q_NULLPTR;
|
|
};
|
|
|
|
class rigstate
|
|
{
|
|
|
|
public:
|
|
|
|
void invalidate(stateTypes s) { map[s]._valid = false; }
|
|
bool isValid(stateTypes s) { return map[s]._valid; }
|
|
bool isUpdated(stateTypes s) { return map[s]._updated; }
|
|
QDateTime whenUpdated(stateTypes s) { return map[s]._dateUpdated; }
|
|
|
|
void set(stateTypes s, quint64 x, bool u) {
|
|
auto d = (std::static_pointer_cast<quint64>(map[s]._value));
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<quint64>(new quint64(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
void set(stateTypes s, qint32 x, bool u) {
|
|
auto d = (std::static_pointer_cast<quint32>(map[s]._value));
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<qint32>(new qint32(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
void set(stateTypes s, qint16 x, bool u) {
|
|
auto d = (std::static_pointer_cast<qint16>(map[s]._value));
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<qint16>(new qint16(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
void set(stateTypes s, quint16 x, bool u) {
|
|
auto d = (std::static_pointer_cast<quint16>(map[s]._value));
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<quint16>(new quint16(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
void set(stateTypes s, quint8 x, bool u) {
|
|
auto d = (std::static_pointer_cast<quint8>(map[s]._value));
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<quint8>(new quint8(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
void set(stateTypes s, bool x, bool u) {
|
|
auto d = std::static_pointer_cast<bool>(map[s]._value);
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<bool>(new bool(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
void set(stateTypes s, duplexMode x, bool u) {
|
|
auto d = (std::static_pointer_cast<duplexMode>(map[s]._value));
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<duplexMode>(new duplexMode(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
|
|
void set(stateTypes s, rigInput x, bool u) {
|
|
auto d = (std::static_pointer_cast<rigInput>(map[s]._value));
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<rigInput>(new rigInput(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
|
|
void set(stateTypes s, QString x, bool u) {
|
|
auto d = (std::static_pointer_cast<QString>(map[s]._value));
|
|
if (d == Q_NULLPTR || *d != x) {
|
|
_mutex.lock();
|
|
map[s]._value = std::shared_ptr<QString>(new QString(x));
|
|
map[s]._valid = true;
|
|
map[s]._updated = u;
|
|
map[s]._dateUpdated = QDateTime::currentDateTime();
|
|
_mutex.unlock();
|
|
}
|
|
}
|
|
|
|
bool getBool(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<bool>(map[s]._value); else return false; }
|
|
quint8 getChar(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<quint8>(map[s]._value); else return 0; }
|
|
qint16 getInt16(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<qint16>(map[s]._value); else return 0;}
|
|
quint16 getUInt16(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<quint16>(map[s]._value); else return 0;}
|
|
qint32 getInt32(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<qint32>(map[s]._value); else return 0;}
|
|
quint32 getUInt32(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<quint32>(map[s]._value); else return 0;}
|
|
quint64 getInt64(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<qint64>(map[s]._value); else return 0;}
|
|
duplexMode getDuplex(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<duplexMode>(map[s]._value); else return dmSplitOff;}
|
|
rigInput getInput(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<rigInput>(map[s]._value); else return inputACC; }
|
|
QString getString(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<QString>(map[s]._value); else return QString(""); }
|
|
QMap<stateTypes, value> map;
|
|
|
|
|
|
private:
|
|
//std::map<stateTypes, std::unique_ptr<valueBase> > values;
|
|
QMutex _mutex;
|
|
};
|
|
|
|
#endif
|