commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3790 - gnuradio/branches/developers/jcorgan/cppwrap/g


From: jcorgan
Subject: [Commit-gnuradio] r3790 - gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++
Date: Sun, 15 Oct 2006 14:03:43 -0600 (MDT)

Author: jcorgan
Date: 2006-10-15 14:03:43 -0600 (Sun, 15 Oct 2006)
New Revision: 3790

Modified:
   
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/dialtone.cc
   
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.

Modified: 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/dialtone.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/dialtone.cc  
    2006-10-15 00:01:00 UTC (rev 3789)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/dialtone.cc  
    2006-10-15 20:03:43 UTC (rev 3790)
@@ -20,22 +20,26 @@
  */
 
 #include <gnuradio/gr_sig_source_f.h>
-#include <gnuradio/audio_alsa_sink.h>
+//#include <gnuradio/audio_alsa_sink.h>
+#include <gnuradio/gr_null_sink.h>
 #include <gr_flow_graph.h>
 
 int main()
 {
     gr_sig_source_f_sptr src0, src1;
-    audio_alsa_sink_sptr sink;
+    gr_block_sptr sink0, sink1;
+//  audio_alsa_sink_sptr sink;
     gr_flow_graph_sptr fg;
     
     src0 = gr_make_sig_source_f(48000, GR_SIN_WAVE, 350, 0.5);
     src1 = gr_make_sig_source_f(48000, GR_SIN_WAVE, 440, 0.5);
-    sink = audio_alsa_make_sink(48000);
-
+//  sink = audio_alsa_make_sink(48000);
+    sink0 = gr_make_null_sink(sizeof(float));
+    sink1 = gr_make_null_sink(sizeof(float));
+    
     fg = gr_make_flow_graph();
-    fg->connect(src0, 0, sink, 0);
-    fg->connect(src1, 0, sink, 1);
+    fg->connect(src0, 0, sink0, 0);
+    fg->connect(src1, 0, sink1, 0);
 
     fg->run();
     

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-15 00:01:00 UTC (rev 3789)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
 2006-10-15 20:03:43 UTC (rev 3790)
@@ -27,7 +27,10 @@
 
 #include <utility>
 #include <algorithm>
+#include <functional>
 
+using namespace std;
+
 gr_flow_graph_sptr gr_make_flow_graph()
 {
     return gr_flow_graph_sptr(new gr_flow_graph());
@@ -69,10 +72,10 @@
 void gr_flow_graph::check_valid_port(gr_io_signature_sptr sig, int port)
 {
     if (port < 0)
-       throw std::out_of_range("gr_flow_graph::check_valid_port: negative port 
number");
+       throw out_of_range("gr_flow_graph::check_valid_port: negative port 
number");
     
     if (sig->max_streams() >= 0 && port >= sig->max_streams())
-       throw std::out_of_range("gr_flow_graph::check_valid_port: port exceeds 
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)
@@ -81,7 +84,7 @@
     for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) {
        gr_endpoint_t endp = edge_iter->second;
        if (endp == dst)
-           throw std::invalid_argument("gr_flow_graph::check_dst_not_used: dst 
already used");
+           throw invalid_argument("gr_flow_graph::check_dst_not_used: dst 
already used");
     }
 }
 
@@ -93,7 +96,7 @@
     int dst_size = dst_sig->sizeof_stream_item(dst.second);
     
     if (src_size != dst_size)
-       throw std::invalid_argument("gr_flow_graph::check_type_match");
+       throw invalid_argument("gr_flow_graph::check_type_match");
 }
 
 void gr_flow_graph::disconnect(gr_block_sptr src_block, int src_port,
@@ -113,7 +116,7 @@
     if (edge_iter != d_edges.end())
        d_edges.erase(edge_iter);
     else
-       throw std::invalid_argument("gr_flow_graph::disconnect_prim: not 
connected");
+       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,
@@ -152,8 +155,8 @@
 {
     gr_block_vector_iterator_t block_iter;
     for(block_iter = d_blocks.begin(); block_iter != d_blocks.end(); 
block_iter++) {
-       std::vector<int> used_inputs = calc_used_ports(*block_iter, false);
-       std::vector<int> used_outputs = calc_used_ports(*block_iter, true);
+       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);
@@ -162,7 +165,7 @@
        int noutputs = used_outputs.size();
 
        if (!(*block_iter)->check_topology(ninputs, noutputs))
-           throw std::invalid_argument("gr_flow_graph::validate");
+           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);
@@ -188,10 +191,10 @@
     }
 }
 
-std::vector<int> gr_flow_graph::calc_used_ports(gr_block_sptr block, bool 
direction)
+vector<int> gr_flow_graph::calc_used_ports(gr_block_sptr block, bool direction)
 {
     gr_edge_vector_iterator_t edge_iter;
-    std::vector<int> result;
+    vector<int> result;
     gr_block_sptr cmp_block;
         
     for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) {
@@ -214,7 +217,7 @@
 }
 
 void gr_flow_graph::check_contiguity(gr_block_sptr block, gr_io_signature_sptr 
sig,
-                                    std::vector<int> &used_ports)
+                                    vector<int> &used_ports)
 {
     int min_s = sig->min_streams();
     int l = used_ports.size();
@@ -223,16 +226,16 @@
        if (min_s == 0)
            return;
        else
-           throw std::invalid_argument("gr_flow_graph::check_contiguity");
+           throw invalid_argument("gr_flow_graph::check_contiguity");
     }
 
     if (used_ports[l-1]+1 < min_s)
-       throw std::invalid_argument("gr_flow_graph::check_contiguity");
+       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 std::invalid_argument("gr_flow_graph::check_contiguity");
+               throw invalid_argument("gr_flow_graph::check_contiguity");
     }
 }
 
@@ -254,10 +257,10 @@
        int decimation = (int)(1.0/(*block_iter)->relative_rate());
        int multiple   = (*block_iter)->output_multiple();
        int history    = (*block_iter)->history();
-       nitems = std::max(nitems, 2*(decimation*multiple+history));
+       nitems = max(nitems, 2*(decimation*multiple+history));
     }
 
