Changeset 3959

Show
Ignore:
Timestamp:
11/08/06 15:15:01
Author:
jcorgan
Message:

Work in progress.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.cc

    r3954 r3959  
    5858    return shared_from_this(); 
    5959} 
    60  
    61 // default implementation 
    62  
    63 bool 
    64 gr_basic_block::check_topology(int ninputs, int noutputs) 
    65 { 
    66     return true; 
    67 } 
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.h

    r3954 r3959  
    6161    } 
    6262 
     63    //! overridden in gr_block and gr_hier_block2 for type sepcific behavior 
     64    virtual bool validate() { return true; } 
     65 
    6366public: 
    6467    virtual ~gr_basic_block(); 
     
    8285     * and output gr_io_signatures. 
    8386     */ 
    84     virtual bool check_topology (int ninputs, int noutputs); 
     87    virtual bool check_topology(int ninputs, int noutputs) { return true; } 
    8588}; 
    8689 
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_block.h

    r3954 r3959  
    198198  bool                  d_fixed_rate; 
    199199 
    200    
     200  // Overrides gr_basic_block 
     201  bool validate() { return true; }              // Nothing to do 
     202     
    201203 protected: 
    202204 
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.cc

    r3953 r3959  
    9898    d_impl->d_connections.push_back(connection); 
    9999} 
     100 
     101bool 
     102gr_hier_block2::validate() 
     103{ 
     104    d_impl->validate(); 
     105} 
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.h

    r3953 r3959  
    6161    void connect(const std::string src_name, int src_port,  
    6262                 const std::string dst_name, int dst_port); 
     63 
     64    // Overrides gr_basic_block, performs recursive validation of connections 
     65    bool validate(); 
    6366}; 
    6467 
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.i

    r3953 r3959  
    5353                 const std::string dst_name, int dst_port) 
    5454        throw (std::invalid_argument); 
     55    bool validate(); 
    5556}; 
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.cc

    r3953 r3959  
    2424#include "config.h" 
    2525#endif 
     26 
     27#define GR_HIER_BLOCK2_IMPL_DEBUG 1 
    2628 
    2729#include <gr_hier_block2_impl.h> 
     
    106108        throw std::invalid_argument("type mismatch"); 
    107109} 
     110 
     111void 
     112gr_hier_block2_impl::validate() 
     113{ 
     114    if (GR_HIER_BLOCK2_IMPL_DEBUG) 
     115        std::cout << "gr_hier_block2_impl::validate()" << std::endl; 
     116 
     117    /* General strategy for validating a hierarchical tree 
     118 
     119        The runtime will call this function with the top block, which is a  
     120        hierarchical block. 
     121         
     122        At each level in the hierarchy, one must ensure: 
     123         
     124        1. Each hierarchical block has its inputs and outputs wired to  
     125           its components 
     126        2. Each component (via check_topology) "agrees" with its number of ports 
     127        3. Each component has its input ports contiguously assigned 
     128        4. Each component has between min and max number of inputs connected 
     129        5. Each component has its output ports contiguously assigned 
     130        6. Each component has between min and max number of outputs connected 
     131         
     132        Within the context of a hierarchical block, the current connnection list 
     133        provides enough information to check criteria #1 for oneself and #2-#6  
     134        for all one's sub-components. So the recursive means to accomplish this  
     135        is: 
     136         
     137        1. When called, check the above criteria #1 for oneself 
     138        2. For each unique block in the connection list, check criteria #2-#6 
     139        3. For each hierarchical block in the connection list, recurse into its  
     140           validate() 
     141         
     142        To simplify step 3, the validate() function is defined as virtual in  
     143        gr_basic_block, as that is what we hold shared pointers to.  We call  
     144        validate() on all unique blocks in the current edge list.  If they are  
     145        hierarchical blocks, we end up here. The validate() function in gr_block 
     146        is a stub returning 'true', as there is nothing to check for in a  
     147        leaf block that isn't covered by 'check_topology' that gets called back 
     148        in step 2. 
     149     
     150    */ 
     151} 
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.h

    r3953 r3959  
    8787    void check_type_match(gr_io_signature_sptr src_sig, int src_port, 
    8888                          gr_io_signature_sptr dst_sig, int dst_port); 
    89                              
     89    void validate(); 
     90                                 
    9091public: 
    9192    ~gr_hier_block2_impl(); 
  • gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc

    r3953 r3959  
    2828 
    2929#include <gr_runtime_impl.h> 
     30#include <gr_hier_block2.h> 
    3031#include <stdexcept> 
    3132#include <iostream> 
    3233 
    3334gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) : 
    34 d_top_block(top_block), 
    35 d_running(false
     35d_running(false), 
     36d_top_block(top_block
    3637{ 
    3738} 
     
    4849 
    4950    if (d_running) 
    50         throw std::runtime_error("Already running"); 
     51        throw std::runtime_error("already running"); 
    5152    else 
    5253        d_running = true; 
    5354 
    54     // Start 
     55    if (!d_top_block->validate()) 
     56        throw std::runtime_error("tree validation failed"); 
    5557} 
    5658