/soc/2012/michael/android: 10298d38b273: Added conversation mana...

Michael Zangl michael at soc.pidgin.im
Sat Jul 7 13:00:48 EDT 2012


Changeset: 10298d38b2739da13c7c4cdeafd6afc08752c096
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-07-07 11:34 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/10298d38b273

Description:

Added conversation manager.

diffstat:

 android/workspace/im.pidgin.libpurple/native/ConversationManager.c                                  |  159 ++++++++++
 android/workspace/im.pidgin.libpurple/native/ConversationManager.h                                  |   13 +
 android/workspace/im.pidgin.libpurple/native/PurpleAccount.c                                        |    2 +-
 android/workspace/im.pidgin.libpurple/native/PurpleAccount.h                                        |   17 +
 android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h                                          |    4 +
 android/workspace/im.pidgin.libpurple/native/build.ant                                              |    5 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java |   85 +++++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java  |   31 +-
 8 files changed, 302 insertions(+), 14 deletions(-)

diffs (truncated from 429 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple/native/ConversationManager.c b/android/workspace/im.pidgin.libpurple/native/ConversationManager.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/ConversationManager.c
@@ -0,0 +1,159 @@
+/*
+ * ConversationManager.c
+ *
+ *  Created on: 07.07.2012
+ *      Author: michaelz
+ */
+
+#include "ConversationManager.h"
+#include "PurpleAccount.h"
+#include "helpers.h"
+#include <libpurple/conversation.h>
+
+JavaObjectReference conversationManager = JAVA_NULL_OBJECT_REF;
+static void create_conversation(PurpleConversation* conv);
+static void destroy_conversation(PurpleConversation* conv);
+static void write_im(PurpleConversation* conv, const char* who, const char* message, PurpleMessageFlags flags, time_t mtime);
+
+PurpleConversationUiOps conversation_ui_ops = {
+		create_conversation,
+		destroy_conversation,
+		NULL,
+		write_im,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+};
+
+static void* conv_get_handle() {
+	static int handle;
+	return &handle;
+}
+
+static void create_conversation(PurpleConversation* conv) {
+static JavaMethodIDCache methodCache = METHOD_CACHE("createConversation", "(J)V");
+
+		jmethodID mid;
+		jlong conv_ptr;
+
+		CALLBACK_START_VOID(conversationManager);
+
+		conv_ptr = pToLong(conv);
+
+		mid = getMethodIDCachedReferenced(env, conversationManager.class, &methodCache);
+		if (mid != NULL) {
+			(*env)->CallVoidMethod(env, conversationManager.handlerObject, mid, conv_ptr);
+		}
+	}
+
+static void destroy_conversation(PurpleConversation* conv) {
+static JavaMethodIDCache methodCache = METHOD_CACHE("destroyConversation", "(J)V");
+
+		jmethodID mid;
+		jlong conv_ptr;
+
+		CALLBACK_START_VOID(conversationManager);
+
+		conv_ptr = pToLong(conv);
+
+		mid = getMethodIDCachedReferenced(env, conversationManager.class, &methodCache);
+		if (mid != NULL) {
+			(*env)->CallVoidMethod(env, conversationManager.handlerObject, mid, conv_ptr);
+		}
+	}
+
+static void write_im(PurpleConversation* conv, const char* who, const char* message, PurpleMessageFlags flags, time_t mtime) {
+static JavaMethodIDCache methodCache = METHOD_CACHE("writeIm", "(JLjava/lang/String;Ljava/lang/String;IJ)V");
+
+		jmethodID mid;
+		jlong conv_ptr;
+		jstring who_obj;
+		jstring message_obj;
+
+		CALLBACK_START_VOID(conversationManager);
+
+		conv_ptr = pToLong(conv);
+		who_obj = (*env)->NewStringUTF(env, who);
+		message_obj = (*env)->NewStringUTF(env, message);
+
+		mid = getMethodIDCachedReferenced(env, conversationManager.class, &methodCache);
+		if (mid != NULL && who_obj != NULL && message_obj != NULL) {
+			(*env)->CallVoidMethod(env, conversationManager.handlerObject, mid, conv_ptr, who_obj, message_obj, (jint) flags, (jlong) mtime);
+		}
+	}
+
+
+
+static void
+update_buddy_typing(PurpleAccount* account, const char* who)
+{
+	static JavaMethodIDCache methodCache =
+			METHOD_CACHE("updateBuddyTyping", "(JLjava/lang/String;)V");
+
+	jmethodID mid;
+	jlong account_ptr;
+	jstring who_obj;
+
+	CALLBACK_START_VOID(conversationManager);
+
+	account_ptr = pToLong(account);
+	who_obj = (*env)->NewStringUTF(env, who);
+
+	mid = getMethodIDCachedReferenced(env, conversationManager.class,
+			&methodCache);
+	if (mid != NULL && who_obj != NULL) {
+		(*env)->CallVoidMethod(env, conversationManager.handlerObject, mid,
+				account_ptr, who_obj);
+	}
+}
+
+/*
+ * Class:     im_pidgin_libpurple_conversation_ConversationManager
+ * Method:    register_native
+ * Signature: ()V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_conversation_ConversationManager_register_1native(
+		JNIEnv *env, jobject obj)
+{
+	setJavaObject(&conversationManager, env, obj);
+	purple_signal_connect(purple_conversations_get_handle(), "buddy-typing",
+			conv_get_handle(), PURPLE_CALLBACK(update_buddy_typing),
+			NULL);
+	purple_signal_connect(purple_conversations_get_handle(),
+			"buddy-typing-stopped", conv_get_handle(),
+			PURPLE_CALLBACK(update_buddy_typing), NULL);
+	purple_conversations_set_ui_ops(&conversation_ui_ops);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_conversation_ConversationManager
+ * Method:    findImWithAccount_native
+ * Signature: (Ljava/lang/String;Lim/pidgin/libpurple/account/PurpleAccount;)J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_conversation_ConversationManager_findImWithAccount_1native(
+		JNIEnv *env, jobject obj, jstring who, jobject account)
+{
+	PurpleAccount *account_native;
+	const char* who_native;
+	PurpleConversation *result;
+
+	account_native = getNativeAccount(env, account);
+	who_native = (*env)->GetStringUTFChars(env, who, NULL);
+	g_return_val_if_fail(who_native != NULL, 0);
+	result = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
+			who_native, account_native);
+	(*env)->ReleaseStringUTFChars(env, who, who_native);
+	return pToLong(result);
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/ConversationManager.h b/android/workspace/im.pidgin.libpurple/native/ConversationManager.h
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/ConversationManager.h
@@ -0,0 +1,13 @@
+/*
+ * ConversationManager.h
+ *
+ *  Created on: 07.07.2012
+ *      Author: michaelz
+ */
+
+#ifndef CONVERSATIONMANAGER_H_
+#define CONVERSATIONMANAGER_H_
+
+#include "ConversationManager_jni.h"
+
+#endif /* CONVERSATIONMANAGER_H_ */
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleAccount.c b/android/workspace/im.pidgin.libpurple/native/PurpleAccount.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleAccount.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleAccount.c
@@ -2,7 +2,7 @@
 #include "helpers.h"
 #include <libpurple/account.h>
 
-static PurpleAccount *
+PurpleAccount *
 getNativeAccount(JNIEnv *env, jobject obj)
 {
 	return (PurpleAccount *) getNativePointer(env, obj);
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleAccount.h b/android/workspace/im.pidgin.libpurple/native/PurpleAccount.h
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleAccount.h
@@ -0,0 +1,17 @@
+/*
+ * PurpleAccount.h
+ *
+ *  Created on: 07.07.2012
+ *      Author: michaelz
+ */
+
+#ifndef PURPLEACCOUNT_H_
+#define PURPLEACCOUNT_H_
+
+#include "PurpleAccount_jni.h"
+#include <libpurple/account.h>
+
+PurpleAccount *
+getNativeAccount(JNIEnv *env, jobject obj);
+
+#endif /* PURPLEACCOUNT_H_ */
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h
--- a/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h
@@ -1,5 +1,9 @@
 #include "PurpleBuddy_jni.h"
 #include <libpurple/blist.h>
 
+#ifndef PURPLEBUDDY_H_
+#define PURPLEBUDDY_H_
 PurpleBuddy *
 getNativeBuddy(JNIEnv *env, jobject obj);
+
+#endif
diff --git a/android/workspace/im.pidgin.libpurple/native/build.ant b/android/workspace/im.pidgin.libpurple/native/build.ant
--- a/android/workspace/im.pidgin.libpurple/native/build.ant
+++ b/android/workspace/im.pidgin.libpurple/native/build.ant
@@ -32,7 +32,7 @@
           target: headers.create                      
          - - - - - - - - - - - - - - - - - -->
 	<target name="headers.create">
-		<javah classdefinition="im.pidgin.libpurple.account.PurpleAccount" to="${javah.out}" />
+		<javah classdefinition="im.pidgin.libpurple.account.PurpleAccount" to="${javah.out}" headerfilename="PurpleAccount_jni.h" />
 		<javah classdefinition="im.pidgin.libpurple.account.PurpleAccountManager" to="${javah.out}" />
 		<javah classdefinition="im.pidgin.libpurple.account.PurpleStatus" to="${javah.out}" />
 
@@ -44,7 +44,8 @@
 		<javah classdefinition="im.pidgin.libpurple.buddy.PurpleBuddy" to="${javah.out}" headerfilename="PurpleBuddy_jni.h" />
 
 		<javah classdefinition="im.pidgin.libpurple.conversation.PurpleConversation" to="${javah.out}" />
-		
+		<javah classdefinition="im.pidgin.libpurple.conversation.ConversationManager" to="${javah.out}" headerfilename="ConversationManager_jni.h" />
+
 		<javah classdefinition="im.pidgin.libpurple.core.EventLoop" to="${javah.out}" headerfilename="EventLoop_jni.h"/>
 		<javah classdefinition="im.pidgin.libpurple.core.PurpleInstance" to="${javah.out}" />
 		<javah classdefinition="im.pidgin.libpurple.core.CoreManager" to="${javah.out}" />
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java
@@ -0,0 +1,85 @@
+package im.pidgin.libpurple.conversation;
+
+import im.pidgin.libpurple.account.PurpleAccount;
+import im.pidgin.libpurple.buddy.PurpleBuddy;
+import im.pidgin.libpurple.core.AbstractPurpleManaged;
+import im.pidgin.libpurple.core.CoreManager;
+import im.pidgin.libpurple.peering.PeerGenerator;
+
+import java.util.Hashtable;
+
+public class ConversationManager extends AbstractPurpleManaged implements
+		PeerGenerator<PurpleConversation> {
+
+	private final Hashtable<Long, PurpleConversation> conversations = new Hashtable<Long, PurpleConversation>();
+
+	public ConversationManager(CoreManager manager) {
+		super(manager);
+	}
+
+	/**
+	 * Registers this conversation manager to libpurple.
+	 */
+	public void register() {
+		register_native();
+	}
+
+	private native void register_native();
+
+	public PurpleConversation newConversation(PurpleBuddy buddy) {
+		PurpleConversation conversation = PurpleConversation.newConversation(
+				buddy, getManager());
+		conversations.put(conversation.getNativePointer(), conversation);
+		return conversation;
+	}
+	
+	protected void createConversation(long conv) { 
+		PurpleConversation conversation = getPeer(conv);
+		conversations.put(conversation.getNativePointer(), conversation);
+	}
+
+	protected void destroyConversation(long conv) { 
+		PurpleConversation conversation = getPeer(conv);
+		conversations.remove(conversation.getNativePointer());
+		conversation.nativeObjectFreed();



More information about the Commits mailing list