mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 05:51:23 +08:00
* originator, machine name, timestamp based, connect with QObject's &QObject::objectNameChanged * list
This commit is contained in:
@@ -10,22 +10,18 @@
|
|||||||
#include "originator.h"
|
#include "originator.h"
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
|
#include <QHostInfo>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
COriginator::COriginator(const QString &name)
|
COriginator::COriginator(const QString &name)
|
||||||
: m_name(name),
|
: m_name(name.trimmed()),
|
||||||
m_machineIdBase64(QDBusConnection::localMachineId().toBase64()),
|
m_machineIdBase64(QDBusConnection::localMachineId().toBase64()),
|
||||||
|
m_machineName(QHostInfo::localHostName()),
|
||||||
m_processName(QCoreApplication::applicationName()),
|
m_processName(QCoreApplication::applicationName()),
|
||||||
m_processId(QCoreApplication::applicationPid()),
|
m_processId(QCoreApplication::applicationPid())
|
||||||
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
|
QByteArray COriginator::getMachineId() const
|
||||||
{
|
{
|
||||||
return QByteArray::fromBase64(m_machineIdBase64.toLocal8Bit());
|
return QByteArray::fromBase64(m_machineIdBase64.toLocal8Bit());
|
||||||
@@ -49,9 +45,9 @@ namespace BlackMisc
|
|||||||
QString COriginator::convertToQString(bool i18n) const
|
QString COriginator::convertToQString(bool i18n) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(i18n);
|
Q_UNUSED(i18n);
|
||||||
QString s;
|
QString s(m_name);
|
||||||
s.append(m_name);
|
|
||||||
s.append(" ").append(m_machineIdBase64);
|
s.append(" ").append(m_machineIdBase64);
|
||||||
|
s.append(" ").append(m_machineName);
|
||||||
s.append(" ").append(QString::number(m_processId));
|
s.append(" ").append(QString::number(m_processId));
|
||||||
s.append(" ").append(m_processName);
|
s.append(" ").append(m_processName);
|
||||||
return s;
|
return s;
|
||||||
@@ -62,12 +58,16 @@ namespace BlackMisc
|
|||||||
if (index.isMyself()) { return this->toCVariant(); }
|
if (index.isMyself()) { return this->toCVariant(); }
|
||||||
|
|
||||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
|
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||||
|
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case IndexName:
|
case IndexName:
|
||||||
return CVariant::fromValue(m_name);
|
return CVariant::fromValue(m_name);
|
||||||
case IndexMachineIdBase64:
|
case IndexMachineIdBase64:
|
||||||
return CVariant::fromValue(m_machineIdBase64);
|
return CVariant::fromValue(m_machineIdBase64);
|
||||||
|
case IndexMachineName:
|
||||||
|
return CVariant::fromValue(getMachineName());
|
||||||
case IndexMachineId:
|
case IndexMachineId:
|
||||||
return CVariant::fromValue(getMachineId());
|
return CVariant::fromValue(getMachineId());
|
||||||
case IndexProcessId:
|
case IndexProcessId:
|
||||||
@@ -80,8 +80,6 @@ namespace BlackMisc
|
|||||||
return CVariant::fromValue(isFromSameProcess());
|
return CVariant::fromValue(isFromSameProcess());
|
||||||
case IndexIsFromSameProcessName:
|
case IndexIsFromSameProcessName:
|
||||||
return CVariant::fromValue(isFromSameProcessName());
|
return CVariant::fromValue(isFromSameProcessName());
|
||||||
case IndexUtcTimestamp:
|
|
||||||
return CVariant::fromValue(getTimestamp());
|
|
||||||
default:
|
default:
|
||||||
return CValueObject::propertyByIndex(index);
|
return CValueObject::propertyByIndex(index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,17 @@
|
|||||||
|
|
||||||
#include "blackmiscexport.h"
|
#include "blackmiscexport.h"
|
||||||
#include "valueobject.h"
|
#include "valueobject.h"
|
||||||
|
#include "timestampbased.h"
|
||||||
#include "blackmiscfreefunctions.h"
|
#include "blackmiscfreefunctions.h"
|
||||||
#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 : public CValueObject<COriginator>
|
class BLACKMISC_EXPORT COriginator :
|
||||||
|
public CValueObject<COriginator>,
|
||||||
|
public ITimestampBased
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Properties by index
|
//! Properties by index
|
||||||
@@ -32,9 +33,9 @@ namespace BlackMisc
|
|||||||
IndexName = BlackMisc::CPropertyIndex::GlobalIndexOriginator,
|
IndexName = BlackMisc::CPropertyIndex::GlobalIndexOriginator,
|
||||||
IndexMachineId,
|
IndexMachineId,
|
||||||
IndexMachineIdBase64,
|
IndexMachineIdBase64,
|
||||||
|
IndexMachineName,
|
||||||
IndexProcessId,
|
IndexProcessId,
|
||||||
IndexProcessName,
|
IndexProcessName,
|
||||||
IndexUtcTimestamp,
|
|
||||||
IndexIsFromLocalMachine,
|
IndexIsFromLocalMachine,
|
||||||
IndexIsFromSameProcess,
|
IndexIsFromSameProcess,
|
||||||
IndexIsFromSameProcessName
|
IndexIsFromSameProcessName
|
||||||
@@ -43,27 +44,27 @@ namespace BlackMisc
|
|||||||
//! Constructor.
|
//! Constructor.
|
||||||
COriginator(const QString &name = QString());
|
COriginator(const QString &name = QString());
|
||||||
|
|
||||||
//! Constructor using the objectName of object as name
|
|
||||||
COriginator(const QObject *object);
|
|
||||||
|
|
||||||
//! Name
|
//! Name
|
||||||
QString getName() const { return m_name; }
|
QString getName() const { return m_name; }
|
||||||
|
|
||||||
|
//! Has name
|
||||||
|
bool hasName() const { return !m_name.isEmpty(); }
|
||||||
|
|
||||||
//! Get machine id
|
//! Get machine id
|
||||||
QByteArray getMachineId() const;
|
QByteArray getMachineId() const;
|
||||||
|
|
||||||
//! Machine 64 base64 encoded
|
//! Machine 64 base64 encoded
|
||||||
QString getMachineIdBase64() const { return m_machineIdBase64; }
|
QString getMachineIdBase64() const { return m_machineIdBase64; }
|
||||||
|
|
||||||
|
//! Machine name
|
||||||
|
QString getMachineName() const { return m_machineName; }
|
||||||
|
|
||||||
//! Get process id
|
//! Get process id
|
||||||
qint64 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;
|
||||||
|
|
||||||
@@ -84,21 +85,22 @@ namespace BlackMisc
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BLACK_ENABLE_TUPLE_CONVERSION(COriginator)
|
BLACK_ENABLE_TUPLE_CONVERSION(COriginator)
|
||||||
QString m_name;
|
QString m_name; //!< originator name
|
||||||
QString m_machineIdBase64; // base 64 encoded
|
QString m_machineIdBase64; //!< base 64 encoded machine id
|
||||||
|
QString m_machineName; //!< human readable machine name
|
||||||
QString m_processName;
|
QString m_processName;
|
||||||
qint64 m_processId;
|
qint64 m_processId;
|
||||||
qint64 m_timestampMsEpoch;
|
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::COriginator, (
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::COriginator, (
|
||||||
attr(o.m_name),
|
attr(o.m_name),
|
||||||
attr(o.m_machineIdBase64),
|
attr(o.m_machineIdBase64),
|
||||||
|
attr(o.m_machineName, flags <DisabledForComparison | DisabledForHashing> ()),
|
||||||
attr(o.m_processName),
|
attr(o.m_processName),
|
||||||
attr(o.m_processId),
|
attr(o.m_processId),
|
||||||
attr(o.m_timestampMsEpoch, flags <DisabledForComparison | DisabledForHashing> ())
|
attr(o.m_timestampMSecsSinceEpoch, flags <DisabledForComparison | DisabledForHashing> ())
|
||||||
))
|
))
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BlackMisc::COriginator)
|
Q_DECLARE_METATYPE(BlackMisc::COriginator)
|
||||||
|
|
||||||
|
|||||||
20
src/blackmisc/originatorlist.cpp
Normal file
20
src/blackmisc/originatorlist.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "originatorlist.h"
|
||||||
|
#include "predicates.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
COriginatorList::COriginatorList() { }
|
||||||
|
|
||||||
|
COriginatorList::COriginatorList(const CSequence<BlackMisc::COriginator> &other) :
|
||||||
|
CSequence<BlackMisc::COriginator>(other)
|
||||||
|
{ }
|
||||||
|
} // namespace
|
||||||
45
src/blackmisc/originatorlist.h
Normal file
45
src/blackmisc/originatorlist.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* 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_ORIGINATORLIST_H
|
||||||
|
#define BLACKMISC_ORIGINATORLIST_H
|
||||||
|
|
||||||
|
#include "blackmiscexport.h"
|
||||||
|
#include "blackmisc/originator.h"
|
||||||
|
#include "collection.h"
|
||||||
|
#include "sequence.h"
|
||||||
|
#include "timestampobjectlist.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
//! Value object encapsulating a list of originator objects
|
||||||
|
class BLACKMISC_EXPORT COriginatorList :
|
||||||
|
public CSequence<BlackMisc::COriginator>,
|
||||||
|
public BlackMisc::Mixin::MetaType<COriginatorList>,
|
||||||
|
public BlackMisc::ITimestampObjectList<COriginator, COriginatorList>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(COriginatorList)
|
||||||
|
|
||||||
|
//! Default constructor.
|
||||||
|
COriginatorList();
|
||||||
|
|
||||||
|
//! Construct from a base class object.
|
||||||
|
COriginatorList(const CSequence<BlackMisc::COriginator> &other);
|
||||||
|
|
||||||
|
};
|
||||||
|
} //namespace
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::COriginatorList)
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::COriginator>)
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::COriginator>)
|
||||||
|
|
||||||
|
#endif //guard
|
||||||
@@ -105,5 +105,4 @@ namespace BlackMisc
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "blackmisc/aviation/aircraftpartslist.h"
|
#include "blackmisc/aviation/aircraftpartslist.h"
|
||||||
#include "blackmisc/network/textmessagelist.h"
|
#include "blackmisc/network/textmessagelist.h"
|
||||||
#include "blackmisc/statusmessagelist.h"
|
#include "blackmisc/statusmessagelist.h"
|
||||||
|
#include "blackmisc/originatorlist.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
@@ -172,5 +173,6 @@ namespace BlackMisc
|
|||||||
template class ITimestampObjectList<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList>;
|
template class ITimestampObjectList<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList>;
|
||||||
template class ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
template class ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
||||||
template class ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
template class ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
||||||
|
template class ITimestampObjectList<BlackMisc::COriginator, BlackMisc::COriginatorList>;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -19,24 +19,6 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
namespace Aviation
|
|
||||||
{
|
|
||||||
class CAircraftSituation;
|
|
||||||
class CAircraftSituationList;
|
|
||||||
class CAircraftParts;
|
|
||||||
class CAircraftPartsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Network
|
|
||||||
{
|
|
||||||
class CTextMessage;
|
|
||||||
class CTextMessageList;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CStatusMessage;
|
|
||||||
class CStatusMessageList;
|
|
||||||
|
|
||||||
|
|
||||||
//! List of objects with timestamp.
|
//! List of objects with timestamp.
|
||||||
//! Such objects should implement \sa ITimestampBased
|
//! Such objects should implement \sa ITimestampBased
|
||||||
template<class OBJ, class CONTAINER>
|
template<class OBJ, class CONTAINER>
|
||||||
@@ -102,10 +84,30 @@ namespace BlackMisc
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! \cond PRIVATE
|
//! \cond PRIVATE
|
||||||
|
namespace Aviation
|
||||||
|
{
|
||||||
|
class CAircraftSituation;
|
||||||
|
class CAircraftSituationList;
|
||||||
|
class CAircraftParts;
|
||||||
|
class CAircraftPartsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
class CTextMessage;
|
||||||
|
class CTextMessageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CStatusMessage;
|
||||||
|
class CStatusMessageList;
|
||||||
|
class COriginator;
|
||||||
|
class COriginatorList;
|
||||||
|
|
||||||
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList>;
|
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList>;
|
||||||
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList>;
|
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList>;
|
||||||
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
||||||
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
||||||
|
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::COriginator, BlackMisc::COriginatorList>;
|
||||||
//! \endcond
|
//! \endcond
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user