Skip to content

get_capability_spec() overwrites the msg content interface and provider have same name #36

Open

Description

@KalanaRatnayake

`const capabilities2_msgs::msg::CapabilitySpec get_capability_spec(const std::string& resource)
{
capabilities2_msgs::msg::CapabilitySpec msg;

// search db for resource
// interfaces
models::interface_model_t interface = cap_db_->get_interface(resource);

if (!interface.header.name.empty())
{
  // package name is first part of name separated by /
  msg.package = interface.header.name.substr(0, interface.header.name.find_first_of('/'));
  msg.type = interface.header.type;
  // get spec convert to yaml then to string
  YAML::Node spec = interface.to_yaml();
  // fix name to remove package name
  spec["name"] = spec["name"].as<std::string>().substr(interface.header.name.find_first_of('/') + 1);
  msg.content = YAML::Dump(spec);
}

// semantic interfaces
models::semantic_interface_model_t semantic_interface = cap_db_->get_semantic_interface(resource);

if (!semantic_interface.header.name.empty())
{
  msg.package = semantic_interface.header.name.substr(0, semantic_interface.header.name.find_first_of('/'));
  msg.type = semantic_interface.header.type;
  YAML::Node spec = semantic_interface.to_yaml();
  spec["name"] = spec["name"].as<std::string>().substr(semantic_interface.header.name.find_first_of('/') + 1);
  msg.content = YAML::Dump(spec);
}

// providers
models::provider_model_t provider = cap_db_->get_provider(resource);

if (!provider.header.name.empty())
{
  msg.package = provider.header.name.substr(0, provider.header.name.find_first_of('/'));
  msg.type = provider.header.type;
  YAML::Node spec = provider.to_yaml();
  spec["name"] = spec["name"].as<std::string>().substr(provider.header.name.find_first_of('/') + 1);
  msg.content = YAML::Dump(spec);
}

return msg;

}`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions