summaryrefslogtreecommitdiff
path: root/gr-howto-write-a-block
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2013-03-01 13:19:00 -0500
committerTom Rondeau <trondeau@vt.edu>2013-03-01 13:19:00 -0500
commitce211603ff8821b50f7c9ebc3931498c6f2bd374 (patch)
treedd8b92841ef4cd0728aa1156b105e7173286627b /gr-howto-write-a-block
parent6121d0b12bcb308586b5888b6c7e82832f692e5c (diff)
parent4c164f4cbb7fc9284bec147809b078d0a8ed9f88 (diff)
Merge branch 'master' into gr_log
Conflicts: cmake/Modules/GrMiscUtils.cmake docs/doxygen/other/main_page.dox gnuradio-core/gnuradio-core.conf.in gnuradio-core/src/lib/swig/CMakeLists.txt gr-digital/lib/CMakeLists.txt gr-howto-write-a-block/CMakeLists.txt gr-qtgui/lib/CMakeLists.txt gr-video-sdl/src/CMakeLists.txt
Diffstat (limited to 'gr-howto-write-a-block')
-rw-r--r--gr-howto-write-a-block/CMakeLists.txt12
-rw-r--r--gr-howto-write-a-block/cmake/Modules/GrSwig.cmake2
-rw-r--r--gr-howto-write-a-block/docs/doxygen/Doxyfile.in12
-rw-r--r--gr-howto-write-a-block/docs/doxygen/Doxyfile.swig_doc.in17
-rw-r--r--gr-howto-write-a-block/docs/doxygen/doxyxml/doxyindex.py103
-rw-r--r--gr-howto-write-a-block/docs/doxygen/doxyxml/example/Doxyfile17
-rw-r--r--gr-howto-write-a-block/docs/doxygen/swig_doc.py159
-rw-r--r--gr-howto-write-a-block/python/CMakeLists.txt1
-rw-r--r--gr-howto-write-a-block/python/__init__.py25
-rwxr-xr-xgr-howto-write-a-block/python/qa_howto.py13
-rw-r--r--gr-howto-write-a-block/python/square3_ff.py47
-rw-r--r--gr-howto-write-a-block/swig/CMakeLists.txt2
12 files changed, 263 insertions, 147 deletions
diff --git a/gr-howto-write-a-block/CMakeLists.txt b/gr-howto-write-a-block/CMakeLists.txt
index 8877ccb0ff..d5d04e24d0 100644
--- a/gr-howto-write-a-block/CMakeLists.txt
+++ b/gr-howto-write-a-block/CMakeLists.txt
@@ -103,17 +103,17 @@ GR_LOGGING()
########################################################################
include_directories(
${CMAKE_SOURCE_DIR}/include
- ${Boost_INCLUDE_DIRS}
- ${LOG4CXX_INCLUDE_DIRS}
- ${GRUEL_INCLUDE_DIRS}
${GNURADIO_CORE_INCLUDE_DIRS}
+ ${GRUEL_INCLUDE_DIRS}
+ ${LOG4CXX_INCLUDE_DIRS}
+ ${Boost_INCLUDE_DIRS}
)
link_directories(
- ${Boost_LIBRARY_DIRS}
- ${LOG4CXX_LIBRARY_DIRS}
- ${GRUEL_LIBRARY_DIRS}
${GNURADIO_CORE_LIBRARY_DIRS}
+ ${GRUEL_LIBRARY_DIRS}
+ ${LOG4CXX_LIBRARY_DIRS}
+ ${Boost_LIBRARY_DIRS}
)
# Set component parameters
diff --git a/gr-howto-write-a-block/cmake/Modules/GrSwig.cmake b/gr-howto-write-a-block/cmake/Modules/GrSwig.cmake
index 6ba5ee3a5c..51a753ec54 100644
--- a/gr-howto-write-a-block/cmake/Modules/GrSwig.cmake
+++ b/gr-howto-write-a-block/cmake/Modules/GrSwig.cmake
@@ -108,7 +108,7 @@ macro(GR_SWIG_MAKE name)
#do swig doc generation if specified
if (GR_SWIG_DOC_FILE)
set(GR_SWIG_DOCS_SOURCE_DEPS ${GR_SWIG_SOURCE_DEPS})
- set(GR_SWIG_DOCS_TAREGT_DEPS ${GR_SWIG_TARGET_DEPS})
+ set(GR_SWIG_DOCS_TARGET_DEPS ${GR_SWIG_TARGET_DEPS})
GR_SWIG_MAKE_DOCS(${GR_SWIG_DOC_FILE} ${GR_SWIG_DOC_DIRS})
list(APPEND GR_SWIG_SOURCE_DEPS ${GR_SWIG_DOC_FILE})
endif()
diff --git a/gr-howto-write-a-block/docs/doxygen/Doxyfile.in b/gr-howto-write-a-block/docs/doxygen/Doxyfile.in
index cb6a913bbe..6ee69ee35b 100644
--- a/gr-howto-write-a-block/docs/doxygen/Doxyfile.in
+++ b/gr-howto-write-a-block/docs/doxygen/Doxyfile.in
@@ -455,12 +455,6 @@ MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
-# If the sources in your project are distributed over multiple directories
-# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
-# in the documentation. The default is NO.
-
-SHOW_DIRECTORIES = NO
-
# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
# This will remove the Files entry from the Quick Index and from the
# Folder Tree View (if specified). The default is YES.
@@ -807,12 +801,6 @@ HTML_FOOTER =
HTML_STYLESHEET =
-# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
-# files or namespaces will be aligned in HTML using tables. If set to
-# NO a bullet list will be used.
-
-HTML_ALIGN_MEMBERS = YES
-
# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
# documentation will contain sections that can be hidden and shown after the
# page has loaded. For this to work a browser that supports
diff --git a/gr-howto-write-a-block/docs/doxygen/Doxyfile.swig_doc.in b/gr-howto-write-a-block/docs/doxygen/Doxyfile.swig_doc.in
index 50b8aa81d6..121c3e8585 100644
--- a/gr-howto-write-a-block/docs/doxygen/Doxyfile.swig_doc.in
+++ b/gr-howto-write-a-block/docs/doxygen/Doxyfile.swig_doc.in
@@ -470,12 +470,6 @@ MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
-# If the sources in your project are distributed over multiple directories
-# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
-# in the documentation. The default is NO.
-
-SHOW_DIRECTORIES = NO
-
# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
# This will remove the Files entry from the Quick Index and from the
# Folder Tree View (if specified). The default is YES.
@@ -796,12 +790,6 @@ HTML_FOOTER =
HTML_STYLESHEET =
-# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
-# files or namespaces will be aligned in HTML using tables. If set to
-# NO a bullet list will be used.
-
-HTML_ALIGN_MEMBERS = YES
-
# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
# documentation will contain sections that can be hidden and shown after the
# page has loaded. For this to work a browser that supports
@@ -950,11 +938,6 @@ ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
-# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories,
-# and Class Hierarchy pages using a tree view instead of an ordered list.
-
-USE_INLINE_TREES = NO
-
# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
# used to set the initial width (in pixels) of the frame in which the tree
# is shown.
diff --git a/gr-howto-write-a-block/docs/doxygen/doxyxml/doxyindex.py b/gr-howto-write-a-block/docs/doxygen/doxyxml/doxyindex.py
index 0132ab86fd..304109a8e5 100644
--- a/gr-howto-write-a-block/docs/doxygen/doxyxml/doxyindex.py
+++ b/gr-howto-write-a-block/docs/doxygen/doxyxml/doxyindex.py
@@ -1,23 +1,23 @@
#
# Copyright 2010 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.
-#
+#
"""
Classes providing more user-friendly interfaces to the doxygen xml
docs than the generated classes provide.
@@ -40,7 +40,7 @@ class DoxyIndex(Base):
if self._parsed:
return
super(DoxyIndex, self)._parse()
- self._root = index.parse(os.path.join(self._xml_path, 'index.xml'))
+ self._root = index.parse(os.path.join(self._xml_path, 'index.xml'))
for mem in self._root.compound:
converted = self.convert_mem(mem)
# For files we want the contents to be accessible directly
@@ -78,7 +78,24 @@ class DoxyCompMem(Base):
bd = description(getattr(parse_data, 'briefdescription', None))
dd = description(getattr(parse_data, 'detaileddescription', None))
self._data['brief_description'] = bd
- self._data['detailed_description'] = dd
+ self._data['detailed_description'] = dd
+
+ def set_parameters(self, data):
+ vs = [ddc.value for ddc in data.detaileddescription.content_]
+ pls = []
+ for v in vs:
+ if hasattr(v, 'parameterlist'):
+ pls += v.parameterlist
+ pis = []
+ for pl in pls:
+ pis += pl.parameteritem
+ dpis = []
+ for pi in pis:
+ dpi = DoxyParameterItem(pi)
+ dpi._parse()
+ dpis.append(dpi)
+ self._data['params'] = dpis
+
class DoxyCompound(DoxyCompMem):
pass
@@ -86,7 +103,6 @@ class DoxyCompound(DoxyCompMem):
class DoxyMember(DoxyCompMem):
pass
-
class DoxyFunction(DoxyMember):
__module__ = "gnuradio.utils.doxyxml"
@@ -98,10 +114,13 @@ class DoxyFunction(DoxyMember):
return
super(DoxyFunction, self)._parse()
self.set_descriptions(self._parse_data)
- self._data['params'] = []
- prms = self._parse_data.param
- for prm in prms:
- self._data['params'].append(DoxyParam(prm))
+ self.set_parameters(self._parse_data)
+ if not self._data['params']:
+ # If the params weren't set by a comment then just grab the names.
+ self._data['params'] = []
+ prms = self._parse_data.param
+ for prm in prms:
+ self._data['params'].append(DoxyParam(prm))
brief_description = property(lambda self: self.data()['brief_description'])
detailed_description = property(lambda self: self.data()['detailed_description'])
@@ -111,7 +130,7 @@ Base.mem_classes.append(DoxyFunction)
class DoxyParam(DoxyMember):
-
+
__module__ = "gnuradio.utils.doxyxml"
def _parse(self):
@@ -121,16 +140,46 @@ class DoxyParam(DoxyMember):
self.set_descriptions(self._parse_data)
self._data['declname'] = self._parse_data.declname
+ @property
+ def description(self):
+ descriptions = []
+ if self.brief_description:
+ descriptions.append(self.brief_description)
+ if self.detailed_description:
+ descriptions.append(self.detailed_description)
+ return '\n\n'.join(descriptions)
+
brief_description = property(lambda self: self.data()['brief_description'])
detailed_description = property(lambda self: self.data()['detailed_description'])
- declname = property(lambda self: self.data()['declname'])
+ name = property(lambda self: self.data()['declname'])
-class DoxyClass(DoxyCompound):
+class DoxyParameterItem(DoxyMember):
+ """A different representation of a parameter in Doxygen."""
+
+ def _parse(self):
+ if self._parsed:
+ return
+ super(DoxyParameterItem, self)._parse()
+ names = []
+ for nl in self._parse_data.parameternamelist:
+ for pn in nl.parametername:
+ names.append(description(pn))
+ # Just take first name
+ self._data['name'] = names[0]
+ # Get description
+ pd = description(self._parse_data.get_parameterdescription())
+ self._data['description'] = pd
+
+ description = property(lambda self: self.data()['description'])
+ name = property(lambda self: self.data()['name'])
+
+class DoxyClass(DoxyCompound):
+
__module__ = "gnuradio.utils.doxyxml"
kind = 'class'
-
+
def _parse(self):
if self._parsed:
return
@@ -139,22 +188,24 @@ class DoxyClass(DoxyCompound):
if self._error:
return
self.set_descriptions(self._retrieved_data.compounddef)
+ self.set_parameters(self._retrieved_data.compounddef)
# Sectiondef.kind tells about whether private or public.
# We just ignore this for now.
self.process_memberdefs()
brief_description = property(lambda self: self.data()['brief_description'])
detailed_description = property(lambda self: self.data()['detailed_description'])
+ params = property(lambda self: self.data()['params'])
Base.mem_classes.append(DoxyClass)
-
+
class DoxyFile(DoxyCompound):
-
+
__module__ = "gnuradio.utils.doxyxml"
kind = 'file'
-
+
def _parse(self):
if self._parsed:
return
@@ -164,7 +215,7 @@ class DoxyFile(DoxyCompound):
if self._error:
return
self.process_memberdefs()
-
+
brief_description = property(lambda self: self.data()['brief_description'])
detailed_description = property(lambda self: self.data()['detailed_description'])
@@ -172,16 +223,16 @@ Base.mem_classes.append(DoxyFile)
class DoxyNamespace(DoxyCompound):
-
+
__module__ = "gnuradio.utils.doxyxml"
kind = 'namespace'
-
+
Base.mem_classes.append(DoxyNamespace)
class DoxyGroup(DoxyCompound):
-
+
__module__ = "gnuradio.utils.doxyxml"
kind = 'group'
@@ -209,7 +260,7 @@ class DoxyGroup(DoxyCompound):
self.process_memberdefs()
title = property(lambda self: self.data()['title'])
-
+
Base.mem_classes.append(DoxyGroup)
@@ -224,7 +275,7 @@ Base.mem_classes.append(DoxyFriend)
class DoxyOther(Base):
-
+
__module__ = "gnuradio.utils.doxyxml"
kinds = set(['variable', 'struct', 'union', 'define', 'typedef', 'enum', 'dir', 'page'])
@@ -232,6 +283,6 @@ class DoxyOther(Base):
@classmethod
def can_parse(cls, obj):
return obj.kind in cls.kinds
-
+
Base.mem_classes.append(DoxyOther)
diff --git a/gr-howto-write-a-block/docs/doxygen/doxyxml/example/Doxyfile b/gr-howto-write-a-block/docs/doxygen/doxyxml/example/Doxyfile
index 9780043be0..dd2e5c77eb 100644
--- a/gr-howto-write-a-block/docs/doxygen/doxyxml/example/Doxyfile
+++ b/gr-howto-write-a-block/docs/doxygen/doxyxml/example/Doxyfile
@@ -476,12 +476,6 @@ MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
-# If the sources in your project are distributed over multiple directories
-# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
-# in the documentation. The default is NO.
-
-SHOW_DIRECTORIES = NO
-
# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
# This will remove the Files entry from the Quick Index and from the
# Folder Tree View (if specified). The default is YES.
@@ -808,12 +802,6 @@ HTML_STYLESHEET =
HTML_TIMESTAMP = YES
-# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
-# files or namespaces will be aligned in HTML using tables. If set to
-# NO a bullet list will be used.
-
-HTML_ALIGN_MEMBERS = YES
-
# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
# documentation will contain sections that can be hidden and shown after the
# page has loaded. For this to work a browser that supports
@@ -978,11 +966,6 @@ ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
-# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories,
-# and Class Hierarchy pages using a tree view instead of an ordered list.
-
-USE_INLINE_TREES = NO
-
# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
# used to set the initial width (in pixels) of the frame in which the tree
# is shown.
diff --git a/gr-howto-write-a-block/docs/doxygen/swig_doc.py b/gr-howto-write-a-block/docs/doxygen/swig_doc.py
index 4e1ce2e475..f24608b3ee 100644
--- a/gr-howto-write-a-block/docs/doxygen/swig_doc.py
+++ b/gr-howto-write-a-block/docs/doxygen/swig_doc.py
@@ -1,23 +1,23 @@
#
-# Copyright 2010,2011 Free Software Foundation, Inc.
-#
+# Copyright 2010-2012 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.
-#
+#
"""
Creates the swig_doc.i SWIG interface file.
Execute using: python swig_doc.py xml_path outputfilename
@@ -27,13 +27,10 @@ python docstrings.
"""
-import sys
-
-try:
- from doxyxml import DoxyIndex, DoxyClass, DoxyFriend, DoxyFunction, DoxyFile, base
-except ImportError:
- from gnuradio.doxyxml import DoxyIndex, DoxyClass, DoxyFriend, DoxyFunction, DoxyFile, base
+import sys, time
+from doxyxml import DoxyIndex, DoxyClass, DoxyFriend, DoxyFunction, DoxyFile
+from doxyxml import DoxyOther, base
def py_name(name):
bits = name.split('_')
@@ -56,8 +53,29 @@ class Block(object):
# Check for a parsing error.
if item.error():
return False
- return item.has_member(make_name(item.name()), DoxyFriend)
-
+ friendname = make_name(item.name())
+ is_a_block = item.has_member(friendname, DoxyFriend)
+ # But now sometimes the make function isn't a friend so check again.
+ if not is_a_block:
+ is_a_block = di.has_member(friendname, DoxyFunction)
+ return is_a_block
+
+class Block2(object):
+ """
+ Checks if doxyxml produced objects correspond to a new style
+ gnuradio block.
+ """
+
+ @classmethod
+ def includes(cls, item):
+ if not isinstance(item, DoxyClass):
+ return False
+ # Check for a parsing error.
+ if item.error():
+ return False
+ is_a_block2 = item.has_member('make', DoxyFunction) and item.has_member('sptr', DoxyOther)
+ return is_a_block2
+
def utoascii(text):
"""
@@ -82,13 +100,19 @@ def combine_descriptions(obj):
if dd:
description.append(dd)
return utoascii('\n\n'.join(description)).strip()
-
+
+def format_params(parameteritems):
+ output = ['Args:']
+ template = ' {0} : {1}'
+ for pi in parameteritems:
+ output.append(template.format(pi.name, pi.description))
+ return '\n'.join(output)
entry_templ = '%feature("docstring") {name} "{docstring}"'
-def make_entry(obj, name=None, templ="{description}", description=None):
+def make_entry(obj, name=None, templ="{description}", description=None, params=[]):
"""
Create a docstring entry for a swig interface file.
-
+
obj - a doxyxml object from which documentation will be extracted.
name - the name of the C object (defaults to obj.name())
templ - an optional template for the docstring containing only one
@@ -102,6 +126,9 @@ def make_entry(obj, name=None, templ="{description}", description=None):
return ''
if description is None:
description = combine_descriptions(obj)
+ if params:
+ description += '\n\n'
+ description += utoascii(format_params(params))
docstring = templ.format(description=description)
if not docstring:
return ''
@@ -121,27 +148,31 @@ def make_func_entry(func, name=None, description=None, params=None):
used as the description instead of extracting it from func.
params - a parameter list that overrides using func.params.
"""
- if params is None:
- params = func.params
- params = [prm.declname for prm in params]
- if params:
- sig = "Params: (%s)" % ", ".join(params)
- else:
- sig = "Params: (NONE)"
- templ = "{description}\n\n" + sig
- return make_entry(func, name=name, templ=utoascii(templ),
- description=description)
-
-
-def make_class_entry(klass, description=None):
+ #if params is None:
+ # params = func.params
+ #params = [prm.declname for prm in params]
+ #if params:
+ # sig = "Params: (%s)" % ", ".join(params)
+ #else:
+ # sig = "Params: (NONE)"
+ #templ = "{description}\n\n" + sig
+ #return make_entry(func, name=name, templ=utoascii(templ),
+ # description=description)
+ return make_entry(func, name=name, description=description, params=params)
+
+
+def make_class_entry(klass, description=None, ignored_methods=[], params=None):
"""
Create a class docstring for a swig interface file.
"""
+ if params is None:
+ params = klass.params
output = []
- output.append(make_entry(klass, description=description))
+ output.append(make_entry(klass, description=description, params=params))
for func in klass.in_category(DoxyFunction):
- name = klass.name() + '::' + func.name()
- output.append(make_func_entry(func, name=name))
+ if func.name() not in ignored_methods:
+ name = klass.name() + '::' + func.name()
+ output.append(make_func_entry(func, name=name))
return "\n\n".join(output)
@@ -175,18 +206,38 @@ def make_block_entry(di, block):
# the make function.
output = []
output.append(make_class_entry(block, description=super_description))
- creator = block.get_member(block.name(), DoxyFunction)
output.append(make_func_entry(make_func, description=super_description,
- params=creator.params))
+ params=block.params))
return "\n\n".join(output)
+def make_block2_entry(di, block):
+ """
+ Create class and function docstrings of a new style gnuradio block for a
+ swig interface file.
+ """
+ descriptions = []
+ # For new style blocks all the relevant documentation should be
+ # associated with the 'make' method.
+ make_func = block.get_member('make', DoxyFunction)
+ description = combine_descriptions(make_func)
+ # Associate the combined description with the class and
+ # the make function.
+ output = []
+ #output.append(make_class_entry(
+ # block, description=description,
+ # ignored_methods=['make'], params=make_func.params))
+ makename = block.name() + '::make'
+ output.append(make_func_entry(
+ make_func, name=makename, description=description,
+ params=make_func.params))
+ return "\n\n".join(output)
def make_swig_interface_file(di, swigdocfilename, custom_output=None):
-
+
output = ["""
/*
* This file was automatically generated using swig_doc.py.
- *
+ *
* Any changes to it will be lost next time it is regenerated.
*/
"""]
@@ -196,32 +247,52 @@ def make_swig_interface_file(di, swigdocfilename, custom_output=None):
# Create docstrings for the blocks.
blocks = di.in_category(Block)
+ blocks2 = di.in_category(Block2)
+
make_funcs = set([])
for block in blocks:
try:
make_func = di.get_member(make_name(block.name()), DoxyFunction)
- make_funcs.add(make_func.name())
- output.append(make_block_entry(di, block))
+ # Don't want to risk writing to output twice.
+ if make_func.name() not in make_funcs:
+ make_funcs.add(make_func.name())
+ output.append(make_block_entry(di, block))
+ except block.ParsingError:
+ sys.stderr.write('Parsing error for block {0}\n'.format(block.name()))
+ raise
+
+ for block in blocks2:
+ try:
+ make_func = block.get_member('make', DoxyFunction)
+ make_func_name = block.name() +'::make'
+ # Don't want to risk writing to output twice.
+ if make_func_name not in make_funcs:
+ make_funcs.add(make_func_name)
+ output.append(make_block2_entry(di, block))
except block.ParsingError:
- print('Parsing error for block %s' % block.name())
+ sys.stderr.write('Parsing error for block {0}\n'.format(block.name()))
+ raise
# Create docstrings for functions
# Don't include the make functions since they have already been dealt with.
- funcs = [f for f in di.in_category(DoxyFunction) if f.name() not in make_funcs]
+ funcs = [f for f in di.in_category(DoxyFunction)
+ if f.name() not in make_funcs and not f.name().startswith('std::')]
for f in funcs:
try:
output.append(make_func_entry(f))
except f.ParsingError:
- print('Parsing error for function %s' % f.name())
+ sys.stderr.write('Parsing error for function {0}\n'.format(f.name()))
# Create docstrings for classes
block_names = [block.name() for block in blocks]
- klasses = [k for k in di.in_category(DoxyClass) if k.name() not in block_names]
+ block_names += [block.name() for block in blocks2]
+ klasses = [k for k in di.in_category(DoxyClass)
+ if k.name() not in block_names and not k.name().startswith('std::')]
for k in klasses:
try:
output.append(make_class_entry(k))
except k.ParsingError:
- print('Parsing error for class %s' % k.name())
+ sys.stderr.write('Parsing error for class {0}\n'.format(k.name()))
# Docstrings are not created for anything that is not a function or a class.
# If this excludes anything important please add it here.
diff --git a/gr-howto-write-a-block/python/CMakeLists.txt b/gr-howto-write-a-block/python/CMakeLists.txt
index d5fb195231..ac55316384 100644
--- a/gr-howto-write-a-block/python/CMakeLists.txt
+++ b/gr-howto-write-a-block/python/CMakeLists.txt
@@ -31,6 +31,7 @@ endif()
GR_PYTHON_INSTALL(
FILES
__init__.py
+ square3_ff.py
DESTINATION ${GR_PYTHON_DIR}/howto
)
diff --git a/gr-howto-write-a-block/python/__init__.py b/gr-howto-write-a-block/python/__init__.py
index 575cbfc222..6e5e1c1475 100644
--- a/gr-howto-write-a-block/python/__init__.py
+++ b/gr-howto-write-a-block/python/__init__.py
@@ -23,32 +23,9 @@ This is the GNU Radio HOWTO module. Place your Python package
description here (python/__init__.py).
'''
-# ----------------------------------------------------------------
-# Temporary workaround for ticket:181 (swig+python problem)
-import sys
-_RTLD_GLOBAL = 0
-try:
- from dl import RTLD_GLOBAL as _RTLD_GLOBAL
-except ImportError:
- try:
- from DLFCN import RTLD_GLOBAL as _RTLD_GLOBAL
- except ImportError:
- pass
-
-if _RTLD_GLOBAL != 0:
- _dlopenflags = sys.getdlopenflags()
- sys.setdlopenflags(_dlopenflags|_RTLD_GLOBAL)
-# ----------------------------------------------------------------
-
-
# import swig generated symbols into the howto namespace
from howto_swig import *
+from square3_ff import square3_ff
# import any pure python here
#
-
-# ----------------------------------------------------------------
-# Tail of workaround
-if _RTLD_GLOBAL != 0:
- sys.setdlopenflags(_dlopenflags) # Restore original flags
-# ----------------------------------------------------------------
diff --git a/gr-howto-write-a-block/python/qa_howto.py b/gr-howto-write-a-block/python/qa_howto.py
index 7321941d5e..5e62fc890d 100755
--- a/gr-howto-write-a-block/python/qa_howto.py
+++ b/gr-howto-write-a-block/python/qa_howto.py
@@ -22,6 +22,7 @@
from gnuradio import gr, gr_unittest
import howto_swig
+from square3_ff import square3_ff
class qa_howto (gr_unittest.TestCase):
@@ -55,5 +56,17 @@ class qa_howto (gr_unittest.TestCase):
result_data = dst.data ()
self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
+ def test_003_square3_ff (self):
+ src_data = (-3, 4, -5.5, 2, 3)
+ expected_result = (9, 16, 30.25, 4, 9)
+ src = gr.vector_source_f (src_data)
+ sqr = square3_ff ()
+ dst = gr.vector_sink_f ()
+ self.tb.connect (src, sqr)
+ self.tb.connect (sqr, dst)
+ self.tb.run ()
+ result_data = dst.data ()
+ self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
+
if __name__ == '__main__':
gr_unittest.main ()
diff --git a/gr-howto-write-a-block/python/square3_ff.py b/gr-howto-write-a-block/python/square3_ff.py
new file mode 100644
index 0000000000..df702734e5
--- /dev/null
+++ b/gr-howto-write-a-block/python/square3_ff.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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.
+#
+
+import numpy
+from gnuradio import gr
+
+class square3_ff(gr.sync_block):
+ " Squaring block "
+ def __init__(self):
+ gr.sync_block.__init__(
+ self,
+ name = "square3_ff",
+ in_sig = [numpy.float32], # Input signature: 1 float at a time
+ out_sig = [numpy.float32], # Output signature: 1 float at a time
+ )
+
+ def work(self, input_items, output_items):
+ """ Notes:
+ - You must not forget the [:] at the output items, otherwise
+ stuff doesn't truly get copied to the output
+ - Both input_ and output_items[N] are numpy arrays, so you can
+ do fancy stuff like multiplying them elementwise
+ - noutput_items and ninput_items are implicit in the length of
+ output_items and input_items, respectively
+ """
+ output_items[0][:] = input_items[0] * input_items[0]
+ return len(output_items[0])
+
diff --git a/gr-howto-write-a-block/swig/CMakeLists.txt b/gr-howto-write-a-block/swig/CMakeLists.txt
index 1e3e59e2c4..4d5f1156e3 100644
--- a/gr-howto-write-a-block/swig/CMakeLists.txt
+++ b/gr-howto-write-a-block/swig/CMakeLists.txt
@@ -39,6 +39,8 @@ foreach(incdir ${GRUEL_INCLUDE_DIRS})
list(APPEND GR_SWIG_INCLUDE_DIRS ${incdir}/gruel/swig)
endforeach(incdir)
+list(APPEND GR_SWIG_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
+
set(GR_SWIG_LIBRARIES gnuradio-howto)
set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/howto_swig_doc.i)
set(GR_SWIG_DOC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../include)