class Vizkit::ConnectorObject

Public Class Methods

new() click to toggle source

# all souces must support on_data def on_data(options,&block) end

# File lib/vizkit/connector_objects.rb, line 15
def initialize
    @supports_options = true
end

Public Instance Methods

argument_types() click to toggle source
# File lib/vizkit/connector_objects.rb, line 41
def argument_types
    []
end
argument_types=(*value) click to toggle source

used to filter underlaying method specs

# File lib/vizkit/connector_objects.rb, line 34
def argument_types=(*value)
end
argument_types?(*value) click to toggle source

returns true if the given arguments are supported

# File lib/vizkit/connector_objects.rb, line 29
def argument_types?(*value)
    true
end
arity=(value) click to toggle source

used to filter underlaying method specs

# File lib/vizkit/connector_objects.rb, line 20
def arity=(value)
end
arity?(value) click to toggle source

returns true if the given arity is supported

# File lib/vizkit/connector_objects.rb, line 24
def arity?(value)
    true
end
connect_to(receiver,options) click to toggle source
# File lib/vizkit/connector_objects.rb, line 54
def connect_to(receiver,options)
    objects,options = Kernel.filter_options options,:getter => nil,:callback => nil,:write_options => Hash.new,:getter_options => Hash.new
    getter = objects[:getter]
    callback = objects[:callback]
    write_opt= objects[:write_options]
    getter_opt= objects[:getter_options]

    # options are for the writing part if the source does not support
    # options
    if !options? && write_opt.empty?
        write_opt = options
        options = Hash.new
    end

    raise ArgumentError, "#{name} cannot be used as :source object" unless respond_to?(:on_data)
    raise ArgumentError, "#{receiver.name} cannot be used as :receiver object" unless receiver.respond_to?(:write)
    raise ArgumentError, "#{getter.name} cannot be used as :getter object" if getter && !getter.respond_to?(:read)
    if callback
        raise ArgumentError, "#{callback.name} cannot be used as :callback object" if !callback.respond_to?(:write)
        raise ArgumentError, "Callback #{callback.name} must have an arity of 1" if !callback.arity?(1)
        callback.arity = 1
        if callback.argument_types? "/std/string"
            callback.argument_types = "std/string"
        elsif callback.argument_types? "QString"
            callback.argument_types = "QString"
        else
            raise ArgumentError, "Callback #{callback.name} must have QString or /std/string as argument type"
        end
    end

   # TODO check types and arity
   # type = if getter
   #             return_type
   #             getter.argument_types
   #             getter.return_type
   #             receiver.argument_types
   #         else
   #             return_type
   #             receiver.argument_types
   #         end

    # connect objects
    p = proc do |result,error|
        if callback
            message = if error
                          error.to_s
                      else
                          "OK"
                      end
            callback.write(write_opt,message){}
        end
    end
    on_data options do |*args|
        if getter
            getter.read getter_opt,*args do |*args|
                receiver.write(write_opt,*args,&p)
            end
        else
            receiver.write(write_opt,*args,&p)
        end
    end
end
name() click to toggle source
# File lib/vizkit/connector_objects.rb, line 45
def name
    @name
end
options?() click to toggle source

returns true if the object supports options for writing or reading

# File lib/vizkit/connector_objects.rb, line 50
def options?
    @supports_options
end
return_type() click to toggle source
# File lib/vizkit/connector_objects.rb, line 37
def return_type
    nil
end