Пример #1
0
JNIEXPORT jstring JNICALL
Java_org_gnome_glib_GlibMisc_g_1format_1size_1for_1display
(
	JNIEnv* env,
	jclass cls,
	jlong _size
)
{
	char* result;
	jstring _result;
	goffset size;

	// convert parameter size
	size = (goffset) _size;

	// call function
	result = g_format_size_for_display(size);

	// cleanup parameter size

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// cleanup return value
	if (result != NULL) {
		g_free(result);
	}

	// and finally
	return _result;
}
Пример #2
0
JNIEXPORT jstring JNICALL
Java_org_gnome_gtk_GtkAssistant_gtk_1assistant_1get_1page_1title
(
	JNIEnv* env,
	jclass cls,
	jlong _self,
	jlong _page
)
{
	const gchar* result;
	jstring _result;
	GtkAssistant* self;
	GtkWidget* page;

	// convert parameter self
	self = (GtkAssistant*) _self;

	// convert parameter page
	page = (GtkWidget*) _page;

	// call function
	result = gtk_assistant_get_page_title(self, page);

	// cleanup parameter self

	// cleanup parameter page

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// and finally
	return _result;
}
Пример #3
0
JNIEXPORT jstring JNICALL
Java_org_gnome_atk_AtkImage_atk_1image_1get_1image_1description
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	const gchar* result;
	jstring _result;
	AtkImage* self;

	// convert parameter self
	self = (AtkImage*) _self;

	// call function
	result = atk_image_get_image_description(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// and finally
	return _result;
}
Пример #4
0
JNIEXPORT jstring JNICALL
Java_org_gnome_gtk_GtkFileChooser_gtk_1file_1chooser_1get_1preview_1uri
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	char* result;
	jstring _result;
	GtkFileChooser* self;

	// convert parameter self
	self = (GtkFileChooser*) _self;

	// call function
	result = gtk_file_chooser_get_preview_uri(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// cleanup return value
	if (result != NULL) {
		g_free(result);
	}

	// and finally
	return _result;
}
Пример #5
0
JNIEXPORT jstring JNICALL
Java_org_gnome_pango_PangoColor_pango_1color_1to_1string
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	gchar* result;
	jstring _result;
	PangoColor* self;

	// convert parameter self
	self = (PangoColor*) _self;

	// call function
	result = pango_color_to_string(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// cleanup return value
	if (result != NULL) {
		g_free(result);
	}

	// and finally
	return _result;
}
Пример #6
0
JNIEXPORT jstring JNICALL
Java_org_gnome_gtk_GtkFontButton_gtk_1font_1button_1get_1title
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	const gchar* result;
	jstring _result;
	GtkFontButton* self;

	// convert parameter self
	self = (GtkFontButton*) _self;

	// call function
	result = gtk_font_button_get_title(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// and finally
	return _result;
}
Пример #7
0
JNIEXPORT jstring JNICALL
Java_org_gnome_atk_AtkAction_atk_1action_1get_1localized_1name
(
	JNIEnv* env,
	jclass cls,
	jlong _self,
	jint _i
)
{
	const gchar* result;
	jstring _result;
	AtkAction* self;
	gint i;

	// convert parameter self
	self = (AtkAction*) _self;

	// convert parameter i
	i = (gint) _i;

	// call function
	result = atk_action_get_localized_name(self, i);

	// cleanup parameter self

	// cleanup parameter i

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// and finally
	return _result;
}
Пример #8
0
JNIEXPORT jstring JNICALL
Java_org_gnome_pango_PangoFontDescription_pango_1font_1description_1to_1filename
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	char* result;
	jstring _result;
	PangoFontDescription* self;

	// convert parameter self
	self = (PangoFontDescription*) _self;

	// call function
	result = pango_font_description_to_filename(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// cleanup return value
	if (result != NULL) {
		g_free(result);
	}

	// and finally
	return _result;
}
Пример #9
0
JNIEXPORT jstring JNICALL
Java_org_gnome_gtk_GtkWindow_gtk_1window_1get_1icon_1name
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	const gchar* result;
	jstring _result;
	GtkWindow* self;

	// convert parameter self
	self = (GtkWindow*) _self;

	// call function
	result = gtk_window_get_icon_name(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// and finally
	return _result;
}
Пример #10
0
JNIEXPORT jstring JNICALL
Java_org_gnome_glib_GlibMisc_g_1get_1user_1special_1dir
(
	JNIEnv* env,
	jclass cls,
	jint _directory
)
{
	const gchar* result;
	jstring _result;
	GUserDirectory directory;

	// convert parameter directory
	directory = (GUserDirectory) _directory;

	// call function
	result = g_get_user_special_dir(directory);

	// cleanup parameter directory

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// and finally
	return _result;
}
Пример #11
0
/*
 * Implements
 *   org.freedesktop.bindings.Environment.getenv(String variableName)
 */
JNIEXPORT jobject JNICALL
Java_org_freedesktop_bindings_Environment_getenv
(
	JNIEnv *env,
	jclass cls,
	jstring _name
)
{
	const gchar* name;
	gchar* result;

	// convert parameter name
	name = bindings_java_getString(env, _name);
	if (name == NULL) {
		return NULL; /* OutOfMemoryError already thrown */
	}

	// call function
	result = (gchar*) g_getenv(name); 

	// clean up name
	bindings_java_releaseString(name);

	// and return	
	return bindings_java_newString(env, result);
}
Пример #12
0
JNIEXPORT jstring JNICALL
Java_oscats_bindings_Time_strftime
(
	JNIEnv *env,
	jclass klass,
	jstring _format,
	jlong _timestamp
)
{
	/*
	 * Call strftime() to generate the string in the desired format. We
	 * pass in size as the max, and the return value indicates how much was
	 * used.
	 */

	const char *format;
	size_t size;
	char buf[MAXWIDTH];
	struct tm *brokendown;
	time_t timestamp;

	size = MAXWIDTH;

	format = bindings_java_getString(env, _format);
	if (format == NULL) {
		return NULL; /* OutOfMemoryError already thrown */
	}

	timestamp = (time_t) _timestamp;

	brokendown = localtime(&timestamp);

	size = strftime(buf, size, format, brokendown);

	bindings_java_releaseString(format);
	if (size == 0) {
		// throw exception instead!
		return bindings_java_newString(env, "Nothing returned!\0");
	}

	return bindings_java_newString(env, buf);
}
Пример #13
0
/*
 * Implements
 *   org.freedesktop.bindings.Plumbing.toHexString(long pointer)
 */
JNIEXPORT jstring JNICALL
Java_org_freedesktop_bindings_Plumbing_toHexString
(
	JNIEnv *env,
	jclass cls,
	jlong _pointer
)
{
	const gchar* result;
	
	result = bindings_java_memory_pointerToString((gpointer) _pointer);
	
	return bindings_java_newString(env, result);
}
Пример #14
0
/**
 * Implements
 *   org.gnome.glib.GObject.g_quark_to_string(long quark)
 */
JNIEXPORT jstring JNICALL
Java_oscats_glib_GObject_g_1quark_1to_1string
(
	JNIEnv* env,
	jclass cls,
	jlong _quark
)
{
	const gchar* str; 

	// call function
	str = g_quark_to_string((GQuark)_quark);

	// and return	
	return bindings_java_newString(env, str);
}
Пример #15
0
JNIEXPORT jstring JNICALL
Java_org_gnome_glib_GlibMisc_g_1get_1user_1name
(
	JNIEnv* env,
	jclass cls
)
{
	const gchar* result;
	jstring _result;

	// call function
	result = g_get_user_name();

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// and finally
	return _result;
}
Пример #16
0
JNIEXPORT jstring JNICALL
Java_org_gnome_glib_GlibMisc_g_1markup_1escape_1text
(
	JNIEnv* env,
	jclass cls,
	jstring _text,
	jint _len
)
{
	char* result;
	jstring _result;
	const gchar* text;
	gssize len;

	// convert parameter text
	text = (const gchar*) bindings_java_getString(env, _text);
	if (text == NULL) {
		return NULL; // Java Exception already thrown
	}

	// convert parameter len
	len = (gssize) _len;

	// call function
	result = g_markup_escape_text(text, len);

	// cleanup parameter text
	bindings_java_releaseString(text);

	// cleanup parameter len

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// cleanup return value
	if (result != NULL) {
		g_free(result);
	}

	// and finally
	return _result;
}
Пример #17
0
/**
 * Implements
 *   org.gnome.glib.GObject.g_type_name(long object)
 * called from
 *   org.gnome.glib.Plumbing.instanceForObject(long pointer)
 * also made available via
 *   org.gnome.glib.GObject.typeName(Object object);
 */
