From 485aeea56f4289555d4b94b2c779015de185a5f0 Mon Sep 17 00:00:00 2001
From: Josh Blum
Date: Wed, 31 Oct 2012 23:09:01 -0700
Subject: swig-ing and test for thread pool
---
python/gras/CMakeLists.txt | 5 +-
python/gras/GRASElements.i | 137 ------------------------------------------
python/gras/GRAS_HierBlock.i | 137 ++++++++++++++++++++++++++++++++++++++++++
python/gras/GRAS_ThreadPool.i | 25 ++++++++
python/gras/__init__.py | 3 +-
5 files changed, 167 insertions(+), 140 deletions(-)
delete mode 100644 python/gras/GRASElements.i
create mode 100644 python/gras/GRAS_HierBlock.i
create mode 100644 python/gras/GRAS_ThreadPool.i
(limited to 'python')
diff --git a/python/gras/CMakeLists.txt b/python/gras/CMakeLists.txt
index 5386096..61e1ba5 100644
--- a/python/gras/CMakeLists.txt
+++ b/python/gras/CMakeLists.txt
@@ -17,9 +17,10 @@ list(APPEND GR_SWIG_INCLUDE_DIRS ${GRAS_INCLUDE_DIRS})
list(APPEND GR_SWIG_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
set(GR_SWIG_LIBRARIES gras)
-GR_SWIG_MAKE(GRASElements GRASElements.i)
+GR_SWIG_MAKE(GRAS_HierBlock GRAS_HierBlock.i)
+GR_SWIG_MAKE(GRAS_ThreadPool GRAS_ThreadPool.i)
GR_SWIG_INSTALL(
- TARGETS GRASElements
+ TARGETS GRAS_HierBlock GRAS_ThreadPool
DESTINATION ${GR_PYTHON_DIR}/gras
COMPONENT ${GRAS_COMP_PYTHON}
)
diff --git a/python/gras/GRASElements.i b/python/gras/GRASElements.i
deleted file mode 100644
index 413ee2a..0000000
--- a/python/gras/GRASElements.i
+++ /dev/null
@@ -1,137 +0,0 @@
-//
-// Copyright 2012 Josh Blum
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with this program. If not, see .
-
-#define GRAS_API
-
-////////////////////////////////////////////////////////////////////////
-// http://www.swig.org/Doc2.0/Library.html#Library_stl_exceptions
-////////////////////////////////////////////////////////////////////////
-%include "exception.i"
-
-%exception
-{
- try
- {
- $action
- }
- catch (const std::exception& e)
- {
- SWIG_exception(SWIG_RuntimeError, e.what());
- }
-}
-
-%{
-#include
-#include
-%}
-
-%include
-%include
-
-////////////////////////////////////////////////////////////////////////
-// pull in hier and top interface
-////////////////////////////////////////////////////////////////////////
-%include
-%include
-
-////////////////////////////////////////////////////////////////////////
-// Make a special top block with python safe unlocking wait
-////////////////////////////////////////////////////////////////////////
-
-%inline %{
-
-namespace gras
-{
-
-struct TopBlockPython : TopBlock
-{
- TopBlockPython(void):
- TopBlock("top")
- {
- //NOP
- }
-
- TopBlockPython(const std::string &name):
- TopBlock(name)
- {
- //NOP
- }
-
- void wait(void)
- {
- PyThreadState *s = PyEval_SaveThread();
- TopBlock::wait();
- PyEval_RestoreThread(s);
- }
-
- bool wait(const double timeout)
- {
- PyThreadState *s = PyEval_SaveThread();
- const bool ret = TopBlock::wait(timeout);
- PyEval_RestoreThread(s);
- return ret;
- }
-};
-}
-
-%}
-
-////////////////////////////////////////////////////////////////////////
-// Remake top block and hier block for multi-arg connnect
-////////////////////////////////////////////////////////////////////////
-%pythoncode %{
-
-def internal_connect__(fcn, obj, *args):
-
- def to_element(obj):
- if isinstance(obj, Element): return obj
- try: return obj.shared_to_element()
- except: raise Exception('cant coerce obj %s to element'%(obj))
-
- if len(args) == 1:
- fcn(obj, to_element(args[0]))
- return
-
- for src, sink in zip(args, args[1:]):
- try: src, src_index = src
- except: src_index = 0
- try: sink, sink_index = sink
- except: sink_index = 0
- fcn(obj, to_element(src), src_index, to_element(sink), sink_index)
-
-class TopBlock(TopBlockPython):
- def __init__(self, *args, **kwargs):
- TopBlockPython.__init__(self, *args, **kwargs)
-
- def connect(self, *args):
- return internal_connect__(TopBlockPython.connect, self, *args)
-
- def disconnect(self, *args):
- return internal_connect__(TopBlockPython.disconnect, self, *args)
-
-HierBlockPython = HierBlock
-
-class HierBlock(HierBlockPython):
- def __init__(self, *args, **kwargs):
- HierBlockPython.__init__(self, *args, **kwargs)
-
- def connect(self, *args):
- return internal_connect__(HierBlock.connect, self, *args)
-
- def disconnect(self, *args):
- return internal_connect__(HierBlock.disconnect, self, *args)
-
-%}
diff --git a/python/gras/GRAS_HierBlock.i b/python/gras/GRAS_HierBlock.i
new file mode 100644
index 0000000..413ee2a
--- /dev/null
+++ b/python/gras/GRAS_HierBlock.i
@@ -0,0 +1,137 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+
+#define GRAS_API
+
+////////////////////////////////////////////////////////////////////////
+// http://www.swig.org/Doc2.0/Library.html#Library_stl_exceptions
+////////////////////////////////////////////////////////////////////////
+%include "exception.i"
+
+%exception
+{
+ try
+ {
+ $action
+ }
+ catch (const std::exception& e)
+ {
+ SWIG_exception(SWIG_RuntimeError, e.what());
+ }
+}
+
+%{
+#include
+#include
+%}
+
+%include
+%include
+
+////////////////////////////////////////////////////////////////////////
+// pull in hier and top interface
+////////////////////////////////////////////////////////////////////////
+%include
+%include
+
+////////////////////////////////////////////////////////////////////////
+// Make a special top block with python safe unlocking wait
+////////////////////////////////////////////////////////////////////////
+
+%inline %{
+
+namespace gras
+{
+
+struct TopBlockPython : TopBlock
+{
+ TopBlockPython(void):
+ TopBlock("top")
+ {
+ //NOP
+ }
+
+ TopBlockPython(const std::string &name):
+ TopBlock(name)
+ {
+ //NOP
+ }
+
+ void wait(void)
+ {
+ PyThreadState *s = PyEval_SaveThread();
+ TopBlock::wait();
+ PyEval_RestoreThread(s);
+ }
+
+ bool wait(const double timeout)
+ {
+ PyThreadState *s = PyEval_SaveThread();
+ const bool ret = TopBlock::wait(timeout);
+ PyEval_RestoreThread(s);
+ return ret;
+ }
+};
+}
+
+%}
+
+////////////////////////////////////////////////////////////////////////
+// Remake top block and hier block for multi-arg connnect
+////////////////////////////////////////////////////////////////////////
+%pythoncode %{
+
+def internal_connect__(fcn, obj, *args):
+
+ def to_element(obj):
+ if isinstance(obj, Element): return obj
+ try: return obj.shared_to_element()
+ except: raise Exception('cant coerce obj %s to element'%(obj))
+
+ if len(args) == 1:
+ fcn(obj, to_element(args[0]))
+ return
+
+ for src, sink in zip(args, args[1:]):
+ try: src, src_index = src
+ except: src_index = 0
+ try: sink, sink_index = sink
+ except: sink_index = 0
+ fcn(obj, to_element(src), src_index, to_element(sink), sink_index)
+
+class TopBlock(TopBlockPython):
+ def __init__(self, *args, **kwargs):
+ TopBlockPython.__init__(self, *args, **kwargs)
+
+ def connect(self, *args):
+ return internal_connect__(TopBlockPython.connect, self, *args)
+
+ def disconnect(self, *args):
+ return internal_connect__(TopBlockPython.disconnect, self, *args)
+
+HierBlockPython = HierBlock
+
+class HierBlock(HierBlockPython):
+ def __init__(self, *args, **kwargs):
+ HierBlockPython.__init__(self, *args, **kwargs)
+
+ def connect(self, *args):
+ return internal_connect__(HierBlock.connect, self, *args)
+
+ def disconnect(self, *args):
+ return internal_connect__(HierBlock.disconnect, self, *args)
+
+%}
diff --git a/python/gras/GRAS_ThreadPool.i b/python/gras/GRAS_ThreadPool.i
new file mode 100644
index 0000000..a50e8a8
--- /dev/null
+++ b/python/gras/GRAS_ThreadPool.i
@@ -0,0 +1,25 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+
+#define GRAS_API
+
+%{
+#include
+%}
+
+%include
+
+%include
diff --git a/python/gras/__init__.py b/python/gras/__init__.py
index 6a836a6..595efeb 100644
--- a/python/gras/__init__.py
+++ b/python/gras/__init__.py
@@ -1 +1,2 @@
-from GRASElements import *
+from GRAS_HierBlock import *
+from GRAS_ThreadPool import *
--
cgit