diff options
author | Benoit Foucher <benoit@zeroc.com> | 2010-01-06 12:43:48 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2010-01-06 12:43:48 +0100 |
commit | bc2e4034079842cde62b6b44c4bdcd6a954f4f46 (patch) | |
tree | 0afd6dbfade2a57978227193d5dccdc267e89d7b /py/modules/IcePy/Connection.cpp | |
parent | bug 4495 - clean up book demos (diff) | |
download | ice-bc2e4034079842cde62b6b44c4bdcd6a954f4f46.tar.bz2 ice-bc2e4034079842cde62b6b44c4bdcd6a954f4f46.tar.xz ice-bc2e4034079842cde62b6b44c4bdcd6a954f4f46.zip |
Merged Mark's pythonami branch
Diffstat (limited to 'py/modules/IcePy/Connection.cpp')
-rw-r--r-- | py/modules/IcePy/Connection.cpp | 106 |
1 files changed, 104 insertions, 2 deletions
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 <ConnectionInfo.h> #include <Endpoint.h> #include <ObjectAdapter.h> +#include <Operation.h> #include <Proxy.h> #include <Util.h> -#include <Ice/Connection.h> +#include <Ice/ConnectionAsync.h> using namespace std; using namespace IcePy; @@ -224,6 +225,103 @@ connectionFlushBatchRequests(ConnectionObject* self) extern "C" #endif static PyObject* +connectionBeginFlushBatchRequests(ConnectionObject* self, PyObject* args, PyObject* kwds) +{ + assert(self->connection); + + static char* argNames[] = + { + const_cast<char*>("_ex"), + const_cast<char*>("_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<PyObject*>(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 +static PyObject* connectionType(ConnectionObject* self) { assert(self->connection); @@ -333,6 +431,10 @@ static PyMethodDef ConnectionMethods[] = PyDoc_STR(STRCAST("getAdapter() -> Ice.ObjectAdapter")) }, { STRCAST("flushBatchRequests"), reinterpret_cast<PyCFunction>(connectionFlushBatchRequests), METH_NOARGS, PyDoc_STR(STRCAST("flushBatchRequests() -> None")) }, + { STRCAST("begin_flushBatchRequests"), reinterpret_cast<PyCFunction>(connectionBeginFlushBatchRequests), + METH_VARARGS | METH_KEYWORDS, PyDoc_STR(STRCAST("begin_flushBatchRequests([_ex][, _sent]) -> Ice.AsyncResult")) }, + { STRCAST("end_flushBatchRequests"), reinterpret_cast<PyCFunction>(connectionEndFlushBatchRequests), METH_VARARGS, + PyDoc_STR(STRCAST("end_flushBatchRequests(Ice.AsyncResult) -> None")) }, { STRCAST("type"), reinterpret_cast<PyCFunction>(connectionType), METH_NOARGS, PyDoc_STR(STRCAST("type() -> string")) }, { STRCAST("timeout"), reinterpret_cast<PyCFunction>(connectionTimeout), METH_NOARGS, @@ -342,7 +444,7 @@ static PyMethodDef ConnectionMethods[] = { STRCAST("getInfo"), reinterpret_cast<PyCFunction>(connectionGetInfo), METH_NOARGS, PyDoc_STR(STRCAST("getInfo() -> Ice.ConnectionInfo")) }, { STRCAST("getEndpoint"), reinterpret_cast<PyCFunction>(connectionGetEndpoint), METH_NOARGS, - PyDoc_STR(STRCAST("getInfo() -> Ice.Endpoint")) }, + PyDoc_STR(STRCAST("getEndpoint() -> Ice.Endpoint")) }, { 0, 0 } /* sentinel */ }; |