[PATCH] Modified handling of dynamic-properties:

Matthias Goldhoorn matthias.goldhoorn at dfki.de
Fri Jan 10 17:25:10 CET 2014


The old behaviour was that a dynamic property get called every time.
Now the set_<name>_internal function get's called instead of the
propery itself. This is done within the caller thread to prevent
a lock if the task is scheduled external.
If the task is already configured then the user setter function get's
called WModified handling of dynamic-properties:

The old behavior was that a dynamic property get called every time.
Now the set_<name>_internal function get's called instead of the
propery itself. This is done within the caller thread to prevent
a lock if the task is scheduled external.
If the task is already configured then the user setter function get's
Called WITHIN the user thread (which means the scheduler must run).
The user has to make sure that ALL dynamic properties get's read within the
Configure hook. The setter function does NOT get called if the task is so far
unconfigured.
ITHING the user thread (which means the sceduler must run).
The user has to make sure that ALL dynamic properties get's read within the
configure hook. The setter function does NOT get called if the task is so far
unconfigured.
---
 lib/orogen/gen/tasks.rb                 | 58 ++++++++++++++++++++++++++-------
 lib/orogen/spec/configuration_object.rb | 10 +++---
 lib/orogen/templates/tasks/TaskBase.cpp |  3 ++
 3 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/lib/orogen/gen/tasks.rb b/lib/orogen/gen/tasks.rb
index 1e52338..fdd2c4a 100644
--- a/lib/orogen/gen/tasks.rb
+++ b/lib/orogen/gen/tasks.rb
@@ -35,11 +35,30 @@ def register_for_generation
 
 
                 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 = "    //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
 
+                    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
 
@@ -61,9 +80,29 @@ def register_for_generation
                     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));"
+                    #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
@@ -160,7 +199,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 +209,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 +906,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)
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}")
diff --git a/lib/orogen/templates/tasks/TaskBase.cpp b/lib/orogen/templates/tasks/TaskBase.cpp
index 757dfd5..1a14a18 100644
--- a/lib/orogen/templates/tasks/TaskBase.cpp
+++ b/lib/orogen/templates/tasks/TaskBase.cpp
@@ -1,6 +1,9 @@
 /* Generated from orogen/lib/orogen/templates/tasks/TAskBase.cpp */
 
 #include "tasks/<%= task.basename %>Base.hpp"
+<% if !task.has_dynamic_properties? %>
+#include <rtt/OperationCaller.hpp>
+<% end %>
 
 using namespace <%= component.name %>;
 
-- 
1.8.5.1


--------------050402090406040107060606
Content-Type: text/x-patch;
 name="0001-Renamed-dynamit-setter-function-see-changes-in-oroge.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-Renamed-dynamit-setter-function-see-changes-in-oroge.pa";
 filename*1="tch"



More information about the Rock-dev mailing list