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/include | |
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/include')
-rw-r--r-- | gruel/src/include/gruel/Makefile.am | 3 | ||||
-rw-r--r-- | gruel/src/include/gruel/msg_accepter.h | 3 | ||||
-rw-r--r-- | gruel/src/include/gruel/msg_passing.h | 111 | ||||
-rw-r--r-- | gruel/src/include/gruel/pmt.h | 49 | ||||
-rw-r--r-- | gruel/src/include/gruel/pmt_sugar.h | 165 | ||||
-rw-r--r-- | gruel/src/include/gruel/send.h | 49 |
6 files changed, 330 insertions, 50 deletions
diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 9f50cb619..67dd12995 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -31,11 +31,12 @@ gruelinclude_HEADERS = \ msg_accepter.h \ msg_accepter_msgq.h \ msg_queue.h \ + msg_passing.h \ pmt.h \ pmt_pool.h \ pmt_serial_tags.h \ + pmt_sugar.h \ realtime.h \ - send.h \ sys_pri.h \ thread_body_wrapper.h \ thread_group.h \ 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 <gruel/pmt.h> +#include <boost/shared_ptr.hpp> namespace gruel { @@ -44,6 +45,8 @@ namespace gruel { virtual void post(pmt::pmt_t msg) = 0; }; + typedef boost::shared_ptr<msg_accepter> msg_accepter_sptr; + } /* namespace gruel */ #endif /* INCLUDED_GRUEL_MSG_ACCEPTER_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..ebbeca815 --- /dev/null +++ b/gruel/src/include/gruel/msg_passing.h @@ -0,0 +1,111 @@ +/* -*- 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 <gruel/pmt.h> +#include <gruel/msg_accepter.h> + + +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) + { + 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; + } + + /*! + * \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; + } + + /*! + * \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 + */ + 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 */ + +#endif /* INCLUDED_GRUEL_MSG_PASSING_H */ diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 240359301..3188aad1d 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -24,6 +24,7 @@ #define INCLUDED_PMT_H #include <boost/intrusive_ptr.hpp> +#include <boost/shared_ptr.hpp> #include <boost/any.hpp> #include <complex> #include <string> @@ -31,6 +32,10 @@ #include <iosfwd> #include <stdexcept> +namespace gruel { + class msg_accepter; +}; + /*! * This file defines a polymorphic type and the operations on it. * @@ -299,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); + /*! * <pre> * ------------------------------------------------------------------------ @@ -484,6 +516,20 @@ 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<gruel::msg_accepter> ma); + +//! Return underlying msg_accepter +boost::shared_ptr<gruel::msg_accepter> pmt_msg_accepter_ref(const pmt_t &obj); + +/* + * ------------------------------------------------------------------------ * General functions * ------------------------------------------------------------------------ */ @@ -717,4 +763,7 @@ void pmt_dump_sizeof(); // debugging } /* namespace pmt */ + +#include <gruel/pmt_sugar.h> + #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..92bcb5fe5 --- /dev/null +++ b/gruel/src/include/gruel/pmt_sugar.h @@ -0,0 +1,165 @@ +/* -*- 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<double> z) + { + return pmt_make_rectangular(z.real(), z.imag()); + } + + //! Make pmt complex + static inline pmt_t + mp(std::complex<float> z) + { + return pmt_make_rectangular(z.real(), z.imag()); + } + + //! Make pmt msg_accepter + static inline pmt_t + mp(boost::shared_ptr<gruel::msg_accepter> 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); + } + + //! 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 */ + + +#endif /* INCLUDED_GRUEL_PMT_SUGAR_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 <gruel/msg_accepter.h> - -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 */ |