Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ target_sources(dsr_api
dsr_inner_eigen_api.cpp
dsr_rt_api.cpp
dsr_utils.cpp
dsr_signal_emitter.cpp
GHistorySaver.cpp
${GEOM_API_SOURCES}
${headers_to_moc}
Expand Down
187 changes: 108 additions & 79 deletions api/dsr_api.cpp

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions api/dsr_rt_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, const std::vector<fl

if (!no_send and node2.has_value()) G->dsrpub_node_attrs.write(&node2.value());

emit G->update_edge_attr_signal(n.id(), to, "RT" ,{"rt_rotation_euler_xyz", "rt_translation"}, SignalInfo{ G->agent_id });
emit G->update_edge_signal(n.id(), to, "RT", SignalInfo{ G->agent_id });
G->emitter.update_edge_attr_signal(n.id(), to, "RT" ,{"rt_rotation_euler_xyz", "rt_translation"}, SignalInfo{ G->agent_id });
G->emitter.update_edge_signal(n.id(), to, "RT", SignalInfo{ G->agent_id });
if (!no_send)
{
emit G->update_node_signal(to_n->id(), to_n->type(), SignalInfo{ G->agent_id });
emit G->update_node_attr_signal(to_n->id(), {"level", "parent"}, SignalInfo{ G->agent_id });
G->emitter.update_node_signal(to_n->id(), to_n->type(), SignalInfo{ G->agent_id });
G->emitter.update_node_attr_signal(to_n->id(), {"level", "parent"}, SignalInfo{ G->agent_id });
}
}
}
Expand Down Expand Up @@ -528,12 +528,12 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, std::vector<float> &

if (!no_send and node2.has_value()) G->dsrpub_node_attrs.write(&node2.value());

emit G->update_edge_attr_signal(n.id(), to, "RT",{"rt_rotation_euler_xyz", "rt_translation"}, SignalInfo{ G->agent_id });
emit G->update_edge_signal(n.id(), to, "RT", SignalInfo{ G->agent_id });
G->emitter.update_edge_attr_signal(n.id(), to, "RT",{"rt_rotation_euler_xyz", "rt_translation"}, SignalInfo{ G->agent_id });
G->emitter.update_edge_signal(n.id(), to, "RT", SignalInfo{ G->agent_id });
if (!no_send)
{
emit G->update_node_signal(to_n->id(), to_n->type(), SignalInfo{ G->agent_id });
emit G->update_node_attr_signal(to_n->id(), {"level", "parent"}, SignalInfo{ G->agent_id });
G->emitter.update_node_signal(to_n->id(), to_n->type(), SignalInfo{ G->agent_id });
G->emitter.update_node_attr_signal(to_n->id(), {"level", "parent"}, SignalInfo{ G->agent_id });
}
}
}
94 changes: 94 additions & 0 deletions api/dsr_signal_emitter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <dsr/api/dsr_api.h>
#include <dsr/api/dsr_signal_emitter.h>
#include <dsr/api/dsr_signal_info.h>
#include <dsr/api/dsr_logging.h>

void DSR::QueuedSignalRunner::run_update_node_signal(std::uint64_t a,
const std::string &b,
SignalInfo c) {
DSR_LOG_DEBUG_L(static_cast<DSR::GraphSettings::LOGLEVEL>(log_level), "[SIGNAL] update_node id:", a, "type:", b);
tp.spawn_task([=, this] {
for (auto fn : uns_fns) {
if (fn)
fn(a, b);
}
});
}
void DSR::QueuedSignalRunner::run_update_node_attr_signal(
std::uint64_t a, const std::vector<std::string> &b, SignalInfo c) {
DSR_LOG_DEBUG_L(static_cast<DSR::GraphSettings::LOGLEVEL>(log_level), "[SIGNAL] update_node_attr id:", a);
tp.spawn_task([=, this] {
for (auto fn : unas_fns) {
if (fn)
fn(a, b);
}
});
}
void DSR::QueuedSignalRunner::run_update_edge_signal(std::uint64_t a,
std::uint64_t b,
const std::string &c,
SignalInfo d) {
DSR_LOG_DEBUG_L(static_cast<DSR::GraphSettings::LOGLEVEL>(log_level), "[SIGNAL] update_edge from:", a, "to:", b, "type:", c);
tp.spawn_task([=, this] {
for (auto fn : ues_fns) {
if (fn)
fn(a, b, c);
}
});
}

