33
33
namespace gr {
34
34
35
35
namespace graph ::property {
36
- inline static const char * kEmplaceBlock = " EmplaceBlock" ;
37
- inline static const char * kRemoveBlock = " RemoveBlock" ;
38
- inline static const char * kReplaceBlock = " ReplaceBlock" ;
39
- inline static const char * kInspectBlock = " InspectBlock" ;
40
-
41
- inline static const char * kBlockEmplaced = " BlockEmplaced" ;
42
- inline static const char * kBlockRemoved = " BlockRemoved" ;
43
- inline static const char * kBlockReplaced = " BlockReplaced" ;
36
+ inline static const char * kInspectBlock = " InspectBlock" ;
44
37
inline static const char * kBlockInspected = " BlockInspected" ;
45
-
46
- inline static const char * kEmplaceEdge = " EmplaceEdge" ;
47
- inline static const char * kRemoveEdge = " RemoveEdge" ;
48
-
49
- inline static const char * kEdgeEmplaced = " EdgeEmplaced" ;
50
- inline static const char * kEdgeRemoved = " EdgeRemoved" ;
51
-
52
38
inline static const char * kGraphInspect = " GraphInspect" ;
53
39
inline static const char * kGraphInspected = " GraphInspected" ;
54
40
@@ -335,12 +321,8 @@ class Graph : public gr::Block<Graph> {
335
321
336
322
Graph (property_map settings = {}) : gr::Block<Graph>(std::move(settings)) {
337
323
_blocks.reserve (100 ); // TODO: remove
338
- propertyCallbacks[graph::property::kEmplaceBlock ] = std::mem_fn (&Graph::propertyCallbackEmplaceBlock);
339
- propertyCallbacks[graph::property::kRemoveBlock ] = std::mem_fn (&Graph::propertyCallbackRemoveBlock);
324
+
340
325
propertyCallbacks[graph::property::kInspectBlock ] = std::mem_fn (&Graph::propertyCallbackInspectBlock);
341
- propertyCallbacks[graph::property::kReplaceBlock ] = std::mem_fn (&Graph::propertyCallbackReplaceBlock);
342
- propertyCallbacks[graph::property::kEmplaceEdge ] = std::mem_fn (&Graph::propertyCallbackEmplaceEdge);
343
- propertyCallbacks[graph::property::kRemoveEdge ] = std::mem_fn (&Graph::propertyCallbackRemoveEdge);
344
326
propertyCallbacks[graph::property::kGraphInspect ] = std::mem_fn (&Graph::propertyCallbackGraphInspect);
345
327
propertyCallbacks[graph::property::kRegistryBlockTypes ] = std::mem_fn (&Graph::propertyCallbackRegistryBlockTypes);
346
328
}
@@ -375,14 +357,10 @@ class Graph : public gr::Block<Graph> {
375
357
*/
376
358
[[nodiscard]] const Sequence& progress () noexcept { return *_progress.get (); }
377
359
378
- BlockModel& addBlock (std::unique_ptr<BlockModel> block, bool doEmitMessage = true ) {
360
+ BlockModel& addBlock (std::unique_ptr<BlockModel> block) {
379
361
auto & newBlock = _blocks.emplace_back (std::move (block));
380
362
newBlock->init (_progress, _ioThreadPool);
381
363
// TODO: Should we connectChildMessagePorts for these blocks as well?
382
- setTopologyChanged ();
383
- if (doEmitMessage) {
384
- this ->emitMessage (graph::property::kBlockEmplaced , serializeBlock (newBlock.get ()));
385
- }
386
364
return *newBlock.get ();
387
365
}
388
366
@@ -393,18 +371,12 @@ class Graph : public gr::Block<Graph> {
393
371
auto & newBlock = _blocks.emplace_back (std::make_unique<BlockWrapper<TBlock>>(std::move (initialSettings)));
394
372
auto * rawBlockRef = static_cast <TBlock*>(newBlock->raw ());
395
373
rawBlockRef->init (_progress, _ioThreadPool);
396
- setTopologyChanged ();
397
- this ->emitMessage (graph::property::kBlockEmplaced , serializeBlock (newBlock.get ()));
398
374
return *rawBlockRef;
399
375
}
400
376
401
377
[[maybe_unused]] auto & emplaceBlock (std::string_view type, property_map initialSettings) {
402
378
if (auto block_load = _pluginLoader->instantiate (type, std::move (initialSettings)); block_load) {
403
- setTopologyChanged ();
404
- auto & newBlock = addBlock (std::move (block_load), false ); // false == do not emit message
405
-
406
- this ->emitMessage (graph::property::kBlockEmplaced , serializeBlock (std::addressof (newBlock)));
407
-
379
+ auto & newBlock = addBlock (std::move (block_load));
408
380
return newBlock;
409
381
}
410
382
throw gr::exception (std::format (" Can not create block {}" , type));
@@ -503,25 +475,6 @@ class Graph : public gr::Block<Graph> {
503
475
return result;
504
476
}
505
477
506
- std::optional<Message> propertyCallbackEmplaceBlock ([[maybe_unused]] std::string_view propertyName, Message message) {
507
- assert (propertyName == graph::property::kEmplaceBlock );
508
- using namespace std ::string_literals;
509
- const auto & data = message.data .value ();
510
- const std::string& type = std::get<std::string>(data.at (" type" s));
511
- const property_map& properties = [&] {
512
- if (auto it = data.find (" properties" s); it != data.end ()) {
513
- return std::get<property_map>(it->second );
514
- } else {
515
- return property_map{};
516
- }
517
- }();
518
-
519
- emplaceBlock (type, properties);
520
-
521
- // Message is sent as a reaction to emplaceBlock, no need for a separate one
522
- return {};
523
- }
524
-
525
478
std::optional<Message> propertyCallbackInspectBlock ([[maybe_unused]] std::string_view propertyName, Message message) {
526
479
assert (propertyName == graph::property::kInspectBlock );
527
480
using namespace std ::string_literals;
@@ -540,12 +493,8 @@ class Graph : public gr::Block<Graph> {
540
493
return {reply};
541
494
}
542
495
543
- std::optional<Message> propertyCallbackRemoveBlock ([[maybe_unused]] std::string_view propertyName, Message message) {
544
- assert (propertyName == graph::property::kRemoveBlock );
545
- using namespace std ::string_literals;
546
- const auto & data = message.data .value ();
547
- const std::string& uniqueName = std::get<std::string>(data.at (" uniqueName" s));
548
- auto it = std::ranges::find_if (_blocks, [&uniqueName](const auto & block) { return block->uniqueName () == uniqueName; });
496
+ void removeBlockByName (std::string_view uniqueName) {
497
+ auto it = std::ranges::find_if (_blocks, [&uniqueName](const auto & block) { return block->uniqueName () == uniqueName; });
549
498
550
499
if (it == _blocks.end ()) {
551
500
throw gr::exception (std::format (" Block {} was not found in {}" , uniqueName, this ->unique_name ));
@@ -554,26 +503,11 @@ class Graph : public gr::Block<Graph> {
554
503
std::erase_if (_edges, [&it](const Edge& edge) { //
555
504
return std::addressof (edge.sourceBlock ()) == it->get () || std::addressof (edge.destinationBlock ()) == it->get ();
556
505
});
557
- _blocks.erase (it);
558
- message.endpoint = graph::property::kBlockRemoved ;
559
506
560
- return {message} ;
507
+ _blocks. erase (it) ;
561
508
}
562
509
563
- std::optional<Message> propertyCallbackReplaceBlock ([[maybe_unused]] std::string_view propertyName, Message message) {
564
- assert (propertyName == graph::property::kReplaceBlock );
565
- using namespace std ::string_literals;
566
- const auto & data = message.data .value ();
567
- const std::string& uniqueName = std::get<std::string>(data.at (" uniqueName" s));
568
- const std::string& type = std::get<std::string>(data.at (" type" s));
569
- const property_map& properties = [&] {
570
- if (auto it = data.find (" properties" s); it != data.end ()) {
571
- return std::get<property_map>(it->second );
572
- } else {
573
- return property_map{};
574
- }
575
- }();
576
-
510
+ gr::BlockModel* replaceBlock (const std::string& uniqueName, const std::string& type, const property_map& properties) {
577
511
auto it = std::ranges::find_if (_blocks, [&uniqueName](const auto & block) { return block->uniqueName () == uniqueName; });
578
512
if (it == _blocks.end ()) {
579
513
throw gr::exception (std::format (" Block {} was not found in {}" , uniqueName, this ->unique_name ));
@@ -585,7 +519,7 @@ class Graph : public gr::Block<Graph> {
585
519
throw gr::exception (std::format (" Can not create block {}" , type));
586
520
}
587
521
588
- addBlock (std::move (newBlock), false ); // false == do not emit message
522
+ addBlock (std::move (newBlock));
589
523
590
524
BlockModel* oldBlock = it->get ();
591
525
for (auto & edge : _edges) {
@@ -599,27 +533,11 @@ class Graph : public gr::Block<Graph> {
599
533
}
600
534
_blocks.erase (it);
601
535
602
- std::optional<Message> result = gr::Message{};
603
- result->endpoint = graph::property::kBlockReplaced ;
604
- result->data = serializeBlock (newBlockRaw);
605
-
606
- (*result->data )[" replacedBlockUniqueName" s] = uniqueName;
607
-
608
- return result;
536
+ return newBlockRaw;
609
537
}
610
538
611
- std::optional<Message> propertyCallbackEmplaceEdge ([[maybe_unused]] std::string_view propertyName, Message message) {
612
- assert (propertyName == graph::property::kEmplaceEdge );
613
- using namespace std ::string_literals;
614
- const auto & data = message.data .value ();
615
- const std::string& sourceBlock = std::get<std::string>(data.at (" sourceBlock" s));
616
- const std::string& sourcePort = std::get<std::string>(data.at (" sourcePort" s));
617
- const std::string& destinationBlock = std::get<std::string>(data.at (" destinationBlock" s));
618
- const std::string& destinationPort = std::get<std::string>(data.at (" destinationPort" s));
619
- [[maybe_unused]] const std::size_t minBufferSize = std::get<gr::Size_t>(data.at (" minBufferSize" s));
620
- [[maybe_unused]] const std::int32_t weight = std::get<std::int32_t >(data.at (" weight" s));
621
- const std::string edgeName = std::get<std::string>(data.at (" edgeName" s));
622
-
539
+ void emplaceEdge (std::string_view sourceBlock, std::string sourcePort, std::string_view destinationBlock, //
540
+ std::string destinationPort, [[maybe_unused]] const std::size_t minBufferSize, [[maybe_unused]] const std::int32_t weight, std::string_view edgeName) {
623
541
auto sourceBlockIt = std::ranges::find_if (_blocks, [&sourceBlock](const auto & block) { return block->uniqueName () == sourceBlock; });
624
542
if (sourceBlockIt == _blocks.end ()) {
625
543
throw gr::exception (std::format (" Block {} was not found in {}" , sourceBlock, this ->unique_name ));
@@ -645,31 +563,20 @@ class Graph : public gr::Block<Graph> {
645
563
646
564
const bool isArithmeticLike = sourcePortRef.portInfo ().isValueTypeArithmeticLike ;
647
565
const std::size_t sanitizedMinBufferSize = minBufferSize == undefined_size ? graph::defaultMinBufferSize (isArithmeticLike) : minBufferSize;
648
- _edges.emplace_back (sourceBlockIt->get (), sourcePort, destinationBlockIt->get (), destinationPort, sanitizedMinBufferSize, weight, edgeName);
649
-
650
- message.endpoint = graph::property::kEdgeEmplaced ;
651
- return message;
566
+ _edges.emplace_back (sourceBlockIt->get (), sourcePort, destinationBlockIt->get (), destinationPort, sanitizedMinBufferSize, weight, std::string (edgeName));
652
567
}
653
568
654
- std::optional<Message> propertyCallbackRemoveEdge ([[maybe_unused]] std::string_view propertyName, Message message) {
655
- assert (propertyName == graph::property::kRemoveEdge );
656
- using namespace std ::string_literals;
657
- const auto & data = message.data .value ();
658
- const std::string& sourceBlock = std::get<std::string>(data.at (" sourceBlock" s));
659
- const std::string& sourcePort = std::get<std::string>(data.at (" sourcePort" s));
660
-
569
+ void removeEdgeBySourcePort (std::string_view sourceBlock, std::string_view sourcePort) {
661
570
auto sourceBlockIt = std::ranges::find_if (_blocks, [&sourceBlock](const auto & block) { return block->uniqueName () == sourceBlock; });
662
571
if (sourceBlockIt == _blocks.end ()) {
663
572
throw gr::exception (std::format (" Block {} was not found in {}" , sourceBlock, this ->unique_name ));
664
573
}
665
574
666
- auto & sourcePortRef = (*sourceBlockIt)->dynamicOutputPort (sourcePort);
575
+ auto & sourcePortRef = (*sourceBlockIt)->dynamicOutputPort (std::string ( sourcePort) );
667
576
668
577
if (sourcePortRef.disconnect () == ConnectionResult::FAILED) {
669
578
throw gr::exception (std::format (" Block {} sourcePortRef could not be disconnected {}" , sourceBlock, this ->unique_name ));
670
579
}
671
- message.endpoint = graph::property::kEdgeRemoved ;
672
- return message;
673
580
}
674
581
675
582
std::optional<Message> propertyCallbackGraphInspect ([[maybe_unused]] std::string_view propertyName, Message message) {
0 commit comments