Class: GirFFI::Builders::MarshallingMethodBuilder

Inherits:
BaseMethodBuilder show all
Defined in:
lib/gir_ffi/builders/marshalling_method_builder.rb

Overview

Implements the creation mapping method for a signal handler. This method converts arguments from C to Ruby, and the result from Ruby to C.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseMethodBuilder

#method_definition

Constructor Details

#initialize(receiver_info, info) ⇒ MarshallingMethodBuilder

Returns a new instance of MarshallingMethodBuilder.



22
23
24
25
26
# File 'lib/gir_ffi/builders/marshalling_method_builder.rb', line 22

def initialize(receiver_info, info)
  super(info, ClosureReturnValueBuilder,
        receiver_info: receiver_info,
        argument_builder_class: ClosureArgumentBuilder)
end

Class Method Details

.for_signal(info) ⇒ Object



15
16
17
18
19
20
# File 'lib/gir_ffi/builders/marshalling_method_builder.rb', line 15

def self.for_signal(info)
  container_info = info.container
  container_type_info = ReceiverTypeInfo.new(container_info)
  receiver_info = ReceiverArgumentInfo.new(container_type_info)
  new receiver_info, info
end

Instance Method Details

#invocationObject



46
47
48
# File 'lib/gir_ffi/builders/marshalling_method_builder.rb', line 46

def invocation
  "wrap(closure.to_ptr).invoke_block(#{call_argument_list})"
end

#method_argumentsObject



34
35
36
# File 'lib/gir_ffi/builders/marshalling_method_builder.rb', line 34

def method_arguments
  %w[closure return_value param_values _invocation_hint _marshal_data]
end

#method_nameObject

Methods used by MethodTemplate



30
31
32
# File 'lib/gir_ffi/builders/marshalling_method_builder.rb', line 30

def method_name
  "marshaller"
end

#preparationObject



38
39
40
41
42
43
44
# File 'lib/gir_ffi/builders/marshalling_method_builder.rb', line 38

def preparation
  if param_names.size == 1
    ["#{param_names.first} = param_values.first.get_value_plain"]
  else
    ["#{param_names.join(", ")} = param_values.map(&:get_value_plain)"]
  end
end

#resultObject



50
51
52
53
54
55
56
# File 'lib/gir_ffi/builders/marshalling_method_builder.rb', line 50

def result
  if (name = @argument_builder_collection.return_value_name)
    ["return_value.set_value #{name}"]
  else
    []
  end
end

#singleton_method?Boolean

Returns:



58
59
60
# File 'lib/gir_ffi/builders/marshalling_method_builder.rb', line 58

def singleton_method?
  true
end