From 0192ae4c125ec66696b044a6e64bed5708977c31 Mon Sep 17 00:00:00 2001
From: J Robert Ray <jrray@imageworks.com>
Date: Wed, 3 Jul 2013 10:49:53 -0700
Subject: [PATCH] Support custom Ice::Dispatchers in Python (sort of).

This is a very thin shim to expose the InitializationData::dispatcher
member, but not a way to implement an Ice::Dispatcher in Python.

Extend the wrapped Ice.InitializationData to check for a 'dispatcher'
attribute. In Python, the user is to pass in a PyCObject-wrapped
Ice::Dispatcher*.

The custom Ice::Dispatcher must still be implemented in C++, and also
exposed to Python in some way.
---
 py/modules/IcePy/Communicator.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/py/modules/IcePy/Communicator.cpp b/py/modules/IcePy/Communicator.cpp
index 43d2e73..9d19221 100644
--- a/py/modules/IcePy/Communicator.cpp
+++ b/py/modules/IcePy/Communicator.cpp
@@ -145,6 +145,7 @@ communicatorInit(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
         PyObjectHandle properties = PyObject_GetAttrString(initData, STRCAST("properties"));
         PyObjectHandle logger = PyObject_GetAttrString(initData, STRCAST("logger"));
         PyObjectHandle threadHook = PyObject_GetAttrString(initData, STRCAST("threadHook"));
+        PyObjectHandle dispatcher = PyObject_GetAttrString(initData, STRCAST("dispatcher"));
         PyErr_Clear(); // PyObject_GetAttrString sets an error on failure.
 
         if(properties.get() && properties.get() != Py_None)
@@ -166,6 +167,16 @@ communicatorInit(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
         {
             data.threadHook = new ThreadHook(threadHook.get());
         }
+
+        if(dispatcher.get() && dispatcher.get() != Py_None)
+        {
+            if (!PyCObject_Check(dispatcher.get())) {
+                PyErr_Format(PyExc_ValueError, STRCAST("Ice.InitializationData dispatcher must be a PyCObject-wrapped Ice::Dispatcher*"));
+                return -1;
+            }
+
+            data.dispatcher = reinterpret_cast<Ice::Dispatcher*>(PyCObject_AsVoidPtr(dispatcher.get()));
+        }
     }
 
     try
-- 
1.8.1.3

