soc.2009.vulture: aa95a716: Began initialising libpurple.

gdick at soc.pidgin.im gdick at soc.pidgin.im
Thu May 28 18:30:51 EDT 2009


-----------------------------------------------------------------
Revision: aa95a7163b729677157e4f645f4861101328a7d3
Ancestor: e3c8c88d222f3a44a062679d623efc96e8650e43
Author: gdick at soc.pidgin.im
Date: 2009-05-27T14:47:05
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/aa95a7163b729677157e4f645f4861101328a7d3

Added files:
        vulture/purpleevloop.c vulture/purpleevloop.h
Modified files:
        vulture/Makefile.mingw vulture/purplemain.c

ChangeLog: 

Began initialising libpurple.

-------------- next part --------------
============================================================
--- vulture/purpleevloop.c	fe203f330d5c92acdf51a8cb790dc940610d6014
+++ vulture/purpleevloop.c	fe203f330d5c92acdf51a8cb790dc940610d6014
@@ -0,0 +1,124 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * purpleevloop.c: Low-level event-loop management for libpurple.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * Much of this file is taken verbatim from libpurple's nullclient.c, which
+ * carries the following copyright notice:
+ *
+ *   Pidgin is the legal property of its developers, whose names are too
+ *   numerous to list here.  Please refer to the COPYRIGHT file distributed
+ *   with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+
+#include <windows.h>
+#include <glib.h>
+
+#include "purple.h"
+
+#include "vulture.h"
+#include "purpleevloop.h"
+
+
+/**
+ * The following eventloop functions are used in both pidgin and purple-text. If your
+ * application uses glib mainloop, you can safely use this verbatim.
+ */
+#define PURPLE_GLIB_READ_COND  (G_IO_IN | G_IO_HUP | G_IO_ERR)
+#define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
+
+typedef struct _PurpleGLibIOClosure {
+	PurpleInputFunction function;
+	guint result;
+	gpointer data;
+} PurpleGLibIOClosure;
+
+static void purple_glib_io_destroy(gpointer data)
+{
+	g_free(data);
+}
+
+static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
+{
+	PurpleGLibIOClosure *closure = data;
+	PurpleInputCondition purple_cond = 0;
+
+	if (condition & PURPLE_GLIB_READ_COND)
+		purple_cond |= PURPLE_INPUT_READ;
+	if (condition & PURPLE_GLIB_WRITE_COND)
+		purple_cond |= PURPLE_INPUT_WRITE;
+
+	closure->function(closure->data, g_io_channel_unix_get_fd(source),
+			  purple_cond);
+
+	return TRUE;
+}
+
+static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
+							   gpointer data)
+{
+	PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1);
+	GIOChannel *channel;
+	GIOCondition cond = 0;
+
+	closure->function = function;
+	closure->data = data;
+
+	if (condition & PURPLE_INPUT_READ)
+		cond |= PURPLE_GLIB_READ_COND;
+	if (condition & PURPLE_INPUT_WRITE)
+		cond |= PURPLE_GLIB_WRITE_COND;
+
+	channel = g_io_channel_unix_new(fd);
+	closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
+					      purple_glib_io_invoke, closure, purple_glib_io_destroy);
+
+	g_io_channel_unref(channel);
+	return closure->result;
+}
+
+static PurpleEventLoopUiOps glib_eventloops = 
+{
+	g_timeout_add,
+	g_source_remove,
+	glib_input_add,
+	g_source_remove,
+	NULL,
+#if GLIB_CHECK_VERSION(2,14,0)
+	g_timeout_add_seconds,
+#else
+	NULL,
+#endif
+
+	/* padding */
+	NULL,
+	NULL,
+	NULL
+};
+/*** End of the eventloop functions. ***/
+
+
+/**
+ * Called as part of the libpurple init process to set up the event loop.
+ */
+void VulturePurpleEventLoopSetUIOps(void)
+{
+	purple_eventloop_set_ui_ops(&glib_eventloops);
+}
============================================================
--- vulture/purpleevloop.h	e56b55cbfe258c8afc5f18cc7ff0f2ba1dab08cb
+++ vulture/purpleevloop.h	e56b55cbfe258c8afc5f18cc7ff0f2ba1dab08cb
@@ -0,0 +1,28 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * purpleevloop.h: Low-level event-loop management for libpurple.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#ifndef _VULTURE_PURPLEEVLOOP_H_
+#define _VULTURE_PURPLEEVLOOP_H_
+
+void VulturePurpleEventLoopSetUIOps(void);
+
+#endif
============================================================
--- vulture/Makefile.mingw	a78cc081f80cb404068906796366af446c50c20e
+++ vulture/Makefile.mingw	5b6091e29988ea1aee14dbffcf0dee6b08e028ab
@@ -54,7 +54,8 @@ VULTURE_C_SRC =	\
 			vulture.c \
 			blist.c \
 			purplemain.c \
