[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4005 - in gnuradio/branches/developers/jcorgan/hier/g
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r4005 - in gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src: lib/runtime python/gnuradio/gr |
Date: |
Sun, 19 Nov 2006 20:38:58 -0700 (MST) |
Author: jcorgan
Date: 2006-11-19 20:38:57 -0700 (Sun, 19 Nov 2006)
New Revision: 4005
Added:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_simple_flowgraph.py
Modified:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/Makefile.am
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i
Log:
Work in progress. Added gr_simple_flowgraph class to represent a 'compiled'
flowgraph.
Modified:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/Makefile.am
===================================================================
---
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/Makefile.am
2006-11-20 02:41:19 UTC (rev 4004)
+++
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/Makefile.am
2006-11-20 03:38:57 UTC (rev 4005)
@@ -32,6 +32,7 @@
libruntime_la_SOURCES = \
gr_basic_block.cc \
gr_simple_flowgraph.cc \
+ gr_simple_flowgraph_detail.cc \
gr_block.cc \
gr_block_detail.cc \
gr_hier_block2.cc \
@@ -69,6 +70,7 @@
grinclude_HEADERS = \
gr_basic_block.h \
gr_simple_flowgraph.h \
+ gr_simple_flowgraph_detail.h \
gr_block.h \
gr_block_detail.h \
gr_hier_block2.h \
Modified:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc
2006-11-20 02:41:19 UTC (rev 4004)
+++
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc
2006-11-20 03:38:57 UTC (rev 4005)
@@ -25,16 +25,32 @@
#endif
#include <gr_simple_flowgraph.h>
+#include <gr_simple_flowgraph_detail.h>
gr_simple_flowgraph_sptr gr_make_simple_flowgraph()
{
return gr_simple_flowgraph_sptr(new gr_simple_flowgraph());
}
-gr_simple_flowgraph::gr_simple_flowgraph()
+gr_simple_flowgraph::gr_simple_flowgraph() :
+d_detail(new gr_simple_flowgraph_detail())
{
}
gr_simple_flowgraph::~gr_simple_flowgraph()
{
+ delete d_detail;
}
+
+void
+gr_simple_flowgraph::define_component(const std::string &name, gr_block_sptr
block)
+{
+ d_detail->define_component(name, block);
+}
+
+void
+gr_simple_flowgraph::connect(const std::string &src_name, int src_port,
+ const std::string &dst_name, int dst_port)
+{
+ d_detail->connect(src_name, src_port, dst_name, dst_port);
+}
Modified:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h
===================================================================
---
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h
2006-11-20 02:41:19 UTC (rev 4004)
+++
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h
2006-11-20 03:38:57 UTC (rev 4005)
@@ -23,21 +23,30 @@
#ifndef INCLUDED_GR_SIMPLE_FLOWGRAPH_H
#define INCLUDED_GR_SIMPLE_FLOWGRAPH_H
+#include <gr_block.h>
#include <boost/shared_ptr.hpp>
+#include <string>
class gr_simple_flowgraph;
typedef boost::shared_ptr<gr_simple_flowgraph> gr_simple_flowgraph_sptr;
gr_simple_flowgraph_sptr gr_make_simple_flowgraph();
+class gr_simple_flowgraph_detail;
+
class gr_simple_flowgraph
{
private:
friend gr_simple_flowgraph_sptr gr_make_simple_flowgraph();
gr_simple_flowgraph();
-
+
+ gr_simple_flowgraph_detail *d_detail;
+
public:
~gr_simple_flowgraph();
+ void define_component(const std::string &name, gr_block_sptr block);
+ void connect(const std::string &src, int src_port,
+ const std::string &dst, int dst_port);
};
#endif /* INCLUDED_GR_SIMPLE_FLOWGRAPH_H */
Modified:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i
===================================================================
---
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i
2006-11-20 02:41:19 UTC (rev 4004)
+++
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i
2006-11-20 03:38:57 UTC (rev 4005)
@@ -30,9 +30,14 @@
class gr_simple_flowgraph
{
+private:
+ gr_simple_flowgraph();
+
public:
~gr_simple_flowgraph();
-
-private:
- gr_simple_flowgraph();
+ void define_component(const std::string name, gr_block_sptr block)
+ throw (std::invalid_argument);
+ void connect(const std::string &src, int src_port,
+ const std::string &dst, int dst_port)
+ throw (std::invalid_argument);
};
Added:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
(rev 0)
+++
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
2006-11-20 03:38:57 UTC (rev 4005)
@@ -0,0 +1,130 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 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 2, 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_simple_flowgraph.h>
+#include <gr_simple_flowgraph_detail.h>
+#include <gr_io_signature.h>
+#include <stdexcept>
+
+gr_edge_sptr
+gr_make_edge(const std::string &src_name, int src_port,
+ const std::string &dst_name, int dst_port)
+{
+ return gr_edge_sptr(new gr_edge(src_name, src_port, dst_name, dst_port));
+}
+
+gr_edge::gr_edge(const std::string &src_name, int src_port, const std::string
&dst_name, int dst_port)
+{
+ d_src_name = src_name;
+ d_dst_name = dst_name;
+ d_src_port = src_port;
+ d_dst_port = dst_port;
+}
+
+gr_edge::~gr_edge()
+{
+}
+
+gr_simple_flowgraph_detail::gr_simple_flowgraph_detail() :
+d_components(),
+d_edges()
+{
+}
+
+gr_simple_flowgraph_detail::~gr_simple_flowgraph_detail()
+{
+}
+
+gr_block_sptr
+gr_simple_flowgraph_detail::lookup_block(const std::string &name)
+{
+ gr_component_miter_t p = d_components.find(name);
+ if (p != d_components.end())
+ return p->second;
+ else
+ return gr_block_sptr();
+}
+
+void
+gr_simple_flowgraph_detail::define_component(const std::string &name,
gr_block_sptr block)
+{
+ if (!block)
+ throw std::invalid_argument("null block passed");
+
+ if (!lookup_block(name))
+ d_components[name] = block;
+ else
+ throw std::invalid_argument("name already in use");
+}
+
+void
+gr_simple_flowgraph_detail::connect(const std::string &src_name, int src_port,
+ const std::string &dst_name, int dst_port)
+{
+ gr_block_sptr src_block = lookup_block(src_name);
+ gr_block_sptr dst_block = lookup_block(dst_name);
+
+ if (!src_block)
+ throw std::invalid_argument("unknown src name");
+ if (!dst_block)
+ throw std::invalid_argument("unknown dst name");
+
+ check_valid_port(src_block->output_signature(), src_port);
+ check_valid_port(dst_block->input_signature(), dst_port);
+ check_dst_not_used(dst_name, dst_port);
+ check_type_match(src_block, src_port, dst_block, dst_port);
+
+ d_edges.push_back(gr_make_edge(src_name, src_port, dst_name, dst_port));
+}
+
+void
+gr_simple_flowgraph_detail::check_valid_port(gr_io_signature_sptr sig, int
port)
+{
+ if (port < 0)
+ throw std::invalid_argument("negative port number");
+ if (sig->max_streams() >= 0 && port >= sig->max_streams())
+ throw std::invalid_argument("port number exceeds max");
+}
+
+void
+gr_simple_flowgraph_detail::check_dst_not_used(const std::string &name, int
port)
+{
+ for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++)
+ if ((*p)->dst_name() == name && (*p)->dst_port() == port)
+ throw std::invalid_argument("dst already in use");
+}
+
+void
+gr_simple_flowgraph_detail::check_type_match(gr_block_sptr src_block, int
src_port,
+ gr_block_sptr dst_block, int
dst_port)
+{
+ int src_size = src_block->output_signature()->sizeof_stream_item(src_port);
+ int dst_size = dst_block->input_signature()->sizeof_stream_item(dst_port);
+
+ if (src_size != dst_size)
+ throw std::invalid_argument("type size mismatch");
+}
+
Property changes on:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h
===================================================================
---
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h
(rev 0)
+++
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h
2006-11-20 03:38:57 UTC (rev 4005)
@@ -0,0 +1,84 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 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 2, 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.
+ */
+
+#ifndef INCLUDED_GR_SIMPLE_FLOWGRAPH_DETAIL_H
+#define INCLUDED_GR_SIMPLE_FLOWGRAPH_DETAIL_H
+
+#include <gr_block.h>
+#include <map>
+
+typedef std::map<std::string, gr_block_sptr> gr_component_map_t;
+typedef std::map<std::string, gr_block_sptr>::iterator gr_component_miter_t;
+
+class gr_edge;
+typedef boost::shared_ptr<gr_edge> gr_edge_sptr;
+gr_edge_sptr gr_make_edge(const std::string &src_name, int src_port,
+ const std::string &dst_name, int dst_port);
+
+class gr_edge
+{
+private:
+ friend gr_edge_sptr gr_make_edge(const std::string &src_name, int src_port,
+ const std::string &dst_name, int dst_port);
+ gr_edge(const std::string &name, int src_port,
+ const std::string &name, int dst_port);
+
+ std::string d_src_name;
+ std::string d_dst_name;
+ int d_src_port;
+ int d_dst_port;
+
+public:
+ ~gr_edge();
+ std::string src_name() const { return d_src_name; }
+ std::string dst_name() const { return d_dst_name; }
+ int src_port() const { return d_src_port; }
+ int dst_port() const { return d_dst_port; }
+};
+
+typedef std::vector<gr_edge_sptr> gr_edge_vector_t;
+typedef std::vector<gr_edge_sptr>::iterator gr_edge_viter_t;
+
+class gr_simple_flowgraph_detail
+{
+private:
+ friend class gr_simple_flowgraph;
+ gr_simple_flowgraph_detail();
+
+ gr_component_map_t d_components;
+ gr_edge_vector_t d_edges;
+
+ gr_block_sptr lookup_block(const std::string &name);
+ void check_valid_port(gr_io_signature_sptr sig, int port);
+ void check_dst_not_used(const std::string &name, int port);
+ void check_type_match(gr_block_sptr src_block, int src_port,
+ gr_block_sptr dst_block, int dst_port);
+
+public:
+ ~gr_simple_flowgraph_detail();
+
+ void define_component(const std::string &name, gr_block_sptr block);
+ void connect(const std::string &src, int src_port,
+ const std::string &dst, int dst_port);
+};
+
+#endif /* INCLUDED_GR_SIMPLE_FLOWGRAPH_H */
Property changes on:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_simple_flowgraph.py
===================================================================
---
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_simple_flowgraph.py
(rev 0)
+++
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_simple_flowgraph.py
2006-11-20 03:38:57 UTC (rev 4005)
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+
+from gnuradio import gr, gr_unittest
+
+class test_simple_flowgraph(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.sfg = gr.simple_flowgraph()
+
+ def tearDown(self):
+ self.sfg = None
+
+ def test_001_define_component(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_int))
+
+ def test_002_define_component_name_in_use(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.assertRaises(ValueError,
+ lambda: self.sfg.define_component("src",
gr.null_sink(gr.sizeof_int)))
+
+ def test_003_connect(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_int))
+ self.sfg.connect("src", 0, "dst", 0)
+
+ def test_004connect_unknown_src(self):
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_int))
+ self.assertRaises(ValueError,
+ lambda: self.sfg.connect("src", 0, "dst", 0))
+
+ def test_005_connect_unknown_dst(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.assertRaises(ValueError,
+ lambda: self.sfg.connect("src", 0, "dst", 0))
+
+ def test_006_connect_invalid_src_port_neg(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_int))
+ self.assertRaises(ValueError,
+ lambda: self.sfg.connect("src", -1, "dst", 0))
+
+ def test_007_connect_invalid_src_port_exceeds(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_int))
+ self.assertRaises(ValueError,
+ lambda: self.sfg.connect("src", 1, "dst", 0))
+
+ def test_008_connect_invalid_dst_port_neg(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_int))
+ self.assertRaises(ValueError,
+ lambda: self.sfg.connect("src", 0, "dst", -1))
+
+ def test_009_connect_invalid_dst_port_exceeds(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_int))
+ self.assertRaises(ValueError,
+ lambda: self.sfg.connect("src", 0, "dst", 1))
+
+ def test_010_connect_invalid_dst_port_in_use(self):
+ self.sfg.define_component("src1", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("src2", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_int))
+ self.sfg.connect("src1", 0, "dst", 0)
+ self.assertRaises(ValueError,
+ lambda: self.sfg.connect("src2", 0, "dst", 0))
+
+ def test_011_connect_one_src_two_dst(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst1", gr.null_sink(gr.sizeof_int))
+ self.sfg.define_component("dst2", gr.null_sink(gr.sizeof_int))
+ self.sfg.connect("src", 0, "dst1", 0)
+ self.sfg.connect("src", 0, "dst2", 0)
+
+ def test_012_connect_type_mismatch(self):
+ self.sfg.define_component("src", gr.null_source(gr.sizeof_int))
+ self.sfg.define_component("dst", gr.null_sink(gr.sizeof_char))
+ self.assertRaises(ValueError,
+ lambda: self.sfg.connect("src", 0, "dst", 0))
+
+if __name__ == "__main__":
+ gr_unittest.main()
Property changes on:
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_simple_flowgraph.py
___________________________________________________________________
Name: svn:executable
+ *
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4005 - in gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src: lib/runtime python/gnuradio/gr,
jcorgan <=