mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
refs #432, register and unregister functions in GUI
* removed old ping functions * removed old notify functions, replace by new ones
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/audio/voiceroomlist.h"
|
||||
#include "blackmisc/eveventhotkeyfunction.h"
|
||||
#include "blackmisc/originator.h"
|
||||
#include "blackmisc/originatorlist.h"
|
||||
#include <QObject>
|
||||
#include <QReadWriteLock>
|
||||
|
||||
@@ -36,9 +36,7 @@ namespace BlackCore
|
||||
{
|
||||
class CInputManager;
|
||||
|
||||
/*!
|
||||
* Application context interface
|
||||
*/
|
||||
//! Application context interface
|
||||
class BLACKCORE_EXPORT IContextApplication : public CContext
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -49,20 +47,6 @@ namespace BlackCore
|
||||
IContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
||||
|
||||
public:
|
||||
//! Parts of the application
|
||||
enum Application : uint
|
||||
{
|
||||
ApplicationGui,
|
||||
ApplicationCore
|
||||
};
|
||||
|
||||
//! State of application
|
||||
enum Actions : uint
|
||||
{
|
||||
ApplicationStarts,
|
||||
ApplicationStops
|
||||
};
|
||||
|
||||
//! Service name
|
||||
static const QString &InterfaceName()
|
||||
{
|
||||
@@ -88,7 +72,7 @@ namespace BlackCore
|
||||
|
||||
signals:
|
||||
//! A component changes
|
||||
void componentChanged(uint component, uint action);
|
||||
void registrationChanged();
|
||||
|
||||
//! A log message was logged
|
||||
//! \note Used with CLogMessage, do not use directly
|
||||
@@ -103,23 +87,26 @@ namespace BlackCore
|
||||
//! \note this is the function which relays CLogMessage via DBus
|
||||
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;
|
||||
//! Register application, can also be used for ping
|
||||
virtual BlackMisc::COriginator registerApplication(const BlackMisc::COriginator &application) = 0;
|
||||
|
||||
//! A component has changed its state
|
||||
virtual void notifyAboutComponentChange(uint component, uint action) = 0;
|
||||
//! Unregister application
|
||||
virtual void unregisterApplication(const BlackMisc::COriginator &application) = 0;
|
||||
|
||||
//! All registered applications
|
||||
virtual BlackMisc::COriginatorList getRegisteredApplications() const = 0;
|
||||
|
||||
//! Remote enabled version of writing a text file
|
||||
virtual bool writeToFile(const QString &fileName, const QString &content) = 0;
|
||||
|
||||
//! Remote enabled version of reading a text file
|
||||
virtual QString readFromFile(const QString &fileName) = 0;
|
||||
virtual QString readFromFile(const QString &fileName) const = 0;
|
||||
|
||||
//! Remote enabled version of deleting a file
|
||||
virtual bool removeFile(const QString &fileName) = 0;
|
||||
|
||||
//! Remote enabled version of file exists
|
||||
virtual bool existsFile(const QString &fileName) = 0;
|
||||
virtual bool existsFile(const QString &fileName) const = 0;
|
||||
|
||||
//! Process remote event
|
||||
virtual void processHotkeyFuncEvent(const BlackMisc::Event::CEventHotkeyFunction &event) = 0;
|
||||
|
||||
@@ -40,20 +40,9 @@ namespace BlackCore
|
||||
emit this->messageLogged(message, origin);
|
||||
}
|
||||
|
||||
qint64 CContextApplication::ping(qint64 token) const
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
||||
void CContextApplication::notifyAboutComponentChange(uint component, uint action)
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << QString::number(component) << QString::number(action);
|
||||
this->componentChanged(component, action);
|
||||
}
|
||||
|
||||
bool CContextApplication::writeToFile(const QString &fileName, const QString &content)
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName << content.left(25);
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName << content.left(25); }
|
||||
if (fileName.isEmpty()) { return false; }
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
@@ -68,9 +57,30 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
QString CContextApplication::readFromFile(const QString &fileName)
|
||||
COriginator CContextApplication::registerApplication(const COriginator &application)
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName;
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; }
|
||||
this->m_registeredApplications.replaceOrAdd(application, application);
|
||||
emit registrationChanged();
|
||||
return application;
|
||||
}
|
||||
|
||||
void CContextApplication::unregisterApplication(const COriginator &application)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; }
|
||||
int r = this->m_registeredApplications.remove(application);
|
||||
if (r > 0) { emit registrationChanged(); }
|
||||
}
|
||||
|
||||
COriginatorList CContextApplication::getRegisteredApplications() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
return m_registeredApplications;
|
||||
}
|
||||
|
||||
QString CContextApplication::readFromFile(const QString &fileName) const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; }
|
||||
QFile file(fileName);
|
||||
QString content;
|
||||
if (fileName.isEmpty()) return content;
|
||||
@@ -85,12 +95,14 @@ namespace BlackCore
|
||||
|
||||
bool CContextApplication::removeFile(const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty()) return false;
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; }
|
||||
if (fileName.isEmpty()) { return false; }
|
||||
return QFile::remove(fileName);
|
||||
}
|
||||
|
||||
bool CContextApplication::existsFile(const QString &fileName)
|
||||
bool CContextApplication::existsFile(const QString &fileName) const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; }
|
||||
if (fileName.isEmpty()) return false;
|
||||
return QFile::exists(fileName);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "context_application.h"
|
||||
#include "context_runtime.h"
|
||||
#include "dbus_server.h"
|
||||
#include "blackmisc/originatorlist.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
@@ -31,23 +32,26 @@ namespace BlackCore
|
||||
//! \copydoc IContextApplication::logMessage
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::COriginator &origin) override;
|
||||
|
||||
//! \copydoc IContextApplication::ping()
|
||||
virtual qint64 ping(qint64 token) const override;
|
||||
|
||||
//! \copydoc IContextApplication::notifyAboutComponentChange
|
||||
virtual void notifyAboutComponentChange(uint component, uint action) override;
|
||||
|
||||
//! \copydoc IContextApplication::writeToFile
|
||||
virtual bool writeToFile(const QString &fileName, const QString &content) override;
|
||||
|
||||
//! \copydoc IContextApplication::registerApplication
|
||||
virtual BlackMisc::COriginator registerApplication(const BlackMisc::COriginator &application) override;
|
||||
|
||||
//! \copydoc IContextApplication::unRegisterApplication
|
||||
virtual void unregisterApplication(const BlackMisc::COriginator &application) override;
|
||||
|
||||
//! \copydoc IContextApplication::getRegisteredApplications
|
||||
virtual BlackMisc::COriginatorList getRegisteredApplications() const override;
|
||||
|
||||
//! \copydoc IContextApplication::readFromFile
|
||||
virtual QString readFromFile(const QString &fileName) override;
|
||||
virtual QString readFromFile(const QString &fileName) const override;
|
||||
|
||||
//! \copydoc IContextApplication::removeFile
|
||||
virtual bool removeFile(const QString &fileName) override;
|
||||
|
||||
//! \copydoc IContextApplication::existsFile
|
||||
virtual bool existsFile(const QString &fileName) override;
|
||||
virtual bool existsFile(const QString &fileName) const override;
|
||||
|
||||
//! \copydoc IContextApplication::processHotkeyFuncEvent
|
||||
virtual void processHotkeyFuncEvent(const BlackMisc::Event::CEventHotkeyFunction &event) override;
|
||||
@@ -58,6 +62,9 @@ namespace BlackCore
|
||||
|
||||
//! Register myself in DBus, fail safe
|
||||
CContextApplication *registerWithDBus(CDBusServer *server);
|
||||
|
||||
private:
|
||||
BlackMisc::COriginatorList m_registeredApplications;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "blackcore/input_manager.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
#include "blackmisc/originatorlist.h"
|
||||
#include <QObject>
|
||||
#include <QMetaEnum>
|
||||
#include <QDBusConnection>
|
||||
@@ -19,10 +20,6 @@ using namespace BlackMisc;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor for DBus
|
||||
*/
|
||||
CContextApplicationProxy::CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextApplication(mode, runtime), m_dBusInterface(nullptr)
|
||||
{
|
||||
this->m_dBusInterface = new CGenericDBusInterface(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), connection, this);
|
||||
@@ -44,9 +41,6 @@ namespace BlackCore
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect for signals
|
||||
*/
|
||||
void CContextApplicationProxy::relaySignals(const QString &serviceName, QDBusConnection &connection)
|
||||
{
|
||||
// signals originating from impl side
|
||||
@@ -54,7 +48,7 @@ namespace BlackCore
|
||||
"messageLogged", this, SIGNAL(messageLogged(BlackMisc::CStatusMessage, BlackMisc::COriginator)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
|
||||
"componentChanged", this, SIGNAL(componentChanged(uint, uint)));
|
||||
"registrationChanged", this, SIGNAL(registrationChanged()));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
|
||||
"fakedSetComVoiceRoom", this, SIGNAL(fakedSetComVoiceRoom(BlackMisc::Audio::CVoiceRoomList)));
|
||||
@@ -62,64 +56,47 @@ namespace BlackCore
|
||||
Q_UNUSED(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* Log a message
|
||||
*/
|
||||
void CContextApplicationProxy::logMessage(const CStatusMessage &message, const COriginator &origin)
|
||||
{
|
||||
this->m_dBusInterface->callDBus(QLatin1Literal("logMessage"), message, origin);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ping, is DBus alive?
|
||||
*/
|
||||
qint64 CContextApplicationProxy::ping(qint64 token) const
|
||||
BlackMisc::COriginator CContextApplicationProxy::registerApplication(const COriginator &application)
|
||||
{
|
||||
qint64 t = this->m_dBusInterface->callDBusRet<qint64>(QLatin1Literal("ping"), token);
|
||||
return t;
|
||||
return this->m_dBusInterface->callDBusRet<BlackMisc::COriginator>(QLatin1Literal("registerApplication"), application);
|
||||
}
|
||||
|
||||
/*
|
||||
* Component has changed
|
||||
*/
|
||||
void CContextApplicationProxy::notifyAboutComponentChange(uint component, uint action)
|
||||
void CContextApplicationProxy::unregisterApplication(const COriginator &application)
|
||||
{
|
||||
this->m_dBusInterface->callDBus(QLatin1Literal("notifyAboutComponentChange"), component, action);
|
||||
this->m_dBusInterface->callDBus(QLatin1Literal("unregisterApplication"), application);
|
||||
}
|
||||
|
||||
BlackMisc::COriginatorList CContextApplicationProxy::getRegisteredApplications() const
|
||||
{
|
||||
return this->m_dBusInterface->callDBusRet<BlackMisc::COriginatorList>(QLatin1Literal("getRegisteredApplications"));
|
||||
}
|
||||
|
||||
/*
|
||||
* To file
|
||||
*/
|
||||
bool CContextApplicationProxy::writeToFile(const QString &fileName, const QString &content)
|
||||
{
|
||||
if (fileName.isEmpty()) return false;
|
||||
if (fileName.isEmpty()) { return false; }
|
||||
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("writeToFile"), fileName, content);
|
||||
}
|
||||
|
||||
/*
|
||||
* From file
|
||||
*/
|
||||
QString CContextApplicationProxy::readFromFile(const QString &fileName)
|
||||
QString CContextApplicationProxy::readFromFile(const QString &fileName) const
|
||||
{
|
||||
if (fileName.isEmpty()) return "";
|
||||
if (fileName.isEmpty()) { return ""; }
|
||||
return this->m_dBusInterface->callDBusRet<QString>(QLatin1Literal("readFromFile"), fileName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete file
|
||||
*/
|
||||
bool CContextApplicationProxy::removeFile(const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty()) return false;
|
||||
if (fileName.isEmpty()) { return false; }
|
||||
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("removeFile"), fileName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check file
|
||||
*/
|
||||
bool CContextApplicationProxy::existsFile(const QString &fileName)
|
||||
bool CContextApplicationProxy::existsFile(const QString &fileName) const
|
||||
{
|
||||
if (fileName.isEmpty()) return false;
|
||||
if (fileName.isEmpty()) { return false; }
|
||||
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("existsFile"), fileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,23 +28,26 @@ namespace BlackCore
|
||||
//! \copydoc IContextApplication::logMessage
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::COriginator &origin) override;
|
||||
|
||||
//! \copydoc IContextApplication::ping()
|
||||
virtual qint64 ping(qint64 token) const override;
|
||||
//! \copydoc IContextApplication::registerApplication
|
||||
virtual BlackMisc::COriginator registerApplication(const BlackMisc::COriginator &application) override;
|
||||
|
||||
//! \copydoc IContextApplication::notifyAboutComponentChange
|
||||
virtual void notifyAboutComponentChange(uint component, uint action) override;
|
||||
//! \copydoc IContextApplication::unRegisterApplication
|
||||
virtual void unregisterApplication(const BlackMisc::COriginator &application) override;
|
||||
|
||||
//! \copydoc IContextApplication::getRegisteredApplications
|
||||
virtual BlackMisc::COriginatorList getRegisteredApplications() const override;
|
||||
|
||||
//! \copydoc IContextApplication::writeToFile
|
||||
virtual bool writeToFile(const QString &fileName, const QString &content) override;
|
||||
|
||||
//! \copydoc IContextApplication::readFromFile
|
||||
virtual QString readFromFile(const QString &fileName) override;
|
||||
virtual QString readFromFile(const QString &fileName) const override;
|
||||
|
||||
//! \copydoc IContextApplication::removeFile
|
||||
virtual bool removeFile(const QString &fileName) override;
|
||||
|
||||
//! \copydoc IContextApplication::existsFile
|
||||
virtual bool existsFile(const QString &fileName) override;
|
||||
virtual bool existsFile(const QString &fileName) const override;
|
||||
|
||||
//! \copydoc IContextApplication::processHotkeyFuncEvent
|
||||
virtual void processHotkeyFuncEvent(const BlackMisc::Event::CEventHotkeyFunction &event) override;
|
||||
@@ -60,7 +63,6 @@ namespace BlackCore
|
||||
BlackMisc::CGenericDBusInterface *m_dBusInterface;
|
||||
|
||||
//! Relay connection signals to local signals
|
||||
//! No idea why this has to be wired and is not done automatically
|
||||
void relaySignals(const QString &serviceName, QDBusConnection &connection);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user