Sha256: e279d73600d07712d96e8091d83bfc331009197ccb432e11b41a6136815d048d

Contents?: true

Size: 1.97 KB

Versions: 6

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require "gir_ffi/variable_name_generator"
require "gir_ffi/builders/closure_argument_builder"
require "gir_ffi/builders/closure_return_value_builder"
require "gir_ffi/builders/argument_builder_collection"
require "gir_ffi/builders/method_template"

module GirFFI
  module Builders
    # 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 MarshallingMethodBuilder < BaseMethodBuilder
      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

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

      ## Methods used by MethodTemplate

      def method_name
        "marshaller"
      end

      def method_arguments
        %w(closure return_value param_values _invocation_hint _marshal_data)
      end

      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

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

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

      def singleton_method?
        true
      end

      private

      def call_argument_list
        @argument_builder_collection.call_argument_names.join(", ")
      end

      def param_names
        @param_names ||= @argument_builder_collection.method_argument_names
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gir_ffi-0.15.9 lib/gir_ffi/builders/marshalling_method_builder.rb
gir_ffi-0.15.8 lib/gir_ffi/builders/marshalling_method_builder.rb
gir_ffi-0.15.7 lib/gir_ffi/builders/marshalling_method_builder.rb
gir_ffi-0.15.6 lib/gir_ffi/builders/marshalling_method_builder.rb
gir_ffi-0.15.5 lib/gir_ffi/builders/marshalling_method_builder.rb
gir_ffi-0.15.4 lib/gir_ffi/builders/marshalling_method_builder.rb