From 0f90ae17548c89a9ccde112948a6b57b54c2a01c Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 18 Aug 2009 17:39:02 -0700 Subject: Add pmt type that wraps a gruel::msg_accepter. QA code doesn't link because pmt depends on msg and vice versa --- gruel/src/lib/pmt/pmt.cc | 33 ++++++++++++++++++++++++++++++++- gruel/src/lib/pmt/qa_pmt_prims.cc | 31 +++++++++++++++++++++++++++++++ gruel/src/lib/pmt/qa_pmt_prims.h | 2 ++ 3 files changed, 65 insertions(+), 1 deletion(-) (limited to 'gruel/src/lib/pmt') diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index f0e3c30a2..5301529b2 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -26,8 +26,9 @@ #include #include #include "pmt_int.h" -#include +#include #include +#include #include namespace pmt { @@ -881,6 +882,36 @@ pmt_any_set(pmt_t obj, const boost::any &any) _any(obj)->set(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(&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) +{ + return boost::any_cast(pmt_any_ref(obj)); +} + + + //////////////////////////////////////////////////////////////////////////// // General Functions //////////////////////////////////////////////////////////////////////////// diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 899674bbb..2c66b8fdb 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -453,6 +454,36 @@ 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); // FIXME + +} + +// ------------------------------------------------------------------------ + void qa_pmt_prims::test_serialize() { diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h index 2fe473c43..fd6f70c8e 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.h +++ b/gruel/src/lib/pmt/qa_pmt_prims.h @@ -40,6 +40,7 @@ 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); @@ -59,6 +60,7 @@ 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(); -- cgit From f7bc7ed21decef03737effa69402d127e1cb54d9 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 18 Aug 2009 18:57:33 -0700 Subject: QA code now works. --- gruel/src/lib/pmt/Makefile.am | 9 --------- gruel/src/lib/pmt/pmt.cc | 8 ++++++-- gruel/src/lib/pmt/qa_pmt_prims.cc | 7 +++---- gruel/src/lib/pmt/test_pmt.cc | 37 ------------------------------------- 4 files changed, 9 insertions(+), 52 deletions(-) delete mode 100644 gruel/src/lib/pmt/test_pmt.cc (limited to 'gruel/src/lib/pmt') 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 5301529b2..42f25b9de 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -907,11 +907,15 @@ pmt_make_msg_accepter(gruel::msg_accepter_sptr ma) gruel::msg_accepter_sptr pmt_msg_accepter_ref(const pmt_t &obj) { - return boost::any_cast(pmt_any_ref(obj)); + try { + return boost::any_cast(pmt_any_ref(obj)); + } + catch (boost::bad_any_cast &e){ + throw pmt_wrong_type("pmt_msg_accepter_ref", obj); + } } - //////////////////////////////////////////////////////////////////////////// // General Functions //////////////////////////////////////////////////////////////////////////// diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 2c66b8fdb..e2d6ec4c6 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -456,9 +456,9 @@ 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(){}; ~qa_pmt_msg_accepter_nop(); - void post(pmt_t) { }; + void post(pmt_t){}; }; qa_pmt_msg_accepter_nop::~qa_pmt_msg_accepter_nop(){} @@ -478,8 +478,7 @@ qa_pmt_prims::test_msg_accepter() 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); // FIXME - + CPPUNIT_ASSERT_THROW(pmt_msg_accepter_ref(p0), pmt_wrong_type); } // ------------------------------------------------------------------------ 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 -#include - -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; -} -- cgit From 4425cea2297d29f7cb90ac045b39928358cff1e4 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 18 Aug 2009 21:02:13 -0700 Subject: gruel::send can now send to a pmt. --- gruel/src/lib/pmt/qa_pmt_prims.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'gruel/src/lib/pmt') diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index e2d6ec4c6..04fdc1a43 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -22,8 +22,7 @@ #include #include -#include -#include +#include #include #include @@ -479,6 +478,12 @@ qa_pmt_prims::test_msg_accepter() 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); + } // ------------------------------------------------------------------------ -- cgit From 6213d97eba31b66f8234357c6f030124f417f74d Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 18 Aug 2009 22:44:05 -0700 Subject: Add blobs and shorthand pmt pseudo-constructors. blobs == Binary Large Object. Very handy for passing around uninterpreted data. The shorthand constructors were implemented by overloading the pmt_t mp(foo) function in the pmt namespace. I originally called "mp" "pmt", but that caused a conflict with the pmt namespace. --- gruel/src/lib/pmt/pmt.cc | 33 +++++++++++++++++++++++++++++++++ gruel/src/lib/pmt/qa_pmt_prims.cc | 19 ++++++++++++++++++- gruel/src/lib/pmt/qa_pmt_prims.h | 2 ++ 3 files changed, 53 insertions(+), 1 deletion(-) (limited to 'gruel/src/lib/pmt') diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index 42f25b9de..e50e21838 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -916,6 +916,39 @@ pmt_msg_accepter_ref(const pmt_t &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 04fdc1a43..59d9e14d3 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -23,7 +23,8 @@ #include #include #include -#include +#include +#include #include using namespace pmt; @@ -557,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(2, 3), + pmt_to_complex(mp(std::complex(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 fd6f70c8e..29ba02f11 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.h +++ b/gruel/src/lib/pmt/qa_pmt_prims.h @@ -45,6 +45,7 @@ class qa_pmt_prims : public CppUnit::TestCase { CPPUNIT_TEST(test_lists); CPPUNIT_TEST(test_serialize); CPPUNIT_TEST(test_sets); + CPPUNIT_TEST(test_sugar); CPPUNIT_TEST_SUITE_END(); private: @@ -65,6 +66,7 @@ class qa_pmt_prims : public CppUnit::TestCase { void test_lists(); void test_serialize(); void test_sets(); + void test_sugar(); }; #endif /* INCLUDED_QA_PMT_PRIMS_H */ -- cgit