log0.3
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
#include "CoreService.h"
|
||||
#include "../utils/logs/logging.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "utils/logs/logging.h"
|
||||
#include "device_bus/DeviceBus.h"
|
||||
|
||||
CoreService* CoreService::instance()
|
||||
{
|
||||
@@ -26,6 +35,34 @@ bool CoreService::initialize()
|
||||
}
|
||||
|
||||
LOG_INFO() << "CoreService initializing";
|
||||
|
||||
// 1. 解析配置路径(放在用户 home 下的相对固定目录:~/softbus/config)
|
||||
const QString configPath =
|
||||
QDir::homePath() + QStringLiteral("/softbus/config/daemon_config.json");
|
||||
|
||||
QFile f(configPath);
|
||||
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
LOG_ERROR() << "CoreService: failed to open" << configPath;
|
||||
return false;
|
||||
}
|
||||
|
||||
const QByteArray data = f.readAll();
|
||||
f.close();
|
||||
|
||||
QJsonParseError pe;
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(data, &pe);
|
||||
if (pe.error != QJsonParseError::NoError || !doc.isObject()) {
|
||||
LOG_ERROR() << "CoreService: invalid JSON in" << configPath << ":" << pe.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
const QJsonObject root = doc.object();
|
||||
|
||||
// 2. 初始化 device_bus(交给 DeviceBus facade 处理具体设备)
|
||||
if (!softbus::device_bus::DeviceBus::instance().initialize(root)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
return true;
|
||||
}
|
||||
@@ -38,6 +75,7 @@ void CoreService::shutdown()
|
||||
}
|
||||
|
||||
LOG_INFO() << "CoreService shutting down";
|
||||
softbus::device_bus::DeviceBus::instance().shutdown();
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class CoreService : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
39
src/core/device/DeviceTypes.cpp
Normal file
39
src/core/device/DeviceTypes.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "core/device/DeviceTypes.h"
|
||||
|
||||
namespace softbus::core::device
|
||||
{
|
||||
|
||||
DeviceKind kindFromType(const QString& typeStr)
|
||||
{
|
||||
const QString t = typeStr.trimmed().toLower();
|
||||
if (t == QStringLiteral("serial")) return DeviceKind::Serial;
|
||||
if (t == QStringLiteral("can")) return DeviceKind::Can;
|
||||
if (t == QStringLiteral("ethernet") || t == QStringLiteral("network")) return DeviceKind::Network;
|
||||
if (t == QStringLiteral("virtual")) return DeviceKind::Virtual;
|
||||
if (t == QStringLiteral("distributed")) return DeviceKind::Distributed;
|
||||
return DeviceKind::Unknown;
|
||||
}
|
||||
|
||||
DeviceKind inferDeviceKindFromEndpoint(const QString& endpoint)
|
||||
{
|
||||
const QString ep = endpoint.trimmed();
|
||||
if (ep.startsWith(QStringLiteral("/dev/tty"))) return DeviceKind::Serial;
|
||||
if (ep.startsWith(QStringLiteral("can"))) return DeviceKind::Can;
|
||||
if (ep.startsWith(QStringLiteral("tcp://")) || ep.startsWith(QStringLiteral("udp://"))) return DeviceKind::Network;
|
||||
return DeviceKind::Unknown;
|
||||
}
|
||||
|
||||
QString driverKeyFor(DeviceKind kind)
|
||||
{
|
||||
switch (kind) {
|
||||
case DeviceKind::Serial: return QStringLiteral("serial_qt");
|
||||
case DeviceKind::Can: return QStringLiteral("can_socketcan");
|
||||
case DeviceKind::Network: return QStringLiteral("tcp_qt");
|
||||
case DeviceKind::Virtual: return QStringLiteral("virtual_device");
|
||||
case DeviceKind::Distributed: return QStringLiteral("distributed_node");
|
||||
default: return QStringLiteral("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace softbus::core::device
|
||||
|
||||
69
src/core/device/DeviceTypes.h
Normal file
69
src/core/device/DeviceTypes.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QString>
|
||||
|
||||
namespace softbus::core::device
|
||||
{
|
||||
|
||||
enum class DeviceKind {
|
||||
Serial,
|
||||
Can,
|
||||
Network,
|
||||
Virtual,
|
||||
Distributed,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
struct DeviceInfo
|
||||
{
|
||||
int id{0};
|
||||
QString endpoint;
|
||||
QString name;
|
||||
QString type; // "serial" / "can" / "network" / ...
|
||||
int address{0};
|
||||
QString protocol;
|
||||
QString protocolDetail;
|
||||
QJsonObject properties;
|
||||
QString status{QStringLiteral("online")};
|
||||
bool isActive{true};
|
||||
QDateTime lastSeen;
|
||||
|
||||
QString toJson() const
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj[QStringLiteral("id")] = id;
|
||||
obj[QStringLiteral("endpoint")] = endpoint;
|
||||
obj[QStringLiteral("name")] = name;
|
||||
obj[QStringLiteral("type")] = type;
|
||||
obj[QStringLiteral("address")] = address;
|
||||
obj[QStringLiteral("protocol")] = protocol;
|
||||
obj[QStringLiteral("protocol_detail")] = protocolDetail;
|
||||
obj[QStringLiteral("properties")] = properties;
|
||||
obj[QStringLiteral("status")] = status;
|
||||
obj[QStringLiteral("isActive")] = isActive;
|
||||
if (lastSeen.isValid()) {
|
||||
obj[QStringLiteral("lastSeen")] = lastSeen.toString(Qt::ISODate);
|
||||
}
|
||||
const QJsonDocument doc(obj);
|
||||
return QString::fromUtf8(doc.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
};
|
||||
|
||||
struct BusMessage
|
||||
{
|
||||
QString id;
|
||||
QString source;
|
||||
QString destination;
|
||||
QJsonObject payload;
|
||||
qint64 timestamp{0};
|
||||
};
|
||||
|
||||
DeviceKind kindFromType(const QString& typeStr);
|
||||
DeviceKind inferDeviceKindFromEndpoint(const QString& endpoint);
|
||||
QString driverKeyFor(DeviceKind kind);
|
||||
|
||||
} // namespace softbus::core::device
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
class LockFreeQueue {
|
||||
public:
|
||||
LockFreeQueue() = default;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
class MemoryPool {
|
||||
public:
|
||||
MemoryPool() = default;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
// Placeholder for data trace model.
|
||||
struct DataTrace {
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
// Placeholder for metadata model.
|
||||
struct Metadata {
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
class IProtocolPlugin {
|
||||
public:
|
||||
virtual ~IProtocolPlugin() = default;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
class PluginManager {
|
||||
public:
|
||||
PluginManager() = default;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user