log0.3
This commit is contained in:
@@ -1,75 +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() 输出
|
||||
}
|
||||
|
||||
#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() 输出
|
||||
}
|
||||
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/**
|
||||
* @file Ipc_dbus.h
|
||||
* @brief D-Bus 服务接口 - 提供核心服务状态和负载查询
|
||||
*/
|
||||
|
||||
#ifndef IPC_DBUS_H
|
||||
#define IPC_DBUS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <QString>
|
||||
// 前向声明
|
||||
class CoreService;
|
||||
/**
|
||||
* @brief D-Bus 服务适配器 - 暴露核心服务接口
|
||||
*/
|
||||
class IpcDBus : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "com.softbus.Daemon")
|
||||
|
||||
public:
|
||||
explicit IpcDBus(CoreService* coreService, const QString& role, QObject* parent = nullptr);
|
||||
~IpcDBus();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief 检查核心服务是否运行
|
||||
* @return true 如果核心服务正在运行
|
||||
*/
|
||||
bool isRunning() const;
|
||||
|
||||
QString ping() const;
|
||||
|
||||
QString getVersion() const;
|
||||
|
||||
/**
|
||||
* @brief 获取核心服务状态信息
|
||||
* @return JSON 格式的状态信息
|
||||
*/
|
||||
QString getStatus() const;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取守护进程的进程ID
|
||||
* @return 进程ID,如果无法获取则返回0
|
||||
*/
|
||||
qint64 getPid() const;
|
||||
|
||||
/**
|
||||
* @brief 关闭守护进程
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
bool reloadConfig();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private slots:
|
||||
void updateLoadInfo();
|
||||
|
||||
private:
|
||||
CoreService* m_coreService{nullptr}; // non-owning
|
||||
QString m_role;
|
||||
};
|
||||
|
||||
#endif // IPC_DBUS_H
|
||||
|
||||
/**
|
||||
* @file Ipc_dbus.h
|
||||
* @brief D-Bus 服务接口 - 提供核心服务状态和负载查询
|
||||
*/
|
||||
|
||||
#ifndef IPC_DBUS_H
|
||||
#define IPC_DBUS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <QString>
|
||||
// 前向声明
|
||||
class CoreService;
|
||||
/**
|
||||
* @brief D-Bus 服务适配器 - 暴露核心服务接口
|
||||
*/
|
||||
class IpcDBus : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "com.softbus.Daemon")
|
||||
|
||||
public:
|
||||
explicit IpcDBus(CoreService* coreService, const QString& role, QObject* parent = nullptr);
|
||||
~IpcDBus();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief 检查核心服务是否运行
|
||||
* @return true 如果核心服务正在运行
|
||||
*/
|
||||
bool isRunning() const;
|
||||
|
||||
QString ping() const;
|
||||
|
||||
QString getVersion() const;
|
||||
|
||||
/**
|
||||
* @brief 获取核心服务状态信息
|
||||
* @return JSON 格式的状态信息
|
||||
*/
|
||||
QString getStatus() const;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取守护进程的进程ID
|
||||
* @return 进程ID,如果无法获取则返回0
|
||||
*/
|
||||
qint64 getPid() const;
|
||||
|
||||
/**
|
||||
* @brief 关闭守护进程
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
bool reloadConfig();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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