Module: OroGen::Gen::RTT_CPP::OperationGeneration

Defined in:
lib/orogen/gen/tasks.rb

Overview

Module that is used to add code generation functionality to Spec::Operation

Instance Method Summary collapse

Instance Method Details

#argument_signature(with_names = true, with_types = true) ⇒ Object

Returns the argument part of the C++ signature for this callable



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/orogen/gen/tasks.rb', line 213

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 =
            if type.cxx_name == qualified_type && !(type < Typelib::NumericType)
                "#{type.cxx_name} const &"
            else
                qualified_type
            end

        ("#{arg if with_types} #{name if with_names}").strip
    end

    arglist.join(", ")
end

#initializeObject



188
189
190
191
# File 'lib/orogen/gen/tasks.rb', line 188

def initialize
    @method_name = self.name.dup
    method_name[0, 1] = method_name[0, 1].downcase
end

#register_for_generationObject

Called to register methods/hook code and so on on the task context



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/orogen/gen/tasks.rb', line 239

def register_for_generation
    thread_flag =
        if in_caller_thread then "RTT::ClientThread"
        else "RTT::OwnThread"
        end

    constructor = "provides()->addOperation( _#{name})\n" +
        "    .doc(#{Generation.multiline_string_to_cxx(doc)})"
    if !arguments.empty?
        constructor += "\n" + arguments.map { |n, _, d| "    .arg(\"#{n}\", \"#{d}\")" }.join("\n")
    end

    if hidden? && !self.base_body
        raise InternalError, "a hidden operation with name #{name} must have a body"
    end


    body =
        if self.body
            self.body
        elsif has_return_value?
            "    return #{return_type.first.cxx_name}();"
        else ""
        end

    task.add_base_member("operation", "_#{name}", "RTT::Operation< #{signature(false)} >").
        initializer("_#{name}(\"#{name}\", &#{task.basename}Base::#{method_name}, this, #{thread_flag})").
        constructor("#{constructor};")


    if hidden? || base_body
        task.add_base_method(return_type[1], method_name, argument_signature).
            body(base_body).
            doc("base implementation of the #{method_name} operation")
    end
    if !hidden?
        task.add_user_method(return_type[1], method_name, argument_signature). 
            body(body).
            doc(doc || "Handler for the #{method_name} operation")
    end
        
end

#signature(with_names = true) ⇒ Object

Returns the C++ signature for this operation. Used in code generation only.



195
196
197
198
199
200
201
202
203
204
# File 'lib/orogen/gen/tasks.rb', line 195

def signature(with_names = true)
    result = return_type[1].dup
    if with_names
        result << " " <<
            if block_given? then yield
            else method_name
            end
    end
    result << "(" << argument_signature(with_names) << ")"
end

#used_typesObject

Returns the set of types that this operation uses, as a Set of Typelib::Type classes.



208
209
210
# File 'lib/orogen/gen/tasks.rb', line 208

def used_types
    each_interface_type.to_a
end