Module: GirFFI::InfoExt::ISignalInfo

Defined in:
lib/gir_ffi/info_ext/i_signal_info.rb

Overview

Extensions for GObjectIntrospection::ISignalInfo needed by GirFFI TODO: Rename methods to not include ‘signal’ everywhere.

Instance Method Summary collapse

Instance Method Details

#cast_back_signal_arguments(*arguments) ⇒ Object

TODO: Generate cast back methods using existing Argument builders.



22
23
24
25
26
27
28
29
30
31
# File 'lib/gir_ffi/info_ext/i_signal_info.rb', line 22

def cast_back_signal_arguments *arguments
  instance = GirFFI::ArgHelper.object_pointer_to_object arguments.shift
  user_data = GirFFI::ArgHelper::OBJECT_STORE[arguments.pop.address]

  extra_arguments = self.args.zip(arguments).map do |info, arg|
    info.cast_signal_argument(arg)
  end

  return [instance, *extra_arguments].push user_data
end

#ffi_callback_argument_typesObject

TODO: Rename and clarify relation to argument_ffi_types: The types returned by ffi_callback_argument_types are more basic than those returned by argument_ffi_types. Is there a way to make these methods more related? Perhaps argument_ffi_types can return more basic types as well?



62
63
64
65
66
67
# File 'lib/gir_ffi/info_ext/i_signal_info.rb', line 62

def ffi_callback_argument_types
  types = args.map do |arg|
    arg.argument_type.to_callback_ffitype
  end
  types.unshift(:pointer).push(:pointer)
end

#gvalue_for_signal_return_valueObject



53
54
55
# File 'lib/gir_ffi/info_ext/i_signal_info.rb', line 53

def gvalue_for_signal_return_value
  GObject::Value.for_g_type return_type.g_type
end

#signal_arguments_to_gvalue_array(instance, *rest) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gir_ffi/info_ext/i_signal_info.rb', line 41

def signal_arguments_to_gvalue_array instance, *rest
  arr = ::GObject::ValueArray.new self.n_args + 1

  arr.append GObject::Value.wrap_instance(instance)

  self.args.zip(rest).each do |info, arg|
    arr.append info.argument_type.make_g_value.set_value(arg)
  end

  arr
end

#signal_callback(&block) ⇒ FFI::Function

Create a signal hander callback. Wraps the given block in such a way that arguments and return value are cast correctly to the ruby world and back.

Parameters:

  • block

    The body of the signal handler

Returns:

  • (FFI::Function)

    The signal handler, ready to be passed as a callback to C.



13
14
15
16
17
18
19
# File 'lib/gir_ffi/info_ext/i_signal_info.rb', line 13

def signal_callback &block
  rettype = self.return_ffi_type
  argtypes = self.ffi_callback_argument_types

  # TODO: Create signal handler type?
  FFI::Function.new rettype, argtypes, &signal_callback_args(&block)
end

#signal_callback_args(&block) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
# File 'lib/gir_ffi/info_ext/i_signal_info.rb', line 33

def signal_callback_args &block
  raise ArgumentError, "Block needed" unless block
  return Proc.new do |*args|
    mapped = cast_back_signal_arguments(*args)
    block.call(*mapped)
  end
end