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/Proxy.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/Proxy.cpp')
-rw-r--r-- | py/modules/IcePy/Proxy.cpp | 389 |
1 files changed, 342 insertions, 47 deletions
diff --git a/py/modules/IcePy/Proxy.cpp b/py/modules/IcePy/Proxy.cpp index 36aea04dece..94f412a436a 100644 --- a/py/modules/IcePy/Proxy.cpp +++ b/py/modules/IcePy/Proxy.cpp @@ -155,7 +155,51 @@ proxyIceIsA(ProxyObject* self, PyObject* args) // PyObjectHandle newArgs = Py_BuildValue(STRCAST("((O), O)"), type, ctx); - return iceIsA(*self->proxy, newArgs.get()); + return invokeBuiltin(reinterpret_cast<PyObject*>(self), "ice_isA", newArgs.get()); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyBeginIceIsA(ProxyObject* self, PyObject* args, PyObject* kwds) +{ + static char* argNames[] = + { + const_cast<char*>("type"), + const_cast<char*>("_response"), + const_cast<char*>("_ex"), + const_cast<char*>("_sent"), + const_cast<char*>("_ctx"), + 0 + }; + PyObject* type; + PyObject* response = Py_None; + PyObject* ex = Py_None; + PyObject* sent = Py_None; + PyObject* ctx = Py_None; + if(!PyArg_ParseTupleAndKeywords(args, kwds, STRCAST("O|OOOO"), argNames, &type, &response, &ex, &sent, &ctx)) + { + return 0; + } + + // + // We need to reformat the arguments to match what is used by the generated code: + // + // ((params...), response|None, ex|None, sent|None, ctx|None) + // + PyObjectHandle newArgs = Py_BuildValue(STRCAST("((O), O, O, O, O)"), type, response, ex, sent, ctx); + + return beginBuiltin(reinterpret_cast<PyObject*>(self), "ice_isA", newArgs.get()); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyEndIceIsA(ProxyObject* self, PyObject* args) +{ + return endBuiltin(reinterpret_cast<PyObject*>(self), "ice_isA", args); } #ifdef WIN32 @@ -175,7 +219,49 @@ proxyIcePing(ProxyObject* self, PyObject* args) // PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O)"), ctx); - return icePing(*self->proxy, newArgs.get()); + return invokeBuiltin(reinterpret_cast<PyObject*>(self), "ice_ping", newArgs.get()); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyBeginIcePing(ProxyObject* self, PyObject* args, PyObject* kwds) +{ + static char* argNames[] = + { + const_cast<char*>("_response"), + const_cast<char*>("_ex"), + const_cast<char*>("_sent"), + const_cast<char*>("_ctx"), + 0 + }; + PyObject* response = Py_None; + PyObject* ex = Py_None; + PyObject* sent = Py_None; + PyObject* ctx = Py_None; + if(!PyArg_ParseTupleAndKeywords(args, kwds, STRCAST("|OOOO"), argNames, &response, &ex, &sent, &ctx)) + { + return 0; + } + + // + // We need to reformat the arguments to match what is used by the generated code: + // + // ((params...), response|None, ex|None, sent|None, ctx|None) + // + PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O, O, O, O)"), response, ex, sent, ctx); + + return beginBuiltin(reinterpret_cast<PyObject*>(self), "ice_ping", newArgs.get()); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyEndIcePing(ProxyObject* self, PyObject* args) +{ + return endBuiltin(reinterpret_cast<PyObject*>(self), "ice_ping", args); } #ifdef WIN32 @@ -195,7 +281,49 @@ proxyIceIds(ProxyObject* self, PyObject* args) // PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O)"), ctx); - return iceIds(*self->proxy, newArgs.get()); + return invokeBuiltin(reinterpret_cast<PyObject*>(self), "ice_ids", newArgs.get()); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyBeginIceIds(ProxyObject* self, PyObject* args, PyObject* kwds) +{ + static char* argNames[] = + { + const_cast<char*>("_response"), + const_cast<char*>("_ex"), + const_cast<char*>("_sent"), + const_cast<char*>("_ctx"), + 0 + }; + PyObject* response = Py_None; + PyObject* ex = Py_None; + PyObject* sent = Py_None; + PyObject* ctx = Py_None; + if(!PyArg_ParseTupleAndKeywords(args, kwds, STRCAST("|OOOO"), argNames, &response, &ex, &sent, &ctx)) + { + return 0; + } + + // + // We need to reformat the arguments to match what is used by the generated code: + // + // ((params...), response|None, ex|None, sent|None, ctx|None) + // + PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O, O, O, O)"), response, ex, sent, ctx); + + return beginBuiltin(reinterpret_cast<PyObject*>(self), "ice_ids", newArgs.get()); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyEndIceIds(ProxyObject* self, PyObject* args) +{ + return endBuiltin(reinterpret_cast<PyObject*>(self), "ice_ids", args); } #ifdef WIN32 @@ -215,7 +343,49 @@ proxyIceId(ProxyObject* self, PyObject* args) // PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O)"), ctx); - return iceId(*self->proxy, newArgs.get()); + return invokeBuiltin(reinterpret_cast<PyObject*>(self), "ice_id", newArgs.get()); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyBeginIceId(ProxyObject* self, PyObject* args, PyObject* kwds) +{ + static char* argNames[] = + { + const_cast<char*>("_response"), + const_cast<char*>("_ex"), + const_cast<char*>("_sent"), + const_cast<char*>("_ctx"), + 0 + }; + PyObject* response = Py_None; + PyObject* ex = Py_None; + PyObject* sent = Py_None; + PyObject* ctx = Py_None; + if(!PyArg_ParseTupleAndKeywords(args, kwds, STRCAST("|OOOO"), argNames, &response, &ex, &sent, &ctx)) + { + return 0; + } + + // + // We need to reformat the arguments to match what is used by the generated code: + // + // ((params...), response|None, ex|None, sent|None, ctx|None) + // + PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O, O, O, O)"), response, ex, sent, ctx); + + return beginBuiltin(reinterpret_cast<PyObject*>(self), "ice_id", newArgs.get()); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyEndIceId(ProxyObject* self, PyObject* args) +{ + return endBuiltin(reinterpret_cast<PyObject*>(self), "ice_id", args); } #ifdef WIN32 @@ -1386,6 +1556,8 @@ extern "C" static PyObject* proxyIceFlushBatchRequests(ProxyObject* self) { + AllowThreads allowThreads; // Release Python's global interpreter lock during remote invocations. + assert(self->proxy); try @@ -1402,30 +1574,120 @@ proxyIceFlushBatchRequests(ProxyObject* self) return Py_None; } +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyBeginIceFlushBatchRequests(ProxyObject* self, PyObject* args, PyObject* kwds) +{ + assert(self->proxy); + + 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_Object_ice_flushBatchRequestsPtr cb; + if(ex || sent) + { + FlushCallbackPtr d = new FlushCallback(ex, sent, "ice_flushBatchRequests"); + cb = Ice::newCallback_Object_ice_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->proxy)->begin_ice_flushBatchRequests(cb); + } + else + { + result = (*self->proxy)->begin_ice_flushBatchRequests(); + } + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + return createAsyncResult(result, reinterpret_cast<PyObject*>(self), 0, 0); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyEndIceFlushBatchRequests(ProxyObject* self, PyObject* args) +{ + assert(self->proxy); + + 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->proxy)->end_ice_flushBatchRequests(r); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + Py_INCREF(Py_None); + return Py_None; +} + namespace IcePy { -class AMI_Object_ice_flushBatchRequestsI : public Ice::AMI_Object_ice_flushBatchRequests +class AMI_Object_ice_flushBatchRequestsI : public IceUtil::Shared { public: AMI_Object_ice_flushBatchRequestsI(PyObject*); ~AMI_Object_ice_flushBatchRequestsI(); - virtual void ice_exception(const Ice::Exception&); + void exception(const Ice::Exception&); + void sent(bool); protected: PyObject* _callback; }; - -class AMI_Object_ice_flushBatchRequestsSentI : public AMI_Object_ice_flushBatchRequestsI, public Ice::AMISentCallback -{ -public: - - AMI_Object_ice_flushBatchRequestsSentI(PyObject*); - - virtual void ice_sent(); -}; +typedef IceUtil::Handle<AMI_Object_ice_flushBatchRequestsI> AMI_Object_ice_flushBatchRequestsIPtr; AMI_Object_ice_flushBatchRequestsI::AMI_Object_ice_flushBatchRequestsI(PyObject* callback) : _callback(callback) @@ -1441,20 +1703,22 @@ AMI_Object_ice_flushBatchRequestsI::~AMI_Object_ice_flushBatchRequestsI() } void -AMI_Object_ice_flushBatchRequestsI::ice_exception(const Ice::Exception& ex) +AMI_Object_ice_flushBatchRequestsI::exception(const Ice::Exception& ex) { AdoptThread adoptThread; // Ensure the current thread is able to call into Python. - PyObjectHandle method = PyObject_GetAttrString(_callback, STRCAST("ice_exception")); - if(!method.get()) + const string methodName = "ice_exception"; + if(!PyObject_HasAttrString(_callback, STRCAST(methodName.c_str()))) { ostringstream ostr; - ostr << "AMI callback object for ice_flushBatchRequests_async does not define ice_exception()"; + ostr << "AMI callback object for ice_flushBatchRequests does not define " << methodName << "()"; string str = ostr.str(); PyErr_Warn(PyExc_RuntimeWarning, const_cast<char*>(str.c_str())); } else { + PyObjectHandle method = PyObject_GetAttrString(_callback, STRCAST(methodName.c_str())); + assert(method.get()); PyObjectHandle exh = convertException(ex); assert(exh.get()); @@ -1467,26 +1731,16 @@ AMI_Object_ice_flushBatchRequestsI::ice_exception(const Ice::Exception& ex) } } -AMI_Object_ice_flushBatchRequestsSentI::AMI_Object_ice_flushBatchRequestsSentI(PyObject* callback) : - AMI_Object_ice_flushBatchRequestsI(callback) -{ -} - void -AMI_Object_ice_flushBatchRequestsSentI::ice_sent() +AMI_Object_ice_flushBatchRequestsI::sent(bool) { AdoptThread adoptThread; // Ensure the current thread is able to call into Python. - PyObjectHandle method = PyObject_GetAttrString(_callback, STRCAST("ice_sent")); - if(!method.get()) - { - ostringstream ostr; - ostr << "AMI callback object for ice_flushBatchRequests_async does not define ice_sent()"; - string str = ostr.str(); - PyErr_Warn(PyExc_RuntimeWarning, const_cast<char*>(str.c_str())); - } - else + const string methodName = "ice_sent"; + if(PyObject_HasAttrString(_callback, STRCAST(methodName.c_str()))) { + PyObjectHandle method = PyObject_GetAttrString(_callback, STRCAST(methodName.c_str())); + assert(method.get()); PyObjectHandle args = PyTuple_New(0); PyObjectHandle tmp = PyObject_Call(method.get(), args.get(), 0); if(PyErr_Occurred()) @@ -1505,23 +1759,22 @@ proxyIceFlushBatchRequestsAsync(ProxyObject* self, PyObject* args) { assert(self->proxy); - PyObject* cb; - if(!PyArg_ParseTuple(args, STRCAST("O"), &cb)) + PyObject* pycb; + if(!PyArg_ParseTuple(args, STRCAST("O"), &pycb)) { return 0; } + AMI_Object_ice_flushBatchRequestsIPtr d = new AMI_Object_ice_flushBatchRequestsI(pycb); + Ice::Callback_Object_ice_flushBatchRequestsPtr cb = + Ice::newCallback_Object_ice_flushBatchRequests(d, &AMI_Object_ice_flushBatchRequestsI::exception, + &AMI_Object_ice_flushBatchRequestsI::sent); + bool result = false; try { - if(PyObject_HasAttrString(cb, STRCAST("ice_sent"))) - { - result = (*self->proxy)->ice_flushBatchRequests_async(new AMI_Object_ice_flushBatchRequestsSentI(cb)); - } - else - { - result = (*self->proxy)->ice_flushBatchRequests_async(new AMI_Object_ice_flushBatchRequestsI(cb)); - } + Ice::AsyncResultPtr r = (*self->proxy)->begin_ice_flushBatchRequests(cb); + result = r->sentSynchronously(); } catch(const Ice::Exception& ex) { @@ -1538,7 +1791,7 @@ extern "C" static PyObject* proxyIceInvoke(ProxyObject* self, PyObject* args) { - return iceInvoke(*self->proxy, args); + return iceInvoke(reinterpret_cast<PyObject*>(self), args); } #ifdef WIN32 @@ -1547,7 +1800,25 @@ extern "C" static PyObject* proxyIceInvokeAsync(ProxyObject* self, PyObject* args) { - return iceInvokeAsync(*self->proxy, args); + return iceInvokeAsync(reinterpret_cast<PyObject*>(self), args); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyBeginIceInvoke(ProxyObject* self, PyObject* args, PyObject* kwds) +{ + return beginIceInvoke(reinterpret_cast<PyObject*>(self), args, kwds); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +proxyEndIceInvoke(ProxyObject* self, PyObject* args) +{ + return endIceInvoke(reinterpret_cast<PyObject*>(self), args); } static PyObject* @@ -1831,12 +2102,28 @@ static PyMethodDef ProxyMethods[] = PyDoc_STR(STRCAST("ice_toString() -> string")) }, { STRCAST("ice_isA"), reinterpret_cast<PyCFunction>(proxyIceIsA), METH_VARARGS, PyDoc_STR(STRCAST("ice_isA(type, [ctx]) -> bool")) }, + { STRCAST("begin_ice_isA"), reinterpret_cast<PyCFunction>(proxyBeginIceIsA), METH_VARARGS | METH_KEYWORDS, + PyDoc_STR(STRCAST("begin_ice_isA(type[, _response][, _ex][, _sent][, _ctx]) -> Ice.AsyncResult")) }, + { STRCAST("end_ice_isA"), reinterpret_cast<PyCFunction>(proxyEndIceIsA), METH_VARARGS, + PyDoc_STR(STRCAST("end_ice_isA(Ice.AsyncResult) -> bool")) }, { STRCAST("ice_ping"), reinterpret_cast<PyCFunction>(proxyIcePing), METH_VARARGS, PyDoc_STR(STRCAST("ice_ping([ctx]) -> None")) }, + { STRCAST("begin_ice_ping"), reinterpret_cast<PyCFunction>(proxyBeginIcePing), METH_VARARGS | METH_KEYWORDS, + PyDoc_STR(STRCAST("begin_ice_ping([_response][, _ex][, _sent][, _ctx]) -> Ice.AsyncResult")) }, + { STRCAST("end_ice_ping"), reinterpret_cast<PyCFunction>(proxyEndIcePing), METH_VARARGS, + PyDoc_STR(STRCAST("end_ice_ping(Ice.AsyncResult) -> None")) }, { STRCAST("ice_ids"), reinterpret_cast<PyCFunction>(proxyIceIds), METH_VARARGS, PyDoc_STR(STRCAST("ice_ids([ctx]) -> list")) }, + { STRCAST("begin_ice_ids"), reinterpret_cast<PyCFunction>(proxyBeginIceIds), METH_VARARGS | METH_KEYWORDS, + PyDoc_STR(STRCAST("begin_ice_ids([_response][, _ex][, _sent][, _ctx]) -> Ice.AsyncResult")) }, + { STRCAST("end_ice_ids"), reinterpret_cast<PyCFunction>(proxyEndIceIds), METH_VARARGS, + PyDoc_STR(STRCAST("end_ice_ids(Ice.AsyncResult) -> list")) }, { STRCAST("ice_id"), reinterpret_cast<PyCFunction>(proxyIceId), METH_VARARGS, PyDoc_STR(STRCAST("ice_id([ctx]) -> string")) }, + { STRCAST("begin_ice_id"), reinterpret_cast<PyCFunction>(proxyBeginIceId), METH_VARARGS | METH_KEYWORDS, + PyDoc_STR(STRCAST("begin_ice_id([_response][, _ex][, _sent][, _ctx]) -> Ice.AsyncResult")) }, + { STRCAST("end_ice_id"), reinterpret_cast<PyCFunction>(proxyEndIceId), METH_VARARGS, + PyDoc_STR(STRCAST("end_ice_id(Ice.AsyncResult) -> string")) }, { STRCAST("ice_getIdentity"), reinterpret_cast<PyCFunction>(proxyIceGetIdentity), METH_NOARGS, PyDoc_STR(STRCAST("ice_getIdentity() -> Ice.Identity")) }, { STRCAST("ice_identity"), reinterpret_cast<PyCFunction>(proxyIceIdentity), METH_VARARGS, @@ -1917,14 +2204,22 @@ static PyMethodDef ProxyMethods[] = PyDoc_STR(STRCAST("ice_getConnection() -> Ice.Connection")) }, { STRCAST("ice_getCachedConnection"), reinterpret_cast<PyCFunction>(proxyIceGetCachedConnection), METH_NOARGS, PyDoc_STR(STRCAST("ice_getCachedConnection() -> Ice.Connection")) }, - { STRCAST("ice_flushBatchRequests"), reinterpret_cast<PyCFunction>(proxyIceFlushBatchRequests), METH_VARARGS, + { STRCAST("ice_flushBatchRequests"), reinterpret_cast<PyCFunction>(proxyIceFlushBatchRequests), METH_NOARGS, PyDoc_STR(STRCAST("ice_flushBatchRequests() -> void")) }, { STRCAST("ice_flushBatchRequests_async"), reinterpret_cast<PyCFunction>(proxyIceFlushBatchRequestsAsync), METH_VARARGS, PyDoc_STR(STRCAST("ice_flushBatchRequests_async(cb) -> bool")) }, + { STRCAST("begin_ice_flushBatchRequests"), reinterpret_cast<PyCFunction>(proxyBeginIceFlushBatchRequests), + METH_VARARGS | METH_KEYWORDS, PyDoc_STR(STRCAST("begin_ice_flushBatchRequests([_ex][, _sent]) -> Ice.AsyncResult")) }, + { STRCAST("end_ice_flushBatchRequests"), reinterpret_cast<PyCFunction>(proxyEndIceFlushBatchRequests), METH_VARARGS, + PyDoc_STR(STRCAST("end_ice_flushBatchRequests(Ice.AsyncResult) -> void")) }, { STRCAST("ice_invoke"), reinterpret_cast<PyCFunction>(proxyIceInvoke), METH_VARARGS, PyDoc_STR(STRCAST("ice_invoke(operation, mode, inParams) -> bool, outParams")) }, { STRCAST("ice_invoke_async"), reinterpret_cast<PyCFunction>(proxyIceInvokeAsync), METH_VARARGS, PyDoc_STR(STRCAST("ice_invoke_async(cb, operation, mode, inParams) -> bool")) }, + { STRCAST("begin_ice_invoke"), reinterpret_cast<PyCFunction>(proxyBeginIceInvoke), METH_VARARGS | METH_KEYWORDS, + PyDoc_STR(STRCAST("begin_ice_invoke(op, mode, inParams[, _response][, _ex][, _sent][, _ctx]) -> Ice.AsyncResult")) }, + { STRCAST("end_ice_invoke"), reinterpret_cast<PyCFunction>(proxyEndIceInvoke), METH_VARARGS, + PyDoc_STR(STRCAST("end_ice_invoke(Ice.AsyncResult) -> (bool, results)")) }, { STRCAST("ice_checkedCast"), reinterpret_cast<PyCFunction>(proxyIceCheckedCast), METH_VARARGS | METH_CLASS, PyDoc_STR(STRCAST("ice_checkedCast(proxy, id[, facetOrCtx[, ctx]]) -> proxy")) }, { STRCAST("ice_uncheckedCast"), reinterpret_cast<PyCFunction>(proxyIceUncheckedCast), METH_VARARGS | METH_CLASS, |