JNIEXPORT jstring JNICALL
Java_oscats_glib_GObject_g_1type_1name
(
	JNIEnv *env,
	jclass cls,
	jlong _object
)
{
	GObject* object;
	const gchar* name;

	// translate value
	object = (GObject*) _object;
	
	// call function & macro	
	name = g_type_name(G_TYPE_FROM_INSTANCE(object));
	//g_print("GObject (%ld): %s\n", (long) G_OBJECT_TYPE(object), name);
	
	// return name. Guard against NullPointerException by returning an
	// empty string instead of null
	return bindings_java_newString(env, (name != NULL ? name : "\0"));
}
Пример #18
0
/**
 * Implements
 *   org.gnome.glib.GValue.g_type_name(long value)
 * called from
 *   org.gnome.glib.GValue.typeName(long value)
 * called from
 *   org.gnome.glib.Plumbing.instanceFor(long pointer)
 * and also made available via
 *   org.gnome.glib.GValue.typeName(Value value)
 */
JNIEXPORT jstring JNICALL
Java_org_gnome_glib_GValue_g_1type_1name
(
	JNIEnv *env,
	jclass cls,
	jlong _value
)
{
	GValue* value;
	const gchar* name;

	// translate value
	value = (GValue*) _value;

	// call function & macro
	name = g_type_name(G_VALUE_TYPE(value));
	//g_print("GValue  g_type_name(%ld): %s\n", (long) G_VALUE_TYPE(value), name);

	// return name. Guard against NullPointerException by returning an
	// empty string instead of null
	return bindings_java_newString(env, (name != NULL ? name : "\0"));
}
Пример #19
0
/**
 * Implements
 *   org.gnome.glib.GValue.g_value_get_string(long value)
 * called from
 *   org.gnome.glib.GValue.getString(Value value)
 * called from
 *   org.gnome.glib.Object.getPropertyString(String name)
 *
 * Extract the string value from a GValue of G_TYPE_STRING, returning the
 * primitive (well, String) to be used as such.
 */
JNIEXPORT jstring JNICALL
Java_org_gnome_glib_GValue_g_1value_1get_1string
(
	JNIEnv* env,
	jclass cls,
	jlong _value
)
{
	GValue* value;
	const gchar* str; 

	// translate value
	value =	(GValue*) _value;
	if (!G_VALUE_HOLDS_STRING(value)) {
		bindings_java_throw(env, "You've asked for the string value of a GValue, but it's not a G_TYPE_STRING!");
		return NULL;
	}

	// call function
	str = g_value_get_string(value);

	// and return	
	return bindings_java_newString(env, str);
}
Пример #20
0
/*
 * Signature the prototype of (*GClosureMarshall), meeting the requirements
 * to be the second argument to g_closure_set_marshal()
 */