void DSR::QueuedSignalRunner::run_update_edge_attr_signal(
std::uint64_t a, std::uint64_t b, const std::string &c,
const std::vector<std::string> &d, SignalInfo e) {
DSR_LOG_DEBUG_L(static_cast<DSR::GraphSettings::LOGLEVEL>(log_level), "[SIGNAL] update_edge_attr from:", a, "to:", b, "type:", c);
tp.spawn_task([=, this] {
for (auto fn : ueas_fns) {
if (fn)
fn(a, b, c, d);
}
});
}

void DSR::QueuedSignalRunner::run_del_edge_signal(std::uint64_t a,
std::uint64_t b,
const std::string &c,
SignalInfo d) {
DSR_LOG_DEBUG_L(static_cast<DSR::GraphSettings::LOGLEVEL>(log_level), "[SIGNAL] del_edge from:", a, "to:", b, "type:", c);
tp.spawn_task([=, this] {
for (auto fn : des_fns) {
if (fn)
fn(a, b, c);
}
});
}
void DSR::QueuedSignalRunner::run_del_node_signal(std::uint64_t a,
SignalInfo b) {
DSR_LOG_DEBUG_L(static_cast<DSR::GraphSettings::LOGLEVEL>(log_level), "[SIGNAL] del_node id:", a);
tp.spawn_task([=, this] {
for (auto fn : den_fns) {
if (fn)
fn(a);
}
});
}

void DSR::QueuedSignalRunner::run_deleted_node_signal(const Node &a,
SignalInfo b) {
DSR_LOG_DEBUG_L(static_cast<DSR::GraphSettings::LOGLEVEL>(log_level), "[SIGNAL] deleted_node name:", a.name(), "id:", a.id());
tp.spawn_task([=, this] {
for (auto fn : dn_fns) {
if (fn)
fn(a);
}
});
}
void DSR::QueuedSignalRunner::run_deleted_edge_signal(const Edge &a,
SignalInfo b) {
DSR_LOG_DEBUG_L(static_cast<DSR::GraphSettings::LOGLEVEL>(log_level), "[SIGNAL] deleted_edge from:", a.from(), "to:", a.to(), "type:", a.type());
tp.spawn_task([=, this] {
for (auto fn : de_fns) {
if (fn)
fn(a);
}
});
}
52 changes: 49 additions & 3 deletions api/include/dsr/api/dsr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
#include "dsr/api/dsr_utils.h"
#include "dsr/api/dsr_signal_info.h"
#include "dsr/api/dsr_graph_settings.h"
#include "dsr/api/dsr_logging.h"
#include "dsr/api/dsr_signal_emitter.h"
#include "dsr/core/types/type_checking/dsr_edge_type.h"
#include "dsr/core/types/type_checking/dsr_node_type.h"
#include "dsr/core/types/type_checking/dsr_attr_name.h"
#include "dsr/core/utils.h"
#include "dsr/core/id_generator.h"
#include "dsr_signal_emitter.h"
#include "threadpool/threadpool.h"

#include <QObject>
Expand All @@ -57,9 +60,9 @@ namespace DSR
size_t size() const;

DSRGraph(GraphSettings settings);
DSRGraph(std::string name, uint32_t id, const std::string& dsr_input_file = std::string(), bool all_same_host = true, int8_t domain_id=0);
[[deprecated("root parameter is not used anymore")]] DSRGraph(uint64_t root, std::string name, int id, const std::string& dsr_input_file = std::string(), bool all_same_host = true, int8_t domain_id=0)
: DSRGraph(name, id, dsr_input_file, all_same_host, domain_id)
DSRGraph(std::string name, uint32_t id, const std::string& dsr_input_file = std::string(), bool all_same_host = true, int8_t domain_id=0, SignalMode = SignalMode::QT);
[[deprecated("root parameter is not used anymore")]] DSRGraph(uint64_t root, std::string name, int id, const std::string& dsr_input_file = std::string(), bool all_same_host = true, int8_t domain_id=0, SignalMode mode = SignalMode::QT)
: DSRGraph(name, id, dsr_input_file, all_same_host, domain_id, mode)
{}

~DSRGraph() override;
Expand Down Expand Up @@ -539,6 +542,14 @@ namespace DSR
return ret_vec;
}


