hardcoded decklink mode fix
This commit is contained in:
@@ -11,7 +11,7 @@ struct lws;
|
||||
|
||||
namespace dmf_node {
|
||||
|
||||
using CommandHandler = std::function<void(const nlohmann::json& payload)>;
|
||||
using CommandHandler = std::function<nlohmann::json(const nlohmann::json& payload)>;
|
||||
using StatusCallback = std::function<void(const nlohmann::json& event)>;
|
||||
|
||||
class ControlServer {
|
||||
|
||||
@@ -29,17 +29,18 @@ struct ControlServer::Impl {
|
||||
struct lws_context* context = nullptr;
|
||||
};
|
||||
|
||||
static void dispatch_command(ControlServerData* data, const nlohmann::json& msg) {
|
||||
static nlohmann::json dispatch_command(ControlServerData* data, const nlohmann::json& msg) {
|
||||
if (!msg.contains("cmd")) {
|
||||
spdlog::warn("Control: message missing 'cmd' field");
|
||||
return;
|
||||
return {{"error", "missing 'cmd' field"}};
|
||||
}
|
||||
auto cmd = msg["cmd"].get<std::string>();
|
||||
auto it = data->commands.find(cmd);
|
||||
if (it != data->commands.end()) {
|
||||
it->second(msg);
|
||||
return it->second(msg);
|
||||
} else {
|
||||
spdlog::warn("Control: unknown command '{}'", cmd);
|
||||
return {{"error", "unknown command: " + cmd}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,8 +103,8 @@ static int callback_all(struct lws* wsi, enum lws_callback_reasons reason,
|
||||
}
|
||||
try {
|
||||
auto msg = nlohmann::json::parse(ps->http_body);
|
||||
dispatch_command(ps->data, msg);
|
||||
return send_http_json(wsi, "200 OK", R"({"ok":true})");
|
||||
auto result = dispatch_command(ps->data, msg);
|
||||
return send_http_json(wsi, "200 OK", result.dump());
|
||||
} catch (const nlohmann::json::parse_error& e) {
|
||||
return send_http_json(wsi, "400 Bad Request",
|
||||
nlohmann::json({{"error", e.what()}}).dump());
|
||||
|
||||
@@ -101,7 +101,7 @@ int NodeRunner::exec(std::unique_ptr<Node> node) {
|
||||
};
|
||||
std::vector<FlowResource> flow_resources;
|
||||
|
||||
control_server->register_command("add_writer", [&](const nlohmann::json& msg) {
|
||||
control_server->register_command("add_writer", [&](const nlohmann::json& msg) -> nlohmann::json {
|
||||
auto flow_id = msg["flow_id"].get<std::string>();
|
||||
auto port_id = msg["port_id"].get<std::string>();
|
||||
auto flow_def = msg["flow_def"].dump();
|
||||
@@ -112,14 +112,15 @@ int NodeRunner::exec(std::unique_ptr<Node> node) {
|
||||
auto status = mxlCreateFlowWriter(mxl_instance_, flow_def.c_str(), nullptr, &writer, &config_info, &created);
|
||||
if (status != MXL_STATUS_OK || !writer) {
|
||||
spdlog::error("Failed to create flow writer for flow {}: status={}", flow_id, static_cast<int>(status));
|
||||
return;
|
||||
return {{"ok", false}, {"error", "failed to create flow writer"}};
|
||||
}
|
||||
spdlog::info("Created flow writer on port '{}' flow {} (created={})", port_id, flow_id, created);
|
||||
flow_resources.push_back({port_id, writer, nullptr});
|
||||
node->on_add_writer(port_id, writer);
|
||||
return {{"ok", true}};
|
||||
});
|
||||
|
||||
control_server->register_command("add_reader", [&](const nlohmann::json& msg) {
|
||||
control_server->register_command("add_reader", [&](const nlohmann::json& msg) -> nlohmann::json {
|
||||
auto flow_id = msg["flow_id"].get<std::string>();
|
||||
auto port_id = msg["port_id"].get<std::string>();
|
||||
|
||||
@@ -127,14 +128,15 @@ int NodeRunner::exec(std::unique_ptr<Node> node) {
|
||||
auto status = mxlCreateFlowReader(mxl_instance_, flow_id.c_str(), nullptr, &reader);
|
||||
if (status != MXL_STATUS_OK || !reader) {
|
||||
spdlog::error("Failed to create flow reader for flow {}: status={}", flow_id, static_cast<int>(status));
|
||||
return;
|
||||
return {{"ok", false}, {"error", "failed to create flow reader"}};
|
||||
}
|
||||
spdlog::info("Created flow reader on port '{}' flow {}", port_id, flow_id);
|
||||
flow_resources.push_back({port_id, nullptr, reader});
|
||||
node->on_add_reader(port_id, reader);
|
||||
return {{"ok", true}};
|
||||
});
|
||||
|
||||
control_server->register_command("remove_writer", [&](const nlohmann::json& msg) {
|
||||
control_server->register_command("remove_writer", [&](const nlohmann::json& msg) -> nlohmann::json {
|
||||
auto port_id = msg["port_id"].get<std::string>();
|
||||
node->on_remove_writer(port_id);
|
||||
for (auto it = flow_resources.begin(); it != flow_resources.end(); ++it) {
|
||||
@@ -145,9 +147,10 @@ int NodeRunner::exec(std::unique_ptr<Node> node) {
|
||||
}
|
||||
}
|
||||
spdlog::info("Removed writer on port '{}'", port_id);
|
||||
return {{"ok", true}};
|
||||
});
|
||||
|
||||
control_server->register_command("remove_reader", [&](const nlohmann::json& msg) {
|
||||
control_server->register_command("remove_reader", [&](const nlohmann::json& msg) -> nlohmann::json {
|
||||
auto port_id = msg["port_id"].get<std::string>();
|
||||
node->on_remove_reader(port_id);
|
||||
for (auto it = flow_resources.begin(); it != flow_resources.end(); ++it) {
|
||||
@@ -158,26 +161,30 @@ int NodeRunner::exec(std::unique_ptr<Node> node) {
|
||||
}
|
||||
}
|
||||
spdlog::info("Removed reader on port '{}'", port_id);
|
||||
return {{"ok", true}};
|
||||
});
|
||||
|
||||
control_server->register_command("configure", [&](const nlohmann::json& msg) {
|
||||
control_server->register_command("configure", [&](const nlohmann::json& msg) -> nlohmann::json {
|
||||
if (msg.contains("params")) {
|
||||
node->configure(msg["params"]);
|
||||
spdlog::info("Reconfigured node '{}'", node_id_);
|
||||
}
|
||||
return {{"ok", true}};
|
||||
});
|
||||
|
||||
control_server->register_command("status", [&](const nlohmann::json& /*msg*/) {
|
||||
control_server->register_command("status", [&](const nlohmann::json& /*msg*/) -> nlohmann::json {
|
||||
nlohmann::json resp;
|
||||
resp["event"] = "status";
|
||||
resp["node_id"] = node_id_;
|
||||
resp["data"] = node->status();
|
||||
control_server->send_event(resp);
|
||||
return resp;
|
||||
});
|
||||
|
||||
control_server->register_command("shutdown", [&](const nlohmann::json& /*msg*/) {
|
||||
control_server->register_command("shutdown", [&](const nlohmann::json& /*msg*/) -> nlohmann::json {
|
||||
spdlog::info("Shutdown command received");
|
||||
g_running = false;
|
||||
return {{"ok", true}};
|
||||
});
|
||||
|
||||
nlohmann::json ready_event;
|
||||
|
||||
Reference in New Issue
Block a user