summaryrefslogtreecommitdiff
path: root/python/modules/IcePy
diff options
context:
space:
mode:
Diffstat (limited to 'python/modules/IcePy')
-rw-r--r--python/modules/IcePy/Endpoint.cpp24
-rw-r--r--python/modules/IcePy/Endpoint.h2
-rw-r--r--python/modules/IcePy/ObjectAdapter.cpp105
-rw-r--r--python/modules/IcePy/Proxy.cpp17
4 files changed, 102 insertions, 46 deletions
diff --git a/python/modules/IcePy/Endpoint.cpp b/python/modules/IcePy/Endpoint.cpp
index 4482c759d47..f2285f381ba 100644
--- a/python/modules/IcePy/Endpoint.cpp
+++ b/python/modules/IcePy/Endpoint.cpp
@@ -252,3 +252,27 @@ IcePy::createEndpoint(const Ice::EndpointPtr& endpoint)
obj->endpoint = new Ice::EndpointPtr(endpoint);
return (PyObject*)obj;
}
+
+bool
+IcePy::toEndpointSeq(PyObject* endpoints, Ice::EndpointSeq& seq)
+{
+ Py_ssize_t sz = PySequence_Fast_GET_SIZE(endpoints);
+ for(Py_ssize_t i = 0; i < sz; ++i)
+ {
+ 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 false;
+ }
+ Ice::EndpointPtr endp = getEndpoint(p);
+ if(!endp)
+ {
+ return false;
+ }
+ seq.push_back(endp);
+ }
+
+ return true;
+}
diff --git a/python/modules/IcePy/Endpoint.h b/python/modules/IcePy/Endpoint.h
index 88f7db88ea4..fdd15e2e7e7 100644
--- a/python/modules/IcePy/Endpoint.h
+++ b/python/modules/IcePy/Endpoint.h
@@ -23,6 +23,8 @@ bool initEndpoint(PyObject*);
PyObject* createEndpoint(const Ice::EndpointPtr&);
Ice::EndpointPtr getEndpoint(PyObject*);
+bool toEndpointSeq(PyObject*, Ice::EndpointSeq&);
+
}
#endif
diff --git a/python/modules/IcePy/ObjectAdapter.cpp b/python/modules/IcePy/ObjectAdapter.cpp
index d2718b1ca50..336df8f0be7 100644
--- a/python/modules/IcePy/ObjectAdapter.cpp
+++ b/python/modules/IcePy/ObjectAdapter.cpp
@@ -563,7 +563,7 @@ adapterWaitForDeactivate(ObjectAdapterObject* self, PyObject* args)
self->deactivateThread = new AdapterInvokeThreadPtr(t);
t->start();
}
-
+
while(!self->deactivated)
{
bool done;
@@ -571,7 +571,7 @@ adapterWaitForDeactivate(ObjectAdapterObject* self, PyObject* args)
AllowThreads allowThreads; // Release Python's global interpreter lock during blocking calls.
done = (*self->deactivateMonitor).timedWait(IceUtil::Time::milliSeconds(timeout));
}
-
+
if(!done)
{
PyRETURN_FALSE;
@@ -1541,8 +1541,42 @@ adapterGetLocator(ObjectAdapterObject* self)
PyObject* locatorProxyType = lookupType("Ice.LocatorPrx");
assert(locatorProxyType);
return createProxy(locator, (*self->adapter)->getCommunicator(), locatorProxyType);
-}
+}
+
+#ifdef WIN32
+extern "C"
+#endif
+static PyObject*
+adapterGetEndpoints(ObjectAdapterObject* self)
+{
+ assert(self->adapter);
+
+ Ice::EndpointSeq endpoints;
+ try
+ {
+ endpoints = (*self->adapter)->getEndpoints();
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return 0;
+ }
+ int count = static_cast<int>(endpoints.size());
+ PyObjectHandle result = PyTuple_New(count);
+ int i = 0;
+ for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p, ++i)
+ {
+ PyObjectHandle endp = createEndpoint(*p);
+ if(!endp.get())
+ {
+ return 0;
+ }
+ PyTuple_SET_ITEM(result.get(), i, endp.release()); // PyTuple_SET_ITEM steals a reference.
+ }
+
+ return result.release();
+}
#ifdef WIN32
extern "C"
@@ -1570,20 +1604,20 @@ adapterRefreshPublishedEndpoints(ObjectAdapterObject* self)
extern "C"
#endif
static PyObject*
-adapterGetEndpoints(ObjectAdapterObject* self)
+adapterGetPublishedEndpoints(ObjectAdapterObject* self)
{
assert(self->adapter);
Ice::EndpointSeq endpoints;
try
{
- endpoints = (*self->adapter)->getEndpoints();
+ endpoints = (*self->adapter)->getPublishedEndpoints();
}
catch(const Ice::Exception& ex)
{
setPythonException(ex);
return 0;
- }
+ }
int count = static_cast<int>(endpoints.size());
PyObjectHandle result = PyTuple_New(count);
@@ -1603,39 +1637,46 @@ adapterGetEndpoints(ObjectAdapterObject* self)
#ifdef WIN32
extern "C"
-#endif
+#endif
static PyObject*
-adapterGetPublishedEndpoints(ObjectAdapterObject* self)
+adapterSetPublishedEndpoints(ObjectAdapterObject* self, PyObject* args)
{
assert(self->adapter);
-
- Ice::EndpointSeq endpoints;
- try
- {
- endpoints = (*self->adapter)->getPublishedEndpoints();
- }
- catch(const Ice::Exception& ex)
- {
- setPythonException(ex);
+
+ PyObject* endpoints;
+ if(!PyArg_ParseTuple(args, STRCAST("O"), &endpoints))
+ {
return 0;
}
- int count = static_cast<int>(endpoints.size());
- PyObjectHandle result = PyTuple_New(count);
- int i = 0;
- for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p, ++i)
+ if(!PyTuple_Check(endpoints) && !PyList_Check(endpoints))
{
- PyObjectHandle endp = createEndpoint(*p);
- if(!endp.get())
- {
- return 0;
- }
- PyTuple_SET_ITEM(result.get(), i, endp.release()); // PyTuple_SET_ITEM steals a reference.
+ PyErr_Format(PyExc_ValueError, STRCAST("argument must be a tuple or list"));
+ return 0;
}
- return result.release();
+ Ice::EndpointSeq seq;
+ if(!toEndpointSeq(endpoints, seq))
+ {
+ return 0;
+ }
+
+ try
+ {
+ AllowThreads allowThreads; // Release Python's global interpreter lock during blocking calls.
+ (*self->adapter)->setPublishedEndpoints(seq);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return 0;
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
}
+
static PyMethodDef AdapterMethods[] =
{
{ STRCAST("getName"), reinterpret_cast<PyCFunction>(adapterGetName), METH_NOARGS,
@@ -1699,13 +1740,15 @@ static PyMethodDef AdapterMethods[] =
{ STRCAST("setLocator"), reinterpret_cast<PyCFunction>(adapterSetLocator), METH_VARARGS,
PyDoc_STR(STRCAST("setLocator(proxy) -> None")) },
{ STRCAST("getLocator"), reinterpret_cast<PyCFunction>(adapterGetLocator), METH_NOARGS,
- PyDoc_STR(STRCAST("getLocator() -> Ice.LocatorPrx")) },
- { STRCAST("refreshPublishedEndpoints"), reinterpret_cast<PyCFunction>(adapterRefreshPublishedEndpoints), METH_NOARGS,
- PyDoc_STR(STRCAST("refreshPublishedEndpoints() -> None")) },
+ PyDoc_STR(STRCAST("getLocator() -> Ice.LocatorPrx")) },
{ STRCAST("getEndpoints"), reinterpret_cast<PyCFunction>(adapterGetEndpoints), METH_NOARGS,
PyDoc_STR(STRCAST("getEndpoints() -> None")) },
+ { STRCAST("refreshPublishedEndpoints"), reinterpret_cast<PyCFunction>(adapterRefreshPublishedEndpoints), METH_NOARGS,
+ PyDoc_STR(STRCAST("refreshPublishedEndpoints() -> None")) },
{ STRCAST("getPublishedEndpoints"), reinterpret_cast<PyCFunction>(adapterGetPublishedEndpoints), METH_NOARGS,
PyDoc_STR(STRCAST("getPublishedEndpoints() -> None")) },
+ { STRCAST("setPublishedEndpoints"), reinterpret_cast<PyCFunction>(adapterSetPublishedEndpoints), METH_VARARGS,
+ PyDoc_STR(STRCAST("setPublishedEndpoints(endpoints) -> None")) },
{ 0, 0 } /* sentinel */
};
diff --git a/python/modules/IcePy/Proxy.cpp b/python/modules/IcePy/Proxy.cpp
index a001f5047a2..a9e22e5c5e9 100644
--- a/python/modules/IcePy/Proxy.cpp
+++ b/python/modules/IcePy/Proxy.cpp
@@ -795,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;