log0.2
This commit is contained in:
75
src/api/ipc_dbus/IpcDBus.cpp
Normal file
75
src/api/ipc_dbus/IpcDBus.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "IpcDBus.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "src/core/CoreService.h"
|
||||
|
||||
IpcDBus::IpcDBus(CoreService* coreService, const QString& role, QObject* parent)
|
||||
: QObject(parent),
|
||||
m_coreService(coreService),
|
||||
m_role(role)
|
||||
{
|
||||
}
|
||||
|
||||
IpcDBus::~IpcDBus() = default;
|
||||
|
||||
bool IpcDBus::isRunning() const
|
||||
{
|
||||
if (!m_coreService) {
|
||||
return false;
|
||||
}
|
||||
return m_coreService->isInitialized();
|
||||
}
|
||||
|
||||
QString IpcDBus::ping() const
|
||||
{
|
||||
return QStringLiteral("pong");
|
||||
}
|
||||
|
||||
QString IpcDBus::getVersion() const
|
||||
{
|
||||
return QCoreApplication::applicationVersion();
|
||||
}
|
||||
|
||||
QString IpcDBus::getStatus() const
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert(QStringLiteral("service"), QStringLiteral("com.softbus.Daemon"));
|
||||
obj.insert(QStringLiteral("objectPath"), QStringLiteral("/com/softbus/Daemon"));
|
||||
obj.insert(QStringLiteral("interface"), QStringLiteral("com.softbus.Daemon"));
|
||||
obj.insert(QStringLiteral("pid"), static_cast<qint64>(QCoreApplication::applicationPid()));
|
||||
obj.insert(QStringLiteral("role"), m_role);
|
||||
obj.insert(QStringLiteral("running"), isRunning());
|
||||
obj.insert(QStringLiteral("timestampMs"), static_cast<qint64>(QDateTime::currentMSecsSinceEpoch()));
|
||||
|
||||
const QJsonDocument doc(obj);
|
||||
return QString::fromUtf8(doc.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
qint64 IpcDBus::getPid() const
|
||||
{
|
||||
return static_cast<qint64>(QCoreApplication::applicationPid());
|
||||
}
|
||||
|
||||
void IpcDBus::shutdown()
|
||||
{
|
||||
if (m_coreService) {
|
||||
m_coreService->shutdown();
|
||||
}
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
bool IpcDBus::reloadConfig()
|
||||
{
|
||||
// 占位:后续移植配置系统时在这里触发 reload
|
||||
return false;
|
||||
}
|
||||
|
||||
void IpcDBus::updateLoadInfo()
|
||||
{
|
||||
// 预留:后续可在此周期性采样 CPU/内存/队列长度等指标,并通过 getStatus() 输出
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
#include <QString>
|
||||
// 前向声明
|
||||
class CoreService;
|
||||
/**
|
||||
* @brief D-Bus 服务适配器 - 暴露核心服务接口
|
||||
*/
|
||||
@@ -18,7 +20,7 @@ class IpcDBus : public QObject
|
||||
Q_CLASSINFO("D-Bus Interface", "com.softbus.Daemon")
|
||||
|
||||
public:
|
||||
explicit IpcDBus(CoreService* coreService, QObject* parent = nullptr);
|
||||
explicit IpcDBus(CoreService* coreService, const QString& role, QObject* parent = nullptr);
|
||||
~IpcDBus();
|
||||
|
||||
public slots:
|
||||
@@ -28,6 +30,10 @@ public slots:
|
||||
*/
|
||||
bool isRunning() const;
|
||||
|
||||
QString ping() const;
|
||||
|
||||
QString getVersion() const;
|
||||
|
||||
/**
|
||||
* @brief 获取核心服务状态信息
|
||||
* @return JSON 格式的状态信息
|
||||
@@ -46,6 +52,8 @@ public slots:
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
bool reloadConfig();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -54,8 +62,8 @@ private slots:
|
||||
void updateLoadInfo();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
CoreService* m_coreService{nullptr}; // non-owning
|
||||
QString m_role;
|
||||
};
|
||||
|
||||
#endif // IPC_DBUS_H
|
||||
Reference in New Issue
Block a user