diff options
Diffstat (limited to 'python/modules/IcePy/Proxy.cpp')
-rw-r--r-- | python/modules/IcePy/Proxy.cpp | 256 |
1 files changed, 217 insertions, 39 deletions
diff --git a/python/modules/IcePy/Proxy.cpp b/python/modules/IcePy/Proxy.cpp index 072d845f5e0..c3fa273fa47 100644 --- a/python/modules/IcePy/Proxy.cpp +++ b/python/modules/IcePy/Proxy.cpp @@ -145,9 +145,7 @@ proxyCompare(ProxyObject* p1, PyObject* other, int op) } } - PyObject* r = result ? getTrue() : getFalse(); - Py_INCREF(r); - return r; + return result ? incTrue() : incFalse(); } #ifdef WIN32 @@ -166,7 +164,7 @@ extern "C" static long proxyHash(ProxyObject* self) { - return static_cast<long>((*self->proxy)->__hash()); + return static_cast<long>((*self->proxy)->_hash()); } #ifdef WIN32 @@ -203,6 +201,27 @@ proxyIceIsA(ProxyObject* self, PyObject* args) extern "C" #endif static PyObject* +proxyIceIsAAsync(ProxyObject* self, PyObject* args) +{ + PyObject* type; + PyObject* ctx = Py_None; + if(!PyArg_ParseTuple(args, STRCAST("O|O!"), &type, &PyDict_Type, &ctx)) + { + return 0; + } + + // + // We need to reformat the arguments to match what is used by the generated code: ((params...), ctx|None) + // + PyObjectHandle newArgs = Py_BuildValue(STRCAST("((O), O)"), type, ctx); + + return invokeBuiltinAsync(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[] = @@ -211,7 +230,7 @@ proxyBeginIceIsA(ProxyObject* self, PyObject* args, PyObject* kwds) const_cast<char*>("_response"), const_cast<char*>("_ex"), const_cast<char*>("_sent"), - const_cast<char*>("_ctx"), + const_cast<char*>("context"), 0 }; PyObject* type; @@ -267,6 +286,26 @@ proxyIcePing(ProxyObject* self, PyObject* args) extern "C" #endif static PyObject* +proxyIcePingAsync(ProxyObject* self, PyObject* args) +{ + PyObject* ctx = Py_None; + if(!PyArg_ParseTuple(args, STRCAST("|O!"), &PyDict_Type, &ctx)) + { + return 0; + } + + // + // We need to reformat the arguments to match what is used by the generated code: ((params...), ctx|None) + // + PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O)"), ctx); + + return invokeBuiltinAsync(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[] = @@ -274,7 +313,7 @@ proxyBeginIcePing(ProxyObject* self, PyObject* args, PyObject* kwds) const_cast<char*>("_response"), const_cast<char*>("_ex"), const_cast<char*>("_sent"), - const_cast<char*>("_ctx"), + const_cast<char*>("context"), 0 }; PyObject* response = Py_None; @@ -329,6 +368,26 @@ proxyIceIds(ProxyObject* self, PyObject* args) extern "C" #endif static PyObject* +proxyIceIdsAsync(ProxyObject* self, PyObject* args) +{ + PyObject* ctx = Py_None; + if(!PyArg_ParseTuple(args, STRCAST("|O!"), &PyDict_Type, &ctx)) + { + return 0; + } + + // + // We need to reformat the arguments to match what is used by the generated code: ((params...), ctx|None) + // + PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O)"), ctx); + + return invokeBuiltinAsync(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[] = @@ -336,7 +395,7 @@ proxyBeginIceIds(ProxyObject* self, PyObject* args, PyObject* kwds) const_cast<char*>("_response"), const_cast<char*>("_ex"), const_cast<char*>("_sent"), - const_cast<char*>("_ctx"), + const_cast<char*>("context"), 0 }; PyObject* response = Py_None; @@ -391,6 +450,26 @@ proxyIceId(ProxyObject* self, PyObject* args) extern "C" #endif static PyObject* +proxyIceIdAsync(ProxyObject* self, PyObject* args) +{ + PyObject* ctx = Py_None; + if(!PyArg_ParseTuple(args, STRCAST("|O!"), &PyDict_Type, &ctx)) + { + return 0; + } + + // + // We need to reformat the arguments to match what is used by the generated code: ((params...), ctx|None) + // + PyObjectHandle newArgs = Py_BuildValue(STRCAST("((), O)"), ctx); + + return invokeBuiltinAsync(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[] = @@ -398,7 +477,7 @@ proxyBeginIceId(ProxyObject* self, PyObject* args, PyObject* kwds) const_cast<char*>("_response"), const_cast<char*>("_ex"), const_cast<char*>("_sent"), - const_cast<char*>("_ctx"), + const_cast<char*>("context"), 0 }; PyObject* response = Py_None; @@ -716,22 +795,9 @@ proxyIceEndpoints(ProxyObject* self, PyObject* args) assert(self->proxy); Ice::EndpointSeq seq; - Py_ssize_t sz = PySequence_Fast_GET_SIZE(endpoints); - for(Py_ssize_t i = 0; i < sz; ++i) + if(!toEndpointSeq(endpoints, seq)) { - PyObject* p = PySequence_Fast_GET_ITEM(endpoints, i); - PyTypeObject* type = &EndpointType; // Necessary to prevent GCC's strict-alias warnings. - if(!PyObject_IsInstance(p, reinterpret_cast<PyObject*>(type))) - { - PyErr_Format(PyExc_ValueError, STRCAST("expected element of type Ice.Endpoint")); - return 0; - } - Ice::EndpointPtr endp = getEndpoint(p); - if(!endp) - { - return 0; - } - seq.push_back(endp); + return 0; } Ice::ObjectPrx newProxy; @@ -1598,8 +1664,8 @@ proxyIceTimeout(ProxyObject* self, PyObject* args) } catch(const IceUtil::IllegalArgumentException& ex) { - PyErr_Format(PyExc_RuntimeError, "%s", STRCAST(ex.reason().c_str())); - return 0; + PyErr_Format(PyExc_RuntimeError, "%s", STRCAST(ex.reason().c_str())); + return 0; } catch(const Ice::Exception& ex) { @@ -1735,6 +1801,51 @@ proxyIceGetConnection(ProxyObject* self) extern "C" #endif static PyObject* +proxyIceGetConnectionAsync(ProxyObject* self, PyObject* /*args*/, PyObject* /*kwds*/) +{ + assert(self->proxy); + const string op = "ice_getConnection"; + + GetConnectionAsyncCallbackPtr d = new GetConnectionAsyncCallback(*self->communicator, op); + Ice::Callback_Object_ice_getConnectionPtr cb = + Ice::newCallback_Object_ice_getConnection(d, &GetConnectionAsyncCallback::response, + &GetConnectionAsyncCallback::exception); + + Ice::AsyncResultPtr result; + + try + { + AllowThreads allowThreads; // Release Python's global interpreter lock during remote invocations. + + result = (*self->proxy)->begin_ice_getConnection(cb); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + PyObjectHandle communicatorObj = getCommunicatorWrapper(*self->communicator); + PyObjectHandle asyncResultObj = + createAsyncResult(result, reinterpret_cast<PyObject*>(self), 0, communicatorObj.get()); + if(!asyncResultObj.get()) + { + return 0; + } + + PyObjectHandle future = createFuture(op, asyncResultObj.get()); + if(!future.get()) + { + return 0; + } + d->setFuture(future.get()); + return future.release(); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* proxyBeginIceGetConnection(ProxyObject* self, PyObject* args, PyObject* kwds) { assert(self->proxy); @@ -1896,6 +2007,50 @@ proxyIceFlushBatchRequests(ProxyObject* self) extern "C" #endif static PyObject* +proxyIceFlushBatchRequestsAsync(ProxyObject* self, PyObject* /*args*/, PyObject* /*kwds*/) +{ + assert(self->proxy); + const string op = "ice_flushBatchRequests"; + + FlushAsyncCallbackPtr d = new FlushAsyncCallback(op); + Ice::Callback_Object_ice_flushBatchRequestsPtr cb = + Ice::newCallback_Object_ice_flushBatchRequests(d, &FlushAsyncCallback::exception, &FlushAsyncCallback::sent); + + Ice::AsyncResultPtr result; + + try + { + AllowThreads allowThreads; // Release Python's global interpreter lock during remote invocations. + + result = (*self->proxy)->begin_ice_flushBatchRequests(cb); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + PyObjectHandle communicatorObj = getCommunicatorWrapper(*self->communicator); + PyObjectHandle asyncResultObj = + createAsyncResult(result, reinterpret_cast<PyObject*>(self), 0, communicatorObj.get()); + if(!asyncResultObj.get()) + { + return 0; + } + + PyObjectHandle future = createFuture(op, asyncResultObj.get()); + if(!future.get()) + { + return 0; + } + d->setFuture(future.get()); + return future.release(); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* proxyBeginIceFlushBatchRequests(ProxyObject* self, PyObject* args, PyObject* kwds) { assert(self->proxy); @@ -2032,7 +2187,7 @@ AMI_Object_ice_flushBatchRequestsI::exception(const Ice::Exception& ex) ostringstream ostr; 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())); + PyErr_WarnEx(PyExc_RuntimeWarning, const_cast<char*>(str.c_str()), 1); } else { @@ -2083,6 +2238,15 @@ proxyIceInvoke(ProxyObject* self, PyObject* args) extern "C" #endif static PyObject* +proxyIceInvokeAsync(ProxyObject* self, PyObject* args, PyObject* /*kwds*/) +{ + 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); @@ -2160,9 +2324,9 @@ proxyIceCheckedCast(PyObject* type, PyObject* args) // PyObject* obj; char* id; - PyObject* facetOrCtx = 0; + PyObject* facetOrContext = 0; PyObject* ctx = 0; - if(!PyArg_ParseTuple(args, STRCAST("OsOO"), &obj, &id, &facetOrCtx, &ctx)) + if(!PyArg_ParseTuple(args, STRCAST("OsOO"), &obj, &id, &facetOrContext, &ctx)) { return 0; } @@ -2181,20 +2345,20 @@ proxyIceCheckedCast(PyObject* type, PyObject* args) PyObject* facet = 0; - if(checkString(facetOrCtx)) + if(checkString(facetOrContext)) { - facet = facetOrCtx; + facet = facetOrContext; } - else if(PyDict_Check(facetOrCtx)) + else if(PyDict_Check(facetOrContext)) { if(ctx != Py_None) { PyErr_Format(PyExc_ValueError, STRCAST("facet argument to checkedCast must be a string")); return 0; } - ctx = facetOrCtx; + ctx = facetOrContext; } - else if(facetOrCtx != Py_None) + else if(facetOrContext != Py_None) { PyErr_Format(PyExc_ValueError, STRCAST("second argument to checkedCast must be a facet or context")); return 0; @@ -2391,26 +2555,34 @@ 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("ice_isAAsync"), reinterpret_cast<PyCFunction>(proxyIceIsAAsync), METH_VARARGS, + PyDoc_STR(STRCAST("ice_isAAsync(type, [ctx]) -> Ice.Future")) }, { 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")) }, + PyDoc_STR(STRCAST("begin_ice_isA(type[, _response][, _ex][, _sent][, context]) -> 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("ice_pingAsync"), reinterpret_cast<PyCFunction>(proxyIcePingAsync), METH_VARARGS, + PyDoc_STR(STRCAST("ice_pingAsync([ctx]) -> Ice.Future")) }, { STRCAST("begin_ice_ping"), reinterpret_cast<PyCFunction>(proxyBeginIcePing), METH_VARARGS | METH_KEYWORDS, - PyDoc_STR(STRCAST("begin_ice_ping([_response][, _ex][, _sent][, _ctx]) -> Ice.AsyncResult")) }, + PyDoc_STR(STRCAST("begin_ice_ping([_response][, _ex][, _sent][, context]) -> 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("ice_idsAsync"), reinterpret_cast<PyCFunction>(proxyIceIdsAsync), METH_VARARGS, + PyDoc_STR(STRCAST("ice_idsAsync([ctx]) -> Ice.Future")) }, { STRCAST("begin_ice_ids"), reinterpret_cast<PyCFunction>(proxyBeginIceIds), METH_VARARGS | METH_KEYWORDS, - PyDoc_STR(STRCAST("begin_ice_ids([_response][, _ex][, _sent][, _ctx]) -> Ice.AsyncResult")) }, + PyDoc_STR(STRCAST("begin_ice_ids([_response][, _ex][, _sent][, context]) -> 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("ice_idAsync"), reinterpret_cast<PyCFunction>(proxyIceIdAsync), METH_VARARGS, + PyDoc_STR(STRCAST("ice_idAsync([ctx]) -> Ice.Future")) }, { STRCAST("begin_ice_id"), reinterpret_cast<PyCFunction>(proxyBeginIceId), METH_VARARGS | METH_KEYWORDS, - PyDoc_STR(STRCAST("begin_ice_id([_response][, _ex][, _sent][, _ctx]) -> Ice.AsyncResult")) }, + PyDoc_STR(STRCAST("begin_ice_id([_response][, _ex][, _sent][, context]) -> 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, @@ -2503,6 +2675,8 @@ static PyMethodDef ProxyMethods[] = PyDoc_STR(STRCAST("ice_connectionId(string) -> Ice.ObjectPrx")) }, { STRCAST("ice_getConnection"), reinterpret_cast<PyCFunction>(proxyIceGetConnection), METH_NOARGS, PyDoc_STR(STRCAST("ice_getConnection() -> Ice.Connection")) }, + { STRCAST("ice_getConnectionAsync"), reinterpret_cast<PyCFunction>(proxyIceGetConnectionAsync), + METH_NOARGS, PyDoc_STR(STRCAST("ice_getConnectionAsync() -> Ice.Future")) }, { STRCAST("begin_ice_getConnection"), reinterpret_cast<PyCFunction>(proxyBeginIceGetConnection), METH_VARARGS | METH_KEYWORDS, PyDoc_STR(STRCAST("begin_ice_getConnection([_response][, _ex]) -> Ice.AsyncResult")) }, { STRCAST("end_ice_getConnection"), reinterpret_cast<PyCFunction>(proxyEndIceGetConnection), METH_VARARGS, @@ -2511,18 +2685,22 @@ static PyMethodDef ProxyMethods[] = PyDoc_STR(STRCAST("ice_getCachedConnection() -> Ice.Connection")) }, { STRCAST("ice_flushBatchRequests"), reinterpret_cast<PyCFunction>(proxyIceFlushBatchRequests), METH_NOARGS, PyDoc_STR(STRCAST("ice_flushBatchRequests() -> void")) }, + { STRCAST("ice_flushBatchRequestsAsync"), reinterpret_cast<PyCFunction>(proxyIceFlushBatchRequestsAsync), + METH_NOARGS, PyDoc_STR(STRCAST("ice_flushBatchRequestsAsync() -> Ice.Future")) }, { 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_invokeAsync"), reinterpret_cast<PyCFunction>(proxyIceInvokeAsync), METH_VARARGS | METH_KEYWORDS, + PyDoc_STR(STRCAST("ice_invokeAsync(op, mode, inParams[, context]) -> Ice.Future")) }, { 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")) }, + PyDoc_STR(STRCAST("begin_ice_invoke(op, mode, inParams[, _response][, _ex][, _sent][, context]) -> 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")) }, + PyDoc_STR(STRCAST("ice_checkedCast(proxy, id[, facetOrContext[, context]]) -> proxy")) }, { STRCAST("ice_uncheckedCast"), reinterpret_cast<PyCFunction>(proxyIceUncheckedCast), METH_VARARGS | METH_CLASS, PyDoc_STR(STRCAST("ice_uncheckedCast(proxy) -> proxy")) }, { STRCAST("checkedCast"), reinterpret_cast<PyCFunction>(proxyCheckedCast), METH_VARARGS | METH_STATIC, |