diff options
author | Benoit Foucher <benoit@zeroc.com> | 2018-01-31 17:21:12 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2018-01-31 17:21:12 +0100 |
commit | c3f44e70ea6a8c9bd16281f4b7e2bcd8f7bae47f (patch) | |
tree | a02e199af243136b4dc4a83929e8c9a185c9dcd8 /python/modules | |
parent | Updated AutoStart description (diff) | |
download | ice-c3f44e70ea6a8c9bd16281f4b7e2bcd8f7bae47f.tar.bz2 ice-c3f44e70ea6a8c9bd16281f4b7e2bcd8f7bae47f.tar.xz ice-c3f44e70ea6a8c9bd16281f4b7e2bcd8f7bae47f.zip |
Added support for ice_fixed, ice_getTimeout, ice_getCompress methods (ICE-7996 & ICE-7976)
Diffstat (limited to 'python/modules')
-rw-r--r-- | python/modules/IcePy/Connection.cpp | 29 | ||||
-rw-r--r-- | python/modules/IcePy/Connection.h | 3 | ||||
-rw-r--r-- | python/modules/IcePy/Proxy.cpp | 99 |
3 files changed, 131 insertions, 0 deletions
diff --git a/python/modules/IcePy/Connection.cpp b/python/modules/IcePy/Connection.cpp index 2a0c5338bb1..efb3f6222c7 100644 --- a/python/modules/IcePy/Connection.cpp +++ b/python/modules/IcePy/Connection.cpp @@ -1275,3 +1275,32 @@ IcePy::createConnection(const Ice::ConnectionPtr& connection, const Ice::Communi } return reinterpret_cast<PyObject*>(obj); } + +bool +IcePy::checkConnection(PyObject* p) +{ + PyTypeObject* type = &ConnectionType; // Necessary to prevent GCC's strict-alias warnings. + return PyObject_IsInstance(p, reinterpret_cast<PyObject*>(type)) == 1; +} + +bool +IcePy::getConnectionArg(PyObject* p, const string& func, const string& arg, Ice::ConnectionPtr& con) +{ + if(p == Py_None) + { + con = 0; + return true; + } + else if(!checkConnection(p)) + { + PyErr_Format(PyExc_ValueError, STRCAST("%s expects an Ice.Connection object or None for argument '%s'"), + func.c_str(), arg.c_str()); + return false; + } + else + { + ConnectionObject* obj = reinterpret_cast<ConnectionObject*>(p); + con = *obj->connection; + return true; + } +} diff --git a/python/modules/IcePy/Connection.h b/python/modules/IcePy/Connection.h index 6abf13a6a0d..b8bc7bb3da2 100644 --- a/python/modules/IcePy/Connection.h +++ b/python/modules/IcePy/Connection.h @@ -21,6 +21,9 @@ bool initConnection(PyObject*); PyObject* createConnection(const Ice::ConnectionPtr&, const Ice::CommunicatorPtr&); +bool checkConnection(PyObject*); +bool getConnectionArg(PyObject*, const std::string&, const std::string&, Ice::ConnectionPtr&); + } #endif diff --git a/python/modules/IcePy/Proxy.cpp b/python/modules/IcePy/Proxy.cpp index 86a4a828eb1..2655d7eb975 100644 --- a/python/modules/IcePy/Proxy.cpp +++ b/python/modules/IcePy/Proxy.cpp @@ -19,6 +19,7 @@ #include <Operation.h> #include <Thread.h> #include <Util.h> +#include <Types.h> #include <Ice/Communicator.h> #include <Ice/LocalException.h> #include <Ice/Locator.h> @@ -1653,6 +1654,36 @@ proxyIceCompress(ProxyObject* self, PyObject* args) extern "C" #endif static PyObject* +proxyIceGetCompress(ProxyObject* self) +{ + assert(self->proxy); + + PyObject* b; + try + { + IceUtil::Optional<bool> compress = (*self->proxy)->ice_getCompress(); + if(compress) + { + b = *compress ? getTrue() : getFalse(); + } + else + { + b = Unset; + } + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + Py_INCREF(b); + return b; +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* proxyIceTimeout(ProxyObject* self, PyObject* args) { int timeout; @@ -1686,6 +1717,34 @@ proxyIceTimeout(ProxyObject* self, PyObject* args) extern "C" #endif static PyObject* +proxyIceGetTimeout(ProxyObject* self) +{ + assert(self->proxy); + + try + { + IceUtil::Optional<int> timeout = (*self->proxy)->ice_getTimeout(); + if(timeout) + { + return PyLong_FromLong(*timeout); + } + else + { + Py_INCREF(Unset); + return Unset; + } + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* proxyIceIsCollocationOptimized(ProxyObject* self) { assert(self->proxy); @@ -1777,6 +1836,40 @@ proxyIceConnectionId(ProxyObject* self, PyObject* args) extern "C" #endif static PyObject* +proxyIceFixed(ProxyObject* self, PyObject* args) +{ + assert(self->proxy); + + PyObject* p; + if(!PyArg_ParseTuple(args, STRCAST("O"), &p)) + { + return 0; + } + + Ice::ConnectionPtr connection; + if(!getConnectionArg(p, "ice_fixed", "connection", connection)) + { + return 0; + } + + Ice::ObjectPrx newProxy; + try + { + newProxy = (*self->proxy)->ice_fixed(connection); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self))); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* proxyIceGetConnection(ProxyObject* self) { assert(self->proxy); @@ -2664,10 +2757,16 @@ static PyMethodDef ProxyMethods[] = PyDoc_STR(STRCAST("ice_isBatchDatagram() -> bool")) }, { STRCAST("ice_compress"), reinterpret_cast<PyCFunction>(proxyIceCompress), METH_VARARGS, PyDoc_STR(STRCAST("ice_compress(bool) -> Ice.ObjectPrx")) }, + { STRCAST("ice_getCompress"), reinterpret_cast<PyCFunction>(proxyIceGetCompress), METH_VARARGS, + PyDoc_STR(STRCAST("ice_getCompress() -> bool")) }, { STRCAST("ice_timeout"), reinterpret_cast<PyCFunction>(proxyIceTimeout), METH_VARARGS, PyDoc_STR(STRCAST("ice_timeout(int) -> Ice.ObjectPrx")) }, + { STRCAST("ice_getTimeout"), reinterpret_cast<PyCFunction>(proxyIceGetTimeout), METH_VARARGS, + PyDoc_STR(STRCAST("ice_getTimeout() -> int")) }, { STRCAST("ice_connectionId"), reinterpret_cast<PyCFunction>(proxyIceConnectionId), METH_VARARGS, PyDoc_STR(STRCAST("ice_connectionId(string) -> Ice.ObjectPrx")) }, + { STRCAST("ice_fixed"), reinterpret_cast<PyCFunction>(proxyIceFixed), METH_VARARGS, + PyDoc_STR(STRCAST("ice_fixed(Ice.Connection) -> 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), |