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/include/gruel/msg_accepter.h | 3 +++ gruel/src/include/gruel/pmt.h | 19 +++++++++++++++++++ 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 ++ 5 files changed, 87 insertions(+), 1 deletion(-) (limited to 'gruel/src') diff --git a/gruel/src/include/gruel/msg_accepter.h b/gruel/src/include/gruel/msg_accepter.h index 3afd6dde0..70ac846f5 100644 --- a/gruel/src/include/gruel/msg_accepter.h +++ b/gruel/src/include/gruel/msg_accepter.h @@ -22,6 +22,7 @@ #define INCLUDED_GRUEL_MSG_ACCEPTER_H #include +#include namespace gruel { @@ -44,6 +45,8 @@ namespace gruel { virtual void post(pmt::pmt_t msg) = 0; }; + typedef boost::shared_ptr msg_accepter_sptr; + } /* namespace gruel */ #endif /* INCLUDED_GRUEL_MSG_ACCEPTER_H */ diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 240359301..b1cb29f7c 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -24,6 +24,7 @@ #define INCLUDED_PMT_H #include +#include #include #include #include @@ -31,6 +32,10 @@ #include #include +namespace gruel { + class msg_accepter; +}; + /*! * This file defines a polymorphic type and the operations on it. * @@ -482,6 +487,20 @@ boost::any pmt_any_ref(pmt_t obj); void pmt_any_set(pmt_t obj, const boost::any &any); +/* + * ------------------------------------------------------------------------ + * msg_accepter -- pmt representation of gruel::msg_accepter + * ------------------------------------------------------------------------ + */ +//! Return true if \p obj is a msg_accepter +bool pmt_is_msg_accepter(const pmt_t &obj); + +//! make a msg_accepter +pmt_t pmt_make_msg_accepter(boost::shared_ptr ma); + +//! Return underlying msg_accepter +boost::shared_ptr pmt_msg_accepter_ref(const pmt_t &obj); + /* * ------------------------------------------------------------------------ * General functions 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/Makefile.am | 13 +++++++++++++ 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 ------------------------------------- gruel/src/lib/test_gruel.cc | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 52 deletions(-) delete mode 100644 gruel/src/lib/pmt/test_pmt.cc create mode 100644 gruel/src/lib/test_gruel.cc (limited to 'gruel/src') diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index 6dfb6787c..9afa0d292 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -25,6 +25,12 @@ SUBDIRS = pmt msg AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) + +TESTS = test_gruel + +noinst_PROGRAMS = test_gruel + + lib_LTLIBRARIES = libgruel.la # magic flags @@ -47,3 +53,10 @@ libgruel_la_LIBADD = \ $(PMT_LIB) \ $(MSG_LIB) \ -lstdc++ + + +# ---------------------------------------------------------------- + +test_gruel_SOURCES = test_gruel.cc +test_gruel_LDADD = libgruel.la pmt/libpmt-qa.la + 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; -} diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc new file mode 100644 index 000000000..669303447 --- /dev/null +++ b/gruel/src/lib/test_gruel.cc @@ -0,0 +1,37 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,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 +#include "pmt/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; +} -- cgit From 0f12441cf801f060c8b0a778016c658db5486607 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 18 Aug 2009 19:12:15 -0700 Subject: Add top-level msg_passing.h include file. Incorporate send.h into msg_passing.h. --- gruel/src/include/gruel/Makefile.am | 2 +- gruel/src/include/gruel/msg_passing.h | 88 +++++++++++++++++++++++++++++++++++ gruel/src/include/gruel/send.h | 49 ------------------- 3 files changed, 89 insertions(+), 50 deletions(-) create mode 100644 gruel/src/include/gruel/msg_passing.h delete mode 100644 gruel/src/include/gruel/send.h (limited to 'gruel/src') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 9f50cb619..9aedc7fda 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -31,11 +31,11 @@ gruelinclude_HEADERS = \ msg_accepter.h \ msg_accepter_msgq.h \ msg_queue.h \ + msg_passing.h \ pmt.h \ pmt_pool.h \ pmt_serial_tags.h \ realtime.h \ - send.h \ sys_pri.h \ thread_body_wrapper.h \ thread_group.h \ diff --git a/gruel/src/include/gruel/msg_passing.h b/gruel/src/include/gruel/msg_passing.h new file mode 100644 index 000000000..611058499 --- /dev/null +++ b/gruel/src/include/gruel/msg_passing.h @@ -0,0 +1,88 @@ +/* -*- c++ -*- */ +/* + * Copyright 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_GRUEL_MSG_PASSING_H +#define INCLUDED_GRUEL_MSG_PASSING_H + +/*! + * \brief Include this header to use the message passing features + */ + +#include +#include + + +namespace gruel { + + /*! + * \brief send message to msg_accepter + * + * \param accepter is the target of the send. + * \param msg is the message to send. It's usually a pmt tuple. + * + * Sending a message is an asynchronous operation. The \p send + * call will not wait for the message either to arrive at the + * destination or to be received. + * + * \returns msg + */ + static inline pmt::pmt_t + send(msg_accepter_sptr accepter, const pmt::pmt_t &msg) + { + return accepter->post(msg); + } + + /*! + * \brief send message to msg_accepter + * + * \param accepter is the target of the send. + * \param msg is the message to send. It's usually a pmt tuple. + * + * Sending a message is an asynchronous operation. The \p send + * call will not wait for the message either to arrive at the + * destination or to be received. + * + * \returns msg + */ + static inline pmt::pmt_t + send(msg_accepter &accepter, const pmt::pmt_t &msg) + { + return accepter.post(msg); + } + + /*! + * \brief send message to msg_accepter + * + * \param accepter is the target of the send. precond: pmt_is_msg_accepter(accepter) + * \param msg is the message to send. It's usually a pmt tuple. + * + * Sending a message is an asynchronous operation. The \p send + * call will not wait for the message either to arrive at the + * destination or to be received. + * + * \returns msg + */ + pmt::pmt_t + send(const pmt_t &accepter, const pmt::pmt_t &msg); + + +} /* namespace gruel */ + +#endif /* INCLUDED_GRUEL_MSG_PASSING_H */ diff --git a/gruel/src/include/gruel/send.h b/gruel/src/include/gruel/send.h deleted file mode 100644 index 292017d45..000000000 --- a/gruel/src/include/gruel/send.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 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_GRUEL_SEND_H -#define INCLUDED_GRUEL_SEND_H - -#include - -namespace gruel { - - - /*! - * \brief send \p msg to \p msg_accepter - * - * Sending a message is an asynchronous operation. The \p send - * call will not wait for the message either to arrive at the - * destination or to be received. - * - * \returns msg - */ - static inline pmt::pmt_t - send(msg_accepter &acc, pmt::pmt_t msg) - { - return acc.post(msg); - } - - - -} /* namespace gruel */ - - -#endif /* INCLUDED_SEND_H */ -- 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/include/gruel/msg_passing.h | 33 ++++++++++++++++++++++++++++----- gruel/src/lib/pmt/qa_pmt_prims.cc | 9 +++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'gruel/src') diff --git a/gruel/src/include/gruel/msg_passing.h b/gruel/src/include/gruel/msg_passing.h index 611058499..ebbeca815 100644 --- a/gruel/src/include/gruel/msg_passing.h +++ b/gruel/src/include/gruel/msg_passing.h @@ -46,7 +46,27 @@ namespace gruel { static inline pmt::pmt_t send(msg_accepter_sptr accepter, const pmt::pmt_t &msg) { - return accepter->post(msg); + accepter->post(msg); + return msg; + } + + /*! + * \brief send message to msg_accepter + * + * \param accepter is the target of the send. + * \param msg is the message to send. It's usually a pmt tuple. + * + * Sending a message is an asynchronous operation. The \p send + * call will not wait for the message either to arrive at the + * destination or to be received. + * + * \returns msg + */ + static inline pmt::pmt_t + send(msg_accepter *accepter, const pmt::pmt_t &msg) + { + accepter->post(msg); + return msg; } /*! @@ -64,7 +84,8 @@ namespace gruel { static inline pmt::pmt_t send(msg_accepter &accepter, const pmt::pmt_t &msg) { - return accepter.post(msg); + accepter.post(msg); + return msg; } /*! @@ -79,9 +100,11 @@ namespace gruel { * * \returns msg */ - pmt::pmt_t - send(const pmt_t &accepter, const pmt::pmt_t &msg); - + static inline pmt::pmt_t + send(pmt::pmt_t accepter, const pmt::pmt_t &msg) + { + return send(pmt_msg_accepter_ref(accepter), msg); + } } /* namespace gruel */ 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/include/gruel/Makefile.am | 1 + gruel/src/include/gruel/pmt.h | 30 ++++++++++++ gruel/src/include/gruel/pmt_sugar.h | 94 +++++++++++++++++++++++++++++++++++++ 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 + 6 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 gruel/src/include/gruel/pmt_sugar.h (limited to 'gruel/src') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 9aedc7fda..67dd12995 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -35,6 +35,7 @@ gruelinclude_HEADERS = \ pmt.h \ pmt_pool.h \ pmt_serial_tags.h \ + pmt_sugar.h \ realtime.h \ sys_pri.h \ thread_body_wrapper.h \ diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index b1cb29f7c..3188aad1d 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -304,6 +304,33 @@ void pmt_vector_set(pmt_t vector, size_t k, pmt_t obj); //! Store \p fill in every position of \p vector void pmt_vector_fill(pmt_t vector, pmt_t fill); +/* + * ------------------------------------------------------------------------ + * Binary Large Objects (BLOBs) + * + * Handy for passing around uninterpreted chunks of memory. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a blob, othewise false. +bool pmt_is_blob(pmt_t x); + +/*! + * \brief Make a blob given a pointer and length in bytes + * + * \param buf is the pointer to data to use to create blob + * \param len is the size of the data in bytes. + * + * The data is copied into the blob. + */ +pmt_t pmt_make_blob(const void *buf, size_t len); + +//! Return a pointer to the blob's data +const void *pmt_blob_data(pmt_t blob); + +//! Return the blob's length in bytes +size_t pmt_blob_length(pmt_t blob); + /*! *
  * ------------------------------------------------------------------------
