34
34
35
35
namespace gr {
36
36
37
+ class Graph ;
38
+ std::string saveGrc (PluginLoader& loader, const gr::Graph& rootGraph);
39
+ inline Graph loadGrc (PluginLoader& loader, std::string_view yamlSrc, std::source_location location = std::source_location::current());
40
+
37
41
namespace graph ::property {
38
42
inline static const char * kEmplaceBlock = " EmplaceBlock" ;
39
43
inline static const char * kRemoveBlock = " RemoveBlock" ;
@@ -54,6 +58,8 @@ inline static const char* kEdgeRemoved = "EdgeRemoved";
54
58
inline static const char * kGraphInspect = " GraphInspect" ;
55
59
inline static const char * kGraphInspected = " GraphInspected" ;
56
60
61
+ inline static const char * kGraphGRC = " GraphGRC" ;
62
+
57
63
inline static const char * kRegistryBlockTypes = " RegistryBlockTypes" ;
58
64
59
65
inline static const char * kSubgraphExportPort = " SubgraphExportPort" ;
@@ -344,6 +350,7 @@ class Graph : public gr::Block<Graph> {
344
350
propertyCallbacks[graph::property::kEmplaceEdge ] = std::mem_fn (&Graph::propertyCallbackEmplaceEdge);
345
351
propertyCallbacks[graph::property::kRemoveEdge ] = std::mem_fn (&Graph::propertyCallbackRemoveEdge);
346
352
propertyCallbacks[graph::property::kGraphInspect ] = std::mem_fn (&Graph::propertyCallbackGraphInspect);
353
+ propertyCallbacks[graph::property::kGraphGRC ] = std::mem_fn (&Graph::propertyCallbackGraphGRC);
347
354
propertyCallbacks[graph::property::kRegistryBlockTypes ] = std::mem_fn (&Graph::propertyCallbackRegistryBlockTypes);
348
355
}
349
356
@@ -702,6 +709,25 @@ class Graph : public gr::Block<Graph> {
702
709
return message;
703
710
}
704
711
712
+ std::optional<Message> propertyCallbackGraphGRC ([[maybe_unused]] std::string_view propertyName, Message message) {
713
+ assert (propertyName == graph::property::kGraphGRC );
714
+
715
+ if (message.cmd == message::Command::Get) {
716
+ message.data = property_map{{" value" , gr::saveGrc (*_pluginLoader, *this )}};
717
+ } else if (message.cmd == message::Command::Set) {
718
+ const auto & data = message.data .value ();
719
+ auto yamlContent = std::get<std::string>(data.at (" value" s));
720
+ *this = gr::loadGrc (*_pluginLoader, yamlContent);
721
+
722
+ setTopologyChanged ();
723
+
724
+ } else {
725
+ throw gr::exception (fmt::format (" Unexpected command type {}" , message.cmd ));
726
+ }
727
+
728
+ return message;
729
+ }
730
+
705
731
std::optional<Message> propertyCallbackRegistryBlockTypes ([[maybe_unused]] std::string_view propertyName, Message message) {
706
732
assert (propertyName == graph::property::kRegistryBlockTypes );
707
733
message.data = property_map{{" types" , _pluginLoader->knownBlocks ()}};
@@ -1467,7 +1493,7 @@ inline gr::property_map saveGraphToMap(PluginLoader& loader, const gr::Graph& ro
1467
1493
1468
1494
} // namespace detail
1469
1495
1470
- inline gr::Graph loadGrc (PluginLoader& loader, std::string_view yamlSrc, std::source_location location = std::source_location::current() ) {
1496
+ inline gr::Graph loadGrc (PluginLoader& loader, std::string_view yamlSrc, std::source_location location) {
1471
1497
Graph resultGraph;
1472
1498
const auto yaml = pmtv::yaml::deserialize (yamlSrc);
1473
1499
if (!yaml) {
0 commit comments