//////////////////////////////////////////////////
///// QueuedSignals for python
/////////////////////////////////////////////////

QueuedSignalRunner* get_signal_runner() {
return emitter.runner.get();
}
private:

DSRGraph(const DSRGraph& G); //Private constructor for DSRCopy
Expand All @@ -557,6 +568,41 @@ namespace DSR
bool same_host;
id_generator generator;
GraphSettings::LOGLEVEL log_level;
signals_fns emitter;

//////////////////////////////////////////////////////////////////////////
// Signal method
///////////////////////////////////////////////////////////////////////////

void set_qt_signals (){
emitter = {
[this](std::uint64_t a, const std::string & b, SignalInfo c = {}) { DSR_LOG_DEBUG("[SIGNAL] update_node id:", a, "type:", b); emit update_node_signal(a, b, c); },
[this](std::uint64_t a, const std::vector<std::string> &b, SignalInfo c = {}) { DSR_LOG_DEBUG("[SIGNAL] update_node_attr id:", a); emit update_node_attr_signal(a, b, c); },
[this](std::uint64_t a, std::uint64_t b, const std::string & c, SignalInfo d = {}) { DSR_LOG_DEBUG("[SIGNAL] update_edge from:", a, "to:", b, "type:", c); emit update_edge_signal(a, b, c, d); },
[this](std::uint64_t a, std::uint64_t b, const std::string & c, const std::vector<std::string> &d, SignalInfo e = {}) { DSR_LOG_DEBUG("[SIGNAL] update_edge_attr from:", a, "to:", b, "type:", c); emit update_edge_attr_signal(a, b, c, d, e); },
[this](std::uint64_t a, std::uint64_t b, const std::string & c, SignalInfo d = {}) { DSR_LOG_DEBUG("[SIGNAL] del_edge from:", a, "to:", b, "type:", c); emit del_edge_signal(a, b, c, d); },
[this](std::uint64_t a, SignalInfo b = {}) { DSR_LOG_DEBUG("[SIGNAL] del_node id:", a); emit del_node_signal(a, b); },
[this](const Node& a, SignalInfo b = {}) { DSR_LOG_DEBUG("[SIGNAL] deleted_node name:", a.name(), "id:", a.id()); emit deleted_node_signal(a, b); },
[this](const Edge& a, SignalInfo b = {}) { DSR_LOG_DEBUG("[SIGNAL] deleted_edge from:", a.from(), "to:", a.to(), "type:", a.type()); emit deleted_edge_signal(a, b); },
nullptr
};
}

void set_queued_signals (){
auto runner = new QueuedSignalRunner();
runner->log_level = static_cast<uint8_t>(log_level);
emitter = {
[runner](std::uint64_t a, const std::string & b, SignalInfo c = {}) { runner->run_update_node_signal(a, b, c); },
[runner](std::uint64_t a, const std::vector<std::string> &b, SignalInfo c = {}) { runner->run_update_node_attr_signal(a, b, c); },
[runner](std::uint64_t a, std::uint64_t b, const std::string & c, SignalInfo d = {}) { runner->run_update_edge_signal(a, b, c, d); },
[runner](std::uint64_t a, std::uint64_t b, const std::string & c, const std::vector<std::string> &d, SignalInfo e = {}) { runner->run_update_edge_attr_signal(a, b, c, d, e); },
[runner](std::uint64_t a, std::uint64_t b, const std::string & c, SignalInfo d = {}) { runner->run_del_edge_signal(a, b, c, d); },
[runner](std::uint64_t a, SignalInfo b = {}) { runner->run_del_node_signal(a, b); },
[runner](const Node& a, SignalInfo b = {}) { runner->run_deleted_node_signal(a, b); },
[runner](const Edge& a, SignalInfo b = {}) { runner->run_deleted_edge_signal(a, b); },
std::unique_ptr<QueuedSignalRunner>(runner)
};
}

//////////////////////////////////////////////////////////////////////////
// Cache maps
Expand Down
2 changes: 2 additions & 0 deletions api/include/dsr/api/dsr_graph_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <string>
#include <dsr/api/dsr_signal_emitter.h>

namespace DSR {

Expand All @@ -17,6 +18,7 @@ struct GraphSettings {
DEBUGL = 0, INFOL, WARNINGL, ERRORL
} log_level {LOGLEVEL::INFOL};
int8_t domain_id = 0;
SignalMode signal_mode = QT;
};

}
69 changes: 69 additions & 0 deletions api/include/dsr/api/dsr_logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

