phase 1
This commit is contained in:
@@ -51,7 +51,7 @@ build/lib/protocol_canopen.so # CANopen 协议插件
|
||||
|
||||
## 运行
|
||||
|
||||
**请在项目根目录下启动**,以便正确加载 `config/` 下的配置文件,并让守护进程找到 `build/lib/` 中的协议插件。
|
||||
**请在项目根目录下启动**,以便正确加载 `config/` 下的配置文件与 `config/lib/` 中的协议插件(亦兼容 `build/lib/`)。
|
||||
|
||||
### 1. 启动守护进程
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ Phase 2 静态 NodeSet2 XML 占位文件,Phase 1 不使用。守护进程通
|
||||
|
||||
| 现象 | 可能原因 | 处理 |
|
||||
|------|----------|------|
|
||||
| 守护进程启动失败:plugin load | 插件 .so 不在搜索路径 | 确认 `build/lib/libprotocol_modbus.so` 存在 |
|
||||
| 守护进程启动失败:plugin load | 插件 .so 不在搜索路径 | 确认 `config/lib/protocol_modbus.so` 或 `build/lib/libprotocol_modbus.so` 存在 |
|
||||
| OPC UA 连接拒绝 | 端口被占用或 OPC UA 未启用 | 检查 4840 端口;确认 `SOFTBUS_WITH_OPCUA=ON` |
|
||||
| Variable 值不更新 | 边缘未连接或 objectRef 不匹配 | 确认 edge 运行且 sourceId 与模型路径一致 |
|
||||
| Method 调用失败 | JSON 格式错误或 objectRef 无效 | 检查入参 JSON 与五层路径 |
|
||||
|
||||
@@ -91,7 +91,7 @@ SOFTBUS_PLUGIN_API void destroy_parser(IParser* parser);
|
||||
|
||||
| 子模块 | 文件 | 说明 | Phase 1 状态 |
|
||||
|--------|------|------|-------------|
|
||||
| logging | `Logger.h/.cpp` | 单例日志,`infoTrace(tag, traceId, ...)` | 已用 |
|
||||
| logging | `Logger.h/.cpp` | 单例日志,`SB_LOG_*` 宏自动附带 `[文件::函数]` 调用位置 | 已用 |
|
||||
| time | `HwClock.h/.cpp` | 纳秒级时间戳 | 已用 |
|
||||
| alignment | `TimeAligner.h/.cpp` | 多通道时间对齐 | 未接入 |
|
||||
| platform | `PlatformSignal.h/.cpp` | SIGINT 优雅退出 | 已用 |
|
||||
|
||||
@@ -67,16 +67,13 @@ uaMethodBinder_->bindExecuteCommand([this](const ExecuteCommand& cmd) {
|
||||
|
||||
### 4.3 插件路径解析
|
||||
|
||||
`resolvePluginPath(pluginName)` 按以下顺序搜索:
|
||||
`resolvePluginPath(pluginName, profilePath)` 按以下顺序搜索(每个目录同时尝试 `lib{name}.so` 与 `{name}.so`):
|
||||
|
||||
1. `{exeDir}/{lib}{name}.so`
|
||||
2. `{exeDir}/../lib/{lib}{name}.so`
|
||||
3. `build/bin/{lib}{name}.so`
|
||||
4. `lib/{lib}{name}.so`
|
||||
5. `bin/{lib}{name}.so`
|
||||
6. `{cwd}/build/bin/{lib}{name}.so`
|
||||
7. `{cwd}/lib/{lib}{name}.so`
|
||||
8. `{cwd}/{lib}{name}.so`
|
||||
1. `{profileDir}/lib/` — 与配置文件同目录,如 `config/lib/`
|
||||
2. `{cwd}/config/lib/`
|
||||
3. `{exeDir}/`、`{exeDir}/../lib/`
|
||||
4. `build/lib/`、`build/bin/`
|
||||
5. `lib/`、`bin/`、`{cwd}/`
|
||||
|
||||
## 5. PipelineEngine
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -14,50 +13,54 @@ public:
|
||||
static Logger& instance();
|
||||
|
||||
void setLevel(LogLevel level);
|
||||
void log(LogLevel level, const std::string& tag, const std::string& message);
|
||||
void log(LogLevel level, const std::string& tag, const std::string& traceId,
|
||||
void log(LogLevel level, const char* file, const char* func, const std::string& tag,
|
||||
const std::string& message);
|
||||
void log(LogLevel level, const char* file, const char* func, const std::string& tag,
|
||||
const std::string& traceId, const std::string& message);
|
||||
|
||||
template <typename... Args>
|
||||
void info(const std::string& tag, Args&&... args)
|
||||
void infoAt(const char* file, const char* func, const std::string& tag, Args&&... args)
|
||||
{
|
||||
log(LogLevel::Info, tag, concat(std::forward<Args>(args)...));
|
||||
log(LogLevel::Info, file, func, tag, concat(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void infoTrace(const std::string& tag, const std::string& traceId, Args&&... args)
|
||||
void infoTraceAt(const char* file, const char* func, const std::string& tag,
|
||||
const std::string& traceId, Args&&... args)
|
||||
{
|
||||
log(LogLevel::Info, tag, traceId, concat(std::forward<Args>(args)...));
|
||||
log(LogLevel::Info, file, func, tag, traceId, concat(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void warn(const std::string& tag, Args&&... args)
|
||||
void warnAt(const char* file, const char* func, const std::string& tag, Args&&... args)
|
||||
{
|
||||
log(LogLevel::Warn, tag, concat(std::forward<Args>(args)...));
|
||||
log(LogLevel::Warn, file, func, tag, concat(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void warnTrace(const std::string& tag, const std::string& traceId, Args&&... args)
|
||||
void warnTraceAt(const char* file, const char* func, const std::string& tag,
|
||||
const std::string& traceId, Args&&... args)
|
||||
{
|
||||
log(LogLevel::Warn, tag, traceId, concat(std::forward<Args>(args)...));
|
||||
log(LogLevel::Warn, file, func, tag, traceId, concat(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void error(const std::string& tag, Args&&... args)
|
||||
void errorAt(const char* file, const char* func, const std::string& tag, Args&&... args)
|
||||
{
|
||||
log(LogLevel::Error, tag, concat(std::forward<Args>(args)...));
|
||||
log(LogLevel::Error, file, func, tag, concat(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void errorTrace(const std::string& tag, const std::string& traceId, Args&&... args)
|
||||
void errorTraceAt(const char* file, const char* func, const std::string& tag,
|
||||
const std::string& traceId, Args&&... args)
|
||||
{
|
||||
log(LogLevel::Error, tag, traceId, concat(std::forward<Args>(args)...));
|
||||
log(LogLevel::Error, file, func, tag, traceId, concat(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void debug(const std::string& tag, Args&&... args)
|
||||
void debugAt(const char* file, const char* func, const std::string& tag, Args&&... args)
|
||||
{
|
||||
log(LogLevel::Debug, tag, concat(std::forward<Args>(args)...));
|
||||
log(LogLevel::Debug, file, func, tag, concat(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -85,3 +88,24 @@ private:
|
||||
};
|
||||
|
||||
} // namespace softbus::core
|
||||
|
||||
#define SB_LOG_DEBUG(tag, ...) \
|
||||
::softbus::core::Logger::instance().debugAt(__FILE__, __func__, tag, ##__VA_ARGS__)
|
||||
|
||||
#define SB_LOG_INFO(tag, ...) \
|
||||
::softbus::core::Logger::instance().infoAt(__FILE__, __func__, tag, ##__VA_ARGS__)
|
||||
|
||||
#define SB_LOG_INFO_TRACE(tag, traceId, ...) \
|
||||
::softbus::core::Logger::instance().infoTraceAt(__FILE__, __func__, tag, traceId, ##__VA_ARGS__)
|
||||
|
||||
#define SB_LOG_WARN(tag, ...) \
|
||||
::softbus::core::Logger::instance().warnAt(__FILE__, __func__, tag, ##__VA_ARGS__)
|
||||
|
||||
#define SB_LOG_WARN_TRACE(tag, traceId, ...) \
|
||||
::softbus::core::Logger::instance().warnTraceAt(__FILE__, __func__, tag, traceId, ##__VA_ARGS__)
|
||||
|
||||
#define SB_LOG_ERROR(tag, ...) \
|
||||
::softbus::core::Logger::instance().errorAt(__FILE__, __func__, tag, ##__VA_ARGS__)
|
||||
|
||||
#define SB_LOG_ERROR_TRACE(tag, traceId, ...) \
|
||||
::softbus::core::Logger::instance().errorTraceAt(__FILE__, __func__, tag, traceId, ##__VA_ARGS__)
|
||||
|
||||
@@ -1,11 +1,44 @@
|
||||
#include <softbus_core/logging/Logger.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace softbus::core {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string fileStem(const char* file)
|
||||
{
|
||||
if (!file || file[0] == '\0') {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const char* base = std::strrchr(file, '/');
|
||||
if (!base) {
|
||||
base = std::strrchr(file, '\\');
|
||||
}
|
||||
base = base ? base + 1 : file;
|
||||
|
||||
std::string stem(base);
|
||||
const auto dot = stem.rfind('.');
|
||||
if (dot != std::string::npos) {
|
||||
stem.resize(dot);
|
||||
}
|
||||
return stem;
|
||||
}
|
||||
|
||||
std::string formatSource(const char* file, const char* func)
|
||||
{
|
||||
const std::string stem = fileStem(file);
|
||||
const char* fn = (func && func[0] != '\0') ? func : "unknown";
|
||||
return stem + "::" + fn;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Logger& Logger::instance()
|
||||
{
|
||||
static Logger logger;
|
||||
@@ -18,14 +51,17 @@ void Logger::setLevel(LogLevel level)
|
||||
level_ = level;
|
||||
}
|
||||
|
||||
void Logger::log(LogLevel level, const std::string& tag, const std::string& message)
|
||||
{
|
||||
log(level, tag, "", message);
|
||||
}
|
||||
|
||||
void Logger::log(LogLevel level, const std::string& tag, const std::string& traceId,
|
||||
void Logger::log(LogLevel level, const char* file, const char* func, const std::string& tag,
|
||||
const std::string& message)
|
||||
{
|
||||
log(level, file, func, tag, "", message);
|
||||
}
|
||||
|
||||
void Logger::log(LogLevel level, const char* file, const char* func, const std::string& tag,
|
||||
const std::string& traceId, const std::string& message)
|
||||
{
|
||||
(void)tag;
|
||||
|
||||
if (static_cast<int>(level) < static_cast<int>(level_)) {
|
||||
return;
|
||||
}
|
||||
@@ -49,7 +85,7 @@ void Logger::log(LogLevel level, const std::string& tag, const std::string& trac
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S")
|
||||
<< " [" << levelStr << "] [" << tag << "]";
|
||||
<< " [" << levelStr << "] [" << formatSource(file, func) << "]";
|
||||
if (!traceId.empty()) {
|
||||
oss << "[trace=" << traceId << "]";
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ bool PluginLoader::load(const std::string& pluginPath)
|
||||
#ifdef SOFTBUS_PLATFORM_WINDOWS
|
||||
handle_ = LoadLibraryA(pluginPath.c_str());
|
||||
if (!handle_) {
|
||||
Logger::instance().error("PluginLoader", "Failed to load plugin: ", pluginPath);
|
||||
SB_LOG_ERROR("PluginLoader", "Failed to load plugin: ", pluginPath);
|
||||
return false;
|
||||
}
|
||||
auto createFramer = reinterpret_cast<CreateFramerFn>(GetProcAddress(static_cast<HMODULE>(handle_), "create_framer"));
|
||||
@@ -32,7 +32,7 @@ bool PluginLoader::load(const std::string& pluginPath)
|
||||
#else
|
||||
handle_ = dlopen(pluginPath.c_str(), RTLD_NOW | RTLD_LOCAL);
|
||||
if (!handle_) {
|
||||
Logger::instance().error("PluginLoader", "Failed to load plugin: ", pluginPath, " err=", dlerror());
|
||||
SB_LOG_ERROR("PluginLoader", "Failed to load plugin: ", pluginPath, " err=", dlerror());
|
||||
return false;
|
||||
}
|
||||
auto createFramer = reinterpret_cast<CreateFramerFn>(dlsym(handle_, "create_framer"));
|
||||
@@ -42,7 +42,7 @@ bool PluginLoader::load(const std::string& pluginPath)
|
||||
#endif
|
||||
|
||||
if (!createFramer || !destroyFramer || !createParser || !destroyParser) {
|
||||
Logger::instance().error("PluginLoader", "Plugin missing required exports: ", pluginPath);
|
||||
SB_LOG_ERROR("PluginLoader", "Plugin missing required exports: ", pluginPath);
|
||||
unload();
|
||||
return false;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ bool PluginLoader::load(const std::string& pluginPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger::instance().info("PluginLoader", "Loaded plugin: ", pluginPath);
|
||||
SB_LOG_INFO("PluginLoader", "Loaded plugin: ", pluginPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ bool CommandDispatcher::dispatch(const softbus::api::ExecuteCommand& command)
|
||||
{
|
||||
std::string error;
|
||||
if (!command.validate(&error)) {
|
||||
softbus::core::Logger::instance().errorTrace("CommandDispatcher", command.traceId,
|
||||
SB_LOG_ERROR_TRACE("CommandDispatcher", command.traceId,
|
||||
"Invalid executeCommand: ", error);
|
||||
return false;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ bool CommandDispatcher::dispatch(const softbus::api::ExecuteCommand& command)
|
||||
}
|
||||
|
||||
const bool ok = uplink_->sendCommand(command);
|
||||
softbus::core::Logger::instance().infoTrace("CommandDispatcher", command.traceId,
|
||||
SB_LOG_INFO_TRACE("CommandDispatcher", command.traceId,
|
||||
"executeCommand dispatched to Edge objectRef=", command.objectRef,
|
||||
" command=", command.command, " success=", ok ? "true" : "false");
|
||||
return ok;
|
||||
|
||||
@@ -20,11 +20,42 @@
|
||||
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace softbus::daemon {
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
#ifdef SOFTBUS_PLATFORM_WINDOWS
|
||||
std::vector<std::string> pluginFileNames(const std::string& pluginName)
|
||||
{
|
||||
return {pluginName + ".dll"};
|
||||
}
|
||||
#else
|
||||
std::vector<std::string> pluginFileNames(const std::string& pluginName)
|
||||
{
|
||||
return {"lib" + pluginName + ".so", pluginName + ".so"};
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string findPluginInDir(const fs::path& dir, const std::string& pluginName)
|
||||
{
|
||||
if (!fs::exists(dir)) {
|
||||
return {};
|
||||
}
|
||||
for (const auto& fileName : pluginFileNames(pluginName)) {
|
||||
const fs::path candidate = dir / fileName;
|
||||
if (fs::exists(candidate)) {
|
||||
return fs::absolute(candidate).string();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CoreService::CoreService() = default;
|
||||
|
||||
CoreService::~CoreService()
|
||||
@@ -32,54 +63,62 @@ CoreService::~CoreService()
|
||||
stop();
|
||||
}
|
||||
|
||||
std::string CoreService::resolvePluginPath(const std::string& pluginName) const
|
||||
std::string CoreService::resolvePluginPath(const std::string& pluginName,
|
||||
const std::string& profilePath) const
|
||||
{
|
||||
#ifdef SOFTBUS_PLATFORM_WINDOWS
|
||||
const std::string fileName = pluginName + ".dll";
|
||||
char exePath[MAX_PATH]{};
|
||||
GetModuleFileNameA(nullptr, exePath, MAX_PATH);
|
||||
const fs::path exeDir = fs::path(exePath).parent_path();
|
||||
#else
|
||||
const std::string fileName = "lib" + pluginName + ".so";
|
||||
fs::path exeDir = fs::current_path();
|
||||
const fs::path exeDir = fs::current_path();
|
||||
#endif
|
||||
|
||||
const fs::path candidates[] = {
|
||||
exeDir / fileName,
|
||||
exeDir / ".." / "lib" / fileName,
|
||||
fs::path("build") / "bin" / fileName,
|
||||
fs::path("lib") / fileName,
|
||||
fs::path("bin") / fileName,
|
||||
fs::current_path() / "build" / "bin" / fileName,
|
||||
fs::current_path() / "lib" / fileName,
|
||||
fs::current_path() / fileName
|
||||
const fs::path profileDir = fs::path(profilePath).parent_path();
|
||||
const fs::path cwd = fs::current_path();
|
||||
|
||||
const fs::path searchDirs[] = {
|
||||
profileDir / "lib",
|
||||
cwd / "config" / "lib",
|
||||
exeDir,
|
||||
exeDir / ".." / "lib",
|
||||
cwd / "build" / "lib",
|
||||
fs::path("build") / "lib",
|
||||
fs::path("build") / "bin",
|
||||
cwd / "build" / "bin",
|
||||
fs::path("lib"),
|
||||
cwd / "lib",
|
||||
fs::path("bin"),
|
||||
cwd
|
||||
};
|
||||
|
||||
for (const auto& candidate : candidates) {
|
||||
if (fs::exists(candidate)) {
|
||||
return fs::absolute(candidate).string();
|
||||
for (const auto& dir : searchDirs) {
|
||||
if (const std::string found = findPluginInDir(dir, pluginName); !found.empty()) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return (exeDir / fileName).string();
|
||||
|
||||
const auto fallbackNames = pluginFileNames(pluginName);
|
||||
return fs::absolute(profileDir / "lib" / fallbackNames.front()).string();
|
||||
}
|
||||
|
||||
bool CoreService::start(const std::string& profilePath, const std::string& modelPath)
|
||||
{
|
||||
if (!profile_.loadFromFile(profilePath)) {
|
||||
softbus::core::Logger::instance().error("CoreService", "Failed to load profile: ", profilePath);
|
||||
SB_LOG_ERROR("CoreService", "Failed to load profile: ", profilePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
objectRegistry_ = std::make_unique<ObjectModelRegistry>();
|
||||
if (!objectRegistry_->loadFromFile(modelPath)) {
|
||||
softbus::core::Logger::instance().error("CoreService", "Failed to load model: ", modelPath);
|
||||
SB_LOG_ERROR("CoreService", "Failed to load model: ", modelPath);
|
||||
return false;
|
||||
}
|
||||
model_ = objectRegistry_->tree();
|
||||
|
||||
const std::string pluginPath = resolvePluginPath(profile_.plugins.modbus);
|
||||
const std::string pluginPath = resolvePluginPath(profile_.plugins.modbus, profilePath);
|
||||
if (!modbusPlugin_.load(pluginPath)) {
|
||||
softbus::core::Logger::instance().error("CoreService", "Failed to load modbus plugin: ", pluginPath);
|
||||
SB_LOG_ERROR("CoreService", "Failed to load modbus plugin: ", pluginPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -99,7 +138,7 @@ bool CoreService::start(const std::string& profilePath, const std::string& model
|
||||
|
||||
softbus::opcua::UaAddressSpaceBuilder builder(uaEngine_->nativeServer());
|
||||
if (!builder.buildFromModel(model_, uaBinder_.get())) {
|
||||
softbus::core::Logger::instance().error("CoreService", "Failed to build OPC UA address space");
|
||||
SB_LOG_ERROR("CoreService", "Failed to build OPC UA address space");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -109,7 +148,7 @@ bool CoreService::start(const std::string& profilePath, const std::string& model
|
||||
commandDispatcher_ = std::make_unique<CommandDispatcher>(uplink_.get());
|
||||
|
||||
uplink_->setRawPacketHandler([this](const softbus::core::RawPacket& packet) {
|
||||
softbus::core::Logger::instance().infoTrace("CoreService", packet.traceId, "RawPacket received");
|
||||
SB_LOG_INFO_TRACE("CoreService", packet.traceId, "RawPacket received");
|
||||
pipeline_->process(packet);
|
||||
});
|
||||
|
||||
@@ -120,7 +159,7 @@ bool CoreService::start(const std::string& profilePath, const std::string& model
|
||||
uplink_->start();
|
||||
ioThread_ = std::thread([this]() { io_.run(); });
|
||||
running_ = true;
|
||||
softbus::core::Logger::instance().info("CoreService", "Daemon started");
|
||||
SB_LOG_INFO("CoreService", "Daemon started");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -141,7 +180,7 @@ void CoreService::stop()
|
||||
uaEngine_->stop();
|
||||
}
|
||||
modbusPlugin_.unload();
|
||||
softbus::core::Logger::instance().info("CoreService", "Daemon stopped");
|
||||
SB_LOG_INFO("CoreService", "Daemon stopped");
|
||||
}
|
||||
|
||||
void CoreService::run(bool selfTest)
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace softbus::daemon {
|
||||
bool IpcOptionalDBus::initialize()
|
||||
{
|
||||
#if SOFTBUS_HAS_DBUS
|
||||
softbus::core::Logger::instance().info("IpcOptionalDBus", "DBus IPC stub initialized");
|
||||
SB_LOG_INFO("IpcOptionalDBus", "DBus IPC stub initialized");
|
||||
#else
|
||||
softbus::core::Logger::instance().info("IpcOptionalDBus", "DBus IPC disabled on this platform");
|
||||
SB_LOG_INFO("IpcOptionalDBus", "DBus IPC disabled on this platform");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,14 +33,13 @@ void PipelineEngine::process(const softbus::core::RawPacket& packet)
|
||||
|
||||
auto parsed = plugin_->parser()->parseFrame(data, size, packet.sourceId);
|
||||
if (!parsed.success) {
|
||||
softbus::core::Logger::instance().warnTrace("PipelineEngine", packet.traceId,
|
||||
"Failed to parse RawPacket");
|
||||
SB_LOG_WARN_TRACE("PipelineEngine", packet.traceId, "Failed to parse RawPacket");
|
||||
return;
|
||||
}
|
||||
|
||||
parsed.message.traceId = packet.traceId;
|
||||
parsed.message.timestampNs = packet.timestampNs;
|
||||
softbus::core::Logger::instance().infoTrace("PipelineEngine", packet.traceId,
|
||||
SB_LOG_INFO_TRACE("PipelineEngine", packet.traceId,
|
||||
"RawPacket converted to DOMMessage id=", parsed.message.id);
|
||||
binder_->bind(parsed.message);
|
||||
}
|
||||
|
||||
@@ -47,12 +47,11 @@ int main(int argc, char* argv[])
|
||||
|
||||
softbus::edge::DeviceFactory factory;
|
||||
const std::string runtimeDeviceId = factory.createRuntimeDeviceId();
|
||||
softbus::core::Logger::instance().info("Edge", "runtimeDeviceId=", runtimeDeviceId,
|
||||
" (local only, not persisted)");
|
||||
SB_LOG_INFO("Edge", "runtimeDeviceId=", runtimeDeviceId, " (local only, not persisted)");
|
||||
|
||||
softbus::edge::UplinkClient uplink(options.daemonHost, options.daemonPort);
|
||||
uplink.setCommandHandler([](const softbus::api::ExecuteCommand& cmd) {
|
||||
softbus::core::Logger::instance().infoTrace("Edge", cmd.traceId,
|
||||
SB_LOG_INFO_TRACE("Edge", cmd.traceId,
|
||||
"executeCommand received: ", cmd.toJson().dump());
|
||||
});
|
||||
|
||||
@@ -66,13 +65,13 @@ int main(int argc, char* argv[])
|
||||
ingress.open();
|
||||
|
||||
softbus::core::PlatformSignal::install([]() {
|
||||
softbus::core::Logger::instance().info("Edge", "Shutdown requested");
|
||||
SB_LOG_INFO("Edge", "Shutdown requested");
|
||||
});
|
||||
|
||||
while (!softbus::core::PlatformSignal::shouldStop()) {
|
||||
uplink.poll();
|
||||
for (const auto& packet : ingress.poll()) {
|
||||
softbus::core::Logger::instance().infoTrace("Edge", packet.traceId,
|
||||
SB_LOG_INFO_TRACE("Edge", packet.traceId,
|
||||
"Uplink RawPacket objectRef=", packet.sourceId);
|
||||
uplink.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ bool UaAddressSpaceBuilder::buildFromModel(const softbus::core::ObjectModelTree&
|
||||
}
|
||||
}
|
||||
|
||||
softbus::core::Logger::instance().info("UaAddressSpaceBuilder", "Address space built for ", tree.site);
|
||||
SB_LOG_INFO("UaAddressSpaceBuilder", "Address space built for ", tree.site);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -11,25 +11,25 @@ UaEventBridge::UaEventBridge(UA_Server* server)
|
||||
|
||||
void UaEventBridge::emitHeartbeat(const std::string& objectRef)
|
||||
{
|
||||
softbus::core::Logger::instance().debug("UaEventBridge", "Heartbeat stub for ", objectRef);
|
||||
SB_LOG_DEBUG("UaEventBridge", "Heartbeat stub for ", objectRef);
|
||||
(void)server_;
|
||||
}
|
||||
|
||||
void UaEventBridge::emitDeviceOnline(const std::string& stableDeviceKey)
|
||||
{
|
||||
softbus::core::Logger::instance().info("UaEventBridge", "Device online stub: ", stableDeviceKey);
|
||||
SB_LOG_INFO("UaEventBridge", "Device online stub: ", stableDeviceKey);
|
||||
(void)server_;
|
||||
}
|
||||
|
||||
void UaEventBridge::emitDeviceOffline(const std::string& stableDeviceKey)
|
||||
{
|
||||
softbus::core::Logger::instance().info("UaEventBridge", "Device offline stub: ", stableDeviceKey);
|
||||
SB_LOG_INFO("UaEventBridge", "Device offline stub: ", stableDeviceKey);
|
||||
(void)server_;
|
||||
}
|
||||
|
||||
void UaEventBridge::emitParseError(const std::string& objectRef, const std::string& detail)
|
||||
{
|
||||
softbus::core::Logger::instance().warn("UaEventBridge", "Parse error at ", objectRef, ": ", detail);
|
||||
SB_LOG_WARN("UaEventBridge", "Parse error at ", objectRef, ": ", detail);
|
||||
(void)server_;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ bool UaMethodBinder::dispatchCommand(const softbus::api::ExecuteCommand& command
|
||||
if (!handler_) {
|
||||
return false;
|
||||
}
|
||||
softbus::core::Logger::instance().infoTrace("UaMethodBinder", command.traceId,
|
||||
SB_LOG_INFO_TRACE("UaMethodBinder", command.traceId,
|
||||
"ExecuteCommand invoked via OPC UA method");
|
||||
return handler_(command);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ bool UaModelBinder::bind(const softbus::core::DOMMessage& message)
|
||||
const std::string key = message.id.empty() ? message.sourceId : message.id;
|
||||
const auto it = pointNodes_.find(key);
|
||||
if (it == pointNodes_.end()) {
|
||||
softbus::core::Logger::instance().warnTrace("UaModelBinder", message.traceId,
|
||||
SB_LOG_WARN_TRACE("UaModelBinder", message.traceId,
|
||||
"No OPC UA node registered for ", key);
|
||||
return false;
|
||||
}
|
||||
@@ -57,12 +57,12 @@ bool UaModelBinder::bind(const softbus::core::DOMMessage& message)
|
||||
UA_Variant_clear(&variant);
|
||||
|
||||
if (status == UA_STATUSCODE_GOOD) {
|
||||
softbus::core::Logger::instance().infoTrace("UaModelBinder", message.traceId,
|
||||
SB_LOG_INFO_TRACE("UaModelBinder", message.traceId,
|
||||
"Bound DOMMessage to OPC UA node ", key, " value=", numericValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
softbus::core::Logger::instance().errorTrace("UaModelBinder", message.traceId,
|
||||
SB_LOG_ERROR_TRACE("UaModelBinder", message.traceId,
|
||||
"Failed to write OPC UA node ", key);
|
||||
return false;
|
||||
#endif
|
||||
|
||||
@@ -22,12 +22,12 @@ bool UaServerEngine::start(uint16_t port, const std::string& applicationName, co
|
||||
(void)port;
|
||||
(void)applicationName;
|
||||
(void)security;
|
||||
softbus::core::Logger::instance().error("UaServerEngine", "OPC UA support not built in");
|
||||
SB_LOG_ERROR("UaServerEngine", "OPC UA support not built in");
|
||||
return false;
|
||||
#else
|
||||
security_ = security;
|
||||
if (security.enableTls) {
|
||||
softbus::core::Logger::instance().warn("UaServerEngine",
|
||||
SB_LOG_WARN("UaServerEngine",
|
||||
"TLS/mTLS requested but not enabled in Phase1 build");
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ bool UaServerEngine::start(uint16_t port, const std::string& applicationName, co
|
||||
UA_ServerConfig* config = UA_Server_getConfig(server_);
|
||||
UA_StatusCode status = UA_ServerConfig_setMinimal(config, port, nullptr);
|
||||
if (status != UA_STATUSCODE_GOOD) {
|
||||
softbus::core::Logger::instance().error("UaServerEngine", "Failed to configure server");
|
||||
SB_LOG_ERROR("UaServerEngine", "Failed to configure server");
|
||||
UA_Server_delete(server_);
|
||||
server_ = nullptr;
|
||||
return false;
|
||||
@@ -44,14 +44,14 @@ bool UaServerEngine::start(uint16_t port, const std::string& applicationName, co
|
||||
config->applicationDescription.applicationName = UA_LOCALIZEDTEXT_ALLOC("en-US", applicationName.c_str());
|
||||
status = UA_Server_run_startup(server_);
|
||||
if (status != UA_STATUSCODE_GOOD) {
|
||||
softbus::core::Logger::instance().error("UaServerEngine", "Failed to start server");
|
||||
SB_LOG_ERROR("UaServerEngine", "Failed to start server");
|
||||
UA_Server_delete(server_);
|
||||
server_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
running_ = true;
|
||||
softbus::core::Logger::instance().info("UaServerEngine", "OPC UA server started on port ", port);
|
||||
SB_LOG_INFO("UaServerEngine", "OPC UA server started on port ", port);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -33,14 +33,14 @@ bool TcpUplinkClient::connect()
|
||||
std::error_code ec;
|
||||
socket_->connect(asio::ip::tcp::endpoint(asio::ip::make_address(host_), port_), ec);
|
||||
if (ec) {
|
||||
softbus::core::Logger::instance().error("TcpUplinkClient", "Connect failed: ", ec.message());
|
||||
SB_LOG_ERROR("TcpUplinkClient", "Connect failed: ", ec.message());
|
||||
socket_.reset();
|
||||
return false;
|
||||
}
|
||||
connected_ = true;
|
||||
ioThread_ = std::thread([this]() { io_.run(); });
|
||||
doRead();
|
||||
softbus::core::Logger::instance().info("TcpUplinkClient", "Connected to ", host_, ":", port_);
|
||||
SB_LOG_INFO("TcpUplinkClient", "Connected to ", host_, ":", port_);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ void TcpUplinkClient::doRead()
|
||||
[this, buffer](const std::error_code& ec, std::size_t bytes) {
|
||||
if (ec) {
|
||||
connected_ = false;
|
||||
softbus::core::Logger::instance().warn("TcpUplinkClient", "Disconnected from daemon");
|
||||
SB_LOG_WARN("TcpUplinkClient", "Disconnected from daemon");
|
||||
return;
|
||||
}
|
||||
readBuffer_.append(buffer->data(), bytes);
|
||||
|
||||
@@ -26,7 +26,7 @@ void TcpUplinkServer::start()
|
||||
{
|
||||
running_ = true;
|
||||
doAccept();
|
||||
softbus::core::Logger::instance().info("TcpUplinkServer", "Listening on ",
|
||||
SB_LOG_INFO("TcpUplinkServer", "Listening on ",
|
||||
acceptor_.local_endpoint().address().to_string(), ":",
|
||||
acceptor_.local_endpoint().port());
|
||||
}
|
||||
@@ -69,7 +69,7 @@ void TcpUplinkServer::doAccept()
|
||||
}
|
||||
clientSocket_ = socket;
|
||||
readBuffer_.clear();
|
||||
softbus::core::Logger::instance().info("TcpUplinkServer", "Edge connected");
|
||||
SB_LOG_INFO("TcpUplinkServer", "Edge connected");
|
||||
doRead(socket);
|
||||
doAccept();
|
||||
});
|
||||
@@ -81,7 +81,7 @@ void TcpUplinkServer::doRead(const std::shared_ptr<asio::ip::tcp::socket> socket
|
||||
socket->async_read_some(asio::buffer(*buffer),
|
||||
[this, socket, buffer](const std::error_code& ec, std::size_t bytes) {
|
||||
if (ec) {
|
||||
softbus::core::Logger::instance().warn("TcpUplinkServer", "Edge disconnected");
|
||||
SB_LOG_WARN("TcpUplinkServer", "Edge disconnected");
|
||||
if (clientSocket_ == socket) {
|
||||
clientSocket_.reset();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user