/soc/2012/michael/android: 8a887696eae2: Fixed some problems wit...
Michael Zangl
michael at soc.pidgin.im
Sat Jul 28 06:54:36 EDT 2012
Changeset: 8a887696eae2ea4e69f0a057cf0cd9463b0b99bb
Author: Michael Zangl <michael at soc.pidgin.im>
Date: 2012-07-28 12:54 +0200
Branch: soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/8a887696eae2
Description:
Fixed some problems with dns/ssl. Added a new glib main thread.
diffstat:
android/workspace/im.pidgin.libpurple/.externalToolBuilders/headers and native.launch | 1 +
android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c | 2 +-
android/workspace/im.pidgin.libpurple/native/EventLoop.c | 112 +++++----
android/workspace/im.pidgin.libpurple/native/SslOps.c | 88 +++++--
android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/EventLoop.java | 8 +
5 files changed, 130 insertions(+), 81 deletions(-)
diffs (truncated from 354 to 300 lines):
diff --git a/android/workspace/im.pidgin.libpurple/.externalToolBuilders/headers and native.launch b/android/workspace/im.pidgin.libpurple/.externalToolBuilders/headers and native.launch
--- a/android/workspace/im.pidgin.libpurple/.externalToolBuilders/headers and native.launch
+++ b/android/workspace/im.pidgin.libpurple/.externalToolBuilders/headers and native.launch
@@ -13,6 +13,7 @@
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="im.pidgin.libpurple"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?>
<resources>
<item path="/im.pidgin.libpurple/src" type="2"/>
</resources>}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/im.pidgin.libpurple/native/build.ant}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
diff --git a/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c b/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c
--- a/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c
+++ b/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c
@@ -25,7 +25,7 @@ resolve_host(PurpleDnsQueryData* query_d
mid = getMethodIDCachedReferenced(env, dns.java_class, &methodCache);
if (mid != NULL) {
- result = (*env)->CallLongMethod(env, dns.handlerObject, mid,
+ result = (*env)->CallBooleanMethod(env, dns.handlerObject, mid,
query_data_ptr, resolved_cb_ptr, failed_cb_ptr);
}
return (gboolean) result;
diff --git a/android/workspace/im.pidgin.libpurple/native/EventLoop.c b/android/workspace/im.pidgin.libpurple/native/EventLoop.c
--- a/android/workspace/im.pidgin.libpurple/native/EventLoop.c
+++ b/android/workspace/im.pidgin.libpurple/native/EventLoop.c
@@ -10,48 +10,10 @@
#include <libpurple/debug.h>
#include "helpers.h"
-static guint
-eventloopAddTimeout(guint interval, GSourceFunc function, gpointer data);
-
-static gboolean
-eventloopRemoveTimeout(guint handle);
+static JavaObjectReference eventloop = JAVA_NULL_OBJECT_REF;
static guint
-eventloopAddInput(int fd, PurpleInputCondition cond, PurpleInputFunction func,
- gpointer user_data);
-
-static gboolean
-eventloopRemoveInput(guint handle);
-
-JavaObjectReference eventloop;
-
-PurpleEventLoopUiOps eventloopUiOps = { eventloopAddTimeout,
- eventloopRemoveTimeout, eventloopAddInput, eventloopRemoveInput, NULL,
- NULL, NULL, NULL, NULL };
-
-JNIEXPORT void JNICALL
-Java_im_pidgin_libpurple_core_EventLoop_init_1native(JNIEnv *env, jobject obj)
-{
- setJavaObject(&eventloop, env, obj);
-}
-
-JNIEXPORT jboolean JNICALL
-Java_im_pidgin_libpurple_core_EventLoop_exeucte_1native(JNIEnv *env,
- jobject obj, jlong functionPointer, jlong data)
-{
- GSourceFunc function = (GSourceFunc) longToP(functionPointer);
- gboolean result = function((gpointer) longToP(data));
- return result ? JNI_TRUE : JNI_FALSE;
-}
-
-PurpleEventLoopUiOps *
-getEventloopUiOps()
-{
- return &eventloopUiOps;
-}
-
-guint
-eventloopAddTimeout(guint interval, GSourceFunc function, gpointer data)
+eventloop_timeout_add(guint interval, GSourceFunc function, gpointer data)
{
static JavaMethodIDCache methodCache =
METHOD_CACHE("eventloopAddTimeout", "(IJJ)I");
@@ -74,8 +36,8 @@ eventloopAddTimeout(guint interval, GSou
return (guint) result;
}
-gboolean
-eventloopRemoveTimeout(guint handle)
+static gboolean
+eventloop_timeout_remove(guint handle)
{
static JavaMethodIDCache methodCache =
METHOD_CACHE("eventloopRemoveTimeout", "(I)Z");
@@ -94,39 +56,40 @@ eventloopRemoveTimeout(guint handle)
}
-#define PIDGIN_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
-#define PIDGIN_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
+#define ANDROID_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
+#define ANDROID_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
-typedef struct _PidginIOClosure {
+typedef struct _AndroidIOClosure {
PurpleInputFunction function;
guint result;
gpointer data;
} PidginIOClosure;
static gboolean
-pidgin_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
+android_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
{
PidginIOClosure *closure = data;
PurpleInputCondition purple_cond = 0;
- if (condition & PIDGIN_READ_COND)
+ if (condition & ANDROID_READ_COND)
purple_cond |= PURPLE_INPUT_READ;
- if (condition & PIDGIN_WRITE_COND)
+ if (condition & ANDROID_WRITE_COND)
purple_cond |= PURPLE_INPUT_WRITE;
purple_debug_misc("eventloop", "CLOSURE: callback for %d, fd is %d\n",
closure->result, g_io_channel_unix_get_fd(source));
+ // TODO: Sync
closure->function(closure->data, g_io_channel_unix_get_fd(source),
purple_cond);
return TRUE;
}
+
static guint
-eventloopAddInput(gint fd, PurpleInputCondition condition,
+eventloop_input_add(gint fd, PurpleInputCondition condition,
PurpleInputFunction function, gpointer data)
{
- purple_debug_info("eventloop", "called input add");
PidginIOClosure *closure = g_new0(PidginIOClosure, 1);
GIOChannel *channel;
GIOCondition cond = 0;
@@ -135,21 +98,60 @@ eventloopAddInput(gint fd, PurpleInputCo
closure->data = data;
if (condition & PURPLE_INPUT_READ)
- cond |= PIDGIN_READ_COND;
+ cond |= ANDROID_READ_COND;
if (condition & PURPLE_INPUT_WRITE)
- cond |= PIDGIN_WRITE_COND;
+ cond |= ANDROID_WRITE_COND;
channel = g_io_channel_unix_new(fd);
closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
- pidgin_io_invoke, closure, g_free);
+ android_io_invoke, closure, g_free);
g_io_channel_unref(channel);
+ purple_debug_info("eventloop", "called input add for %d, result: %d", fd,
+ closure->result);
return closure->result;
}
-gboolean
-eventloopRemoveInput(guint handle)
+static gboolean
+eventloop_input_remove(guint handle)
{
return g_source_remove(handle);
}
+
+static PurpleEventLoopUiOps eventloopUiOps = { eventloop_timeout_add,
+ eventloop_timeout_remove, eventloop_input_add, eventloop_input_remove, NULL,
+ NULL, NULL, NULL, NULL };
+
+JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_core_EventLoop_init_1native(JNIEnv *env, jobject obj)
+{
+ setJavaObject(&eventloop, env, obj);
+}
+
+/*
+ * Class: im_pidgin_libpurple_core_EventLoop
+ * Method: runGLibLoop_native
+ * Signature: ()V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_core_EventLoop_runGLibLoop_1native(JNIEnv *env,
+ jobject obj)
+{
+ GMainLoop *loop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(loop);
+}
+
+JNIEXPORT jboolean JNICALL
+Java_im_pidgin_libpurple_core_EventLoop_exeucte_1native(JNIEnv *env,
+ jobject obj, jlong functionPointer, jlong data)
+{
+ GSourceFunc function = (GSourceFunc) longToP(functionPointer);
+ gboolean result = function((gpointer) longToP(data));
+ return result ? JNI_TRUE : JNI_FALSE;
+}
+
+PurpleEventLoopUiOps *
+getEventloopUiOps()
+{
+ return &eventloopUiOps;
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/SslOps.c b/android/workspace/im.pidgin.libpurple/native/SslOps.c
--- a/android/workspace/im.pidgin.libpurple/native/SslOps.c
+++ b/android/workspace/im.pidgin.libpurple/native/SslOps.c
@@ -21,49 +21,86 @@ uninit()
{
}
-static void
-registerConnection(PurpleSslConnection* gsc)
+static jobject
+fd_to_socket(JNIEnv *env, int unix_fd)
{
static JavaMethodIDCache fdConstructor = METHOD_CACHE("<init>", "()V");
+ static JavaMethodIDCache socketImplConstructor =
+ METHOD_CACHE("<init>", "(Ljava/io/FileDescriptor;)V");
static JavaMethodIDCache socketConstructor =
- METHOD_CACHE("<init>", "(Ljava/io/FileDescriptor;)V");
+ METHOD_CACHE("<init>", "(Ljava/net/SocketImpl;)V");
+
+ jobject fd;
+ jclass fdClass;
+ jmethodID fdConstructorMid;
+ jfieldID fdField;
+ jobject socketImpl;
+ jclass socketImplClass;
+ jmethodID socketImplConstructorMid;
+ jobject socket;
+ jclass socketClass;
+ jmethodID socketConstructorMid;
+ jfieldID connectedField;
+ jfieldID boundField;
+
+ fdClass = (*env)->FindClass(env, "java/io/FileDescriptor");
+ fdConstructorMid = getMethodIDCachedReferenced(env, fdClass,
+ &fdConstructor);
+ g_return_val_if_fail(fdConstructorMid != NULL, NULL);
+ fd = (*env)->NewObject(env, fdClass, fdConstructorMid);
+ fdField = (*env)->GetFieldID(env, fdClass, "descriptor", "I");
+ g_return_val_if_fail(fdField != NULL, NULL);
+ (*env)->SetIntField(env, fd, fdField, unix_fd);
+
+ // Android 4: socketImplClass = (*env)->FindClass(env, "android/net/LocalSocketImpl");
+ socketImplClass = (*env)->FindClass(env, "org/apache/harmony/luni/net/PlainSocketImpl");
+ socketImplConstructorMid = getMethodIDCachedReferenced(env, socketImplClass,
+ &socketImplConstructor);
+ g_return_val_if_fail(socketImplConstructorMid != NULL, NULL);
+ socketImpl = (*env)->NewObject(env, socketImplClass,
+ socketImplConstructorMid, fd);
+
+ socketClass = (*env)->FindClass(env, "java/net/Socket");
+ socketConstructorMid = getMethodIDCachedReferenced(env, socketClass,
+ &socketConstructor);
+ g_return_val_if_fail(socketConstructorMid != NULL, NULL);
+ socket = (*env)->NewObject(env, socketClass, socketConstructorMid,
+ socketImpl);
+
+ connectedField = (*env)->GetFieldID(env, socketClass, "isConnected", "Z");
+ g_return_val_if_fail(connectedField != NULL, NULL);
+ (*env)->SetBooleanField(env, socket, connectedField, JNI_TRUE);
+ boundField = (*env)->GetFieldID(env, socketClass, "isBound", "Z");
+ g_return_val_if_fail(boundField != NULL, NULL);
+ (*env)->SetBooleanField(env, socket, boundField, JNI_TRUE);
+
+ return socket;
+}
+
+static void
+connection_register(PurpleSslConnection* gsc)
+{
+ g_log("jni", G_LOG_LEVEL_DEBUG, "ssl registerConnection");
static JavaMethodIDCache connectionConstructor =
METHOD_CACHE("<init>", "(JLjava/net/Socket;)V");
static JavaMethodIDCache connectMethod = METHOD_CACHE("connect", "()Z");
CALLBACK_START_VOID(&ssl);
- jobject fd;
- jclass fdClass;
- jmethodID fdConstructorMid;
- jfieldID fdField;
jobject socket;
- jclass socketClass;
- jmethodID socketConstructorMid;
jobject connection;
jmethodID connectionConstructorMid;
jclass connectionClass;
jmethodID connectMid;
+ socket = fd_to_socket(env, gsc->fd);
+ g_return_if_fail(socket != NULL);
+
gsc->private_data = g_new(JavaObjectReference, 1);
g_return_if_fail(gsc->private_data != NULL);
- fdClass = (*env)->FindClass(env, "java/io/FileDescriptor");
- fdConstructorMid = getMethodIDCachedReferenced(env, fdClass,
- &fdConstructor);
More information about the Commits
mailing list