diff options
author | Johnathan Corgan | 2009-08-26 16:48:36 -0700 |
---|---|---|
committer | Johnathan Corgan | 2009-08-26 16:48:36 -0700 |
commit | 20e87ef0575d6bf09ab19fa1d025dbe71eec27fb (patch) | |
tree | 931c373077f156fe667464d9136d00df68f06604 /gruel/src/lib/pmt | |
parent | 23fb5e602d48f6924e70b363bf9480fd41b928b0 (diff) | |
parent | cafcd00720877d099262e78ac623a13118574233 (diff) | |
download | gnuradio-20e87ef0575d6bf09ab19fa1d025dbe71eec27fb.tar.gz gnuradio-20e87ef0575d6bf09ab19fa1d025dbe71eec27fb.tar.bz2 gnuradio-20e87ef0575d6bf09ab19fa1d025dbe71eec27fb.zip |
Merge msg-passing from http://gnuradio.org/git/eb.git
* Add shorthand for making tuples.
* Add blobs and shorthand pmt pseudo-constructors.
* gruel::send can now send to a pmt.
* Add top-level msg_passing.h include file.
* QA code now works.
* Add pmt type that wraps a gruel::msg_accepter.
Diffstat (limited to 'gruel/src/lib/pmt')
-rw-r--r-- | gruel/src/lib/pmt/Makefile.am | 9 | ||||
-rw-r--r-- | gruel/src/lib/pmt/pmt.cc | 70 | ||||
-rw-r--r-- | gruel/src/lib/pmt/qa_pmt_prims.cc | 56 | ||||
-rw-r--r-- | gruel/src/lib/pmt/qa_pmt_prims.h | 4 | ||||
-rw-r--r-- | gruel/src/lib/pmt/test_pmt.cc | 37 |
5 files changed, 127 insertions, 49 deletions
diff --git a/gruel/src/lib/pmt/Makefile.am b/gruel/src/lib/pmt/Makefile.am index 2b710a598..8750cbdf8 100644 --- a/gruel/src/lib/pmt/Makefile.am +++ b/gruel/src/lib/pmt/Makefile.am @@ -23,7 +23,6 @@ include $(top_srcdir)/Makefile.common AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) -TESTS = test_pmt noinst_LTLIBRARIES = libpmt.la @@ -90,14 +89,6 @@ libpmt_qa_la_LIBADD = \ $(CPPUNIT_LIBS) \ -lstdc++ -noinst_PROGRAMS = \ - test_pmt - - -LIBPMTQA = libpmt-qa.la - -test_pmt_SOURCES = test_pmt.cc -test_pmt_LDADD = $(LIBPMTQA) # Do creation and inclusion of other Makefiles last diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index f0e3c30a2..e50e21838 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -26,8 +26,9 @@ #include <vector> #include <gruel/pmt.h> #include "pmt_int.h" -#include <stdio.h> +#include <gruel/msg_accepter.h> #include <gruel/pmt_pool.h> +#include <stdio.h> #include <string.h> namespace pmt { @@ -882,6 +883,73 @@ pmt_any_set(pmt_t obj, const boost::any &any) } //////////////////////////////////////////////////////////////////////////// +// msg_accepter -- built from "any" +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_is_msg_accepter(const pmt_t &obj) +{ + if (!pmt_is_any(obj)) + return false; + + boost::any r = pmt_any_ref(obj); + return boost::any_cast<gruel::msg_accepter_sptr>(&r) != 0; +} + +//! make a msg_accepter +pmt_t +pmt_make_msg_accepter(gruel::msg_accepter_sptr ma) +{ + return pmt_make_any(ma); +} + +//! Return underlying msg_accepter +gruel::msg_accepter_sptr +pmt_msg_accepter_ref(const pmt_t &obj) +{ + try { + return boost::any_cast<gruel::msg_accepter_sptr>(pmt_any_ref(obj)); + } + catch (boost::bad_any_cast &e){ + throw pmt_wrong_type("pmt_msg_accepter_ref", obj); + } +} + + +//////////////////////////////////////////////////////////////////////////// +// Binary Large Object -- currently a u8vector +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_is_blob(pmt_t x) +{ + // return pmt_is_u8vector(x); + return pmt_is_uniform_vector(x); +} + +pmt_t +pmt_make_blob(const void *buf, size_t len_in_bytes) +{ + return pmt_init_u8vector(len_in_bytes, (const uint8_t *) buf); +} + +const void * +pmt_blob_data(pmt_t blob) +{ + size_t len; + return pmt_uniform_vector_elements(blob, len); +} + +size_t +pmt_blob_length(pmt_t blob) +{ + size_t len; + pmt_uniform_vector_elements(blob, len); + return len; +} + + +//////////////////////////////////////////////////////////////////////////// // General Functions //////////////////////////////////////////////////////////////////////////// diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 899674bbb..59d9e14d3 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -22,8 +22,9 @@ #include <qa_pmt_prims.h> #include <cppunit/TestAssert.h> -#include <gruel/pmt.h> -#include <stdio.h> +#include <gruel/msg_passing.h> +#include <cstdio> +#include <cstring> #include <sstream> using namespace pmt; @@ -453,6 +454,41 @@ qa_pmt_prims::test_any() // ------------------------------------------------------------------------ +class qa_pmt_msg_accepter_nop : public gruel::msg_accepter { +public: + qa_pmt_msg_accepter_nop(){}; + ~qa_pmt_msg_accepter_nop(); + void post(pmt_t){}; +}; + +qa_pmt_msg_accepter_nop::~qa_pmt_msg_accepter_nop(){} + +void +qa_pmt_prims::test_msg_accepter() +{ + pmt_t sym = pmt_intern("my-symbol"); + + boost::any a0; + a0 = std::string("Hello!"); + pmt_t p0 = pmt_make_any(a0); + + gruel::msg_accepter_sptr ma0 = gruel::msg_accepter_sptr(new qa_pmt_msg_accepter_nop()); + pmt_t p1 = pmt_make_msg_accepter(ma0); + + CPPUNIT_ASSERT_EQUAL(ma0.get(), pmt_msg_accepter_ref(p1).get()); + + CPPUNIT_ASSERT_THROW(pmt_msg_accepter_ref(sym), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_msg_accepter_ref(p0), pmt_wrong_type); + + // just confirm interfaces on send are OK + gruel::send(ma0.get(), sym); + gruel::send(ma0, sym); + gruel::send(p1, sym); + +} + +// ------------------------------------------------------------------------ + void qa_pmt_prims::test_serialize() { @@ -522,3 +558,19 @@ qa_pmt_prims::test_sets() CPPUNIT_ASSERT(!pmt_subsetp(l3,l2)); } +void +qa_pmt_prims::test_sugar() +{ + CPPUNIT_ASSERT(pmt_is_symbol(mp("my-symbol"))); + CPPUNIT_ASSERT_EQUAL((long) 10, pmt_to_long(mp(10))); + CPPUNIT_ASSERT_EQUAL((double) 1e6, pmt_to_double(mp(1e6))); + CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, 3), + pmt_to_complex(mp(std::complex<double>(2, 3)))); + + int buf[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + pmt_t blob = mp(buf, sizeof(buf)); + const void *data = pmt_blob_data(blob); + size_t nbytes = pmt_blob_length(blob); + CPPUNIT_ASSERT_EQUAL(sizeof(buf), nbytes); + CPPUNIT_ASSERT(memcmp(buf, data, nbytes) == 0); +} diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h index 2fe473c43..29ba02f11 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.h +++ b/gruel/src/lib/pmt/qa_pmt_prims.h @@ -40,10 +40,12 @@ class qa_pmt_prims : public CppUnit::TestCase { CPPUNIT_TEST(test_misc); CPPUNIT_TEST(test_dict); CPPUNIT_TEST(test_any); + CPPUNIT_TEST(test_msg_accepter); CPPUNIT_TEST(test_io); CPPUNIT_TEST(test_lists); CPPUNIT_TEST(test_serialize); CPPUNIT_TEST(test_sets); + CPPUNIT_TEST(test_sugar); CPPUNIT_TEST_SUITE_END(); private: @@ -59,10 +61,12 @@ class qa_pmt_prims : public CppUnit::TestCase { void test_misc(); void test_dict(); void test_any(); + void test_msg_accepter(); void test_io(); void test_lists(); void test_serialize(); void test_sets(); + void test_sugar(); }; #endif /* INCLUDED_QA_PMT_PRIMS_H */ diff --git a/gruel/src/lib/pmt/test_pmt.cc b/gruel/src/lib/pmt/test_pmt.cc deleted file mode 100644 index 034785f4e..000000000 --- a/gruel/src/lib/pmt/test_pmt.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., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#include <cppunit/TextTestRunner.h> -#include <qa_pmt.h> - -int -main(int argc, char **argv) -{ - - CppUnit::TextTestRunner runner; - - runner.addTest(qa_pmt::suite ()); - - bool was_successful = runner.run("", false); - - return was_successful ? 0 : 1; -} |