static void
bindings_java_marshaller
(
	GClosure* closure,
	GValue* return_value,
	guint n_param_values,
	const GValue* param_values,
	gpointer invocation_hint,
	gpointer marshal_data
)
{
 	BindingsJavaClosure* bjc;
 	JNIEnv* env;
 	jvalue* jargs;
	guint i;
	GType type;

	// Return values, as necessary
	jboolean _b;
	gboolean b;
	
	jint _e;
	
	jstring _str;
	gchar* str;
	GObject* obj;
	
	/*
	 * Begin marshaller by downcasting the GClosure we got.
	 */

	bjc = (BindingsJavaClosure*) closure;

	/*
	 * Get the JNIEnv interface pointer
	 */

	env = bindings_java_getEnv();
	if (env == NULL) {
		g_critical("Couldn't get JNIEnv interface, aborting marshal");
		return;
	}
		
	/*
	 * Build the parameters for the callback. The signature of the
	 * handlers on the Java side for a signal "name" would be:
	 *
	 * 	receiveName(Signal handler, type arg0, type arg1, ...)
	 *
	 * Note that arg0 is universally the source object (in otherwords, a
	 * method function where the first argument is always a reference to
	 * self).
	 *
	 * In case you didn't know, JNI's jvalue us a rather complex union
	 * which holds any of the possible things you can send across the
	 * boundary. So we allocate an array of them, then for each parameter
	 * passed to the marshaller, whack them in.
	 */

	jargs = g_newa(jvalue, n_param_values + 1);

	jargs[0].l = bjc->handler;

	for(i = 0; i < n_param_values; i++) {
		type = G_VALUE_TYPE(&param_values[i]);
		switch(G_TYPE_FUNDAMENTAL(type)) {
		case G_TYPE_CHAR:
			jargs[i+1].c = g_value_get_char(&param_values[i]);
      			break;

		case G_TYPE_UCHAR:
			jargs[i+1].c = g_value_get_uchar(&param_values[i]);
      			break;

		case G_TYPE_BOOLEAN:
			b = g_value_get_boolean(&param_values[i]);
			jargs[i+1].z = (b == TRUE) ? JNI_TRUE : JNI_FALSE;
			break;

		case G_TYPE_INT:
			jargs[i+1].i = g_value_get_int(&param_values[i]);
			break;

		case G_TYPE_UINT:
			jargs[i+1].i = g_value_get_uint(&param_values[i]);
			break;

		case G_TYPE_ENUM:
			jargs[i+1].i = g_value_get_enum(&param_values[i]);
			break;

		case G_TYPE_FLAGS:
			jargs[i+1].i = g_value_get_flags(&param_values[i]);
			break;

		case G_TYPE_LONG:
			jargs[i+1].j = g_value_get_long(&param_values[i]);
			break;

		case G_TYPE_ULONG:
			jargs[i+1].j = g_value_get_ulong(&param_values[i]);
			break;

		case G_TYPE_FLOAT:
			jargs[i+1].f = g_value_get_float(&param_values[i]);
			break;

		case G_TYPE_DOUBLE:
			jargs[i+1].d = g_value_get_double(&param_values[i]);
			break;

		case G_TYPE_STRING:
			jargs[i+1].l = bindings_java_newString(env, g_value_get_string(&param_values[i]));
      			break;

		case G_TYPE_OBJECT:
		case G_TYPE_INTERFACE:
			/*
			 * GObjects are just pointers, and so we pass up the
			 * address across the boundary to be looked up and
			 * either an existing Proxy returned or a new Proxy
			 * created.
			 */
			obj = g_value_get_object(&param_values[i]);
			bindings_java_memory_cleanup(obj, FALSE);
			jargs[i+1].j = (jlong) obj;
			break;

		case G_TYPE_BOXED:
			/*
			 * We make a copy of the GBoxed so that we own it and
			 * thus it can (will) survive the duration of the
			 * signal in the event that the developer using this
			 * code keeps a reference to the returned Boxed.
			 */
			jargs[i+1].j = (jlong) g_boxed_copy(type, g_value_get_boxed(&param_values[i]));
			break;

		case G_TYPE_PARAM:
			/*
			 * We're ignoring GParamSpec at the moment. They
			 * normally only show up in 'notify' signals, and we
			 * don't need them.
			 */
		case G_TYPE_POINTER:
			/*
			 * and, we're ignoring something that gets registered
			 * as a gpointer, by definition it has no type
			 * information and there's nothing we can do.
			 */
			jargs[i+1].j = (jlong) NULL;
			break;

		default:
			/*
			 * Unrecognized. Probably means we need to add a clause above.
			 */
			g_printerr("Don't know how to marshal a %s", g_type_name(type));
			jargs[i+1].l = 0;
			break;
		}
	}
	
	/*
	 * And now we invoke the callback on the Java side Signal handler; we have to
	 * select the correct function based on what return type is necessary.
	 */

	switch(bjc->returnType) {
	case 'V':
		/*
		 * void return signals
		 */
		(*env)->CallStaticVoidMethodA(env, bjc->receiver, bjc->method, jargs);
		break;

	case 'Z':
		/*
		 * boolean return signals
		 */
		_b = (*env)->CallStaticBooleanMethodA(env, bjc->receiver, bjc->method, jargs);		
		if (_b == JNI_TRUE) {
			b = TRUE;
		} else if (_b == JNI_FALSE) {
			b = FALSE;
		} else {
			g_critical("How did you manage to return a boolean that's neither TRUE nor FALSE?");
			return;
		}
		
		g_value_set_boolean(return_value, b);
		break;

	case 'I':
		/*
		 * integer return signals
		 */
		_e = (*env)->CallStaticIntMethodA(env, bjc->receiver, bjc->method, jargs);
		
		g_value_set_int(return_value, _e);
		break;

	case 'E':
		/*
		 * enum return signals
		 */
		_e = (*env)->CallStaticIntMethodA(env, bjc->receiver, bjc->method, jargs);		
		
		g_value_set_enum(return_value, _e);
		break;

	case 'L':
		/*
		 * String return signals
		 *
		 * L is actually Object, of course, but the only type we need to
		 * worry about is java.lang.String encode it for now, and so make the
		 * enormous assumption that a string is what we get back.
		 */
		_str = (*env)->CallStaticObjectMethodA(env, bjc->receiver, bjc->method, jargs);
		if (_str == NULL) {
			g_warning("Invoking string handler returned null. That's probably bad");
			break;
		}
		
		str = (gchar*) bindings_java_getString(env, _str);
		if (str == NULL) {
			/* OutOfMemoryError already thrown */
			return;
		}
		
		// according to the API docs, this copies the input...
		g_value_set_string(return_value, str);
		
		// ... so we can release str
		bindings_java_releaseString(str);
		break;

	default:
		/*
		 * If it's not void, boolean or gchar*, then what kind of signal is it?
		 */
		g_critical("Invocation for return type %c not implemented", bjc->returnType);
		break;
	}

	/*
	 * Cleanup
	 */

	for(i = 0; i < n_param_values; i++) {
  		type = G_VALUE_TYPE(&param_values[i]);
		switch(G_TYPE_FUNDAMENTAL(type)) {
		case G_TYPE_STRING:
			(*env)->DeleteLocalRef(env, jargs[i+1].l);
			break;

		default:
			break;
		}
	}
	
	/*
	 * Don't need to free jargs - we alloca()'d it
	 */
	
	/*
	 * Now, check if an exception occurred in the callback. There's a
	 * catch: because we're in native code right now [care of the call to
	 * gtk_main()] the exception gets swallowed until we return from that
	 * native call. So we call the function which causes the main loop to
	 * terminate, with the result that the exception will propegate out
	 * and, yes, probably halt the program.
	 *
	 * This is abrupt, but it is deliberate: we need to force developers
	 * to deal with criticals emitted by the underlying libraries.
	 * Otherwise, the next thing that is likely to happen is a
	 * segmentation fault, and not only does that crash the "program" but
	 * it takes out the Java Virtual Machine running it. People don't
	 * like VM crashes.
	 *
	 * Uncaught exceptions of any kind leaving a signal handler are to be
	 * considered programmer error and will be fatal.
	 */

	if ((*env)->ExceptionOccurred(env)) {
		gtk_main_quit();
	}
}