Author: ArcRiley Date: 2009-01-09 12:01:35 -0500 (Fri, 09 Jan 2009) New Revision: 1452
Modified: trunk/concordance/src/Core.c trunk/concordance/src/Core.h Log: Signifigantly cleaned up and streamlined the queueSend source creation Modified: trunk/concordance/src/Core.c =================================================================== --- trunk/concordance/src/Core.c 2009-01-09 10:19:52 UTC (rev 1451) +++ trunk/concordance/src/Core.c 2009-01-09 17:01:35 UTC (rev 1452) @@ -20,12 +20,10 @@ */ #include "Core.h" -#include "utils.h" static gpointer conCore_loop (gpointer); static int conCore_listenChannel (conCoreObject*, conChannel*); static gboolean conCore_listenNew (GIOChannel*, GIOCondition, gpointer); -void conCore_queuePullNew (conCoreObject* self); static gboolean conCore_sessionRead (GIOChannel*, GIOCondition, gpointer); static gboolean conCore_sessionWrite (GIOChannel*, GIOCondition, gpointer); static void conCore_xmlStart (gpointer, const XML_Char*, @@ -65,8 +63,9 @@ static int conCore_init(PyObject* s, PyObject* args, PyObject* kwds) { /*\ cdef : \*/ - conCoreObject* self = (conCoreObject*) s; - static char* kwlist[] = {"client", "server", 0}; + conCoreObject* self = (conCoreObject*) s; + conCoreQueueSource* qSource; + static char* kwlist[] = {"client", "server", 0}; #ifdef MS_WINDOWS /* initialize wsaData if it hasn't already by another Core @@ -150,9 +149,18 @@ */ self->context = g_main_context_new(); - /* temporary */ - conCore_queuePullNew(self); + /* add our sending asyncqueue as an event source + GSource* g_source_new (GSourceFuncs *source_funcs, + guint struct_size); + guint g_source_attach (GSource *source, + GMainContext *context); + */ + qSource = (conCoreQueueSource*) g_source_new(&conCore_queueSourceFuncs, + sizeof(conCoreQueueSource)); + qSource->self = self; + g_source_attach((GSource*) qSource, self->context); + /* open the listening channels Note that the sockets default to -1 and remain -1 on failure, the @@ -228,16 +236,19 @@ PyObject_Del(self); } + static PyObject* conCore_getattro(conCoreObject* self, PyObject* key) { return PyObject_GenericGetAttr((PyObject*) self, key); } + static int conCore_setattro(conCoreObject* self, PyObject* key, PyObject* value) { return PyObject_GenericSetAttr((PyObject*) self, key, value); } + static PyObject* conCore_defaultHandle(PyObject* self, PyObject* args) { /* Placeholder method, just return empty string */ @@ -260,7 +271,7 @@ /* ensure there are no arguments save self */ if (!PyArg_ParseTupleAndKeywords(args, kwds, ":__call__", kwlist)) return NULL; - + /* loop until a signal is raised int PyErr_CheckSignals (); @@ -280,7 +291,7 @@ gpointer g_async_queue_timed_pop (GAsyncQueue *queue, GTimeVal *end_time); - */ + */ Py_BEGIN_ALLOW_THREADS popped = g_async_queue_timed_pop(self->queueRecv, &popEnd); Py_END_ALLOW_THREADS @@ -290,7 +301,7 @@ /* build argument tuple - PyObject* PyUnicode_FromStringAndSize (const char *u, + PyObject* PyUnicode_FromStringAndSize (const char *u, Py_ssize_t size) PyObject* PyTuple_Pack (Py_ssize_t n, ...) @@ -500,7 +511,7 @@ const gchar *val, gssize len); */ - session->wbuff = g_string_append_len(session->wbuff, + session->wbuff = g_string_append_len(session->wbuff, str+sent, len-sent); /* add a watch to send more when the channel is ready for it @@ -594,9 +605,8 @@ /* get the next callback reply and send it gpointer g_async_queue_pop (GAsyncQueue *queue); - */ + */ pop = g_async_queue_pop(self->queueSend); - printf("}%s", pop->message->str); conCore_sessionSend(pop->session, pop->message->str, pop->message->len); /* free popped message before returning @@ -611,39 +621,6 @@ return TRUE; } - void - conCore_queuePullNew(conCoreObject* self) { /*\ - cdef : \*/ - conCoreQueueSource* source; - - /* populate srcfuncs - - typedef struct { - gboolean (*prepare) (GSource *source, - gint *timeout_); - gboolean (*check) (GSource *source); - gboolean (*dispatch) (GSource *source, - GSourceFunc callback, - gpointer user_data); - void (*finalize) (GSource *source); - } GSourceFuncs; - */ - self->queueFuncs.prepare = conCore_queuePullPrepare; - self->queueFuncs.check = conCore_queuePullCheck; - self->queueFuncs.dispatch = conCore_queuePullDispatch; - self->queueFuncs.finalize = NULL; - - /* return the new source - - GSource * g_source_new (GSourceFuncs *source_funcs, - guint struct_size); - */ - source = (conCoreQueueSource*) g_source_new(&self->queueFuncs, - sizeof(conCoreQueueSource)); - source->self = self; - g_source_attach((GSource*) source, self->context); - } - /* # ########################################################################### @@ -1126,7 +1103,7 @@ /* remaining: response, abort */ } - + /* other depth=1 namespaces */ break; } @@ -1140,7 +1117,7 @@ const gchar *format, ...); */ - g_string_append_printf(session->ebuff, "<%s xmlns='%s'", + g_string_append_printf(session->ebuff, "<%s xmlns='%s'", element[1], element[0]); for (i = 0; atts[i]; i += 2) g_string_append_printf(session->ebuff, " %s='%s'", @@ -1262,7 +1239,7 @@ if (session->state == CON_E_OPEN) /* character data should be ignored at the stream level */ return; - + /* append character data to element buffer GString* g_string_append_len (GString *string, @@ -1279,6 +1256,13 @@ # Class MethodDef and Type # */ + GSourceFuncs conCore_queueSourceFuncs = { + conCore_queuePullPrepare, /*prepare*/ + conCore_queuePullCheck, /*check*/ + conCore_queuePullDispatch, /*dispatch*/ + NULL, /*finalize*/ + }; + static PyMethodDef conCore_methods[] = { {"clientHandle", conCore_defaultHandle, @@ -1287,7 +1271,6 @@ { NULL, NULL }, /* sentinel */ }; - PyTypeObject conCore_Type = { PyVarObject_HEAD_INIT(NULL, 0) "concordance.Core", /*tp_name*/ Modified: trunk/concordance/src/Core.h =================================================================== --- trunk/concordance/src/Core.h 2009-01-09 10:19:52 UTC (rev 1451) +++ trunk/concordance/src/Core.h 2009-01-09 17:01:35 UTC (rev 1452) @@ -37,7 +37,9 @@ #include <netdb.h> #endif +#include "utils.h" + typedef struct { GIOChannel* chan; const gchar* addr; @@ -98,6 +100,7 @@ } conCoreQueueSource; +GSourceFuncs conCore_queueSourceFuncs; PyTypeObject conCore_Type; #define conCoreObject_Check(v) (Py_TYPE(v) == &conCore_Type) _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn