mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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 <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QHostInfo>
|
||||
|
||||
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<ColumnIndex>();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -14,16 +14,17 @@
|
||||
|
||||
#include "blackmiscexport.h"
|
||||
#include "valueobject.h"
|
||||
#include "timestampbased.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
//! Value object encapsulating information about the originiator
|
||||
class BLACKMISC_EXPORT COriginator : public CValueObject<COriginator>
|
||||
class BLACKMISC_EXPORT COriginator :
|
||||
public CValueObject<COriginator>,
|
||||
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 <DisabledForComparison | DisabledForHashing> ())
|
||||
))
|
||||
attr(o.m_name),
|
||||
attr(o.m_machineIdBase64),
|
||||
attr(o.m_machineName, flags <DisabledForComparison | DisabledForHashing> ()),
|
||||
attr(o.m_processName),
|
||||
attr(o.m_processId),
|
||||
attr(o.m_timestampMSecsSinceEpoch, flags <DisabledForComparison | DisabledForHashing> ())
|
||||
))
|
||||
|
||||
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
|
||||
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "blackmisc/aviation/aircraftpartslist.h"
|
||||
#include "blackmisc/network/textmessagelist.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/originatorlist.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
@@ -172,5 +173,6 @@ namespace BlackMisc
|
||||
template class ITimestampObjectList<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList>;
|
||||
template class ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
||||
template class ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
||||
template class ITimestampObjectList<BlackMisc::COriginator, BlackMisc::COriginatorList>;
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -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<class OBJ, class CONTAINER>
|
||||
@@ -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<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::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
||||
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
||||
extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList<BlackMisc::COriginator, BlackMisc::COriginatorList>;
|
||||
//! \endcond
|
||||
|
||||
} //namespace
|
||||
|
||||
Reference in New Issue
Block a user