summaryrefslogtreecommitdiff
path: root/py/modules/IcePy/Util.h
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-09-20 19:31:14 +0000
committerMark Spruiell <mes@zeroc.com>2004-09-20 19:31:14 +0000
commit482ec157c69410327b5d4dfad44861a07e141aa5 (patch)
treec3d3bd12b088996c60622382e6ab925f55bdd8c7 /py/modules/IcePy/Util.h
parentbug fix - adapter should be wrapped (diff)
downloadice-482ec157c69410327b5d4dfad44861a07e141aa5.tar.bz2
ice-482ec157c69410327b5d4dfad44861a07e141aa5.tar.xz
ice-482ec157c69410327b5d4dfad44861a07e141aa5.zip
use threads to allow signal handling
Diffstat (limited to 'py/modules/IcePy/Util.h')
-rw-r--r--py/modules/IcePy/Util.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/py/modules/IcePy/Util.h b/py/modules/IcePy/Util.h
index 0cab651227b..f49a521fd5c 100644
--- a/py/modules/IcePy/Util.h
+++ b/py/modules/IcePy/Util.h
@@ -14,6 +14,9 @@
#include <Ice/BuiltinSequences.h>
#include <Ice/Current.h>
#include <Ice/Exception.h>
+#include <IceUtil/Thread.h>
+#include <IceUtil/Monitor.h>
+#include <IceUtil/Mutex.h>
namespace IcePy
{
@@ -139,6 +142,55 @@ bool setIdentity(PyObject*, const Ice::Identity&);
//
bool getIdentity(PyObject*, Ice::Identity&);
+//
+// This class invokes a member function in a separate thread.
+//
+template<typename T>
+class InvokeThread : public IceUtil::Thread
+{
+public:
+
+ InvokeThread(const IceInternal::Handle<T>& target, void (T::*func)(void),
+ IceUtil::Monitor<IceUtil::Mutex>& monitor, bool& done) :
+ _target(target), _func(func), _monitor(monitor), _done(done), _ex(0)
+ {
+ }
+
+ ~InvokeThread()
+ {
+ delete _ex;
+ }
+
+ virtual void run()
+ {
+ try
+ {
+ (_target.get() ->* _func)();
+ }
+ catch(const Ice::Exception& ex)
+ {
+ _ex = ex.ice_clone();
+ }
+
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_monitor);
+ _done = true;
+ _monitor.notify();
+ }
+
+ Ice::Exception* getException() const
+ {
+ return _ex;
+ }
+
+private:
+
+ IceInternal::Handle<T> _target;
+ void (T::*_func)(void);
+ IceUtil::Monitor<IceUtil::Mutex>& _monitor;
+ bool& _done;
+ Ice::Exception* _ex;
+};
+
}
extern "C" PyObject* IcePy_identityToString(PyObject*, PyObject*);