summaryrefslogtreecommitdiff
path: root/py/modules/IcePy/ObjectAdapter.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2007-09-24 16:48:44 -0700
committerMark Spruiell <mes@zeroc.com>2007-09-24 16:48:44 -0700
commita368e10bfe43a027ed3c2ebe152978ff6126ce97 (patch)
tree583b9f0fa12bce0c8d4aa053d705f12f4ed7d840 /py/modules/IcePy/ObjectAdapter.cpp
parentSquashed commit of the following: (diff)
downloadice-a368e10bfe43a027ed3c2ebe152978ff6126ce97.tar.bz2
ice-a368e10bfe43a027ed3c2ebe152978ff6126ce97.tar.xz
ice-a368e10bfe43a027ed3c2ebe152978ff6126ce97.zip
refactoring operation invocation & dispatch in Python
Diffstat (limited to 'py/modules/IcePy/ObjectAdapter.cpp')
-rw-r--r--py/modules/IcePy/ObjectAdapter.cpp182
1 files changed, 0 insertions, 182 deletions
diff --git a/py/modules/IcePy/ObjectAdapter.cpp b/py/modules/IcePy/ObjectAdapter.cpp
index 28fe39933c4..0416b6a3a89 100644
--- a/py/modules/IcePy/ObjectAdapter.cpp
+++ b/py/modules/IcePy/ObjectAdapter.cpp
@@ -48,78 +48,6 @@ struct ObjectAdapterObject
bool held;
};
-//
-// Encapsulates a Python servant.
-//
-class ServantWrapper : public Ice::BlobjectArrayAsync
-{
-public:
-
- ServantWrapper(PyObject*);
- ~ServantWrapper();
-
- virtual void ice_invoke_async(const Ice::AMD_Array_Object_ice_invokePtr&,
- const pair<const Ice::Byte*, const Ice::Byte*>&,
- const Ice::Current&) = 0;
-
- PyObject* getObject();
-
-protected:
-
- PyObject* _servant;
-};
-typedef IceUtil::Handle<ServantWrapper> ServantWrapperPtr;
-
-class ConcreteServantWrapper : public ServantWrapper
-{
-public:
-
- ConcreteServantWrapper(PyObject*);
-
- virtual void ice_invoke_async(const Ice::AMD_Array_Object_ice_invokePtr&,
- const pair<const Ice::Byte*, const Ice::Byte*>&,
- const Ice::Current&);
-
-private:
-
- typedef map<string, OperationPtr> OperationMap;
- OperationMap _operationMap;
- OperationMap::iterator _lastOp;
-};
-
-class BlobjectServantWrapper : public ServantWrapper
-{
-public:
-
- BlobjectServantWrapper(PyObject*, bool);
-
- virtual void ice_invoke_async(const Ice::AMD_Array_Object_ice_invokePtr&,
- const pair<const Ice::Byte*, const Ice::Byte*>&,
- const Ice::Current&);
-
-private:
-
- const OperationPtr _op;
-};
-
-static ServantWrapperPtr
-createServantWrapper(PyObject* servant)
-{
- ServantWrapperPtr wrapper;
- PyObject* blobjectType = lookupType("Ice.Blobject");
- PyObject* blobjectAsyncType = lookupType("Ice.BlobjectAsync");
- if(PyObject_IsInstance(servant, blobjectType))
- {
- return new BlobjectServantWrapper(servant, false);
- }
- else if(PyObject_IsInstance(servant, blobjectAsyncType))
- {
- return new BlobjectServantWrapper(servant, true);
- }
-
- return new ConcreteServantWrapper(servant);
-}
-
class ServantLocatorWrapper : public Ice::ServantLocator
{
public:
@@ -159,116 +87,6 @@ typedef IceUtil::Handle<ServantLocatorWrapper> ServantLocatorWrapperPtr;
}
//
-// ServantWrapper implementation.
-//
-IcePy::ServantWrapper::ServantWrapper(PyObject* servant) :
- _servant(servant)
-{
- Py_INCREF(_servant);
-}
-
-IcePy::ServantWrapper::~ServantWrapper()
-{
- AdoptThread adoptThread; // Ensure the current thread is able to call into Python.
-
- Py_DECREF(_servant);
-}
-
-PyObject*
-IcePy::ServantWrapper::getObject()
-{
- Py_INCREF(_servant);
- return _servant;
-}
-
-//
-// ConcreteServantWrapper implementation.
-//
-IcePy::ConcreteServantWrapper::ConcreteServantWrapper(PyObject* servant) :
- ServantWrapper(servant), _lastOp(_operationMap.end())
-{
-}
-
-void
-IcePy::ConcreteServantWrapper::ice_invoke_async(const Ice::AMD_Array_Object_ice_invokePtr& cb,
- const pair<const Ice::Byte*, const Ice::Byte*>& inParams,
- const Ice::Current& current)
-{
- AdoptThread adoptThread; // Ensure the current thread is able to call into Python.
-
- try
- {
- //
- // Locate the Operation object. As an optimization we keep a reference
- // to the most recent operation we've dispatched, so check that first.
- //
- OperationPtr op;
- if(_lastOp != _operationMap.end() && _lastOp->first == current.operation)
- {
- op = _lastOp->second;
- }
- else
- {
- //
- // Next check our cache of operations.
- //
- _lastOp = _operationMap.find(current.operation);
- if(_lastOp == _operationMap.end())
- {
- //
- // Look for the Operation object in the servant's type.
- //
- string attrName = "_op_" + current.operation;
- PyObjectHandle h = PyObject_GetAttrString((PyObject*)_servant->ob_type,
- const_cast<char*>(attrName.c_str()));
- if(!h.get())
- {
- Ice::OperationNotExistException ex(__FILE__, __LINE__);
- ex.id = current.id;
- ex.facet = current.facet;
- ex.operation = current.operation;
- throw ex;
- }
-
- op = getOperation(h.get());
- _lastOp = _operationMap.insert(OperationMap::value_type(current.operation, op)).first;
- }
- else
- {
- op = _lastOp->second;
- }
- }
-
- __checkMode(op->mode(), current.mode);
-
- op->dispatch(_servant, cb, inParams, current);
- }
- catch(const Ice::Exception& ex)
- {
- AllowThreads allowThreads; // Release Python's global interpreter lock during blocking calls.
- cb->ice_exception(ex);
- }
-}
-
-//
-// BlobjectServantWrapper implementation.
-//
-IcePy::BlobjectServantWrapper::BlobjectServantWrapper(PyObject* servant, bool async) :
- ServantWrapper(servant),
- _op(getIceInvokeOperation(async))
-{
-}
-
-void
-IcePy::BlobjectServantWrapper::ice_invoke_async(
- const Ice::AMD_Array_Object_ice_invokePtr& cb, const pair<const Ice::Byte*, const Ice::Byte*>& inParams,
- const Ice::Current& current)
-{
- AdoptThread adoptThread; // Ensure the current thread is able to call into Python.
- _op->dispatch(_servant, cb, inParams, current);
-}
-
-//
// ServantLocatorWrapper implementation.
//
IcePy::ServantLocatorWrapper::ServantLocatorWrapper(PyObject* locator) :