/soc/2012/michael/android: 38f0405d5cc5: Updated BList native fu...

Michael Zangl michael at soc.pidgin.im
Sat Jul 7 03:34:27 EDT 2012


Changeset: 38f0405d5cc54b0c3cf3664a930a5b3d12ee24c7
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-07-02 22:14 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/38f0405d5cc5

Description:

Updated BList native functions to implement more functionality and implemented java object creation.

diffstat:

 android/workspace/im.pidgin.libpurple/native/PurpleBlistGroup.c                             |   4 +-
 android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c                           |  14 ++++
 android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c                              |  30 ++++++++-
 android/workspace/im.pidgin.libpurple/native/PurplePluginManager.c                          |  11 ++-
 android/workspace/im.pidgin.libpurple/native/helpers.c                                      |   4 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlist.java        |   5 -
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java |  27 ++++++++-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java    |  16 +++++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/buddy/PurpleBuddy.java        |  30 +++++++++-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/icon/PurpleIcon.java          |  17 +++++
 10 files changed, 138 insertions(+), 20 deletions(-)

diffs (truncated from 302 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBlistGroup.c b/android/workspace/im.pidgin.libpurple/native/PurpleBlistGroup.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleBlistGroup.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBlistGroup.c
@@ -2,10 +2,10 @@
 #include "helpers.h"
 #include <libpurple/blist.h>
 
-static PurpleBlistNode *
+static PurpleGroup *
 getNativeGroup(JNIEnv *env, jobject obj)
 {
-	return (PurpleBlistNode*) getNativePointer(env, obj);
+	return (PurpleGroup*) getNativePointer(env, obj);
 }
 
 /*
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c b/android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c
@@ -0,0 +1,14 @@
+#include "PurpleBlistManager.h"
+#include "helpers.h"
+#include <libpurple/blist.h>
+
+/*
+ * Class:     im_pidgin_libpurple_blist_PurpleBlistManager
+ * Method:    getRoot_native
+ * Signature: ()Lim/pidgin/libpurple/blist/PurpleBlistNode;
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_blist_PurpleBlistManager_getRoot_1native(JNIEnv *env,
+		jobject obj)
+{
+	return pToLong(purple_blist_get_root());
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c b/android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c
@@ -10,6 +10,28 @@
 
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
+ * Method:    register_native
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_im_pidgin_libpurple_blist_PurpleBlistNode_register_1native
+  (JNIEnv *env, jobject obj) {
+	void* ref = (*env)->NewGlobalRef(env, obj);
+	purple_blist_node_set_ui_data(getNativeNode(env, obj), ref);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
+ * Method:    getCachedPeer_native
+ * Signature: (J)Lim/pidgin/libpurple/blist/PurpleBlistNode;
+ */
+JNIEXPORT jobject JNICALL Java_im_pidgin_libpurple_blist_PurpleBlistNode_getCachedPeer_1native
+  (JNIEnv *env, jclass cls, jlong nodePointer) {
+	void* ref = purple_blist_node_get_ui_data((PurpleBlistNode*) longToP(nodePointer));
+	return (jobject) ref;
+}
+
+/*
+ * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
  * Method:    getTypeFor_native
  * Signature: (J)I
  */JNIEXPORT jint JNICALL
@@ -26,7 +48,7 @@
 Java_im_pidgin_libpurple_blist_PurpleBlistNode_getNextSibling_1native(
 		JNIEnv *env, jobject obj)
 {
-	return purple_blist_node_get_sibling_next(getNativeNode(env, obj));
+	return pToLong(purple_blist_node_get_sibling_next(getNativeNode(env, obj)));
 }
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
@@ -36,7 +58,7 @@
 Java_im_pidgin_libpurple_blist_PurpleBlistNode_getPreviousSibling_1native(
 		JNIEnv *env, jobject obj)
 {
-	return purple_blist_node_get_sibling_prev(getNativeNode(env, obj));
+	return pToLong(purple_blist_node_get_sibling_prev(getNativeNode(env, obj)));
 }
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
@@ -46,7 +68,7 @@
 Java_im_pidgin_libpurple_blist_PurpleBlistNode_getParent_1native(JNIEnv *env,
 		jobject obj)
 {
-	return purple_blist_node_get_parent(getNativeNode(env, obj));
+	return pToLong(purple_blist_node_get_parent(getNativeNode(env, obj)));
 }
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
@@ -56,5 +78,5 @@
 Java_im_pidgin_libpurple_blist_PurpleBlistNode_getFirstChild_1native(
 		JNIEnv *env, jobject obj)
 {
-	return purple_blist_node_get_first_child(getNativeNode(env, obj));
+	return pToLong(purple_blist_node_get_first_child(getNativeNode(env, obj)));
 }
diff --git a/android/workspace/im.pidgin.libpurple/native/PurplePluginManager.c b/android/workspace/im.pidgin.libpurple/native/PurplePluginManager.c
--- a/android/workspace/im.pidgin.libpurple/native/PurplePluginManager.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurplePluginManager.c
@@ -11,7 +11,10 @@
 Java_im_pidgin_libpurple_plugin_PurplePluginManager_getProtocolPlugins_1native(
 		JNIEnv *env, jobject obj)
 {
-	 return pToLong(purple_plugins_get_protocols());
+	GList *list = purple_plugins_get_protocols();
+	__android_log_print(ANDROID_LOG_INFO, "jni", "loaded plugins: %i %p",
+			g_list_length(list), (void *) list);
+	return pToLong(list);
 }
 
 /*
@@ -22,7 +25,7 @@
 Java_im_pidgin_libpurple_plugin_PurplePluginManager_getPlugins_1native(
 		JNIEnv *env, jobject obj)
 {
-	 return pToLong(purple_plugins_get_all());
+	return pToLong(purple_plugins_get_all());
 }
 
 /*
@@ -30,8 +33,8 @@
  * Method:    getById_native
  * Signature: (Ljava/lang/String;)Lim/pidgin/libpurple/plugin/PurpleProtocolPlugin;
  */JNIEXPORT jlong JNICALL
-Java_im_pidgin_libpurple_plugin_PurplePluginManager_getById_1native(
-		JNIEnv *env, jobject obj, jstring id)
+Java_im_pidgin_libpurple_plugin_PurplePluginManager_getById_1native(JNIEnv *env,
+		jobject obj, jstring id)
 {
 	const char* id_native;
 	jlong result;
diff --git a/android/workspace/im.pidgin.libpurple/native/helpers.c b/android/workspace/im.pidgin.libpurple/native/helpers.c
--- a/android/workspace/im.pidgin.libpurple/native/helpers.c
+++ b/android/workspace/im.pidgin.libpurple/native/helpers.c
@@ -48,10 +48,12 @@
 		jclass class = (*env)->FindClass(env,
 				"im/pidgin/libpurple/peering/Peered");
 		if (class == NULL) {
+			__android_log_print(ANDROID_LOG_ERROR, "jni", "Could not find peered class");
 			return NULL;
 		}
-		(*env)->GetFieldID(env, class, "nativePointer", "J");
+		peerField = (*env)->GetFieldID(env, class, "nativePointer", "J");
 		if (peerField == NULL) {
+			__android_log_print(ANDROID_LOG_ERROR, "jni", "Could not find field for peer");
 			return NULL;
 		}
 	}
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlist.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlist.java
deleted file mode 100644
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlist.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package im.pidgin.libpurple.blist;
-
-public class PurpleBlist {
-
-}
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java
@@ -1,5 +1,30 @@
 package im.pidgin.libpurple.blist;
 
-public class PurpleBlistManager {
+import im.pidgin.libpurple.core.CoreManager;
+import im.pidgin.libpurple.peering.PeerGenerator;
+
+public class PurpleBlistManager implements PeerGenerator<PurpleBlistNode>{
+
+	private final CoreManager coreManager;
+
+	public PurpleBlistManager(CoreManager coreManager) {
+		this.coreManager = coreManager;
+	}
+	
+	public PurpleBlistNode getRoot() {
+		return getPeer(getRoot_native());
+	}
+
+	private native long getRoot_native();
+
+	@Override
+	public PurpleBlistNode getPeer(long pointer) {
+		return PurpleBlistNode.getCachedPeer_native(pointer);
+	}
+
+	@Override
+	public long getPeer(PurpleBlistNode object) {
+		return object.getNativePointer();
+	}
 
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
@@ -15,8 +15,20 @@
 
 	protected PurpleBlistNode(long nativePointer, CoreManager manager) {
 		super(nativePointer, manager);
+		register_native();
 	}
 
+	private native void register_native();
+
+	/**
+	 * Gets the cached java object for a given node, or returns
+	 * <code>null</code> if no object was cached.
+	 * 
+	 * @param pointer The pointer to the native object.
+	 * @return The peer or <code>null</code>
+	 */
+	protected static native PurpleBlistNode getCachedPeer_native(long pointer);
+
 	public static PurpleBlistNode constructNode(long nativePointer,
 			CoreManager manager) {
 		int type = getTypeFor_native(nativePointer);
@@ -64,4 +76,8 @@
 
 	private native long getFirstChild_native();
 
+	@Override
+	protected long getNativePointer() {
+		return super.getNativePointer();
+	}
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/buddy/PurpleBuddy.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/buddy/PurpleBuddy.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/buddy/PurpleBuddy.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/buddy/PurpleBuddy.java
@@ -1,7 +1,9 @@
 package im.pidgin.libpurple.buddy;
 
 import im.pidgin.libpurple.account.PurpleAccount;
+import im.pidgin.libpurple.blist.PurpleBlistManager;
 import im.pidgin.libpurple.blist.PurpleBlistNode;
+import im.pidgin.libpurple.blist.PurpleContact;
 import im.pidgin.libpurple.core.CoreManager;
 
 public class PurpleBuddy extends PurpleBlistNode {
@@ -29,10 +31,32 @@
 	private native String getServerAlias_native();
 
 	public PurpleAccount getAccount() {
-		return getAccount_native();
+		return getManager().getAccountList().getPeer(getAccount_native());
 	}
 
-	private native PurpleAccount getAccount_native();
+	private native long getAccount_native();
 
-	
+	/**
+	 * Checks if the buddy is online
+	 * 
+	 * @return true if the account of the buddy is online and the buddy has an
+	 *         online presence.
+	 */
+	public boolean isOnline() {
+		return isOnline_native();
+	}
+
+	private native boolean isOnline_native();
+
+	public PurpleContact getContact() {
+		PurpleBlistManager blist = getManager().getBlist();
+		PurpleBlistNode contact = blist.getPeer(getContact_native());
+		if (contact instanceof PurpleContact) {
+			return (PurpleContact) contact;
+		} else {
+			return null;
+		}
+	}
+
+	private native long getContact_native();
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/icon/PurpleIcon.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/icon/PurpleIcon.java
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/icon/PurpleIcon.java
@@ -0,0 +1,17 @@
+package im.pidgin.libpurple.icon;
+
+import im.pidgin.libpurple.peering.Peered;
+
+public class PurpleIcon extends Peered{
+	protected PurpleIcon(long nativePointer) {
+		super(nativePointer);
+	}
+
+	public static PurpleIcon generateFromPointer(long nativePointer) {
+		if (nativePointer == 0) {
+			return null;
+		} else {
+			return new PurpleIcon(nativePointer);
+		}



More information about the Commits mailing list