summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJosh Blum2012-10-31 21:50:43 -0700
committerJosh Blum2012-10-31 21:50:43 -0700
commit61bd98faa4d10a4791669f4f1c196268a6178a4e (patch)
tree9587a3614ba0ad9213a538b2b3043adb15bbf3f7 /python
parent32f9c796f5b30b7bd802c5f1802a94de2b50ec10 (diff)
downloadsandhi-61bd98faa4d10a4791669f4f1c196268a6178a4e.tar.gz
sandhi-61bd98faa4d10a4791669f4f1c196268a6178a4e.tar.bz2
sandhi-61bd98faa4d10a4791669f4f1c196268a6178a4e.zip
swig work on top and hier
Diffstat (limited to 'python')
-rw-r--r--python/gr_tags.i32
-rw-r--r--python/gras/CMakeLists.txt22
-rw-r--r--python/gras/GRASElements.i (renamed from python/gras.i)120
-rw-r--r--python/gras/__init__.py1
-rw-r--r--python/runtime.i71
5 files changed, 68 insertions, 178 deletions
diff --git a/python/gr_tags.i b/python/gr_tags.i
deleted file mode 100644
index 828d014..0000000
--- a/python/gr_tags.i
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2011 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-%{
-#include <gr_tags.h>
-%}
-
-%include <pmt_swig.i> //for pmt support
-
-%include <gr_tags.h>
-
-//gives support for a vector of tags (get tags in range)
-%include "std_vector.i"
-%template(tags_vector_t) std::vector<gr_tag_t>;
diff --git a/python/gras/CMakeLists.txt b/python/gras/CMakeLists.txt
index a55d09e..cd0c9be 100644
--- a/python/gras/CMakeLists.txt
+++ b/python/gras/CMakeLists.txt
@@ -16,18 +16,18 @@ find_package(Boost) #for headers
list(APPEND GR_SWIG_INCLUDE_DIRS ${GRAS_INCLUDE_DIRS})
list(APPEND GR_SWIG_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
-#GR_SWIG_MAKE(${pmc_swig_module} ${pmc_swig_module}.i)
-#GR_SWIG_INSTALL(
-# TARGETS ${pmc_swig_module}
-# DESTINATION ${GR_PYTHON_DIR}/PMC
-# COMPONENT ${PMC_COMP_PYTHON}
-#)
+GR_SWIG_MAKE(GRASElements GRASElements.i)
+GR_SWIG_INSTALL(
+ TARGETS GRASElements
+ DESTINATION ${GR_PYTHON_DIR}/gras
+ COMPONENT ${GRAS_COMP_PYTHON}
+)
########################################################################
# Install rules
########################################################################
-#GR_PYTHON_INSTALL(
-# FILES __init__.py
-# DESTINATION ${GR_PYTHON_DIR}/PMC
-# COMPONENT ${PMC_COMP_PYTHON}
-#)
+GR_PYTHON_INSTALL(
+ FILES __init__.py
+ DESTINATION ${GR_PYTHON_DIR}/gras
+ COMPONENT ${GRAS_COMP_PYTHON}
+)
diff --git a/python/gras.i b/python/gras/GRASElements.i
index 0fe1ea3..1217ae8 100644
--- a/python/gras.i
+++ b/python/gras/GRASElements.i
@@ -14,83 +14,90 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-%rename(io_signature) gr_make_io_signature;
-%rename(io_signature2) gr_make_io_signature2;
-%rename(io_signature3) gr_make_io_signature3;
-%rename(io_signaturev) gr_make_io_signaturev;
-
-//const size types used by blocks in python
-%constant int sizeof_char = sizeof(char);
-%constant int sizeof_short = sizeof(short);
-%constant int sizeof_int = sizeof(int);
-%constant int sizeof_float = sizeof(float);
-%constant int sizeof_double = sizeof(double);
-%constant int sizeof_gr_complex = sizeof(gr_complex);
+#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 <gras/element.hpp>
+#include <gras/hier_block.hpp>
+#include <gras/top_block.hpp>
+#include <gras/io_signature.hpp>
+
+%}
+
+
+////////////////////////////////////////////////////////////////////////
//helps with funny swig error for io signature
-%ignore gnuradio::IOSignature::operator->();
-%ignore gnuradio::IOSignature::operator->() const;
-
-%ignore gnuradio::Block::input_buffer_allocator;
-%ignore gnuradio::Block::output_buffer_allocator;
-
-%include <gnuradio/thread_pool.hpp>
-%include <gnuradio/element.hpp>
-%include <gnuradio/tags.hpp>
-%include <gnuradio/block.hpp>
-%include <gnuradio/hier_block.hpp>
-%include <gnuradio/top_block.hpp>
-%include <gnuradio/io_signature.hpp>
-%include <gr_io_signature.h>
-%include <gr_block.h>
-%include <gr_hier_block2.h>
-%include <gr_top_block.h>
-%include <gr_sync_block.h>
-%include <gr_sync_decimator.h>
-%include <gr_sync_interpolator.h>
+////////////////////////////////////////////////////////////////////////
+%ignore gras::IOSignature::operator->();
+%ignore gras::IOSignature::operator->() const;
+
+%include <std_vector.i>
+%template () std::vector<int>;
+
+////////////////////////////////////////////////////////////////////////
+// pull in hier and top interface
+////////////////////////////////////////////////////////////////////////
+%include <boost_shared_ptr.i>
+%shared_ptr(gras::ElementImpl)
+
+%include <gras/element.hpp>
+%include <gras/hier_block.hpp>
+%include <gras/top_block.hpp>
+%include <gras/io_signature.hpp>
////////////////////////////////////////////////////////////////////////
// Make a special top block with python safe unlocking wait
////////////////////////////////////////////////////////////////////////
-%include "gruel_common.i"
%inline %{
-namespace gnuradio
+namespace gras
{
-//typedef TopBlock TopBlockBase;
-typedef gr_top_block TopBlockBase; //maximal set of all API
-
-struct TopBlockPython : TopBlockBase
+struct TopBlockPython : TopBlock
{
TopBlockPython(void):
- TopBlockBase("top")
+ TopBlock("top")
{
//NOP
}
TopBlockPython(const std::string &name):
- TopBlockBase(name)
+ TopBlock(name)
{
//NOP
}
void wait(void)
{
- GR_PYTHON_BLOCKING_CODE
- (
- TopBlockBase::wait();
- )
+ PyThreadState *s = PyEval_SaveThread();
+ TopBlock::wait();
+ PyEval_RestoreThread(s);
}
bool wait(const double timeout)
{
- bool ret = false;
- GR_PYTHON_BLOCKING_CODE
- (
- ret = TopBlock::wait(timeout);
- )
+ PyThreadState *s = PyEval_SaveThread();
+ const bool ret = TopBlock::wait(timeout);
+ PyEval_RestoreThread(s);
return ret;
}
};
@@ -142,19 +149,4 @@ class HierBlock(HierBlock):
def disconnect(self, *args):
return internal_connect__(HierBlock.disconnect, self, *args)
-top_block = TopBlock
-
-class hier_block(gr_hier_block2):
- def __init__(self, *args, **kwargs):
- gr_hier_block2.__init__(self, *args, **kwargs)
- self._hb = self #backwards compat
-
- def connect(self, *args):
- return internal_connect__(gr_hier_block2.connect, self, *args)
-
- def disconnect(self, *args):
- return internal_connect__(gr_hier_block2.disconnect, self, *args)
-
-hier_block2 = hier_block
-
%}
diff --git a/python/gras/__init__.py b/python/gras/__init__.py
new file mode 100644
index 0000000..6a836a6
--- /dev/null
+++ b/python/gras/__init__.py
@@ -0,0 +1 @@
+from GRASElements import *
diff --git a/python/runtime.i b/python/runtime.i
deleted file mode 100644
index 8895a7f..0000000
--- a/python/runtime.i
+++ /dev/null
@@ -1,71 +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 <http://www.gnu.org/licenses/>.
-
-#define GR_CORE_API
-#define GRAS_API
-
-//not here to fight you swig, reference() is ambigi with shared ptr, but whatevs
-%ignore gri_agc_cc::reference();
-%ignore gri_agc2_ff::reference();
-%ignore gri_agc2_cc::reference();
-
-%{
-
-#include <gnuradio/thread_pool.hpp>
-#include <gnuradio/element.hpp>
-#include <gnuradio/block.hpp>
-#include <gnuradio/hier_block.hpp>
-#include <gnuradio/top_block.hpp>
-#include <gnuradio/io_signature.hpp>
-#include <gnuradio/tags.hpp>
-#include <gr_io_signature.h>
-#include <gr_block.h>
-#include <gr_top_block.h>
-#include <gr_hier_block2.h>
-#include <gr_message.h>
-#include <gr_msg_handler.h>
-#include <gr_msg_queue.h>
-#include <gr_sync_block.h>
-#include <gr_sync_decimator.h>
-#include <gr_sync_interpolator.h>
-
-%}
-
-%include <gr_message.i>
-%include <gr_msg_handler.i>
-%include <gr_msg_queue.i>
-%include <gr_swig_block_magic.i>
-
-#ifdef SW_RUNTIME
-
-%include "gras.i"
-
-#else
-
-//the bare minimum block inheritance interface to make things work but keep swig cxx file size down
-%include <gnuradio/element.hpp>
-namespace gnuradio
-{
- struct Block : Element{};
- struct HierBlock : Element{};
-}
-struct gr_hier_block2 : gnuradio::HierBlock{};
-struct gr_block : gnuradio::Block{};
-struct gr_sync_block : gr_block{};
-struct gr_sync_interpolator : gr_sync_block{};
-struct gr_sync_decimator : gr_sync_block{};
-
-#endif