GICallableInfo * peas_gi_get_method_info (GType iface_type, const gchar *method_name) { GIRepository *repo; GIBaseInfo *iface_info; GIFunctionInfo *func_info; repo = g_irepository_get_default (); iface_info = g_irepository_find_by_gtype (repo, iface_type); if (iface_info == NULL) { g_warning ("Type not found in introspection: '%s'", g_type_name (iface_type)); return NULL; } switch (g_base_info_get_type (iface_info)) { case GI_INFO_TYPE_OBJECT: func_info = g_object_info_find_method ((GIObjectInfo *) iface_info, method_name); break; case GI_INFO_TYPE_INTERFACE: func_info = g_interface_info_find_method ((GIInterfaceInfo *) iface_info, method_name); break; default: func_info = NULL; } g_base_info_unref (iface_info); return (GICallableInfo *) func_info; }
static JSBool fundamental_instance_new_resolve_interface(JSContext *context, JS::HandleObject obj, JS::MutableHandleObject objp, Fundamental *proto_priv, char *name) { GIFunctionInfo *method_info; JSBool ret; GType *interfaces; guint n_interfaces; guint i; ret = JS_TRUE; interfaces = g_type_interfaces(proto_priv->gtype, &n_interfaces); for (i = 0; i < n_interfaces; i++) { GIBaseInfo *base_info; GIInterfaceInfo *iface_info; base_info = g_irepository_find_by_gtype(g_irepository_get_default(), interfaces[i]); if (base_info == NULL) continue; /* An interface GType ought to have interface introspection info */ g_assert(g_base_info_get_type(base_info) == GI_INFO_TYPE_INTERFACE); iface_info = (GIInterfaceInfo *) base_info; method_info = g_interface_info_find_method(iface_info, name); g_base_info_unref(base_info); if (method_info != NULL) { if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) { if (gjs_define_function(context, obj, proto_priv->gtype, (GICallableInfo *) method_info)) { objp.set(obj); } else { ret = JS_FALSE; } } g_base_info_unref((GIBaseInfo *) method_info); } } g_free(interfaces); return ret; }
static bool interface_new_resolve(JSContext *context, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp) { Interface *priv; char *name; bool ret = false; GIFunctionInfo *method_info; if (!gjs_get_string_id(context, id, &name)) return true; priv = priv_from_js(context, obj); if (priv == NULL) goto out; /* If we have no GIRepository information then this interface was defined * from within GJS. In that case, it has no properties that need to be * resolved from within C code, as interfaces cannot inherit. */ if (priv->info == NULL) { ret = true; goto out; } method_info = g_interface_info_find_method((GIInterfaceInfo*) priv->info, name); if (method_info != NULL) { if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) { if (gjs_define_function(context, obj, priv->gtype, (GICallableInfo*)method_info) == NULL) { g_base_info_unref((GIBaseInfo*)method_info); goto out; } objp.set(obj); } g_base_info_unref((GIBaseInfo*)method_info); } ret = true; out: g_free (name); return ret; }
static VALUE rg_get_method(VALUE self, VALUE rb_n_or_name) { GIInterfaceInfo *info; GIFunctionInfo *function_info; info = SELF(self); if (RB_TYPE_P(rb_n_or_name, T_FIXNUM)) { gint n; n = NUM2INT(rb_n_or_name); function_info = g_interface_info_get_method(info, n); } else { const char *name; name = RVAL2CSTR(rb_n_or_name); function_info = g_interface_info_find_method(info, name); } return GI_BASE_INFO2RVAL_WITH_UNREF(function_info); }
static JSBool interface_new_resolve(JSContext *context, JSObject *obj, jsid id, unsigned flags, JSObject **objp) { Interface *priv; char *name; JSBool ret = JS_FALSE; GIFunctionInfo *method_info; *objp = NULL; if (!gjs_get_string_id(context, id, &name)) return JS_TRUE; priv = priv_from_js(context, obj); if (priv == NULL) goto out; method_info = g_interface_info_find_method((GIInterfaceInfo*) priv->info, name); if (method_info != NULL) { if (gjs_define_function(context, obj, priv->gtype, (GICallableInfo*)method_info) == NULL) { g_base_info_unref((GIBaseInfo*)method_info); goto out; } *objp = obj; g_base_info_unref((GIBaseInfo*)method_info); } ret = JS_TRUE; out: g_free (name); return ret; }
/** * g_object_info_find_method_using_interfaces: * @info: a #GIObjectInfo * @name: name of method to obtain * @implementor: (out) (transfer full): The implementor of the interface * * Obtain a method of the object given a @name, searching both the * object @info and any interfaces it implements. %NULL will be * returned if there's no method available with that name. * * Note that this function does *not* search parent classes; you will have * to chain up if that's desired. * * Returns: (transfer full): the #GIFunctionInfo. Free the struct by calling * g_base_info_unref() when done. */ GIFunctionInfo * g_object_info_find_method_using_interfaces (GIObjectInfo *info, const gchar *name, GIObjectInfo **implementor) { GIFunctionInfo *result = NULL; GIObjectInfo *implementor_result = NULL; result = g_object_info_find_method (info, name); if (result) implementor_result = g_base_info_ref ((GIBaseInfo*) info); if (result == NULL) { int n_interfaces; int i; n_interfaces = g_object_info_get_n_interfaces (info); for (i = 0; i < n_interfaces; ++i) { GIInterfaceInfo *iface_info; iface_info = g_object_info_get_interface (info, i); result = g_interface_info_find_method (iface_info, name); if (result != NULL) { implementor_result = iface_info; break; } g_base_info_unref ((GIBaseInfo*) iface_info); } } if (implementor) *implementor = implementor_result; else if (implementor_result != NULL) g_base_info_unref ((GIBaseInfo*) implementor_result); return result; }