-			purplequeue.c
+			purplequeue.c \
+			purpleevloop.c
 
 # VULTURE_RC_SRC = win32/pidgin_dll_rc.rc
 VULTURE_OBJECTS = $(VULTURE_C_SRC:%.c=%.o) $(VULTURE_RC_SRC:%.rc=%.o)
============================================================
--- vulture/purplemain.c	e8c5342881802739b4e1b87081736515bf125c1c
+++ vulture/purplemain.c	5a750ec1520e2331c64a8f25facc8761c8cf8c96
@@ -39,14 +39,22 @@
 #include <process.h>
 #include <glib.h>
 
+#include "purple.h"
+
 #include "vulture.h"
 #include "purplemain.h"
 #include "purplequeue.h"
+#include "purpleevloop.h"
 
 
 static UINT CALLBACK PurpleThread(void *lpvData);
+static int InitLibpurple(void);
+static void InitUI(void);
 
 
+#define VULTURE_ID	"vulture"
+
+
 GMainLoop *g_lpgmainloop = NULL;
 
 
@@ -82,25 +90,70 @@ void VultureShutDownLibpurple(void)
  *
  * @param	lpvData		Currently unused.
  *
- * @return Always zero. This is used as the thread's exit code.
+ * @return Exit code. Zero on success; non-zero on error.
  */
 static UINT CALLBACK PurpleThread(void *lpvData)
 {
 	GSource *lpgsourceSync = VultureCreateSyncQueueSource();
 	GSource *lpgsourceAsync = VultureCreateAsyncQueueSource();
 
+	int iRet = 0;
+
 	UNREFERENCED_PARAMETER(lpvData);
 
 	g_lpgmainloop = g_main_loop_new(NULL, TRUE);
 
+	/* Poll the queues. */
 	g_source_attach(lpgsourceSync, NULL);
 	g_source_attach(lpgsourceAsync, NULL);
 
-	g_main_loop_run(g_lpgmainloop);
+	if(InitLibpurple() == 0)
+		g_main_loop_run(g_lpgmainloop);
+	else
+	{
+		/* TODO: Display a message and replace magic number. */
+		exit(1);
+	}
 
 	g_main_loop_unref(g_lpgmainloop);
 	g_source_unref(lpgsourceAsync);
 	g_source_unref(lpgsourceSync);
 
+	return iRet;
+}
+
+
+/**
+ * Begins initialising libpurple. This function will eventually pass control
+ * to InitUI which does most of the work.
+ *
+ * @return Zero on success; non-zero on error.
+ */
+static int InitLibpurple(void)
+{
+	static PurpleCoreUiOps coreuiops = 
+	{
+		NULL, NULL, InitUI, NULL,
+		/* padding */
+		NULL, NULL, NULL, NULL
+	};
+
+	VulturePurpleEventLoopSetUIOps();
+	purple_core_set_ui_ops(&coreuiops);
+
+	/* Init the core, which will eventually call InitUI. */
+	if(!purple_core_init(VULTURE_ID))
+		return 1;
+
 	return 0;
 }
+
+
+/**
+ * Initialises higher-level libpurple components.
+ *
+ * \sa InitLibpurple.
+ */
+static void InitUI(void)
+{
+}


More information about the Commits mailing list