コード例 #1
0
ファイル: seed-libxml.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_xml_xpath_register_ns (SeedContext ctx,
			    SeedObject function,
			    SeedObject this_object,
			    gsize argument_count,
			    const SeedValue arguments[],
			    SeedException * exception)
{
  xmlXPathContextPtr xpath;
  guchar *prefix;
  guchar *ns_uri;
  if (argument_count != 2)
    {
      seed_make_exception (ctx, exception, "ArgumentError",
			   "xpathRegisterNs expects 2 arguments, got %zd",
			   argument_count);
      return seed_make_undefined (ctx);
    }
  xpath = XML_XPATH_PRIV (this_object);
  prefix = (guchar *)seed_value_to_string (ctx, arguments[0], exception);
  ns_uri = (guchar *)seed_value_to_string (ctx, arguments[1], exception);

  xmlXPathRegisterNs (xpath, prefix, ns_uri);
  g_free (prefix);
  g_free (ns_uri);

  return seed_make_undefined (ctx);
}
コード例 #2
0
ファイル: seed-gettext.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_gettext_dcngettext (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException * exception)
{
	gchar * domainname, * msgid, * msgid_plural;
	guint n;
	gint category;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.dcngettext", 5);

	domainname = seed_value_to_string (ctx, args[0], exception);
	msgid = seed_value_to_string (ctx, args[1], exception);
	msgid_plural = seed_value_to_string (ctx, args[2], exception);
	n = seed_value_to_uint (ctx, args[3], exception);
	category = seed_value_to_int (ctx, args[4], exception);

	ret = seed_value_from_string (ctx,
	                              dcngettext(domainname, msgid, msgid_plural, n, category),
	                              exception);
	g_free(domainname);
	g_free(msgid);
	g_free(msgid_plural);

	return ret;
}
コード例 #3
0
ファイル: dbus-exports.c プロジェクト: iRi-E/GNOME-Seed
// Is this going to leak later?
static gboolean
signature_from_method(SeedContext ctx,
		      SeedObject method_obj,
                      const char **signature,
		      SeedException *exception)
{
  SeedValue signature_value;

  if ((signature_value = seed_object_get_property(ctx,
						 method_obj, "outSignature")))
    {
      *signature = seed_value_to_string (ctx, signature_value, exception);
      if (*signature == NULL)
	{
	  return FALSE;
        }
    }
  else
    {
      /* We default to a{sv} */
      *signature = "a{sv}";
    }

  return TRUE;
}
コード例 #4
0
ファイル: seed-libxml.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_xml_parse_file (SeedContext ctx,
		     SeedObject function,
		     SeedObject this_object,
		     gsize argument_count,
		     const SeedValue arguments[],
		     SeedException * exception)
{
  SeedObject ret;
  xmlDocPtr doc;
  gchar *path;
  if (argument_count != 1)
    {
      seed_make_exception (ctx, exception, "ArgumentError",
			   "parseFile expected 1 argument, got %zd",
			   argument_count);
      return seed_make_null (ctx);
    }
  path = seed_value_to_string (ctx, arguments[0], exception);
  doc = xmlParseFile (path);
  if (!doc)
    {
      seed_make_exception (ctx, exception, "XMLError",
			   "Document not parsed successfully");
      g_free (path);
      return seed_make_null (ctx);
    }
  ret = seed_make_xml_doc (ctx, doc);

  g_free (path);
  return ret;
}
コード例 #5
0
ファイル: seed-cairo-surface.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_cairo_surface_write_to_png (SeedContext ctx,
				 SeedObject function,
				 SeedObject this_object,
				 gsize argument_count,
				 const SeedValue arguments[],
				 SeedException *exception)
{
  cairo_status_t ret;
  cairo_surface_t *surf;
  gchar *filename;
  CHECK_THIS();

  if (argument_count != 1)
    {
      EXPECTED_EXCEPTION("write_to_png", "1 argument");
    }

  surf = seed_object_get_private (this_object);
  filename = seed_value_to_string (ctx, arguments[0], exception);

  ret = cairo_surface_write_to_png (surf, filename);
  g_free (filename);

  return seed_value_from_long (ctx, ret, exception);
}
コード例 #6
0
ファイル: seed-sqlite.c プロジェクト: iRi-E/GNOME-Seed
SeedObject sqlite_construct_database(SeedContext ctx,
				     SeedObject constructor,
				     size_t argument_count,
				     const SeedValue arguments[],
				     SeedException * exception)
{
  SeedObject ret;
  gchar *file;
  sqlite3 *db;
  int rc;

  if (argument_count != 1)
    {
      seed_make_exception(ctx, exception, "ArgumentError",
			  "sqlite.Database constructor expected 1 argument");
      return (SeedObject) seed_make_null(ctx);
    }
  file = seed_value_to_string(ctx, arguments[0], exception);

  rc = sqlite3_open(file, &db);

  g_free(file);

  ret = seed_make_object(ctx, sqlite_class, db);
  seed_object_set_property(ctx, ret, "status",
			   seed_value_from_int(ctx, rc, exception));

  return ret;
}
コード例 #7
0
ファイル: seed-libxml.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_xml_xpath_eval (SeedContext ctx,
		     SeedObject function,
		     SeedObject this_object,
		     gsize argument_count,
		     const SeedValue arguments[],
		     SeedException * exception)
{
  xmlXPathObjectPtr xpath_obj;
  xmlXPathContextPtr xpath_ctx;
  guchar *xpath;

  if (argument_count != 1)
    {
      seed_make_exception (ctx, exception,
			   "ArgumentError",
			   "xpathEval expected 1 argument, got %zd",
			   argument_count);
      return seed_make_null (ctx);
    }
  xpath_ctx = XML_XPATH_PRIV (this_object);

  xpath = (guchar *)seed_value_to_string (ctx, arguments[0], exception);
  xpath_obj = xmlXPathEval (xpath, xpath_ctx);
  g_free (xpath);

  return seed_make_object (ctx, xml_xpathobj_class, xpath_obj);
}
コード例 #8
0
ファイル: seed-exceptions.c プロジェクト: kanzure/seed
/**
 * seed_exception_get_file:
 * @ctx: A #SeedContext.
 * @exception: A reference to a #SeedException.
 *
 * Retrieves the file name the given exception was thrown from; keep in mind
 * that exceptions created from C have an undefined file name.
 *
 * Return value: A #gchar* representing the name of the file from which
 *               @exception was thrown.
 *
 */
