Example #1
0
File: seed-gi.c Project: GNOME/seed
static SeedValue
gjs_add_interface(SeedContext ctx,
                  SeedObject function,
                  SeedObject this_object,
                  size_t argumentCount,
                  const SeedValue arguments[],
                  SeedException* exception)
{
    // TODO: to be implemented.
    seed_make_exception(ctx, exception, "ImplementationError",
                        "Not implemented yet");
    return seed_make_undefined(ctx);
}
Example #2
0
SeedValue ghtml_webview_js_console_print (SeedContext ctx, SeedObject function, SeedObject thisObject, size_t argumentCount, SeedValue arguments[], SeedException * exception) {

	if (argumentCount != 1){
		seed_make_exception (ctx, exception, GHTML_JS_INVALID_PARAMS,
			"print expected 1 argument, got %zd", argumentCount
		);  return seed_make_null (ctx);
	}

	gchar * buf = seed_value_to_string (ctx, arguments[0], exception);

	g_print ("%s\n", buf);

	g_free (buf);

	return seed_make_undefined (ctx);

}
static SeedValue
seed_cairo_pdf_surface_set_size (SeedContext ctx,
				 SeedObject function,
				 SeedObject this_object,
				 gsize argument_count,
				 const SeedValue arguments[],
				 SeedException *exception)
{
  cairo_surface_t *surf;
  gdouble x, y;

  CHECK_THIS();
  if (argument_count != 2)
    {
      EXPECTED_EXCEPTION("set_size", "2 arguments");
    }
  surf = seed_object_get_private (this_object);
  x = seed_value_to_double (ctx, arguments[0], exception);
  y = seed_value_to_double (ctx, arguments[1], exception);

  cairo_pdf_surface_set_size (surf, x, y);

  return seed_make_undefined (ctx);
}
Example #4
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;
}
Example #5
0
static SeedValue
async_call_callback(SeedContext ctx,
		    SeedObject function,
		    SeedObject this_object,
		    gsize argument_count,
		    const SeedValue arguments[],
		    SeedException *exception)
{
    DBusConnection *connection;
    DBusBusType which_bus;
    DBusMessage *reply;
    const char *sender;
    dbus_uint32_t serial;
    SeedValue prop_value, retval;
    const char *signature;
    gboolean thrown;

    retval = seed_make_undefined (ctx);
    reply = NULL;
    thrown = FALSE;

    prop_value = seed_object_get_property (ctx, function, "_dbusSender");
    sender = seed_value_to_string (ctx, prop_value, exception);
    if (!sender)
      return FALSE;

    prop_value = seed_object_get_property(ctx,
                                     function,
					  "_dbusSerial");


    serial = seed_value_to_uint (ctx, prop_value, exception);
    prop_value = seed_object_get_property(ctx,
					  function,
					  "_dbusBusType");

    which_bus = seed_value_to_int(ctx, prop_value, exception);

    /* From now we have enough information to
     * send the exception back to the callee so we'll do so
     */
    prop_value = seed_object_get_property(ctx,
					  function,
					  "_dbusOutSignature");

    signature = seed_value_to_string (ctx, prop_value, exception);
    if (!signature)
        return FALSE;

    if (argument_count != 1) {
      seed_make_exception(ctx, exception, "ArgumentError",
			  "The callback to async DBus calls takes one argument, "
			  "the return value or array of return values");
        thrown = TRUE;
        goto out;
    }

    reply = build_reply_from_jsval(ctx,
                                   signature,
                                   sender,
                                   serial,
                                   arguments[0],
				   exception);

out:
    if (!reply && thrown)
      {
	if (!dbus_reply_from_exception_and_sender(ctx, sender, serial, &reply, exception))
	  g_warning("dbus method invocation failed but no exception was set?");
      }

    if (reply)
      {
        big_dbus_add_bus_weakref(which_bus, &connection);
        if (!connection)
	  {
            seed_make_exception(ctx, exception, "DBusError",
				"We were disconnected from the bus before the callback "
				"to some async remote call was called");
            dbus_message_unref(reply);
            big_dbus_remove_bus_weakref(which_bus, &connection);
            return FALSE;
	  }
        dbus_connection_send(connection, reply, NULL);
        big_dbus_remove_bus_weakref(which_bus, &connection);
        dbus_message_unref(reply);
    }

    return retval;
}