summaryrefslogtreecommitdiff
path: root/python/modules/IcePy/Connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'python/modules/IcePy/Connection.cpp')
-rw-r--r--python/modules/IcePy/Connection.cpp29
1 files changed, 29 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;
+ }
+}