diff options
Diffstat (limited to 'mblock/src/lib')
55 files changed, 0 insertions, 6263 deletions
diff --git a/mblock/src/lib/.gitignore b/mblock/src/lib/.gitignore deleted file mode 100644 index b2a2f45a7..000000000 --- a/mblock/src/lib/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo -/test_mblock -/qa_bitset_mbh.cc -/benchmark_send -/getres diff --git a/mblock/src/lib/Makefile.am b/mblock/src/lib/Makefile.am deleted file mode 100644 index dbdfcdd9d..000000000 --- a/mblock/src/lib/Makefile.am +++ /dev/null @@ -1,132 +0,0 @@ -# -# Copyright 2006,2007,2008,2009 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 $(top_srcdir)/Makefile.common - -AM_CPPFLAGS = $(DEFINES) $(OMNITHREAD_INCLUDES) $(GRUEL_INCLUDES) \ - $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) \ - $(MBLOCK_INCLUDES) - -# disable test until we fix ticket:180 -# TESTS = test_mblock - -lib_LTLIBRARIES = libmblock.la libmblock-qa.la - -EXTRA_DIST = \ - README.locking \ - qa_bitset.mbh - - -BUILT_SOURCES = \ - qa_bitset_mbh.cc - -qa_bitset_mbh.cc : qa_bitset.mbh - $(COMPILE_MBH) $(srcdir)/qa_bitset.mbh qa_bitset_mbh.cc - -# These are the source files that go into the mblock shared library -libmblock_la_SOURCES = \ - mb_class_registry.cc \ - mb_connection.cc \ - mb_endpoint.cc \ - mb_exception.cc \ - mb_gettid.cc \ - mb_mblock.cc \ - mb_mblock_impl.cc \ - mb_message.cc \ - mb_msg_accepter.cc \ - mb_msg_accepter_msgq.cc \ - mb_msg_accepter_smp.cc \ - mb_msg_queue.cc \ - mb_port.cc \ - mb_port_simple.cc \ - mb_protocol_class.cc \ - mb_runtime.cc \ - mb_runtime_base.cc \ - mb_runtime_nop.cc \ - mb_runtime_thread_per_block.cc \ - mb_timer_queue.cc \ - mb_util.cc \ - mb_worker.cc - - -# magic flags -libmblock_la_LDFLAGS = $(NO_UNDEFINED) - -# link the library against the c++ standard library -libmblock_la_LIBADD = \ - $(OMNITHREAD_LA) \ - $(GRUEL_LA) \ - -lstdc++ - -noinst_HEADERS = \ - mb_gettid.h \ - mb_msg_accepter_msgq.h \ - mb_port_simple.h \ - mb_util.h \ - mb_connection.h \ - mb_endpoint.h \ - mb_mblock_impl.h \ - mb_msg_accepter_smp.h \ - mb_runtime_base.h \ - mb_runtime_nop.h \ - mb_runtime_thread_per_block.h \ - mb_timer_queue.h \ - mb_worker.h \ - mbi_runtime_lock.h \ - qa_mblock.h \ - qa_mblock_prims.h \ - qa_mblock_send.h \ - qa_mblock_sys.h \ - qa_timeouts.h - - -# Build the qa code into its own library - -libmblock_qa_la_SOURCES = \ - qa_bitset.cc \ - qa_bitset_mbh.cc \ - qa_disconnect.cc \ - qa_mblock.cc \ - qa_mblock_prims.cc \ - qa_mblock_send.cc \ - qa_mblock_sys.cc \ - qa_timeouts.cc - - -# magic flags -libmblock_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid-version - -# link the library against the c++ standard library -libmblock_qa_la_LIBADD = \ - libmblock.la \ - $(CPPUNIT_LIBS) \ - -lstdc++ - - -noinst_PROGRAMS = \ - test_mblock \ - benchmark_send - -test_mblock_SOURCES = test_mblock.cc -test_mblock_LDADD = libmblock-qa.la - -benchmark_send_SOURCES = benchmark_send.cc -benchmark_send_LDADD = libmblock-qa.la diff --git a/mblock/src/lib/README.locking b/mblock/src/lib/README.locking deleted file mode 100644 index 12d4735e7..000000000 --- a/mblock/src/lib/README.locking +++ /dev/null @@ -1,4 +0,0 @@ -The Big Runtime Lock must be held when: - -Manipulating or traversing any mblock's d_port_map, d_comp_map or d_conn_table. - diff --git a/mblock/src/lib/benchmark_send.cc b/mblock/src/lib/benchmark_send.cc deleted file mode 100644 index a02b37c0d..000000000 --- a/mblock/src/lib/benchmark_send.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <mblock/runtime.h> -#include <iostream> - -using namespace pmt; - -int -main(int argc, char **argv) -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - long nmsgs = 1000000; - long batch_size = 100; - - pmt_t arg = pmt_list2(pmt_from_long(nmsgs), // # of messages to send through pipe - pmt_from_long(batch_size)); - - rt->run("top", "qa_bitset_top", arg, &result); - - if (!pmt_equal(PMT_T, result)){ - std::cerr << "benchmark_send: incorrect result"; - return 1; - } - - return 0; -} diff --git a/mblock/src/lib/getres.cc b/mblock/src/lib/getres.cc deleted file mode 100644 index c05ba792a..000000000 --- a/mblock/src/lib/getres.cc +++ /dev/null @@ -1,32 +0,0 @@ -#include <time.h> -#include <stdio.h> - -int -main(int argc, char **argv) -{ - bool ok = true; - struct timespec ts; - int r; - - r = clock_getres(CLOCK_REALTIME, &ts); - if (r != 0){ - perror("clock_getres(CLOCK_REALTIME, ...)"); - ok = false; - } - else - printf("clock_getres(CLOCK_REALTIME, ...) => %11.9f\n", - (double) ts.tv_sec + ts.tv_nsec * 1e-9); - - - r = clock_getres(CLOCK_MONOTONIC, &ts); - if (r != 0){ - perror("clock_getres(CLOCK_MONOTONIC, ..."); - ok = false; - } - else - printf("clock_getres(CLOCK_MONOTONIC, ...) => %11.9f\n", - (double) ts.tv_sec + ts.tv_nsec * 1e-9); - - - return ok == true ? 0 : 1; -} diff --git a/mblock/src/lib/mb_class_registry.cc b/mblock/src/lib/mb_class_registry.cc deleted file mode 100644 index 7ccee2969..000000000 --- a/mblock/src/lib/mb_class_registry.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/class_registry.h> -#include <map> - -static std::map<std::string, mb_mblock_maker_t> s_registry; - -bool -mb_class_registry::register_maker(const std::string &name, mb_mblock_maker_t maker) -{ - s_registry[name] = maker; - return true; -} - -bool -mb_class_registry::lookup_maker(const std::string &name, mb_mblock_maker_t *maker) -{ - if (s_registry.count(name) == 0){ // not registered - *maker = (mb_mblock_maker_t) 0; - return false; - } - - *maker = s_registry[name]; - return true; -} diff --git a/mblock/src/lib/mb_connection.cc b/mblock/src/lib/mb_connection.cc deleted file mode 100644 index 7e3bb8977..000000000 --- a/mblock/src/lib/mb_connection.cc +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mb_connection.h> - -bool -mb_conn_table::lookup_conn_by_name(const std::string &component_name, - const std::string &port_name, - mb_conn_iter *itp, int *which_ep) -{ - mb_conn_iter end = d_connections.end(); - for (mb_conn_iter it = d_connections.begin(); it != end; ++it){ - - if (it->d_ep[0].component_name() == component_name - && it->d_ep[0].port_name() == port_name){ - *itp = it; - *which_ep = 0; - return true; - } - - if (it->d_ep[1].component_name() == component_name - && it->d_ep[1].port_name() == port_name){ - *itp = it; - *which_ep = 1; - return true; - } - } - - return false; -} - -bool -mb_conn_table::lookup_conn_by_port(const mb_port *port, - mb_conn_iter *itp, int *which_ep) -{ - mb_conn_iter end = d_connections.end(); - for (mb_conn_iter it = d_connections.begin(); it != end; ++it){ - if (it->d_ep[0].port().get() == port){ - *itp = it; - *which_ep = 0; - return true; - } - if (it->d_ep[1].port().get() == port){ - *itp = it; - *which_ep = 1; - return true; - } - } - - return false; -} - -void -mb_conn_table::create_conn(const mb_endpoint &ep0, const mb_endpoint &ep1) -{ - d_connections.push_back(mb_connection(ep0, ep1)); -} - -void -mb_conn_table::disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2) -{ - mb_conn_iter it; - int which_ep; - - // look for comp_name1/port_name1 - bool found = lookup_conn_by_name(comp_name1, port_name1, &it, &which_ep); - - if (!found) // no error if not found - return; - - // FIXME if/when we do replicated ports, we may have one-to-many, - // or many-to-many bindings. For now, be paranoid - assert(it->d_ep[which_ep^1].component_name() == comp_name2); - assert(it->d_ep[which_ep^1].port_name() == port_name2); - - d_connections.erase(it); // Poof! -} - -void -mb_conn_table::disconnect_component(const std::string component_name) -{ - mb_conn_iter next; - mb_conn_iter end = d_connections.end(); - for (mb_conn_iter it = d_connections.begin(); it != end; it = next){ - if (it->d_ep[0].component_name() == component_name - || it->d_ep[1].component_name() == component_name) - next = d_connections.erase(it); // Poof! - else - next = ++it; - } -} - -void -mb_conn_table::disconnect_all() -{ - d_connections.clear(); // All gone! -} - -int -mb_conn_table::nconnections() const -{ - return d_connections.size(); -} diff --git a/mblock/src/lib/mb_connection.h b/mblock/src/lib/mb_connection.h deleted file mode 100644 index 2aa604054..000000000 --- a/mblock/src/lib/mb_connection.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_CONNECTION_H -#define INCLUDED_MB_CONNECTION_H - -#include <mb_endpoint.h> -#include <list> - -/*! - * \brief Representation of a connection - */ -struct mb_connection { - mb_endpoint d_ep[2]; - - mb_connection(const mb_endpoint &ep0, const mb_endpoint &ep1){ - d_ep[0] = ep0; - d_ep[1] = ep1; - } -}; - -typedef std::list<mb_connection>::iterator mb_conn_iter; -typedef std::list<mb_connection>::const_iterator mb_conn_const_iter; - -/*! - * \brief data structure that keeps track of connections - */ -class mb_conn_table { - std::list<mb_connection> d_connections; - -public: - bool - lookup_conn_by_name(const std::string &component_name, - const std::string &port_name, - mb_conn_iter *it, int *which_ep); - - bool - lookup_conn_by_port(const mb_port *port, - mb_conn_iter *it, int *which_ep); - - void - create_conn(const mb_endpoint &ep0, const mb_endpoint &ep1); - - - void - disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2); - - void - disconnect_component(const std::string component_name); - - void - disconnect_all(); - - int - nconnections() const; - -}; - -#endif /* INCLUDED_MB_CONNECTION_H */ diff --git a/mblock/src/lib/mb_endpoint.cc b/mblock/src/lib/mb_endpoint.cc deleted file mode 100644 index 721c66b8c..000000000 --- a/mblock/src/lib/mb_endpoint.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_endpoint.h> - -using namespace pmt; - -bool -mb_endpoint::inside_of_relay_port_p() const -{ - return d_port->port_type() == mb_port::RELAY && d_component_name == "self"; -} - -pmt_t -mb_endpoint::incoming_message_set() const -{ - if (inside_of_relay_port_p()) // swap incoming and outgoing - return port()->outgoing_message_set(); - else - return port()->incoming_message_set(); -} - -pmt_t -mb_endpoint::outgoing_message_set() const -{ - if (inside_of_relay_port_p()) // swap incoming and outgoing - return port()->incoming_message_set(); - else - return port()->outgoing_message_set(); -} diff --git a/mblock/src/lib/mb_endpoint.h b/mblock/src/lib/mb_endpoint.h deleted file mode 100644 index c4d8b6114..000000000 --- a/mblock/src/lib/mb_endpoint.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_ENDPOINT_H -#define INCLUDED_MB_ENDPOINT_H - -#include <string> -#include <mblock/port.h> - -/*! - * \brief Endpoint specification for connection - */ -class mb_endpoint -{ - std::string d_component_name; - std::string d_port_name; - mb_port_sptr d_port; // the port object that this maps to - -public: - mb_endpoint(){} - - mb_endpoint(const std::string &component_name, - const std::string &port_name, - mb_port_sptr port) - : d_component_name(component_name), - d_port_name(port_name), - d_port(port) {} - - const std::string &component_name() const { return d_component_name; } - const std::string &port_name() const { return d_port_name; } - mb_port_sptr port() const { return d_port; } - - //! Does this endpoint represent the inside of a relay port - bool inside_of_relay_port_p() const; - - pmt::pmt_t incoming_message_set() const; - pmt::pmt_t outgoing_message_set() const; -}; - -#endif /* INCLUDED_MB_ENDPOINT_H */ diff --git a/mblock/src/lib/mb_exception.cc b/mblock/src/lib/mb_exception.cc deleted file mode 100644 index 810131840..000000000 --- a/mblock/src/lib/mb_exception.cc +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/exception.h> -#include <mblock/mblock.h> -#include <mb_util.h> - - -mbe_base::mbe_base(mb_mblock *mb, const std::string &msg) - : logic_error(msg) // FIXME extract block class name and id and add to msg -{ -} - -mbe_not_implemented::mbe_not_implemented(mb_mblock *mb, const std::string &msg) - : mbe_base(mb, "Not implemented: " + msg) -{ -} - -mbe_no_such_class::mbe_no_such_class(mb_mblock *mb, const std::string &class_name) - : mbe_base(mb, "No such class: " + class_name) -{ -} - -mbe_no_such_component::mbe_no_such_component(mb_mblock *mb, const std::string &component_name) - : mbe_base(mb, "No such component: " + component_name) -{ -} - - -mbe_duplicate_component::mbe_duplicate_component(mb_mblock *mb, const std::string &component_name) - : mbe_base(mb, "Duplicate component: " + component_name) -{ -} - -mbe_no_such_port::mbe_no_such_port(mb_mblock *mb, const std::string &port_name) - : mbe_base(mb, "No such port: " + port_name) -{ -} - -mbe_duplicate_port::mbe_duplicate_port(mb_mblock *mb, const std::string &port_name) - : mbe_base(mb, "Duplicate port: " + port_name) -{ -} - -mbe_already_connected::mbe_already_connected(mb_mblock *mb, - const std::string &comp_name, - const std::string &port_name) - : mbe_base(mb, "Port already connected: " + mb_util::join_names(comp_name, port_name)) -{ -} - - - -mbe_incompatible_ports::mbe_incompatible_ports(mb_mblock *mb, - const std::string &comp1_name, - const std::string &port1_name, - const std::string &comp2_name, - const std::string &port2_name) - : mbe_base(mb, "Incompatible ports: " - + mb_util::join_names(comp1_name, port1_name) + " " - + mb_util::join_names(comp2_name, port2_name)) -{ -} - -mbe_invalid_port_type::mbe_invalid_port_type(mb_mblock *mb, - const std::string &comp_name, - const std::string &port_name) - : mbe_base(mb, "Invalid port type for connection: " + mb_util::join_names(comp_name, port_name)) -{ -} - -mbe_mblock_failed::mbe_mblock_failed(mb_mblock *mb, - const std::string &msg) - : mbe_base(mb, "Message block failed: " + msg) -{ -} - -mbe_terminate::mbe_terminate() -{ -} - -mbe_exit::mbe_exit() -{ -} diff --git a/mblock/src/lib/mb_gettid.cc b/mblock/src/lib/mb_gettid.cc deleted file mode 100644 index 9383d35ac..000000000 --- a/mblock/src/lib/mb_gettid.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_gettid.h> - -#define NEED_STUB - -#if defined(HAVE_SYS_SYSCALL_H) && defined(HAVE_UNISTD_H) - -#include <sys/syscall.h> -#include <unistd.h> - -#if defined(SYS_gettid) -#undef NEED_STUB - -int mb_gettid() -{ - return syscall(SYS_gettid); -} - -#endif -#endif - -#if defined(NEED_STUB) - -int -mb_gettid() -{ - return 0; -} - -#endif diff --git a/mblock/src/lib/mb_gettid.h b/mblock/src/lib/mb_gettid.h deleted file mode 100644 index adbad126c..000000000 --- a/mblock/src/lib/mb_gettid.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/*! - * \brief Return Linux taskid, or 0 if not available - */ -int mb_gettid(); - diff --git a/mblock/src/lib/mb_mblock.cc b/mblock/src/lib/mb_mblock.cc deleted file mode 100644 index 2e77dc4af..000000000 --- a/mblock/src/lib/mb_mblock.cc +++ /dev/null @@ -1,230 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mb_mblock_impl.h> -#include <mblock/runtime.h> -#include <mblock/exception.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_sys_port = pmt_intern("%sys-port"); -static pmt_t s_halt = pmt_intern("%halt"); - -mb_visitor::~mb_visitor() -{ - // nop base case for virtual destructor. -} - - -mb_mblock::mb_mblock(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : d_impl(mb_mblock_impl_sptr( - new mb_mblock_impl(dynamic_cast<mb_runtime_base*>(runtime), - this, instance_name))) -{ -} - -mb_mblock::~mb_mblock() -{ -} - - -void -mb_mblock::initial_transition() -{ - // default implementation does nothing -} - -void -mb_mblock::handle_message(mb_message_sptr msg) -{ - // default implementation does nothing -} - - -void -mb_mblock::main_loop() -{ - while (1){ - mb_message_sptr msg; - try { - while (1){ - msg = impl()->msgq().get_highest_pri_msg(); - - // check for %halt from %sys-port - if (pmt_eq(msg->port_id(), s_sys_port) && pmt_eq(msg->signal(), s_halt)) - exit(); - - handle_message(msg); - } - } - catch (pmt_exception e){ - std::cerr << "\nmb_mblock::main_loop: ignored pmt_exception: " - << e.what() - << "\nin mblock instance \"" << instance_name() - << "\" while handling message:" - << "\n port_id = " << msg->port_id() - << "\n signal = " << msg->signal() - << "\n data = " << msg->data() - << "\n metatdata = " << msg->metadata() << std::endl; - } - } -} - -//////////////////////////////////////////////////////////////////////// -// Forward other methods to implementation class // -//////////////////////////////////////////////////////////////////////// - -mb_port_sptr -mb_mblock::define_port(const std::string &port_name_string, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type) -{ - return d_impl->define_port(port_name_string, protocol_class_name, - conjugated, port_type); -} - -void -mb_mblock::define_component(const std::string &component_name, - const std::string &class_name, - pmt_t user_arg) - -{ - d_impl->define_component(component_name, class_name, user_arg); -} - -void -mb_mblock::connect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2) -{ - d_impl->connect(comp_name1, port_name1, - comp_name2, port_name2); -} - - -void -mb_mblock::disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2) -{ - d_impl->disconnect(comp_name1, port_name1, - comp_name2, port_name2); -} - -void -mb_mblock::disconnect_component(const std::string &component_name) -{ - d_impl->disconnect_component(component_name); -} - -void -mb_mblock::disconnect_all() -{ - d_impl->disconnect_all(); -} - -int -mb_mblock::nconnections() const -{ - return d_impl->nconnections(); -} - -bool -mb_mblock::walk_tree(mb_visitor *visitor) -{ - return d_impl->walk_tree(visitor); -} - -std::string -mb_mblock::instance_name() const -{ - return d_impl->instance_name(); -} - -void -mb_mblock::set_instance_name(const std::string &name) -{ - d_impl->set_instance_name(name); -} - -std::string -mb_mblock::class_name() const -{ - return d_impl->class_name(); -} - -void -mb_mblock::set_class_name(const std::string &name) -{ - d_impl->set_class_name(name); -} - -mb_mblock * -mb_mblock::parent() const -{ - return d_impl->mblock_parent(); -} - -void -mb_mblock::exit() -{ - throw mbe_exit(); // adios... -} - -void -mb_mblock::shutdown_all(pmt_t result) -{ - d_impl->runtime()->request_shutdown(result); -} - -pmt_t -mb_mblock::schedule_one_shot_timeout(const mb_time &abs_time, pmt_t user_data) -{ - mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port); - return d_impl->runtime()->schedule_one_shot_timeout(abs_time, user_data, - accepter); -} - -pmt_t -mb_mblock::schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt_t user_data) -{ - mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port); - return d_impl->runtime()->schedule_periodic_timeout(first_abs_time, - delta_time, - user_data, - accepter); -} - -void -mb_mblock::cancel_timeout(pmt_t handle) -{ - d_impl->runtime()->cancel_timeout(handle); -} - diff --git a/mblock/src/lib/mb_mblock_impl.cc b/mblock/src/lib/mb_mblock_impl.cc deleted file mode 100644 index 8a1784f4d..000000000 --- a/mblock/src/lib/mb_mblock_impl.cc +++ /dev/null @@ -1,328 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_mblock_impl.h> -#include <mblock/mblock.h> -#include <mblock/protocol_class.h> -#include <mblock/port.h> -#include <mb_port_simple.h> -#include <mblock/exception.h> -#include <mb_util.h> -#include <mb_msg_accepter_smp.h> -#include <mbi_runtime_lock.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_self = pmt_intern("self"); - -//////////////////////////////////////////////////////////////////////// - -bool -mb_mblock_impl::port_is_defined(const std::string &name) -{ - return d_port_map.count(name) != 0; -} - -bool -mb_mblock_impl::comp_is_defined(const std::string &name) -{ - return name == "self" || d_comp_map.count(name) != 0; -} - -//////////////////////////////////////////////////////////////////////// - -mb_mblock_impl::mb_mblock_impl(mb_runtime_base *runtime, mb_mblock *mb, - const std::string &instance_name) - : d_runtime(runtime), d_mb(mb), d_mb_parent(0), - d_instance_name(instance_name), d_class_name("mblock") -{ -} - -mb_mblock_impl::~mb_mblock_impl() -{ - d_mb = 0; // we don't own it -} - - -mb_port_sptr -mb_mblock_impl::define_port(const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type) -{ - mbi_runtime_lock l(this); - - if (port_is_defined(port_name)) - throw mbe_duplicate_port(d_mb, port_name); - - mb_port_sptr p = - mb_port_sptr(new mb_port_simple(d_mb, - port_name, protocol_class_name, - conjugated, port_type)); - d_port_map[port_name] = p; - return p; -} - -void -mb_mblock_impl::define_component(const std::string &name, - const std::string &class_name, - pmt_t user_arg) -{ - { - mbi_runtime_lock l(this); - - if (comp_is_defined(name)) // check for duplicate name - throw mbe_duplicate_component(d_mb, name); - } - - // We ask the runtime to create the component so that it can worry about - // mblock placement on a NUMA machine or on a distributed multicomputer - - mb_mblock_sptr component = - d_runtime->create_component(instance_name() + "/" + name, - class_name, user_arg); - { - mbi_runtime_lock l(this); - - component->d_impl->d_mb_parent = d_mb; // set component's parent link - d_comp_map[name] = component; - } -} - -void -mb_mblock_impl::connect(const std::string &comp_name1, - const std::string &port_name1, - const std::string &comp_name2, - const std::string &port_name2) -{ - mbi_runtime_lock l(this); - - mb_endpoint ep0 = check_and_resolve_endpoint(comp_name1, port_name1); - mb_endpoint ep1 = check_and_resolve_endpoint(comp_name2, port_name2); - - if (!endpoints_are_compatible(ep0, ep1)) - throw mbe_incompatible_ports(d_mb, - comp_name1, port_name1, - comp_name2, port_name2); - // FIXME more checks? - - d_conn_table.create_conn(ep0, ep1); -} - -void -mb_mblock_impl::disconnect(const std::string &comp_name1, - const std::string &port_name1, - const std::string &comp_name2, - const std::string &port_name2) -{ - mbi_runtime_lock l(this); - - d_conn_table.disconnect(comp_name1, port_name1, comp_name2, port_name2); - invalidate_all_port_caches(); -} - -void -mb_mblock_impl::disconnect_component(const std::string component_name) -{ - mbi_runtime_lock l(this); - - d_conn_table.disconnect_component(component_name); - invalidate_all_port_caches(); -} - -void -mb_mblock_impl::disconnect_all() -{ - mbi_runtime_lock l(this); - - d_conn_table.disconnect_all(); - invalidate_all_port_caches(); -} - -int -mb_mblock_impl::nconnections() -{ - mbi_runtime_lock l(this); - - return d_conn_table.nconnections(); -} - -//////////////////////////////////////////////////////////////////////// - -mb_endpoint -mb_mblock_impl::check_and_resolve_endpoint(const std::string &comp_name, - const std::string &port_name) -{ - mb_conn_iter it; - int which_ep; - mb_port_sptr port = resolve_port(comp_name, port_name); - - // Confirm that we're not trying to connect to the inside of one of - // our EXTERNAL ports. Connections that include "self" as the - // component name must be either INTERNAL or RELAY. - - if (comp_name == "self" && port->port_type() == mb_port::EXTERNAL) - throw mbe_invalid_port_type(d_mb, comp_name, port_name); - - // Is this endpoint already connected? - if (d_conn_table.lookup_conn_by_name(comp_name, port_name, &it, &which_ep)) - throw mbe_already_connected(d_mb, comp_name, port_name); - - return mb_endpoint(comp_name, port_name, port); -} - -mb_port_sptr -mb_mblock_impl::resolve_port(const std::string &comp_name, - const std::string &port_name) -{ - if (comp_name == "self"){ - // Look through our ports. - if (!port_is_defined(port_name)) - throw mbe_no_such_port(d_mb, mb_util::join_names("self", port_name)); - return d_port_map[port_name]; - } - else { - // Look through the specified child's ports. - if (!comp_is_defined(comp_name)) - throw mbe_no_such_component(d_mb, comp_name); - - mb_mblock_impl_sptr c_impl = d_comp_map[comp_name]->d_impl; // childs impl pointer - if (!c_impl->port_is_defined(port_name)) - throw mbe_no_such_port(d_mb, mb_util::join_names(comp_name, port_name)); - - mb_port_sptr c_port = c_impl->d_port_map[port_name]; - - if (c_port->port_type() == mb_port::INTERNAL) // can't "see" a child's internal ports - throw mbe_no_such_port(d_mb, mb_util::join_names(comp_name, port_name)); - - return c_port; - } -} - - - -bool -mb_mblock_impl::endpoints_are_compatible(const mb_endpoint &ep0, - const mb_endpoint &ep1) -{ - pmt_t p0_outgoing = ep0.outgoing_message_set(); - pmt_t p0_incoming = ep0.incoming_message_set(); - - pmt_t p1_outgoing = ep1.outgoing_message_set(); - pmt_t p1_incoming = ep1.incoming_message_set(); - - return (pmt_subsetp(p0_outgoing, p1_incoming) - && pmt_subsetp(p1_outgoing, p0_incoming)); -} - -bool -mb_mblock_impl::walk_tree(mb_visitor *visitor) -{ - if (!(*visitor)(d_mb)) - return false; - - mb_comp_map_t::iterator it; - for (it = d_comp_map.begin(); it != d_comp_map.end(); ++it) - if (!(it->second->walk_tree(visitor))) - return false; - - return true; -} - -mb_msg_accepter_sptr -mb_mblock_impl::make_accepter(pmt_t port_name) -{ - // FIXME this should probably use some kind of configurable factory - mb_msg_accepter *ma = - new mb_msg_accepter_smp(d_mb->shared_from_this(), port_name); - - return mb_msg_accepter_sptr(ma); -} - -bool -mb_mblock_impl::lookup_other_endpoint(const mb_port *port, mb_endpoint *ep) -{ - mb_conn_iter it; - int which_ep = 0; - - if (!d_conn_table.lookup_conn_by_port(port, &it, &which_ep)) - return false; - - *ep = it->d_ep[which_ep^1]; - return true; -} - -mb_mblock_sptr -mb_mblock_impl::component(const std::string &comp_name) -{ - if (comp_name == "self") - return d_mb->shared_from_this(); - - if (d_comp_map.count(comp_name) == 0) - return mb_mblock_sptr(); // null pointer - - return d_comp_map[comp_name]; -} - -void -mb_mblock_impl::set_instance_name(const std::string &name) -{ - d_instance_name = name; -} - -void -mb_mblock_impl::set_class_name(const std::string &name) -{ - d_class_name = name; -} - -/* - * This is the "Big Hammer" port cache invalidator. - * It invalidates _all_ of the port caches in the entire mblock tree. - * It's overkill, but was simple to code. - */ -void -mb_mblock_impl::invalidate_all_port_caches() -{ - class invalidator : public mb_visitor - { - public: - bool operator()(mb_mblock *mblock) - { - mb_mblock_impl_sptr impl = mblock->impl(); - mb_port_map_t::iterator it = impl->d_port_map.begin(); - mb_port_map_t::iterator end = impl->d_port_map.end(); - for (; it != end; ++it) - it->second->invalidate_cache(); - return true; - } - }; - - invalidator visitor; - - // Always true, except in early QA code - if (runtime()->top()) - runtime()->top()->walk_tree(&visitor); -} diff --git a/mblock/src/lib/mb_mblock_impl.h b/mblock/src/lib/mb_mblock_impl.h deleted file mode 100644 index f460ecc5b..000000000 --- a/mblock/src/lib/mb_mblock_impl.h +++ /dev/null @@ -1,226 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MBLOCK_IMPL_H -#define INCLUDED_MB_MBLOCK_IMPL_H - -#include <mblock/mblock.h> -#include <mb_runtime_base.h> -#include <mb_connection.h> -#include <mblock/msg_queue.h> -#include <list> -#include <map> - - -typedef std::map<std::string, mb_port_sptr> mb_port_map_t; -typedef std::map<std::string, mb_mblock_sptr> mb_comp_map_t; - - -/*! - * \brief The private implementation details of the mblock system. - */ -class mb_mblock_impl : boost::noncopyable -{ - mb_runtime_base *d_runtime; // pointer to runtime - mb_mblock *d_mb; // pointer to our associated mblock - mb_mblock *d_mb_parent; // pointer to our parent - - std::string d_instance_name; // hierarchical name - std::string d_class_name; // name of this (derived) class - - mb_port_map_t d_port_map; // our ports - mb_comp_map_t d_comp_map; // our components - mb_conn_table d_conn_table; // our connections - - mb_msg_queue d_msgq; // incoming messages for us - -public: - mb_mblock_impl(mb_runtime_base *runtime, mb_mblock *mb, - const std::string &instance_name); - ~mb_mblock_impl(); - - /*! - * \brief Define a port. - * - * EXTERNAL and RELAY ports are part of our peer interface. - * INTERNAL ports are used to talk to sub-components. - * - * \param port_name The name of the port (must be unique within this mblock). - * \param protocol_class_name The name of the protocol class associated with - * this port. It must already be defined. - * \param conjugated Are the incoming and outgoing message sets swapped? - * \param port_type INTERNAL, EXTERNAL or RELAY. - */ - mb_port_sptr - define_port(const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type); - - /*! - * \brief Define a subcomponent by name. - * - * Called within the constructor to tell the system the - * names and identities of our sub-component mblocks. - * - * \param component_name The name of the sub-component (must be unique with this mblock). - * \param class_name The class of the instance that is to be created. - * \param user_arg The argument to pass to the constructor of the component. - */ - void - define_component(const std::string &component_name, - const std::string &class_name, - pmt::pmt_t user_arg); - - /*! - * \brief connect endpoint_1 to endpoint_2 - * - * \param comp_name1 component on one end of the connection - * \param port_name1 the name of the port on comp1 - * \param comp_name2 component on the other end of the connection - * \param port_name2 the name of the port on comp2 - * - * An endpoint is specified by the component's local name (given as - * component_name in the call to register_component) and the name of - * the port on that component. - * - * To connect an internal or relay port, use "self" as the component name. - */ - void - connect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2); - - /*! - * \brief disconnect endpoint_1 from endpoint_2 - * - * \param comp_name1 component on one end of the connection - * \param port_name1 the name of the port on comp1 - * \param comp_name2 component on the other end of the connection - * \param port_name2 the name of the port on comp2 - * - * An endpoint is specified by the component's local name (given as - * component_name in the call to register_component) and the name of - * the port on that component. - * - * To disconnect an internal or relay port, use "self" as the component name. - */ - void - disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2); - - /*! - * \brief disconnect all connections to specified component - * \param component_name component to disconnect - */ - void - disconnect_component(const std::string component_name); - - /*! - * \brief disconnect all connections to all components - */ - void - disconnect_all(); - - /*! - * \brief Return number of connections (QA mostly) - */ - int - nconnections(); - - bool - walk_tree(mb_visitor *visitor); - - mb_msg_accepter_sptr - make_accepter(pmt::pmt_t port_name); - - mb_msg_queue & - msgq() { return d_msgq; } - - //! Return instance name of this block - std::string instance_name() const { return d_instance_name; } - - //! Set the instance name of this block - void set_instance_name(const std::string &name); - - //! Return the class name of this block - std::string class_name() const { return d_class_name; } - - //! Set the class name - void set_class_name(const std::string &name); - - /*! - * \brief If bound, store endpoint from the other end of the connection. - * - * \param port [in] port the port that we're searching for. - * \param ep [out] the other end point from the matching connection. - * - * \returns true iff there's a matching connection. - */ - bool - lookup_other_endpoint(const mb_port *port, mb_endpoint *ep); - - - //! Return point to associated mblock - mb_mblock *mblock() const { return d_mb; } - - //! Return pointer to the parent of our mblock - mb_mblock *mblock_parent() const { return d_mb_parent; } - - //! Lookup a component by name - mb_mblock_sptr component(const std::string &comp_name); - - //! Return the runtime instance - mb_runtime_base *runtime() { return d_runtime; } - - //! Set the runtime instance - void set_runtime(mb_runtime_base *runtime) { d_runtime = runtime; } - - /* - * Our implementation methods - */ -private: - //bool port_is_defined(pmt::pmt_t name); - bool port_is_defined(const std::string &name); - //bool comp_is_defined(pmt::pmt_t name); - bool comp_is_defined(const std::string &name); - - mb_endpoint - check_and_resolve_endpoint(const std::string &comp_name, - const std::string &port_name); - - - mb_port_sptr - resolve_port(const std::string &comp_name, - const std::string &port_name); - - static bool - endpoints_are_compatible(const mb_endpoint &ep0, - const mb_endpoint &ep1); - - /*! - * \brief walk mblock tree and invalidate all port resolution caches. - * \internal - */ - void - invalidate_all_port_caches(); -}; - - -#endif /* INCLUDED_MB_MBLOCK_IMPL_H */ diff --git a/mblock/src/lib/mb_message.cc b/mblock/src/lib/mb_message.cc deleted file mode 100644 index 4daa34079..000000000 --- a/mblock/src/lib/mb_message.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/message.h> -#include <stdio.h> -#include <gruel/pmt_pool.h> - -using namespace pmt; - -static const int CACHE_LINE_SIZE = 64; // good guess -static const int MAX_MESSAGES = 1024; // KLUDGE max number of messages in sys - // 0 -> no limit -#if MB_MESSAGE_LOCAL_ALLOCATOR - -static pmt_pool -global_msg_pool(sizeof(mb_message), CACHE_LINE_SIZE, 16*1024, MAX_MESSAGES); - -void * -mb_message::operator new(size_t size) -{ - void *p = global_msg_pool.malloc(); - - // fprintf(stderr, "mb_message::new p = %p\n", p); - assert((reinterpret_cast<intptr_t>(p) & (CACHE_LINE_SIZE - 1)) == 0); - return p; -} - -void -mb_message::operator delete(void *p, size_t size) -{ - global_msg_pool.free(p); -} - -#endif - - -mb_message_sptr -mb_make_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority) -{ - return mb_message_sptr(new mb_message(signal, data, metadata, priority)); -} - -mb_message::mb_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority) - : d_signal(signal), d_data(data), d_metadata(metadata), d_priority(priority), - d_port_id(PMT_NIL) -{ -} - -mb_message::~mb_message() -{ - // NOP -} - -std::ostream& -operator<<(std::ostream& os, const mb_message &msg) -{ - os << "<msg: signal=" << msg.signal() - << " port_id=" << msg.port_id() - << " data=" << msg.data() - << " metadata=" << msg.metadata() - << " pri=" << msg.priority() - << ">"; - - return os; -} diff --git a/mblock/src/lib/mb_msg_accepter.cc b/mblock/src/lib/mb_msg_accepter.cc deleted file mode 100644 index 88b92394c..000000000 --- a/mblock/src/lib/mb_msg_accepter.cc +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/msg_accepter.h> - -mb_msg_accepter::~mb_msg_accepter() -{ - // nop -} diff --git a/mblock/src/lib/mb_msg_accepter_msgq.cc b/mblock/src/lib/mb_msg_accepter_msgq.cc deleted file mode 100644 index 6c74ac47a..000000000 --- a/mblock/src/lib/mb_msg_accepter_msgq.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_msg_accepter_msgq.h> -#include <mblock/message.h> - -using namespace pmt; - -pmt_t s_sys_port = pmt_intern("%sys-port"); - -mb_msg_accepter_msgq::mb_msg_accepter_msgq(mb_msg_queue *msgq) - : d_msgq(msgq) -{ -} - -mb_msg_accepter_msgq::~mb_msg_accepter_msgq() -{ -} - -void -mb_msg_accepter_msgq::operator()(pmt_t signal, pmt_t data, - pmt_t metadata, mb_pri_t priority) -{ - mb_message_sptr msg = mb_make_message(signal, data, metadata, priority); - msg->set_port_id(s_sys_port); - d_msgq->insert(msg); -} diff --git a/mblock/src/lib/mb_msg_accepter_msgq.h b/mblock/src/lib/mb_msg_accepter_msgq.h deleted file mode 100644 index f84bca596..000000000 --- a/mblock/src/lib/mb_msg_accepter_msgq.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MSG_ACCEPTER_MSGQ_H -#define INCLUDED_MB_MSG_ACCEPTER_MSGQ_H - -#include <mblock/msg_accepter.h> -#include <mblock/msg_queue.h> - -/*! - * \brief Concrete class that accepts messages and inserts them into a message queue. - */ -class mb_msg_accepter_msgq : public mb_msg_accepter { - mb_msg_queue *d_msgq; - -public: - mb_msg_accepter_msgq(mb_msg_queue *msgq); - ~mb_msg_accepter_msgq(); - void operator()(pmt::pmt_t signal, pmt::pmt_t data, pmt::pmt_t metadata, mb_pri_t priority); -}; - -#endif /* INCLUDED_MB_MSG_ACCEPTER_MSGQ_H */ diff --git a/mblock/src/lib/mb_msg_accepter_smp.cc b/mblock/src/lib/mb_msg_accepter_smp.cc deleted file mode 100644 index 1ec8c5bfd..000000000 --- a/mblock/src/lib/mb_msg_accepter_smp.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_msg_accepter_smp.h> -#include <mblock/common.h> -#include <mblock/mblock.h> -#include <mb_mblock_impl.h> -#include <mblock/message.h> - -using namespace pmt; - -mb_msg_accepter_smp::mb_msg_accepter_smp(mb_mblock_sptr mblock, pmt_t port_name) - : d_mb(mblock), d_port_name(port_name) -{ -} - -mb_msg_accepter_smp::~mb_msg_accepter_smp() -{ - // nop -} - -void -mb_msg_accepter_smp::operator()(pmt_t signal, pmt_t data, - pmt_t metadata, mb_pri_t priority) -{ - mb_message_sptr msg = mb_make_message(signal, data, metadata, priority); - msg->set_port_id(d_port_name); - d_mb->impl()->msgq().insert(msg); -} diff --git a/mblock/src/lib/mb_msg_accepter_smp.h b/mblock/src/lib/mb_msg_accepter_smp.h deleted file mode 100644 index 3028484f7..000000000 --- a/mblock/src/lib/mb_msg_accepter_smp.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MSG_ACCEPTER_SMP_H -#define INCLUDED_MB_MSG_ACCEPTER_SMP_H - -#include <mblock/msg_accepter.h> - -/*! - * \brief Concrete message acceptor that does an mb_msg_queue insertion - */ -class mb_msg_accepter_smp : public mb_msg_accepter -{ - mb_mblock_sptr d_mb; - pmt::pmt_t d_port_name; - -public: - mb_msg_accepter_smp(mb_mblock_sptr mblock, pmt::pmt_t port_name); - ~mb_msg_accepter_smp(); - - void operator()(pmt::pmt_t signal, pmt::pmt_t data, pmt::pmt_t metadata, mb_pri_t priority); -}; - - -#endif /* INCLUDED_MB_MSG_ACCEPTER_SMP_H */ diff --git a/mblock/src/lib/mb_msg_queue.cc b/mblock/src/lib/mb_msg_queue.cc deleted file mode 100644 index c68c5fd64..000000000 --- a/mblock/src/lib/mb_msg_queue.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/msg_queue.h> -#include <mblock/message.h> - - -mb_msg_queue::mb_msg_queue() - : d_not_empty(&d_mutex) -{ -} - -mb_msg_queue::~mb_msg_queue() -{ -} - -void -mb_msg_queue::insert(mb_message_sptr msg) -{ - omni_mutex_lock l(d_mutex); - - mb_pri_t q = mb_pri_clamp(msg->priority()); - - if (d_queue[q].empty_p()){ - d_queue[q].tail = d_queue[q].head = msg; - msg->d_next.reset(); //msg->d_next = 0; - } - else { - d_queue[q].tail->d_next = msg; - d_queue[q].tail = msg; - msg->d_next.reset(); // msg->d_next = 0; - } - - // FIXME set bit in bitmap - - d_not_empty.signal(); -} - -/* - * Delete highest pri message from the queue and return it. - * Returns equivalent of zero pointer if queue is empty. - * - * Caller must be holding d_mutex - */ -mb_message_sptr -mb_msg_queue::get_highest_pri_msg_helper() -{ - // FIXME use bitmap and ffz to find best queue in O(1) - - for (mb_pri_t q = 0; q <= MB_PRI_WORST; q++){ - - if (!d_queue[q].empty_p()){ - mb_message_sptr msg = d_queue[q].head; - d_queue[q].head = msg->d_next; - if (d_queue[q].head == 0){ - d_queue[q].tail.reset(); // d_queue[q].tail = 0; - // FIXME clear bit in bitmap - } - - msg->d_next.reset(); // msg->d_next = 0; - return msg; - } - } - - return mb_message_sptr(); // eqv to a zero pointer -} - - -mb_message_sptr -mb_msg_queue::get_highest_pri_msg_nowait() -{ - omni_mutex_lock l(d_mutex); - - return get_highest_pri_msg_helper(); -} - -mb_message_sptr -mb_msg_queue::get_highest_pri_msg() -{ - omni_mutex_lock l(d_mutex); - - while (1){ - mb_message_sptr msg = get_highest_pri_msg_helper(); - if (msg) // Got one; return it - return msg; - - d_not_empty.wait(); // Wait for something - } -} - -mb_message_sptr -mb_msg_queue::get_highest_pri_msg_timedwait(const mb_time &abs_time) -{ - unsigned long secs = abs_time.d_secs; - unsigned long nsecs = abs_time.d_nsecs; - - omni_mutex_lock l(d_mutex); - - while (1){ - mb_message_sptr msg = get_highest_pri_msg_helper(); - if (msg) // Got one; return it - return msg; - - if (!d_not_empty.timedwait(secs, nsecs)) // timed out - return mb_message_sptr(); // eqv to zero pointer - } -} diff --git a/mblock/src/lib/mb_port.cc b/mblock/src/lib/mb_port.cc deleted file mode 100644 index a26a2c414..000000000 --- a/mblock/src/lib/mb_port.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/port.h> -#include <mblock/protocol_class.h> - -using namespace pmt; - -mb_port::mb_port(mb_mblock *mblock, - const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type) - : d_port_name(port_name), d_port_symbol(pmt_intern(port_name)), - d_conjugated(conjugated), d_port_type(port_type), - d_mblock(mblock) -{ - pmt_t pc = mb_protocol_class_lookup(pmt_intern(protocol_class_name)); - if (pmt_is_null(pc)){ - throw std::runtime_error("mb_port: unknown protocol class '" - + protocol_class_name + "'"); - } - d_protocol_class = pc; -} - -mb_port::~mb_port() -{ - // nop -} - -pmt_t -mb_port::incoming_message_set() const -{ - if (!conjugated()) - return mb_protocol_class_incoming(protocol_class()); - else // swap the sets - return mb_protocol_class_outgoing(protocol_class()); -} - -pmt_t -mb_port::outgoing_message_set() const -{ - if (!conjugated()) - return mb_protocol_class_outgoing(protocol_class()); - else // swap the sets - return mb_protocol_class_incoming(protocol_class()); -} diff --git a/mblock/src/lib/mb_port_simple.cc b/mblock/src/lib/mb_port_simple.cc deleted file mode 100644 index 235e59de2..000000000 --- a/mblock/src/lib/mb_port_simple.cc +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mb_port_simple.h> -#include <mblock/msg_accepter.h> -#include <mblock/exception.h> -#include <mblock/mblock.h> -#include <mb_mblock_impl.h> -#include <assert.h> -#include <mbi_runtime_lock.h> - -using namespace pmt; - -mb_port_simple::mb_port_simple(mb_mblock *mblock, - const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type) - : mb_port(mblock, port_name, protocol_class_name, conjugated, port_type), - d_cache_valid(false) -{ -} - -mb_port_simple::~mb_port_simple() -{ - // nop -} - -void -mb_port_simple::send(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority) -{ - if (port_type() == mb_port::RELAY) // Can't send directly to a RELAY port - throw mbe_invalid_port_type(mblock(), mblock()->instance_name(), port_name()); - - mb_msg_accepter_sptr accepter = find_accepter(this); - if (accepter) - (*accepter)(signal, data, metadata, priority); -} - - -mb_msg_accepter_sptr -mb_port_simple::find_accepter(mb_port_simple *start) -{ - mb_port_simple *p = start; - mb_port_simple *pp = 0; - mb_mblock *context = 0; - mb_endpoint peer_ep; - mb_msg_accepter_sptr r; - - if (start->d_cache_valid) - return start->d_cached_accepter; - - mbi_runtime_lock l(p->mblock()); - - // Set up initial context. - - switch(p->port_type()){ - case mb_port::INTERNAL: // binding is in our name space - context = p->mblock(); - break; - - case mb_port::EXTERNAL: // binding is in parent's name space - context = p->mblock()->parent(); - if (!context) // can't be bound if there's no parent - return mb_msg_accepter_sptr(); // not bound - break; - - default: - throw std::logic_error("Can't happen: mb_port_simple::find_accepter [1]"); - } - - - traverse: - - if (!context->impl()->lookup_other_endpoint(p, &peer_ep)) - return mb_msg_accepter_sptr(); // not bound - - pp = dynamic_cast<mb_port_simple *>(peer_ep.port().get()); // peer port - assert(pp); - - switch (pp->port_type()){ - case mb_port::INTERNAL: // Terminate here. - case mb_port::EXTERNAL: - r = pp->make_accepter(); - - // cache the result - - start->d_cached_accepter = r; - start->d_cache_valid = true; - return r; - - case mb_port::RELAY: // Traverse to other side of relay port. - if (peer_ep.inside_of_relay_port_p()){ - // We're on inside of relay port, headed out. - p = pp; - context = p->mblock()->parent(); - - // Corner case: we're attempting to traverse a relay port on the border - // of the top block... - if (!context) - return mb_msg_accepter_sptr(); // not bound - - goto traverse; - } - else { - // We're on the outside of relay port, headed in. - p = pp; - context = p->mblock(); - goto traverse; - } - break; - - default: - throw std::logic_error("Can't happen: mb_port_simple::find_accepter [2]"); - } -} - - -mb_msg_accepter_sptr -mb_port_simple::make_accepter() -{ - return d_mblock->impl()->make_accepter(port_symbol()); -} - -void -mb_port_simple::invalidate_cache() -{ - d_cache_valid = false; - d_cached_accepter.reset(); -} diff --git a/mblock/src/lib/mb_port_simple.h b/mblock/src/lib/mb_port_simple.h deleted file mode 100644 index 485c809fe..000000000 --- a/mblock/src/lib/mb_port_simple.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_PORT_SIMPLE_H -#define INCLUDED_MB_PORT_SIMPLE_H - -#include <mblock/port.h> - -/*! - * \brief Concrete port realization - */ -class mb_port_simple : public mb_port -{ - bool d_cache_valid; - mb_msg_accepter_sptr d_cached_accepter; - -protected: - static mb_msg_accepter_sptr - find_accepter(mb_port_simple *start); - - mb_msg_accepter_sptr - make_accepter(); - -public: - mb_port_simple(mb_mblock *mblock, - const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type); - - ~mb_port_simple(); - - /*! - * \brief send a message - * - * \param signal the event name - * \param data optional data - * \param metadata optional metadata - * \param priority the urgency at which the message is sent - */ - void - send(pmt::pmt_t signal, - pmt::pmt_t data = pmt::PMT_NIL, - pmt::pmt_t metadata = pmt::PMT_NIL, - mb_pri_t priority = MB_PRI_DEFAULT); - - /* - * \brief Invalidate any cached peer resolutions - * \internal - */ - void invalidate_cache(); - -}; - -#endif /* INCLUDED_MB_PORT_SIMPLE_H */ diff --git a/mblock/src/lib/mb_protocol_class.cc b/mblock/src/lib/mb_protocol_class.cc deleted file mode 100644 index 1c696fb7c..000000000 --- a/mblock/src/lib/mb_protocol_class.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/protocol_class.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_ALL_PROTOCOL_CLASSES = PMT_NIL; - -pmt_t -mb_make_protocol_class(pmt_t name, pmt_t incoming, pmt_t outgoing) -{ - // (protocol-class <name> <incoming> <outgoing>) - - if (!pmt_is_symbol(name)) - throw pmt_wrong_type("mb_make_protocol_class: NAME must be symbol", name); - if (!(pmt_is_pair(incoming) || pmt_is_null(incoming))) - throw pmt_wrong_type("mb_make_protocol_class: INCOMING must be a list", name); - if (!(pmt_is_pair(outgoing) || pmt_is_null(outgoing))) - throw pmt_wrong_type("mb_make_protocol_class: OUTGOING must be a list", name); - - pmt_t t = pmt_cons(pmt_intern("protocol-class"), - pmt_cons(name, - pmt_cons(incoming, - pmt_cons(outgoing, PMT_NIL)))); - - // Remember this protocol class. - s_ALL_PROTOCOL_CLASSES = pmt_cons(t, s_ALL_PROTOCOL_CLASSES); - return t; -} - -pmt_t -mb_protocol_class_name(pmt_t pc) -{ - return pmt_nth(1, pc); -} - -pmt_t -mb_protocol_class_incoming(pmt_t pc) -{ - return pmt_nth(2, pc); -} - -pmt_t -mb_protocol_class_outgoing(pmt_t pc) -{ - return pmt_nth(3, pc); -} - -pmt_t -mb_protocol_class_lookup(pmt_t name) -{ - pmt_t lst = s_ALL_PROTOCOL_CLASSES; - - while (pmt_is_pair(lst)){ - if (pmt_eq(name, mb_protocol_class_name(pmt_car(lst)))) - return pmt_car(lst); - lst = pmt_cdr(lst); - } - - return PMT_NIL; -} - -mb_protocol_class_init::mb_protocol_class_init(const char *data, size_t len) -{ - std::stringbuf sb; - sb.str(std::string(data, len)); - - while (1){ - pmt_t obj = pmt_deserialize(sb); - - if (0){ - pmt_write(obj, std::cout); - std::cout << std::endl; - } - - if (pmt_is_eof_object(obj)) - return; - - mb_make_protocol_class(pmt_nth(0, obj), // protocol-class name - pmt_nth(1, obj), // list of incoming msg names - pmt_nth(2, obj)); // list of outgoing msg names - } -} diff --git a/mblock/src/lib/mb_runtime.cc b/mblock/src/lib/mb_runtime.cc deleted file mode 100644 index 57a05c416..000000000 --- a/mblock/src/lib/mb_runtime.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/runtime.h> -#include <mb_runtime_thread_per_block.h> - -mb_runtime_sptr -mb_make_runtime() -{ - return mb_runtime_sptr(new mb_runtime_thread_per_block()); -} - -mb_runtime::~mb_runtime() -{ - // nop -} - diff --git a/mblock/src/lib/mb_runtime_base.cc b/mblock/src/lib/mb_runtime_base.cc deleted file mode 100644 index f259a690d..000000000 --- a/mblock/src/lib/mb_runtime_base.cc +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_runtime_base.h> - -using namespace pmt; - -/* - * Default nop implementations... - */ - -void -mb_runtime_base::request_shutdown(pmt_t result) -{ -} - -pmt_t -mb_runtime_base::schedule_one_shot_timeout(const mb_time &abs_time, - pmt_t user_data, - mb_msg_accepter_sptr accepter) -{ - return PMT_F; -} - -pmt_t -mb_runtime_base::schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt_t user_data, - mb_msg_accepter_sptr accepter) -{ - return PMT_F; -} - -void -mb_runtime_base::cancel_timeout(pmt_t handle) -{ -} - diff --git a/mblock/src/lib/mb_runtime_base.h b/mblock/src/lib/mb_runtime_base.h deleted file mode 100644 index 78be2922d..000000000 --- a/mblock/src/lib/mb_runtime_base.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_RUNTIME_BASE_H -#define INCLUDED_MB_RUNTIME_BASE_H - -#include <mblock/runtime.h> -#include <gnuradio/omnithread.h> -#include <mblock/time.h> - -/* - * \brief This is the runtime class used by the implementation. - */ -class mb_runtime_base : public mb_runtime -{ - omni_mutex d_brl; // big runtime lock (avoid using this if possible...) - -protected: - mb_msg_accepter_sptr d_accepter; - -public: - - /*! - * \brief lock the big runtime lock - * \internal - */ - inline void lock() { d_brl.lock(); } - - /*! - * \brief unlock the big runtime lock - * \internal - */ - inline void unlock() { d_brl.unlock(); } - - virtual void request_shutdown(pmt::pmt_t result); - - virtual mb_mblock_sptr - create_component(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg) = 0; - - virtual pmt::pmt_t - schedule_one_shot_timeout(const mb_time &abs_time, pmt::pmt_t user_data, - mb_msg_accepter_sptr accepter); - - virtual pmt::pmt_t - schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt::pmt_t user_data, - mb_msg_accepter_sptr accepter); - virtual void - cancel_timeout(pmt::pmt_t handle); - - mb_msg_accepter_sptr - accepter() { return d_accepter; } - -}; - - -#endif /* INCLUDED_MB_RUNTIME_BASE_H */ diff --git a/mblock/src/lib/mb_runtime_nop.cc b/mblock/src/lib/mb_runtime_nop.cc deleted file mode 100644 index 8293e0c24..000000000 --- a/mblock/src/lib/mb_runtime_nop.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_runtime_nop.h> -#include <mblock/mblock.h> -#include <mblock/class_registry.h> -#include <mblock/exception.h> - -using namespace pmt; - -mb_runtime_sptr -mb_make_runtime_nop() -{ - return mb_runtime_sptr(new mb_runtime_nop()); -} - - -mb_runtime_nop::mb_runtime_nop() -{ - // nop for now -} - -mb_runtime_nop::~mb_runtime_nop() -{ - // nop for now -} - - -bool -mb_runtime_nop::run(const std::string &instance_name, - const std::string &class_name, - pmt_t user_arg, pmt_t *result) -{ - class initial_visitor : public mb_visitor - { - public: - bool operator()(mb_mblock *mblock) - { - mblock->initial_transition(); - return true; - } - }; - - initial_visitor visitor; - - if (result) - *result = PMT_T; - - d_top = create_component(instance_name, class_name, user_arg); - d_top->walk_tree(&visitor); - - return true; -} - -mb_mblock_sptr -mb_runtime_nop::create_component(const std::string &instance_name, - const std::string &class_name, - pmt_t user_arg) -{ - mb_mblock_maker_t maker; - if (!mb_class_registry::lookup_maker(class_name, &maker)) - throw mbe_no_such_class(0, class_name + " (in " + instance_name + ")"); - - return maker(this, instance_name, user_arg); -} diff --git a/mblock/src/lib/mb_runtime_nop.h b/mblock/src/lib/mb_runtime_nop.h deleted file mode 100644 index 735c0405e..000000000 --- a/mblock/src/lib/mb_runtime_nop.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_RUNTIME_NOP_H -#define INCLUDED_MB_RUNTIME_NOP_H - -#include <mb_runtime_base.h> - -/*! - * \brief Public constructor (factory) for mb_runtime_nop objects. - */ -mb_runtime_sptr mb_make_runtime_nop(); - -/*! - * \brief Concrete runtime that does nothing. Used only during early QA tests. - */ -class mb_runtime_nop : public mb_runtime_base -{ -public: - mb_runtime_nop(); - ~mb_runtime_nop(); - - bool run(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg, - pmt::pmt_t *result); - -protected: - mb_mblock_sptr - create_component(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg); -}; - -#endif /* INCLUDED_MB_RUNTIME_NOP_H */ diff --git a/mblock/src/lib/mb_runtime_thread_per_block.cc b/mblock/src/lib/mb_runtime_thread_per_block.cc deleted file mode 100644 index b16009436..000000000 --- a/mblock/src/lib/mb_runtime_thread_per_block.cc +++ /dev/null @@ -1,350 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_runtime_thread_per_block.h> -#include <mblock/mblock.h> -#include <mb_mblock_impl.h> -#include <mblock/class_registry.h> -#include <mblock/exception.h> -#include <mb_worker.h> -#include <gnuradio/omnithread.h> -#include <iostream> -#include <mb_msg_accepter_msgq.h> - -using namespace pmt; - -static pmt_t s_halt = pmt_intern("%halt"); -static pmt_t s_sys_port = pmt_intern("%sys-port"); -static pmt_t s_shutdown = pmt_intern("%shutdown"); -static pmt_t s_request_shutdown = pmt_intern("%request-shutdown"); -static pmt_t s_worker_state_changed = pmt_intern("%worker-state-changed"); -static pmt_t s_timeout = pmt_intern("%timeout"); -static pmt_t s_request_timeout = pmt_intern("%request-timeout"); -static pmt_t s_cancel_timeout = pmt_intern("%cancel-timeout"); -static pmt_t s_send_halt = pmt_intern("send-halt"); -static pmt_t s_exit_now = pmt_intern("exit-now"); - -static void -send_sys_msg(mb_msg_queue &msgq, pmt_t signal, - pmt_t data = PMT_F, pmt_t metadata = PMT_F, - mb_pri_t priority = MB_PRI_BEST) -{ - mb_message_sptr msg = mb_make_message(signal, data, metadata, priority); - msg->set_port_id(s_sys_port); - msgq.insert(msg); -} - - -mb_runtime_thread_per_block::mb_runtime_thread_per_block() - : d_shutdown_in_progress(false), - d_shutdown_result(PMT_T) -{ - d_accepter = mb_msg_accepter_sptr(new mb_msg_accepter_msgq(&d_msgq)); -} - -mb_runtime_thread_per_block::~mb_runtime_thread_per_block() -{ - // FIXME iterate over workers and ensure that they are dead. - - if (!d_workers.empty()) - std::cerr << "\nmb_runtime_thread_per_block: dtor (# workers = " - << d_workers.size() << ")\n"; -} - -void -mb_runtime_thread_per_block::request_shutdown(pmt_t result) -{ - (*accepter())(s_request_shutdown, result, PMT_F, MB_PRI_BEST); -} - -bool -mb_runtime_thread_per_block::run(const std::string &instance_name, - const std::string &class_name, - pmt_t user_arg, pmt_t *result) -{ - if (result) // set it to something now, in case we throw - *result = PMT_F; - - // reset the shutdown state - d_shutdown_in_progress = false; - d_shutdown_result = PMT_T; - - assert(d_workers.empty()); - - while (!d_timer_queue.empty()) // ensure timer queue is empty - d_timer_queue.pop(); - - /* - * Create the top-level component, and recursively all of its - * subcomponents. - */ - d_top = create_component(instance_name, class_name, user_arg); - - try { - run_loop(); - } - catch (...){ - d_top.reset(); - throw; - } - - if (result) - *result = d_shutdown_result; - - d_top.reset(); - return true; -} - -void -mb_runtime_thread_per_block::run_loop() -{ - while (1){ - mb_message_sptr msg; - - if (d_timer_queue.empty()) // Any timeouts pending? - msg = d_msgq.get_highest_pri_msg(); // Nope. Block forever. - - else { - mb_timeout_sptr to = d_timer_queue.top(); // Yep. Get earliest timeout. - - // wait for a msg or the timeout... - msg = d_msgq.get_highest_pri_msg_timedwait(to->d_when); - - if (!msg){ // We timed out. - d_timer_queue.pop(); // Remove timeout from timer queue. - - // send the %timeout msg - (*to->d_accepter)(s_timeout, to->d_user_data, to->handle(), MB_PRI_BEST); - - if (to->d_is_periodic){ - to->d_when = to->d_when + to->d_delta; // update time of next firing - d_timer_queue.push(to); // push it back into the queue - } - continue; - } - } - - pmt_t signal = msg->signal(); - - if (pmt_eq(signal, s_worker_state_changed)){ // %worker-state-changed - omni_mutex_lock l1(d_workers_mutex); - reap_dead_workers(); - if (d_workers.empty()) // no work left to do... - return; - } - else if (pmt_eq(signal, s_request_shutdown)){ // %request-shutdown - if (!d_shutdown_in_progress){ - d_shutdown_in_progress = true; - d_shutdown_result = msg->data(); - - // schedule a timeout for ourselves... - schedule_one_shot_timeout(mb_time::time(0.100), s_send_halt, d_accepter); - send_all_sys_msg(s_shutdown); - } - } - else if (pmt_eq(signal, s_request_timeout)){ // %request-timeout - mb_timeout_sptr to = - boost::any_cast<mb_timeout_sptr>(pmt_any_ref(msg->data())); - d_timer_queue.push(to); - } - else if (pmt_eq(signal, s_cancel_timeout)){ // %cancel-timeout - d_timer_queue.cancel(msg->data()); - } - else if (pmt_eq(signal, s_timeout) - && pmt_eq(msg->data(), s_send_halt)){ // %timeout, send-halt - - // schedule another timeout for ourselves... - schedule_one_shot_timeout(mb_time::time(0.100), s_exit_now, d_accepter); - send_all_sys_msg(s_halt); - } - else if (pmt_eq(signal, s_timeout) - && pmt_eq(msg->data(), s_exit_now)){ // %timeout, exit-now - - // We only get here if we've sent all workers %shutdown followed - // by %halt, and one or more of them is still alive. They must - // be blocked in the kernel. FIXME We could add one more step: - // pthread_kill(...) but for now, we'll just ignore them... - return; - } - else { - std::cerr << "mb_runtime_thread_per_block: unhandled msg: " << msg << std::endl; - } - } -} - -void -mb_runtime_thread_per_block::reap_dead_workers() -{ - // Already holding mutex - // omni_mutex_lock l1(d_workers_mutex); - - for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ){ - bool is_dead; - - // We can't join while holding the worker mutex, since that would - // attempt to destroy the mutex we're holding (omnithread's join - // deletes the omni_thread object after the pthread_join - // completes) Instead, we lock just long enough to figure out if - // the worker is dead. - { - omni_mutex_lock l2((*wi)->d_mutex); - is_dead = (*wi)->d_state == mb_worker::TS_DEAD; - } - - if (is_dead){ - if (0) - std::cerr << "\nruntime: " - << "(" << (*wi)->id() << ") " - << (*wi)->d_mblock->instance_name() << " is TS_DEAD\n"; - void *ignore; - (*wi)->join(&ignore); - wi = d_workers.erase(wi); - continue; - } - ++wi; - } -} - -// -// Create the thread, then create the component in the thread. -// Return a pointer to the created mblock. -// -// Can be invoked from any thread -// -mb_mblock_sptr -mb_runtime_thread_per_block::create_component(const std::string &instance_name, - const std::string &class_name, - pmt_t user_arg) -{ - mb_mblock_maker_t maker; - if (!mb_class_registry::lookup_maker(class_name, &maker)) - throw mbe_no_such_class(0, class_name + " (in " + instance_name + ")"); - - // FIXME here's where we'd lookup NUMA placement requests & mblock - // priorities and communicate them to the worker we're creating... - - // Create the worker thread - mb_worker *w = - new mb_worker(this, maker, instance_name, user_arg); - - w->start_undetached(); // start it - - // Wait for it to reach TS_RUNNING or TS_DEAD - - bool is_dead; - mb_worker::cause_of_death_t why_dead; - { - omni_mutex_lock l(w->d_mutex); - while (!(w->d_state == mb_worker::TS_RUNNING - || w->d_state == mb_worker::TS_DEAD)) - w->d_state_cond.wait(); - - is_dead = w->d_state == mb_worker::TS_DEAD; - why_dead = w->d_why_dead; - } - - // If the worker failed to init (constructor or initial_transition - // raised an exception), reap the worker now and raise an exception. - - if (is_dead && why_dead != mb_worker::RIP_EXIT){ - - void *ignore; - w->join(&ignore); - - // FIXME with some work we ought to be able to propagate the - // exception from the worker. - throw mbe_mblock_failed(0, instance_name); - } - - assert(w->d_mblock); - - // Add w to the vector of workers, and return the mblock. - { - omni_mutex_lock l(d_workers_mutex); - d_workers.push_back(w); - } - - if (0) - std::cerr << "\nruntime: created " - << "(" << w->id() << ") " - << w->d_mblock->instance_name() << "\n"; - - return w->d_mblock; -} - -void -mb_runtime_thread_per_block::send_all_sys_msg(pmt_t signal, - pmt_t data, - pmt_t metadata, - mb_pri_t priority) -{ - omni_mutex_lock l1(d_workers_mutex); - - for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ++wi){ - send_sys_msg((*wi)->d_mblock->impl()->msgq(), - signal, data, metadata, priority); - } -} - -// -// Can be invoked from any thread. -// Sends a message to the runtime. -// -pmt_t -mb_runtime_thread_per_block::schedule_one_shot_timeout - (const mb_time &abs_time, - pmt_t user_data, - mb_msg_accepter_sptr accepter) -{ - mb_timeout_sptr to(new mb_timeout(abs_time, user_data, accepter)); - (*d_accepter)(s_request_timeout, pmt_make_any(to), PMT_F, MB_PRI_BEST); - return to->handle(); -} - -// -// Can be invoked from any thread. -// Sends a message to the runtime. -// -pmt_t -mb_runtime_thread_per_block::schedule_periodic_timeout - (const mb_time &first_abs_time, - const mb_time &delta_time, - pmt_t user_data, - mb_msg_accepter_sptr accepter) -{ - mb_timeout_sptr to(new mb_timeout(first_abs_time, delta_time, - user_data, accepter)); - (*d_accepter)(s_request_timeout, pmt_make_any(to), PMT_F, MB_PRI_BEST); - return to->handle(); -} - -// -// Can be invoked from any thread. -// Sends a message to the runtime. -// -void -mb_runtime_thread_per_block::cancel_timeout(pmt_t handle) -{ - (*d_accepter)(s_cancel_timeout, handle, PMT_F, MB_PRI_BEST); -} diff --git a/mblock/src/lib/mb_runtime_thread_per_block.h b/mblock/src/lib/mb_runtime_thread_per_block.h deleted file mode 100644 index 74ed6073a..000000000 --- a/mblock/src/lib/mb_runtime_thread_per_block.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_RUNTIME_THREAD_PER_BLOCK_H -#define INCLUDED_MB_RUNTIME_THREAD_PER_BLOCK_H - -#include <mb_runtime_base.h> -#include <mb_worker.h> -#include <mblock/msg_queue.h> -#include <mb_timer_queue.h> - -/*! - * \brief Concrete runtime that uses a thread per mblock - * \internal - * - * These are all implementation details. - */ -class mb_runtime_thread_per_block : public mb_runtime_base -{ -public: - omni_mutex d_workers_mutex; // hold while manipulating d_workers - std::vector<mb_worker*> d_workers; - bool d_shutdown_in_progress; - pmt::pmt_t d_shutdown_result; - mb_msg_queue d_msgq; - mb_timer_queue d_timer_queue; - - typedef std::vector<mb_worker*>::iterator worker_iter_t; - - mb_runtime_thread_per_block(); - ~mb_runtime_thread_per_block(); - - bool run(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg, - pmt::pmt_t *result); - - void request_shutdown(pmt::pmt_t result); - -protected: - mb_mblock_sptr - create_component(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg); - - pmt::pmt_t - schedule_one_shot_timeout(const mb_time &abs_time, pmt::pmt_t user_data, - mb_msg_accepter_sptr accepter); - - pmt::pmt_t - schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt::pmt_t user_data, - mb_msg_accepter_sptr accepter); - void - cancel_timeout(pmt::pmt_t handle); - -private: - void reap_dead_workers(); - void run_loop(); - - void send_all_sys_msg(pmt::pmt_t signal, pmt::pmt_t data = pmt::PMT_F, - pmt::pmt_t metadata = pmt::PMT_F, - mb_pri_t priority = MB_PRI_BEST); -}; - -#endif /* INCLUDED_MB_RUNTIME_THREAD_PER_BLOCK_H */ diff --git a/mblock/src/lib/mb_timer_queue.cc b/mblock/src/lib/mb_timer_queue.cc deleted file mode 100644 index 411900c59..000000000 --- a/mblock/src/lib/mb_timer_queue.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_timer_queue.h> - -using namespace pmt; - -static pmt_t -make_handle() -{ - static long counter = 0; - pmt_t n = pmt_from_long(counter++); - return pmt_list1(n); // guaranteed to be a unique object -} - -// one-shot constructor -mb_timeout::mb_timeout(const mb_time &abs_time, - pmt_t user_data, mb_msg_accepter_sptr accepter) - : d_when(abs_time), d_is_periodic(false), - d_user_data(user_data), d_handle(make_handle()), d_accepter(accepter) -{ -} - -// periodic constructor -mb_timeout::mb_timeout(const mb_time &first_abs_time, const mb_time &delta_time, - pmt_t user_data, mb_msg_accepter_sptr accepter) - : d_when(first_abs_time), d_delta(delta_time), d_is_periodic(true), - d_user_data(user_data), d_handle(make_handle()), d_accepter(accepter) -{ -} - -void -mb_timer_queue::cancel(pmt_t handle) -{ - container_type::iterator it; - - for (it = c.begin(); it != c.end();){ - if (pmt_equal((*it)->handle(), handle)) - it = c.erase(it); - else - ++it; - } - std::make_heap(c.begin(), c.end(), comp); -} diff --git a/mblock/src/lib/mb_timer_queue.h b/mblock/src/lib/mb_timer_queue.h deleted file mode 100644 index 7a1ad6fa3..000000000 --- a/mblock/src/lib/mb_timer_queue.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_TIMER_QUEUE_H -#define INCLUDED_MB_TIMER_QUEUE_H - -#include <mblock/time.h> -#include <vector> -#include <queue> -#include <gruel/pmt.h> -#include <mblock/msg_accepter.h> - -class mb_timeout { -public: - mb_time d_when; // absolute time to fire timeout - mb_time d_delta; // if periodic, delta_t to next timeout - bool d_is_periodic; // true iff this is a periodic timeout - pmt::pmt_t d_user_data; // data from %timeout msg - pmt::pmt_t d_handle; // handle for cancellation - mb_msg_accepter_sptr d_accepter; // where to send the message - - // one-shot constructor - mb_timeout(const mb_time &abs_time, - pmt::pmt_t user_data, mb_msg_accepter_sptr accepter); - - // periodic constructor - mb_timeout(const mb_time &first_abs_time, const mb_time &delta_time, - pmt::pmt_t user_data, mb_msg_accepter_sptr accepter); - - pmt::pmt_t handle() const { return d_handle; } -}; - -typedef boost::shared_ptr<mb_timeout> mb_timeout_sptr; - - -//! Sort criterion for priority_queue -class timeout_later -{ -public: - bool operator() (const mb_timeout_sptr t1, const mb_timeout_sptr t2) - { - return t1->d_when > t2->d_when; - } -}; - - -class mb_timer_queue : public std::priority_queue<mb_timeout_sptr, - std::vector<mb_timeout_sptr>, - timeout_later> -{ -public: - void cancel(pmt::pmt_t handle); -}; - -#endif /* INCLUDED_MB_TIMER_QUEUE_H */ diff --git a/mblock/src/lib/mb_util.cc b/mblock/src/lib/mb_util.cc deleted file mode 100644 index 60a0e44fb..000000000 --- a/mblock/src/lib/mb_util.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mb_util.h> - - -std::string -mb_util::join_names(const std::string &comp_name, - const std::string &port_name) -{ - return comp_name + ":" + port_name; -} diff --git a/mblock/src/lib/mb_util.h b/mblock/src/lib/mb_util.h deleted file mode 100644 index fe420d6ed..000000000 --- a/mblock/src/lib/mb_util.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_UTIL_H -#define INCLUDED_MB_UTIL_H - -#include <string> - -class mb_util -{ -public: - static std::string - join_names(const std::string &comp_name, - const std::string &port_name); -}; - -#endif /* INCLUDED_MB_UTIL_H */ diff --git a/mblock/src/lib/mb_worker.cc b/mblock/src/lib/mb_worker.cc deleted file mode 100644 index 7d2896a11..000000000 --- a/mblock/src/lib/mb_worker.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_worker.h> -#include <mb_runtime_thread_per_block.h> -#include <mblock/exception.h> -#include <mblock/mblock.h> -#include <mb_gettid.h> -#include <mblock/msg_accepter.h> -#include <iostream> -#include <cstdio> -#ifdef HAVE_SCHED_H -#include <sched.h> -#endif - -#define VERBOSE 0 // define to 0 or 1 - -using namespace pmt; - -static pmt_t s_worker_state_changed = pmt_intern("%worker-state-changed"); - - -mb_worker::mb_worker(mb_runtime_thread_per_block *runtime, - mb_mblock_maker_t maker, - const std::string &instance_name, - pmt_t user_arg) - : omni_thread((void *) 0, PRIORITY_NORMAL), - d_runtime(runtime), d_maker(maker), - d_instance_name(instance_name), d_user_arg(user_arg), - d_state_cond(&d_mutex), d_state(TS_UNINITIALIZED), - d_why_dead(RIP_NOT_DEAD_YET) -{ -} - -#if 0 -mb_worker::~mb_worker() -{ -} -#endif - -#ifdef HAVE_SCHED_SETAFFINITY -static void -set_affinity(const std::string &instance_name, const std::string &class_name) -{ - //static int counter = 0; - cpu_set_t mask; - CPU_ZERO(&mask); - - if (0){ - - //CPU_SET(counter & 0x1, &mask); - //counter++; - CPU_SET(0, &mask); - - int r = sched_setaffinity(mb_gettid(), sizeof(mask), &mask); - if (r == -1) - perror("sched_setaffinity"); - } -} -#else -static void -set_affinity(const std::string &instance_name, const std::string &class_name) -{ -} -#endif - -void -mb_worker::set_state(worker_state_t state) -{ - { - omni_mutex_lock l2(d_mutex); - - d_state = state; // update our state - d_state_cond.broadcast(); // Notify everybody who cares... - } - - // send msg to runtime, telling it something changed. - (*d_runtime->accepter())(s_worker_state_changed, PMT_F, PMT_F, MB_PRI_BEST); -} - -void * -mb_worker::run_undetached(void *ignored) -{ - // FIXME add pthread_sigmask stuff - - //set_affinity(d_instance_name, d_class_name); - set_affinity(d_instance_name, ""); - - try { - worker_thread_top_level(); - d_why_dead = RIP_EXIT; - } - catch (mbe_terminate){ - d_why_dead = RIP_TERMINATE; - } - catch (mbe_exit){ - d_why_dead = RIP_EXIT; - } - catch (std::logic_error e){ - if (d_why_dead == RIP_NOT_DEAD_YET) - d_why_dead = RIP_UNHANDLED_EXCEPTION; - - std::cerr << "\nmb_worker::run_undetached: unhandled exception:\n"; - std::cerr << " " << e.what() << std::endl; - } - catch (...){ - if (d_why_dead == RIP_NOT_DEAD_YET) - d_why_dead = RIP_UNHANDLED_EXCEPTION; - } - - if (VERBOSE) - std::cerr << "\nrun_undetached: about to return, d_why_dead = " - << d_why_dead << std::endl; - - set_state(TS_DEAD); - return 0; -} - -void -mb_worker::worker_thread_top_level() -{ - if (VERBOSE) - std::cerr << "worker_thread_top_level (enter):" << std::endl - << " instance_name: " << d_instance_name << std::endl - << " omnithread id: " << id() << std::endl - << " gettid: " << mb_gettid() << std::endl - << " getpid: " << getpid() << std::endl; - - cause_of_death_t pending_cause_of_death = RIP_NOT_DEAD_YET; - - try { - pending_cause_of_death = RIP_CTOR_EXCEPTION; - d_mblock = d_maker(d_runtime, d_instance_name, d_user_arg); - - if (VERBOSE) - std::cerr << "worker_thread_top_level (post-construction):" << std::endl - << " instance_name: " << d_instance_name << std::endl; - - pending_cause_of_death = RIP_INIT_EXCEPTION; - d_mblock->initial_transition(); - - if (VERBOSE) - std::cerr << "worker_thread_top_level (post-initial-transition):" << std::endl - << " instance_name: " << d_instance_name << std::endl; - - set_state(TS_RUNNING); - - pending_cause_of_death = RIP_UNHANDLED_EXCEPTION; - d_mblock->main_loop(); - } - catch (...){ - d_why_dead = pending_cause_of_death; - throw; - } - - if (VERBOSE) - std::cerr << "worker_thread_top_level (exit):" << std::endl - << " instance_name: " << d_instance_name << std::endl; -} diff --git a/mblock/src/lib/mb_worker.h b/mblock/src/lib/mb_worker.h deleted file mode 100644 index 0037d131f..000000000 --- a/mblock/src/lib/mb_worker.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_WORKER_H -#define INCLUDED_MB_WORKER_H - -#include <gnuradio/omnithread.h> -#include <mblock/common.h> -#include <mblock/class_registry.h> - - -class mb_worker; -//typedef boost::shared_ptr<mb_worker> mb_worker_sptr; - -class mb_runtime_thread_per_block; - -/*! - * \brief Worker thread for thread_per_block runtime - * \internal - */ -class mb_worker : public omni_thread -{ -public: - //! worker thread states - enum worker_state_t { - TS_UNINITIALIZED, // new, uninitialized - TS_RUNNING, // normal steady-state condition. - TS_DEAD // thread is dead - }; - - //! why we're dead - enum cause_of_death_t { - RIP_NOT_DEAD_YET, // not dead - RIP_EXIT, // normal exit - RIP_TERMINATE, // caught terminate exception - RIP_CTOR_EXCEPTION, // constructor raised an exception - RIP_INIT_EXCEPTION, // initial_transition rasised an exception - RIP_UNHANDLED_EXCEPTION // somebody (most likely handle_message) raised an exception - }; - - /* - * Args used by new thread to create mb_mblock - */ - mb_runtime_thread_per_block *d_runtime; - mb_mblock_maker_t d_maker; - std::string d_instance_name; - pmt::pmt_t d_user_arg; - - mb_mblock_sptr d_mblock; //< holds pointer to created mblock - - /*! - * \brief General mutex for all these fields. - * - * They are accessed by both the main runtime thread and the newly - * created thread that runs the mblock's main loop. - */ - omni_mutex d_mutex; - omni_condition d_state_cond; //< state change notifications - worker_state_t d_state; - cause_of_death_t d_why_dead; - - mb_worker(mb_runtime_thread_per_block *runtime, - mb_mblock_maker_t maker, - const std::string &instance_name, - pmt::pmt_t user_arg); - - // ~mb_worker(); - - - /*! - * \brief This code runs as the top-level of the new thread - */ - void worker_thread_top_level(); - - /*! - * \brief Invokes the top-level of the new thread (name kind of sucks) - */ - void *run_undetached(void *arg); - -private: - // Neither d_mutex nor runtime->d_mutex may be held while calling this. - // It locks and unlocks them itself. - void set_state(worker_state_t state); -}; - - - -#endif /* INCLUDED_MB_WORKER_H */ diff --git a/mblock/src/lib/mbi_runtime_lock.h b/mblock/src/lib/mbi_runtime_lock.h deleted file mode 100644 index 020cd733c..000000000 --- a/mblock/src/lib/mbi_runtime_lock.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MBI_RUNTIME_LOCK_H -#define INCLUDED_MBI_RUNTIME_LOCK_H - -#include <mblock/runtime.h> -#include <mb_mblock_impl.h> -#include <boost/utility.hpp> - -/*! - * \brief acquire and release big runtime lock - * - * As an alternative to: - * { - * rt->lock(); - * ..... - * rt->unlock(); - * } - * - * you can use a single instance of the mbi_runtime_lock class: - * - * { - * mbi_runtime_lock l(rt); - * .... - * } - * - * This has the advantage that rt->unlock() will be called automatically - * when an exception is thrown. - */ - -class mbi_runtime_lock : boost::noncopyable { - mb_runtime_base *d_rt; -public: - mbi_runtime_lock(mb_runtime_base *rt) : d_rt(rt) { d_rt->lock(); } - mbi_runtime_lock(mb_mblock_impl *mi) : d_rt(mi->runtime()) { d_rt->lock(); } - mbi_runtime_lock(mb_mblock *mb) : d_rt(mb->impl()->runtime()) { d_rt->lock(); } - ~mbi_runtime_lock(void) { d_rt->unlock(); } - -}; - -#endif /* INCLUDED_MBI_RUNTIME_LOCK_H */ - diff --git a/mblock/src/lib/qa_bitset.cc b/mblock/src/lib/qa_bitset.cc deleted file mode 100644 index 7cfd83856..000000000 --- a/mblock/src/lib/qa_bitset.cc +++ /dev/null @@ -1,496 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/mblock.h> -#include <mblock/protocol_class.h> -#include <mblock/message.h> -#include <mblock/class_registry.h> -#include <iostream> -#include <cstdio> -#include <sstream> -#include <bitset> - -using namespace pmt; - -static pmt_t s_in = pmt_intern("in"); -static pmt_t s_out = pmt_intern("out"); -static pmt_t s_data = pmt_intern("data"); -static pmt_t s_start = pmt_intern("start"); -static pmt_t s_send_batch = pmt_intern("send-batch"); -static pmt_t s_long0 = pmt_from_long(0); - -static std::string -str(long x) -{ - std::ostringstream s; - s << x; - return s.str(); -} - -/*! - * \brief mblock used for QA. - * - * Messages arriving on "in" consist of a pair containing a (long) - * message number in the car, and a (long) bitmap in the cdr. For - * each message received on "in", a new message is sent on "out". The - * new message is the same format as the input, but the bitmap in - * the cdr has a "1" or'd into it that corresponds to the bit number - * specified in the constructor. - * - * The bitmap can be used by the ultimate receiver to confirm - * traversal of a set of blocks, if the blocks are assigned unique bit - * numbers. - */ -class qa_bitset : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - int d_bitno; - -public: - qa_bitset(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void handle_message(mb_message_sptr msg); -}; - -qa_bitset::qa_bitset(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::EXTERNAL); - d_out = define_port("out", "qa-bitset", true, mb_port::EXTERNAL); -} - -void -qa_bitset::handle_message(mb_message_sptr msg) -{ - if (pmt_eq(msg->port_id(), s_in) && pmt_eq(msg->signal(), s_data)){ - d_out->send(s_data, - pmt_cons(pmt_car(msg->data()), - pmt_from_long((1L << d_bitno) | pmt_to_long(pmt_cdr(msg->data()))))); - } -} - -REGISTER_MBLOCK_CLASS(qa_bitset); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset mblocks. - */ -class qa_bitset2 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset2::qa_bitset2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset", pmt_from_long(bitno + 1)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset2); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset2 mblocks. - */ -class qa_bitset4 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset4(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset4::qa_bitset4(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset2", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset2", pmt_from_long(bitno + 2)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset4); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset4 mblocks. - */ -class qa_bitset8 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset8(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset8::qa_bitset8(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset4", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset4", pmt_from_long(bitno + 4)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset8); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset8 mblocks. - */ -class qa_bitset16 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset16(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset16::qa_bitset16(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset8", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset8", pmt_from_long(bitno + 8)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset16); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset16 mblocks. - */ -class qa_bitset32 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset32(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset32::qa_bitset32(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset16", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset16", pmt_from_long(bitno + 16)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset32); - -// ------------------------------------------------------------------------ - -class qa_bitset_src : public mb_mblock -{ - mb_port_sptr d_cs_top; - mb_port_sptr d_cs; - - mb_port_sptr d_out; - - long d_msg_number; // starting message number - long d_nmsgs_to_send; // # of messages to send - long d_batch_size; // # of messages to send per batch - -public: - qa_bitset_src(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void handle_message(mb_message_sptr msg); - -protected: - void send_one(); - void send_batch(); -}; - -qa_bitset_src::qa_bitset_src(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_msg_number = pmt_to_long(pmt_nth(0, user_arg)); - d_nmsgs_to_send = pmt_to_long(pmt_nth(1, user_arg)); - d_batch_size = pmt_to_long(pmt_nth(2, user_arg)); - - d_cs_top = define_port("cs_top", "qa-bitset-cs", true, mb_port::EXTERNAL); - d_cs = define_port("cs", "qa-bitset-cs", true, mb_port::EXTERNAL); - - d_out = define_port("out", "qa-bitset", true, mb_port::EXTERNAL); -} - -void -qa_bitset_src::handle_message(mb_message_sptr msg) -{ - if ((pmt_eq(msg->port_id(), d_cs_top->port_symbol()) - || pmt_eq(msg->port_id(), d_cs->port_symbol())) - && pmt_eq(msg->signal(), s_send_batch)){ - send_batch(); - } -} - -void -qa_bitset_src::send_batch() -{ - for (int i = 0; i < d_batch_size; i++) - send_one(); -} - -void -qa_bitset_src::send_one() -{ - if (d_nmsgs_to_send > 0){ - pmt_t msg_number = pmt_from_long(d_msg_number++); - d_out->send(s_data, pmt_cons(msg_number, s_long0)); - } - if (--d_nmsgs_to_send <= 0) - exit(); -} - -REGISTER_MBLOCK_CLASS(qa_bitset_src); - -// ------------------------------------------------------------------------ - -class qa_bitset_sink : public mb_mblock -{ - // Maximum number of messages we can track - static const size_t MAX_MSGS = 1 * 1024 * 1024; - - mb_port_sptr d_cs0; - mb_port_sptr d_cs1; - mb_port_sptr d_cs2; - mb_port_sptr d_cs3; - - mb_port_sptr d_in0; - mb_port_sptr d_in1; - mb_port_sptr d_in2; - mb_port_sptr d_in3; - - long d_nmsgs_to_recv; // # of messages to receive - long d_batch_size; // # of messages to receive per batch - uint32_t d_expected_mask; - - std::bitset<MAX_MSGS> d_bitset; - long d_nrecvd; - -public: - qa_bitset_sink(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void handle_message(mb_message_sptr msg); - -protected: - void receive_one(mb_message_sptr msg); -}; - -qa_bitset_sink::qa_bitset_sink(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_nrecvd(0) -{ - d_nmsgs_to_recv = pmt_to_long(pmt_nth(0, user_arg)); - d_batch_size = pmt_to_long(pmt_nth(1, user_arg)); - d_expected_mask = pmt_to_long(pmt_nth(2, user_arg)); - - if (d_nmsgs_to_recv > (long) MAX_MSGS) - throw std::out_of_range("qa_bitset_sink: nmsgs_to_recv is too big"); - - if (d_batch_size < 1) - throw std::out_of_range("qa_bitset_sink: batch_size must be >= 1"); - - d_cs0 = define_port("cs0", "qa-bitset-cs", true, mb_port::EXTERNAL); - d_cs1 = define_port("cs1", "qa-bitset-cs", true, mb_port::EXTERNAL); - d_cs2 = define_port("cs2", "qa-bitset-cs", true, mb_port::EXTERNAL); - d_cs3 = define_port("cs3", "qa-bitset-cs", true, mb_port::EXTERNAL); - - d_in0 = define_port("in0", "qa-bitset", false, mb_port::EXTERNAL); - d_in1 = define_port("in1", "qa-bitset", false, mb_port::EXTERNAL); - d_in2 = define_port("in2", "qa-bitset", false, mb_port::EXTERNAL); - d_in3 = define_port("in3", "qa-bitset", false, mb_port::EXTERNAL); -} - -void -qa_bitset_sink::handle_message(mb_message_sptr msg) -{ - if ((pmt_eq(msg->port_id(), d_in0->port_symbol()) - || pmt_eq(msg->port_id(), d_in1->port_symbol()) - || pmt_eq(msg->port_id(), d_in2->port_symbol()) - || pmt_eq(msg->port_id(), d_in3->port_symbol())) - && pmt_eq(msg->signal(), s_data)){ - - receive_one(msg); - } -} - -void -qa_bitset_sink::receive_one(mb_message_sptr msg) -{ - long msg_number = pmt_to_long(pmt_car(msg->data())); - uint32_t mask = pmt_to_long(pmt_cdr(msg->data())); - - // std::cout << msg->data() << std::endl; - - d_nrecvd++; - if (d_nrecvd % d_batch_size == d_batch_size - 1){ - d_cs0->send(s_send_batch); - d_cs1->send(s_send_batch); - d_cs2->send(s_send_batch); - d_cs3->send(s_send_batch); - } - - if (msg_number >= d_nmsgs_to_recv){ - std::cerr << "qa_bitset_sink::receive_one: msg_number too big (" - << msg_number << ")\n"; - shutdown_all(PMT_F); - return; - } - if (mask != d_expected_mask){ - fprintf(stderr, - "qa_bitset_sink::receive_one: Wrong mask. Expected 0x%08x, got 0x%08x\n", - d_expected_mask, mask); - shutdown_all(PMT_F); - return; - } - - if (d_bitset.test((size_t) msg_number)){ - std::cerr << "qa_bitset_sink::receive_one: duplicate msg_number (" - << msg_number << ")\n"; - shutdown_all(PMT_F); - return; - } - - d_bitset.set((size_t) msg_number); - if (d_nrecvd == d_nmsgs_to_recv) - shutdown_all(PMT_T); // we're done! -} - -REGISTER_MBLOCK_CLASS(qa_bitset_sink); - -// ------------------------------------------------------------------------ - -class qa_bitset_top : public mb_mblock -{ - static const int NPIPES = 4; - - std::vector<mb_port_sptr> d_cs; - - long d_nmsgs; // # of messages to send - long d_batch_size; // # of messages to receive per batch - -public: - qa_bitset_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void initial_transition(); -}; - -qa_bitset_top::qa_bitset_top(mb_runtime *runtime, - const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_nmsgs = pmt_to_long(pmt_nth(0, user_arg)); - d_nmsgs = (d_nmsgs / NPIPES) * NPIPES; - d_batch_size = pmt_to_long(pmt_nth(1, user_arg)); - - /* - * We build NPIPES sources which feed NPIPES pipelines, each of which - * consists of 8-mblocks. All pipelines feed into a single sink - * which keeps track the results. - */ - for (int i = 0; i < NPIPES; i++){ - d_cs.push_back(define_port("cs"+str(i), "qa-bitset-cs", false, mb_port::INTERNAL)); - - // sources of test messages - define_component("src"+str(i), "qa_bitset_src", - pmt_list3(pmt_from_long(i * d_nmsgs/NPIPES), - pmt_from_long(d_nmsgs/NPIPES), - pmt_from_long(d_batch_size))); - - // 8-mblock processing pipelines - define_component("pipeline"+str(i), "qa_bitset8", pmt_from_long(0)); - } - - // sink for output of pipelines - define_component("sink", "qa_bitset_sink", - pmt_list3(pmt_from_long(d_nmsgs), - pmt_from_long(d_batch_size * NPIPES), - pmt_from_long(0x000000ff))); - - for (int i = 0; i < NPIPES; i++){ - connect("self", "cs"+str(i), "src"+str(i), "cs_top"); - connect("src"+str(i), "out", "pipeline"+str(i), "in"); - connect("src"+str(i), "cs", "sink", "cs"+str(i)); - connect("pipeline"+str(i), "out", "sink", "in"+str(i)); - } -} - -void -qa_bitset_top::initial_transition() -{ - for (int i = 0; i < NPIPES; i++){ - d_cs[i]->send(s_send_batch); // prime the pump - d_cs[i]->send(s_send_batch); - } -} - -REGISTER_MBLOCK_CLASS(qa_bitset_top); diff --git a/mblock/src/lib/qa_bitset.mbh b/mblock/src/lib/qa_bitset.mbh deleted file mode 100644 index 3fbcb80db..000000000 --- a/mblock/src/lib/qa_bitset.mbh +++ /dev/null @@ -1,61 +0,0 @@ -;; -*- scheme -*- ; not really, but tells emacs how to format this -;; -;; Copyright 2007 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 this program; if not, write to the Free Software Foundation, Inc., -;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -;; - -;; ---------------------------------------------------------------- -;; qa-bitset -- interface to mblock QA code -;; - -(define-protocol-class qa-bitset - - (:incoming - - (data n bitmask) - - ) - ) - -(define-protocol-class qa-bitset-cs - - (:outgoing - - (send-batch) - - ) - ) - -;; ---------------------------------------------------------------- -;; qa-disconnect -- interface to mblock QA code -;; - -(define-protocol-class qa-disconnect-cs - - (:outgoing - - (select-pipe n) - - ) - - (:incoming - - (ack n) - - ) - ) diff --git a/mblock/src/lib/qa_disconnect.cc b/mblock/src/lib/qa_disconnect.cc deleted file mode 100644 index c7619bfc3..000000000 --- a/mblock/src/lib/qa_disconnect.cc +++ /dev/null @@ -1,241 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/mblock.h> -#include <mblock/protocol_class.h> -#include <mblock/message.h> -#include <mblock/class_registry.h> -#include <iostream> -#include <cstdio> -#include <sstream> -#include <bitset> - -using namespace pmt; - -static pmt_t s_in = pmt_intern("in"); -static pmt_t s_out = pmt_intern("out"); -static pmt_t s_data = pmt_intern("data"); -static pmt_t s_ack = pmt_intern("ack"); -static pmt_t s_select_pipe = pmt_intern("select-pipe"); -static pmt_t s_long0 = pmt_from_long(0); -static pmt_t s_sys_port = pmt_intern("%sys-port"); -static pmt_t s_shutdown = pmt_intern("%shutdown"); - -class qa_disconnect_mux : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - mb_port_sptr d_cs; - -public: - qa_disconnect_mux(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -qa_disconnect_mux::qa_disconnect_mux(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - d_cs = define_port("cs", "qa-disconnect-cs", true, mb_port::EXTERNAL); - - define_component("pipeline0", "qa_bitset8", pmt_from_long(0)); - define_component("pipeline1", "qa_bitset8", pmt_from_long(8)); -} - -void -qa_disconnect_mux::initial_transition(){} - -void -qa_disconnect_mux::handle_message(mb_message_sptr msg) -{ - if (pmt_eq(msg->port_id(), d_cs->port_symbol()) // select-pipe on cs - && pmt_eq(msg->signal(), s_select_pipe)){ - - long which_pipe = pmt_to_long(pmt_nth(0, msg->data())); - - disconnect_component("pipeline0"); - disconnect_component("pipeline1"); - - switch(which_pipe){ - - case 0: - connect("self", "in", "pipeline0", "in"); - connect("self", "out", "pipeline0", "out"); - break; - - case 1: - connect("self", "in", "pipeline1", "in"); - connect("self", "out", "pipeline1", "out"); - break; - } - - d_cs->send(s_ack, msg->data()); - return; - } -} - -REGISTER_MBLOCK_CLASS(qa_disconnect_mux); - -// ------------------------------------------------------------------------ - -class qa_disconnect_top : public mb_mblock -{ - enum state_t { - UNINITIALIZED, - WAIT_FOR_ACK, - WAIT_FOR_DATA - }; - - state_t d_state; - int d_msg_number; - int d_nmsgs_to_send; - - mb_port_sptr d_in; - mb_port_sptr d_out; - mb_port_sptr d_cs; - - void check_pipe_send_next_msg(); - void send_next_msg(); - void select_pipe(int n); - - // alternate pipes every 128 messages - static int which_pipe(int msg_number) { return (msg_number >> 7) & 0x1; } - bool time_to_switch() { return (d_msg_number & 0x7f) == 0; } - -public: - qa_disconnect_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -qa_disconnect_top::qa_disconnect_top(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_state(UNINITIALIZED), d_msg_number(0) -{ - d_nmsgs_to_send = pmt_to_long(pmt_nth(0, user_arg)); - - d_in = define_port("in", "qa-bitset", false, mb_port::INTERNAL); - d_out = define_port("out", "qa-bitset", true, mb_port::INTERNAL); - d_cs = define_port("cs", "qa-disconnect-cs", false, mb_port::INTERNAL); - - define_component("mux", "qa_disconnect_mux", PMT_F); - - connect("self", "cs", "mux", "cs"); - connect("self", "out", "mux", "in"); - connect("self", "in", "mux", "out"); -} - -void -qa_disconnect_top::initial_transition() -{ - check_pipe_send_next_msg(); -} - -void -qa_disconnect_top::handle_message(mb_message_sptr msg) -{ - if (0) - std::cerr << "qa_disconnect_top::handle_msg state = " - << d_state << "\n msg = " << msg << std::endl; - - if (pmt_eq(msg->port_id(), d_cs->port_symbol()) // ack on cs - && pmt_eq(msg->signal(), s_ack) - && d_state == WAIT_FOR_ACK){ - - send_next_msg(); - return; - } - - if (pmt_eq(msg->port_id(), d_in->port_symbol()) // data on in - && pmt_eq(msg->signal(), s_data) - && d_state == WAIT_FOR_DATA){ - - /* - * Confirm that msg passed through the pipe that we expect... - */ - static const long expected_mask[2] = { 0x000000ff, 0x0000ff00 }; - - long msg_number = pmt_to_long(pmt_car(msg->data())); - long mask = pmt_to_long(pmt_cdr(msg->data())); - - if (mask != expected_mask[which_pipe(msg_number)]){ - fprintf(stderr, "\nqa_disconnect_top: wrong mask in msg_number = 0x%08lx\n", - msg_number); - fprintf(stderr, " expected = 0x%08lx, actual = 0x%08lx\n", - expected_mask[which_pipe(msg_number)], mask); - shutdown_all(PMT_F); - return; - } - - if (msg_number == d_nmsgs_to_send - 1){ // we're done (and were successful) - shutdown_all(PMT_T); - return; - } - - check_pipe_send_next_msg(); - return; - } - - if (pmt_eq(msg->port_id(), s_sys_port) // ignore %shutdown on %sys-port - && pmt_eq(msg->signal(), s_shutdown)) - return; - - std::cerr << "qa_disconnect_top: unhandled msg: state = " - << d_state << "\n msg = " << msg << std::endl; -} - -void -qa_disconnect_top::select_pipe(int n) -{ - d_cs->send(s_select_pipe, pmt_list1(pmt_from_long(n))); - d_state = WAIT_FOR_ACK; -} - -void -qa_disconnect_top::send_next_msg() -{ - d_state = WAIT_FOR_DATA; - if (d_msg_number == d_nmsgs_to_send) // we've sent all we're supposed to - return; - - d_out->send(s_data, pmt_cons(pmt_from_long(d_msg_number), s_long0)); - d_msg_number++; -} - -void -qa_disconnect_top::check_pipe_send_next_msg() -{ - if (time_to_switch()) - select_pipe(which_pipe(d_msg_number)); - else - send_next_msg(); -} - -REGISTER_MBLOCK_CLASS(qa_disconnect_top); diff --git a/mblock/src/lib/qa_mblock.cc b/mblock/src/lib/qa_mblock.cc deleted file mode 100644 index c0629790d..000000000 --- a/mblock/src/lib/qa_mblock.cc +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * This class gathers together all the test cases for mblock into - * a single test suite. As you create new test cases, add them here. - */ - -#include <qa_mblock.h> -#include <qa_mblock_prims.h> -#include <qa_mblock_send.h> -#include <qa_mblock_sys.h> -#include <qa_timeouts.h> - -CppUnit::TestSuite * -qa_mblock::suite() -{ - CppUnit::TestSuite *s = new CppUnit::TestSuite("mblock"); - - s->addTest (qa_mblock_prims::suite()); - s->addTest (qa_mblock_send::suite()); - s->addTest (qa_mblock_sys::suite()); - s->addTest (qa_timeouts::suite()); - - return s; -} diff --git a/mblock/src/lib/qa_mblock.h b/mblock/src/lib/qa_mblock.h deleted file mode 100644 index 056c42237..000000000 --- a/mblock/src/lib/qa_mblock.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef INCLUDED_QA_MBLOCK_H -#define INCLUDED_QA_MBLOCK_H - -#include <cppunit/TestSuite.h> - -//! collect all the tests for mblock - -class qa_mblock { - public: - //! return suite of tests for all of mblock - static CppUnit::TestSuite *suite(); -}; - -#endif /* INCLUDED_QA_MBLOCK_H */ diff --git a/mblock/src/lib/qa_mblock_prims.cc b/mblock/src/lib/qa_mblock_prims.cc deleted file mode 100644 index e49bd60d4..000000000 --- a/mblock/src/lib/qa_mblock_prims.cc +++ /dev/null @@ -1,448 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <qa_mblock_prims.h> -#include <cppunit/TestAssert.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <stdio.h> - -using namespace pmt; - -static pmt_t s_cs = pmt_intern("cs"); -static pmt_t s_debug = pmt_intern("debug"); -static pmt_t s_in = pmt_intern("in"); -static pmt_t s_out = pmt_intern("out"); - - -// ================================================================ - -class dp_1 : public mb_mblock -{ -public: - dp_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dp_1(); -}; - -dp_1::dp_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ -} - -dp_1::~dp_1(){} - -REGISTER_MBLOCK_CLASS(dp_1); - -// ---------------------------------------------------------------- - -class dp_2 : public mb_mblock -{ -public: - dp_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dp_2(); -}; - -dp_2::dp_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_port("cs", "cs-protocol", false, mb_port::EXTERNAL); -} - -dp_2::~dp_2(){} - -REGISTER_MBLOCK_CLASS(dp_2); - -// ---------------------------------------------------------------- - -class dp_3 : public mb_mblock -{ -public: - dp_3(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dp_3(); -}; - -dp_3::dp_3(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_port("cs", "cs-protocol", false, mb_port::EXTERNAL); - define_port("cs", "cs-protocol", false, mb_port::EXTERNAL); // duplicate def -} - -dp_3::~dp_3(){} - -REGISTER_MBLOCK_CLASS(dp_3); - -// ---------------------------------------------------------------- - -void -qa_mblock_prims::test_define_ports() -{ - - mb_runtime_sptr rts = mb_make_runtime(); - mb_runtime *rt = rts.get(); - - // Should work - mb_mblock_sptr mb1 = mb_mblock_sptr(new dp_1(rt, "top", PMT_F)); - - // raises runtime_error because of unknown protocol "cs-protocol" - CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dp_2(rt, "top", PMT_F)), - std::runtime_error); - - // define the protocol class - pmt_t pc = mb_make_protocol_class(pmt_intern("cs-protocol"), - pmt_list2(pmt_intern("start"), - pmt_intern("stop")), - PMT_NIL); - - // std::cout << "pc = " << pc << '\n'; - - mb_mblock_sptr mb2 = mb_mblock_sptr(new dp_2(rt, "top", PMT_F)); - - // raises pmt_exception because of duplicate port definition of "cs" - CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dp_3(rt, "top", PMT_F)), - mbe_duplicate_port); -} - -// ================================================================ - -class dc_0 : public mb_mblock -{ -public: - dc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dc_0(); -}; - -dc_0::dc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ -} - -dc_0::~dc_0() {} - -REGISTER_MBLOCK_CLASS(dc_0); - -// ---------------------------------------------------------------- - -class dc_ok : public mb_mblock -{ -public: - dc_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dc_ok(); -}; - -dc_ok::dc_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_component("c0", "dc_0"); - define_component("c1", "dc_0"); - define_component("c2", "dc_0"); -} - -dc_ok::~dc_ok(){} - -REGISTER_MBLOCK_CLASS(dc_ok); - -// ---------------------------------------------------------------- - -class dc_not_ok : public mb_mblock -{ -public: - dc_not_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dc_not_ok(); -}; - -dc_not_ok::dc_not_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_component("c0", "dc_0"); - define_component("c0", "dc_0"); // duplicate name -} - -dc_not_ok::~dc_not_ok(){} - -REGISTER_MBLOCK_CLASS(dc_not_ok); - -// ---------------------------------------------------------------- - -void -qa_mblock_prims::test_define_components() -{ - mb_runtime_sptr rts = mb_make_runtime(); - mb_runtime *rt = rts.get(); - - // Should work - mb_mblock_sptr mb1 = mb_mblock_sptr(new dc_ok(rt, "top", PMT_F)); - - // raises pmt_exception because of duplicate component definition of "c0" - CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dc_not_ok(rt, "top", PMT_F)), - mbe_duplicate_component); -} - -// ================================================================ - -class tc_norm : public mb_mblock -{ -public: - tc_norm(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) - { - define_port("data", "i/o", false, mb_port::EXTERNAL); - define_port("norm", "i/o", false, mb_port::EXTERNAL); - define_port("conj", "i/o", true, mb_port::EXTERNAL); - define_port("int", "i/o", false, mb_port::INTERNAL); - } - - ~tc_norm(); -}; - -tc_norm::~tc_norm(){} - -REGISTER_MBLOCK_CLASS(tc_norm); - -//////////////////////////////////////////////////////////////// - -class tc_0 : public mb_mblock -{ -public: - tc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) - { - define_port("norm", "i/o", false, mb_port::EXTERNAL); - define_port("conj", "i/o", true, mb_port::EXTERNAL); - define_port("int", "i/o", false, mb_port::INTERNAL); - - define_component("c0", "tc_norm"); - define_component("c1", "tc_norm"); - define_component("c2", "tc_norm"); - define_component("c3", "tc_norm"); - define_component("c4", "tc_norm"); - define_component("c5", "tc_norm"); - - // OK - connect("c0", "norm", "c1", "conj"); - - // No: No such component name - CPPUNIT_ASSERT_THROW(connect("foo", "data", "c1", "norm"), mbe_no_such_component); - - // No: No such port name - CPPUNIT_ASSERT_THROW(connect("c0", "data", "c1", "foo"), mbe_no_such_port); - - // No: already connected - CPPUNIT_ASSERT_THROW(connect("c0", "norm", "c2", "data"), mbe_already_connected); - - // No: already connected - CPPUNIT_ASSERT_THROW(connect("c2", "data", "c0", "norm"), mbe_already_connected); - - // No: incompatible ports - CPPUNIT_ASSERT_THROW(connect("c1", "norm", "c2", "norm"), mbe_incompatible_ports); - - // OK - connect("c1", "norm", "c2", "conj"); - - // No: No such port name - CPPUNIT_ASSERT_THROW(connect("c2", "norm", "self", "foo"), mbe_no_such_port); - - // No: can't connect to child's internal port - CPPUNIT_ASSERT_THROW(connect("c0", "conj", "c2", "int"), mbe_no_such_port); - - // No: can't connect to our own external port - CPPUNIT_ASSERT_THROW(connect("self", "norm", "c0", "conj"), mbe_invalid_port_type); - - // OK: connecting to one of our internal ports - connect("self", "int", "c3", "conj"); - - // ===== Now test disconnecting some stuff ===== - - // Confirm we're already connected - CPPUNIT_ASSERT_THROW(connect("self", "int", "c3", "conj"), mbe_already_connected); - - int nc = nconnections(); - disconnect("self", "int", "c3", "conj"); // disconnect - CPPUNIT_ASSERT_EQUAL(nc-1, nconnections()); - - connect("self", "int", "c3", "conj"); // reconnect - CPPUNIT_ASSERT_EQUAL(nc, nconnections()); - - // confirm we're already connected - CPPUNIT_ASSERT_THROW(connect("self", "int", "c3", "conj"), mbe_already_connected); - - - connect("c0", "conj", "c5", "data"); - connect("c4", "norm", "c5", "conj"); - connect("c4", "conj", "c5", "norm"); - - nc = nconnections(); - disconnect_component("c4"); - CPPUNIT_ASSERT_EQUAL(nc-2, nconnections()); - - disconnect_component("c5"); - CPPUNIT_ASSERT_EQUAL(nc-3, nconnections()); - - disconnect_all(); - CPPUNIT_ASSERT_EQUAL(0, nconnections()); - - } - - ~tc_0(); -}; - -tc_0::~tc_0(){} - -REGISTER_MBLOCK_CLASS(tc_0); - -//////////////////////////////////////////////////////////////// - -class tc_1 : public mb_mblock -{ -public: - tc_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) - { - define_component("c0", "tc_norm"); - define_component("c1", "tc_norm"); - - connect("c0", "norm", "c1", "conj"); - } - - ~tc_1(); -}; - -tc_1::~tc_1(){} - -REGISTER_MBLOCK_CLASS(tc_1); - -//////////////////////////////////////////////////////////////// - -void -qa_mblock_prims::test_connect() -{ - // define the protocol class - mb_make_protocol_class(pmt_intern("data"), // name of class - pmt_list1(pmt_intern("data")), // in - PMT_NIL); // out - - mb_make_protocol_class(pmt_intern("i/o"), // name of class - pmt_list1(pmt_intern("in")), // in - pmt_list1(pmt_intern("out"))); // out - - mb_runtime_sptr rts = mb_make_runtime(); - mb_runtime *rt = rts.get(); - - mb_mblock_sptr mb0 = mb_mblock_sptr(new tc_0(rt, "top", PMT_F)); -} - -//////////////////////////////////////////////////////////////// - -void -qa_mblock_prims::test_msg_queue() -{ - mb_msg_queue q; - - // check initial state - CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0); - - CPPUNIT_ASSERT(MB_NPRI >= 5); // sanity check for this test - - // insert three messages at the same pri and ensure that they come out in order - // signal data metadata pri - q.insert(mb_make_message(PMT_NIL, pmt_from_long(0), PMT_NIL, MB_PRI_BEST + 2)); - q.insert(mb_make_message(PMT_NIL, pmt_from_long(1), PMT_NIL, MB_PRI_BEST + 2)); - q.insert(mb_make_message(PMT_NIL, pmt_from_long(2), PMT_NIL, MB_PRI_BEST + 2)); - - CPPUNIT_ASSERT_EQUAL(0L, pmt_to_long(q.get_highest_pri_msg_nowait()->data())); - CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(q.get_highest_pri_msg_nowait()->data())); - CPPUNIT_ASSERT_EQUAL(2L, pmt_to_long(q.get_highest_pri_msg_nowait()->data())); - - CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0); - - - // insert messages of different priorities in pseudo-random order - // signal data metadata pri - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 3)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 2)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 4)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 0)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 1)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 3)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 2)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 4)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 0)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 1)); - - // confirm that they come out in order - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 0, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 0, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 1, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 1, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 2, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 2, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 3, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 3, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 4, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 4, q.get_highest_pri_msg_nowait()->priority()); - - // check final state - CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0); -} - -//////////////////////////////////////////////////////////////// - -void -qa_mblock_prims::test_make_accepter() -{ - mb_runtime_sptr rts = mb_make_runtime(); - mb_runtime *rt = rts.get(); - - // create a block - mb_mblock_sptr mb = mb_mblock_sptr(new dp_2(rt, "top", PMT_F)); - - // use "internal use only" method... - mb_msg_accepter_sptr accepter = mb->impl()->make_accepter(pmt_intern("cs")); - - // Now push a few messages into it... - // signal data metadata pri - (*accepter)(PMT_NIL, pmt_from_long(0), PMT_NIL, MB_PRI_BEST + 2); - (*accepter)(PMT_NIL, pmt_from_long(1), PMT_NIL, MB_PRI_BEST + 2); - (*accepter)(PMT_NIL, pmt_from_long(2), PMT_NIL, MB_PRI_BEST + 2); - - // try to pull them out - - pmt_t cs = pmt_intern("cs"); - - mb_message_sptr msg = mb->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(pmt_eq(cs, msg->port_id())); // confirm that port_id is set - CPPUNIT_ASSERT_EQUAL(0L, pmt_to_long(msg->data())); // and that data is correct - - CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(mb->impl()->msgq().get_highest_pri_msg_nowait()->data())); - CPPUNIT_ASSERT_EQUAL(2L, pmt_to_long(mb->impl()->msgq().get_highest_pri_msg_nowait()->data())); -} diff --git a/mblock/src/lib/qa_mblock_prims.h b/mblock/src/lib/qa_mblock_prims.h deleted file mode 100644 index cf928ee4f..000000000 --- a/mblock/src/lib/qa_mblock_prims.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef INCLUDED_QA_MBLOCK_PRIMS_H -#define INCLUDED_QA_MBLOCK_PRIMS_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_mblock_prims : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_mblock_prims); - CPPUNIT_TEST(test_define_ports); - CPPUNIT_TEST(test_define_components); - CPPUNIT_TEST(test_connect); - CPPUNIT_TEST(test_msg_queue); - CPPUNIT_TEST(test_make_accepter); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_define_ports(); - void test_define_components(); - void test_connect(); - void test_msg_queue(); - void test_make_accepter(); -}; - -#endif /* INCLUDED_QA_MBLOCK_PRIMS_H */ - diff --git a/mblock/src/lib/qa_mblock_send.cc b/mblock/src/lib/qa_mblock_send.cc deleted file mode 100644 index 53f93927b..000000000 --- a/mblock/src/lib/qa_mblock_send.cc +++ /dev/null @@ -1,477 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <qa_mblock_send.h> -#include <cppunit/TestAssert.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mb_runtime_nop.h> // QA only -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <stdio.h> - -using namespace pmt; - -static pmt_t s_data = pmt_intern("data"); -static pmt_t s_status = pmt_intern("status"); -static pmt_t s_control = pmt_intern("control"); -static pmt_t s_p0 = pmt_intern("p0"); -static pmt_t s_p1 = pmt_intern("p1"); -static pmt_t s_p2 = pmt_intern("p2"); -static pmt_t s_p3 = pmt_intern("p3"); -static pmt_t s_e1 = pmt_intern("e1"); -static pmt_t s_r1 = pmt_intern("r1"); - -static void -define_protocol_classes() -{ - // Defined from client point-of-view. - mb_make_protocol_class(pmt_intern("qa-send-cs"), // name - pmt_list1(s_status), // incoming - pmt_list1(s_control)); // outgoing - -} - -mb_mblock_sptr -get_top(mb_runtime_sptr rts) -{ - return dynamic_cast<mb_runtime_nop *>(rts.get())->top(); -} - -// ================================================================ -// test_simple_routing -// ================================================================ - -// sub-block for test_simple_routing - -class sr1 : public mb_mblock -{ - mb_port_sptr d_p1; - mb_port_sptr d_p2; - mb_port_sptr d_p3; - -public: - sr1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~sr1(); - void initial_transition(); -}; - -sr1::sr1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_p1 = define_port("p1", "qa-send-cs", true, mb_port::EXTERNAL); - d_p2 = define_port("p2", "qa-send-cs", true, mb_port::EXTERNAL); - d_p3 = define_port("p3", "qa-send-cs", false, mb_port::EXTERNAL); -} - -sr1::~sr1(){} - -void -sr1::initial_transition() -{ - // std::cout << instance_name() << "[sr1]: initial_transition\n"; - - // send two messages to each port - pmt_t our_name = pmt_intern(instance_name()); - d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(0))); - d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(1))); - - d_p2->send(s_status, pmt_list3(our_name, s_p2, pmt_from_long(0))); - d_p2->send(s_status, pmt_list3(our_name, s_p2, pmt_from_long(1))); -} - -REGISTER_MBLOCK_CLASS(sr1); - -// ---------------------------------------------------------------- - -// top-level container block for test_simple_routing -class sr0 : public mb_mblock -{ - mb_port_sptr d_p0; - -public: - sr0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~sr0(); - void initial_transition(); -}; - -sr0::sr0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_p0 = define_port("p0", "qa-send-cs", false, mb_port::INTERNAL); - - define_component("mb1", "sr1"); - define_component("mb2", "sr1"); - - connect("self", "p0", "mb1", "p1"); - connect("mb1", "p2", "mb2", "p3"); - connect("mb1", "p3", "mb2", "p2"); -} - -sr0::~sr0(){} - -void -sr0::initial_transition() -{ - // std::cout << instance_name() << "[sr0]: initial_transition\n"; - - // send two messages to p0 - pmt_t our_name = pmt_intern(instance_name()); - d_p0->send(s_control, pmt_list3(our_name, s_p0, pmt_from_long(0))); - d_p0->send(s_control, pmt_list3(our_name, s_p0, pmt_from_long(1))); -} - -REGISTER_MBLOCK_CLASS(sr0); - -// ---------------------------------------------------------------- - -/* - * This tests basic message routing using INTERNAL and EXTERNAL ports. - * It does not rely on the guts of the runtime being complete, - * which is good, because at the time this is being written, it isn't. - */ -void -qa_mblock_send::test_simple_routing() -{ - define_protocol_classes(); - - mb_message_sptr msg; - - mb_runtime_sptr rt = mb_make_runtime_nop(); - rt->run("top", "sr0", PMT_F); - - mb_mblock_sptr mb0 = get_top(rt); - - // Reach into the guts and see if the messages ended up where they should have - - // mb0 should have received two messages sent from mb1 via its p1 - msg = mb0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p0, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = mb0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p0, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p1, pmt_from_long(1)), - msg->data())); - - // mb1 should have received - // two messages from mb0 via its p0 and - // two messages from mb2 via its p3 - - mb_mblock_sptr mb1 = mb0->impl()->component("mb1"); - - msg = mb1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p1, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top"), s_p0, pmt_from_long(0)), - msg->data())); - - msg = mb1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p1, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top"), s_p0, pmt_from_long(1)), - msg->data())); - - msg = mb1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb2"), s_p2, pmt_from_long(0)), - msg->data())); - - msg = mb1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb2"), s_p2, pmt_from_long(1)), - msg->data())); - - - // mb2 should have received - // two messages from mb2 via its p2 - - mb_mblock_sptr mb2 = mb0->impl()->component("mb2"); - - msg = mb2->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p2, pmt_from_long(0)), - msg->data())); - - msg = mb2->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p2, pmt_from_long(1)), - msg->data())); -} - -// ================================================================ -// test_relay_routing_1 -// ================================================================ - -// internal block for test_relay_routing - -class rr2 : public mb_mblock -{ - mb_port_sptr d_p1; - mb_port_sptr d_p2; - -public: - rr2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~rr2(); - void initial_transition(); -}; - -rr2::rr2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_p1 = define_port("p1", "qa-send-cs", true, mb_port::EXTERNAL); - d_p2 = define_port("p2", "qa-send-cs", false, mb_port::EXTERNAL); -} - -rr2::~rr2(){} - -void -rr2::initial_transition() -{ - // std::cout << instance_name() << "[rr2]: initial_transition\n"; - - // send two messages via p1 - pmt_t our_name = pmt_intern(instance_name()); - d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(0))); - d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(1))); -} - -REGISTER_MBLOCK_CLASS(rr2); - -// ---------------------------------------------------------------- - -// intermediate block for test_relay_routing - -class rr1 : public mb_mblock -{ - mb_port_sptr d_p1; - mb_port_sptr d_p2; - -public: - rr1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~rr1(); -}; - -rr1::rr1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_p1 = define_port("p1", "qa-send-cs", true, mb_port::RELAY); - d_p2 = define_port("p2", "qa-send-cs", false, mb_port::RELAY); - - define_component("c0", "rr2"); - - connect("self", "p1", "c0", "p1"); - connect("self", "p2", "c0", "p2"); -} - -rr1::~rr1(){} - -REGISTER_MBLOCK_CLASS(rr1); - -// ---------------------------------------------------------------- - -// top-level container for test_relay_routing - -class rr0_a : public mb_mblock -{ -public: - rr0_a(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~rr0_a(); -}; - -rr0_a::rr0_a(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_component("c0", "rr1"); - define_component("c1", "rr2"); - - connect("c0", "p1", "c1", "p2"); - connect("c0", "p2", "c1", "p1"); -} - -rr0_a::~rr0_a(){} - -REGISTER_MBLOCK_CLASS(rr0_a); - -/* - * This tests basic message routing using RELAY and EXTERNAL ports. - * It does not rely on the guts of the runtime being complete, - * which is good, because at the time this is being written, it isn't. - */ -void -qa_mblock_send::test_relay_routing_1() -{ - mb_message_sptr msg; - - mb_runtime_sptr rt = mb_make_runtime_nop(); - rt->run("top", "rr0_a", PMT_F); - mb_mblock_sptr top = get_top(rt); - - // Reach into the guts and see if the messages ended up where they should have - - mb_mblock_sptr c0 = top->impl()->component("c0"); - mb_mblock_sptr c0c0 = c0->impl()->component("c0"); - - mb_mblock_sptr c1 = top->impl()->component("c1"); - - // c0c0 should have received - // two message from c1 via its p2 - - msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - //std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - //std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1"), s_p1, pmt_from_long(1)), - msg->data())); - - // c1 should have received - // two message from c0c0 via its p2 - - msg = c1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - //std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = c1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - //std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(1)), - msg->data())); -} - -// ================================================================ -// test_relay_routing_2 -// ================================================================ - -// top-level container for test_relay_routing_2 - -class rr0_b : public mb_mblock -{ -public: - rr0_b(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~rr0_b(); -}; - -rr0_b::rr0_b(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_component("c0", "rr1"); - define_component("c1", "rr1"); - - connect("c0", "p1", "c1", "p2"); - connect("c0", "p2", "c1", "p1"); -} - -rr0_b::~rr0_b(){} - -REGISTER_MBLOCK_CLASS(rr0_b); - -/* - * This tests basic message routing using RELAY and EXTERNAL ports. - * It does not rely on the guts of the runtime being complete, - * which is good, because at the time this is being written, it isn't. - */ -void -qa_mblock_send::test_relay_routing_2() -{ - mb_message_sptr msg; - - mb_runtime_sptr rt = mb_make_runtime_nop(); - rt->run("top", "rr0_b", PMT_F); - mb_mblock_sptr top = get_top(rt); - - // Reach into the guts and see if the messages ended up where they should have - - mb_mblock_sptr c0 = top->impl()->component("c0"); - mb_mblock_sptr c0c0 = c0->impl()->component("c0"); - - mb_mblock_sptr c1 = top->impl()->component("c1"); - mb_mblock_sptr c1c0 = c1->impl()->component("c0"); - - // c0c0 should have received - // two message from c1c0 via its p2 - - msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1/c0"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1/c0"), s_p1, pmt_from_long(1)), - msg->data())); - - // c1c0 should have received - // two message from c0c0 via its p2 - - msg = c1c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = c1c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(1)), - msg->data())); -} diff --git a/mblock/src/lib/qa_mblock_send.h b/mblock/src/lib/qa_mblock_send.h deleted file mode 100644 index b1a6832ce..000000000 --- a/mblock/src/lib/qa_mblock_send.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef INCLUDED_QA_MBLOCK_SEND_H -#define INCLUDED_QA_MBLOCK_SEND_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_mblock_send : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_mblock_send); - CPPUNIT_TEST(test_simple_routing); - CPPUNIT_TEST(test_relay_routing_1); - CPPUNIT_TEST(test_relay_routing_2); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_simple_routing(); - void test_relay_routing_1(); - void test_relay_routing_2(); -}; - -#endif /* INCLUDED_QA_MBLOCK_SEND_H */ - diff --git a/mblock/src/lib/qa_mblock_sys.cc b/mblock/src/lib/qa_mblock_sys.cc deleted file mode 100644 index 8c8dbbf0a..000000000 --- a/mblock/src/lib/qa_mblock_sys.cc +++ /dev/null @@ -1,272 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <qa_mblock_sys.h> -#include <cppunit/TestAssert.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mb_runtime_nop.h> // QA only -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <stdio.h> -#include <string.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_data = pmt_intern("data"); -static pmt_t s_status = pmt_intern("status"); -static pmt_t s_control = pmt_intern("control"); -static pmt_t s_p0 = pmt_intern("p0"); -static pmt_t s_p1 = pmt_intern("p1"); -static pmt_t s_p2 = pmt_intern("p2"); -static pmt_t s_p3 = pmt_intern("p3"); -static pmt_t s_e1 = pmt_intern("e1"); -static pmt_t s_r1 = pmt_intern("r1"); - -static void -define_protocol_classes() -{ - mb_make_protocol_class(s_data, // name - pmt_list1(s_data), // incoming - pmt_list1(s_data)); // outgoing -} - - -// ================================================================ -// test_sys_1 -// ================================================================ - -class sys_1 : public mb_mblock -{ - pmt_t d_user_arg; - mb_port_sptr d_data; - -public: - sys_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~sys_1(); - void initial_transition(); -}; - -sys_1::sys_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_user_arg(user_arg) -{ - d_data = define_port("data", "data", true, mb_port::EXTERNAL); -} - -sys_1::~sys_1(){} - -void -sys_1::initial_transition() -{ - shutdown_all(d_user_arg); -} - -REGISTER_MBLOCK_CLASS(sys_1); - -void -qa_mblock_sys::test_sys_1() -{ - define_protocol_classes(); - - pmt_t result; - pmt_t n1 = pmt_from_long(1); - pmt_t n2 = pmt_from_long(2); - - mb_runtime_sptr rt1 = mb_make_runtime(); - -#if 0 - try { - rt1->run("top-1", "sys_1", n1, &result); - } - catch (omni_thread_fatal e){ - std::cerr << "caught omni_thread_fatal: error = " << e.error - << ": " << strerror(e.error) << std::endl; - } - catch (omni_thread_invalid){ - std::cerr << "caught omni_thread_invalid\n"; - } -#else - rt1->run("top-1", "sys_1", n1, &result); -#endif - CPPUNIT_ASSERT(pmt_equal(n1, result)); - - // Execute run a second time, with the same rt, to ensure sanity. - rt1->run("top-2", "sys_1", n2, &result); - CPPUNIT_ASSERT(pmt_equal(n2, result)); -} - -// ================================================================ -// test_sys_2 -// ================================================================ - -class squarer : public mb_mblock -{ - mb_port_sptr d_data; - -public: - squarer(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - - void handle_message(mb_message_sptr msg); -}; - -squarer::squarer(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_data = define_port("data", "data", true, mb_port::EXTERNAL); -} - -void -squarer::handle_message(mb_message_sptr msg) -{ - if (!pmt_eq(msg->signal(), s_data)) // we only handle the "data" message - return; - - // long x -> (long x . long (x * x)) - - pmt_t x_pmt = msg->data(); - long x = pmt_to_long(x_pmt); - d_data->send(s_data, pmt_cons(x_pmt, pmt_from_long(x * x))); -} - -REGISTER_MBLOCK_CLASS(squarer); - -// ---------------------------------------------------------------- - -class sys_2 : public mb_mblock -{ - mb_port_sptr d_data; - -public: - sys_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -sys_2::sys_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_data = define_port("data", "data", true, mb_port::INTERNAL); - define_component("squarer", "squarer"); - connect("self", "data", "squarer", "data"); -} - -void -sys_2::initial_transition() -{ - // FIXME start timer to detect general failure - - d_data->send(s_data, pmt_from_long(0)); // send initial message -} - -void -sys_2::handle_message(mb_message_sptr msg) -{ - if (!pmt_eq(msg->signal(), s_data)) // we only handle the "data" message - return; - - // first check correctness of message - - long x = pmt_to_long(pmt_car(msg->data())); - long y = pmt_to_long(pmt_cdr(msg->data())); - - // std::cout << msg->data() << std::endl; - - if (y != x * x){ - std::cerr << "sys_2::handle_message: Expected y == x * x. Got y = " - << y << " for x = " << x << std::endl; - - shutdown_all(PMT_F); // failed - } - - if (x == 100) - shutdown_all(PMT_T); // done, OK - else - d_data->send(s_data, pmt_from_long(x + 1)); // send next request -} - -REGISTER_MBLOCK_CLASS(sys_2); - -// ---------------------------------------------------------------- - -void -qa_mblock_sys::test_sys_2() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - // std::cerr << "qa_mblock_sys::test_sys_2 (enter)\n"; - - rt->run("top-sys-2", "sys_2", PMT_F, &result); - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -// ================================================================ -// test_bitset_1 -// ================================================================ - -void -qa_mblock_sys::test_bitset_1() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - long nmsgs = 1000; - long batch_size = 8; - - pmt_t arg = pmt_list2(pmt_from_long(nmsgs), // # of messages to send through pipe - pmt_from_long(batch_size)); - - rt->run("top", "qa_bitset_top", arg, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -// ================================================================ -// test_disconnect -// ================================================================ - -void -qa_mblock_sys::test_disconnect() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - long nmsgs = 10240; - - pmt_t arg = pmt_list1(pmt_from_long(nmsgs)); // # of messages to send through pipe - - - rt->run("top", "qa_disconnect_top", arg, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} diff --git a/mblock/src/lib/qa_mblock_sys.h b/mblock/src/lib/qa_mblock_sys.h deleted file mode 100644 index 0e0053a5d..000000000 --- a/mblock/src/lib/qa_mblock_sys.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef INCLUDED_QA_MBLOCK_SYS_H -#define INCLUDED_QA_MBLOCK_SYS_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_mblock_sys : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_mblock_sys); - CPPUNIT_TEST(test_sys_1); - CPPUNIT_TEST(test_sys_2); - CPPUNIT_TEST(test_bitset_1); - CPPUNIT_TEST(test_disconnect); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_sys_1(); - void test_sys_2(); - void test_bitset_1(); - void test_disconnect(); -}; - -#endif /* INCLUDED_QA_MBLOCK_SYS_H */ - diff --git a/mblock/src/lib/qa_timeouts.cc b/mblock/src/lib/qa_timeouts.cc deleted file mode 100644 index b230f86d8..000000000 --- a/mblock/src/lib/qa_timeouts.cc +++ /dev/null @@ -1,291 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <qa_timeouts.h> -#include <cppunit/TestAssert.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/message.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <mb_timer_queue.h> -#include <string.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_timeout = pmt_intern("%timeout"); -static pmt_t s_done = pmt_intern("done"); - - -// ------------------------------------------------------------------------ -// Exercise the priority queue used to implement timeouts. -// ------------------------------------------------------------------------ -void -qa_timeouts::test_timer_queue() -{ - mb_timer_queue tq; - mb_msg_accepter_sptr accepter; - - mb_timeout_sptr t1000_000 = - mb_timeout_sptr(new mb_timeout(mb_time(1000,0), PMT_F, accepter)); - - mb_timeout_sptr t2000_000 = - mb_timeout_sptr(new mb_timeout(mb_time(2000,0), PMT_F, accepter)); - - mb_timeout_sptr t3000_000 = - mb_timeout_sptr(new mb_timeout(mb_time(3000,0), PMT_F, accepter)); - - mb_timeout_sptr t3000_125 = - mb_timeout_sptr(new mb_timeout(mb_time(3000,125), PMT_F, accepter)); - - mb_timeout_sptr t3000_250 = - mb_timeout_sptr(new mb_timeout(mb_time(3000,250), PMT_F, accepter)); - - mb_timeout_sptr t4000_000 = - mb_timeout_sptr(new mb_timeout(mb_time(4000,0), PMT_F, accepter)); - - // insert in pseudo-random order - - tq.push(t3000_125); - tq.push(t1000_000); - tq.push(t4000_000); - tq.push(t3000_250); - tq.push(t2000_000); - tq.push(t3000_000); - - CPPUNIT_ASSERT_EQUAL(t1000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t2000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t3000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t3000_125, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t3000_250, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t4000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT(tq.empty()); - - // insert in pseudo-random order - - tq.push(t3000_000); - tq.push(t4000_000); - tq.push(t3000_125); - tq.push(t1000_000); - tq.push(t2000_000); - tq.push(t3000_250); - - tq.cancel(t1000_000->handle()); - - CPPUNIT_ASSERT_EQUAL(t2000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t3000_000, tq.top()); - tq.pop(); - - tq.cancel(t3000_250->handle()); - - CPPUNIT_ASSERT_EQUAL(t3000_125, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t4000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT(tq.empty()); -} - -// ------------------------------------------------------------------------ -// Test one-shot timeouts -// ------------------------------------------------------------------------ - -// FWIW, on SuSE 10.1 for x86-64, clock_getres returns 0.004 seconds. - -// #define TIMING_MARGIN 0.010 // seconds // was failing on some systems -#define TIMING_MARGIN 0.025 // seconds (really sloppy; consider enabling RT scheduler) - - -class qa_timeouts_1_top : public mb_mblock -{ - int d_nleft; - int d_nerrors; - mb_time d_t0; - -public: - qa_timeouts_1_top(mb_runtime *runtime, - const std::string &instance_name, pmt_t user_arg); - - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -qa_timeouts_1_top::qa_timeouts_1_top(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_nleft(0), d_nerrors(0) -{ -} - -void -qa_timeouts_1_top::initial_transition() -{ - d_t0 = mb_time::time(); // now - - schedule_one_shot_timeout(d_t0 + 0.200, pmt_from_double(0.200)); - schedule_one_shot_timeout(d_t0 + 0.125, pmt_from_double(0.125)); - schedule_one_shot_timeout(d_t0 + 0.075, pmt_from_double(0.075)); - schedule_one_shot_timeout(d_t0 + 0.175, pmt_from_double(0.175)); - - d_nleft = 4; -} - -void -qa_timeouts_1_top::handle_message(mb_message_sptr msg) -{ - if (pmt_eq(msg->signal(), s_timeout)){ - mb_time t_now = mb_time::time(); - double expected_delta_t = pmt_to_double(msg->data()); - double actual_delta_t = (t_now - d_t0).double_time(); - double delta = expected_delta_t - actual_delta_t; - - if (fabs(delta) > TIMING_MARGIN){ - std::cerr << "qa_timeouts_1_top: expected_delta_t = " << expected_delta_t - << " actual_delta_t = " << actual_delta_t << std::endl; - d_nerrors++; - } - - if (--d_nleft <= 0) - shutdown_all(d_nerrors == 0 ? PMT_T : PMT_F); - } -} - -REGISTER_MBLOCK_CLASS(qa_timeouts_1_top); - -void -qa_timeouts::test_timeouts_1() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "qa_timeouts_1_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -// ------------------------------------------------------------------------ -// Test periodic timeouts -// ------------------------------------------------------------------------ - -class qa_timeouts_2_top : public mb_mblock -{ - int d_nhandled; - int d_nerrors; - double d_delta_t; - mb_time d_t0; - -public: - qa_timeouts_2_top(mb_runtime *runtime, - const std::string &instance_name, pmt_t user_arg); - - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -qa_timeouts_2_top::qa_timeouts_2_top(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_nhandled(0), d_nerrors(0), d_delta_t(0.075) -{ -} - -void -qa_timeouts_2_top::initial_transition() -{ - d_t0 = mb_time::time(); // now - - schedule_periodic_timeout(d_t0 + d_delta_t, mb_time(d_delta_t), PMT_T); -} - -void -qa_timeouts_2_top::handle_message(mb_message_sptr msg) -{ - static const int NMSGS_TO_HANDLE = 5; - - if (pmt_eq(msg->signal(), s_timeout) - && !pmt_eq(msg->data(), s_done)){ - - mb_time t_now = mb_time::time(); - - d_nhandled++; - - double expected_delta_t = d_delta_t * d_nhandled; - double actual_delta_t = (t_now - d_t0).double_time(); - double delta = expected_delta_t - actual_delta_t; - - if (fabs(delta) > TIMING_MARGIN){ - std::cerr << "qa_timeouts_2_top: expected_delta_t = " << expected_delta_t - << " actual_delta_t = " << actual_delta_t << std::endl; - d_nerrors++; - } - - if (d_nhandled == NMSGS_TO_HANDLE){ - cancel_timeout(msg->metadata()); // test cancel_timeout... - schedule_one_shot_timeout(d_t0 + (d_delta_t * (d_nhandled + 2)), s_done); - } - } - - if (pmt_eq(msg->signal(), s_timeout) - && pmt_eq(msg->data(), s_done)){ - if (d_nhandled != NMSGS_TO_HANDLE){ - std::cerr << "qa_timeouts_2_top: d_nhandled = " << d_nhandled - << " expected d_nhandled = " << NMSGS_TO_HANDLE - << " (cancel_timeout didn't work)\n"; - d_nerrors++; - } - shutdown_all(d_nerrors == 0 ? PMT_T : PMT_F); - } -} - -REGISTER_MBLOCK_CLASS(qa_timeouts_2_top); - -void -qa_timeouts::test_timeouts_2() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "qa_timeouts_2_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} diff --git a/mblock/src/lib/qa_timeouts.h b/mblock/src/lib/qa_timeouts.h deleted file mode 100644 index 7c6443646..000000000 --- a/mblock/src/lib/qa_timeouts.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef INCLUDED_QA_TIMEOUTS_H -#define INCLUDED_QA_TIMEOUTS_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_timeouts : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_timeouts); - CPPUNIT_TEST(test_timer_queue); - CPPUNIT_TEST(test_timeouts_1); - CPPUNIT_TEST(test_timeouts_2); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_timer_queue(); - void test_timeouts_1(); - void test_timeouts_2(); -}; - -#endif /* INCLUDED_QA_TIMEOUTS_H */ - diff --git a/mblock/src/lib/test_mblock.cc b/mblock/src/lib/test_mblock.cc deleted file mode 100644 index b98d1b5a7..000000000 --- a/mblock/src/lib/test_mblock.cc +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <cppunit/TextTestRunner.h> -#include <qa_mblock.h> - -int -main(int argc, char **argv) -{ - - CppUnit::TextTestRunner runner; - - runner.addTest(qa_mblock::suite ()); - - bool was_successful = runner.run("", false); - - return was_successful ? 0 : 1; -} |