diff --git a/src/blackmisc/originator.cpp b/src/blackmisc/originator.cpp index ee5fff7dd..c76a7648d 100644 --- a/src/blackmisc/originator.cpp +++ b/src/blackmisc/originator.cpp @@ -10,22 +10,18 @@ #include "originator.h" #include #include +#include namespace BlackMisc { COriginator::COriginator(const QString &name) - : m_name(name), + : m_name(name.trimmed()), m_machineIdBase64(QDBusConnection::localMachineId().toBase64()), + m_machineName(QHostInfo::localHostName()), m_processName(QCoreApplication::applicationName()), - m_processId(QCoreApplication::applicationPid()), - m_timestampMsEpoch(QDateTime::currentMSecsSinceEpoch()) + m_processId(QCoreApplication::applicationPid()) { } - 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()); @@ -49,9 +45,9 @@ namespace BlackMisc QString COriginator::convertToQString(bool i18n) const { Q_UNUSED(i18n); - QString s; - s.append(m_name); + QString s(m_name); s.append(" ").append(m_machineIdBase64); + s.append(" ").append(m_machineName); s.append(" ").append(QString::number(m_processId)); s.append(" ").append(m_processName); return s; @@ -62,12 +58,16 @@ namespace BlackMisc if (index.isMyself()) { return this->toCVariant(); } ColumnIndex i = index.frontCasted(); + if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } + switch (i) { case IndexName: return CVariant::fromValue(m_name); case IndexMachineIdBase64: return CVariant::fromValue(m_machineIdBase64); + case IndexMachineName: + return CVariant::fromValue(getMachineName()); case IndexMachineId: return CVariant::fromValue(getMachineId()); case IndexProcessId: @@ -80,8 +80,6 @@ namespace BlackMisc return CVariant::fromValue(isFromSameProcess()); case IndexIsFromSameProcessName: return CVariant::fromValue(isFromSameProcessName()); - case IndexUtcTimestamp: - return CVariant::fromValue(getTimestamp()); default: return CValueObject::propertyByIndex(index); } diff --git a/src/blackmisc/originator.h b/src/blackmisc/originator.h index e395843fe..5ff1e1146 100644 --- a/src/blackmisc/originator.h +++ b/src/blackmisc/originator.h @@ -14,16 +14,17 @@ #include "blackmiscexport.h" #include "valueobject.h" +#include "timestampbased.h" #include "blackmiscfreefunctions.h" #include #include -class QObject; - namespace BlackMisc { //! Value object encapsulating information about the originiator - class BLACKMISC_EXPORT COriginator : public CValueObject + class BLACKMISC_EXPORT COriginator : + public CValueObject, + public ITimestampBased { public: //! Properties by index @@ -32,9 +33,9 @@ namespace BlackMisc IndexName = BlackMisc::CPropertyIndex::GlobalIndexOriginator, IndexMachineId, IndexMachineIdBase64, + IndexMachineName, IndexProcessId, IndexProcessName, - IndexUtcTimestamp, IndexIsFromLocalMachine, IndexIsFromSameProcess, IndexIsFromSameProcessName @@ -43,27 +44,27 @@ namespace BlackMisc //! 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; } + //! Has name + bool hasName() const { return !m_name.isEmpty(); } + //! Get machine id QByteArray getMachineId() const; //! Machine 64 base64 encoded QString getMachineIdBase64() const { return m_machineIdBase64; } + //! Machine name + QString getMachineName() const { return m_machineName; } + //! Get process id 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; @@ -84,21 +85,22 @@ namespace BlackMisc private: BLACK_ENABLE_TUPLE_CONVERSION(COriginator) - QString m_name; - QString m_machineIdBase64; // base 64 encoded + QString m_name; //!< originator name + QString m_machineIdBase64; //!< base 64 encoded machine id + QString m_machineName; //!< human readable machine name QString m_processName; qint64 m_processId; - qint64 m_timestampMsEpoch; }; } // namespace BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::COriginator, ( - attr(o.m_name), - attr(o.m_machineIdBase64), - attr(o.m_processName), - attr(o.m_processId), - attr(o.m_timestampMsEpoch, flags ()) -)) + attr(o.m_name), + attr(o.m_machineIdBase64), + attr(o.m_machineName, flags ()), + attr(o.m_processName), + attr(o.m_processId), + attr(o.m_timestampMSecsSinceEpoch, flags ()) + )) Q_DECLARE_METATYPE(BlackMisc::COriginator) diff --git a/src/blackmisc/originatorlist.cpp b/src/blackmisc/originatorlist.cpp new file mode 100644 index 000000000..e640939dc --- /dev/null +++ b/src/blackmisc/originatorlist.cpp @@ -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 &other) : + CSequence(other) + { } +} // namespace diff --git a/src/blackmisc/originatorlist.h b/src/blackmisc/originatorlist.h new file mode 100644 index 000000000..14d44ba1b --- /dev/null +++ b/src/blackmisc/originatorlist.h @@ -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, + public BlackMisc::Mixin::MetaType, + public BlackMisc::ITimestampObjectList + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(COriginatorList) + + //! Default constructor. + COriginatorList(); + + //! Construct from a base class object. + COriginatorList(const CSequence &other); + + }; +} //namespace + +Q_DECLARE_METATYPE(BlackMisc::COriginatorList) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/timestampbased.h b/src/blackmisc/timestampbased.h index 6c00f7a12..4c5ed61ab 100644 --- a/src/blackmisc/timestampbased.h +++ b/src/blackmisc/timestampbased.h @@ -105,5 +105,4 @@ namespace BlackMisc } // namespace - #endif // guard diff --git a/src/blackmisc/timestampobjectlist.cpp b/src/blackmisc/timestampobjectlist.cpp index ba548c275..f32b6d9a1 100644 --- a/src/blackmisc/timestampobjectlist.cpp +++ b/src/blackmisc/timestampobjectlist.cpp @@ -13,6 +13,7 @@ #include "blackmisc/aviation/aircraftpartslist.h" #include "blackmisc/network/textmessagelist.h" #include "blackmisc/statusmessagelist.h" +#include "blackmisc/originatorlist.h" #include #include @@ -172,5 +173,6 @@ namespace BlackMisc template class ITimestampObjectList; template class ITimestampObjectList; template class ITimestampObjectList; + template class ITimestampObjectList; } // namespace diff --git a/src/blackmisc/timestampobjectlist.h b/src/blackmisc/timestampobjectlist.h index ff1c38ed3..1bc4610c2 100644 --- a/src/blackmisc/timestampobjectlist.h +++ b/src/blackmisc/timestampobjectlist.h @@ -19,24 +19,6 @@ 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. //! Such objects should implement \sa ITimestampBased template @@ -102,10 +84,30 @@ namespace BlackMisc }; //! \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; extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; //! \endcond } //namespace