summaryrefslogtreecommitdiff
path: root/python/modules/IcePy/Communicator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'python/modules/IcePy/Communicator.cpp')
-rw-r--r--python/modules/IcePy/Communicator.cpp218
1 files changed, 172 insertions, 46 deletions
diff --git a/python/modules/IcePy/Communicator.cpp b/python/modules/IcePy/Communicator.cpp
index eafa723a57c..63d19e7634d 100644
--- a/python/modules/IcePy/Communicator.cpp
+++ b/python/modules/IcePy/Communicator.cpp
@@ -16,7 +16,6 @@
#include <ImplicitContext.h>
#include <Logger.h>
#include <ObjectAdapter.h>
-#include <ObjectFactory.h>
#include <Operation.h>
#include <Properties.h>
#include <PropertiesAdmin.h>
@@ -24,6 +23,8 @@
#include <Thread.h>
#include <Types.h>
#include <Util.h>
+#include <ValueFactoryManager.h>
+#include <Ice/ValueFactory.h>
#include <Ice/Initialize.h>
#include <Ice/CommunicatorAsync.h>
#include <Ice/LocalException.h>
@@ -141,12 +142,14 @@ communicatorInit(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
bool hasArgs = argList != 0;
Ice::InitializationData data;
+
if(initData)
{
PyObjectHandle properties = PyObject_GetAttrString(initData, STRCAST("properties"));
PyObjectHandle logger = PyObject_GetAttrString(initData, STRCAST("logger"));
PyObjectHandle threadHook = PyObject_GetAttrString(initData, STRCAST("threadHook"));
PyObjectHandle batchRequestInterceptor = PyObject_GetAttrString(initData, STRCAST("batchRequestInterceptor"));
+
PyErr_Clear(); // PyObject_GetAttrString sets an error on failure.
if(properties.get() && properties.get() != Py_None)
@@ -175,6 +178,11 @@ communicatorInit(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
}
}
+ //
+ // We always supply our own implementation of ValueFactoryManager.
+ //
+ data.valueFactoryManager = new ValueFactoryManager;
+
try
{
if(argList)
@@ -253,8 +261,6 @@ communicatorInit(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
delete[] argv;
self->communicator = new Ice::CommunicatorPtr(communicator);
- ObjectFactoryPtr factory = new ObjectFactory;
- (*self->communicator)->addObjectFactory(factory, "");
CommunicatorMap::iterator p = _communicatorMap.find(communicator);
if(p != _communicatorMap.end())
@@ -301,6 +307,10 @@ static PyObject*
communicatorDestroy(CommunicatorObject* self)
{
assert(self->communicator);
+
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast((*self->communicator)->getValueFactoryManager());
+ assert(vfm);
+
try
{
AllowThreads allowThreads; // Release Python's global interpreter lock to avoid a potential deadlock.
@@ -309,17 +319,25 @@ communicatorDestroy(CommunicatorObject* self)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return 0;
}
+ vfm->destroy();
+
//
// Break cyclic reference between this object and its Python wrapper.
//
Py_XDECREF(self->wrapper);
self->wrapper = 0;
- Py_INCREF(Py_None);
- return Py_None;
+ if(PyErr_Occurred())
+ {
+ return 0;
+ }
+ else
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
}
#ifdef WIN32
@@ -683,13 +701,24 @@ communicatorIdentityToString(CommunicatorObject* self, PyObject* args)
extern "C"
#endif
static PyObject*
-communicatorFlushBatchRequests(CommunicatorObject* self)
+communicatorFlushBatchRequests(CommunicatorObject* self, PyObject* args)
{
+ PyObject* compressBatchType = lookupType("Ice.CompressBatch");
+ PyObject* compressBatch;
+ if(!PyArg_ParseTuple(args, STRCAST("O!"), compressBatchType, &compressBatch))
+ {
+ return 0;
+ }
+
+ PyObjectHandle v = PyObject_GetAttrString(compressBatch, STRCAST("_value"));
+ assert(v.get());
+ Ice::CompressBatch cb = static_cast<Ice::CompressBatch>(PyLong_AsLong(v.get()));
+
assert(self->communicator);
try
{
AllowThreads allowThreads; // Release Python's global interpreter lock to avoid a potential deadlock.
- (*self->communicator)->flushBatchRequests();
+ (*self->communicator)->flushBatchRequests(cb);
}
catch(const Ice::Exception& ex)
{
@@ -705,23 +734,88 @@ communicatorFlushBatchRequests(CommunicatorObject* self)
extern "C"
#endif
static PyObject*
+communicatorFlushBatchRequestsAsync(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
+{
+ PyObject* compressBatchType = lookupType("Ice.CompressBatch");
+ PyObject* compressBatch;
+ if(!PyArg_ParseTuple(args, STRCAST("O!"), compressBatchType, &compressBatch))
+ {
+ return 0;
+ }
+
+ PyObjectHandle v = PyObject_GetAttrString(compressBatch, STRCAST("_value"));
+ assert(v.get());
+ Ice::CompressBatch cb = static_cast<Ice::CompressBatch>(PyLong_AsLong(v.get()));
+
+ assert(self->communicator);
+ const string op = "flushBatchRequests";
+
+ FlushAsyncCallbackPtr d = new FlushAsyncCallback(op);
+ Ice::Callback_Communicator_flushBatchRequestsPtr callback =
+ Ice::newCallback_Communicator_flushBatchRequests(d, &FlushAsyncCallback::exception, &FlushAsyncCallback::sent);
+
+ Ice::AsyncResultPtr result;
+
+ try
+ {
+ AllowThreads allowThreads; // Release Python's global interpreter lock during remote invocations.
+
+ result = (*self->communicator)->begin_flushBatchRequests(cb, callback);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return 0;
+ }
+
+ PyObjectHandle asyncResultObj = createAsyncResult(result, 0, 0, self->wrapper);
+ 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*
communicatorBeginFlushBatchRequests(CommunicatorObject* self, PyObject* args, PyObject* kwds)
{
assert(self->communicator);
static char* argNames[] =
{
+ const_cast<char*>("compress"),
const_cast<char*>("_ex"),
const_cast<char*>("_sent"),
0
};
+ PyObject* compressBatch;
PyObject* ex = Py_None;
PyObject* sent = Py_None;
- if(!PyArg_ParseTupleAndKeywords(args, kwds, STRCAST("|OO"), argNames, &ex, &sent))
+ if(!PyArg_ParseTupleAndKeywords(args, kwds, STRCAST("O|OO"), argNames, &compressBatch, &ex, &sent))
+ {
+ return 0;
+ }
+
+ PyObject* compressBatchType = lookupType("Ice.CompressBatch");
+ if(!PyObject_IsInstance(compressBatch, reinterpret_cast<PyObject*>(compressBatchType)))
{
return 0;
}
+ PyObjectHandle v = PyObject_GetAttrString(compressBatch, STRCAST("_value"));
+ assert(v.get());
+ Ice::CompressBatch cb = static_cast<Ice::CompressBatch>(PyLong_AsLong(v.get()));
+
if(ex == Py_None)
{
ex = 0;
@@ -738,11 +832,11 @@ communicatorBeginFlushBatchRequests(CommunicatorObject* self, PyObject* args, Py
return 0;
}
- Ice::Callback_Communicator_flushBatchRequestsPtr cb;
+ Ice::Callback_Communicator_flushBatchRequestsPtr callback;
if(ex || sent)
{
FlushCallbackPtr d = new FlushCallback(ex, sent, "flushBatchRequests");
- cb = Ice::newCallback_Communicator_flushBatchRequests(d, &FlushCallback::exception, &FlushCallback::sent);
+ callback = Ice::newCallback_Communicator_flushBatchRequests(d, &FlushCallback::exception, &FlushCallback::sent);
}
Ice::AsyncResultPtr result;
@@ -750,13 +844,13 @@ communicatorBeginFlushBatchRequests(CommunicatorObject* self, PyObject* args, Py
{
AllowThreads allowThreads; // Release Python's global interpreter lock during remote invocations.
- if(cb)
+ if(callback)
{
- result = (*self->communicator)->begin_flushBatchRequests(cb);
+ result = (*self->communicator)->begin_flushBatchRequests(cb, callback);
}
else
{
- result = (*self->communicator)->begin_flushBatchRequests();
+ result = (*self->communicator)->begin_flushBatchRequests(cb);
}
}
catch(const Ice::Exception& ex)
@@ -1168,12 +1262,16 @@ extern "C"
static PyObject*
communicatorAddObjectFactory(CommunicatorObject* self, PyObject* args)
{
- PyObject* factoryType = lookupType("Ice.ObjectFactory");
- assert(factoryType);
+ PyObject* objectFactoryType = lookupType("Ice.ObjectFactory");
+ assert(objectFactoryType);
+ PyObject* valueFactoryType = lookupType("types.FunctionType");
+ assert(valueFactoryType);
- PyObject* factory;
+ PyObject* objectFactory;
PyObject* strObj;
- if(!PyArg_ParseTuple(args, STRCAST("O!O"), factoryType, &factory, &strObj))
+ PyObject* valueFactory;
+ if(!PyArg_ParseTuple(args, STRCAST("O!OO!"), objectFactoryType, &objectFactory, &strObj, valueFactoryType,
+ &valueFactory))
{
return 0;
}
@@ -1184,11 +1282,12 @@ communicatorAddObjectFactory(CommunicatorObject* self, PyObject* args)
return 0;
}
- ObjectFactoryPtr pof;
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast((*self->communicator)->getValueFactoryManager());
+ assert(vfm);
+
try
{
- pof = ObjectFactoryPtr::dynamicCast((*self->communicator)->findObjectFactory(""));
- assert(pof);
+ vfm->add(valueFactory, objectFactory, id);
}
catch(const Ice::Exception& ex)
{
@@ -1197,11 +1296,6 @@ communicatorAddObjectFactory(CommunicatorObject* self, PyObject* args)
}
- if(!pof->add(factory, id))
- {
- return 0;
- }
-
Py_INCREF(Py_None);
return Py_None;
}
@@ -1224,19 +1318,21 @@ communicatorFindObjectFactory(CommunicatorObject* self, PyObject* args)
return 0;
}
- ObjectFactoryPtr pof;
- try
- {
- pof = ObjectFactoryPtr::dynamicCast((*self->communicator)->findObjectFactory(""));
- assert(pof);
- }
- catch(const Ice::Exception& ex)
- {
- setPythonException(ex);
- return 0;
- }
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast((*self->communicator)->getValueFactoryManager());
+ assert(vfm);
- return pof->find(id);
+ return vfm->findObjectFactory(id);
+}
+
+#ifdef WIN32
+extern "C"
+#endif
+static PyObject*
+communicatorGetValueFactoryManager(CommunicatorObject* self)
+{
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast((*self->communicator)->getValueFactoryManager());
+
+ return vfm->getObject();
}
#ifdef WIN32
@@ -1570,6 +1666,8 @@ static PyMethodDef CommunicatorMethods[] =
PyDoc_STR(STRCAST("addObjectFactory(factory, id) -> None")) },
{ STRCAST("findObjectFactory"), reinterpret_cast<PyCFunction>(communicatorFindObjectFactory), METH_VARARGS,
PyDoc_STR(STRCAST("findObjectFactory(id) -> Ice.ObjectFactory")) },
+ { STRCAST("getValueFactoryManager"), reinterpret_cast<PyCFunction>(communicatorGetValueFactoryManager), METH_NOARGS,
+ PyDoc_STR(STRCAST("getValueFactoryManager() -> Ice.ValueFactoryManager")) },
{ STRCAST("getImplicitContext"), reinterpret_cast<PyCFunction>(communicatorGetImplicitContext), METH_NOARGS,
PyDoc_STR(STRCAST("getImplicitContext() -> Ice.ImplicitContext")) },
{ STRCAST("getProperties"), reinterpret_cast<PyCFunction>(communicatorGetProperties), METH_NOARGS,
@@ -1584,11 +1682,13 @@ static PyMethodDef CommunicatorMethods[] =
PyDoc_STR(STRCAST("getDefaultLocator() -> proxy")) },
{ STRCAST("setDefaultLocator"), reinterpret_cast<PyCFunction>(communicatorSetDefaultLocator), METH_VARARGS,
PyDoc_STR(STRCAST("setDefaultLocator(proxy) -> None")) },
- { STRCAST("flushBatchRequests"), reinterpret_cast<PyCFunction>(communicatorFlushBatchRequests), METH_NOARGS,
- PyDoc_STR(STRCAST("flushBatchRequests() -> None")) },
+ { STRCAST("flushBatchRequests"), reinterpret_cast<PyCFunction>(communicatorFlushBatchRequests), METH_VARARGS,
+ PyDoc_STR(STRCAST("flushBatchRequests(compress) -> None")) },
+ { STRCAST("flushBatchRequestsAsync"), reinterpret_cast<PyCFunction>(communicatorFlushBatchRequestsAsync),
+ METH_VARARGS, PyDoc_STR(STRCAST("flushBatchRequestsAsync(compress) -> Ice.Future")) },
{ STRCAST("begin_flushBatchRequests"), reinterpret_cast<PyCFunction>(communicatorBeginFlushBatchRequests),
METH_VARARGS | METH_KEYWORDS,
- PyDoc_STR(STRCAST("begin_flushBatchRequests([_ex][, _sent]) -> Ice.AsyncResult")) },
+ PyDoc_STR(STRCAST("begin_flushBatchRequests(compress[, _ex][, _sent]) -> Ice.AsyncResult")) },
{ STRCAST("end_flushBatchRequests"), reinterpret_cast<PyCFunction>(communicatorEndFlushBatchRequests),
METH_VARARGS, PyDoc_STR(STRCAST("end_flushBatchRequests(Ice.AsyncResult) -> None")) },
{ STRCAST("createAdmin"), reinterpret_cast<PyCFunction>(communicatorCreateAdmin), METH_VARARGS,
@@ -1712,25 +1812,51 @@ IcePy::getCommunicatorWrapper(const Ice::CommunicatorPtr& communicator)
CommunicatorMap::iterator p = _communicatorMap.find(communicator);
assert(p != _communicatorMap.end());
CommunicatorObject* obj = reinterpret_cast<CommunicatorObject*>(p->second);
- Py_INCREF(obj->wrapper);
- return obj->wrapper;
+ if(obj->wrapper)
+ {
+ Py_INCREF(obj->wrapper);
+ return obj->wrapper;
+ }
+ else
+ {
+ //
+ // Communicator must have been destroyed already.
+ //
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
}
extern "C"
PyObject*
-IcePy_identityToString(PyObject* /*self*/, PyObject* obj)
+IcePy_identityToString(PyObject* /*self*/, PyObject* args)
{
+ PyObject* identityType = lookupType("Ice.Identity");
+ PyObject* obj;
+ PyObject* mode = 0;
+ if(!PyArg_ParseTuple(args, STRCAST("O!O"), identityType, &obj, &mode))
+ {
+ return 0;
+ }
+
Ice::Identity id;
if(!getIdentity(obj, id))
{
return 0;
}
-
+
+ Ice::ToStringMode toStringMode = Ice::Unicode;
+ if(mode != Py_None && PyObject_HasAttrString(mode, STRCAST("value")))
+ {
+ PyObjectHandle modeValue = PyObject_GetAttrString(mode, STRCAST("value"));
+ toStringMode = static_cast<Ice::ToStringMode>(PyLong_AsLong(modeValue.get()));
+ }
+
string str;
try
{
- str = Ice::identityToString(id);
+ str = identityToString(id, toStringMode);
}
catch(const Ice::Exception& ex)
{