static void gedit_plugins_engine_init (GeditPluginsEngine *engine) { gchar *typelib_dir; GError *error = NULL; gedit_debug (DEBUG_PLUGINS); engine->priv = gedit_plugins_engine_get_instance_private (engine); peas_engine_enable_loader (PEAS_ENGINE (engine), "python3"); engine->priv->plugin_settings = g_settings_new ("org.gnome.gedit.plugins"); /* Require gedit's typelib. */ typelib_dir = g_build_filename (gedit_dirs_get_gedit_lib_dir (), "girepository-1.0", NULL); if (!g_irepository_require_private (g_irepository_get_default (), typelib_dir, "Gedit", "3.0", 0, &error)) { g_warning ("Could not load Gedit repository: %s", error->message); g_error_free (error); error = NULL; } g_free (typelib_dir); /* This should be moved to libpeas */ if (!g_irepository_require (g_irepository_get_default (), "Peas", "1.0", 0, &error)) { g_warning ("Could not load Peas repository: %s", error->message); g_error_free (error); error = NULL; } if (!g_irepository_require (g_irepository_get_default (), "PeasGtk", "1.0", 0, &error)) { g_warning ("Could not load PeasGtk repository: %s", error->message); g_error_free (error); error = NULL; } peas_engine_add_search_path (PEAS_ENGINE (engine), gedit_dirs_get_user_plugins_dir (), gedit_dirs_get_user_plugins_dir ()); peas_engine_add_search_path (PEAS_ENGINE (engine), gedit_dirs_get_gedit_plugins_dir (), gedit_dirs_get_gedit_plugins_data_dir ()); g_settings_bind (engine->priv->plugin_settings, GEDIT_SETTINGS_ACTIVE_PLUGINS, engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT); }
static void liferea_plugins_engine_init (LifereaPluginsEngine * engine) { gchar *typelib_dir; GError *error = NULL; engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine, LIFEREA_TYPE_PLUGINS_ENGINE, LifereaPluginsEnginePrivate); peas_engine_enable_loader (PEAS_ENGINE (engine), "python"); engine->priv->plugin_settings = g_settings_new ("net.sf.liferea.plugins"); /* Require Lifereas's typelib. */ typelib_dir = g_build_filename (PACKAGE_LIB_DIR, "girepository-1.0", NULL); if (!g_irepository_require_private (g_irepository_get_default (), typelib_dir, "Liferea", "3.0", 0, &error)) { g_warning ("Could not load Liferea repository: %s", error->message); g_error_free (error); error = NULL; } g_free (typelib_dir); /* This should be moved to libpeas */ if (!g_irepository_require (g_irepository_get_default (), "Peas", "1.0", 0, &error)) { g_warning ("Could not load Peas repository: %s", error->message); g_error_free (error); error = NULL; } if (!g_irepository_require (g_irepository_get_default (), "PeasGtk", "1.0", 0, &error)) { g_warning ("Could not load PeasGtk repository: %s", error->message); g_error_free (error); error = NULL; } peas_engine_add_search_path (PEAS_ENGINE (engine), g_build_filename (g_get_user_data_dir (), "liferea", "plugins", NULL), g_build_filename (g_get_user_data_dir (), "liferea", "plugins", NULL)); peas_engine_add_search_path (PEAS_ENGINE (engine), g_build_filename (PACKAGE_LIB_DIR, "plugins", NULL), g_build_filename (PACKAGE_DATA_DIR, "plugins", NULL)); g_settings_bind (engine->priv->plugin_settings, "active-plugins", engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT); }
static JSBool convert_int_to_enum (JSContext *context, jsval *value_p, GType gtype, int v) { double v_double; if (v > 0 && v < G_MAXINT) { /* Optimize the unambiguous case */ v_double = v; } else { GIBaseInfo *info; /* Need to distinguish between negative integers and unsigned integers */ info = g_irepository_find_by_gtype(g_irepository_get_default(), gtype); if (info == NULL) /* hope for the best */ v_double = v; else v_double = _gjs_enum_from_int ((GIEnumInfo *)info, v); g_base_info_unref(info); } return JS_NewNumberValue(context, v_double, value_p); }
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; }
void Y_gy_init(int argc) { #if !GLIB_CHECK_VERSION(2,35,1) g_type_init(); #endif ypush_gy_Repository()->repo = g_irepository_get_default(); }
static SCM scm_g_irepository_get_default (void) { SCM repository = scm_make_smob (repository_t); SCM_SET_SMOB_DATA (repository, g_irepository_get_default ()); return repository; }
/* * The *resolved out parameter, on success, should be false to indicate that id * was not resolved; and true if id was resolved. */ static bool param_resolve(JSContext *context, JS::HandleObject obj, JS::HandleId id, bool *resolved) { GIObjectInfo *info = NULL; GIFunctionInfo *method_info; Param *priv; bool ret = false; priv = priv_from_js(context, obj); if (priv != NULL) { /* instance, not prototype */ *resolved = false; return true; } GjsAutoJSChar name; if (!gjs_get_string_id(context, id, &name)) { *resolved = false; return true; /* not resolved, but no error */ } info = (GIObjectInfo*)g_irepository_find_by_gtype(g_irepository_get_default(), G_TYPE_PARAM); method_info = g_object_info_find_method(info, name); if (method_info == NULL) { *resolved = false; ret = true; goto out; } #if GJS_VERBOSE_ENABLE_GI_USAGE _gjs_log_info_usage((GIBaseInfo*) method_info); #endif if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) { gjs_debug(GJS_DEBUG_GOBJECT, "Defining method %s in prototype for GObject.ParamSpec", g_base_info_get_name( (GIBaseInfo*) method_info)); if (gjs_define_function(context, obj, G_TYPE_PARAM, method_info) == NULL) { g_base_info_unref( (GIBaseInfo*) method_info); goto out; } *resolved = true; /* we defined the prop in obj */ } g_base_info_unref( (GIBaseInfo*) method_info); ret = true; out: if (info != NULL) g_base_info_unref( (GIBaseInfo*)info); return ret; }
static JSBool resolve_namespace_object(JSContext *context, JSObject *repo_obj, jsid ns_id, const char *ns_name) { GIRepository *repo; GError *error; char *version; JSObject *override; jsval result; JSObject *gi_namespace = NULL; JSBool ret = JS_FALSE; char *check_name = NULL; if (g_strcmp0 (ns_name, "GMenu") == 0) { check_name = g_strdup ("CMenu"); } else { check_name = g_strdup (ns_name); } JS_BeginRequest(context); if (!get_version_for_ns(context, repo_obj, ns_id, &version)) goto out; repo = g_irepository_get_default(); error = NULL; g_irepository_require(repo, check_name, version, (GIRepositoryLoadFlags) 0, &error); if (error != NULL) { gjs_throw(context, "Requiring %s, version %s: %s", check_name, version?version:"none", error->message); g_error_free(error); g_free(version); goto out; } g_free(version); /* Defines a property on "obj" (the javascript repo object) * with the given namespace name, pointing to that namespace * in the repo. */ gi_namespace = gjs_create_ns(context, check_name); JS_AddObjectRoot(context, &gi_namespace); /* Define the property early, to avoid reentrancy issues if the override module looks for namespaces that import this */ if (!JS_DefineProperty(context, repo_obj, ns_name, OBJECT_TO_JSVAL(gi_namespace), NULL, NULL, GJS_MODULE_PROP_FLAGS)) g_error("no memory to define ns property"); override = lookup_override_function(context, ns_id);
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 JSObject* gjs_lookup_fundamental_prototype_from_gtype(JSContext *context, GType gtype) { GIObjectInfo *info; JSObject *proto; info = (GIObjectInfo *) g_irepository_find_by_gtype(g_irepository_get_default(), gtype); proto = gjs_lookup_fundamental_prototype(context, info, gtype); if (info) g_base_info_unref((GIBaseInfo*)info); return proto; }
static PyObject * _wrap_g_irepository_get_default (PyObject *self) { static PyGIRepository *repository = NULL; if (!repository) { repository = (PyGIRepository *) PyObject_New (PyGIRepository, &PyGIRepository_Type); if (repository == NULL) { return NULL; } repository->repository = g_irepository_get_default(); } Py_INCREF ( (PyObject *) repository); return (PyObject *) repository; }
void testing_init (void) { GError *error = NULL; static gboolean initialized = FALSE; if (initialized) return; testing_util_init (); g_irepository_require_private (g_irepository_get_default (), BUILDDIR "/tests/libpeas/introspection", "Introspection", "1.0", 0, &error); g_assert_no_error (error); initialized = TRUE; }
int main(void) { GIRepository *repository; GError *error = NULL; GIBaseInfo *base_info; GIArgument in_args[5]; GIArgument retval; g_type_init(); repository = g_irepository_get_default(); g_irepository_require(repository, "GLib", "2.0", 0, &error); if (error) { g_error("ERROR: %s\n", error->message); return 1; } base_info = g_irepository_find_by_name(repository, "GLib", "assertion_message"); if (!base_info) { g_error("ERROR: %s\n", "Could not find GLib.warn_message"); return 1; } in_args[0].v_pointer = "domain"; in_args[1].v_pointer = "glib-print.c"; in_args[2].v_pointer = "30"; in_args[3].v_pointer = "main"; in_args[4].v_pointer = "hello world"; if (!g_function_info_invoke ((GIFunctionInfo *)base_info, (const GIArgument*)&in_args, 5, NULL, 0, &retval, &error)) { g_error("ERROR: %s\n", error->message); return 1; } g_base_info_unref (base_info); return 0; }
int main(int argc, char **argv) { GIRepository *repo; GITypelib *ret; GIBaseInfo *info; GIArgument in_arg[1]; GIArgument ret_arg; GError *error; gboolean invoke_return; repo = g_irepository_get_default (); error = NULL; ret = g_irepository_require (repo, "GLib", NULL, 0, &error); g_assert (ret != NULL); g_assert (error == NULL); info = g_irepository_find_by_name (repo, "GLib", "file_read_link"); g_assert (info != NULL); g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION); g_assert (g_function_info_get_flags ((GIFunctionInfo *)info) & GI_FUNCTION_THROWS); in_arg[0].v_string = g_strdup ("non-existent-file/hope"); error = NULL; invoke_return = g_function_info_invoke ((GIFunctionInfo *)info, in_arg, 1, NULL, 0, &ret_arg, &error); g_free(in_arg[0].v_string); g_assert (invoke_return == FALSE); g_assert (error != NULL); g_assert (error->domain == G_FILE_ERROR); g_assert (error->code == G_FILE_ERROR_NOENT); exit(0); }
void gjs_define_param_class(JSContext *context, JS::HandleObject in_object) { const char *constructor_name; JS::RootedObject prototype(context), constructor(context); GIObjectInfo *info; constructor_name = "ParamSpec"; if (!gjs_init_class_dynamic(context, in_object, nullptr, "GObject", constructor_name, &gjs_param_class, gjs_param_constructor, 0, /* props of prototype */ &gjs_param_proto_props[0], /* funcs of prototype */ &gjs_param_proto_funcs[0], /* props of constructor, MyConstructor.myprop */ NULL, /* funcs of constructor, MyConstructor.myfunc() */ gjs_param_constructor_funcs, &prototype, &constructor)) { g_error("Can't init class %s", constructor_name); } JS::RootedObject gtype_obj(context, gjs_gtype_create_gtype_wrapper(context, G_TYPE_PARAM)); JS_DefineProperty(context, constructor, "$gtype", gtype_obj, JSPROP_PERMANENT); info = (GIObjectInfo*)g_irepository_find_by_gtype(g_irepository_get_default(), G_TYPE_PARAM); gjs_object_define_static_methods(context, constructor, G_TYPE_PARAM, info); g_base_info_unref( (GIBaseInfo*) info); gjs_debug(GJS_DEBUG_GPARAM, "Defined class %s prototype is %p class %p in object %p", constructor_name, prototype.get(), JS_GetClass(prototype), in_object.get()); }
static GIPropertyInfo * _pygi_lookup_property_from_g_type (GType g_type, const gchar *attr_name) { GIRepository *repository; GIBaseInfo *info; gssize n_infos; gssize i; GType parent; repository = g_irepository_get_default(); info = g_irepository_find_by_gtype (repository, g_type); if (info == NULL) { return NULL; } n_infos = g_object_info_get_n_properties ( (GIObjectInfo *) info); for (i = 0; i < n_infos; i++) { GIPropertyInfo *property_info; property_info = g_object_info_get_property ( (GIObjectInfo *) info, i); g_assert (info != NULL); if (strcmp (attr_name, g_base_info_get_name (property_info)) == 0) { g_base_info_unref (info); return property_info; } g_base_info_unref (property_info); } g_base_info_unref (info); parent = g_type_parent (g_type); if (parent > 0) return _pygi_lookup_property_from_g_type (parent, attr_name); return NULL; }
static GISignalInfo * _pygi_lookup_signal_from_g_type (GType g_type, const gchar *signal_name) { GIRepository *repository; GIBaseInfo *info; GISignalInfo *signal_info = NULL; repository = g_irepository_get_default(); info = g_irepository_find_by_gtype (repository, g_type); if (info == NULL) return NULL; if (GI_IS_OBJECT_INFO (info)) signal_info = g_object_info_find_signal ((GIObjectInfo *) info, signal_name); else if (GI_IS_INTERFACE_INFO (info)) signal_info = g_interface_info_find_signal ((GIInterfaceInfo *) info, signal_name); g_base_info_unref (info); return signal_info; }
static JSValueRef ns_get_property(JSContextRef context, JSObjectRef obj, JSStringRef property_name, JSValueRef* exception) { Ns *priv = NULL; char *name = NULL; GIRepository *repo = NULL; GIBaseInfo *info; JSValueRef ret = NULL; gboolean defined; name = gwkjs_jsstring_to_cstring(property_name); /* let Object.prototype resolve these */ if (strcmp(name, "valueOf") == 0 || strcmp(name, "toString") == 0) { goto out; } priv = priv_from_js(obj); gwkjs_debug_jsprop(GWKJS_DEBUG_GNAMESPACE, "Resolve prop '%s' hook obj %p priv %p", name, (void *)obj, priv); if (priv == NULL) { goto out; } // If the module was already included, the default proto system // should return the property, not this method. if (g_hash_table_contains(priv->modules, name)) goto out; repo = g_irepository_get_default(); info = g_irepository_find_by_name(repo, priv->gi_namespace, name); if (info == NULL) { /* No property defined, but no error either, so return TRUE */ goto out; } gwkjs_debug(GWKJS_DEBUG_GNAMESPACE, "Found info type %s for '%s' in namespace '%s'", gwkjs_info_type_name(g_base_info_get_type(info)), g_base_info_get_name(info), g_base_info_get_namespace(info)); g_hash_table_replace(priv->modules, g_strdup(name), NULL); if ((ret = gwkjs_define_info(context, obj, info, &defined))) { g_base_info_unref(info); //XXX: Does it return THIS?! // if (defined) // objp.set(obj); /* we defined the property in this object */ } else { g_hash_table_remove(priv->modules, name); gwkjs_debug(GWKJS_DEBUG_GNAMESPACE, "Failed to define info '%s'", g_base_info_get_name(info)); g_base_info_unref(info); } out: g_free(name); return ret; }
/* * Like JSResolveOp, but flags provide contextual information as follows: * * JSRESOLVE_QUALIFIED a qualified property id: obj.id or obj[id], not id * JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment * JSRESOLVE_DETECTING 'if (o.p)...' or similar detection opcode sequence * JSRESOLVE_DECLARING var, const, or function prolog declaration opcode * JSRESOLVE_CLASSNAME class name used when constructing * * The *objp out parameter, on success, should be null to indicate that id * was not resolved; and non-null, referring to obj or one of its prototypes, * if id was resolved. */ static JSBool ns_new_resolve(JSContext *context, JS::HandleObject obj, JS::HandleId id, unsigned flags, JS::MutableHandleObject objp) { Ns *priv; char *name; GIRepository *repo; GIBaseInfo *info; JSBool ret = JS_FALSE; gboolean defined; if (!gjs_get_string_id(context, id, &name)) return JS_TRUE; /* not resolved, but no error */ /* let Object.prototype resolve these */ if (strcmp(name, "valueOf") == 0 || strcmp(name, "toString") == 0) { ret = JS_TRUE; goto out; } priv = priv_from_js(context, obj); gjs_debug_jsprop(GJS_DEBUG_GNAMESPACE, "Resolve prop '%s' hook obj %p priv %p", name, *obj, priv); if (priv == NULL) { ret = JS_TRUE; /* we are the prototype, or have the wrong class */ goto out; } JS_BeginRequest(context); repo = g_irepository_get_default(); info = g_irepository_find_by_name(repo, priv->gi_namespace, name); if (info == NULL) { /* No property defined, but no error either, so return TRUE */ JS_EndRequest(context); ret = JS_TRUE; goto out; } gjs_debug(GJS_DEBUG_GNAMESPACE, "Found info type %s for '%s' in namespace '%s'", gjs_info_type_name(g_base_info_get_type(info)), g_base_info_get_name(info), g_base_info_get_namespace(info)); if (gjs_define_info(context, obj, info, &defined)) { g_base_info_unref(info); if (defined) objp.set(obj); /* we defined the property in this object */ ret = JS_TRUE; } else { gjs_debug(GJS_DEBUG_GNAMESPACE, "Failed to define info '%s'", g_base_info_get_name(info)); g_base_info_unref(info); } JS_EndRequest(context); out: g_free(name); return ret; }
/* Returns the singleton process-global default * GObjectIntrospection::Repository. It is not currently supported to have * multiple repositories in a particular process, but this function is provided * in the unlikely eventuality that it would become possible, and as a * convenience for higher level language bindings to conform to the GObject * method call conventions. * * @return [GObjectIntrospection::Repository] The global singleton * GObjectIntrospection::Repository. */ static VALUE rg_s_default(G_GNUC_UNUSED VALUE klass) { return GOBJ2RVAL(g_irepository_get_default()); }
int main(int argc, char **argv) { IsApplication *application; GSettings *settings; IsManager *manager; gchar *plugin_dir; PeasEngine *engine; PeasExtensionSet *set; GError *error = NULL; gtk_init(&argc, &argv); if (!g_irepository_require(g_irepository_get_default(), "Peas", "1.0", 0, &error)) { is_warning("main", "Could not load Peas repository: %s", error->message); g_error_free (error); error = NULL; } engine = peas_engine_get_default(); g_signal_connect(engine, "notify::plugin-list", G_CALLBACK(on_plugin_list_notify), NULL); /* add home dir to search path */ plugin_dir = g_build_filename(g_get_user_config_dir(), PACKAGE, "plugins", NULL); peas_engine_add_search_path(engine, plugin_dir, NULL); g_free(plugin_dir); /* add system path to search path */ plugin_dir = g_build_filename(LIBDIR, PACKAGE, "plugins", NULL); peas_engine_add_search_path(engine, plugin_dir, NULL); g_free(plugin_dir); /* init notifications */ is_notify_init(); application = is_application_new(); settings = g_settings_new("indicator-sensors.application"); g_settings_bind(settings, "temperature-scale", application, "temperature-scale", G_SETTINGS_BIND_DEFAULT); /* create extension set and set manager as object */ set = peas_extension_set_new(engine, PEAS_TYPE_ACTIVATABLE, "object", application, NULL); /* activate all activatable extensions */ peas_extension_set_call(set, "activate"); /* and make sure to activate any ones which are found in the future */ g_signal_connect(set, "extension-added", G_CALLBACK(on_extension_added), application); g_signal_connect(set, "extension-removed", G_CALLBACK(on_extension_removed), application); /* since all plugins are now inited show a notification if we detected * sensors but none are enabled - TODO: perhaps just open the pref's * dialog?? */ manager = is_application_get_manager(application); GSList *sensors = is_manager_get_all_sensors_list(manager); if (sensors) { gchar **enabled_sensors = is_manager_get_enabled_sensors(manager); if (!g_strv_length(enabled_sensors)) { is_notify(IS_NOTIFY_LEVEL_INFO, _("No Sensors Enabled For Monitoring"), _("Sensors detected but none are enabled for monitoring. To enable monitoring of sensors open the Preferences window and select the sensors to monitor")); } g_strfreev(enabled_sensors); g_slist_foreach(sensors, (GFunc)g_object_unref, NULL); g_slist_free(sensors); } gtk_main(); g_object_unref(application); is_notify_uninit(); return 0; }
/* a hook on getting a property; set value_p to override property's value. * Return value is JS_FALSE on OOM/exception. */ static JSBool param_get_prop(JSContext *context, JSObject *obj, jsid id, jsval *value_p) { JSBool success; Param *priv; GParamSpec *pspec; char *name; GType gtype; GIObjectInfo *info = NULL, *parent_info = NULL; GIFieldInfo *field_info = NULL; GITypeInfo *type_info = NULL; GIArgument arg; if (!gjs_get_string_id(context, id, &name)) return JS_TRUE; /* not something we affect, but no error */ priv = priv_from_js(context, obj); if (priv == NULL) { g_free(name); return JS_FALSE; /* wrong class */ } success = JS_FALSE; pspec = priv->gparam; gtype = G_TYPE_FROM_INSTANCE(pspec); info = (GIObjectInfo*)g_irepository_find_by_gtype(g_irepository_get_default(), gtype); if (info == NULL) { /* We may have a non-introspectable GParamSpec subclass here. Just return VOID. */ *value_p = JSVAL_VOID; success = JS_TRUE; goto out; } parent_info = g_object_info_get_parent(info); field_info = find_field_info(info, name); if (field_info == NULL) { /* Try it on the parent GParamSpec for generic GParamSpec properties. */ field_info = find_field_info(parent_info, name); } if (field_info == NULL) { *value_p = JSVAL_VOID; success = JS_TRUE; goto out; } type_info = g_field_info_get_type(field_info); if (!g_field_info_get_field(field_info, priv->gparam, &arg)) { gjs_throw(context, "Reading field %s.%s is not supported", g_base_info_get_name(info), g_base_info_get_name((GIBaseInfo*)field_info)); goto out; } if (!gjs_value_from_g_argument(context, value_p, type_info, &arg, TRUE)) goto out; success = JS_TRUE; out: if (field_info != NULL) g_base_info_unref((GIBaseInfo*)field_info); if (type_info != NULL) g_base_info_unref((GIBaseInfo*)type_info); if (info != NULL) g_base_info_unref((GIBaseInfo*)info); if (parent_info != NULL) g_base_info_unref((GIBaseInfo*)parent_info); g_free(name); return success; }
static JSBool gjs_value_from_g_value_internal(JSContext *context, jsval *value_p, const GValue *gvalue, gboolean no_copy, GSignalQuery *signal_query, gint arg_n) { GType gtype; gtype = G_VALUE_TYPE(gvalue); gjs_debug_marshal(GJS_DEBUG_GCLOSURE, "Converting gtype %s to jsval", g_type_name(gtype)); if (gtype == G_TYPE_STRING) { const char *v; v = g_value_get_string(gvalue); if (v == NULL) { gjs_debug_marshal(GJS_DEBUG_GCLOSURE, "Converting NULL string to JSVAL_NULL"); *value_p = JSVAL_NULL; } else { if (!gjs_string_from_utf8(context, v, -1, value_p)) return JS_FALSE; } } else if (gtype == G_TYPE_CHAR) { char v; v = g_value_get_schar(gvalue); *value_p = INT_TO_JSVAL(v); } else if (gtype == G_TYPE_UCHAR) { unsigned char v; v = g_value_get_uchar(gvalue); *value_p = INT_TO_JSVAL(v); } else if (gtype == G_TYPE_INT) { int v; v = g_value_get_int(gvalue); return JS_NewNumberValue(context, v, value_p); } else if (gtype == G_TYPE_UINT) { uint v; v = g_value_get_uint(gvalue); return JS_NewNumberValue(context, v, value_p); } else if (gtype == G_TYPE_DOUBLE) { double d; d = g_value_get_double(gvalue); return JS_NewNumberValue(context, d, value_p); } else if (gtype == G_TYPE_FLOAT) { double d; d = g_value_get_float(gvalue); return JS_NewNumberValue(context, d, value_p); } else if (gtype == G_TYPE_BOOLEAN) { gboolean v; v = g_value_get_boolean(gvalue); *value_p = BOOLEAN_TO_JSVAL(v); } else if (g_type_is_a(gtype, G_TYPE_OBJECT) || g_type_is_a(gtype, G_TYPE_INTERFACE)) { GObject *gobj; JSObject *obj; gobj = g_value_get_object(gvalue); obj = gjs_object_from_g_object(context, gobj); *value_p = OBJECT_TO_JSVAL(obj); } else if (gtype == G_TYPE_STRV) { if (!gjs_array_from_strv (context, value_p, g_value_get_boxed (gvalue))) { gjs_throw(context, "Failed to convert strv to array"); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_HASH_TABLE) || g_type_is_a(gtype, G_TYPE_ARRAY) || g_type_is_a(gtype, G_TYPE_BYTE_ARRAY) || g_type_is_a(gtype, G_TYPE_PTR_ARRAY)) { gjs_throw(context, "Unable to introspect element-type of container in GValue"); return JS_FALSE; } else if (g_type_is_a(gtype, G_TYPE_BOXED) || g_type_is_a(gtype, G_TYPE_VARIANT)) { GjsBoxedCreationFlags boxed_flags; GIBaseInfo *info; void *gboxed; JSObject *obj; if (g_type_is_a(gtype, G_TYPE_BOXED)) gboxed = g_value_get_boxed(gvalue); else gboxed = g_value_get_variant(gvalue); boxed_flags = GJS_BOXED_CREATION_NONE; /* special case GError */ if (g_type_is_a(gtype, G_TYPE_ERROR)) { obj = gjs_error_from_gerror(context, gboxed, FALSE); *value_p = OBJECT_TO_JSVAL(obj); return TRUE; } /* The only way to differentiate unions and structs is from * their g-i info as both GBoxed */ info = g_irepository_find_by_gtype(g_irepository_get_default(), gtype); if (info == NULL) { gjs_throw(context, "No introspection information found for %s", g_type_name(gtype)); return JS_FALSE; } if (g_base_info_get_type(info) == GI_INFO_TYPE_STRUCT && g_struct_info_is_foreign((GIStructInfo*)info)) { JSBool ret; GIArgument arg; arg.v_pointer = gboxed; ret = gjs_struct_foreign_convert_from_g_argument(context, value_p, info, &arg); g_base_info_unref(info); return ret; } switch (g_base_info_get_type(info)) { case GI_INFO_TYPE_BOXED: case GI_INFO_TYPE_STRUCT: if (no_copy) boxed_flags |= GJS_BOXED_CREATION_NO_COPY; obj = gjs_boxed_from_c_struct(context, (GIStructInfo *)info, gboxed, boxed_flags); break; case GI_INFO_TYPE_UNION: obj = gjs_union_from_c_union(context, (GIUnionInfo *)info, gboxed); break; default: gjs_throw(context, "Unexpected introspection type %d for %s", g_base_info_get_type(info), g_type_name(gtype)); g_base_info_unref(info); return JS_FALSE; } *value_p = OBJECT_TO_JSVAL(obj); g_base_info_unref(info); } else if (g_type_is_a(gtype, G_TYPE_ENUM)) { return convert_int_to_enum(context, value_p, gtype, g_value_get_enum(gvalue)); } else if (g_type_is_a(gtype, G_TYPE_PARAM)) { GParamSpec *gparam; JSObject *obj; gparam = g_value_get_param(gvalue); obj = gjs_param_from_g_param(context, gparam); *value_p = OBJECT_TO_JSVAL(obj); } else if (signal_query && g_type_is_a(gtype, G_TYPE_POINTER)) { JSBool res; GArgument arg; GIArgInfo *arg_info; GIBaseInfo *obj; GISignalInfo *signal_info; GITypeInfo type_info; obj = g_irepository_find_by_gtype(NULL, signal_query->itype); if (!obj) { gjs_throw(context, "Signal argument with GType %s isn't introspectable", g_type_name(signal_query->itype)); return JS_FALSE; } signal_info = g_object_info_find_signal((GIObjectInfo*)obj, signal_query->signal_name); if (!signal_info) { gjs_throw(context, "Unknown signal."); g_base_info_unref((GIBaseInfo*)obj); return JS_FALSE; } arg_info = g_callable_info_get_arg(signal_info, arg_n - 1); g_arg_info_load_type(arg_info, &type_info); arg.v_pointer = g_value_get_pointer(gvalue); res = gjs_value_from_g_argument(context, value_p, &type_info, &arg, TRUE); g_base_info_unref((GIBaseInfo*)arg_info); g_base_info_unref((GIBaseInfo*)signal_info); g_base_info_unref((GIBaseInfo*)obj); return res; } else if (g_type_is_a(gtype, G_TYPE_POINTER)) { gpointer pointer; pointer = g_value_get_pointer(gvalue); if (pointer == NULL) { *value_p = JSVAL_NULL; } else { gjs_throw(context, "Can't convert non-null pointer to JS value"); return JS_FALSE; } } else if (g_value_type_transformable(gtype, G_TYPE_DOUBLE)) { GValue double_value = { 0, }; double v; g_value_init(&double_value, G_TYPE_DOUBLE); g_value_transform(gvalue, &double_value); v = g_value_get_double(&double_value); return JS_NewNumberValue(context, v, value_p); } else if (g_value_type_transformable(gtype, G_TYPE_INT)) { GValue int_value = { 0, }; int v; g_value_init(&int_value, G_TYPE_INT); g_value_transform(gvalue, &int_value); v = g_value_get_int(&int_value); return JS_NewNumberValue(context, v, value_p); } else { gjs_throw(context, "Don't know how to convert GType %s to JavaScript object", g_type_name(gtype)); return JS_FALSE; } return JS_TRUE; }
static JSBool param_new_internal(JSContext *cx, uintN argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); GParamSpec *pspec = NULL; JSBool ret = JS_FALSE; gchar *method_name; gchar *prop_name; JSObject *prop_gtype_jsobj; GType prop_gtype; GType prop_type; gchar *nick; gchar *blurb; GParamFlags flags; if (!gjs_parse_args(cx, "GObject.ParamSpec._new_internal", "!sossi", argc, argv, "prop_name", &prop_name, "prop_gtype", &prop_gtype_jsobj, "nick", &nick, "blurb", &blurb, "flags", &flags)) return JS_FALSE; prop_gtype = gjs_gtype_get_actual_gtype(cx, prop_gtype_jsobj); prop_type = G_TYPE_FUNDAMENTAL(prop_gtype); method_name = g_strdup_printf("GObject.ParamSpec.%s", g_type_name(prop_type)); argv += 5; argc -= 5; switch (prop_type) { case G_TYPE_UCHAR: case G_TYPE_CHAR: { gchar *minimum, *maximum, *default_value; if (!gjs_parse_args(cx, method_name, "sss", argc, argv, "minimum", &minimum, "maximum", &maximum, "default_value", &default_value)) goto out; if (prop_type == G_TYPE_CHAR) pspec = g_param_spec_char(prop_name, nick, blurb, minimum[0], maximum[0], default_value[0], flags); else pspec = g_param_spec_uchar(prop_name, nick, blurb, minimum[0], maximum[0], default_value[0], flags); g_free(minimum); g_free(maximum); g_free(default_value); } break; case G_TYPE_INT: case G_TYPE_UINT: case G_TYPE_LONG: case G_TYPE_ULONG: case G_TYPE_INT64: case G_TYPE_UINT64: { gint64 minimum, maximum, default_value; if (!gjs_parse_args(cx, method_name, "ttt", argc, argv, "minimum", &minimum, "maximum", &maximum, "default_value", &default_value)) goto out; switch (prop_type) { case G_TYPE_INT: pspec = g_param_spec_int(prop_name, nick, blurb, minimum, maximum, default_value, flags); break; case G_TYPE_UINT: pspec = g_param_spec_uint(prop_name, nick, blurb, minimum, maximum, default_value, flags); break; case G_TYPE_LONG: pspec = g_param_spec_long(prop_name, nick, blurb, minimum, maximum, default_value, flags); break; case G_TYPE_ULONG: pspec = g_param_spec_ulong(prop_name, nick, blurb, minimum, maximum, default_value, flags); break; case G_TYPE_INT64: pspec = g_param_spec_int64(prop_name, nick, blurb, minimum, maximum, default_value, flags); break; case G_TYPE_UINT64: pspec = g_param_spec_uint64(prop_name, nick, blurb, minimum, maximum, default_value, flags); break; } } break; case G_TYPE_BOOLEAN: { gboolean default_value; if (!gjs_parse_args(cx, method_name, "b", argc, argv, "default_value", &default_value)) goto out; default_value = JSVAL_TO_BOOLEAN(argv[0]); pspec = g_param_spec_boolean(prop_name, nick, blurb, default_value, flags); } break; case G_TYPE_ENUM: { JSObject *gtype_jsobj; GType gtype; GIEnumInfo *info; gint64 default_value; if (!gjs_parse_args(cx, method_name, "ot", argc, argv, "gtype", >ype_jsobj, "default_value", &default_value)) goto out; gtype = gjs_gtype_get_actual_gtype(cx, gtype_jsobj); if (gtype == G_TYPE_NONE) { gjs_throw(cx, "Passed invalid GType to GParamSpecEnum constructor"); goto out; } info = g_irepository_find_by_gtype(g_irepository_get_default(), gtype); if (!_gjs_enum_value_is_valid(cx, info, default_value)) goto out; pspec = g_param_spec_enum(prop_name, nick, blurb, gtype, default_value, flags); } break; case G_TYPE_FLAGS: { JSObject *gtype_jsobj; GType gtype; gint64 default_value; if (!gjs_parse_args(cx, method_name, "ot", argc, argv, "gtype", >ype_jsobj, "default_value", &default_value)) goto out; gtype = gjs_gtype_get_actual_gtype(cx, gtype_jsobj); if (gtype == G_TYPE_NONE) { gjs_throw(cx, "Passed invalid GType to GParamSpecFlags constructor"); goto out; } if (!_gjs_flags_value_is_valid(cx, gtype, default_value)) goto out; pspec = g_param_spec_flags(prop_name, nick, blurb, gtype, default_value, flags); } break; case G_TYPE_FLOAT: case G_TYPE_DOUBLE: { gfloat minimum, maximum, default_value; if (!gjs_parse_args(cx, "GObject.ParamSpec.float", "fff", argc, argv, "minimum", &minimum, "maximum", &maximum, "default_value", &default_value)) goto out; if (prop_type == G_TYPE_FLOAT) pspec = g_param_spec_float(prop_name, nick, blurb, minimum, maximum, default_value, flags); else pspec = g_param_spec_double(prop_name, nick, blurb, minimum, maximum, default_value, flags); } break; case G_TYPE_STRING: { gchar *default_value; if (!gjs_parse_args(cx, method_name, "s", argc, argv, "default_value", &default_value)) goto out; pspec = g_param_spec_string(prop_name, nick, blurb, default_value, flags); g_free (default_value); } break; case G_TYPE_PARAM: pspec = g_param_spec_param(prop_name, nick, blurb, prop_type, flags); break; case G_TYPE_BOXED: pspec = g_param_spec_boxed(prop_name, nick, blurb, prop_type, flags); break; case G_TYPE_POINTER: pspec = g_param_spec_pointer(prop_name, nick, blurb, flags); break; case G_TYPE_OBJECT: pspec = g_param_spec_object(prop_name, nick, blurb, prop_type, flags); break; default: gjs_throw(cx, "Could not create param spec for type '%s'", g_type_name(prop_gtype)); goto out; } ret = JS_TRUE; jsval foo = OBJECT_TO_JSVAL(gjs_param_from_g_param(cx, pspec)); JS_SET_RVAL(cx, vp, foo); out: g_free(method_name); g_free(prop_name); g_free(nick); g_free(blurb); return ret; }
void gb_plugins_init (void) { PeasEngine *engine; const GList *list; /* * Ensure plugin-extensible types are registered. * This allows libgnome-builder.la to be linked and not drop * important symbols. */ g_type_ensure (GB_TYPE_APPLICATION); g_type_ensure (GB_TYPE_DOCUMENT); g_type_ensure (GB_TYPE_TREE); g_type_ensure (GB_TYPE_TREE_BUILDER); g_type_ensure (GB_TYPE_TREE_NODE); g_type_ensure (GB_TYPE_VIEW); g_type_ensure (GB_TYPE_VIEW_GRID); g_type_ensure (GB_TYPE_WORKBENCH); g_type_ensure (GB_TYPE_WORKSPACE); engine = peas_engine_get_default (); peas_engine_enable_loader (engine, "python3"); if (g_getenv ("GB_IN_TREE_PLUGINS") != NULL) { GDir *dir; g_irepository_require_private (g_irepository_get_default (), BUILDDIR"/libide", "Ide", "1.0", 0, NULL); if ((dir = g_dir_open (BUILDDIR"/plugins", 0, NULL))) { const gchar *name; while ((name = g_dir_read_name (dir))) { gchar *path; path = g_build_filename (BUILDDIR, "plugins", name, NULL); peas_engine_prepend_search_path (engine, path, path); g_free (path); } g_dir_close (dir); } } else { peas_engine_prepend_search_path (engine, PACKAGE_LIBDIR"/gnome-builder/plugins", PACKAGE_DATADIR"/gnome-builder/plugins"); } list = peas_engine_get_plugin_list (engine); for (; list; list = list->next) { if (peas_plugin_info_is_builtin (list->data)) peas_engine_load_plugin (engine, list->data); } }