Author: ArcRiley Date: 2009-02-27 23:16:32 -0500 (Fri, 27 Feb 2009) New Revision: 1538
Modified: trunk/concordance/include/concordance.h trunk/concordance/src/_core/step.c Log: added multitype queue message support Modified: trunk/concordance/include/concordance.h =================================================================== --- trunk/concordance/include/concordance.h 2009-02-28 04:16:28 UTC (rev 1537) +++ trunk/concordance/include/concordance.h 2009-02-28 04:16:32 UTC (rev 1538) @@ -50,15 +50,20 @@ } concordGlobals; typedef struct { + guint major; + guint minor; +} concordVersion; + + +typedef struct { PyObject* self; gchar* method; GAsyncQueue* queueReturn; /* callback return queue */ - GString* message; -} concordCore_QueueMsg; + union { + gint type0; /* type == 0 */ + GString* type1; /* type == 1 */ + } message; + gint message_type; /* message type (see above) */ +} concordQueueMsg; -typedef struct { - guint major; - guint minor; -} concordVersion; - #endif Modified: trunk/concordance/src/_core/step.c =================================================================== --- trunk/concordance/src/_core/step.c 2009-02-28 04:16:28 UTC (rev 1537) +++ trunk/concordance/src/_core/step.c 2009-02-28 04:16:32 UTC (rev 1538) @@ -22,7 +22,7 @@ #include "concordance._core.h" static void -concordCore_queueFreeMsg(concordCore_QueueMsg* msg) { +_freeQueue(concordQueueMsg* msg) { /* free message struct and it's members gchar* g_string_free (GString *string, @@ -30,7 +30,9 @@ void g_free (gpointer mem); */ g_free(msg->method); - g_string_free(msg->message, TRUE); + if (msg->message_type == 1) { + g_string_free(msg->message.type1, TRUE); + } g_free(msg); } @@ -39,7 +41,7 @@ concordStep() { /*\ cdef : \*/ PyObject* output; - concordCore_QueueMsg* popped; + concordQueueMsg* popped; GTimeVal popEnd; /* calculate end time to wait for next callback, 0.5 seconds ahead @@ -64,7 +66,7 @@ if (!popped) return; - /* call our handler + /* call our handler method using correct message type PyObject* PyObject_CallMethod (PyObject *o, char *method, @@ -78,24 +80,40 @@ Therefore, Py_BuildValue will return NULL but won’t raise an exception. If no exception has been raised yet, SystemError is set. + i (integer) [int] + Convert a plain C int to a Python integer object. + U# (string) [char *, int] Convert a C string and its length to a Python unicode object. If the C string pointer is NULL, the length is ignored and None is returned. */ - output = PyEval_CallMethod(popped->self, popped->method, "OU#", - popped->self, - popped->message->str, popped->message->len); + switch (popped->message_type) { + case 0 : { + /* int message */ + output = PyEval_CallMethod(popped->self, popped->method, "Oi", + popped->self, popped->message.type0); + break; + } + case 1 : { + /* str message */ + output = PyEval_CallMethod(popped->self, popped->method, "OU#", + popped->self, + popped->message.type1->str, + popped->message.type1->len); + break; + } + } if (!output) { /* free message struct and exit here if callback raised an error */ - concordCore_queueFreeMsg(popped); + _freeQueue(popped); return; } /* if output is None, decref it, free message struct, and continue */ if (output == Py_None) { Py_DECREF(output); - concordCore_queueFreeMsg(popped); + _freeQueue(popped); return; } @@ -111,7 +129,7 @@ const char *message); */ Py_DECREF(output); - concordCore_queueFreeMsg(popped); + _freeQueue(popped); PyErr_SetString(PyExc_TypeError, "handle must return a Unicode string or None"); return NULL; @@ -127,8 +145,8 @@ GString* g_string_assign (GString *string, const gchar *rval); */ - popped->message = g_string_assign(popped->message, - concordPyUnicodeToUTF8(output)); + popped->message.type1 = g_string_assign(popped->message.type1, + concordPyUnicodeToUTF8(output)); /* send response with the included self-addressed stamped envelope @@ -139,7 +157,7 @@ } else /* free message struct since we didn't use it */ - concordCore_queueFreeMsg(popped); + _freeQueue(popped); /* free the output object _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn