summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------gnuradio0
-rw-r--r--lib/CMakeLists.txt2
-rw-r--r--python/gras/GRAS_Block.i60
-rw-r--r--tests/block_test.py35
4 files changed, 83 insertions, 14 deletions
diff --git a/gnuradio b/gnuradio
-Subproject 06d587559fbb7bbaea0167535f3cde1bc13a355
+Subproject ff90bae8a04dc7b6375d7f9301061d1a1e98d61
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 5987d46..0657f28 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -58,7 +58,7 @@ list(APPEND GRAS_SOURCES
########################################################################
# Build library
########################################################################
-add_library(gras STATIC ${GRAS_SOURCES})
+add_library(gras SHARED ${GRAS_SOURCES})
target_link_libraries(gras ${GRAS_LIBRARIES})
install(TARGETS gras
diff --git a/python/gras/GRAS_Block.i b/python/gras/GRAS_Block.i
index ccd3963..ddbc69a 100644
--- a/python/gras/GRAS_Block.i
+++ b/python/gras/GRAS_Block.i
@@ -17,21 +17,49 @@
#define GRAS_API
%module(directors="1") GRAS_Block
+%feature("director") gras::BlockPython;
+%feature("nodirector") gras::BlockPython::input_buffer_allocator;
+%feature("nodirector") gras::BlockPython::output_buffer_allocator;
+%feature("nodirector") gras::BlockPython::work;
+%feature("nodirector") gras::BlockPython::propagate_tags;
-%feature("director") BlockPython;
+////////////////////////////////////////////////////////////////////////
+// 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());
+ }
+}
+
+%feature("director:except")
+{
+ if ($error != NULL)
+ {
+ throw Swig::DirectorMethodException();
+ }
+}
%{
#include <gras/block.hpp>
+#include <iostream>
%}
-%include <gras/io_signature.i>
%include <gras/element.i>
+%include <gras/io_signature.i>
%include <gras/sbuffer.hpp>
%include <gras/tags.hpp>
%include <gras/block.hpp>
%include <PMC/PMC.i>
-
////////////////////////////////////////////////////////////////////////
// Make a special block with safe overloads
////////////////////////////////////////////////////////////////////////
@@ -47,16 +75,19 @@ struct BlockPython : Block
Block(name)
{
//NOP
+ std::cout << "C++ Block init!!\n";
}
+ virtual ~BlockPython(void){}
+
int work
(
const InputItems &input_items,
const OutputItems &output_items
)
{
- PyGILState_STATE s;
- s = PyGILState_Ensure();
+ std::cout << "C++ call work!!\n";
+ PyGILState_STATE s = PyGILState_Ensure();
int ret = 0;
try
{
@@ -75,10 +106,7 @@ struct BlockPython : Block
(
const InputItems &input_items,
const OutputItems &output_items
- )
- {
- throw std::runtime_error("Error in BlockPython::python_work: SWIG directors issue?");
- }
+ ){}
};
}
@@ -99,6 +127,7 @@ def sig_to_dtype_sig(sig):
class Block(BlockPython):
def __init__(self, name='Block', in_sig=None, out_sig=None):
BlockPython.__init__(self, name)
+ print 'BlockPython.__init__(self, name)'
self.set_input_signature(in_sig)
self.set_output_signature(in_sig)
@@ -115,5 +144,18 @@ class Block(BlockPython):
def python_work(self, input_items, output_items):
print 'python work called'
+ return -1
+
+ def check_topology(self, *args):
+ print 'check top ', args
+ return True
+
+ def start(self):
+ print 'PYTHON START'
+ return True
+
+ def stop(self):
+ print 'PYTHON STOP'
+ return False
%}
diff --git a/tests/block_test.py b/tests/block_test.py
index 020e615..d076f8e 100644
--- a/tests/block_test.py
+++ b/tests/block_test.py
@@ -3,19 +3,46 @@ import unittest
import gras
import numpy
+class NullSource(gras.Block):
+ def __init__(self):
+ gras.Block.__init__(self, 'NullSource')
+ self.set_output_signature([numpy.int32])
+
+ def callback(self, x):
+ print x
+
+class NullSink(gras.Block):
+ def __init__(self):
+ gras.Block.__init__(self, 'NullSink')
+ self.set_input_signature([numpy.int32])
+
+ def callback(self, x):
+ print x
+
class BlockTest(unittest.TestCase):
def test_make_block(self):
- null_src = gras.Block('NullSource')
- null_src.set_output_signature([numpy.int32])
+ null_src = NullSource()
+
+ null_sink = NullSink()
+
+ #null_src.doit(321)
- null_sink = gras.Block('NullSink')
- null_sink.set_input_signature([numpy.int32])
+ #return
tb = gras.TopBlock()
print 'connect...'
tb.connect(null_src, null_sink)
+ print 'run'
+
+ print 'py start'
+ tb.start()
+ import time; time.sleep(1)
+ print 'py stop'
+ tb.stop()
+ print 'py wait'
+ tb.wait()
print 'ok'
tb.disconnect(null_src, null_sink)