On 13.01.2014 10:42, Sylvain Joyeux wrote:
On Friday, January 10, 2014 05:26:18 PM Matthias Goldhoorn wrote:
Here is the updated patchset

another patch is on the RTT mailing list regard the blocking behaviour
Looks much better for me.

Minor comments:
  - I thought we would keep the setBlaBLa for the operation name, only the
    "internal method" would be called __orogen_setBlaBla.
Why we still need the "old" operation?, i removed them to have not twice methods for the same.
The method setBlaBla is kept and called from the __orogen_ bla
  - you do not need to include OperationCaller in TaskBase anymore
*done*
  - the yard return value specification was right for #setter_operation (you do
    need the brackets)
??? where what *confused*
  - the code for property and attributes is really really similar. Please
    factor it into a separate method
*done*
  - you did not update the commit message
*done*

--
 Dipl.-Inf. Matthias Goldhoorn
 Space and Underwater Robotic

 Universität Bremen
 FB 3 - Mathematik und Informatik
 AG Robotik
 Robert-Hooke-Straße 1
 28359 Bremen, Germany
Zentrale: +49 421 178 45-6611 Besuchsadresse der Nebengeschäftstelle:
 Robert-Hooke-Straße 5
 28359 Bremen, Germany
Tel.: +49 421 178 45-4193
 Empfang: +49 421 178 45-6600
 Fax:     +49 421 178 45-4150
 E-Mail:[email protected]

 Weitere Informationen:http://www.informatik.uni-bremen.de/robotik

>From fb2c3944e9e9dcd040a727708232da14fd74211a Mon Sep 17 00:00:00 2001
From: Matthias Goldhoorn <[email protected]>
Date: Mon, 13 Jan 2014 13:26:42 +0100
Subject: [PATCH] Modified handling of dynamic-properties:

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 | 10 +++----
 2 files changed, 42 insertions(+), 20 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..b14943c 100644
--- a/lib/orogen/spec/configuration_object.rb
+++ b/lib/orogen/spec/configuration_object.rb
@@ -18,9 +18,9 @@ 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
-            #
-            # @return [Orocos::Spec::Operation]
+            # only for dynamic properties. 
+            # 
+            # @return Orocos::Spec::Operation
             attr_accessor :setter_operation
 
             # The name of the type this property is using, for consistency with
@@ -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

_______________________________________________
Rock-dev mailing list
[email protected]
http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev

Reply via email to