[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5231 - in gnuradio/branches/developers/jcorgan/disc2/
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r5231 - in gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src: lib/runtime python/gnuradio/gr |
Date: |
Wed, 2 May 2007 19:04:18 -0600 (MDT) |
Author: jcorgan
Date: 2007-05-02 19:04:17 -0600 (Wed, 02 May 2007)
New Revision: 5231
Modified:
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime.cc
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
Log:
Merged r5179:5191 from jcorgan/disc
Modified:
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
2007-05-03 01:00:37 UTC (rev 5230)
+++
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
2007-05-03 01:04:17 UTC (rev 5231)
@@ -55,20 +55,20 @@
if (src.get() == dst.get())
throw std::invalid_argument("src and destination blocks cannot be the
same");
- // Assignments to block inputs or outputs
+ // Connectments to block inputs or outputs
int max_port;
if (src.get() == d_owner) {
max_port = src->input_signature()->max_streams();
if ((max_port != -1 && (src_port >= max_port)) || src_port < 0)
throw std::invalid_argument("source port out of range");
- return assign_input(src_port, dst_port, dst);
+ return connect_input(src_port, dst_port, dst);
}
if (dst.get() == d_owner) {
max_port = dst->output_signature()->max_streams();
if ((max_port != -1 && (dst_port >= max_port)) || dst_port < 0)
throw std::invalid_argument("source port out of range");
- return assign_output(dst_port, src_port, src);
+ return connect_output(dst_port, src_port, src);
}
// Internal connections
@@ -81,13 +81,25 @@
gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port,
gr_basic_block_sptr dst, int dst_port)
{
- // Handle disconnecting inputs and outputs
+ if (GR_HIER_BLOCK2_DETAIL_DEBUG)
+ std::cout << "disconnecting: " << gr_endpoint(src, src_port)
+ << " -> " << gr_endpoint(dst, dst_port) << std::endl;
+ if (src.get() == dst.get())
+ throw std::invalid_argument("src and destination blocks cannot be the
same");
+
+ if (src.get() == d_owner)
+ return disconnect_input(src_port, dst_port, dst);
+
+ if (dst.get() == d_owner)
+ return disconnect_output(dst_port, src_port, src);
+
+ // Internal connections
d_fg->disconnect(src, src_port, dst, dst_port);
}
void
-gr_hier_block2_detail::assign_input(int my_port, int port, gr_basic_block_sptr
block)
+gr_hier_block2_detail::connect_input(int my_port, int port,
gr_basic_block_sptr block)
{
if (my_port < 0 || my_port >= (signed)d_inputs.size())
throw std::invalid_argument("input port number out of range");
@@ -99,7 +111,7 @@
}
void
-gr_hier_block2_detail::assign_output(int my_port, int port,
gr_basic_block_sptr block)
+gr_hier_block2_detail::connect_output(int my_port, int port,
gr_basic_block_sptr block)
{
if (my_port < 0 || my_port >= (signed)d_outputs.size())
throw std::invalid_argument("output port number out of range");
@@ -110,6 +122,30 @@
d_outputs[my_port] = gr_endpoint(block, port);
}
+void
+gr_hier_block2_detail::disconnect_input(int my_port, int port,
gr_basic_block_sptr block)
+{
+ if (my_port < 0 || my_port >= (signed)d_inputs.size())
+ throw std::invalid_argument("input port number out of range");
+
+ if (d_inputs[my_port].block() != block)
+ throw std::invalid_argument("block not assigned to given input, can't
disconnect");
+
+ d_inputs[my_port] = gr_endpoint();
+}
+
+void
+gr_hier_block2_detail::disconnect_output(int my_port, int port,
gr_basic_block_sptr block)
+{
+ if (my_port < 0 || my_port >= (signed)d_outputs.size())
+ throw std::invalid_argument("input port number out of range");
+
+ if (d_outputs[my_port].block() != block)
+ throw std::invalid_argument("block not assigned to given output, can't
disconnect");
+
+ d_outputs[my_port] = gr_endpoint();
+}
+
gr_endpoint
gr_hier_block2_detail::resolve_port(int port, bool is_input)
{
Modified:
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h
===================================================================
---
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h
2007-05-03 01:00:37 UTC (rev 5230)
+++
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h
2007-05-03 01:04:17 UTC (rev 5231)
@@ -45,8 +45,10 @@
gr_basic_block_sptr dst, int dst_port);
void disconnect(gr_basic_block_sptr, int src_port,
gr_basic_block_sptr, int dst_port);
- void assign_input(int my_port, int port, gr_basic_block_sptr block);
- void assign_output(int my_port, int port, gr_basic_block_sptr block);
+ void connect_input(int my_port, int port, gr_basic_block_sptr block);
+ void connect_output(int my_port, int port, gr_basic_block_sptr block);
+ void disconnect_input(int my_port, int port, gr_basic_block_sptr block);
+ void disconnect_output(int my_port, int port, gr_basic_block_sptr block);
void flatten(gr_simple_flowgraph_sptr sfg);
gr_endpoint resolve_port(int port, bool is_input);
gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input);
Modified:
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime.cc
2007-05-03 01:00:37 UTC (rev 5230)
+++
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime.cc
2007-05-03 01:04:17 UTC (rev 5231)
@@ -26,11 +26,8 @@
#include <gr_runtime.h>
#include <gr_runtime_impl.h>
-#include <gr_local_sighandler.h>
#include <iostream>
-static gr_runtime *s_runtime = 0;
-
gr_runtime_sptr
gr_make_runtime(gr_hier_block2_sptr top_block)
{
@@ -40,28 +37,16 @@
gr_runtime::gr_runtime(gr_hier_block2_sptr top_block)
{
d_impl = new gr_runtime_impl(top_block);
- s_runtime = this;
}
gr_runtime::~gr_runtime()
{
- s_runtime = 0; // we don't own this
delete d_impl;
}
-// FIXME: This prevents using more than one gr_runtime instance
-static void
-runtime_sigint_handler(int signum)
-{
- if (s_runtime)
- s_runtime->stop();
-}
-
void
gr_runtime::start()
{
- gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
-
d_impl->start();
}
@@ -74,24 +59,18 @@
void
gr_runtime::wait()
{
- gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
-
d_impl->wait();
}
void
gr_runtime::run()
{
- gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
-
- d_impl->start();
- d_impl->wait();
+ start();
+ wait();
}
void
gr_runtime::restart()
{
- gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
-
d_impl->restart();
}
Modified:
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
2007-05-03 01:00:37 UTC (rev 5230)
+++
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
2007-05-03 01:04:17 UTC (rev 5231)
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2007 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -24,10 +24,12 @@
#include "config.h"
#endif
+#include <gr_runtime.h>
#include <gr_runtime_impl.h>
#include <gr_simple_flowgraph.h>
#include <gr_hier_block2.h>
#include <gr_hier_block2_detail.h>
+#include <gr_local_sighandler.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
@@ -36,24 +38,39 @@
#include <stdexcept>
#include <iostream>
+#define GR_RUNTIME_IMPL_DEBUG 1
+
+static gr_runtime_impl *s_runtime = 0;
+
+// FIXME: This prevents using more than one gr_runtime instance
+void
+runtime_sigint_handler(int signum)
+{
+ if (s_runtime)
+ s_runtime->stop();
+}
+
gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block)
: d_running(false),
d_top_block(top_block),
d_sfg(gr_make_simple_flowgraph())
{
+ s_runtime = this;
}
gr_runtime_impl::~gr_runtime_impl()
{
+ s_runtime = 0; // we don't own this
}
void
gr_runtime_impl::start()
{
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "start: entered" << std::endl;
+
if (d_running)
throw std::runtime_error("already running");
- else
- d_running = true;
// Create new simple flow graph by flattening hierarchical block
d_sfg->d_detail->reset();
@@ -70,24 +87,33 @@
void
gr_runtime_impl::start_threads()
{
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "start_threads: entered" << std::endl;
+
d_graphs = d_sfg->d_detail->partition();
- d_threads.clear();
for (std::vector<gr_block_vector_t>::iterator p = d_graphs.begin();
p != d_graphs.end(); p++) {
gr_scheduler_thread *thread = new gr_scheduler_thread(*p);
+ d_threads.push_back(thread);
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "start_threads: starting " << thread << std::endl;
thread->start();
- d_threads.push_back(thread);
}
+
+ d_running = true;
}
void
gr_runtime_impl::stop()
{
- if (!d_running)
- throw std::runtime_error("not running");
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "stop: entered" << std::endl;
- for (gr_scheduler_thread_viter_t p = d_threads.begin(); p !=
d_threads.end(); p++)
- (*p)->stop();
+ for (gr_scheduler_thread_viter_t p = d_threads.begin(); p !=
d_threads.end(); p++) {
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "stop: stopping thread " << (*p) << std::endl;
+ (*p)->stop();
+ }
d_running = false;
}
@@ -95,24 +121,37 @@
void
gr_runtime_impl::wait()
{
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "wait: entered" << std::endl;
+
void *dummy_status; // don't ever dereference this
+ gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
for (gr_scheduler_thread_viter_t p = d_threads.begin(); p !=
d_threads.end(); p++) {
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "wait: joining thread " << (*p) << std::endl;
(*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now
dead
(*p) = 0; // FIXME: switch to stl::list and actually remove from container
}
+
+ d_threads.clear();
}
void
gr_runtime_impl::restart()
{
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "restart: entered" << std::endl;
+
if (!d_running)
throw std::runtime_error("not running");
// Stop scheduler threads and wait for completion
stop();
wait();
-
+ if (GR_RUNTIME_IMPL_DEBUG)
+ std::cout << "restart: threads stopped" << std::endl;
+
// Create new simple flow graph
gr_simple_flowgraph_sptr new_sfg = gr_make_simple_flowgraph();
d_top_block->d_detail->flatten(new_sfg);
@@ -161,3 +200,4 @@
{
d_sts->stop();
}
+
Modified:
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
===================================================================
---
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
2007-05-03 01:00:37 UTC (rev 5230)
+++
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
2007-05-03 01:04:17 UTC (rev 5231)
@@ -67,6 +67,7 @@
{
private:
gr_runtime_impl(gr_hier_block2_sptr top_block);
+ friend void runtime_sigint_handler(int signum);
friend class gr_runtime;
bool d_running;
Modified:
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
2007-05-03 01:00:37 UTC (rev 5230)
+++
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
2007-05-03 01:04:17 UTC (rev 5231)
@@ -32,6 +32,8 @@
#include <iostream>
#include <stdexcept>
+#define GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG 1
+
gr_edge_sptr
gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst)
{
@@ -479,5 +481,9 @@
void
gr_simple_flowgraph_detail::merge_connections(gr_simple_flowgraph_sptr sfg)
{
- // NOT IMPLEMENTED
+ // For each block used in new flow graph, see if it exists in old flow graph
+ for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) {
+ if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG)
+ std::cout << "merge: testing " << (*p) << std::endl;
+ }
}
Modified:
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
===================================================================
---
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
2007-05-03 01:00:37 UTC (rev 5230)
+++
gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
2007-05-03 01:04:17 UTC (rev 5231)
@@ -158,17 +158,87 @@
self.assertEquals(expected, actual1)
self.assertEquals(expected, actual2)
- def test_015_connect_disconnect(self):
- expected = (1.0, 2.0, 3.0, 4.0)
- hblock = gr.top_block("test_block")
- src = gr.vector_source_f(expected, False)
- sink1 = gr.vector_sink_f()
- sink2 = gr.vector_sink_f()
- hblock.connect(src, sink1)
- hblock.connect(src, sink2)
- hblock.disconnect(src, sink2)
- runtime = gr.runtime(hblock)
- runtime.run()
-
+ def test_015_disconnect_input(self):
+ hblock = gr.hier_block2("test_block",
+ gr.io_signature(1,1,gr.sizeof_int),
+ gr.io_signature(1,1,gr.sizeof_int))
+ nop1 = gr.nop(gr.sizeof_int)
+ hblock.connect(hblock, nop1)
+ hblock.disconnect(hblock, nop1)
+
+ def test_016_disconnect_input_not_connected(self):
+ hblock = gr.hier_block2("test_block",
+ gr.io_signature(1,1,gr.sizeof_int),
+ gr.io_signature(1,1,gr.sizeof_int))
+ nop1 = gr.nop(gr.sizeof_int)
+ nop2 = gr.nop(gr.sizeof_int)
+ hblock.connect(hblock, nop1)
+ self.assertRaises(ValueError,
+ lambda: hblock.disconnect(hblock, nop2))
+
+ def test_017_disconnect_input_neg(self):
+ hblock = gr.hier_block2("test_block",
+ gr.io_signature(1,1,gr.sizeof_int),
+ gr.io_signature(1,1,gr.sizeof_int))
+ nop1 = gr.nop(gr.sizeof_int)
+ hblock.connect(hblock, nop1)
+ self.assertRaises(ValueError,
+ lambda: hblock.disconnect((hblock, -1), nop1))
+
+ def test_018_disconnect_input_exceeds(self):
+ hblock = gr.hier_block2("test_block",
+ gr.io_signature(1,1,gr.sizeof_int),
+ gr.io_signature(1,1,gr.sizeof_int))
+ nop1 = gr.nop(gr.sizeof_int)
+ hblock.connect(hblock, nop1)
+ self.assertRaises(ValueError,
+ lambda: hblock.disconnect((hblock, 1), nop1))
+
+ def test_019_disconnect_output(self):
+ hblock = gr.hier_block2("test_block",
+ gr.io_signature(1,1,gr.sizeof_int),
+ gr.io_signature(1,1,gr.sizeof_int))
+ nop1 = gr.nop(gr.sizeof_int)
+ hblock.connect(nop1, hblock)
+ hblock.disconnect(nop1, hblock)
+
+ def test_020_disconnect_output_not_connected(self):
+ hblock = gr.hier_block2("test_block",
+ gr.io_signature(1,1,gr.sizeof_int),
+ gr.io_signature(1,1,gr.sizeof_int))
+ nop1 = gr.nop(gr.sizeof_int)
+ nop2 = gr.nop(gr.sizeof_int)
+ hblock.connect(nop1, hblock)
+ self.assertRaises(ValueError,
+ lambda: hblock.disconnect(nop2, hblock))
+
+ def test_021_disconnect_output_neg(self):
+ hblock = gr.hier_block2("test_block",
+ gr.io_signature(1,1,gr.sizeof_int),
+ gr.io_signature(1,1,gr.sizeof_int))
+ nop1 = gr.nop(gr.sizeof_int)
+ hblock.connect(hblock, nop1)
+ self.assertRaises(ValueError,
+ lambda: hblock.disconnect(nop1, (hblock, -1)))
+
+ def test_022_disconnect_output_exceeds(self):
+ hblock = gr.hier_block2("test_block",
+ gr.io_signature(1,1,gr.sizeof_int),
+ gr.io_signature(1,1,gr.sizeof_int))
+ nop1 = gr.nop(gr.sizeof_int)
+ hblock.connect(nop1, hblock)
+ self.assertRaises(ValueError,
+ lambda: hblock.disconnect(nop1, (hblock, 1)))
+
+ def test_023_run(self):
+ hblock = gr.top_block("test_block")
+ data = (1.0, 2.0, 3.0, 4.0)
+ src = gr.vector_source_f(data, False)
+ dst = gr.vector_sink_f()
+ hblock.connect(src, dst)
+ r = gr.runtime(hblock)
+ r.run()
+ self.assertEquals(data, dst.data())
+
if __name__ == "__main__":
gr_unittest.main()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5231 - in gnuradio/branches/developers/jcorgan/disc2/gnuradio-core/src: lib/runtime python/gnuradio/gr,
jcorgan <=