mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
refs #428 Add additional COriginator constructors and methods
One constructor will accept a QString argument directly and use it as the originator name. The other one accepting the a pointer to QObject will use QObject's objectName.
This commit is contained in:
@@ -13,13 +13,22 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
// Default constructor
|
||||
COriginator::COriginator()
|
||||
: m_machineId(QDBusConnection::localMachineId()),
|
||||
COriginator::COriginator(const QString &name)
|
||||
: m_name(name),
|
||||
m_machineIdBase64(QDBusConnection::localMachineId().toBase64()),
|
||||
m_processName(QCoreApplication::applicationName()),
|
||||
m_processId(QCoreApplication::applicationPid()),
|
||||
m_processName(QCoreApplication::applicationName())
|
||||
m_timestampMsEpoch(QDateTime::currentMSecsSinceEpoch())
|
||||
{ }
|
||||
|
||||
COriginator::COriginator(const QObject *object) : COriginator(object->objectName())
|
||||
{
|
||||
Q_ASSERT_X(!object->objectName().isEmpty(), Q_FUNC_INFO, "Missing name");
|
||||
}
|
||||
|
||||
QByteArray COriginator::getMachineId() const
|
||||
{
|
||||
return QByteArray::fromBase64(m_machineIdBase64.toLocal8Bit());
|
||||
}
|
||||
|
||||
bool COriginator::isFromLocalMachine() const
|
||||
@@ -37,16 +46,50 @@ namespace BlackMisc
|
||||
return QCoreApplication::applicationName() == getProcessName();
|
||||
}
|
||||
|
||||
QString COriginator::convertToQString(bool /* i18n */) const
|
||||
QString COriginator::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s;
|
||||
s.append(m_originatorName);
|
||||
s.append(" ").append(m_machineId);
|
||||
s.append(" ").append(m_primaryIpAddress);
|
||||
s.append(" ").append(m_objectId);
|
||||
s.append(" ").append(m_processId);
|
||||
s.append(m_name);
|
||||
s.append(" ").append(m_machineIdBase64);
|
||||
s.append(" ").append(QString::number(m_processId));
|
||||
s.append(" ").append(m_processName);
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
CVariant COriginator::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->toCVariant(); }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexName:
|
||||
return CVariant::fromValue(m_name);
|
||||
case IndexMachineIdBase64:
|
||||
return CVariant::fromValue(m_machineIdBase64);
|
||||
case IndexMachineId:
|
||||
return CVariant::fromValue(getMachineId());
|
||||
case IndexProcessId:
|
||||
return CVariant::fromValue(m_processId);
|
||||
case IndexProcessName:
|
||||
return CVariant::fromValue(m_processName);
|
||||
case IndexIsFromLocalMachine:
|
||||
return CVariant::fromValue(isFromLocalMachine());
|
||||
case IndexIsFromSameProcess:
|
||||
return CVariant::fromValue(isFromSameProcess());
|
||||
case IndexIsFromSameProcessName:
|
||||
return CVariant::fromValue(isFromSameProcessName());
|
||||
case IndexUtcTimestamp:
|
||||
return CVariant::fromValue(getTimestamp());
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void COriginator::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISC_EVENT_ORIGINATOR_H
|
||||
#define BLACKMISC_EVENT_ORIGINATOR_H
|
||||
#ifndef BLACKMISC_ORIGINATOR_H
|
||||
#define BLACKMISC_ORIGINATOR_H
|
||||
|
||||
//! \file
|
||||
|
||||
@@ -18,34 +18,52 @@
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
//! Value object encapsulating information about the originiator
|
||||
class BLACKMISC_EXPORT COriginator :
|
||||
public Mixin::MetaType<COriginator>,
|
||||
public Mixin::HashByTuple<COriginator>,
|
||||
public Mixin::DBusByTuple<COriginator>,
|
||||
public Mixin::EqualsByTuple<COriginator>,
|
||||
public Mixin::LessThanByTuple<COriginator>,
|
||||
public Mixin::CompareByTuple<COriginator>,
|
||||
public Mixin::Index<COriginator>,
|
||||
public Mixin::String<COriginator>,
|
||||
public Mixin::Icon<COriginator>
|
||||
class BLACKMISC_EXPORT COriginator : public CValueObject<COriginator>
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
COriginator();
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexName = BlackMisc::CPropertyIndex::GlobalIndexOriginator,
|
||||
IndexMachineId,
|
||||
IndexMachineIdBase64,
|
||||
IndexProcessId,
|
||||
IndexProcessName,
|
||||
IndexUtcTimestamp,
|
||||
IndexIsFromLocalMachine,
|
||||
IndexIsFromSameProcess,
|
||||
IndexIsFromSameProcessName
|
||||
};
|
||||
|
||||
//! Constructor.
|
||||
COriginator(const QString &name = QString());
|
||||
|
||||
//! Constructor using the objectName of object as name
|
||||
COriginator(const QObject *object);
|
||||
|
||||
//! Name
|
||||
QString getName() const { return m_name; }
|
||||
|
||||
//! Get machine id
|
||||
QByteArray getMachineId() const {return m_machineId;}
|
||||
QByteArray getMachineId() const;
|
||||
|
||||
//! Machine 64 base64 encoded
|
||||
QString getMachineIdBase64() const { return m_machineIdBase64; }
|
||||
|
||||
//! Get process id
|
||||
qint32 getProcessId() const {return m_processId;}
|
||||
qint64 getProcessId() const {return m_processId;}
|
||||
|
||||
//! Get process name
|
||||
QString getProcessName() const {return m_processName;}
|
||||
|
||||
//! When created
|
||||
QDateTime getTimestamp() const { return QDateTime::fromMSecsSinceEpoch(m_timestampMsEpoch); }
|
||||
|
||||
//! Check if originating from the same local machine
|
||||
bool isFromLocalMachine() const;
|
||||
|
||||
@@ -58,25 +76,30 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(COriginator)
|
||||
QString m_originatorName;
|
||||
QByteArray m_machineId;
|
||||
QByteArray m_primaryIpAddress;
|
||||
QByteArray m_objectId;
|
||||
qint32 m_processId;
|
||||
QString m_name;
|
||||
QString m_machineIdBase64; // base 64 encoded
|
||||
QString m_processName;
|
||||
qint64 m_processId;
|
||||
qint64 m_timestampMsEpoch;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::COriginator, (
|
||||
o.m_originatorName,
|
||||
o.m_machineId,
|
||||
o.m_primaryIpAddress,
|
||||
o.m_objectId,
|
||||
o.m_processId,
|
||||
o.m_processName
|
||||
attr(o.m_name),
|
||||
attr(o.m_machineIdBase64),
|
||||
attr(o.m_processName),
|
||||
attr(o.m_processId),
|
||||
attr(o.m_timestampMsEpoch, flags <DisabledForComparison | DisabledForHashing> ())
|
||||
))
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::COriginator)
|
||||
|
||||
#endif // BLACKMISC_EVENT_ORIGINATOR_H
|
||||
#endif // guard
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace BlackMisc
|
||||
GlobalIndexCStatusMessage = 200,
|
||||
GlobalIndexCNameVariantPair = 300,
|
||||
GlobalIndexTimestampBased = 400,
|
||||
GlobalIndexOriginator = 500,
|
||||
GlobalIndexCCallsign = 1000,
|
||||
GlobalIndexCAircraft = 1100,
|
||||
GlobalIndexCAircraftSituation = 1200,
|
||||
|
||||
Reference in New Issue
Block a user