summaryrefslogtreecommitdiff
path: root/py/modules
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2005-02-08 22:10:01 +0000
committerMark Spruiell <mes@zeroc.com>2005-02-08 22:10:01 +0000
commitc79a843b280cb8cc9559126b76e4f8b8ee3a651c (patch)
tree5618e1380944dc1fb564f4cc5d67189fd44ee037 /py/modules
parentremoving Slice translation for Glacier (diff)
downloadice-c79a843b280cb8cc9559126b76e4f8b8ee3a651c.tar.bz2
ice-c79a843b280cb8cc9559126b76e4f8b8ee3a651c.tar.xz
ice-c79a843b280cb8cc9559126b76e4f8b8ee3a651c.zip
updating Ice::Connection for bidir
Diffstat (limited to 'py/modules')
-rw-r--r--py/modules/IcePy/.depend2
-rw-r--r--py/modules/IcePy/Connection.cpp94
-rw-r--r--py/modules/IcePy/Current.cpp18
-rw-r--r--py/modules/IcePy/ObjectAdapter.cpp41
-rw-r--r--py/modules/IcePy/ObjectAdapter.h4
5 files changed, 124 insertions, 35 deletions
diff --git a/py/modules/IcePy/.depend b/py/modules/IcePy/.depend
index 014a3957368..f7bb3ab1fee 100644
--- a/py/modules/IcePy/.depend
+++ b/py/modules/IcePy/.depend
@@ -1,5 +1,5 @@
Communicator.o: Communicator.cpp Communicator.h Logger.h ObjectAdapter.h ObjectFactory.h Properties.h Proxy.h Util.h
-Connection.o: Connection.cpp Connection.h Proxy.h Util.h
+Connection.o: Connection.cpp Connection.h ObjectAdapter.h Proxy.h Util.h
Current.o: Current.cpp Current.h Connection.h ObjectAdapter.h Util.h
Init.o: Init.cpp Communicator.h Connection.h Current.h Logger.h ObjectAdapter.h Operation.h Properties.h Proxy.h Slice.h Types.h Util.h
Logger.o: Logger.cpp Logger.h Util.h
diff --git a/py/modules/IcePy/Connection.cpp b/py/modules/IcePy/Connection.cpp
index 17ba5672a9e..a6fc415b761 100644
--- a/py/modules/IcePy/Connection.cpp
+++ b/py/modules/IcePy/Connection.cpp
@@ -11,6 +11,7 @@
# include <IceUtil/Config.h>
#endif
#include <Connection.h>
+#include <ObjectAdapter.h>
#include <Proxy.h>
#include <Util.h>
#include <Ice/Connection.h>
@@ -90,12 +91,27 @@ connectionClose(ConnectionObject* self, PyObject* args)
extern "C"
#endif
static PyObject*
-connectionFlushBatchRequests(ConnectionObject* self)
+connectionCreateProxy(ConnectionObject* self, PyObject* args)
{
+ PyObject* identityType = lookupType("Ice.Identity");
+ PyObject* id;
+ if(!PyArg_ParseTuple(args, "O!", identityType, &id))
+ {
+ return NULL;
+ }
+
+ Ice::Identity ident;
+ if(!getIdentity(id, ident))
+ {
+ return NULL;
+ }
+
assert(self->connection);
+ assert(self->communicator);
+ Ice::ObjectPrx proxy;
try
{
- (*self->connection)->flushBatchRequests();
+ proxy = (*self->connection)->createProxy(ident);
}
catch(const Ice::Exception& ex)
{
@@ -103,35 +119,74 @@ connectionFlushBatchRequests(ConnectionObject* self)
return NULL;
}
- Py_INCREF(Py_None);
- return Py_None;
+ return createProxy(proxy, (*self->communicator));
}
#ifdef WIN32
extern "C"
#endif
static PyObject*
-connectionCreateProxy(ConnectionObject* self, PyObject* args)
+connectionSetAdapter(ConnectionObject* self, PyObject* args)
{
- PyObject* identityType = lookupType("Ice.Identity");
- PyObject* id;
- if(!PyArg_ParseTuple(args, "O!", identityType, &id))
+ PyObject* adapterType = lookupType("Ice.ObjectAdapter");
+ PyObject* adapter;
+ if(!PyArg_ParseTuple(args, "O!", adapterType, &adapter))
{
- return NULL;
+ return NULL;
}
- Ice::Identity ident;
- if(!getIdentity(id, ident))
+ Ice::ObjectAdapterPtr oa = unwrapObjectAdapter(adapter);
+ assert(oa);
+
+ assert(self->connection);
+ assert(self->communicator);
+ try
{
- return NULL;
+ (*self->connection)->setAdapter(oa);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return NULL;
}
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+#ifdef WIN32
+extern "C"
+#endif
+static PyObject*
+connectionGetAdapter(ConnectionObject* self)
+{
+ Ice::ObjectAdapterPtr adapter;
+
assert(self->connection);
assert(self->communicator);
- Ice::ObjectPrx proxy;
try
{
- proxy = (*self->connection)->createProxy(ident);
+ adapter = (*self->connection)->getAdapter();
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return NULL;
+ }
+
+ return wrapObjectAdapter(adapter);
+}
+
+#ifdef WIN32
+extern "C"
+#endif
+static PyObject*
+connectionFlushBatchRequests(ConnectionObject* self)
+{
+ assert(self->connection);
+ try
+ {
+ (*self->connection)->flushBatchRequests();
}
catch(const Ice::Exception& ex)
{
@@ -139,7 +194,8 @@ connectionCreateProxy(ConnectionObject* self, PyObject* args)
return NULL;
}
- return createProxy(proxy, (*self->communicator));
+ Py_INCREF(Py_None);
+ return Py_None;
}
#ifdef WIN32
@@ -209,10 +265,14 @@ static PyMethodDef ConnectionMethods[] =
{
{ "close", (PyCFunction)connectionClose, METH_VARARGS,
PyDoc_STR("close(bool) -> None") },
- { "flushBatchRequests", (PyCFunction)connectionFlushBatchRequests, METH_NOARGS,
- PyDoc_STR("flushBatchRequests() -> None") },
{ "createProxy", (PyCFunction)connectionCreateProxy, METH_VARARGS,
PyDoc_STR("createProxy(Ice.Identity) -> Ice.ObjectPrx") },
+ { "setAdapter", (PyCFunction)connectionSetAdapter, METH_VARARGS,
+ PyDoc_STR("setAdapter(Ice.ObjectAdapter) -> None") },
+ { "getAdapter", (PyCFunction)connectionGetAdapter, METH_NOARGS,
+ PyDoc_STR("getAdapter() -> Ice.ObjectAdapter") },
+ { "flushBatchRequests", (PyCFunction)connectionFlushBatchRequests, METH_NOARGS,
+ PyDoc_STR("flushBatchRequests() -> None") },
{ "type", (PyCFunction)connectionType, METH_NOARGS,
PyDoc_STR("type() -> string") },
{ "timeout", (PyCFunction)connectionTimeout, METH_NOARGS,
diff --git a/py/modules/IcePy/Current.cpp b/py/modules/IcePy/Current.cpp
index 8fa0b93add8..3b59c42e278 100644
--- a/py/modules/IcePy/Current.cpp
+++ b/py/modules/IcePy/Current.cpp
@@ -111,23 +111,7 @@ currentGetter(CurrentObject* self, void* closure)
{
if(self->adapter == NULL)
{
- //
- // Create an Ice.ObjectAdapter wrapper for IcePy.ObjectAdapter.
- //
- PyObjectHandle adapterI = createObjectAdapter(self->current->adapter);
- if(adapterI.get() == NULL)
- {
- return NULL;
- }
- PyObject* wrapper = lookupType("Ice.ObjectAdapterI");
- assert(wrapper != NULL);
- PyObjectHandle args = PyTuple_New(1);
- if(args.get() == NULL)
- {
- return NULL;
- }
- PyTuple_SET_ITEM(args.get(), 0, adapterI.release());
- self->adapter = PyObject_Call(wrapper, args.get(), NULL);
+ self->adapter = wrapObjectAdapter(self->current->adapter);
if(self->adapter == NULL)
{
return NULL;
diff --git a/py/modules/IcePy/ObjectAdapter.cpp b/py/modules/IcePy/ObjectAdapter.cpp
index 4c5477d7919..c1299178cd6 100644
--- a/py/modules/IcePy/ObjectAdapter.cpp
+++ b/py/modules/IcePy/ObjectAdapter.cpp
@@ -1431,3 +1431,44 @@ IcePy::createObjectAdapter(const Ice::ObjectAdapterPtr& adapter)
}
return (PyObject*)obj;
}
+
+Ice::ObjectAdapterPtr
+IcePy::getObjectAdapter(PyObject* obj)
+{
+ assert(PyObject_IsInstance(obj, (PyObject*)&ObjectAdapterType));
+ ObjectAdapterObject* oaobj = (ObjectAdapterObject*)obj;
+ return *oaobj->adapter;
+}
+
+PyObject*
+IcePy::wrapObjectAdapter(const Ice::ObjectAdapterPtr& adapter)
+{
+ //
+ // Create an Ice.ObjectAdapter wrapper for IcePy.ObjectAdapter.
+ //
+ PyObjectHandle adapterI = createObjectAdapter(adapter);
+ if(adapterI.get() == NULL)
+ {
+ return NULL;
+ }
+ PyObject* wrapperType = lookupType("Ice.ObjectAdapterI");
+ assert(wrapperType != NULL);
+ PyObjectHandle args = PyTuple_New(1);
+ if(args.get() == NULL)
+ {
+ return NULL;
+ }
+ PyTuple_SET_ITEM(args.get(), 0, adapterI.release());
+ return PyObject_Call(wrapperType, args.get(), NULL);
+}
+
+Ice::ObjectAdapterPtr
+IcePy::unwrapObjectAdapter(PyObject* obj)
+{
+ PyObject* wrapperType = lookupType("Ice.ObjectAdapterI");
+ assert(wrapperType != NULL);
+ assert(PyObject_IsInstance(obj, wrapperType));
+ PyObjectHandle impl = PyObject_GetAttrString(obj, "_impl");
+ assert(impl.get() != NULL);
+ return getObjectAdapter(impl.get());
+}
diff --git a/py/modules/IcePy/ObjectAdapter.h b/py/modules/IcePy/ObjectAdapter.h
index 266c615504e..7d191580832 100644
--- a/py/modules/IcePy/ObjectAdapter.h
+++ b/py/modules/IcePy/ObjectAdapter.h
@@ -21,6 +21,10 @@ extern PyTypeObject ObjectAdapterType;
bool initObjectAdapter(PyObject*);
PyObject* createObjectAdapter(const Ice::ObjectAdapterPtr&);
+Ice::ObjectAdapterPtr getObjectAdapter(PyObject*);
+
+PyObject* wrapObjectAdapter(const Ice::ObjectAdapterPtr&);
+Ice::ObjectAdapterPtr unwrapObjectAdapter(PyObject*);
}