예제 #1
0
class SemanticCapabilityInterface(object):
    """Represents a Semantic Capability Interface

    A Semantic Capability Interface is defined by:

    - name (str): name of the redefined interface
    - redefines (str): name of a capability being redefined
    - spec_type (str): type of the interface specification (has to be 'semantic_interface')
    - spec_version (int): version of the interface specification
    - description (str): free form description of the interface
    - global_namespace (str or None): (optional) global namespace for all ROS Names, None means no global_namespace
    - remappings (dict): (optional) map from ROS Names in redefined interface to Names in this interface
    """
    spec_type = 'interface'

    def __init__(self, name, redefines, spec_version, description=None, global_namespace=None):
        self.name = name
        self.redefines = redefines
        self.spec_version = spec_version
        self.description = description
        self.global_namespace = global_namespace
        self.__remap_collection = RemapCollection()

    @property
    def remappings(self):
        return self.__remap_collection.remappings

    def add_remappings_by_dict(self, remappings_dict):
        self.__remap_collection.add_remappings_by_dict(remappings_dict)
예제 #2
0
class DependsOnRelationship(object):
    """Models the depends_on relationship between a Capability Provider and a Capability

    This relationship consists of:

    - capability_name (str): name of the Capability which is depended on
    - provider_preference (str): (optional) name of preferred provider for the Capability which is depended on
    - remappings (dict): map of ROS Names defined in the Capability to their new names for this provider
    """
    valid_remapping_types = ['topics', 'services', 'parameters', 'actions']

    def __init__(self, capability_name, preferred_provider):
        self.name = capability_name
        self.capability_name = capability_name
        self.provider = preferred_provider
        self.preferred_provider = preferred_provider
        self.__remap_collection = RemapCollection()

    def __str__(self):
        msg = "{0}:\n{1}".format(self.name, str(self.__remap_collection))
        if self.provider:
            msg += "\npreferred provider: {0}".format(self.provider)
        return msg

    @property
    def remappings(self):
        return self.__remap_collection.remappings

    def add_remappings_by_dict(self, remappings_dict):
        self.__remap_collection.add_remappings_by_dict(remappings_dict)
예제 #3
0
class SemanticCapabilityInterface(object):
    """Represents a Semantic Capability Interface

    A Semantic Capability Interface is defined by:

    - name (str): name of the redefined interface
    - redefines (str): name of a capability being redefined
    - spec_type (str): type of the interface specification (has to be 'semantic_interface')
    - spec_version (int): version of the interface specification
    - description (str): free form description of the interface
    - global_namespace (str or None): (optional) global namespace for all ROS Names, None means no global_namespace
    - remappings (dict): (optional) map from ROS Names in redefined interface to Names in this interface
    """
    spec_type = 'interface'

    def __init__(self, name, redefines, spec_version, description=None, global_namespace=None):
        self.name = name
        self.redefines = redefines
        self.spec_version = spec_version
        self.default_provider = 'unknown'
        self.description = description
        self.global_namespace = global_namespace
        self.__remap_collection = RemapCollection()

    @property
    def remappings(self):
        return self.__remap_collection.remappings

    def add_remappings_by_dict(self, remappings_dict):
        self.__remap_collection.add_remappings_by_dict(remappings_dict)

    def __str__(self):
        return """Semantic Capability Interface:
{{
  name: {name}
  spec version: {spec_version}
  default provider: {default_provider}
  redefines: {redefines}
  global namespace: {global_namespace}
  description:
    {description}
}}""".format(**self.__dict__)
예제 #4
0
class CapabilityProvider(object):
    """Represents a Capability Provider

    A Capability Provider is defined by:

    - name (str): name of the provider
    - spec_type (str): type of the specification (has to be 'provider')
    - spec_version (int): version of the provider specification
    - description (str): free form description of the provider
    - implements (str): Name of a Capability Interface which this provider implements
    - launch_file (str or None): Path to a launch file which runs the provider, None indicates no launch file to run
    - depends_on (dict): list of depends on relationships to Capabilities with remappings and provider preference
    - remappings (dict): map of ROS Names defined in the Capability to their new names for this provider
    - nodelet_manager (str or None): name of the nodelet manager used by the provider, this is an implementation hint
    """
    spec_type = 'provider'

    def __init__(self,
                 name,
                 spec_version,
                 implements,
                 launch_file=None,
                 description=None,
                 remappings=None,
                 nodelet_manager=None):
        self.name = name
        self.spec_version = spec_version
        self.description = description
        self.implements = implements
        self.launch_file = launch_file
        self.nodelet_manager = nodelet_manager
        self.__remap_collection = RemapCollection()
        self.add_remappings_by_dict(remappings or {})
        self.__depends_on = {}

    @property
    def remappings(self):
        return self.__remap_collection.remappings

    @property
    def remappings_by_type(self):
        return self.__remap_collection.remappings_by_type

    def add_remappings_by_dict(self, remappings_dict):
        self.__remap_collection.add_remappings_by_dict(remappings_dict)

    @property
    def dependencies(self):
        return self.__depends_on

    def depends_on(self, interface_name):
        return interface_name in self.__depends_on

    def add_depends_on(self, interface_name, preferred_provider=None):
        relationship = DependsOnRelationship(interface_name,
                                             preferred_provider)
        # The dict strucutre of YAML should prevent duplicate interface_name keys
        self.__depends_on[interface_name] = relationship

    def __str__(self):
        return """Capability Provider:
{{
  name: {name}
  spec version: {spec_version}
  implements: {implements}{nodelet_manager_str}
  description:
    {description}
{remappings_str}
  depend on relationships:
{depends_on_str}
}}
""".format(depends_on_str="[\n" +
           "\n".join([str(v) for v in self.__depends_on.values()]) + "\n]",
           remappings_str=str(self.__remap_collection) + "\n",
           nodelet_manager_str='' if self.nodelet_manager is None else '\n' +
           self.nodelet_manager + '\n',
           **self.__dict__)
예제 #5
0
class CapabilityProvider(object):
    """Represents a Capability Provider

    A Capability Provider is defined by:

    - name (str): name of the provider
    - spec_type (str): type of the specification (has to be 'provider')
    - spec_version (int): version of the provider specification
    - description (str): free form description of the provider
    - implements (str): Name of a Capability Interface which this provider implements
    - launch_file (str or None): Path to a launch file which runs the provider, None indicates no launch file to run
    - depends_on (dict): list of depends on relationships to Capabilities with remappings and provider preference
    - remappings (dict): map of ROS Names defined in the Capability to their new names for this provider
    - nodelet_manager (str or None): name of the nodelet manager used by the provider, this is an implementation hint
    """
    spec_type = 'provider'

    def __init__(self, name, spec_version, implements, launch_file=None,
                 description=None, remappings=None, nodelet_manager=None):
        self.name = name
        self.spec_version = spec_version
        self.description = description
        self.implements = implements
        self.launch_file = launch_file
        self.nodelet_manager = nodelet_manager
        self.__remap_collection = RemapCollection()
        self.add_remappings_by_dict(remappings or {})
        self.__depends_on = {}

    @property
    def remappings(self):
        return self.__remap_collection.remappings

    def add_remappings_by_dict(self, remappings_dict):
        self.__remap_collection.add_remappings_by_dict(remappings_dict)

    @property
    def dependencies(self):
        return self.__depends_on

    def depends_on(self, interface_name):
        return interface_name in self.__depends_on

    def add_depends_on(self, interface_name, preferred_provider=None):
        relationship = DependsOnRelationship(interface_name, preferred_provider)
        # The dict strucutre of YAML should prevent duplicate interface_name keys
        self.__depends_on[interface_name] = relationship

    def __str__(self):
        return """Capability Provider:
{{
  name: {name}
  spec version: {spec_version}
  implements: {implements}{nodelet_manager_str}
  description:
    {description}
{remappings_str}
  depend on relationships:
{depends_on_str}
}}
""".format(depends_on_str="[\n" + "\n".join([str(v) for v in self.__depends_on.values()]) + "\n]",
           remappings_str=str(self.__remap_collection) + "\n",
           nodelet_manager_str='' if self.nodelet_manager is None else '\n' + self.nodelet_manager + '\n',
           **self.__dict__)