gchar *
seed_exception_get_file (JSContextRef ctx, JSValueRef e)
{
  JSValueRef line;
  g_assert ((e));
  if (!JSValueIsObject (ctx, e))
    return 0;
  line = seed_object_get_property (ctx, (JSObjectRef) e, "sourceURL");
  return seed_value_to_string (ctx, line, 0);
}
コード例 #9
0
ファイル: seed-exceptions.c プロジェクト: kanzure/seed
/**
 * seed_exception_get_message:
 * @ctx: A #SeedContext.
 * @exception: A reference to a #SeedException.
 *
 * Retrieves the message of the given exception; this should be a
 * human-readable string describing the exception enough that a developer
 * could utilize the message in order to determine where to look to debug
 * the problem.
 *
 * Return value: A #gchar* representing the detailed message of @exception.
 *
 */
gchar *
seed_exception_get_message (JSContextRef ctx, JSValueRef e)
{
  JSValueRef name;
  g_assert ((e));
  if (!JSValueIsObject (ctx, e))
    return 0;

  name = seed_object_get_property (ctx, (JSObjectRef) e, "message");
  return seed_value_to_string (ctx, name, NULL);
}
コード例 #10
0
ファイル: seed-gettext.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_gettext_dgettext (SeedContext ctx,
                       SeedObject function,
                       SeedObject this_object,
                       gsize argument_count,
                       const SeedValue args[],
                       SeedException * exception)
{
	gchar * domainname, * msgid;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.dgettext", 2);

	domainname = seed_value_to_string (ctx, args[0], exception);
	msgid = seed_value_to_string (ctx, args[1], exception);

	ret = seed_value_from_string (ctx, dgettext(domainname, msgid), exception);
	g_free(domainname);
	g_free(msgid);

	return ret;
}
コード例 #11
0
ファイル: seed-signals.c プロジェクト: dannote/seed
static JSValueRef
seed_gobject_signal_connect_by_name (JSContextRef ctx,
				     JSObjectRef function,
				     JSObjectRef thisObject,
				     size_t argumentCount,
				     const JSValueRef arguments[],
				     JSValueRef * exception)
{
  GType obj_type;
  JSObjectRef user_data = NULL;
  gchar *signal_name;
  GObject *obj;
  gulong id;

  if (argumentCount < 2 || argumentCount > 3)
    {
      seed_make_exception (ctx, exception, "ArgumentError",
			   "Signal connection expected"
			   " 2 or 3 arguments. Got " "%zd", argumentCount);

      return JSValueMakeNull (ctx);
    }

  if (JSValueIsNull (ctx, arguments[1]) ||
      !JSValueIsObject (ctx, arguments[1]) ||
      !JSObjectIsFunction (ctx, (JSObjectRef) arguments[1]))
    {
      seed_make_exception (ctx, exception, "ArgumentError",
			   "Signal connection by name "
			   "requires a function" " as second argument");
      return JSValueMakeNull (ctx);
    }

  if (argumentCount == 3)
    {
      user_data = (JSObjectRef) arguments[2];
    }

  signal_name = seed_value_to_string (ctx, arguments[0], exception);
  obj = (GObject *) JSObjectGetPrivate (thisObject);
  obj_type = G_OBJECT_TYPE (obj);

  id = seed_gobject_signal_connect (ctx, signal_name, obj,
				    (JSObjectRef) arguments[1], NULL,
				    user_data);

  g_free (signal_name);

  return seed_value_from_ulong (ctx, id, exception);
}
コード例 #12
0
ファイル: dbus-exports.c プロジェクト: iRi-E/GNOME-Seed
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;
}
コード例 #13
0
ファイル: seed-gettext.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_gettext_bind_textdomain_codeset (SeedContext ctx,
                                      SeedObject function,
                                      SeedObject this_object,
                                      gsize argument_count,
                                      const SeedValue args[],
                                      SeedException * exception)
{
	gchar * domainname, * codeset;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.bind_textdomain_codeset", 2);

	domainname = seed_value_to_string (ctx, args[0], exception);
	codeset = seed_value_to_string (ctx, args[1], exception);

	ret = seed_value_from_string (ctx,
	                              bind_textdomain_codeset(domainname, codeset),
	                              exception);
	g_free(domainname);
	g_free(codeset);

	return ret;
}
コード例 #14
0
ファイル: seed-gettext.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_gettext_ngettext (SeedContext ctx,
                       SeedObject function,
                       SeedObject this_object,
                       gsize argument_count,
                       const SeedValue args[],
                       SeedException * exception)
{
	gchar * msgid, * msgid_plural;
	guint n;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.ngettext", 3);

	msgid = seed_value_to_string (ctx, args[0], exception);
	msgid_plural = seed_value_to_string (ctx, args[1], exception);
	n = seed_value_to_uint (ctx, args[2], exception);

	ret = seed_value_from_string (ctx, ngettext(msgid, msgid_plural, n), exception);
	g_free(msgid);
	g_free(msgid_plural);

	return ret;
}
コード例 #15
0
ファイル: chdir.c プロジェクト: hypersoft/ghtml
SeedValue ghtml_webview_js_chdir (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,
			"chdir expected 1 argument, got %zd", argumentCount
		);  return seed_make_null (ctx);
	}

	gchar * val = seed_value_to_string(ctx, arguments[0], exception);
	SeedValue result = (SeedValue) JSValueMakeNumber(ctx, g_chdir(val));

	g_free(val);

	return result;
}
コード例 #16
0
ファイル: seed-ffi.c プロジェクト: dannote/seed
static SeedObject
seed_ffi_construct_library (SeedContext ctx,
			    SeedObject constructor,
			    size_t argument_count,
			    const SeedValue arguments[],
			    SeedException *exception)
{
  GModule *mod;
  SeedObject ret;
  gchar *filename;
  seed_ffi_library_priv *priv;
  
  if (argument_count != 1 && argument_count != 0)
    {
      seed_make_exception (ctx, exception, 
			   "ArgumentError", 
			   "ffi.Library constructor expects 1 argument (filename, or none to use NULL GModule), got %zd", 
			   argument_count);
      return seed_make_null (ctx);
    }
  if (argument_count == 1)
    filename = seed_value_to_string (ctx, arguments[0], exception);
  else
    filename = NULL;
  
  mod = g_module_open (filename, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
  if (!mod)
    {
      seed_make_exception (ctx, exception, "GModuleError",
			   "Opening module (%s) failed with: %s",
			   filename, g_module_error ());
      g_free (filename);
      return seed_make_null (ctx);
    }
  
  priv = g_slice_alloc (sizeof (seed_ffi_library_priv));
  priv->mod = mod;
  
  // TODO: Value destroy function.
  priv->symbols = g_hash_table_new_full (g_str_hash, g_str_equal, 
					 g_free, NULL);
  
  ret = seed_make_object (ctx, ffi_library_class, priv);
  
  g_free (filename);
  
  return ret;
}
コード例 #17
0
ファイル: print.c プロジェクト: hypersoft/ghtml
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);

}
コード例 #18
0
ファイル: seed-readline.c プロジェクト: dannote/seed
static SeedValue
seed_rl_insert(SeedContext ctx,
	       SeedObject function,
	       SeedObject this_object,
	       size_t argument_count,
	       const SeedValue arguments[],
	       SeedValue * exception)
{
  gchar *ins;
  gint ret;
  
  CHECK_ARG_COUNT("readline.insert", 1);
  
  ins = seed_value_to_string (ctx, arguments[0], exception);
  ret = rl_insert_text (ins);
  g_free (ins);

  return seed_value_from_int (ctx, ret, exception);
}
コード例 #19
0
ファイル: seed-sqlite.c プロジェクト: iRi-E/GNOME-Seed
SeedValue seed_sqlite_exec(SeedContext ctx,
			   SeedObject function,
			   SeedObject this_object,
			   size_t argument_count,
			   const SeedValue arguments[],
			   SeedException * exception)
{
  gchar *statement;
  gchar *sqlite_error = 0;
  sqlite3 *db;
  int rc;

  if (argument_count < 1)
    {
      seed_make_exception(ctx, exception, "ArgumentError",
			  "sqlite.Database.exec expected 1 or 2 arguments");
      return seed_make_null(ctx);
    }

  statement = seed_value_to_string(ctx, arguments[0], exception);
  db = seed_object_get_private(this_object);

  g_assert(db);

  rc = sqlite3_exec(db, statement,
		    seed_sqlite_exec_callback,
		    argument_count == 2 ? arguments[1] : 0, &sqlite_error);
  g_free(statement);

  if (rc != SQLITE_OK)
    {
      if (sqlite_error)
	{
		seed_make_exception(ctx, exception, "SqliteError",
				    sqlite_error, NULL);
	  sqlite3_free(sqlite_error);
	}
      return seed_make_null(ctx);
    }

  return seed_value_from_int(ctx, rc, exception);

}
コード例 #20
0
ファイル: seed-readline.c プロジェクト: dannote/seed
static SeedValue
seed_readline(SeedContext ctx,
	      SeedObject function,
	      SeedObject this_object,
	      size_t argument_count,
	      const SeedValue arguments[], SeedValue * exception)
{
  SeedValue valstr = 0;
  gchar *str = NULL;
  gchar *buf;
  const gchar *histfname = g_get_home_dir();
  gchar *path = g_build_filename(histfname, ".seed_history", NULL);

  if (!readline_has_initialized)
    {
      read_history(path);
      readline_has_initialized = TRUE;
    }

  CHECK_ARG_COUNT("readline.readline", 1);

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

  str = readline(buf);
  if (str && *str)
    {
      add_history(str);
      valstr = seed_value_from_string(ctx, str, exception);
      g_free(str);
    }

  write_history(path);
  history_truncate_file(path, 1000);

  g_free(buf);
  g_free(path);

  if (valstr == 0)
    valstr = seed_make_null(ctx);

  return valstr;
}
コード例 #21
0
ファイル: seed-gettext.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_gettext_textdomain (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue arguments[],
                         SeedException * exception)
{
	gchar * domain_name;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.textdomain", 1);

	domain_name = seed_value_to_string (ctx, arguments[0], exception);

	ret = seed_value_from_string (ctx, textdomain(domain_name), exception);
	g_free(domain_name);

	return ret;
}
コード例 #22
0
ファイル: seed-multiprocessing.c プロジェクト: dannote/seed
SeedValue seed_pipe_write(SeedContext ctx,
			  SeedObject function,
			  SeedObject this_object,
			  size_t argument_count,
			  const SeedValue arguments[],
			  SeedException * exception)
{
  gchar *data;
  gsize written;
  gchar eol = '\n';
  GET_CHANNEL;
  
  CHECK_ARG_COUNT("multiprocessing.pipe.write", 1);

  data = seed_value_to_string(ctx, arguments[0], exception);
  g_io_channel_write_chars(priv->write, data, -1, &written, 0);
  g_io_channel_write_chars(priv->write, &eol, 1, 0, 0);
  g_io_channel_flush(priv->write, 0);

  return seed_value_from_int(ctx, written, exception);
}
コード例 #23
0
ファイル: seed-readline.c プロジェクト: dannote/seed
static SeedValue
seed_readline_bind(SeedContext ctx,
		   SeedObject function,
		   SeedObject this_object,
		   size_t argument_count,
		   const SeedValue arguments[], SeedValue * exception)
{
  gchar *key;
  ffi_closure *c;
  
  CHECK_ARG_COUNT("readline.bind", 2);

  key = seed_value_to_string(ctx, arguments[0], exception);
  c = seed_make_rl_closure((SeedObject) arguments[1]);

  rl_bind_key(*key, (rl_command_func_t *) c);

  g_free(key);

  return seed_make_null(ctx);
}
コード例 #24
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);
}
コード例 #25
0
ファイル: seed-gettext.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_gettext_setlocale (SeedContext ctx,
                        SeedObject function,
                        SeedObject this_object,
                        gsize argument_count,
                        const SeedValue args[],
                        SeedException * exception)
{
	gchar * locale;
	gint category;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.setlocale", 2);

	category = seed_value_to_int (ctx, args[0], exception);
	locale = seed_value_to_string (ctx, args[1], exception);

	ret = seed_value_from_string (ctx,
	                              setlocale(category, locale),
	                              exception);
	g_free(locale);

	return ret;
}
コード例 #26
0
ファイル: dbus-exports.c プロジェクト: iRi-E/GNOME-Seed
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;
}
コード例 #27
0
ファイル: api-types.c プロジェクト: iRi-E/GNOME-Seed
void basic_types(TestSimpleFixture * fixture, gconstpointer _data)
{
	// bool to/from JS equality

	gboolean bool_test_in = TRUE;
	SeedValue *bool_test = seed_value_from_boolean(fixture->context,
												   bool_test_in, NULL);
	gboolean bool_test_out = seed_value_to_boolean(fixture->context,
												   bool_test, NULL);

	g_assert(bool_test_in == bool_test_out);

	// uint to/from JS equality

	guint uint_test_in = 2946623;
	SeedValue *uint_test = seed_value_from_uint(fixture->context,
												uint_test_in, NULL);
	guint uint_test_out = seed_value_to_uint(fixture->context,
											 uint_test, NULL);

	g_assert(uint_test_in == uint_test_out);

	// int to/from JS equality

	gint int_test_in = -54374;
	SeedValue *int_test = seed_value_from_int(fixture->context,
											  int_test_in, NULL);
	gint int_test_out = seed_value_to_int(fixture->context,
										  int_test, NULL);

	g_assert(int_test_in == int_test_out);

	// char to/from JS equality

	gchar char_test_in = -126;
	SeedValue *char_test = seed_value_from_char(fixture->context,
												char_test_in, NULL);
	gchar char_test_out = seed_value_to_char(fixture->context,
											 char_test, NULL);

	g_assert(char_test_in == char_test_out);

	// uchar to/from JS equality

	guchar uchar_test_in = 250;
	SeedValue *uchar_test = seed_value_from_uchar(fixture->context,
												  uchar_test_in, NULL);
	guchar uchar_test_out = seed_value_to_uchar(fixture->context,
												uchar_test, NULL);

	g_assert(uchar_test_in == uchar_test_out);

	// long to/from JS equality

	glong long_test_in = -454250;
	SeedValue *long_test = seed_value_from_long(fixture->context,
												long_test_in, NULL);
	glong long_test_out = seed_value_to_long(fixture->context,
											 long_test, NULL);

	g_assert(long_test_in == long_test_out);

	// ulong to/from JS equality

	gulong ulong_test_in = 250;
	SeedValue *ulong_test = seed_value_from_ulong(fixture->context,
												  ulong_test_in, NULL);
	gulong ulong_test_out = seed_value_to_ulong(fixture->context,
												ulong_test, NULL);

	g_assert(ulong_test_in == ulong_test_out);

	// int64 to/from JS equality

	gint64 int64_test_in = -54374;
	SeedValue *int64_test = seed_value_from_int64(fixture->context,
												  int64_test_in, NULL);
	gint64 int64_test_out = seed_value_to_int64(fixture->context,
												int64_test, NULL);

	g_assert(int64_test_in == int64_test_out);

	// uint64 to/from JS equality

	guint64 uint64_test_in = 2946623;
	SeedValue *uint64_test = seed_value_from_uint64(fixture->context,
													uint64_test_in, NULL);
	guint64 uint64_test_out = seed_value_to_uint64(fixture->context,
												   uint64_test, NULL);

	g_assert(uint64_test_in == uint64_test_out);

	// float to/from JS equality

	gfloat float_test_in = 1.618;
	SeedValue *float_test = seed_value_from_float(fixture->context,
												  float_test_in, NULL);
	gfloat float_test_out = seed_value_to_float(fixture->context,
												float_test, NULL);

	g_assert(float_test_in == float_test_out);

	// double to/from JS equality

	gdouble double_test_in = 1.6134857638;
	SeedValue *double_test = seed_value_from_double(fixture->context,
													double_test_in, NULL);
	gdouble double_test_out = seed_value_to_double(fixture->context,
												   double_test, NULL);

	g_assert(double_test_in == double_test_out);

	// string to/from JS equality

	gchar *string_test_in = "Hello, world!";
	SeedValue *string_test = seed_value_from_string(fixture->context,
													string_test_in, NULL);
	gchar *string_test_out = seed_value_to_string(fixture->context,
												  string_test, NULL);

	g_assert(strncmp(string_test_in, string_test_out,
					 strlen(string_test_in)) == 0);

	// filename to/from JS equality

	gchar *filename_test_in = "/bin";
	SeedValue *filename_test = seed_value_from_filename(fixture->context,
														filename_test_in,
														NULL);
	gchar *filename_test_out = seed_value_to_filename(fixture->context,
													  filename_test, NULL);

	g_assert(strncmp(filename_test_in, filename_test_out,
					 strlen(filename_test_in)) == 0);
	SeedValue si[2];
	si[0] = seed_value_from_string (fixture->context, "Hi", NULL);
	si[1] = seed_value_from_int (fixture->context, 1, NULL);
	gint ni;
	gchar *ns;

	seed_value_to_format (fixture->context, "si", si, NULL, &ns, &ni, NULL);
	g_assert (ni == 1);
	g_assert (!strcmp(ns, "Hi"));


}
コード例 #28
0
ファイル: seed-ffi.c プロジェクト: dannote/seed
static ffi_type *
gtype_to_ffi_type (SeedContext ctx, 
		   SeedValue value,
		   GType otype,
		   GArgument *garg,
		   gpointer *arg,
		   SeedException *exception)
{
  ffi_type *return_type;
  GType type = g_type_fundamental (otype);
  g_assert (type != G_TYPE_INVALID);

  switch (type)
    {
    case G_TYPE_BOOLEAN:
    case G_TYPE_CHAR:
    case G_TYPE_INT:
      return_type = &ffi_type_sint;
      garg->v_int = seed_value_to_int (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_UCHAR:
    case G_TYPE_UINT:
      return_type = &ffi_type_uint;
      garg->v_uint = seed_value_to_uint (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_STRING:
      return_type = &ffi_type_pointer;
      garg->v_pointer = seed_value_to_string (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_OBJECT:
      //    case G_TYPE_BOXED:
    case G_TYPE_POINTER:
      return_type = &ffi_type_pointer;
      garg->v_pointer = seed_pointer_get_pointer (ctx, value);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_FLOAT:
      return_type = &ffi_type_float;
      garg->v_float = seed_value_to_float (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_DOUBLE:
      return_type = &ffi_type_double;
      garg->v_double = seed_value_to_double (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_LONG:
      return_type = &ffi_type_slong;
      garg->v_uint = seed_value_to_uint (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_ULONG:
      return_type = &ffi_type_ulong;
      garg->v_ulong = seed_value_to_ulong (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_INT64:
      return_type = &ffi_type_sint64;
      garg->v_int64 = seed_value_to_int64 (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_UINT64:
      return_type = &ffi_type_uint64;
      garg->v_uint64 = seed_value_to_uint64 (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    default:
      g_warning ("Unsupported fundamental in type: %s", g_type_name (type));
      return_type = &ffi_type_pointer;
      garg->v_pointer = NULL;
      *arg = (garg->v_pointer);
      break;
    }
  return return_type;
}