Fabric 0.2.0
Loading...
Searching...
No Matches
compatibility_plugin.hpp
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <vector>
4#include <tinyxml2.h>
5#include <rclcpp/rclcpp.hpp>
7
8namespace fabric
9{
16{
17public:
19 virtual ~CompatibilityValidation() = default;
20
24 void initialize(const rclcpp::Node::SharedPtr& node) override
25 {
26 initialize_base(node, "CompatibilityValidationPlugin");
27 }
28
35 void validate(fabric::Plan& plan, std::vector<CapabilityInfo>& capabilities) override
36 {
37 // Iterate through the plan and check whether each connection's interface and provider are matched in
38 // the provided CapabilityInfo data. If a provider is not matched, it could be in alternative providers.
39
40 for (const auto& [id, connection] : plan.connections)
41 {
42 bool source_matched = false;
43
44 // Check source node
45 for (const auto& cap : capabilities)
46 {
47 if (connection.source.interface == cap.interface)
48 {
49 if (connection.source.provider == cap.provider)
50 {
51 source_matched = true;
52 break;
53 }
54 else
55 {
56 // Check alternative providers
57 if (std::find(cap.alt_providers.begin(), cap.alt_providers.end(), connection.source.provider) != cap.alt_providers.end())
58 {
59 source_matched = true;
60 break;
61 }
62 }
63 }
64 }
65
66 if (!source_matched)
67 {
68 throw fabric::fabric_exception("Unmatched interface: " + connection.source.interface + " provider: " + connection.source.provider +
69 " combination");
70 }
71 }
72 }
73};
74} // namespace fabric
Syntax validation plugin for XML plans.
Definition compatibility_plugin.hpp:16
void validate(fabric::Plan &plan, std::vector< CapabilityInfo > &capabilities) override
Validate the given XML plan for compatibility.
Definition compatibility_plugin.hpp:35
virtual ~CompatibilityValidation()=default
void initialize(const rclcpp::Node::SharedPtr &node) override
Initialize the syntax validation plugin.
Definition compatibility_plugin.hpp:24
Abstract base class for XML plan validation plugins.
Definition validation_base.hpp:19
void initialize_base(const rclcpp::Node::SharedPtr &node, const std::string &plugin_name)
Base initialization method for derived classes.
Definition validation_base.hpp:48
Definition parser_base.hpp:9
Definition structs.hpp:70
std::map< int, connection > connections
Definition structs.hpp:74
Structure representing connections between nodes.
Definition structs.hpp:42
node source
Definition structs.hpp:43
Base class for driver exceptions.
Definition exception.hpp:14
Structure representing a node in the fabric.
Definition structs.hpp:26
std::string provider
Definition structs.hpp:28
std::string interface
Definition structs.hpp:27