[PATCH] Modified handling of dynamic-properties:
Matthias Goldhoorn
matthias.goldhoorn at dfki.de
Wed Jan 22 10:36:49 CET 2014
The old behaviour was that a dynamic property get called every time.
Now when the (renamed) __orogen_set<name> function get's called it checks
wether the task is already configured or not. If the task is not configured
then only the property get's updated. If the task was already configures
the set<name> function get's called. Therefore the user has to make sure
all properties (even the dynamic) one get's applied within the configureHook
---
lib/orogen/gen/tasks.rb | 52 +++++++++++++++++++++++----------
lib/orogen/spec/configuration_object.rb | 8 ++---
2 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/lib/orogen/gen/tasks.rb b/lib/orogen/gen/tasks.rb
index 1e52338..d6808ee 100644
--- a/lib/orogen/gen/tasks.rb
+++ b/lib/orogen/gen/tasks.rb
@@ -15,6 +15,38 @@ def self.multiline_string_to_cxx(str)
end
end
+ module ConfigurationObjectGeneration
+ def gen_dynamic_setter
+ if dynamic? && (setter_operation.task == task)
+ #Adding user method
+ task.add_base_method("bool", "set#{name.capitalize}",setter_operation.argument_signature).
+ body(" return true;")
+ task.add_user_method("bool", "set#{name.capitalize}",setter_operation.argument_signature).
+ body( " return(#{task.name}Base::set#{name.capitalize}(value));")
+
+ #Adding user method cal to updateDynamicProperties
+ task.add_code_to_base_method_before "updateDynamicProperties"," if(!set#{name.capitalize}(_#{name}.get())) return false;\n"
+
+ setter_operation.base_body= <<EOF
+ // The following steps happen within the base Implementation:
+ // if the task is not configured yet, update the classical property and return true
+ // if the task is configured OR running so far, call the user method to update the value
+ // if the user method return false, we return false too and do NOT update the classical value
+ if(isConfigured()){
+ if(!set#{name.capitalize}(#{setter_operation.argument_signature(true,false)})){
+ return false;
+ }
+ }
+ _#{name}.set(value);
+ return true;
+EOF
+ setter_operation.hidden = true
+ end
+
+
+ end
+ end
+
# Module that is used to add code generation functionality to
# Spec::Property
module PropertyGeneration
@@ -34,11 +66,7 @@ def register_for_generation
constructor(constructor.join("\n"))
- if dynamic? && (setter_operation.task == task)
- task.add_code_to_base_method_before "updateDynamicProperties"," if(!set#{name.capitalize}(_#{name}.get())) return false;\n"
- setter_operation.base_body = " //Update the RTT value of this property\n _#{name}.set(value); \n return true;"
- setter_operation.body = " //TODO Add your code here \n\n //Call the base function, DO-NOT remove\n return(#{task.name}Base::set#{name.capitalize}(value));"
- end
+ gen_dynamic_setter
end
end
@@ -60,11 +88,7 @@ def register_for_generation
initializer("_#{name}(\"#{name}\")").
constructor(constructor.join("\n"))
- if dynamic? && (setter_operation.task == task)
- task.add_code_to_base_method_before "updateDynamicAttributes"," if(!set#{name.capitalize}(_#{name}.get())) return false;\n"
- setter_operation.base_body = " //Update the RTT value of this attribute\n _#{name}.set(value); \n return true;"
- setter_operation.body = " //TODO Add your code here \n\n //Call the base function, DO-NOT remove\n return(#{task.name}Base::set#{name.capitalize}(value));"
- end
+ gen_dynamic_setter
end
end
@@ -160,7 +184,7 @@ def used_types
end
# Returns the argument part of the C++ signature for this callable
- def argument_signature(with_names = true)
+ def argument_signature(with_names = true, with_types = true)
arglist = arguments.map do |name, type, doc, qualified_type|
# Auto-add const-ref for non-trivial types
arg =
@@ -170,9 +194,7 @@ def argument_signature(with_names = true)
qualified_type
end
- if with_names then "#{arg} #{name}"
- else arg
- end
+ ("#{arg if with_types} #{name if with_names}").strip
end
arglist.join(", ")
@@ -869,7 +891,6 @@ def has_base_method?(name)
all_base_methods.any? { |m| m.name == name }
end
-
# This function adds @param code [String] AFTER the already defined code on the
# @param name [String] given method
def add_code_to_base_method_after(name,code)
@@ -948,6 +969,7 @@ def add_base_destruction(kind, name, code)
end
ConfigurationObject = Spec::ConfigurationObject
+ ConfigurationObject.include ConfigurationObjectGeneration
Attribute = Spec::Attribute
Attribute.include AttributeGeneration
Property = Spec::Property
diff --git a/lib/orogen/spec/configuration_object.rb b/lib/orogen/spec/configuration_object.rb
index 5715948..50fd8b9 100644
--- a/lib/orogen/spec/configuration_object.rb
+++ b/lib/orogen/spec/configuration_object.rb
@@ -18,8 +18,8 @@ class ConfigurationObject
def dynamic?; !!@setter_operation end
# An operation that can be used to set the property. This is non-nil
- # only for dynamic properties
- #
+ # only for dynamic properties.
+ #
# @return [Orocos::Spec::Operation]
attr_accessor :setter_operation
@@ -57,9 +57,9 @@ def initialize(task, name, type, default_value)
end
def dynamic
- @setter_operation = task.find_operation("set#{name.capitalize}")
+ @setter_operation = task.find_operation("__orogen_set#{name.capitalize}")
if !@setter_operation
- @setter_operation = task.operation("set#{name.capitalize}").
+ @setter_operation = task.operation("__orogen_set#{name.capitalize}").
returns("bool").
argument("value", type_name).
doc("Dynamic Property setter of #{name}")
--
1.8.5.2
--------------050005090605020102050106--
More information about the Rock-dev
mailing list