mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +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
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
COriginator::COriginator(const QString &name)
|
||||||
// Default constructor
|
: m_name(name),
|
||||||
COriginator::COriginator()
|
m_machineIdBase64(QDBusConnection::localMachineId().toBase64()),
|
||||||
: m_machineId(QDBusConnection::localMachineId()),
|
m_processName(QCoreApplication::applicationName()),
|
||||||
m_processId(QCoreApplication::applicationPid()),
|
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
|
bool COriginator::isFromLocalMachine() const
|
||||||
@@ -37,16 +46,50 @@ namespace BlackMisc
|
|||||||
return QCoreApplication::applicationName() == getProcessName();
|
return QCoreApplication::applicationName() == getProcessName();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString COriginator::convertToQString(bool /* i18n */) const
|
QString COriginator::convertToQString(bool i18n) const
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(i18n);
|
||||||
QString s;
|
QString s;
|
||||||
s.append(m_originatorName);
|
s.append(m_name);
|
||||||
s.append(" ").append(m_machineId);
|
s.append(" ").append(m_machineIdBase64);
|
||||||
s.append(" ").append(m_primaryIpAddress);
|
s.append(" ").append(QString::number(m_processId));
|
||||||
s.append(" ").append(m_objectId);
|
|
||||||
s.append(" ").append(m_processId);
|
|
||||||
s.append(" ").append(m_processName);
|
s.append(" ").append(m_processName);
|
||||||
return s;
|
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.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef BLACKMISC_EVENT_ORIGINATOR_H
|
#ifndef BLACKMISC_ORIGINATOR_H
|
||||||
#define BLACKMISC_EVENT_ORIGINATOR_H
|
#define BLACKMISC_ORIGINATOR_H
|
||||||
|
|
||||||
//! \file
|
//! \file
|
||||||
|
|
||||||
@@ -18,34 +18,52 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
class QObject;
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|
||||||
//! Value object encapsulating information about the originiator
|
//! Value object encapsulating information about the originiator
|
||||||
class BLACKMISC_EXPORT COriginator :
|
class BLACKMISC_EXPORT COriginator : public CValueObject<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>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Default constructor.
|
//! Properties by index
|
||||||
COriginator();
|
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
|
//! 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
|
//! Get process id
|
||||||
qint32 getProcessId() const {return m_processId;}
|
qint64 getProcessId() const {return m_processId;}
|
||||||
|
|
||||||
//! Get process name
|
//! Get process name
|
||||||
QString getProcessName() const {return m_processName;}
|
QString getProcessName() const {return m_processName;}
|
||||||
|
|
||||||
|
//! When created
|
||||||
|
QDateTime getTimestamp() const { return QDateTime::fromMSecsSinceEpoch(m_timestampMsEpoch); }
|
||||||
|
|
||||||
//! Check if originating from the same local machine
|
//! Check if originating from the same local machine
|
||||||
bool isFromLocalMachine() const;
|
bool isFromLocalMachine() const;
|
||||||
|
|
||||||
@@ -58,25 +76,30 @@ namespace BlackMisc
|
|||||||
//! \copydoc CValueObject::convertToQString
|
//! \copydoc CValueObject::convertToQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
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:
|
private:
|
||||||
BLACK_ENABLE_TUPLE_CONVERSION(COriginator)
|
BLACK_ENABLE_TUPLE_CONVERSION(COriginator)
|
||||||
QString m_originatorName;
|
QString m_name;
|
||||||
QByteArray m_machineId;
|
QString m_machineIdBase64; // base 64 encoded
|
||||||
QByteArray m_primaryIpAddress;
|
|
||||||
QByteArray m_objectId;
|
|
||||||
qint32 m_processId;
|
|
||||||
QString m_processName;
|
QString m_processName;
|
||||||
|
qint64 m_processId;
|
||||||
|
qint64 m_timestampMsEpoch;
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::COriginator, (
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::COriginator, (
|
||||||
o.m_originatorName,
|
attr(o.m_name),
|
||||||
o.m_machineId,
|
attr(o.m_machineIdBase64),
|
||||||
o.m_primaryIpAddress,
|
attr(o.m_processName),
|
||||||
o.m_objectId,
|
attr(o.m_processId),
|
||||||
o.m_processId,
|
attr(o.m_timestampMsEpoch, flags <DisabledForComparison | DisabledForHashing> ())
|
||||||
o.m_processName
|
|
||||||
))
|
))
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BlackMisc::COriginator)
|
Q_DECLARE_METATYPE(BlackMisc::COriginator)
|
||||||
|
|
||||||
#endif // BLACKMISC_EVENT_ORIGINATOR_H
|
#endif // guard
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ namespace BlackMisc
|
|||||||
GlobalIndexCStatusMessage = 200,
|
GlobalIndexCStatusMessage = 200,
|
||||||
GlobalIndexCNameVariantPair = 300,
|
GlobalIndexCNameVariantPair = 300,
|
||||||
GlobalIndexTimestampBased = 400,
|
GlobalIndexTimestampBased = 400,
|
||||||
|
GlobalIndexOriginator = 500,
|
||||||
GlobalIndexCCallsign = 1000,
|
GlobalIndexCCallsign = 1000,
|
||||||
GlobalIndexCAircraft = 1100,
|
GlobalIndexCAircraft = 1100,
|
||||||
GlobalIndexCAircraftSituation = 1200,
|
GlobalIndexCAircraftSituation = 1200,
|
||||||
|
|||||||
Reference in New Issue
Block a user