static gboolean peas_plugin_loader_seed_load (PeasPluginLoader *loader, PeasPluginInfo *info) { PeasPluginLoaderSeed *sloader = PEAS_PLUGIN_LOADER_SEED (loader); SeedContext context; gchar *script; SeedException exc = NULL; SeedObject global, extensions; SeedInfo *sinfo; context = seed_context_create (seed->group, NULL); seed_prepare_global_context (context); script = get_script_for_plugin_info (info, context); seed_simple_evaluate (context, script, &exc); g_free (script); if (exc) { gchar *exc_string = seed_exception_to_string (context, exc); g_warning ("Seed Exception: %s", exc_string); g_free (exc_string); seed_context_unref (context); return FALSE; } global = seed_context_get_global_object (context); extensions = seed_object_get_property (context, global, "extensions"); if (seed_value_is_object (context, extensions)) { sinfo = (SeedInfo *) g_slice_new (SeedInfo); sinfo->context = context; sinfo->extensions = extensions; seed_context_ref (context); seed_value_protect (context, extensions); g_hash_table_insert (sloader->loaded_plugins, info, sinfo); } seed_context_unref (context); return TRUE; }
static gboolean peas_plugin_loader_seed_load (PeasPluginLoader *loader, PeasPluginInfo *info) { PeasPluginLoaderSeed *sloader = PEAS_PLUGIN_LOADER_SEED (loader); gchar *filename; gchar *content; GError *error = NULL; SeedContext context; SeedScript *script; SeedException exc = NULL; SeedObject global, extensions; SeedInfo *sinfo; filename = get_script_filename_for_plugin_info (info); g_debug ("Seed script filename is '%s'", filename); if (!g_file_get_contents (filename, &content, NULL, &error)) { g_warning ("Error: %s", error->message); g_error_free (error); g_free (filename); return FALSE; } context = seed_context_create (seed->group, NULL); seed_prepare_global_context (context); script = seed_make_script (context, content, filename, 0); seed_evaluate (context, script, NULL); exc = seed_script_exception (script); seed_script_destroy (script); g_free (content); g_free (filename); if (exc) { gchar *exc_string = seed_exception_to_string (context, exc); g_warning ("Seed Exception: %s", exc_string); g_free (exc_string); seed_context_unref (context); return FALSE; } global = seed_context_get_global_object (context); extensions = seed_object_get_property (context, global, "extensions"); if (seed_value_is_object (context, extensions)) { sinfo = (SeedInfo *) g_slice_new (SeedInfo); sinfo->context = context; sinfo->extensions = extensions; seed_value_protect (context, extensions); g_hash_table_insert (sloader->loaded_plugins, info, sinfo); return TRUE; } else { g_warning ("extensions is not an object in plugin '%s'", peas_plugin_info_get_module_name (info)); seed_context_unref (context); return FALSE; } }
void seed_signal_marshal_func (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) { SeedClosure *seed_closure = (SeedClosure *) closure; JSValueRef *args, exception = 0; JSValueRef ret = 0; guint i; gchar *mes; GSignalQuery signal_query = { 0, }; if (marshal_data) { /* Inspired from gjs/gi/value.c:closure_marshal() */ /* we are used for a signal handler */ guint signal_id; signal_id = GPOINTER_TO_UINT(marshal_data); g_signal_query(signal_id, &signal_query); if (!signal_query.signal_id) g_error("Signal handler being called on invalid signal"); if (signal_query.n_params + 1 != n_param_values) g_error("Signal handler being called with wrong number of parameters"); } JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0); seed_prepare_global_context (ctx); SEED_NOTE (INVOCATION, "Signal Marshal: "); args = g_newa (JSValueRef, n_param_values + 1); for (i = 0; i < n_param_values; i++) { args[i] = seed_value_from_gvalue_for_signal (ctx, (GValue *) & param_values[i], 0, &signal_query, i); if (!args[i]) g_error ("Error in signal marshal. " "Unable to convert argument of type: %s \n", g_type_name (param_values[i].g_type)); } if (seed_closure->user_data) args[i] = seed_closure->user_data; else args[i] = JSValueMakeNull (ctx); ret = JSObjectCallAsFunction (ctx, seed_closure->function, NULL, n_param_values + 1, args, &exception); if (exception) { seed_closure_warn_exception (closure, ctx, exception); exception = NULL; } if (ret && !JSValueIsNull (ctx, ret) && (seed_closure->return_type != G_TYPE_NONE)) { seed_value_to_gvalue (ctx, ret, seed_closure->return_type, return_value, &exception); } if (exception) { mes = seed_exception_to_string (ctx, exception); g_warning ("Exception in signal handler return value. %s \n", mes); g_free (mes); } JSGlobalContextRelease ((JSGlobalContextRef) ctx); JSGarbageCollect(ctx); }
static DBusHandlerResult on_message(DBusConnection *connection, DBusMessage *message, void *user_data) { SeedContext ctx; const char *path; DBusHandlerResult result; SeedObject obj; const char *method_name; char *async_method_name; SeedValue method_value; DBusMessage *reply; Exports *priv; priv = user_data; async_method_name = NULL; reply = NULL; ctx = seed_context_create (group, NULL); seed_prepare_global_context (ctx); if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; method_value = seed_make_undefined (ctx); result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; path = dbus_message_get_path(message); obj = find_js_property_by_path(ctx, priv->object, path); if (obj == NULL) { g_warning("There is no JS object at %s", path); goto out; } method_name = dbus_message_get_member(message); async_method_name = g_strdup_printf("%sAsync", method_name); /* try first if an async version exists */ if (find_method(ctx, obj, async_method_name, &method_value)) { g_warning ("Invoking async method %s on JS obj at dbus path %s", async_method_name, path); reply = invoke_js_async_from_dbus(ctx, priv->which_bus, message, obj, method_value, NULL); // Need exception here. result = DBUS_HANDLER_RESULT_HANDLED; /* otherwise try the sync version */ } else if (find_method(ctx, obj, method_name, &method_value)) { g_warning("Invoking method %s on JS obj at dbus path %s", method_name, path); reply = invoke_js_from_dbus(ctx, message, obj, method_value, NULL); // Need exception here result = DBUS_HANDLER_RESULT_HANDLED; /* otherwise FAIL */ } else { g_warning("There is a JS object at %s but it has no method %s", path, method_name); } if (reply != NULL) { dbus_connection_send(connection, reply, NULL); dbus_message_unref(reply); } out: seed_context_unref (ctx); if (async_method_name) g_free(async_method_name); return result; }