@@ -736,4 +763,7 @@ void pmt_dump_sizeof();	// debugging
 
 } /* namespace pmt */
 
+
+#include 
+
 #endif /* INCLUDED_PMT_H */
diff --git a/gruel/src/include/gruel/pmt_sugar.h b/gruel/src/include/gruel/pmt_sugar.h
new file mode 100644
index 000000000..830dfc3fe
--- /dev/null
+++ b/gruel/src/include/gruel/pmt_sugar.h
@@ -0,0 +1,94 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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_GRUEL_PMT_SUGAR_H
+#define INCLUDED_GRUEL_PMT_SUGAR_H
+
+/*!
+ * This file is included by pmt.h and contains pseudo-constructor
+ * shorthand for making pmt objects
+ */
+
+namespace pmt {
+
+  //! Make pmt symbol
+  static inline pmt_t
+  mp(const std::string &s)
+  {
+    return pmt_string_to_symbol(s);
+  }
+
+  //! Make pmt symbol
+  static inline pmt_t
+  mp(const char *s)
+  {
+    return pmt_string_to_symbol(s);
+  }
+
+  //! Make pmt long
+  static inline pmt_t
+  mp(long x){
+    return pmt_from_long(x);
+  }
+
+  //! Make pmt long
+  static inline pmt_t
+  mp(int x){
+    return pmt_from_long(x);
+  }
+
+  //! Make pmt double
+  static inline pmt_t
+  mp(double x){
+    return pmt_from_double(x);
+  }
+  
+  //! Make pmt complex
+  static inline pmt_t
+  mp(std::complex z)
+  {
+    return pmt_make_rectangular(z.real(), z.imag());
+  }
+
+  //! Make pmt complex
+  static inline pmt_t
+  mp(std::complex z)
+  {
+    return pmt_make_rectangular(z.real(), z.imag());
+  }
+
+  //! Make pmt msg_accepter
+  static inline pmt_t
+  mp(boost::shared_ptr ma)
+  {
+    return pmt_make_msg_accepter(ma);
+  }
+
+  //! Make pmt Binary Large Object (BLOB)
+  static inline pmt_t
+  mp(const void *data, size_t len_in_bytes)
+  {
+    return pmt_make_blob(data, len_in_bytes);
+  }
+
+} /* namespace pmt */
+
+
+#endif /* INCLUDED_GRUEL_PMT_SUGAR_H */
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 


