(root)/
glib-2.79.0/
girepository/
girffi.h
       1  /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2   * GObject introspection: Helper functions for ffi integration
       3   *
       4   * Copyright (C) 2008 Red Hat, Inc
       5   *
       6   * SPDX-License-Identifier: LGPL-2.1-or-later
       7   *
       8   * This library is free software; you can redistribute it and/or
       9   * modify it under the terms of the GNU Lesser General Public
      10   * License as published by the Free Software Foundation; either
      11   * version 2 of the License, or (at your option) any later version.
      12   *
      13   * This library is distributed in the hope that it will be useful,
      14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16   * Lesser General Public License for more details.
      17   *
      18   * You should have received a copy of the GNU Lesser General Public
      19   * License along with this library; if not, write to the
      20   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      21   * Boston, MA 02111-1307, USA.
      22   */
      23  
      24  #pragma once
      25  
      26  #if !defined (__GIREPOSITORY_H_INSIDE__) && !defined (GI_COMPILATION)
      27  #error "Only <girepository.h> can be included directly."
      28  #endif
      29  
      30  #include <ffi.h>
      31  #include "girepository.h"
      32  
      33  G_BEGIN_DECLS
      34  
      35  /**
      36   * GIFFIClosureCallback:
      37   * @cif: the `ffi_cif` passed to
      38   *   [method@GIRepository.CallableInfo.create_closure]
      39   * @ret: (out caller-allocates): a pointer to the memory used for the function’s
      40   *   return value
      41   * @args: a vector of pointers to memory holding the arguments to the function
      42   * @user_data: the user data passed to
      43   *   [method@GIRepository.CallableInfo.create_closure]
      44   *
      45   * The function which will be called when a closure created with
      46   * [method@GIRepository.CallableInfo.create_closure] is invoked.
      47   *
      48   * The value of @ret is undefined if the function returns `void`.
      49   *
      50   * Since: 2.80
      51   */
      52  typedef void (*GIFFIClosureCallback) (ffi_cif  *cif,
      53                                        void     *ret,
      54                                        void    **args,
      55                                        void     *user_data);
      56  
      57  /**
      58   * GIFunctionInvoker:
      59   * @cif: the cif
      60   * @native_address: the native address
      61   *
      62   * Structure containing the data necessary to invoke a callable function.
      63   *
      64   * Since: 2.80
      65   */
      66  typedef struct {
      67    ffi_cif cif;
      68    gpointer native_address;
      69    /*< private >*/
      70    gpointer padding[3];
      71  } GIFunctionInvoker;
      72  
      73  /**
      74   * GIFFIReturnValue:
      75   *
      76   * The type of a return value from a callable invocation closure.
      77   *
      78   * Since: 2.80
      79   */
      80  typedef GIArgument GIFFIReturnValue;
      81  
      82  GI_AVAILABLE_IN_ALL
      83  ffi_type *    gi_type_tag_get_ffi_type            (GITypeTag type_tag, gboolean is_pointer);
      84  
      85  GI_AVAILABLE_IN_ALL
      86  ffi_type *    gi_type_info_get_ffi_type           (GITypeInfo           *info);
      87  
      88  GI_AVAILABLE_IN_ALL
      89  void          gi_type_info_extract_ffi_return_value (GITypeInfo                  *return_info,
      90                                                       GIFFIReturnValue            *ffi_value,
      91                                                       GIArgument                  *arg);
      92  
      93  GI_AVAILABLE_IN_ALL
      94  void          gi_type_tag_extract_ffi_return_value (GITypeTag         return_tag,
      95                                                      GIInfoType        interface_type,
      96                                                      GIFFIReturnValue *ffi_value,
      97                                                      GIArgument       *arg);
      98  
      99  GI_AVAILABLE_IN_ALL
     100  gboolean      gi_function_info_prep_invoker        (GIFunctionInfo       *info,
     101                                                      GIFunctionInvoker    *invoker,
     102                                                      GError              **error);
     103  
     104  GI_AVAILABLE_IN_ALL
     105  gboolean      gi_function_invoker_new_for_address  (gpointer              addr,
     106                                                      GICallableInfo       *info,
     107                                                      GIFunctionInvoker    *invoker,
     108                                                      GError              **error);
     109  
     110  GI_AVAILABLE_IN_ALL
     111  void          gi_function_invoker_destroy          (GIFunctionInvoker    *invoker);
     112  
     113  
     114  GI_AVAILABLE_IN_ALL
     115  ffi_closure * gi_callable_info_create_closure (GICallableInfo       *callable_info,
     116                                                 ffi_cif              *cif,
     117                                                 GIFFIClosureCallback  callback,
     118                                                 gpointer              user_data);
     119  
     120  GI_AVAILABLE_IN_ALL
     121  gpointer * gi_callable_info_get_closure_native_address (GICallableInfo       *callable_info,
     122                                                          ffi_closure          *closure);
     123  
     124  GI_AVAILABLE_IN_ALL
     125  void          gi_callable_info_destroy_closure (GICallableInfo       *callable_info,
     126                                                  ffi_closure          *closure);
     127  
     128  G_END_DECLS