[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r3798 - in gnuradio/branches/developers/jcorgan/cppwra
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r3798 - in gnuradio/branches/developers/jcorgan/cppwrap: config gnuradio-examples gnuradio-examples/c++ |
Date: |
Mon, 16 Oct 2006 15:56:49 -0600 (MDT) |
Author: jcorgan
Date: 2006-10-16 15:56:48 -0600 (Mon, 16 Oct 2006)
New Revision: 3798
Added:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/config/grc_gnuradio_examples.m4
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/Makefile.am
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/Makefile.am
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
Log:
Work in progress, refactoring and cleanup.
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/config/grc_gnuradio_examples.m4
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/config/grc_gnuradio_examples.m4
2006-10-16 19:30:34 UTC (rev 3797)
+++
gnuradio/branches/developers/jcorgan/cppwrap/config/grc_gnuradio_examples.m4
2006-10-16 21:56:48 UTC (rev 3798)
@@ -35,7 +35,7 @@
gnuradio-examples/python/multi_usrp/Makefile \
gnuradio-examples/python/networking/Makefile \
gnuradio-examples/python/usrp/Makefile \
- gnuradio-examples/native/Makefile
+ gnuradio-examples/c++/Makefile
])
passed=yes
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/Makefile.am
===================================================================
--- gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/Makefile.am
2006-10-16 19:30:34 UTC (rev 3797)
+++ gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/Makefile.am
2006-10-16 21:56:48 UTC (rev 3798)
@@ -21,4 +21,4 @@
include $(top_srcdir)/Makefile.common
-SUBDIRS = python native
+SUBDIRS = python c++
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/Makefile.am
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/Makefile.am
2006-10-16 19:30:34 UTC (rev 3797)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/Makefile.am
2006-10-16 21:56:48 UTC (rev 3798)
@@ -28,6 +28,7 @@
dialtone_SOURCES = \
dialtone.cc \
+ gr_basic_flowgraph.cc \
gr_flow_graph.cc \
gr_scheduler.cc
Added:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
(rev 0)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
2006-10-16 21:56:48 UTC (rev 3798)
@@ -0,0 +1,436 @@
+/*
+ * 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.
+ */
+
+#include <gr_basic_flowgraph.h>
+#include <gr_block_detail.h>
+#include <gr_io_signature.h>
+#include <gr_buffer.h>
+
+#include <iostream>
+#include <algorithm>
+
+using namespace std;
+
+/********** BEGIN PUBLIC METHODS **********/
+
+// Create an instance of a shared pointer to a gr_basic_flowgraph
+// allocated on the heap. No further memory management is needed.
+gr_basic_flowgraph_sptr gr_make_basic_flowgraph()
+{
+ return gr_basic_flowgraph_sptr(new gr_basic_flowgraph());
+}
+
+// Destructor, nothing to do.
+gr_basic_flowgraph::~gr_basic_flowgraph()
+{
+ // NOP
+}
+
+// Establishes a connection between supplied blocks and ports
+void gr_basic_flowgraph::connect(gr_block_sptr src_block, int src_port,
+ gr_block_sptr dst_block, int dst_port)
+{
+ // TODO: check shared pointer validity
+ connect_prim(gr_endpoint_t(src_block, src_port),
+ gr_endpoint_t(dst_block, dst_port));
+}
+
+// Removes an individual connection between supplied blocks and ports
+void gr_basic_flowgraph::disconnect(gr_block_sptr src_block, int src_port,
+ gr_block_sptr dst_block, int dst_port)
+{
+ disconnect_prim(gr_endpoint_t(src_block, src_port),
+ gr_endpoint_t(dst_block, dst_port));
+}
+
+// Removes all connections between blocks in graph
+void gr_basic_flowgraph::disconnect_all()
+{
+ d_edges.clear();
+ printf("Disconnected all blocks.\n");
+}
+
+// Returns list of lists of blocks comprising unique islands
+// of connectivity in flow graph.
+gr_block_vector_vector_t gr_basic_flowgraph::calc_partitions()
+{
+ gr_block_vector_vector_t result;
+ gr_block_vector_t nodes = d_blocks;
+ gr_block_vector_t graph;
+
+ while (nodes.size() > 0) {
+ graph = calc_reachable_vertices(nodes[0], nodes);
+
+ // Partition should be at least one block
+ assert(graph.size());
+
+ result.push_back(topological_sort(graph));
+
+ // Remove all nodes in graph from node list
+ gr_block_vector_iterator_t block_iter;
+ for(block_iter = graph.begin(); block_iter != graph.end(); block_iter++)
+ nodes.erase(find(nodes.begin(), nodes.end(), *block_iter));
+ }
+
+ return result;
+}
+
+/********** BEGIN PRIVATE METHODS **********/
+
+static ostream &operator << (ostream &os, const gr_block_sptr block)
+{
+ os << block->name() << "(" << block->unique_id() << ")";
+ return os;
+}
+
+// Constructor, nothing to do.
+gr_basic_flowgraph::gr_basic_flowgraph()
+{
+ // NOP
+}
+
+// Establishes a connection between supplied blocks and ports, exceptions
+// passed upwards on error conditions. All overloaded versions of 'connect'
+// should resolve to calls here.
+void gr_basic_flowgraph::connect_prim(gr_endpoint_t src, gr_endpoint_t dst)
+{
+ // Correctness checks. Port numbers must be in range, the destination must
+ // not be already used, and they must have the same stream data type.
+ check_valid_port(src.first->output_signature(), src.second);
+ check_valid_port(dst.first->input_signature(), dst.second);
+ check_dst_not_used(dst);
+ check_type_match(src, dst);
+
+ // Create edge instance and add to edge list
+ d_edges.push_back(gr_edge_t(src, dst));
+
+ cout << "Connected " << src.first << ":" << src.second << " to "
+ << dst.second << ":" << dst.first << endl;
+}
+
+// Removes an edge from the list of edges. All overloaded version sof
'disconnect'
+// shoudl resolve to calls here.
+void gr_basic_flowgraph::disconnect_prim(gr_endpoint_t src, gr_endpoint_t dst)
+{
+ gr_edge_vector_iterator_t edge_iter;
+ edge_iter = find(d_edges.begin(), d_edges.end(), gr_edge_t(src, dst));
+ if (edge_iter != d_edges.end())
+ d_edges.erase(edge_iter);
+ else
+ throw invalid_argument("gr_basic_flowgraph::disconnect_prim: not
connected");
+
+ cout << "Disconnected " << src.first << ":" << src.second << " from "
+ << dst.second << ":" << dst.first << endl;
+}
+
+// Ports must not be negative and must be less than max streams for block
+void gr_basic_flowgraph::check_valid_port(gr_io_signature_sptr sig, int port)
+{
+ if (port < 0)
+ throw out_of_range("gr_basic_flowgraph::check_valid_port: negative port
number");
+
+ if (sig->max_streams() >= 0 && port >= sig->max_streams())
+ throw out_of_range("gr_basic_flowgraph::check_valid_port: port exceeds
max_streams");
+}
+
+// Destination ports must not already be in use
+void gr_basic_flowgraph::check_dst_not_used(gr_endpoint_t dst)
+{
+ gr_edge_vector_iterator_t edge_iter;
+ for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) {
+ gr_endpoint_t endp = edge_iter->second;
+ if (endp == dst)
+ throw invalid_argument("gr_basic_flowgraph::check_dst_not_used: dst
already used");
+ }
+}
+
+// Connected ports must have the same data size
+void gr_basic_flowgraph::check_type_match(gr_endpoint_t src, gr_endpoint_t dst)
+{
+ gr_io_signature_sptr src_sig = src.first->output_signature();
+ gr_io_signature_sptr dst_sig = dst.first->input_signature();
+ int src_size = src_sig->sizeof_stream_item(src.second);
+ int dst_size = dst_sig->sizeof_stream_item(dst.second);
+
+ if (src_size != dst_size)
+ throw invalid_argument("gr_basic_flowgraph::check_type_match");
+}
+
+// Scans edge list and assembles list of unique blocks used
+void gr_basic_flowgraph::create_block_list()
+{
+ gr_block_vector_iterator_t block_iter;
+ gr_edge_vector_iterator_t edge_iter;
+
+ // TODO: use sort() and unique() instead
+ for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) {
+ gr_block_sptr src_block = edge_iter->first.first;
+ gr_block_sptr dst_block = edge_iter->second.first;
+
+ block_iter = find(d_blocks.begin(), d_blocks.end(), src_block);
+ if (block_iter == d_blocks.end())
+ d_blocks.push_back(src_block);
+
+ block_iter = find(d_blocks.begin(), d_blocks.end(), dst_block);
+ if (block_iter == d_blocks.end())
+ d_blocks.push_back(dst_block);
+ }
+
+ cout << "Flow graph has " << d_blocks.size() << " unique blocks." << endl;
+}
+
+// Based on connectivity, create block details, buffers, and assign to block
outputs
+// and downstream inputs.
+void gr_basic_flowgraph::connect_blocks()
+{
+ gr_block_vector_iterator_t block_iter;
+ for(block_iter = d_blocks.begin(); block_iter != d_blocks.end();
block_iter++) {
+ vector<int> used_inputs = calc_used_ports(*block_iter, false);
+ vector<int> used_outputs = calc_used_ports(*block_iter, true);
+
+ // Blocks must have inputs sequentially assigned with no gaps
+ check_contiguity(*block_iter, (*block_iter)->input_signature(),
used_inputs);
+ check_contiguity(*block_iter, (*block_iter)->output_signature(),
used_outputs);
+
+ int ninputs = used_inputs.size();
+ int noutputs = used_outputs.size();
+
+ // Ask blocks if their input/ouput connectivity makes sense
+ if (!(*block_iter)->check_topology(ninputs, noutputs))
+ throw invalid_argument("gr_basic_flowgraph::connect_blocks:
topology check failed");
+
+ // Allocate block detail and output buffer and assign
+ gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs);
+ for(int i = 0; i < noutputs; i++)
+ detail->set_output(i, allocate_buffer(*block_iter, i));
+ (*block_iter)->set_detail(detail);
+ }
+
+ // Connect inputs to outputs for each block
+ for(block_iter = d_blocks.begin(); block_iter != d_blocks.end();
block_iter++) {
+ // Get its detail and edges that feed into it
+ gr_block_detail_sptr detail = (*block_iter)->detail();
+ gr_edge_vector_t in_edges = calc_input_edges(*block_iter);
+
+ // For each edge that feeds into it
+ gr_edge_vector_iterator_t edge_iter;
+ for(edge_iter = in_edges.begin(); edge_iter != in_edges.end();
edge_iter++) {
+ // Set the input buffer on the destination port to the output
+ // buffer on the source port
+ int dst_port = edge_iter->second.second;
+ int src_port = edge_iter->first.second;
+ gr_block_sptr src_block = edge_iter->first.first;
+ gr_buffer_sptr src_buffer = src_block->detail()->output(src_port);
+
+ cout << "Setting input buffer on " << dst_port << ":"
+ << edge_iter->second.first << endl;
+ detail->set_input(dst_port, gr_buffer_add_reader(src_buffer,
(*block_iter)->history()-1));
+ }
+ }
+}
+
+// Allocate and return shared pointer to gr_buffer appropriate to given block
and port
+gr_buffer_sptr gr_basic_flowgraph::allocate_buffer(gr_block_sptr block, int
port)
+{
+ // Start by allocating at least number of items in fixed block size
+ int item_size = block->output_signature()->sizeof_stream_item(port);
+ int nitems = s_fixed_buffer_size/item_size;
+
+ // Make sure there are at least twice the output_multiple no. of items
+ if (nitems < 2*block->output_multiple()) // Note: this means
output_multiple()
+ nitems = 2*block->output_multiple(); // can't be changed by block
dynamically
+
+ // If any downstream blocks are decimators and/or have a large
output_multiple,
+ // ensure we have a buffer at least twice their decimation
factor*output_multiple
+ gr_block_vector_t blocks = calc_downstream_blocks(gr_endpoint_t(block,
port));
+ gr_block_vector_iterator_t block_iter;
+ for(block_iter = blocks.begin(); block_iter != blocks.end(); block_iter++)
{
+ int decimation = (int)(1.0/(*block_iter)->relative_rate());
+ int multiple = (*block_iter)->output_multiple();
+ int history = (*block_iter)->history();
+ nitems = max(nitems, 2*(decimation*multiple+history));
+ }
+
+ cout << "Block " << block << " has output buffer of " << nitems
+ << " items, each of size " << item_size << endl;
+
+ return gr_make_buffer(nitems, item_size);
+}
+
+// Recursively mark all reachable blocks from given block and vertex list
+void gr_basic_flowgraph::reachable_dfs_visit(gr_block_sptr block,
gr_vertex_vector_t &vertices)
+{
+ // Find vertex corresponding to block, mark visited
+ // FIXME: pass in the vector when recursing instead of looking it up again
+ gr_vertex_t vertex;
+ gr_vertex_vector_iterator_t vertex_iter;
+ for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++)
+ if (vertex_iter->first == block) {
+ vertex = *vertex_iter;
+ vertex_iter->second = GR_VERTEX_BLACK;
+ }
+
+ // Recurse into adjacent vertices
+ gr_vertex_vector_t adjacent = calc_adjacent_vertices(vertex, vertices);
+ for (vertex_iter = adjacent.begin(); vertex_iter != adjacent.end();
vertex_iter++)
+ if (vertex_iter->second == GR_VERTEX_WHITE)
+ reachable_dfs_visit(vertex_iter->first, vertices);
+}
+
+// Return list of blocks sorted in topological order
+gr_block_vector_t gr_basic_flowgraph::topological_sort(gr_block_vector_t
blocks)
+{
+ gr_block_vector_t result;
+
+ // Not yet implemented, just return identity
+ result = blocks;
+
+ return result;
+}
+
+// Return a list of ports already used in block.
+// direction == false, check inputs
+// direction == true, check outputs
+vector<int> gr_basic_flowgraph::calc_used_ports(gr_block_sptr block, bool
direction)
+{
+ gr_edge_vector_iterator_t edge_iter;
+ vector<int> result;
+ gr_block_sptr cmp_block;
+
+ for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) {
+ if (!direction) { // inputs
+ cmp_block = edge_iter->second.first;
+ if (cmp_block == block)
+ result.push_back(edge_iter->second.second);
+ }
+ else { // outputs
+ cmp_block = edge_iter->first.first;
+ if (cmp_block == block)
+ result.push_back(edge_iter->first.second);
+ }
+ }
+
+ // Remove duplicates
+ sort(result.begin(), result.end());
+ unique(result.begin(), result.end());
+ return result;
+}
+
+// Check that block inputs are fully assigned
+void gr_basic_flowgraph::check_contiguity(gr_block_sptr block,
gr_io_signature_sptr sig,
+ vector<int> &used_ports)
+{
+ int min_s = sig->min_streams();
+ int l = used_ports.size();
+
+ if (l == 0) {
+ if (min_s == 0)
+ return;
+ else
+ throw invalid_argument("gr_basic_flowgraph::check_contiguity: too
many inputs");
+ }
+
+ if (used_ports[l-1]+1 < min_s)
+ throw invalid_argument("gr_basic_flowgraph::check_contiguity:
insufficient inputs");
+
+ if (used_ports[l-1]+1 != l) {
+ for (int i = 0; i < l; i++)
+ if (used_ports[i] != i)
+ throw invalid_argument("gr_basic_flowgraph::check_contiguity:
missing input");
+ }
+}
+
+// Return list of blocks downstream of a given endpoint
+gr_block_vector_t gr_basic_flowgraph::calc_downstream_blocks(gr_endpoint_t src)
+{
+ gr_block_vector_t result;
+ gr_edge_vector_iterator_t edge_iter;
+
+ for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++)
+ if (edge_iter->first == src)
+ result.push_back(edge_iter->second.first);
+
+ // Remove duplicates
+ sort(result.begin(), result.end());
+ unique(result.begin(), result.end());
+ return result;
+}
+
+// Return list of edges that flow into a given block
+gr_edge_vector_t gr_basic_flowgraph::calc_input_edges(gr_block_sptr block)
+{
+ gr_edge_vector_t result;
+ gr_edge_vector_iterator_t edge_iter;
+ for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++)
+ if (edge_iter->second.first == block)
+ result.push_back(*edge_iter);
+
+ return result;
+}
+
+// Return a list of blocks reachable from a given block via any port
+gr_block_vector_t gr_basic_flowgraph::calc_reachable_vertices(gr_block_sptr
block, gr_block_vector_t &blocks)
+{
+ gr_block_vector_t result;
+ gr_vertex_vector_t vertices;
+
+ // Create working list of vertices
+ gr_block_vector_iterator_t block_iter;
+ for(block_iter = blocks.begin(); block_iter != blocks.end(); block_iter++)
+ vertices.push_back(make_pair(*block_iter, GR_VERTEX_WHITE));
+
+ // Mark all reachable vertices from 'block'
+ reachable_dfs_visit(block, vertices);
+
+ // Collect all the blocks from the marked vertices into the result vector
+ gr_vertex_vector_iterator_t vertex_iter;
+ for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++)
+ if (vertex_iter->second == GR_VERTEX_BLACK)
+ result.push_back(vertex_iter->first);
+
+ return result;
+}
+
+// Return a list of vertices adjacent to a given vertex
+gr_vertex_vector_t gr_basic_flowgraph::calc_adjacent_vertices(gr_vertex_t
vertex, gr_vertex_vector_t &vertices)
+{
+ gr_vertex_vector_t result;
+
+ // Find any blocks that are inputs or outputs
+ gr_block_vector_t matches;
+ gr_edge_vector_iterator_t edge_iter;
+ for (edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++)
{
+ if (edge_iter->first.first == vertex.first)
+ matches.push_back(edge_iter->second.first);
+ if (edge_iter->second.first == vertex.first)
+ matches.push_back(edge_iter->first.first);
+ }
+
+ // Then collect those vertices that match those blocks
+ gr_vertex_vector_iterator_t vertex_iter;
+ for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++) {
+ gr_block_vector_iterator_t match = find(matches.begin(), matches.end(),
vertex_iter->first);
+ if (match != matches.end())
+ result.push_back(*vertex_iter);
+ }
+
+ return result;
+}
Property changes on:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
(rev 0)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
2006-10-16 21:56:48 UTC (rev 3798)
@@ -0,0 +1,115 @@
+/*
+ * 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_BASIC_FLOWGRAPH_H
+#define INCLUDED_GR_BASIC_FLOWGRAPH_H
+
+#include <gr_block.h>
+#include <boost/enable_shared_from_this.hpp>
+
+class gr_basic_flowgraph;
+typedef boost::shared_ptr<gr_basic_flowgraph> gr_basic_flowgraph_sptr;
+gr_basic_flowgraph_sptr gr_make_basic_flowgraph();
+
+// Dupe to gr_scheduler.h, but we can't include it here
+class gr_scheduler;
+typedef boost::shared_ptr<gr_scheduler> gr_scheduler_sptr;
+
+// Oh, for the love of Python, of which the STL is but the faintest
approximation,
+// that those poor souls who toil in C++ land might know some glimmer of the
+// beauty and majesty of lists and list comprehensions. At least one may take
some
+// small solace that one is not mired in the dreaded environs of pure C,
though such
+// consolation is no recompense for the agony of templates, pairs, and
iterators!
+
+// Container for list of gr_blocks, and list of lists
+typedef std::vector<gr_block_sptr> gr_block_vector_t;
+typedef std::vector<gr_block_sptr>::iterator gr_block_vector_iterator_t;
+typedef std::vector<gr_block_vector_t> gr_block_vector_vector_t;
+typedef std::vector<gr_block_vector_t>::iterator
gr_block_vector_vector_iterator_t; // :-)
+
+// Flow graph endpoints, edges
+typedef std::pair<gr_block_sptr, int> gr_endpoint_t;
+typedef std::pair<gr_endpoint_t, gr_endpoint_t> gr_edge_t;
+typedef std::vector<gr_edge_t> gr_edge_vector_t;
+typedef std::vector<gr_edge_t>::iterator gr_edge_vector_iterator_t;
+
+// Flow graph vertices
+typedef enum { GR_VERTEX_WHITE, GR_VERTEX_GRAY, GR_VERTEX_BLACK }
gr_vertex_color_t;
+typedef std::pair<gr_block_sptr, gr_vertex_color_t> gr_vertex_t;
+typedef std::vector<gr_vertex_t> gr_vertex_vector_t;
+typedef std::vector<gr_vertex_t>::iterator gr_vertex_vector_iterator_t;
+
+#define GR_FIXED_BUFFER_SIZE (32*(1L<<10))
+
+// Implements container primitives
+class gr_basic_flowgraph : public
boost::enable_shared_from_this<gr_basic_flowgraph>
+{
+protected:
+ // Private constructor ensures use of shared pointers
+ gr_basic_flowgraph();
+ friend gr_basic_flowgraph_sptr gr_make_basic_flowgraph();
+
+ // Add or remove graph edges
+ void connect_prim(gr_endpoint_t src, gr_endpoint_t dst);
+ void disconnect_prim(gr_endpoint_t src, gr_endpoint_t dst);
+
+ // Validation methods, throws exceptions on errors
+ void check_valid_port(gr_io_signature_sptr sig, int port);
+ void check_dst_not_used(gr_endpoint_t dst);
+ void check_type_match(gr_endpoint_t src, gr_endpoint_t dst);
+ void check_contiguity(gr_block_sptr block, gr_io_signature_sptr sig,
+ std::vector<int> &used_ports);
+
+ // Utility functions
+ void create_block_list();
+ void connect_blocks();
+ gr_buffer_sptr allocate_buffer(gr_block_sptr block, int port);
+ void reachable_dfs_visit(gr_block_sptr block, gr_vertex_vector_t
&vertices);
+ gr_block_vector_t topological_sort(gr_block_vector_t blocks);
+
+ std::vector<int> calc_used_ports(gr_block_sptr block, bool direction);
+ gr_block_vector_t calc_downstream_blocks(gr_endpoint_t src);
+ gr_edge_vector_t calc_input_edges(gr_block_sptr block);
+ gr_block_vector_t calc_reachable_vertices(gr_block_sptr block,
gr_block_vector_t &blocks);
+ gr_vertex_vector_t calc_adjacent_vertices(gr_vertex_t vertex,
gr_vertex_vector_t &vertices);
+
+ // Private data
+ static const int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE;
+ gr_edge_vector_t d_edges; // Block:port to port:block connections
+ gr_block_vector_t d_blocks; // List of unique blocks in
graph
+
+public:
+ // Destructor
+ ~gr_basic_flowgraph();
+
+ // Add or remove graph edges
+ void connect(gr_block_sptr src_block, int src_port,
+ gr_block_sptr dst_block, int dst_port);
+ void disconnect(gr_block_sptr src_block, int src_port,
+ gr_block_sptr dst_block, int dst_port);
+ void disconnect_all();
+
+ // Returns a list of lists of blocks that represent distinct
+ // islands of connectivity in the graph
+ gr_block_vector_vector_t calc_partitions();
+};
+
+#endif /* INCLUDED_GR_BASIC_FLOWGRAPH */
Property changes on:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
2006-10-16 19:30:34 UTC (rev 3797)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
2006-10-16 21:56:48 UTC (rev 3798)
@@ -21,12 +21,8 @@
#include <gr_flow_graph.h>
#include <gr_scheduler.h>
-#include <gr_block_detail.h>
-#include <gr_io_signature.h>
-#include <gr_buffer.h>
+#include <stdexcept>
-#include <algorithm>
-
using namespace std;
gr_flow_graph_sptr gr_make_flow_graph()
@@ -44,259 +40,6 @@
// NOP
}
-void gr_flow_graph::connect(gr_block_sptr src_block, int src_port,
- gr_block_sptr dst_block, int dst_port)
-{
- connect_prim(gr_endpoint_t(src_block, src_port),
- gr_endpoint_t(dst_block, dst_port));
-}
-
-// More connect convenience functions (that resolve into calls to
-// connect_prim) go here
-
-void gr_flow_graph::connect_prim(gr_endpoint_t src, gr_endpoint_t dst)
-{
- check_valid_port(src.first->output_signature(), src.second);
- check_valid_port(dst.first->input_signature(), dst.second);
- check_dst_not_used(dst);
- check_type_match(src, dst);
-
- d_edges.push_back(gr_edge_t(src, dst));
- printf("Successfully connected %s(%li):%i to %i:%s(%li)\n",
- src.first->name().c_str(), src.first->unique_id(), src.second,
- dst.second, dst.first->name().c_str(), dst.first->unique_id());
-}
-
-void gr_flow_graph::check_valid_port(gr_io_signature_sptr sig, int port)
-{
- if (port < 0)
- throw out_of_range("gr_flow_graph::check_valid_port: negative port
number");
-
- if (sig->max_streams() >= 0 && port >= sig->max_streams())
- throw out_of_range("gr_flow_graph::check_valid_port: port exceeds
max_streams");
-}
-
-void gr_flow_graph::check_dst_not_used(gr_endpoint_t dst)
-{
- gr_edge_vector_iterator_t edge_iter;
- for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) {
- gr_endpoint_t endp = edge_iter->second;
- if (endp == dst)
- throw invalid_argument("gr_flow_graph::check_dst_not_used: dst
already used");
- }
-}
-
-void gr_flow_graph::check_type_match(gr_endpoint_t src, gr_endpoint_t dst)
-{
- gr_io_signature_sptr src_sig = src.first->output_signature();
- gr_io_signature_sptr dst_sig = dst.first->input_signature();
- int src_size = src_sig->sizeof_stream_item(src.second);
- int dst_size = dst_sig->sizeof_stream_item(dst.second);
-
- if (src_size != dst_size)
- throw invalid_argument("gr_flow_graph::check_type_match");
-}
-
-void gr_flow_graph::disconnect(gr_block_sptr src_block, int src_port,
- gr_block_sptr dst_block, int dst_port)
-{
- disconnect_prim(gr_endpoint_t(src_block, src_port),
- gr_endpoint_t(dst_block, dst_port));
-}
-
-// More disconnect convenience functions (that resolve into calls to
-// disconnect_prim) go here
-
-void gr_flow_graph::disconnect_prim(gr_endpoint_t src, gr_endpoint_t dst)
-{
- gr_edge_vector_iterator_t edge_iter;
- edge_iter = find(d_edges.begin(), d_edges.end(), gr_edge_t(src, dst));
- if (edge_iter != d_edges.end())
- d_edges.erase(edge_iter);
- else
- throw invalid_argument("gr_flow_graph::disconnect_prim: not connected");
-
- printf("Successfully disconnected %s(%li):%i to %i:%s(%li)\n",
- src.first->name().c_str(), src.first->unique_id(), src.second,
- dst.second, dst.first->name().c_str(), dst.first->unique_id());
-}
-
-void gr_flow_graph::disconnect_all()
-{
- d_edges.clear();
- printf("Disconnected all blocks.\n");
-}
-
-void gr_flow_graph::create_block_list()
-{
- gr_block_vector_iterator_t block_iter;
- gr_edge_vector_iterator_t edge_iter;
-
- // TODO: use sort() and unique() instead
- for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) {
- gr_block_sptr src_block = edge_iter->first.first;
- gr_block_sptr dst_block = edge_iter->second.first;
-
- block_iter = find(d_blocks.begin(), d_blocks.end(), src_block);
- if (block_iter == d_blocks.end())
- d_blocks.push_back(src_block);
-
- block_iter = find(d_blocks.begin(), d_blocks.end(), dst_block);
- if (block_iter == d_blocks.end())
- d_blocks.push_back(dst_block);
- }
-
- printf("Flow graph has %i connected blocks.\n", d_blocks.size());
-}
-
-void gr_flow_graph::connect_blocks()
-{
- gr_block_vector_iterator_t block_iter;
- for(block_iter = d_blocks.begin(); block_iter != d_blocks.end();
block_iter++) {
- vector<int> used_inputs = calc_used_ports(*block_iter, false);
- vector<int> used_outputs = calc_used_ports(*block_iter, true);
-
- check_contiguity(*block_iter, (*block_iter)->input_signature(),
used_inputs);
- check_contiguity(*block_iter, (*block_iter)->output_signature(),
used_outputs);
-
- int ninputs = used_inputs.size();
- int noutputs = used_outputs.size();
-
- if (!(*block_iter)->check_topology(ninputs, noutputs))
- throw invalid_argument("gr_flow_graph::validate");
-
- // Allocate block detail and output buffer and assign
- gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs);
- for(int i = 0; i < noutputs; i++)
- detail->set_output(i, allocate_buffer(*block_iter, i));
- (*block_iter)->set_detail(detail);
- }
-
- // Connect inputs to outputs for each block
- for(block_iter = d_blocks.begin(); block_iter != d_blocks.end();
block_iter++) {
- // Get its detail and edges that feed into it
- gr_block_detail_sptr detail = (*block_iter)->detail();
- gr_edge_vector_t in_edges = calc_input_edges(*block_iter);
-
- // For each edge that feeds into it
- gr_edge_vector_iterator_t edge_iter;
- for(edge_iter = in_edges.begin(); edge_iter != in_edges.end();
edge_iter++) {
- // Set the input buffer on the destination port to the output
- // buffer on the source port
- int dst_port = edge_iter->second.second;
- int src_port = edge_iter->first.second;
- gr_block_sptr src_block = edge_iter->first.first;
- gr_buffer_sptr src_buffer = src_block->detail()->output(src_port);
-
- printf("Setting input buffer on %i:%s(%li).\n", dst_port,
- edge_iter->second.first->name().c_str(),
- edge_iter->second.first->unique_id());
-
- detail->set_input(dst_port, gr_buffer_add_reader(src_buffer,
(*block_iter)->history()-1));
- }
- }
-}
-
-vector<int> gr_flow_graph::calc_used_ports(gr_block_sptr block, bool direction)
-{
- gr_edge_vector_iterator_t edge_iter;
- vector<int> result;
- gr_block_sptr cmp_block;
-
- for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) {
- if (!direction) { // inputs
- cmp_block = edge_iter->second.first;
- if (cmp_block == block)
- result.push_back(edge_iter->second.second);
- }
- else { // outputs
- cmp_block = edge_iter->first.first;
- if (cmp_block == block)
- result.push_back(edge_iter->first.second);
- }
- }
-
- // Remove duplicates
- sort(result.begin(), result.end());
- unique(result.begin(), result.end());
- return result;
-}
-
-void gr_flow_graph::check_contiguity(gr_block_sptr block, gr_io_signature_sptr
sig,
- vector<int> &used_ports)
-{
- int min_s = sig->min_streams();
- int l = used_ports.size();
-
- if (l == 0) {
- if (min_s == 0)
- return;
- else
- throw invalid_argument("gr_flow_graph::check_contiguity");
- }
-
- if (used_ports[l-1]+1 < min_s)
- throw invalid_argument("gr_flow_graph::check_contiguity");
-
- if (used_ports[l-1]+1 != l) {
- for (int i = 0; i < l; i++)
- if (used_ports[i] != i)
- throw invalid_argument("gr_flow_graph::check_contiguity");
- }
-}
-
-gr_buffer_sptr gr_flow_graph::allocate_buffer(gr_block_sptr block, int port)
-{
- // Start by allocating at least number of items in fixed block size
- int item_size = block->output_signature()->sizeof_stream_item(port);
- int nitems = s_fixed_buffer_size/item_size;
-
- // Make sure there are at least twice the output_multiple no. of items
- if (nitems < 2*block->output_multiple()) // Note: this means
output_multiple()
- nitems = 2*block->output_multiple(); // can't be changed by block
dynamically
-
- // If any downstream blocks are decimators and/or have a large
output_multiple,
- // ensure we have a buffer at least twice their decimation
factor*output_multiple
- gr_block_vector_t blocks = calc_downstream_blocks(gr_endpoint_t(block,
port));
- gr_block_vector_iterator_t block_iter;
- for(block_iter = blocks.begin(); block_iter != blocks.end(); block_iter++)
{
- int decimation = (int)(1.0/(*block_iter)->relative_rate());
- int multiple = (*block_iter)->output_multiple();
- int history = (*block_iter)->history();
- nitems = max(nitems, 2*(decimation*multiple+history));
- }
-
- printf("Block %s(%li) has output buffer of %i items, each of size %i\n",
- block->name().c_str(), block->unique_id(), nitems, item_size);
-
- return gr_make_buffer(nitems, item_size);
-}
-
-gr_block_vector_t gr_flow_graph::calc_downstream_blocks(gr_endpoint_t src)
-{
- gr_block_vector_t result;
- gr_edge_vector_iterator_t edge_iter;
-
- for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++)
- if (edge_iter->first == src)
- result.push_back(edge_iter->second.first);
-
- sort(result.begin(), result.end());
- unique(result.begin(), result.end());
- return result;
-}
-
-gr_edge_vector_t gr_flow_graph::calc_input_edges(gr_block_sptr block)
-{
- gr_edge_vector_t result;
- gr_edge_vector_iterator_t edge_iter;
- for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++)
- if (edge_iter->second.first == block)
- result.push_back(*edge_iter);
-
- return result;
-}
-
void gr_flow_graph::start()
{
if (d_scheduler)
@@ -331,102 +74,3 @@
start();
wait();
}
-
-gr_block_vector_vector_t gr_flow_graph::calc_partitions()
-{
- gr_block_vector_vector_t result;
- gr_block_vector_t nodes = d_blocks;
- gr_block_vector_t graph;
-
- while (nodes.size() > 0) {
- graph = calc_reachable_vertices(nodes[0], nodes);
-
- // Partition should be at least one block
- assert(graph.size());
-
- result.push_back(topological_sort(graph));
-
- // Remove all nodes in graph from node list
- gr_block_vector_iterator_t block_iter;
- for(block_iter = graph.begin(); block_iter != graph.end(); block_iter++)
- nodes.erase(find(nodes.begin(), nodes.end(), *block_iter));
- }
-
- return result;
-}
-
-gr_block_vector_t gr_flow_graph::calc_reachable_vertices(gr_block_sptr block,
gr_block_vector_t &blocks)
-{
- gr_block_vector_t result;
- gr_vertex_vector_t vertices;
-
- // Create working list of vertices
- gr_block_vector_iterator_t block_iter;
- for(block_iter = blocks.begin(); block_iter != blocks.end(); block_iter++)
- vertices.push_back(make_pair(*block_iter, GR_VERTEX_WHITE));
-
- // Mark all reachable vertices from 'block'
- reachable_dfs_visit(block, vertices);
-
- // Collect all the blocks from the marked vertices into the result vector
- gr_vertex_vector_iterator_t vertex_iter;
- for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++)
- if (vertex_iter->second == GR_VERTEX_BLACK)
- result.push_back(vertex_iter->first);
-
- return result;
-}
-
-void gr_flow_graph::reachable_dfs_visit(gr_block_sptr block,
gr_vertex_vector_t &vertices)
-{
- // Find vertex corresponding to block, mark visited
- // FIXME: pass in the vector when recursing instead of looking it up again
- gr_vertex_t vertex;
- gr_vertex_vector_iterator_t vertex_iter;
- for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++)
- if (vertex_iter->first == block) {
- vertex = *vertex_iter;
- vertex_iter->second = GR_VERTEX_BLACK;
- }
-
- // Recurse into adjacent vertices
- gr_vertex_vector_t adjacent = calc_adjacent_vertices(vertex, vertices);
- for (vertex_iter = adjacent.begin(); vertex_iter != adjacent.end();
vertex_iter++)
- if (vertex_iter->second == GR_VERTEX_WHITE)
- reachable_dfs_visit(vertex_iter->first, vertices);
-}
-
-gr_vertex_vector_t gr_flow_graph::calc_adjacent_vertices(gr_vertex_t vertex,
gr_vertex_vector_t &vertices)
-{
- gr_vertex_vector_t result;
-
- // Find any blocks that are inputs or outputs
- gr_block_vector_t matches;
- gr_edge_vector_iterator_t edge_iter;
- for (edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++)
{
- if (edge_iter->first.first == vertex.first)
- matches.push_back(edge_iter->second.first);
- if (edge_iter->second.first == vertex.first)
- matches.push_back(edge_iter->first.first);
- }
-
- // Then collect those vertices that match those blocks
- gr_vertex_vector_iterator_t vertex_iter;
- for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++) {
- gr_block_vector_iterator_t match = find(matches.begin(), matches.end(),
vertex_iter->first);
- if (match != matches.end())
- result.push_back(*vertex_iter);
- }
-
- return result;
-}
-
-gr_block_vector_t gr_flow_graph::topological_sort(gr_block_vector_t blocks)
-{
- gr_block_vector_t result;
-
- // NOP
- result = blocks;
-
- return result;
-}
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
2006-10-16 19:30:34 UTC (rev 3797)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
2006-10-16 21:56:48 UTC (rev 3798)
@@ -22,8 +22,7 @@
#ifndef INCLUDED_GR_FLOW_GRAPH_H
#define INCLUDED_GR_FLOW_GRAPH_H
-#include <gr_block.h>
-#include <boost/enable_shared_from_this.hpp>
+#include <gr_basic_flowgraph.h>
class gr_flow_graph;
typedef boost::shared_ptr<gr_flow_graph> gr_flow_graph_sptr;
@@ -33,79 +32,17 @@
class gr_scheduler;
typedef boost::shared_ptr<gr_scheduler> gr_scheduler_sptr;
-// Oh, for the love of Python, of which the STL is but the faintest
approximation,
-// that those poor souls who toil in C++ land might know some glimmer of the
-// beauty and majesty of lists and list comprehensions. At least one may take
some
-// small solace that one is not mired in the dreaded environs of pure C,
though such
-// consolation is no recompense for the agony of templates, pairs, and
iterators!
-
-// Container for list of gr_blocks, and list of lists
-typedef std::vector<gr_block_sptr> gr_block_vector_t;
-typedef std::vector<gr_block_sptr>::iterator gr_block_vector_iterator_t;
-typedef std::vector<gr_block_vector_t> gr_block_vector_vector_t;
-typedef std::vector<gr_block_vector_t>::iterator
gr_block_vector_vector_iterator_t; // :-)
-
-// Flow graph endpoints, edges
-typedef std::pair<gr_block_sptr, int> gr_endpoint_t;
-typedef std::pair<gr_endpoint_t, gr_endpoint_t> gr_edge_t;
-typedef std::vector<gr_edge_t> gr_edge_vector_t;
-typedef std::vector<gr_edge_t>::iterator gr_edge_vector_iterator_t;
-
-// Flow graph vertices
-typedef enum { GR_VERTEX_WHITE, GR_VERTEX_GRAY, GR_VERTEX_BLACK }
gr_vertex_color_t;
-typedef std::pair<gr_block_sptr, gr_vertex_color_t> gr_vertex_t;
-typedef std::vector<gr_vertex_t> gr_vertex_vector_t;
-typedef std::vector<gr_vertex_t>::iterator gr_vertex_vector_iterator_t;
-
-#define GR_FIXED_BUFFER_SIZE (32*(1L<<10))
-
-class gr_flow_graph : public boost::enable_shared_from_this<gr_flow_graph>
+class gr_flow_graph : public gr_basic_flowgraph
{
private:
gr_flow_graph();
friend gr_flow_graph_sptr gr_make_flow_graph();
- void connect_prim(gr_endpoint_t src, gr_endpoint_t dst);
- void check_valid_port(gr_io_signature_sptr sig, int port);
- void check_dst_not_used(gr_endpoint_t dst);
- void check_type_match(gr_endpoint_t src, gr_endpoint_t dst);
- void disconnect_prim(gr_endpoint_t src, gr_endpoint_t dst);
-
- void create_block_list();
- void connect_blocks();
- std::vector<int> calc_used_ports(gr_block_sptr block, bool direction);
- void check_contiguity(gr_block_sptr block, gr_io_signature_sptr sig,
- std::vector<int> &used_ports);
-
- gr_buffer_sptr allocate_buffer(gr_block_sptr block, int port);
- gr_block_vector_t calc_downstream_blocks(gr_endpoint_t src);
- gr_edge_vector_t calc_input_edges(gr_block_sptr block);
- gr_block_vector_t calc_reachable_vertices(gr_block_sptr block,
gr_block_vector_t &blocks);
- void reachable_dfs_visit(gr_block_sptr block, gr_vertex_vector_t
&vertices);
- gr_vertex_vector_t calc_adjacent_vertices(gr_vertex_t vertex,
gr_vertex_vector_t &vertices);
- gr_block_vector_t topological_sort(gr_block_vector_t blocks);
-
- static const int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE;
- gr_edge_vector_t d_edges;
- gr_block_vector_t d_blocks;
gr_scheduler_sptr d_scheduler;
public:
~gr_flow_graph();
- // At least the public interface of the class is sane
- void connect(gr_block_sptr src_block, int src_port,
- gr_block_sptr dst_block, int dst_port);
- // more connect convenience functions go here
-
- void disconnect(gr_block_sptr src_block, int src_port,
- gr_block_sptr dst_block, int dst_port);
- void disconnect_all();
-
- // more disconnect convenience functions go here
-
- gr_block_vector_vector_t calc_partitions();
-
void start();
void stop();
void wait();
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
2006-10-16 19:30:34 UTC (rev 3797)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
2006-10-16 21:56:48 UTC (rev 3798)
@@ -21,7 +21,10 @@
#include <gr_scheduler.h>
#include <gr_flow_graph.h>
+#include <iostream>
+using namespace std;
+
gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph)
{
return gr_scheduler_thread_sptr(new gr_scheduler_thread(graph));
@@ -40,7 +43,7 @@
void gr_scheduler_thread::run(void *arg)
{
- printf("Running thread...\n");
+ cout << "Running thread..." << endl;
d_sts->run();
}
@@ -49,15 +52,15 @@
d_sts->stop();
}
-gr_scheduler_sptr gr_make_scheduler(gr_flow_graph_sptr fg)
+gr_scheduler_sptr gr_make_scheduler(gr_basic_flowgraph_sptr fg)
{
return gr_scheduler_sptr(new gr_scheduler(fg));
}
-gr_scheduler::gr_scheduler(gr_flow_graph_sptr fg)
+gr_scheduler::gr_scheduler(gr_basic_flowgraph_sptr fg)
{
gr_block_vector_vector_t graphs = fg->calc_partitions();
- printf("Flowgraph has %i sub-graphs.\n", graphs.size());
+ cout << "Flowgraph has " << graphs.size() << " sub-graphs." << endl;
gr_block_vector_vector_iterator_t graph_iter;
for (graph_iter = graphs.begin(); graph_iter != graphs.end(); graph_iter++)
@@ -71,7 +74,7 @@
void gr_scheduler::start()
{
- printf("There are %i threads to run.\n", d_threads.size());
+ cout << "There are " << d_threads.size() << " to run." << endl;
gr_scheduler_thread_vector_iterator_t thread_iter;
for (thread_iter = d_threads.begin(); thread_iter != d_threads.end();
thread_iter++)
@@ -84,10 +87,9 @@
void gr_scheduler::wait()
{
- // Untile join() exception is solved below
+ // Until join() exception is solved below
while(1);
-/*
gr_scheduler_thread_vector_iterator_t thread_iter;
for (thread_iter = d_threads.begin(); thread_iter != d_threads.end();
thread_iter++) {
while(1) {
@@ -97,5 +99,4 @@
break;
}
}
-*/
}
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
2006-10-16 19:30:34 UTC (rev 3797)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
2006-10-16 21:56:48 UTC (rev 3798)
@@ -25,8 +25,6 @@
#include <gr_flow_graph.h>
#include <omnithread.h>
#include <gr_single_threaded_scheduler.h>
-
-#include <vector>
#include <boost/shared_ptr.hpp>
class gr_scheduler_thread;
@@ -52,16 +50,15 @@
class gr_scheduler;
typedef boost::shared_ptr<gr_scheduler> gr_scheduler_sptr;
-gr_scheduler_sptr gr_make_scheduler(gr_flow_graph_sptr fg);
+gr_scheduler_sptr gr_make_scheduler(gr_basic_flowgraph_sptr fg);
-
class gr_scheduler
{
private:
gr_scheduler_thread_vector_t d_threads;
- gr_scheduler(gr_flow_graph_sptr fg);
- friend gr_scheduler_sptr gr_make_scheduler(gr_flow_graph_sptr fg);
+ gr_scheduler(gr_basic_flowgraph_sptr fg);
+ friend gr_scheduler_sptr gr_make_scheduler(gr_basic_flowgraph_sptr fg);
public:
~gr_scheduler();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r3798 - in gnuradio/branches/developers/jcorgan/cppwrap: config gnuradio-examples gnuradio-examples/c++,
jcorgan <=