From cafcd00720877d099262e78ac623a13118574233 Mon Sep 17 00:00:00 2001
From: Eric Blossom
Date: Wed, 19 Aug 2009 09:57:42 -0700
Subject: Add shorthand for making tuples.

---
 gruel/src/include/gruel/pmt_sugar.h | 71 +++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

(limited to 'gruel/src')

diff --git a/gruel/src/include/gruel/pmt_sugar.h b/gruel/src/include/gruel/pmt_sugar.h
index 830dfc3fe..92bcb5fe5 100644
--- a/gruel/src/include/gruel/pmt_sugar.h
+++ b/gruel/src/include/gruel/pmt_sugar.h
@@ -88,6 +88,77 @@ namespace pmt {
     return pmt_make_blob(data, len_in_bytes);
   }
 
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0)
+  {
+    return pmt_make_tuple(e0);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1)
+  {
+    return pmt_make_tuple(e0, e1);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2)
+  {
+    return pmt_make_tuple(e0, e1, e2);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3)
+  {
+    return pmt_make_tuple(e0, e1, e2, e3);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4)
+  {
+    return pmt_make_tuple(e0, e1, e2, e3, e4);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5)
+  {
+    return pmt_make_tuple(e0, e1, e2, e3, e4, e5);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6)
+  {
+    return pmt_make_tuple(e0, e1, e2, e3, e4, e5, e6);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7)
+  {
+    return pmt_make_tuple(e0, e1, e2, e3, e4, e5, e6, e7);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7, const pmt_t &e8)
+  {
+    return pmt_make_tuple(e0, e1, e2, e3, e4, e5, e6, e7, e8);
+  }
+
+  //! Make tuple
+  static inline pmt_t
+  mp(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7, const pmt_t &e8, const pmt_t &e9)
+  {
+    return pmt_make_tuple(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9);
+  }
+
+
 } /* namespace pmt */
 
 
-- 
cgit