Пример #1
0
static gboolean
dbus_reply_from_exception_and_sender(SeedContext  ctx,
                                     const gchar  *sender,
                                     dbus_uint32_t serial,
                                     DBusMessage **reply_p,
				     SeedException *exception)
{
  SeedValue name_val;
  gchar *s;
  const gchar *name = NULL;


  *reply_p = NULL;

  if (seed_value_is_undefined (ctx, *exception) ||
      seed_value_is_null (ctx, *exception) ||
      !seed_value_is_object (ctx, *exception))
    return FALSE;

  name_val = seed_object_get_property(ctx, *exception, "dbusErrorName");
  name = seed_value_to_string (ctx, name_val, NULL);

  s = seed_exception_to_string (ctx, *exception);
  g_warning("JS exception we will send as dbus reply to %s: %s",
	    sender,
	    s);

    *reply_p = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
    dbus_message_set_destination(*reply_p, sender);
    dbus_message_set_reply_serial(*reply_p, serial);
    dbus_message_set_no_reply(*reply_p, TRUE);
    dbus_message_set_error_name(*reply_p, name ? name : DBUS_ERROR_FAILED);
    if (s != NULL) {
         DBusMessageIter iter;

        dbus_message_iter_init_append(*reply_p, &iter);

        if (!dbus_message_iter_append_basic(&iter,
                                            DBUS_TYPE_STRING,
                                            &s)) {
            dbus_message_unref(*reply_p);
            g_free(s);
            return FALSE;
        }
        g_free(s);
    }

    return TRUE;
}
Пример #2
0
static SeedObject
seed_cairo_construct_pdf_surface (SeedContext ctx,
				    SeedObject constructor,
				    size_t argument_count,
				    const SeedValue arguments[],
				    SeedException * exception)
{
  cairo_surface_t *ret;
  gchar *filename = NULL;
  gdouble width, height;
  if (argument_count != 3)
    {
      EXPECTED_EXCEPTION("PDFSurface", "3 arguments");
    }

  if (!seed_value_is_null (ctx, arguments[0]))
    filename  = seed_value_to_string (ctx, arguments[0], exception);
  width = seed_value_to_double (ctx, arguments[1], exception);
  height = seed_value_to_double (ctx, arguments[2], exception);
  ret = cairo_pdf_surface_create (filename, width, height);

  return seed_object_from_cairo_pdf_surface (ctx, ret);
}
Пример #3
0
static PeasExtension *
peas_plugin_loader_seed_create_extension (PeasPluginLoader *loader,
                                          PeasPluginInfo   *info,
                                          GType             exten_type,
                                          guint             n_parameters,
                                          GParameter       *parameters)
{
  PeasPluginLoaderSeed *sloader = PEAS_PLUGIN_LOADER_SEED (loader);
  SeedInfo *sinfo;
  SeedValue extension_ctor, extension;
  guint i, j;
  SeedValue value;
  GValue gvalue = { 0 };
  GArray *interfaces;
  gchar **property_names;

  sinfo = (SeedInfo *) g_hash_table_lookup (sloader->loaded_plugins, info);

  /* FIXME: instantiate new object and pass the parameters */
  extension_ctor = seed_object_get_property (sinfo->context,
                                             sinfo->extensions,
                                             g_type_name (exten_type));
  if (!extension_ctor ||
      seed_value_is_undefined (sinfo->context, extension_ctor) ||
      seed_value_is_null (sinfo->context, extension_ctor))
    return NULL;

  if (!seed_value_is_object (sinfo->context, extension_ctor))
    {
      g_warning ("Extension '%s' in plugin '%s' is not a Seed object",
                 g_type_name (exten_type), peas_plugin_info_get_module_name (info));
      return NULL;
    }

  /* Instantiate the ctor object into a new specific object. */
  extension = JSObjectCallAsConstructor (sinfo->context, extension_ctor, 0, NULL, NULL);

  if (extension == NULL)
    {
#ifndef PEAS_DISABLE_DEPRECATED_FEATURES
      gchar **property_names;

      g_warning ("DEPRECATION WARNING: Extension '%s' in plugin '%s' is not a valid "
                 "constructor function. Support for extension initialization by array "
                 "copy will be dropped soon.",
                 g_type_name (exten_type), peas_plugin_info_get_module_name (info));

      extension = seed_make_object (sinfo->context, NULL, NULL);
      property_names = seed_object_copy_property_names (sinfo->context,
                                                        extension_ctor);
      for (i = 0; property_names[i] != NULL; i++)
        {
          SeedValue value;
          value = seed_object_get_property (sinfo->context,
                                            extension_ctor,
                                            property_names[i]);
          seed_object_set_property (sinfo->context,
                                    extension,
                                    property_names[i],
                                    value);
        }

        g_strfreev (property_names);
#else
      g_warning ("Extension '%s' in plugin '%s' is not a valid constructor",
                 g_type_name (exten_type), peas_plugin_info_get_module_name (info));
      return NULL;
#endif
    }

  /* Set the properties as well, cannot use
   * g_object_set_property() because it may be construct-only
   */
  for (i = 0; i < n_parameters; i++)
    {
      gchar *key;

      /* We want to normalize the property names to have a '_' instead of the
       * conventional '-', to make them accessible through this.property_name */
      key = g_strdup (parameters[i].name);
      for (j = 0; key[j] != '\0'; j++)
        {
          if (key[j] == '-')
            key[j] = '_';
        }

      value = seed_value_from_gvalue (sinfo->context,
                                      &parameters[i].value,
                                      NULL);
      seed_object_set_property (sinfo->context,
                                extension,
                                key,
                                value);

      g_free (key);
    }

  /* Set the plugin info as an attribute of the instance */
  g_value_init (&gvalue, PEAS_TYPE_PLUGIN_INFO);
  g_value_set_boxed (&gvalue, info);

  value = seed_value_from_gvalue (sinfo->context, &gvalue, NULL);
  seed_object_set_property (sinfo->context, extension, "plugin_info", value);

  g_value_unset (&gvalue);


  /* Do not add exten_type as it will be added below */
  interfaces = g_array_new (TRUE, FALSE, sizeof (GType));

  property_names = seed_object_copy_property_names (sinfo->context,
                                                    sinfo->extensions);

  for (i = 0; property_names[i] != NULL; ++i)
    {
      gchar *property_name = property_names[i];
      SeedValue *prop_extension_ctor;
      GType the_type;

      prop_extension_ctor = seed_object_get_property (sinfo->context,
                                                      sinfo->extensions,
                                                      property_name);

      if (prop_extension_ctor != extension_ctor)
        continue;

      if (!seed_value_is_object (sinfo->context, extension_ctor))
        {
          g_warning ("Extension '%s' in plugin '%s' is not a Seed object",
                     property_name, peas_plugin_info_get_module_name (info));
          continue;
        }

      the_type = peas_gi_get_type_from_name (property_name);

      if (the_type == G_TYPE_INVALID)
        {
          g_warning ("Could not find GType for '%s', "
                     "did you forget to import it?", property_name);
        }
      else
        {
          g_array_append_val (interfaces, the_type);
        }
    }

  g_array_sort (interfaces, (GCompareFunc) prerequisites_sort);

  g_strfreev (property_names);

  return peas_extension_seed_new (exten_type,
                                  (GType *) g_array_free (interfaces, FALSE),
                                  sinfo->context, extension);
}
Пример #4
0
static DBusMessage*
invoke_js_from_dbus(SeedContext ctx,
                    DBusMessage *method_call,
                    SeedObject this_obj,
                    SeedObject method_obj,
		    SeedException *exception)
{
    DBusMessage *reply;
    int argc;
    SeedValue *argv;
    SeedValue rval;
    DBusMessageIter arg_iter;
    GArray *values;
    const char *signature;

    reply = NULL;

    dbus_message_iter_init(method_call, &arg_iter);

    if (!seed_js_values_from_dbus(ctx, &arg_iter, &values, exception))
      {
	if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
	  g_warning("conversion of dbus method arg failed but no exception was set?");
        return reply;
      }

    argc = values->len;
    argv = (SeedValue *)values->data;

    seed_js_add_dbus_props(ctx, method_call, argv[0], exception);

    rval = seed_object_call (ctx, method_obj, NULL,
		      argc, argv, exception);
    if (!seed_value_is_null (ctx, *exception) &&
	seed_value_is_object (ctx, *exception))
      {
	g_warning("dbus method invocation failed");

        if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
	  g_warning("dbus method invocation failed but no exception was set?");

        goto out;
      }

    if (dbus_reply_from_exception(ctx, method_call, &reply, exception))
      {
	g_warning("Closure invocation succeeded but an exception was set?");
	goto out;
      }

    if (!signature_from_method(ctx,
                               method_obj,
                               &signature, exception))
      {
        if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
	  g_warning("dbus method invocation failed but no exception was set?");

        goto out;
      }

    reply = build_reply_from_jsval(ctx,
                                   signature,
                                   dbus_message_get_sender(method_call),
                                   dbus_message_get_serial(method_call),
                                   rval,
				   exception);

 out:
    g_array_free(values, TRUE);

    if (reply)
      g_warning ("Sending %s reply to dbus method %s",
		 dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN ?
		 "normal" : "error",
		 dbus_message_get_member(method_call));
    else
      g_warning ("Failed to create reply to dbus method %s",
		 dbus_message_get_member(method_call));

    return reply;
}