From bc2e4034079842cde62b6b44c4bdcd6a954f4f46 Mon Sep 17 00:00:00 2001 From: Benoit Foucher Date: Wed, 6 Jan 2010 12:43:48 +0100 Subject: Merged Mark's pythonami branch --- py/modules/IcePy/Connection.cpp | 106 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) (limited to 'py/modules/IcePy/Connection.cpp') diff --git a/py/modules/IcePy/Connection.cpp b/py/modules/IcePy/Connection.cpp index 2d1cba09c5f..d2f5ffce2cc 100644 --- a/py/modules/IcePy/Connection.cpp +++ b/py/modules/IcePy/Connection.cpp @@ -14,9 +14,10 @@ #include #include #include +#include #include #include -#include +#include using namespace std; using namespace IcePy; @@ -220,6 +221,103 @@ connectionFlushBatchRequests(ConnectionObject* self) return Py_None; } +#ifdef WIN32 +extern "C" +#endif +static PyObject* +connectionBeginFlushBatchRequests(ConnectionObject* self, PyObject* args, PyObject* kwds) +{ + assert(self->connection); + + static char* argNames[] = + { + const_cast("_ex"), + const_cast("_sent"), + 0 + }; + PyObject* ex = Py_None; + PyObject* sent = Py_None; + if(!PyArg_ParseTupleAndKeywords(args, kwds, STRCAST("|OO"), argNames, &ex, &sent)) + { + return 0; + } + + if(ex == Py_None) + { + ex = 0; + } + if(sent == Py_None) + { + sent = 0; + } + + if(!ex && sent) + { + PyErr_Format(PyExc_RuntimeError, + STRCAST("exception callback must also be provided when sent callback is used")); + return 0; + } + + Ice::Callback_Connection_flushBatchRequestsPtr cb; + if(ex || sent) + { + FlushCallbackPtr d = new FlushCallback(ex, sent, "flushBatchRequests"); + cb = Ice::newCallback_Connection_flushBatchRequests(d, &FlushCallback::exception, &FlushCallback::sent); + } + + Ice::AsyncResultPtr result; + try + { + AllowThreads allowThreads; // Release Python's global interpreter lock during remote invocations. + + if(cb) + { + result = (*self->connection)->begin_flushBatchRequests(cb); + } + else + { + result = (*self->connection)->begin_flushBatchRequests(); + } + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + return createAsyncResult(result, 0, reinterpret_cast(self), 0); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +connectionEndFlushBatchRequests(ConnectionObject* self, PyObject* args) +{ + assert(self->connection); + + PyObject* result; + if(!PyArg_ParseTuple(args, STRCAST("O!"), &AsyncResultType, &result)) + { + return 0; + } + + Ice::AsyncResultPtr r = getAsyncResult(result); + try + { + AllowThreads allowThreads; // Release Python's global interpreter lock during blocking invocations. + (*self->connection)->end_flushBatchRequests(r); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + Py_INCREF(Py_None); + return Py_None; +} + #ifdef WIN32 extern "C" #endif @@ -333,6 +431,10 @@ static PyMethodDef ConnectionMethods[] = PyDoc_STR(STRCAST("getAdapter() -> Ice.ObjectAdapter")) }, { STRCAST("flushBatchRequests"), reinterpret_cast(connectionFlushBatchRequests), METH_NOARGS, PyDoc_STR(STRCAST("flushBatchRequests() -> None")) }, + { STRCAST("begin_flushBatchRequests"), reinterpret_cast(connectionBeginFlushBatchRequests), + METH_VARARGS | METH_KEYWORDS, PyDoc_STR(STRCAST("begin_flushBatchRequests([_ex][, _sent]) -> Ice.AsyncResult")) }, + { STRCAST("end_flushBatchRequests"), reinterpret_cast(connectionEndFlushBatchRequests), METH_VARARGS, + PyDoc_STR(STRCAST("end_flushBatchRequests(Ice.AsyncResult) -> None")) }, { STRCAST("type"), reinterpret_cast(connectionType), METH_NOARGS, PyDoc_STR(STRCAST("type() -> string")) }, { STRCAST("timeout"), reinterpret_cast(connectionTimeout), METH_NOARGS, @@ -342,7 +444,7 @@ static PyMethodDef ConnectionMethods[] = { STRCAST("getInfo"), reinterpret_cast(connectionGetInfo), METH_NOARGS, PyDoc_STR(STRCAST("getInfo() -> Ice.ConnectionInfo")) }, { STRCAST("getEndpoint"), reinterpret_cast(connectionGetEndpoint), METH_NOARGS, - PyDoc_STR(STRCAST("getInfo() -> Ice.Endpoint")) }, + PyDoc_STR(STRCAST("getEndpoint() -> Ice.Endpoint")) }, { 0, 0 } /* sentinel */ }; -- cgit v1.2.3