From 8c0537444b1a55b39638bd4a63e11335d8170ffc Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Wed, 2 Feb 2022 16:05:57 +0900 Subject: [PATCH 1/2] [incompat] Factory object can set Property. --- OpenRTM_aist/GlobalFactory.py | 31 ++++++++++++++++++++++++++++--- OpenRTM_aist/InPortBase.py | 30 ++++++++++++++++++++++++++++++ OpenRTM_aist/OutPortBase.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/OpenRTM_aist/GlobalFactory.py b/OpenRTM_aist/GlobalFactory.py index 45b14876..8c6e3e47 100644 --- a/OpenRTM_aist/GlobalFactory.py +++ b/OpenRTM_aist/GlobalFactory.py @@ -51,14 +51,14 @@ def getIdentifiers(self): # ReturnCode addFactory(const Identifier& id, # Creator creator) - def addFactory(self, id, creator): + def addFactory(self, id, creator, prop=None): if not creator: return self.INVALID_ARG if id in self._creators: return self.ALREADY_EXISTS - self._creators[id] = creator + self._creators[id] = FactoryEntry(id, creator, prop) return self.FACTORY_OK # ReturnCode removeFactory(const Identifier& id) @@ -76,9 +76,34 @@ def createObject(self, id): if not id in self._creators: print("Factory.createObject return None id: ", id) return None - obj_ = self._creators[id]() + obj_ = self._creators[id].creator() return obj_ + def getProperties(self, id): + if not id in self._creators: + print("Factory.getProperties return None id: ", id) + return None + return self._creators[id].prop + + +class FactoryEntry: + def __init__(self, id, creator, prop=None): + self._id = id + self._creator = creator + self._prop = prop + + @property + def id(self): + return self._id + + @property + def creator(self): + return self._creator + + @property + def prop(self): + return self._prop + gfactory = None diff --git a/OpenRTM_aist/InPortBase.py b/OpenRTM_aist/InPortBase.py index d98425aa..aac4ed40 100644 --- a/OpenRTM_aist/InPortBase.py +++ b/OpenRTM_aist/InPortBase.py @@ -1175,10 +1175,25 @@ def initProviders(self): # InPortProvider supports "push" dataflow type if provider_types: + prop_options = OpenRTM_aist.Properties() self._rtcout.RTC_DEBUG("dataflow_type push is supported") self.appendProperty("dataport.dataflow_type", "push") for provider_type in provider_types: self.appendProperty("dataport.interface_type", provider_type) + prop_if = factory.getProperties(provider_type) + if prop_if is None: + prop_if = OpenRTM_aist.Properties() + + prop_node = prop_options.getNode(provider_type) + prop_node.mergeProperties(prop_if) + + prop = OpenRTM_aist.Properties() + OpenRTM_aist.NVUtil.copyToProperties( + prop, self._profile.properties) + prop_dataport = prop.getNode("dataport.interface_type") + prop_dataport.mergeProperties(prop_options) + OpenRTM_aist.NVUtil.copyFromProperties( + self._profile.properties, prop) self._providerTypes = provider_types return @@ -1219,10 +1234,25 @@ def initConsumers(self): # OutPortConsumer supports "pull" dataflow type if consumer_types: + prop_options = OpenRTM_aist.Properties() self._rtcout.RTC_PARANOID("dataflow_type pull is supported") self.appendProperty("dataport.dataflow_type", "pull") for consumer_type in consumer_types: self.appendProperty("dataport.interface_type", consumer_type) + prop_if = factory.getProperties(consumer_type) + if prop_if is None: + prop_if = OpenRTM_aist.Properties() + + prop_node = prop_options.getNode(consumer_type) + prop_node.mergeProperties(prop_if) + + prop = OpenRTM_aist.Properties() + OpenRTM_aist.NVUtil.copyToProperties( + prop, self._profile.properties) + prop_dataport = prop.getNode("dataport.interface_type") + prop_dataport.mergeProperties(prop_options) + OpenRTM_aist.NVUtil.copyFromProperties( + self._profile.properties, prop) self._consumerTypes = consumer_types return diff --git a/OpenRTM_aist/OutPortBase.py b/OpenRTM_aist/OutPortBase.py index 7f9e45b4..3c792a17 100644 --- a/OpenRTM_aist/OutPortBase.py +++ b/OpenRTM_aist/OutPortBase.py @@ -1188,11 +1188,27 @@ def initProviders(self): provider_types = provider_types + list(set_ptypes) # OutPortProvider supports "pull" dataflow type + if provider_types: + prop_options = OpenRTM_aist.Properties() self._rtcout.RTC_DEBUG("dataflow_type pull is supported") self.appendProperty("dataport.dataflow_type", "pull") for provider_type in provider_types: self.appendProperty("dataport.interface_type", provider_type) + prop_if = factory.getProperties(provider_type) + if prop_if is None: + prop_if = OpenRTM_aist.Properties() + + prop_node = prop_options.getNode(provider_type) + prop_node.mergeProperties(prop_if) + + prop = OpenRTM_aist.Properties() + OpenRTM_aist.NVUtil.copyToProperties( + prop, self._profile.properties) + prop_dataport = prop.getNode("dataport.interface_type") + prop_dataport.mergeProperties(prop_options) + OpenRTM_aist.NVUtil.copyFromProperties( + self._profile.properties, prop) self._providerTypes = provider_types @@ -1232,10 +1248,25 @@ def initConsumers(self): # InPortConsumer supports "push" dataflow type if consumer_types: + prop_options = OpenRTM_aist.Properties() self._rtcout.RTC_PARANOID("dataflow_type push is supported") self.appendProperty("dataport.dataflow_type", "push") for consumer_type in consumer_types: self.appendProperty("dataport.interface_type", consumer_type) + prop_if = factory.getProperties(consumer_type) + if prop_if is None: + prop_if = OpenRTM_aist.Properties() + + prop_node = prop_options.getNode(consumer_type) + prop_node.mergeProperties(prop_if) + + prop = OpenRTM_aist.Properties() + OpenRTM_aist.NVUtil.copyToProperties( + prop, self._profile.properties) + prop_dataport = prop.getNode("dataport.interface_type") + prop_dataport.mergeProperties(prop_options) + OpenRTM_aist.NVUtil.copyFromProperties( + self._profile.properties, prop) self._consumerTypes = consumer_types From 6cefac82a1edc768798252c4ebaaf4a7d1c44aea Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Mon, 7 Feb 2022 06:56:55 +0900 Subject: [PATCH 2/2] [compat] fixed parameter name. --- OpenRTM_aist/InPortBase.py | 4 ++-- OpenRTM_aist/OutPortBase.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenRTM_aist/InPortBase.py b/OpenRTM_aist/InPortBase.py index aac4ed40..4d3e71e4 100644 --- a/OpenRTM_aist/InPortBase.py +++ b/OpenRTM_aist/InPortBase.py @@ -1190,7 +1190,7 @@ def initProviders(self): prop = OpenRTM_aist.Properties() OpenRTM_aist.NVUtil.copyToProperties( prop, self._profile.properties) - prop_dataport = prop.getNode("dataport.interface_type") + prop_dataport = prop.getNode("dataport.interface_option") prop_dataport.mergeProperties(prop_options) OpenRTM_aist.NVUtil.copyFromProperties( self._profile.properties, prop) @@ -1249,7 +1249,7 @@ def initConsumers(self): prop = OpenRTM_aist.Properties() OpenRTM_aist.NVUtil.copyToProperties( prop, self._profile.properties) - prop_dataport = prop.getNode("dataport.interface_type") + prop_dataport = prop.getNode("dataport.interface_option") prop_dataport.mergeProperties(prop_options) OpenRTM_aist.NVUtil.copyFromProperties( self._profile.properties, prop) diff --git a/OpenRTM_aist/OutPortBase.py b/OpenRTM_aist/OutPortBase.py index 3c792a17..48c9761e 100644 --- a/OpenRTM_aist/OutPortBase.py +++ b/OpenRTM_aist/OutPortBase.py @@ -1205,7 +1205,7 @@ def initProviders(self): prop = OpenRTM_aist.Properties() OpenRTM_aist.NVUtil.copyToProperties( prop, self._profile.properties) - prop_dataport = prop.getNode("dataport.interface_type") + prop_dataport = prop.getNode("dataport.interface_option") prop_dataport.mergeProperties(prop_options) OpenRTM_aist.NVUtil.copyFromProperties( self._profile.properties, prop) @@ -1263,7 +1263,7 @@ def initConsumers(self): prop = OpenRTM_aist.Properties() OpenRTM_aist.NVUtil.copyToProperties( prop, self._profile.properties) - prop_dataport = prop.getNode("dataport.interface_type") + prop_dataport = prop.getNode("dataport.interface_option") prop_dataport.mergeProperties(prop_options) OpenRTM_aist.NVUtil.copyFromProperties( self._profile.properties, prop)