gr-osmosdr/lib/runtime/block_registry.cc

112 lines
2.9 KiB
C++

/* -*- c++ -*- */
/*
* Copyright 2012-2013 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 3, 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 <gnuradio/basic_block.h>
#include <gnuradio/block.h>
#include <gnuradio/block_detail.h>
#include <gnuradio/block_registry.h>
#include <gnuradio/tpb_detail.h>
#include <stdio.h>
gr::block_registry global_block_registry;
namespace gr {
block_registry::block_registry()
{
}
long
block_registry::block_register(basic_block* block)
{
gr::thread::scoped_lock guard(d_mutex);
if(d_map.find(block->name()) == d_map.end()) {
d_map[block->name()] = blocksubmap_t();
d_map[block->name()][0] = block;
return 0;
}
else {
for(size_t i=0; i<=d_map[block->name()].size(); i++){
if(d_map[block->name()].find(i) == d_map[block->name()].end()){
d_map[block->name()][i] = block;
return i;
}
}
}
throw std::runtime_error("should not reach this");
}
void
block_registry::block_unregister(basic_block* block)
{
gr::thread::scoped_lock guard(d_mutex);
d_map[block->name()].erase( d_map[block->name()].find(block->symbolic_id()));
}
std::string
block_registry::register_symbolic_name(basic_block* block)
{
std::stringstream ss;
ss << block->name() << block->symbolic_id();
//std::cout << "register_symbolic_name: " << ss.str() << std::endl;
register_symbolic_name(block, ss.str());
return ss.str();
}
void
block_registry::register_symbolic_name(basic_block* block, std::string name)
{
gr::thread::scoped_lock guard(d_mutex);
}
void
block_registry::register_primitive(std::string blk, block* ref)
{
gr::thread::scoped_lock guard(d_mutex);
primitive_map[blk] = ref;
}
void
block_registry::unregister_primitive(std::string blk)
{
gr::thread::scoped_lock guard(d_mutex);
primitive_map.erase(primitive_map.find(blk));
}
void
block_registry::notify_blk(std::string blk)
{
gr::thread::scoped_lock guard(d_mutex);
if(primitive_map.find(blk) == primitive_map.end()) {
return;
}
if(primitive_map[blk]->detail().get())
primitive_map[blk]->detail()->d_tpb.notify_msg();
}
} /* namespace gr */