#include <iostream>
#include <tuple>
#include <utility>
#include <dsr/api/dsr_graph_settings.h>

// ANSI color codes
#define DSR_COLOR_RESET "\033[0m"
#define DSR_COLOR_DEBUG "\033[36m" // Cyan
#define DSR_COLOR_INFO "\033[32m" // Green
#define DSR_COLOR_WARNING "\033[33m" // Yellow
#define DSR_COLOR_ERROR "\033[31m" // Red

// Logging macros for use inside DSRGraph (where log_level is a member)
#define DSR_LOG_DEBUG(...) do { if (log_level <= DSR::GraphSettings::LOGLEVEL::DEBUGL) { std::cout << DSR_COLOR_DEBUG "[DSR DEBUG] " DSR_COLOR_RESET; DSR_LOG_PRINT(__VA_ARGS__); } } while(0)
#define DSR_LOG_INFO(...) do { if (log_level <= DSR::GraphSettings::LOGLEVEL::INFOL) { std::cout << DSR_COLOR_INFO "[DSR INFO] " DSR_COLOR_RESET; DSR_LOG_PRINT(__VA_ARGS__); } } while(0)
#define DSR_LOG_WARNING(...) do { if (log_level <= DSR::GraphSettings::LOGLEVEL::WARNINGL) { std::cout << DSR_COLOR_WARNING "[DSR WARNING] " DSR_COLOR_RESET; DSR_LOG_PRINT(__VA_ARGS__); } } while(0)
#define DSR_LOG_ERROR(...) do { if (log_level <= DSR::GraphSettings::LOGLEVEL::ERRORL) { std::cout << DSR_COLOR_ERROR "[DSR ERROR] " DSR_COLOR_RESET; DSR_LOG_PRINT(__VA_ARGS__); } } while(0)

// Logging macros with explicit log level parameter (for use outside DSRGraph, e.g. signal emitter)
#define DSR_LOG_DEBUG_L(lvl, ...) do { if ((lvl) <= DSR::GraphSettings::LOGLEVEL::DEBUGL) { std::cout << DSR_COLOR_DEBUG "[DSR DEBUG] " DSR_COLOR_RESET; DSR_LOG_PRINT(__VA_ARGS__); } } while(0)
#define DSR_LOG_INFO_L(lvl, ...) do { if ((lvl) <= DSR::GraphSettings::LOGLEVEL::INFOL) { std::cout << DSR_COLOR_INFO "[DSR INFO] " DSR_COLOR_RESET; DSR_LOG_PRINT(__VA_ARGS__); } } while(0)
#define DSR_LOG_WARNING_L(lvl, ...) do { if ((lvl) <= DSR::GraphSettings::LOGLEVEL::WARNINGL) { std::cout << DSR_COLOR_WARNING "[DSR WARNING] " DSR_COLOR_RESET; DSR_LOG_PRINT(__VA_ARGS__); } } while(0)

// Internal: print helpers for composite types
namespace dsr_log_detail {

template<typename T1, typename T2>
inline void print_value(std::ostream& os, const std::pair<T1, T2>& p) {
os << '(' << p.first << ", " << p.second << ')';
}

template<typename... Ts>
inline void print_value(std::ostream& os, const std::tuple<Ts...>& t) {
os << '(';
std::apply([&os](const auto&... args) {
size_t n = 0;
((os << (n++ ? ", " : "") << args), ...);
}, t);
os << ')';
}

inline void print_value(std::ostream& os, bool v) {
os << (v ? "true" : "false");
}

template<typename T>
inline void print_value(std::ostream& os, const T& v) {
os << v;
}

} // namespace dsr_log_detail

// Internal: print variadic args separated by spaces
inline void dsr_log_print_impl() { std::cout << std::endl; }

template<typename T, typename... Args>
inline void dsr_log_print_impl(const T& first, const Args&... rest) {
dsr_log_detail::print_value(std::cout, first);
if constexpr (sizeof...(rest) > 0) {
std::cout << ' ';
dsr_log_print_impl(rest...);
} else {
std::cout << std::endl;
}
}

#define DSR_LOG_PRINT(...) dsr_log_print_impl(__VA_ARGS__)
Loading
Loading