Пример #1
0
static int seed_sqlite_exec_callback(SeedObject function,
				     int argc,
				     gchar ** argv, gchar ** azColName)
{
  SeedGlobalContext ctx;
  SeedObject hash;
  int i;

  if (!function)
    return 0;

  ctx = seed_context_create(eng->group, NULL);

  hash = seed_make_object(ctx, 0, 0);
  for (i = 0; i < argc; i++)
    {
      seed_object_set_property(ctx, hash,
			       azColName[i],
			       seed_value_from_string(ctx, argv[i], 0));
    }

  seed_object_call(ctx, function, 0, 1, &hash, 0);

  seed_context_unref(ctx);

  return 0;
}
Пример #2
0
static void
destroy_seed_info (SeedInfo *info)
{
  seed_value_unprotect (info->context, info->extensions);
  seed_context_unref (info->context);

  g_slice_free (SeedInfo, info);
}
Пример #3
0
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;
}
Пример #4
0
static void
peas_extension_seed_dispose (GObject *object)
{
  PeasExtensionSeed *sexten = PEAS_EXTENSION_SEED (object);

  if (sexten->js_object != NULL)
    {
      seed_value_unprotect (sexten->js_context, sexten->js_object);
      seed_context_unref (sexten->js_context);

      sexten->js_object = NULL;
      sexten->js_context = NULL;
    }
}
Пример #5
0
static void
seed_handle_rl_closure(ffi_cif * cif, void *result, void **args, void *userdata)
{
  SeedContext ctx = seed_context_create(eng->group, NULL);
  SeedValue exception = 0;
  SeedObject function = (SeedObject) userdata;

  seed_object_call(ctx, function, 0, 0, 0, &exception);
  if (exception)
    {
      gchar *mes = seed_exception_to_string(ctx,
					    exception);
      g_warning("Exception in readline bind key closure. %s \n", mes);
    }
  seed_context_unref((SeedContext) ctx);
}
Пример #6
0
static gboolean gio_marshal_func(GIOChannel * source,
				 GIOCondition condition, gpointer data)
{
  SeedGlobalContext ctx = seed_context_create(eng->group, 0);
  SeedValue jscondition = seed_value_from_long(ctx, (glong) condition, 0);
  SeedValue args[3], ret;
  marshal_privates *priv = (marshal_privates *) data;
  gboolean bret;

  args[0] = priv->source;
  args[1] = jscondition;
  args[2] = priv->user_data;

  ret = seed_object_call(ctx, priv->function, 0, 3, args, 0);

  bret = seed_value_to_boolean(ctx, ret, 0);
  seed_context_unref(ctx);

  if (!bret)
    g_free(priv);

  return bret;
}
Пример #7
0
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;
    }
}
Пример #8
0
void test_simple_fixture_teardown(TestSimpleFixture * fixture,
				  gconstpointer data)
{
  seed_context_unref(fixture->context);
}
Пример #9
0
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;
}