From a7d27c72345a61a93efb2490a6160c5f9baa8056 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 23 May 2015 18:51:14 +0200 Subject: [PATCH] refs #428 Move COriginator from Event into BlackMisc namespace --- src/blackcore/context_application.h | 6 +- src/blackcore/context_application_impl.cpp | 2 +- src/blackcore/context_application_impl.h | 2 +- src/blackcore/context_application_proxy.cpp | 4 +- src/blackcore/context_application_proxy.h | 2 +- src/blackmisc/blackmiscfreefunctions.cpp | 3 +- src/blackmisc/eventallclasses.h | 1 - src/blackmisc/eveventhotkeyfunction.h | 2 +- src/blackmisc/evoriginator.cpp | 57 -------------- src/blackmisc/evoriginator.h | 78 -------------------- src/blackmisc/originator.cpp | 52 +++++++++++++ src/blackmisc/originator.h | 82 +++++++++++++++++++++ 12 files changed, 145 insertions(+), 146 deletions(-) delete mode 100644 src/blackmisc/evoriginator.cpp delete mode 100644 src/blackmisc/evoriginator.h create mode 100644 src/blackmisc/originator.cpp create mode 100644 src/blackmisc/originator.h diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index 5ab8b5e20..144f4f813 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -17,7 +17,7 @@ #include "blackmisc/statusmessagelist.h" #include "blackmisc/audio/voiceroomlist.h" #include "blackmisc/eveventhotkeyfunction.h" -#include "blackmisc/evoriginator.h" +#include "blackmisc/originator.h" #include #include @@ -92,7 +92,7 @@ namespace BlackCore //! A log message was logged //! \note Used with CLogMessage, do not use directly - void messageLogged(const BlackMisc::CStatusMessage &message, const BlackMisc::Event::COriginator &origin); + void messageLogged(const BlackMisc::CStatusMessage &message, const BlackMisc::COriginator &origin); //! Work around for audio context, #382 void fakedSetComVoiceRoom(const BlackMisc::Audio::CVoiceRoomList &requestedRooms); @@ -101,7 +101,7 @@ namespace BlackCore //! Log a log message //! \note Not pure because it can be called from the base class constructor. //! \note this is the function which relays CLogMessage via DBus - virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::Event::COriginator &origin) { Q_UNUSED(message); Q_UNUSED(origin); } + virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::COriginator &origin) { Q_UNUSED(message); Q_UNUSED(origin); } //! Ping a token, used to check if application is alive virtual qint64 ping(qint64 token) const = 0; diff --git a/src/blackcore/context_application_impl.cpp b/src/blackcore/context_application_impl.cpp index 8037dc3ac..7a5422524 100644 --- a/src/blackcore/context_application_impl.cpp +++ b/src/blackcore/context_application_impl.cpp @@ -31,7 +31,7 @@ namespace BlackCore return this; } - void CContextApplication::logMessage(const CStatusMessage &message, const Event::COriginator &origin) + void CContextApplication::logMessage(const CStatusMessage &message, const COriginator &origin) { if (!origin.isFromSameProcess()) { diff --git a/src/blackcore/context_application_impl.h b/src/blackcore/context_application_impl.h index 21308f654..d1e33df10 100644 --- a/src/blackcore/context_application_impl.h +++ b/src/blackcore/context_application_impl.h @@ -29,7 +29,7 @@ namespace BlackCore public slots: //! \copydoc IContextApplication::logMessage - virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::Event::COriginator &origin) override; + virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::COriginator &origin) override; //! \copydoc IContextApplication::ping() virtual qint64 ping(qint64 token) const override; diff --git a/src/blackcore/context_application_proxy.cpp b/src/blackcore/context_application_proxy.cpp index 81e8fcbe5..bf353e053 100644 --- a/src/blackcore/context_application_proxy.cpp +++ b/src/blackcore/context_application_proxy.cpp @@ -35,7 +35,7 @@ namespace BlackCore connect(inputManager, &CInputManager::hotkeyFuncEvent, this, &CContextApplicationProxy::processHotkeyFuncEvent); inputManager->setEventForwarding(true); - connect(this, &IContextApplication::messageLogged, this, [](const CStatusMessage & message, const Event::COriginator & origin) + connect(this, &IContextApplication::messageLogged, this, [](const CStatusMessage & message, const COriginator & origin) { if (!origin.isFromSameProcess()) { @@ -65,7 +65,7 @@ namespace BlackCore /* * Log a message */ - void CContextApplicationProxy::logMessage(const CStatusMessage &message, const Event::COriginator &origin) + void CContextApplicationProxy::logMessage(const CStatusMessage &message, const COriginator &origin) { this->m_dBusInterface->callDBus(QLatin1Literal("logMessage"), message, origin); } diff --git a/src/blackcore/context_application_proxy.h b/src/blackcore/context_application_proxy.h index a98f79db9..7e051e88f 100644 --- a/src/blackcore/context_application_proxy.h +++ b/src/blackcore/context_application_proxy.h @@ -26,7 +26,7 @@ namespace BlackCore public slots: //! \copydoc IContextApplication::logMessage - virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::Event::COriginator &origin) override; + virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::COriginator &origin) override; //! \copydoc IContextApplication::ping() virtual qint64 ping(qint64 token) const override; diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index bea853314..67ea3fb88 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -20,6 +20,7 @@ #include "statusmessagelist.h" #include "pixmap.h" #include "iconlist.h" +#include "originator.h" #include "eventallclasses.h" #include #include @@ -80,7 +81,6 @@ void BlackMisc::Hardware::registerMetadata() */ void BlackMisc::Event::registerMetadata() { - COriginator::registerMetadata(); CEventHotkeyFunction::registerMetadata(); } @@ -105,6 +105,7 @@ void BlackMisc::registerMetadata() CLogCategory::registerMetadata(); CLogCategoryList::registerMetadata(); CPixmap::registerMetadata(); + COriginator::registerMetadata(); // sub namespaces PhysicalQuantities::registerMetadata(); diff --git a/src/blackmisc/eventallclasses.h b/src/blackmisc/eventallclasses.h index 45ae7cadb..e27303021 100644 --- a/src/blackmisc/eventallclasses.h +++ b/src/blackmisc/eventallclasses.h @@ -10,7 +10,6 @@ #ifndef BLACKMISC_EVENT_ALLCLASSES_H #define BLACKMISC_EVENT_ALLCLASSES_H -#include "blackmisc/evoriginator.h" #include "blackmisc/eveventhotkeyfunction.h" #endif // guard diff --git a/src/blackmisc/eveventhotkeyfunction.h b/src/blackmisc/eveventhotkeyfunction.h index 99b32bf2f..9f9862e9c 100644 --- a/src/blackmisc/eveventhotkeyfunction.h +++ b/src/blackmisc/eveventhotkeyfunction.h @@ -14,7 +14,7 @@ #include "blackmiscexport.h" #include "valueobject.h" -#include "evoriginator.h" +#include "originator.h" #include "hotkeyfunction.h" #include "blackmiscfreefunctions.h" diff --git a/src/blackmisc/evoriginator.cpp b/src/blackmisc/evoriginator.cpp deleted file mode 100644 index 77512084f..000000000 --- a/src/blackmisc/evoriginator.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (C) 2014 - * 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 "evoriginator.h" -#include -#include - -namespace BlackMisc -{ - namespace Event - { - // Default constructor - COriginator::COriginator() - : m_machineId(QDBusConnection::localMachineId()), - m_processId(QCoreApplication::applicationPid()), - m_processName(QCoreApplication::applicationName()) - { - } - - bool COriginator::isFromLocalMachine() const - { - return QDBusConnection::localMachineId() == getMachineId(); - } - - bool COriginator::isFromSameProcess() const - { - return QCoreApplication::applicationPid() == getProcessId() && isFromLocalMachine(); - } - - bool COriginator::isFromSameProcessName() const - { - return QCoreApplication::applicationName() == getProcessName(); - } - - /* - * Convert to string - */ - QString COriginator::convertToQString(bool /* i18n */) const - { - 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(" ").append(m_processName); - return s; - } - - } -} diff --git a/src/blackmisc/evoriginator.h b/src/blackmisc/evoriginator.h deleted file mode 100644 index 298596c7b..000000000 --- a/src/blackmisc/evoriginator.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (C) 2014 - * 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. - */ - -#ifndef BLACKMISC_EVENT_ORIGINATOR_H -#define BLACKMISC_EVENT_ORIGINATOR_H - -//! \file - -#include "blackmiscexport.h" -#include "valueobject.h" -#include "blackmiscfreefunctions.h" -#include -#include - -namespace BlackMisc -{ - namespace Event - { - - //! Value object encapsulating information about the originiator - class BLACKMISC_EXPORT COriginator : - public Mixin::MetaType, - public Mixin::HashByTuple, - public Mixin::DBusByTuple, - public Mixin::EqualsByTuple, - public Mixin::LessThanByTuple, - public Mixin::CompareByTuple, - public Mixin::Index, - public Mixin::String, - public Mixin::Icon - { - public: - //! Default constructor. - COriginator(); - - //! Get machine id - QByteArray getMachineId() const {return m_machineId;} - - //! Get process id - qint32 getProcessId() const {return m_processId;} - - //! Get process name - QString getProcessName() const {return m_processName;} - - //! Check if originating from the same local machine - bool isFromLocalMachine() const; - - //! Check if originating from the same process id - bool isFromSameProcess() const; - - //! Check if originating from the same process name - bool isFromSameProcessName() const; - - //! \copydoc CValueObject::convertToQString - QString convertToQString(bool i18n = false) const; - - private: - BLACK_ENABLE_TUPLE_CONVERSION(COriginator) - QString m_originatorName; - QByteArray m_machineId; - QByteArray m_primaryIpAddress; - QByteArray m_objectId; - qint32 m_processId; - QString m_processName; - }; - } -} - -BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Event::COriginator, (o.m_originatorName, o.m_machineId, o.m_primaryIpAddress, o.m_objectId, o.m_processId, o.m_processName)) -Q_DECLARE_METATYPE(BlackMisc::Event::COriginator) - -#endif // BLACKMISC_EVENT_ORIGINATOR_H diff --git a/src/blackmisc/originator.cpp b/src/blackmisc/originator.cpp new file mode 100644 index 000000000..204d227a9 --- /dev/null +++ b/src/blackmisc/originator.cpp @@ -0,0 +1,52 @@ +/* Copyright (C) 2014 + * 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 "originator.h" +#include +#include + +namespace BlackMisc +{ + + // Default constructor + COriginator::COriginator() + : m_machineId(QDBusConnection::localMachineId()), + m_processId(QCoreApplication::applicationPid()), + m_processName(QCoreApplication::applicationName()) + { + } + + bool COriginator::isFromLocalMachine() const + { + return QDBusConnection::localMachineId() == getMachineId(); + } + + bool COriginator::isFromSameProcess() const + { + return QCoreApplication::applicationPid() == getProcessId() && isFromLocalMachine(); + } + + bool COriginator::isFromSameProcessName() const + { + return QCoreApplication::applicationName() == getProcessName(); + } + + QString COriginator::convertToQString(bool /* i18n */) const + { + 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(" ").append(m_processName); + return s; + } + +} diff --git a/src/blackmisc/originator.h b/src/blackmisc/originator.h new file mode 100644 index 000000000..014a920bd --- /dev/null +++ b/src/blackmisc/originator.h @@ -0,0 +1,82 @@ +/* Copyright (C) 2014 + * 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. + */ + +#ifndef BLACKMISC_EVENT_ORIGINATOR_H +#define BLACKMISC_EVENT_ORIGINATOR_H + +//! \file + +#include "blackmiscexport.h" +#include "valueobject.h" +#include "blackmiscfreefunctions.h" +#include +#include + +namespace BlackMisc +{ + + //! Value object encapsulating information about the originiator + class BLACKMISC_EXPORT COriginator : + public Mixin::MetaType, + public Mixin::HashByTuple, + public Mixin::DBusByTuple, + public Mixin::EqualsByTuple, + public Mixin::LessThanByTuple, + public Mixin::CompareByTuple, + public Mixin::Index, + public Mixin::String, + public Mixin::Icon + { + public: + //! Default constructor. + COriginator(); + + //! Get machine id + QByteArray getMachineId() const {return m_machineId;} + + //! Get process id + qint32 getProcessId() const {return m_processId;} + + //! Get process name + QString getProcessName() const {return m_processName;} + + //! Check if originating from the same local machine + bool isFromLocalMachine() const; + + //! Check if originating from the same process id + bool isFromSameProcess() const; + + //! Check if originating from the same process name + bool isFromSameProcessName() const; + + //! \copydoc CValueObject::convertToQString + QString convertToQString(bool i18n = false) const; + + private: + BLACK_ENABLE_TUPLE_CONVERSION(COriginator) + QString m_originatorName; + QByteArray m_machineId; + QByteArray m_primaryIpAddress; + QByteArray m_objectId; + qint32 m_processId; + QString m_processName; + }; +} + +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::COriginator, ( + o.m_originatorName, + o.m_machineId, + o.m_primaryIpAddress, + o.m_objectId, + o.m_processId, + o.m_processName +)) +Q_DECLARE_METATYPE(BlackMisc::COriginator) + +#endif // BLACKMISC_EVENT_ORIGINATOR_H