-    printf("Block %s(%i) has output buffer of %i items, each of size %i\n", 
+    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);
@@ -291,7 +294,7 @@
 void gr_flow_graph::start()
 {
     if (d_scheduler)
-       throw std::runtime_error("Scheduler already running!");
+       throw runtime_error("Scheduler already running!");
        
     create_block_list();
     connect_blocks();
@@ -305,7 +308,7 @@
 void gr_flow_graph::stop()
 {
     if (!d_scheduler)
-       throw std::runtime_error("Scheduler not running!");
+       throw runtime_error("Scheduler not running!");
 
     d_scheduler->stop();
     d_scheduler.reset();
@@ -314,7 +317,7 @@
 void gr_flow_graph::wait()
 {
     if (!d_scheduler)
-       throw std::runtime_error("Scheduler not running!");
+       throw runtime_error("Scheduler not running!");
     d_scheduler->wait();
     d_scheduler.reset();
 }
@@ -325,8 +328,43 @@
     wait();
 }
 
-gr_partitions_t gr_flow_graph::calc_partitions()
+gr_block_vector_vector_t gr_flow_graph::calc_partitions()
 {
-    gr_partitions_t result;
+    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);
+       printf("graph.size() = %i \n", graph.size());
+       result.push_back(topological_sort(graph));
+       printf("n=%i g=%i r=%i\n", nodes.size(), graph.size(), result.size());
+       
+       // 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;
+
+    // NOP
+    result.push_back(block);
+    
+    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-15 00:01:00 UTC (rev 3789)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
  2006-10-15 20:03:43 UTC (rev 3790)
@@ -36,7 +36,7 @@
 // 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_partitions_t;
+typedef std::vector<gr_block_vector_t> gr_block_vector_vector_t;
 
 // Flow graph endpoints and edges
 typedef std::pair<gr_block_sptr, int> gr_endpoint_t;
@@ -67,7 +67,9 @@
     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);
+    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;
@@ -87,7 +89,7 @@
     
     // more disconnect convenience functions go here
     
-    gr_partitions_t calc_partitions();
+    gr_block_vector_vector_t calc_partitions();
 
     void start();
     void stop();

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-15 00:01:00 UTC (rev 3789)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
  2006-10-15 20:03:43 UTC (rev 3790)
@@ -29,7 +29,7 @@
 
 gr_scheduler::gr_scheduler(gr_flow_graph_sptr fg)
 {
-    d_partitions = fg->calc_partitions();
+    d_graphs = fg->calc_partitions();
 }
 
 gr_scheduler::~gr_scheduler()

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-15 00:01:00 UTC (rev 3789)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
   2006-10-15 20:03:43 UTC (rev 3790)
@@ -33,7 +33,7 @@
 class gr_scheduler
 {
 private:
-    gr_partitions_t d_partitions;
+    gr_block_vector_vector_t d_graphs;
 
     gr_scheduler(gr_flow_graph_sptr fg);
     friend gr_scheduler_sptr gr_make_scheduler(gr_flow_graph_sptr fg);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]