/soc/2012/michael/android: 983f7a7425d3: Implemented GListRefere...

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


Changeset: 983f7a7425d3aa8c492612bdd9e5cab3927709d7
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-06-24 10:21 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/983f7a7425d3

Description:

Implemented GListReference native bindings. Added a new ProtocolList interface to access the protocols.

diffstat:

 android/workspace/im.pidgin.libpurple/native/GListReference.c                                 |  68 ++++++---
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java           |   5 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/EventLoop.java             |  29 ++-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/PurpleInstance.java        |   5 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/plugin/PurplePluginManager.java |  28 ++-
 5 files changed, 85 insertions(+), 50 deletions(-)

diffs (257 lines):

diff --git a/android/workspace/im.pidgin.libpurple/native/GListReference.c b/android/workspace/im.pidgin.libpurple/native/GListReference.c
--- a/android/workspace/im.pidgin.libpurple/native/GListReference.c
+++ b/android/workspace/im.pidgin.libpurple/native/GListReference.c
@@ -1,53 +1,67 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class im_pidgin_libpurple_glib_GListReference */
+#include "GListReference.h"
+#include <glib.h>
+#include "helpers.h"
 
-#ifndef _Included_im_pidgin_libpurple_glib_GListReference
-#define _Included_im_pidgin_libpurple_glib_GListReference
-#ifdef __cplusplus
-extern "C" {
-#endif
+GList *
+getGList(JNIEnv *env, jobject obj)
+{
+	return (GList *) getNativePointer(env, obj);
+}
+
 /*
  * Class:     im_pidgin_libpurple_glib_GListReference
  * Method:    length_native
  * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_im_pidgin_libpurple_glib_GListReference_length_1native
-  (JNIEnv *, jobject);
+ */JNIEXPORT jint JNICALL
+Java_im_pidgin_libpurple_glib_GListReference_length_1native(JNIEnv *env,
+		jobject obj)
+{
+	return g_list_length(getGList(env, obj));
+}
 
 /*
  * Class:     im_pidgin_libpurple_glib_GListReference
  * Method:    nth_native
  * Signature: (I)J
- */
-JNIEXPORT jlong JNICALL Java_im_pidgin_libpurple_glib_GListReference_nth_1native
-  (JNIEnv *, jobject, jint);
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_glib_GListReference_nth_1native(JNIEnv *env,
+		jobject obj, jint n)
+{
+	return pToLong(g_list_nth(getGList(env, obj), (guint) n));
+}
 
 /*
  * Class:     im_pidgin_libpurple_glib_GListReference
  * Method:    data_native
  * Signature: (J)J
- */
-JNIEXPORT jlong JNICALL Java_im_pidgin_libpurple_glib_GListReference_data_1native
-  (JNIEnv *, jobject, jlong);
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_glib_GListReference_data_1native(JNIEnv *env,
+		jobject obj, jlong ref)
+{
+	GList *item = (GList*) longToP(ref);
+	return pToLong(item->data);
+}
 
 /*
  * Class:     im_pidgin_libpurple_glib_GListReference
  * Method:    next_native
  * Signature: (J)J
- */
-JNIEXPORT jlong JNICALL Java_im_pidgin_libpurple_glib_GListReference_next_1native
-  (JNIEnv *, jobject, jlong);
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_glib_GListReference_next_1native(JNIEnv *env,
+		jobject obj, jlong ref)
+{
+	GList *item = (GList*) longToP(ref);
+	return pToLong(g_list_next(item));
+}
 
 /*
  * Class:     im_pidgin_libpurple_glib_GListReference
  * Method:    previous_native
  * Signature: (J)J
- */
-JNIEXPORT jlong JNICALL Java_im_pidgin_libpurple_glib_GListReference_previous_1native
-  (JNIEnv *, jobject, jlong);
-
-#ifdef __cplusplus
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_glib_GListReference_previous_1native(JNIEnv *env,
+		jobject obj, jlong ref)
+{
+	GList *item = (GList*) longToP(ref);
+	return pToLong(g_list_previous(item));
 }
-#endif
-#endif
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
@@ -2,6 +2,7 @@
 
 import im.pidgin.libpurple.account.PurpleAccountManager;
 import im.pidgin.libpurple.core.thread.PurpleThread;
+import im.pidgin.libpurple.plugin.PurplePluginList;
 import im.pidgin.libpurple.plugin.PurplePluginManager;
 
 /**
@@ -18,7 +19,7 @@
 	
 	private final PurpleThread purpleThread = new PurpleThread();
 	
-	private final PurplePluginManager pluginManager = new PurplePluginManager(this);
+	private final PurplePluginList pluginManager = new PurplePluginManager(this);
 	
 	/**
 	 * Initializes libpurple by setting all the ui ops and calling
@@ -54,7 +55,7 @@
 		return accountList;
 	}
 	
-	public PurplePluginManager getPluginManager() {
+	public PurplePluginList getPluginManager() {
 		return pluginManager;
 	}
 
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/EventLoop.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/EventLoop.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/EventLoop.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/EventLoop.java
@@ -33,7 +33,7 @@
 	 * <p>
 	 * Only called once from main thread.
 	 */
-	public void register() {
+	public synchronized void register() {
 		init_native();
 	}
 
@@ -58,18 +58,23 @@
 	 * @return a handle for the timeout, which can be passed to timeout_remove.
 	 */
 	protected int eventloopAddTimeout(int interval, long function, long data) {
-		int key = timeoutCounter;
-		
-		System.out.println("Adding eventloop task " + key + " to be scheduled every " + interval + " milliseconds.");
-		EventloopTask task = new EventloopTask(new EventloopFunctionExecutor(
-				key, function, data), getManager().getThread());
-		if (interval <= 0) {
-			interval = 1;
+		int key;
+		synchronized (scheduledTimersMutex) {
+			key = timeoutCounter;
+
+			System.out.println("Adding eventloop task " + key
+					+ " to be scheduled every " + interval + " milliseconds.");
+			EventloopTask task = new EventloopTask(
+					new EventloopFunctionExecutor(key, function, data),
+					getManager().getThread());
+			if (interval <= 0) {
+				interval = 1;
+			}
+			eventTimer.schedule(task, interval, interval);
+
+			scheduledTimers.put(key, task);
+			timeoutCounter++;
 		}
-		eventTimer.schedule(task, interval, interval);
-
-		scheduledTimers.put(key, task);
-		timeoutCounter++;
 		return key;
 	}
 
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/PurpleInstance.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/PurpleInstance.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/PurpleInstance.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/PurpleInstance.java
@@ -2,6 +2,7 @@
 
 import im.pidgin.libpurple.account.PurpleAccountList;
 import im.pidgin.libpurple.exceptions.PurpleRuntimeException;
+import im.pidgin.libpurple.plugin.PurplePluginList;
 
 import java.io.File;
 
@@ -84,4 +85,8 @@
 	public PurpleAccountList getAccountList() {
 		return coreManager.getAccountList();
 	}
+	
+	public PurplePluginList getPluginList() {
+		return coreManager.getPluginManager();
+	}
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/plugin/PurplePluginManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/plugin/PurplePluginManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/plugin/PurplePluginManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/plugin/PurplePluginManager.java
@@ -7,7 +7,7 @@
 import java.util.Hashtable;
 import java.util.List;
 
-public class PurplePluginManager implements PeerGenerator<PurplePlugin> {
+public class PurplePluginManager implements PeerGenerator<PurplePlugin>, PurplePluginList {
 
 	private final CoreManager core;
 
@@ -46,22 +46,20 @@
 		return object.getNativePointer();
 	}
 
-	/**
-	 * Gets a list of all known plugins
-	 * 
-	 * @return A unmodifyable list.
+	/* (non-Javadoc)
+	 * @see im.pidgin.libpurple.plugin.PurplePluginList#getPlugins()
 	 */
+	@Override
 	public List<PurplePlugin> getPlugins() {
 		return GList.fromNativeList(getPlugins_native(), this, false);
 	}
 
 	private native long getProtocolPlugins_native();
 
-	/**
-	 * Gets a list of all protocol plugins
-	 * 
-	 * @return An unmodifyable list of the known protocol plugins.
+	/* (non-Javadoc)
+	 * @see im.pidgin.libpurple.plugin.PurplePluginList#getProtocolPlugins()
 	 */
+	@Override
 	public List<PurpleProtocolPlugin> getProtocolPlugins() {
 		return GList.fromNativeList(getPlugins_native(),
 				new ProtocolPluginGenerator(), false);
@@ -78,9 +76,21 @@
 		}
 	}
 
+	/* (non-Javadoc)
+	 * @see im.pidgin.libpurple.plugin.PurplePluginList#getProtocolPlugin(java.lang.String)
+	 */
+	@Override
 	public PurpleProtocolPlugin getProtocolPlugin(String protocolId) {
 		return getProtocolPeer(getById_native(protocolId));
 	}
 
+	/* (non-Javadoc)
+	 * @see im.pidgin.libpurple.plugin.PurplePluginList#getPlugin(java.lang.String)
+	 */
+	@Override
+	public PurplePlugin getPlugin(String protocolId) {
+		return getPeer(getById_native(protocolId));
+	}
+
 	private native long getById_native(String protocolId);
 }



More information about the Commits mailing list