From b48de00cfefac61414b0ea568e5014f2794e50cd Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 20 Jun 2008 18:14:47 +0000 Subject: Merged -r8639:8641 from jcorgan/gruel into trunk. Adds libgruel, the GNU Radio Utility Etcetera Library. See README for description. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8642 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/AUTHORS | 1 + gruel/ChangeLog | 20 +++++++ gruel/Makefile.am | 30 ++++++++++ gruel/README | 30 ++++++++++ gruel/gruel.pc.in | 11 ++++ gruel/src/Makefile.am | 22 +++++++ gruel/src/include/Makefile.am | 22 +++++++ gruel/src/include/gruel/Makefile.am | 27 +++++++++ gruel/src/include/gruel/realtime.h | 44 ++++++++++++++ gruel/src/lib/Makefile.am | 39 +++++++++++++ gruel/src/lib/realtime.cc | 112 ++++++++++++++++++++++++++++++++++++ 11 files changed, 358 insertions(+) create mode 100644 gruel/AUTHORS create mode 100644 gruel/ChangeLog create mode 100644 gruel/Makefile.am create mode 100644 gruel/README create mode 100644 gruel/gruel.pc.in create mode 100644 gruel/src/Makefile.am create mode 100644 gruel/src/include/Makefile.am create mode 100644 gruel/src/include/gruel/Makefile.am create mode 100644 gruel/src/include/gruel/realtime.h create mode 100644 gruel/src/lib/Makefile.am create mode 100644 gruel/src/lib/realtime.cc (limited to 'gruel') diff --git a/gruel/AUTHORS b/gruel/AUTHORS new file mode 100644 index 000000000..18e03c4a9 --- /dev/null +++ b/gruel/AUTHORS @@ -0,0 +1 @@ +Johnathan Corgan diff --git a/gruel/ChangeLog b/gruel/ChangeLog new file mode 100644 index 000000000..b185665ee --- /dev/null +++ b/gruel/ChangeLog @@ -0,0 +1,20 @@ +# +# Copyright 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# diff --git a/gruel/Makefile.am b/gruel/Makefile.am new file mode 100644 index 000000000..93f56a7db --- /dev/null +++ b/gruel/Makefile.am @@ -0,0 +1,30 @@ +# +# Copyright 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +EXTRA_DIST = \ + gruel.pc.in + +SUBDIRS = src + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = gruel.pc diff --git a/gruel/README b/gruel/README new file mode 100644 index 000000000..585cf026a --- /dev/null +++ b/gruel/README @@ -0,0 +1,30 @@ +# +# Copyright 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +The GNU Radio Utility Etcetera Library, a collection of low-level routines +to avoid dependencies on the full GNU Radio core or other libraries. + +Over time, some code from libgnuradio-core, libpmt, libmblock, libusrp, +and libusrp2 will migrate here, to avoid duplication of code and simplify +dependencies. + +By design, this library will not have dependencies on any other part +of GNU Radio, but may have external dependencies such as Boost. diff --git a/gruel/gruel.pc.in b/gruel/gruel.pc.in new file mode 100644 index 000000000..6377f5bb3 --- /dev/null +++ b/gruel/gruel.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: gruel +Description: The GNU Radio Utility Etcetera Library +Requires: +Version: @VERSION@ +Libs: -L${libdir} -lgruel +Cflags: -I${includedir} diff --git a/gruel/src/Makefile.am b/gruel/src/Makefile.am new file mode 100644 index 000000000..90c0f88bd --- /dev/null +++ b/gruel/src/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +SUBDIRS = include lib diff --git a/gruel/src/include/Makefile.am b/gruel/src/include/Makefile.am new file mode 100644 index 000000000..7a178810a --- /dev/null +++ b/gruel/src/include/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +SUBDIRS = gruel diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am new file mode 100644 index 000000000..8ea484ced --- /dev/null +++ b/gruel/src/include/gruel/Makefile.am @@ -0,0 +1,27 @@ +# +# Copyright 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +gruelincludedir = $(prefix)/include/gruel + +gruelinclude_HEADERS = \ + realtime.h diff --git a/gruel/src/include/gruel/realtime.h b/gruel/src/include/gruel/realtime.h new file mode 100644 index 000000000..ded70ed0d --- /dev/null +++ b/gruel/src/include/gruel/realtime.h @@ -0,0 +1,44 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_REALTIME_H +#define INCLUDED_REALTIME_H + +namespace gruel { + + typedef enum { + RT_OK = 0, + RT_NOT_IMPLEMENTED, + RT_NO_PRIVS, + RT_OTHER_ERROR + } rt_status_t; + + /*! + * \brief If possible, enable high-priority "real time" scheduling. + * \ingroup misc + */ + rt_status_t + enable_realtime_scheduling(); + +} // namespace gruel + +#endif /* INCLUDED_GR_REALTIME_H */ diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am new file mode 100644 index 000000000..972ff4ca9 --- /dev/null +++ b/gruel/src/lib/Makefile.am @@ -0,0 +1,39 @@ +# +# Copyright 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +AM_CPPFLAGS = $(DEFINES) $(BOOST_CFLAGS) $(GRUEL_INCLUDES) $(WITH_INCLUDES) + +lib_LTLIBRARIES = libgruel.la + +# These are the source files that go into the gruel shared library +libgruel_la_SOURCES = \ + realtime.cc + +# magic flags +libgruel_la_LDFLAGS = $(NO_UNDEFINED) + +# link the library against the c++ standard library +libgruel_la_LIBADD = \ + -lstdc++ + +noinst_HEADERS = diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc new file mode 100644 index 000000000..bdcb31ab6 --- /dev/null +++ b/gruel/src/lib/realtime.cc @@ -0,0 +1,112 @@ +/* -*- 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#ifdef HAVE_SCHED_H +#include +#endif + +#include +#include +#include + +#if defined(HAVE_SCHED_SETSCHEDULER) + +namespace gruel { + + rt_status_t + enable_realtime_scheduling() + { + int policy = SCHED_FIFO; + int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2; + int pid = 0; // this process + + struct sched_param param; + memset(¶m, 0, sizeof(param)); + param.sched_priority = pri; + int result = sched_setscheduler(pid, policy, ¶m); + if (result != 0){ + if (errno == EPERM) + return RT_NO_PRIVS; + else { + perror ("sched_setscheduler: failed to set real time priority"); + return RT_OTHER_ERROR; + } + } + + //printf("SCHED_FIFO enabled with priority = %d\n", pri); + return RT_OK; + } + +} // namespace gruel + +#elif defined(HAVE_PTHREAD_SETSCHEDPARAM) + +#include +#include + +namespace gruel { + + rt_status_t + enable_realtime_scheduling() + { + int policy = SCHED_FIFO; + int pri = (sched_get_priority_max (policy) + + sched_get_priority_min (policy)) / 2; + pthread_t this_thread = pthread_self (); // this process + struct sched_param param; + memset (¶m, 0, sizeof (param)); + param.sched_priority = pri; + int result = pthread_setschedparam (this_thread, policy, ¶m); + if (result != 0) { + if (errno == EPERM) + return RT_NO_PRIVS; + else { + perror ("pthread_setschedparam: failed to set real time priority"); + return RT_OTHER_ERROR; + } + } + + //printf("SCHED_FIFO enabled with priority = %d\n", pri); + return RT_OK; + } +} // namespace gruel + +// #elif // could try negative niceness + +#else + +namespace gruel { + + rt_status_t + enable_realtime_scheduling() + { + return RT_NOT_IMPLEMENTED; + } +} // namespace gruel + +#endif -- cgit From 1adf4453962da0c2ebda1a8833ef3b5b849754e3 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sun, 22 Jun 2008 22:56:48 +0000 Subject: Added autoconf independent bytesex routines to libgruel. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8654 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/include/gruel/Makefile.am | 4 +++ gruel/src/include/gruel/inet.h.in | 63 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 gruel/src/include/gruel/inet.h.in (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 8ea484ced..e5970cc49 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -21,7 +21,11 @@ include $(top_srcdir)/Makefile.common +BUILT_SOURCES = \ + inet.h + gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ + $(BUILT_SOURCES) \ realtime.h diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in new file mode 100644 index 000000000..dd0525708 --- /dev/null +++ b/gruel/src/include/gruel/inet.h.in @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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, see . + */ + +#ifndef INCLUDED_INET_H +#define INCLUDED_INET_H + +#include + +#if @GR_ARCH_BIGENDIAN@ /* GR_ARCH_BIGENDIAN */ +// Nothing to do... +static inline uint32_t htonl(uint32_t x){ return x; } +static inline uint16_t htons(uint16_t x){ return x; } +static inline uint32_t ntohl(uint32_t x){ return x; } +static inline uint16_t ntohs(uint16_t x){ return x; } +#else +#if @GR_HAVE_BYTESWAP@ /* GR_HAVE_BYTESWAP */ +#include +#else +#warning Using non-portable code (likely wrong other than ILP32). + +static inline unsigned short int +bswap_16 (unsigned short int x) +{ + return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); +} + +static inline unsigned int +bswap_32 (unsigned int x) +{ + return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ + | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); +} +#endif /* GR_HAVE_BYTESWAP */ + +static inline uint32_t htonl(uint32_t x){ return bswap_32(x); } +static inline uint16_t htons(uint16_t x){ return bswap_16(x); } +static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); } +static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); } +#endif /* GR_ARCH_BIGENDIAN */ + +static inline uint8_t ntohx(uint8_t x){ return x; } +static inline uint16_t ntohx(uint16_t x){ return ntohs(x); } +static inline uint32_t ntohx(uint32_t x){ return ntohl(x); } +static inline uint8_t htonx(uint8_t x){ return x; } +static inline uint16_t htonx(uint16_t x){ return htons(x); } +static inline uint32_t htonx(uint32_t x){ return htonl(x); } + +#endif /* INCLUDED_INET_H */ -- cgit From c1ff40ad50fd29ff64c8c3991d7b5f69b43c661d Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 23 Jun 2008 00:25:56 +0000 Subject: Use system byteswap implementations where available. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8658 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/include/gruel/inet.h.in | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in index dd0525708..a98d83e9c 100644 --- a/gruel/src/include/gruel/inet.h.in +++ b/gruel/src/include/gruel/inet.h.in @@ -19,6 +19,11 @@ #ifndef INCLUDED_INET_H #define INCLUDED_INET_H +#if @GR_HAVE_ARPA_INET@ /* GR_HAVE_ARPA_INET */ +#include +#elif @GR_HAVE_NETINET_IN@ /* GR_HAVE_NETINET_IN */ +#include +#else #include #if @GR_ARCH_BIGENDIAN@ /* GR_ARCH_BIGENDIAN */ @@ -31,19 +36,17 @@ static inline uint16_t ntohs(uint16_t x){ return x; } #if @GR_HAVE_BYTESWAP@ /* GR_HAVE_BYTESWAP */ #include #else -#warning Using non-portable code (likely wrong other than ILP32). - -static inline unsigned short int -bswap_16 (unsigned short int x) +static inline uint16_t +bswap_16 (uint16_t x) { return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); } -static inline unsigned int -bswap_32 (unsigned int x) +static inline uint32_t +bswap_32 (uint32_t x) { - return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ - | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); + return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ + | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); } #endif /* GR_HAVE_BYTESWAP */ @@ -53,6 +56,8 @@ static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); } static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); } #endif /* GR_ARCH_BIGENDIAN */ +#endif /* !(GR_HAVE_NETINET_IN || GR_HAVE_ARPA_INET) */ + static inline uint8_t ntohx(uint8_t x){ return x; } static inline uint16_t ntohx(uint16_t x){ return ntohs(x); } static inline uint32_t ntohx(uint32_t x){ return ntohl(x); } -- cgit From 2c8ea58e4d76f54c98d71d3fcc64bc29da490908 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 19 Aug 2008 23:09:56 +0000 Subject: Merged features/mp-sched -r8915:9335 into the trunk. The trunk now contains the SMP aware scheduler. This changeset introduces a dependency on boost 1.35 or later. See source:gnuradio/trunk/README.building-boost for additional info. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9336 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/include/gruel/Makefile.am | 4 +- gruel/src/include/gruel/thread_body_wrapper.h | 68 ++++++++++++++++++ gruel/src/include/gruel/thread_group.h | 44 ++++++++++++ gruel/src/lib/Makefile.am | 14 ++-- gruel/src/lib/thread_body_wrapper.cc | 85 +++++++++++++++++++++++ gruel/src/lib/thread_group.cc | 99 +++++++++++++++++++++++++++ 6 files changed, 307 insertions(+), 7 deletions(-) create mode 100644 gruel/src/include/gruel/thread_body_wrapper.h create mode 100644 gruel/src/include/gruel/thread_group.h create mode 100644 gruel/src/lib/thread_body_wrapper.cc create mode 100644 gruel/src/lib/thread_group.cc (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index e5970cc49..50fad2531 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -28,4 +28,6 @@ gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ $(BUILT_SOURCES) \ - realtime.h + realtime.h \ + thread_body_wrapper.h \ + thread_group.h diff --git a/gruel/src/include/gruel/thread_body_wrapper.h b/gruel/src/include/gruel/thread_body_wrapper.h new file mode 100644 index 000000000..27dbbf7bb --- /dev/null +++ b/gruel/src/include/gruel/thread_body_wrapper.h @@ -0,0 +1,68 @@ +/* -*- c++ -*- */ +/* + * Copyright 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_THREAD_BODY_WRAPPER_H +#define INCLUDED_THREAD_BODY_WRAPPER_H + +#include +#include +#include + +namespace gruel +{ + + void mask_signals(); + + template + class thread_body_wrapper + { + F d_f; + std::string d_name; + + public: + + explicit thread_body_wrapper(F f, const std::string &name="") + : d_f(f), d_name(name) {} + + void operator()() + { + mask_signals(); + + try { + d_f(); + } + catch(boost::thread_interrupted const &) + { + } + catch(std::exception const &e) + { + std::cerr << "thread[" << d_name << "]: " + << e.what() << std::endl; + } + catch(...) + { + std::cerr << "thread[" << d_name << "]: " + << "caught unrecognized exception\n"; + } + } + }; +} + +#endif /* INCLUDED_THREAD_BODY_WRAPPER_H */ diff --git a/gruel/src/include/gruel/thread_group.h b/gruel/src/include/gruel/thread_group.h new file mode 100644 index 000000000..ae9a4250b --- /dev/null +++ b/gruel/src/include/gruel/thread_group.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright (C) 2001-2003 William E. Kempf + * Copyright (C) 2007 Anthony Williams + * Copyright 2008 Free Software Foundation, Inc. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +/* + * This was extracted from Boost 1.35.0 and fixed. + */ + +#ifndef INCLUDED_GRUEL_THREAD_GROUP_H +#define INCLUDED_GRUEL_THREAD_GROUP_H + +#include +#include +#include +#include + +namespace gruel +{ + class thread_group : public boost::noncopyable + { + public: + thread_group(); + ~thread_group(); + + boost::thread* create_thread(const boost::function0& threadfunc); + void add_thread(boost::thread* thrd); + void remove_thread(boost::thread* thrd); + void join_all(); + void interrupt_all(); + size_t size() const; + + private: + std::list m_threads; + mutable boost::shared_mutex m_mutex; + }; +} + +#endif /* INCLUDED_GRUEL_THREAD_GROUP_H */ diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index 972ff4ca9..7181c9418 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -21,19 +21,21 @@ include $(top_srcdir)/Makefile.common -AM_CPPFLAGS = $(DEFINES) $(BOOST_CFLAGS) $(GRUEL_INCLUDES) $(WITH_INCLUDES) +AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(GRUEL_INCLUDES) $(WITH_INCLUDES) lib_LTLIBRARIES = libgruel.la +# magic flags +libgruel_la_LDFLAGS = $(NO_UNDEFINED) $(BOOST_LDFLAGS) -version-info 0:0:0 + # These are the source files that go into the gruel shared library libgruel_la_SOURCES = \ - realtime.cc - -# magic flags -libgruel_la_LDFLAGS = $(NO_UNDEFINED) + realtime.cc \ + thread_body_wrapper.cc \ + thread_group.cc -# link the library against the c++ standard library libgruel_la_LIBADD = \ + $(BOOST_THREAD_LIB) -lstdc++ noinst_HEADERS = diff --git a/gruel/src/lib/thread_body_wrapper.cc b/gruel/src/lib/thread_body_wrapper.cc new file mode 100644 index 000000000..86c4edb5b --- /dev/null +++ b/gruel/src/lib/thread_body_wrapper.cc @@ -0,0 +1,85 @@ +/* -*- c++ -*- */ +/* + * Copyright 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 +#endif +#include +#ifdef HAVE_SIGNAL_H +#include +#endif +#include + +namespace gruel { + +#if defined(HAVE_PTHREAD_SIGMASK) && defined(HAVE_SIGNAL_H) + + void mask_signals() + { + sigset_t new_set; + int r; + + sigemptyset(&new_set); + sigaddset(&new_set, SIGHUP); // block these... + sigaddset(&new_set, SIGINT); + sigaddset(&new_set, SIGPIPE); + sigaddset(&new_set, SIGALRM); + sigaddset(&new_set, SIGTERM); + sigaddset(&new_set, SIGUSR1); + sigaddset(&new_set, SIGCHLD); +#ifdef SIGPOLL + sigaddset(&new_set, SIGPOLL); +#endif +#ifdef SIGPROF + sigaddset(&new_set, SIGPROF); +#endif +#ifdef SIGSYS + sigaddset(&new_set, SIGSYS); +#endif +#ifdef SIGTRAP + sigaddset(&new_set, SIGTRAP); +#endif +#ifdef SIGURG + sigaddset(&new_set, SIGURG); +#endif +#ifdef SIGVTALRM + sigaddset(&new_set, SIGVTALRM); +#endif +#ifdef SIGXCPU + sigaddset(&new_set, SIGXCPU); +#endif +#ifdef SIGXFSZ + sigaddset(&new_set, SIGXFSZ); +#endif + r = pthread_sigmask(SIG_BLOCK, &new_set, 0); + if (r != 0) + perror("pthread_sigmask"); + } + +#else + + void mask_signals() + { + } + +#endif + +}; diff --git a/gruel/src/lib/thread_group.cc b/gruel/src/lib/thread_group.cc new file mode 100644 index 000000000..fa78567ec --- /dev/null +++ b/gruel/src/lib/thread_group.cc @@ -0,0 +1,99 @@ +/* -*- c++ -*- */ +/* + * Copyright (C) 2001-2003 William E. Kempf + * Copyright (C) 2007 Anthony Williams + * Copyright 2008 Free Software Foundation, Inc. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +/* + * This was extracted from Boost 1.35.0 and fixed. + */ + +#include + +namespace gruel +{ + thread_group::thread_group() + { + } + + thread_group::~thread_group() + { + // We shouldn't have to scoped_lock here, since referencing this object + // from another thread while we're deleting it in the current thread is + // going to lead to undefined behavior any way. + for (std::list::iterator it = m_threads.begin(); + it != m_threads.end(); ++it) + { + delete (*it); + } + } + + boost::thread* thread_group::create_thread(const boost::function0& threadfunc) + { + // No scoped_lock required here since the only "shared data" that's + // modified here occurs inside add_thread which does scoped_lock. + std::auto_ptr thrd(new boost::thread(threadfunc)); + add_thread(thrd.get()); + return thrd.release(); + } + + void thread_group::add_thread(boost::thread* thrd) + { + boost::lock_guard guard(m_mutex); + + // For now we'll simply ignore requests to add a thread object multiple + // times. Should we consider this an error and either throw or return an + // error value? + std::list::iterator it = std::find(m_threads.begin(), + m_threads.end(), thrd); + BOOST_ASSERT(it == m_threads.end()); + if (it == m_threads.end()) + m_threads.push_back(thrd); + } + + void thread_group::remove_thread(boost::thread* thrd) + { + boost::lock_guard guard(m_mutex); + + // For now we'll simply ignore requests to remove a thread object that's + // not in the group. Should we consider this an error and either throw or + // return an error value? + std::list::iterator it = std::find(m_threads.begin(), + m_threads.end(), thrd); + BOOST_ASSERT(it != m_threads.end()); + if (it != m_threads.end()) + m_threads.erase(it); + } + + void thread_group::join_all() + { + boost::shared_lock guard(m_mutex); + for (std::list::iterator it = m_threads.begin(); + it != m_threads.end(); ++it) + { + (*it)->join(); + } + } + + void thread_group::interrupt_all() + { + boost::shared_lock guard(m_mutex); + for(std::list::iterator it=m_threads.begin(),end=m_threads.end(); + it!=end; + ++it) + { + (*it)->interrupt(); + } + } + + size_t thread_group::size() const + { + boost::shared_lock guard(m_mutex); + return m_threads.size(); + } + +} // namespace gruel -- cgit From 8885c15d42ac21113c2bae0e9fc05b3194d75d68 Mon Sep 17 00:00:00 2001 From: eb Date: Fri, 19 Sep 2008 00:42:37 +0000 Subject: conditional debugging code git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9605 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/lib/realtime.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc index bdcb31ab6..b84117fb2 100644 --- a/gruel/src/lib/realtime.cc +++ b/gruel/src/lib/realtime.cc @@ -45,6 +45,13 @@ namespace gruel { int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2; int pid = 0; // this process + if (0){ + fprintf(stderr, "sched_setscheduler version\n"); + fprintf(stderr, "pri_min(SCHED_FIFO) = %d\n", sched_get_priority_min(SCHED_FIFO)); + fprintf(stderr, "pri_max(SCHED_FIFO) = %d\n", sched_get_priority_max(SCHED_FIFO)); + fprintf(stderr, "pri = %d\n", pri); + } + struct sched_param param; memset(¶m, 0, sizeof(param)); param.sched_priority = pri; @@ -75,8 +82,15 @@ namespace gruel { enable_realtime_scheduling() { int policy = SCHED_FIFO; - int pri = (sched_get_priority_max (policy) + - sched_get_priority_min (policy)) / 2; + int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2; + + if (0){ + fprintf(stderr, "pthread_setschedparam version\n"); + fprintf(stderr, "pri_min(SCHED_FIFO) = %d\n", sched_get_priority_min(SCHED_FIFO)); + fprintf(stderr, "pri_max(SCHED_FIFO) = %d\n", sched_get_priority_max(SCHED_FIFO)); + fprintf(stderr, "pri = %d\n", pri); + } + pthread_t this_thread = pthread_self (); // this process struct sched_param param; memset (¶m, 0, sizeof (param)); -- cgit From 8e1575e9bc9ab9b78ae1620c15b8bf7a9ce8c25f Mon Sep 17 00:00:00 2001 From: eb Date: Fri, 19 Sep 2008 21:47:55 +0000 Subject: extend gruel:enable_realtime_scheduling interface to allow pri/policy git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9607 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/include/gruel/Makefile.am | 1 + gruel/src/include/gruel/realtime.h | 60 +++++++++++++++++++++--- gruel/src/include/gruel/sys_pri.h | 41 ++++++++++++++++ gruel/src/lib/Makefile.am | 2 +- gruel/src/lib/realtime.cc | 93 +++++++++++++++++++++---------------- gruel/src/lib/sys_pri.cc | 61 ++++++++++++++++++++++++ 6 files changed, 211 insertions(+), 47 deletions(-) create mode 100644 gruel/src/include/gruel/sys_pri.h create mode 100644 gruel/src/lib/sys_pri.cc (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 50fad2531..648d53e20 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -29,5 +29,6 @@ gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ $(BUILT_SOURCES) \ realtime.h \ + sys_pri.h \ thread_body_wrapper.h \ thread_group.h diff --git a/gruel/src/include/gruel/realtime.h b/gruel/src/include/gruel/realtime.h index ded70ed0d..8beec26d6 100644 --- a/gruel/src/include/gruel/realtime.h +++ b/gruel/src/include/gruel/realtime.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,8 +20,16 @@ * Boston, MA 02110-1301, USA. */ -#ifndef INCLUDED_REALTIME_H -#define INCLUDED_REALTIME_H +#ifndef INCLUDED_GRUEL_REALTIME_H +#define INCLUDED_GRUEL_REALTIME_H + +#include + +/*! + * \brief System independent way to ask for realtime scheduling + * + * \sa sys_pri.h + */ namespace gruel { @@ -32,13 +40,53 @@ namespace gruel { RT_OTHER_ERROR } rt_status_t; + + enum rt_sched_policy { + RT_SCHED_RR = 0, // round robin + RT_SCHED_FIFO = 1, // first in first out + }; + + /* + * Define the range for our virtual priorities (don't change these) + * + * Processes (or threads) with numerically higher priority values + * are scheduled before processes with numerically lower priority + * values. Thus, the value returned by rt_priority_max() will be + * greater than the value returned by rt_priority_min(). + */ + static inline int rt_priority_min() { return 0; } + static inline int rt_priority_max() { return 15; } + static inline int rt_priority_default() { return 1; } + + struct rt_sched_param { + int priority; + rt_sched_policy policy; + + rt_sched_param() + : priority(rt_priority_default()), policy(RT_SCHED_RR){} + + rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR) + { + if (priority_ < rt_priority_min() || priority_ > rt_priority_max()) + throw std::invalid_argument("rt_sched_param: priority out of range"); + + priority = priority_; + policy = policy_; + } + }; + /*! - * \brief If possible, enable high-priority "real time" scheduling. + * \brief If possible, enable "realtime" scheduling. * \ingroup misc + * + * In general, this means that the code will be scheduled before any + * non-realtime (normal) processes. Note that if your code contains + * an non-blocking infinite loop and you enable realtime scheduling, + * it's possible to hang the system. */ rt_status_t - enable_realtime_scheduling(); + enable_realtime_scheduling(rt_sched_param = rt_sched_param()); } // namespace gruel -#endif /* INCLUDED_GR_REALTIME_H */ +#endif /* INCLUDED_GRUEL_REALTIME_H */ diff --git a/gruel/src/include/gruel/sys_pri.h b/gruel/src/include/gruel/sys_pri.h new file mode 100644 index 000000000..b0fd83654 --- /dev/null +++ b/gruel/src/include/gruel/sys_pri.h @@ -0,0 +1,41 @@ +/* -*- c++ -*- */ +/* + * Copyright 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_GRUEL_SYS_PRI_H +#define INCLUDED_GRUEL_SYS_PRI_H + +#include + +/* + * A single place to define real-time priorities used by the system itself + */ +namespace gruel { + + struct sys_pri { + static rt_sched_param python(); // python code + static rt_sched_param normal(); // normal blocks + static rt_sched_param gcell_event_handler(); + static rt_sched_param usrp2_backend(); // thread that services the ethernet + }; + +} + +#endif /* INCLUDED_GRUEL_SYS_PRI_H */ diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index 7181c9418..c2a008e48 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -31,11 +31,11 @@ libgruel_la_LDFLAGS = $(NO_UNDEFINED) $(BOOST_LDFLAGS) -version-info 0:0:0 # These are the source files that go into the gruel shared library libgruel_la_SOURCES = \ realtime.cc \ + sys_pri.cc \ thread_body_wrapper.cc \ thread_group.cc libgruel_la_LIBADD = \ $(BOOST_THREAD_LIB) - -lstdc++ noinst_HEADERS = diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc index b84117fb2..1de8b6dc0 100644 --- a/gruel/src/lib/realtime.cc +++ b/gruel/src/lib/realtime.cc @@ -30,94 +30,107 @@ #include #endif +#include +#include #include #include #include -#if defined(HAVE_SCHED_SETSCHEDULER) +#if defined(HAVE_PTHREAD_SETSCHEDPARAM) || defined(HAVE_SCHED_SETSCHEDULER) +#include namespace gruel { - rt_status_t - enable_realtime_scheduling() + /*! + * Rescale our virtual priority so that it maps to the middle 1/2 of + * the priorities given by min_real_pri and max_real_pri. + */ + static int + rescale_virtual_pri(int virtual_pri, int min_real_pri, int max_real_pri) { - int policy = SCHED_FIFO; - int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2; - int pid = 0; // this process + float rmin = min_real_pri + (0.25 * (max_real_pri - min_real_pri)); + float rmax = min_real_pri + (0.75 * (max_real_pri - min_real_pri)); + float m = (rmax - rmin) / (rt_priority_max() - rt_priority_min()); + float y = m * (virtual_pri - rt_priority_min()) + rmin; + int y_int = static_cast(rint(y)); + return std::max(min_real_pri, std::min(max_real_pri, y_int)); + } - if (0){ - fprintf(stderr, "sched_setscheduler version\n"); - fprintf(stderr, "pri_min(SCHED_FIFO) = %d\n", sched_get_priority_min(SCHED_FIFO)); - fprintf(stderr, "pri_max(SCHED_FIFO) = %d\n", sched_get_priority_max(SCHED_FIFO)); - fprintf(stderr, "pri = %d\n", pri); - } +} // namespace gruel + +#endif + + +#if defined(HAVE_PTHREAD_SETSCHEDPARAM) + +namespace gruel { + rt_status_t + enable_realtime_scheduling(rt_sched_param p) + { + int policy = p.policy == RT_SCHED_FIFO ? SCHED_FIFO : SCHED_RR; + int min_real_pri = sched_get_priority_min(policy); + int max_real_pri = sched_get_priority_min(policy); + int pri = rescale_virtual_pri(p.priority, min_real_pri, max_real_pri); + + pthread_t this_thread = pthread_self (); // this process struct sched_param param; - memset(¶m, 0, sizeof(param)); + memset (¶m, 0, sizeof (param)); param.sched_priority = pri; - int result = sched_setscheduler(pid, policy, ¶m); - if (result != 0){ + int result = pthread_setschedparam (this_thread, policy, ¶m); + if (result != 0) { if (errno == EPERM) return RT_NO_PRIVS; else { - perror ("sched_setscheduler: failed to set real time priority"); + perror ("pthread_setschedparam: failed to set real time priority"); return RT_OTHER_ERROR; } } - + //printf("SCHED_FIFO enabled with priority = %d\n", pri); return RT_OK; } - } // namespace gruel -#elif defined(HAVE_PTHREAD_SETSCHEDPARAM) -#include -#include +#elif defined(HAVE_SCHED_SETSCHEDULER) namespace gruel { rt_status_t - enable_realtime_scheduling() + enable_realtime_scheduling(rt_sched_param p) { - int policy = SCHED_FIFO; - int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2; - - if (0){ - fprintf(stderr, "pthread_setschedparam version\n"); - fprintf(stderr, "pri_min(SCHED_FIFO) = %d\n", sched_get_priority_min(SCHED_FIFO)); - fprintf(stderr, "pri_max(SCHED_FIFO) = %d\n", sched_get_priority_max(SCHED_FIFO)); - fprintf(stderr, "pri = %d\n", pri); - } + int policy = p.policy == RT_SCHED_FIFO ? SCHED_FIFO : SCHED_RR; + int min_real_pri = sched_get_priority_min(policy); + int max_real_pri = sched_get_priority_min(policy); + int pri = rescale_virtual_pri(p.priority, min_real_pri, max_real_pri); - pthread_t this_thread = pthread_self (); // this process + int pid = 0; // this process struct sched_param param; - memset (¶m, 0, sizeof (param)); + memset(¶m, 0, sizeof(param)); param.sched_priority = pri; - int result = pthread_setschedparam (this_thread, policy, ¶m); - if (result != 0) { + int result = sched_setscheduler(pid, policy, ¶m); + if (result != 0){ if (errno == EPERM) return RT_NO_PRIVS; else { - perror ("pthread_setschedparam: failed to set real time priority"); + perror ("sched_setscheduler: failed to set real time priority"); return RT_OTHER_ERROR; } } - + //printf("SCHED_FIFO enabled with priority = %d\n", pri); return RT_OK; } -} // namespace gruel -// #elif // could try negative niceness +} // namespace gruel #else namespace gruel { rt_status_t - enable_realtime_scheduling() + enable_realtime_scheduling(rt_sched_param p) { return RT_NOT_IMPLEMENTED; } diff --git a/gruel/src/lib/sys_pri.cc b/gruel/src/lib/sys_pri.cc new file mode 100644 index 000000000..dc0164d70 --- /dev/null +++ b/gruel/src/lib/sys_pri.cc @@ -0,0 +1,61 @@ +/* -*- c++ -*- */ +/* + * Copyright 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 +#endif +#include + +namespace gruel { + + /* + * These may need per-OS tweaking. + * + * Under linux virtual_pri -> system_pri + * 0 -> 0 + * 1 -> 5 + * 2 -> 10 + * 3 -> 15 + * 4 -> 20 // typically used by jack and pulse audio + * 5 -> 25 + * 6 -> 30 + * 7 -> 35 + * 8 -> 40 + * 9 -> 45 + * 10 -> 50 + * 11 -> 54 + * 12 -> 59 + * 13 -> 64 + * 14 -> 69 + * 15 -> 74 + */ + rt_sched_param + sys_pri::python() { return rt_sched_param(0, RT_SCHED_RR); } + + rt_sched_param + sys_pri::normal() { return rt_sched_param(2, RT_SCHED_RR); } + + rt_sched_param + sys_pri::gcell_event_handler(){ return rt_sched_param(5, RT_SCHED_FIFO); } + + rt_sched_param + sys_pri::usrp2_backend() { return rt_sched_param(6, RT_SCHED_FIFO); } +} -- cgit From 20f913ec2e71888a451250ba841c980638221c65 Mon Sep 17 00:00:00 2001 From: eb Date: Mon, 22 Sep 2008 21:53:29 +0000 Subject: fixed copy/paste problem and error handling git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9639 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/lib/realtime.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc index 1de8b6dc0..d1907b3c1 100644 --- a/gruel/src/lib/realtime.cc +++ b/gruel/src/lib/realtime.cc @@ -70,19 +70,20 @@ namespace gruel { { int policy = p.policy == RT_SCHED_FIFO ? SCHED_FIFO : SCHED_RR; int min_real_pri = sched_get_priority_min(policy); - int max_real_pri = sched_get_priority_min(policy); + int max_real_pri = sched_get_priority_max(policy); int pri = rescale_virtual_pri(p.priority, min_real_pri, max_real_pri); - pthread_t this_thread = pthread_self (); // this process struct sched_param param; memset (¶m, 0, sizeof (param)); param.sched_priority = pri; - int result = pthread_setschedparam (this_thread, policy, ¶m); + int result = pthread_setschedparam (pthread_self(), policy, ¶m); if (result != 0) { - if (errno == EPERM) + if (result == EPERM) // N.B., return value, not errno return RT_NO_PRIVS; else { - perror ("pthread_setschedparam: failed to set real time priority"); + fprintf(stderr, + "pthread_setschedparam: failed to set real time priority: %s\n", + strerror(result)); return RT_OTHER_ERROR; } } @@ -102,7 +103,7 @@ namespace gruel { { int policy = p.policy == RT_SCHED_FIFO ? SCHED_FIFO : SCHED_RR; int min_real_pri = sched_get_priority_min(policy); - int max_real_pri = sched_get_priority_min(policy); + int max_real_pri = sched_get_priority_max(policy); int pri = rescale_virtual_pri(p.priority, min_real_pri, max_real_pri); int pid = 0; // this process -- cgit From 801b22a99512ed3dfd2b92bfc597bfc3451ccbc9 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 23 Sep 2008 21:57:31 +0000 Subject: usrp2 work-in-progress git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9643 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/lib/realtime.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc index d1907b3c1..7397cf3d3 100644 --- a/gruel/src/lib/realtime.cc +++ b/gruel/src/lib/realtime.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2007 Free Software Foundation, Inc. + * Copyright 2006,2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -73,6 +73,9 @@ namespace gruel { int max_real_pri = sched_get_priority_max(policy); int pri = rescale_virtual_pri(p.priority, min_real_pri, max_real_pri); + // FIXME check hard and soft limits with getrlimit, and limit the value we ask for. + // fprintf(stderr, "pthread_setschedparam: policy = %d, pri = %d\n", policy, pri); + struct sched_param param; memset (¶m, 0, sizeof (param)); param.sched_priority = pri; @@ -106,6 +109,9 @@ namespace gruel { int max_real_pri = sched_get_priority_max(policy); int pri = rescale_virtual_pri(p.priority, min_real_pri, max_real_pri); + // FIXME check hard and soft limits with getrlimit, and limit the value we ask for. + // fprintf(stderr, "sched_setscheduler: policy = %d, pri = %d\n", policy, pri); + int pid = 0; // this process struct sched_param param; memset(¶m, 0, sizeof(param)); -- cgit From 9c396d3353075919ae76b6f146ed6485b56880c6 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 3 Nov 2008 20:35:04 +0000 Subject: Fix issue caused by pkg-config stripping -I/usr/include from --cflags git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9920 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/include/gruel/realtime.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/realtime.h b/gruel/src/include/gruel/realtime.h index 8beec26d6..d110ec956 100644 --- a/gruel/src/include/gruel/realtime.h +++ b/gruel/src/include/gruel/realtime.h @@ -84,6 +84,9 @@ namespace gruel { * an non-blocking infinite loop and you enable realtime scheduling, * it's possible to hang the system. */ + + // NOTE: If you change this, you need to change the code in + // gnuradio-core/src/lib/runtime/gr_realtime.i, see note there. rt_status_t enable_realtime_scheduling(rt_sched_param = rt_sched_param()); -- cgit From 85b76dd55f422cf70238c58f2e39c2c28555f6ce Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 27 Jan 2009 18:00:05 +0000 Subject: General housekeeping--removing ancient cruft mostly. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10315 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/AUTHORS | 1 - gruel/ChangeLog | 20 -------------------- 2 files changed, 21 deletions(-) delete mode 100644 gruel/AUTHORS delete mode 100644 gruel/ChangeLog (limited to 'gruel') diff --git a/gruel/AUTHORS b/gruel/AUTHORS deleted file mode 100644 index 18e03c4a9..000000000 --- a/gruel/AUTHORS +++ /dev/null @@ -1 +0,0 @@ -Johnathan Corgan diff --git a/gruel/ChangeLog b/gruel/ChangeLog deleted file mode 100644 index b185665ee..000000000 --- a/gruel/ChangeLog +++ /dev/null @@ -1,20 +0,0 @@ -# -# Copyright 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., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# -- cgit From 6f50256f958ac60d5fc9212b24d86777c1b2ec0d Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 20 Jul 2009 03:47:14 +0000 Subject: Merged r11452:11459 from jcorgan/pmt-gruel into trunk. Trunk passes distcheck. * Merges libpmt into libgruel * Modifies libmblock to use libgruel gruel::pmt_t will be the fundamental msg content for the new message passing implemention for 3.3. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11460 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/Makefile.am | 3 +- gruel/src/include/gruel/Makefile.am | 5 +- gruel/src/include/gruel/pmt.h | 682 ++++++++++++++++ gruel/src/include/gruel/pmt_pool.h | 72 ++ gruel/src/lib/Makefile.am | 97 ++- gruel/src/lib/generate_unv.py | 190 +++++ gruel/src/lib/pmt.cc | 1041 +++++++++++++++++++++++++ gruel/src/lib/pmt_int.h | 227 ++++++ gruel/src/lib/pmt_io.cc | 141 ++++ gruel/src/lib/pmt_pool.cc | 112 +++ gruel/src/lib/pmt_serialize.cc | 357 +++++++++ gruel/src/lib/qa_pmt.cc | 40 + gruel/src/lib/qa_pmt.h | 36 + gruel/src/lib/qa_pmt_prims.cc | 438 +++++++++++ gruel/src/lib/qa_pmt_prims.h | 67 ++ gruel/src/lib/test_pmt.cc | 37 + gruel/src/lib/unv_qa_template.cc.t | 35 + gruel/src/lib/unv_template.cc.t | 122 +++ gruel/src/lib/unv_template.h.t | 23 + gruel/src/scheme/Makefile.am | 21 + gruel/src/scheme/gnuradio/Makefile.am | 31 + gruel/src/scheme/gnuradio/gen-serial-tags.scm | 118 +++ gruel/src/scheme/gnuradio/macros-etc.scm | 50 ++ gruel/src/scheme/gnuradio/pmt-serial-tags.scm | 75 ++ gruel/src/scheme/gnuradio/pmt-serialize.scm | 48 ++ 25 files changed, 4057 insertions(+), 11 deletions(-) create mode 100644 gruel/src/include/gruel/pmt.h create mode 100644 gruel/src/include/gruel/pmt_pool.h create mode 100755 gruel/src/lib/generate_unv.py create mode 100644 gruel/src/lib/pmt.cc create mode 100644 gruel/src/lib/pmt_int.h create mode 100644 gruel/src/lib/pmt_io.cc create mode 100644 gruel/src/lib/pmt_pool.cc create mode 100644 gruel/src/lib/pmt_serialize.cc create mode 100644 gruel/src/lib/qa_pmt.cc create mode 100644 gruel/src/lib/qa_pmt.h create mode 100644 gruel/src/lib/qa_pmt_prims.cc create mode 100644 gruel/src/lib/qa_pmt_prims.h create mode 100644 gruel/src/lib/test_pmt.cc create mode 100644 gruel/src/lib/unv_qa_template.cc.t create mode 100644 gruel/src/lib/unv_template.cc.t create mode 100644 gruel/src/lib/unv_template.h.t create mode 100644 gruel/src/scheme/Makefile.am create mode 100644 gruel/src/scheme/gnuradio/Makefile.am create mode 100755 gruel/src/scheme/gnuradio/gen-serial-tags.scm create mode 100644 gruel/src/scheme/gnuradio/macros-etc.scm create mode 100644 gruel/src/scheme/gnuradio/pmt-serial-tags.scm create mode 100644 gruel/src/scheme/gnuradio/pmt-serialize.scm (limited to 'gruel') diff --git a/gruel/src/Makefile.am b/gruel/src/Makefile.am index 90c0f88bd..71bdd8573 100644 --- a/gruel/src/Makefile.am +++ b/gruel/src/Makefile.am @@ -19,4 +19,5 @@ # Boston, MA 02110-1301, USA. # -SUBDIRS = include lib +SUBDIRS = lib include scheme + diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 648d53e20..d7354b871 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008,2009 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -28,6 +28,9 @@ gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ $(BUILT_SOURCES) \ + pmt.h \ + pmt_pool.h \ + pmt_serial_tags.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 new file mode 100644 index 000000000..6dc4508b1 --- /dev/null +++ b/gruel/src/include/gruel/pmt.h @@ -0,0 +1,682 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_PMT_H +#define INCLUDED_PMT_H + +#include +#include +#include +#include +#include +#include +#include + +/*! + * This file defines a polymorphic type and the operations on it. + * + * It draws heavily on the idea of scheme and lisp data types. + * The interface parallels that in Guile 1.8, with the notable + * exception that these objects are transparently reference counted. + */ + +namespace gruel { + +/*! + * \brief base class of all pmt types + */ +class pmt_base; + +/*! + * \brief typedef for shared pointer (transparent reference counting). + * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm + */ +typedef boost::shared_ptr pmt_t; + + +class pmt_exception : public std::logic_error +{ +public: + pmt_exception(const std::string &msg, pmt_t obj); +}; + +class pmt_wrong_type : public pmt_exception +{ +public: + pmt_wrong_type(const std::string &msg, pmt_t obj); +}; + +class pmt_out_of_range : public pmt_exception +{ +public: + pmt_out_of_range(const std::string &msg, pmt_t obj); +}; + +class pmt_notimplemented : public pmt_exception +{ +public: + pmt_notimplemented(const std::string &msg, pmt_t obj); +}; + +/* + * ------------------------------------------------------------------------ + * Booleans. Two constants, #t and #f. + * + * In predicates, anything that is not #f is considered true. + * I.e., there is a single false value, #f. + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_T; //< \#t : boolean true constant +extern const pmt_t PMT_F; //< \#f : boolean false constant + +//! Return true if obj is \#t or \#f, else return false. +bool pmt_is_bool(pmt_t obj); + +//! Return false if obj is \#f, else return true. +bool pmt_is_true(pmt_t obj); + +//! Return true if obj is \#f, else return true. +bool pmt_is_false(pmt_t obj); + +//! Return \#f is val is false, else return \#t. +pmt_t pmt_from_bool(bool val); + +//! Return true if val is PMT_T, return false when val is PMT_F, +// else raise wrong_type exception. +bool pmt_to_bool(pmt_t val); + +/* + * ------------------------------------------------------------------------ + * Symbols + * ------------------------------------------------------------------------ + */ + +//! Return true if obj is a symbol, else false. +bool pmt_is_symbol(const pmt_t& obj); + +//! Return the symbol whose name is \p s. +pmt_t pmt_string_to_symbol(const std::string &s); + +//! Alias for pmt_string_to_symbol +pmt_t pmt_intern(const std::string &s); + + +/*! + * If \p is a symbol, return the name of the symbol as a string. + * Otherwise, raise the wrong_type exception. + */ +const std::string pmt_symbol_to_string(const pmt_t& sym); + +/* + * ------------------------------------------------------------------------ + * Numbers: we support integer, real and complex + * ------------------------------------------------------------------------ + */ + +//! Return true if obj is any kind of number, else false. +bool pmt_is_number(pmt_t obj); + +/* + * ------------------------------------------------------------------------ + * Integers + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is an integer number, else false +bool pmt_is_integer(pmt_t x); + +//! Return the pmt value that represents the integer \p x. +pmt_t pmt_from_long(long x); + +/*! + * \brief Convert pmt to long if possible. + * + * When \p x represents an exact integer that fits in a long, + * return that integer. Else raise an exception, either wrong_type + * when x is not an exact integer, or out_of_range when it doesn't fit. + */ +long pmt_to_long(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * Reals + * ------------------------------------------------------------------------ + */ + +/* + * \brief Return true if \p obj is a real number, else false. + */ +bool pmt_is_real(pmt_t obj); + +//! Return the pmt value that represents double \p x. +pmt_t pmt_from_double(double x); + +/*! + * \brief Convert pmt to double if possible. + * + * Returns the number closest to \p val that is representable + * as a double. The argument \p val must be a real or integer, otherwise + * a wrong_type exception is raised. + */ +double pmt_to_double(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * Complex + * ------------------------------------------------------------------------ + */ + +/*! + * \brief return true if \p obj is a complex number, false otherwise. + */ +bool pmt_is_complex(pmt_t obj); + +//! Return a complex number constructed of the given real and imaginary parts. +pmt_t pmt_make_rectangular(double re, double im); + +/*! + * If \p z is complex, real or integer, return the closest complex. + * Otherwise, raise the wrong_type exception. + */ +std::complex pmt_to_complex(pmt_t z); + +/* + * ------------------------------------------------------------------------ + * Pairs + * ------------------------------------------------------------------------ + */ + +extern const pmt_t PMT_NIL; //< the empty list + +//! Return true if \p x is the empty list, otherwise return false. +bool pmt_is_null(const pmt_t& x); + +//! Return true if \p obj is a pair, else false. +bool pmt_is_pair(const pmt_t& obj); + +//! Return a newly allocated pair whose car is \p x and whose cdr is \p y. +pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); + +//! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. +pmt_t pmt_car(const pmt_t& pair); + +//! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. +pmt_t pmt_cdr(const pmt_t& pair); + +//! Stores \p value in the car field of \p pair. +void pmt_set_car(pmt_t pair, pmt_t value); + +//! Stores \p value in the cdr field of \p pair. +void pmt_set_cdr(pmt_t pair, pmt_t value); + +pmt_t pmt_caar(pmt_t pair); +pmt_t pmt_cadr(pmt_t pair); +pmt_t pmt_cdar(pmt_t pair); +pmt_t pmt_cddr(pmt_t pair); +pmt_t pmt_caddr(pmt_t pair); +pmt_t pmt_cadddr(pmt_t pair); + +/* + * ------------------------------------------------------------------------ + * Vectors + * + * These vectors can hold any kind of objects. Indexing is zero based. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a vector, othewise false. +bool pmt_is_vector(pmt_t x); + +//! Make a vector of length \p k, with initial values set to \p fill +pmt_t pmt_make_vector(size_t k, pmt_t fill); + +/*! + * Return the contents of position \p k of \p vector. + * \p k must be a valid index of \p vector. + */ +pmt_t pmt_vector_ref(pmt_t vector, size_t k); + +//! Store \p obj in position \p k. +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); + +/*! + *
+ * ------------------------------------------------------------------------
+ *		       Uniform Numeric Vectors
+ *
+ * A uniform numeric vector is a vector whose elements are all of single
+ * numeric type.  pmt offers uniform numeric vectors for signed and
+ * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
+ * floating point values, and complex floating-point numbers of these
+ * two sizes.  Indexing is zero based.
+ *
+ * The names of the functions include these tags in their names:
+ *
+ *    u8  unsigned 8-bit integers
+ *    s8  signed 8-bit integers
+ *   u16  unsigned 16-bit integers
+ *   s16  signed 16-bit integers
+ *   u32  unsigned 32-bit integers
+ *   s32  signed 32-bit integers
+ *   u64  unsigned 64-bit integers
+ *   s64  signed 64-bit integers
+ *   f32  the C++ type float
+ *   f64  the C++ type double
+ *   c32  the C++ type complex
+ *   c64  the C++ type complex
+ * ------------------------------------------------------------------------
+ * 
+ */ + +//! true if \p x is any kind of uniform numeric vector +bool pmt_is_uniform_vector(pmt_t x); + +bool pmt_is_u8vector(pmt_t x); +bool pmt_is_s8vector(pmt_t x); +bool pmt_is_u16vector(pmt_t x); +bool pmt_is_s16vector(pmt_t x); +bool pmt_is_u32vector(pmt_t x); +bool pmt_is_s32vector(pmt_t x); +bool pmt_is_u64vector(pmt_t x); +bool pmt_is_s64vector(pmt_t x); +bool pmt_is_f32vector(pmt_t x); +bool pmt_is_f64vector(pmt_t x); +bool pmt_is_c32vector(pmt_t x); +bool pmt_is_c64vector(pmt_t x); + +pmt_t pmt_make_u8vector(size_t k, uint8_t fill); +pmt_t pmt_make_s8vector(size_t k, int8_t fill); +pmt_t pmt_make_u16vector(size_t k, uint16_t fill); +pmt_t pmt_make_s16vector(size_t k, int16_t fill); +pmt_t pmt_make_u32vector(size_t k, uint32_t fill); +pmt_t pmt_make_s32vector(size_t k, int32_t fill); +pmt_t pmt_make_u64vector(size_t k, uint64_t fill); +pmt_t pmt_make_s64vector(size_t k, int64_t fill); +pmt_t pmt_make_f32vector(size_t k, float fill); +pmt_t pmt_make_f64vector(size_t k, double fill); +pmt_t pmt_make_c32vector(size_t k, std::complex fill); +pmt_t pmt_make_c64vector(size_t k, std::complex fill); + +pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); +pmt_t pmt_init_s8vector(size_t k, const int8_t *data); +pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); +pmt_t pmt_init_s16vector(size_t k, const int16_t *data); +pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); +pmt_t pmt_init_s32vector(size_t k, const int32_t *data); +pmt_t pmt_init_u64vector(size_t k, const uint64_t *data); +pmt_t pmt_init_s64vector(size_t k, const int64_t *data); +pmt_t pmt_init_f32vector(size_t k, const float *data); +pmt_t pmt_init_f64vector(size_t k, const double *data); +pmt_t pmt_init_c32vector(size_t k, const std::complex *data); +pmt_t pmt_init_c64vector(size_t k, const std::complex *data); + +uint8_t pmt_u8vector_ref(pmt_t v, size_t k); +int8_t pmt_s8vector_ref(pmt_t v, size_t k); +uint16_t pmt_u16vector_ref(pmt_t v, size_t k); +int16_t pmt_s16vector_ref(pmt_t v, size_t k); +uint32_t pmt_u32vector_ref(pmt_t v, size_t k); +int32_t pmt_s32vector_ref(pmt_t v, size_t k); +uint64_t pmt_u64vector_ref(pmt_t v, size_t k); +int64_t pmt_s64vector_ref(pmt_t v, size_t k); +float pmt_f32vector_ref(pmt_t v, size_t k); +double pmt_f64vector_ref(pmt_t v, size_t k); +std::complex pmt_c32vector_ref(pmt_t v, size_t k); +std::complex pmt_c64vector_ref(pmt_t v, size_t k); + +void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x); //< v[k] = x +void pmt_s8vector_set(pmt_t v, size_t k, int8_t x); +void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x); +void pmt_s16vector_set(pmt_t v, size_t k, int16_t x); +void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x); +void pmt_s32vector_set(pmt_t v, size_t k, int32_t x); +void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x); +void pmt_s64vector_set(pmt_t v, size_t k, int64_t x); +void pmt_f32vector_set(pmt_t v, size_t k, float x); +void pmt_f64vector_set(pmt_t v, size_t k, double x); +void pmt_c32vector_set(pmt_t v, size_t k, std::complex x); +void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); + +// Return const pointers to the elements + +const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements +const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements +const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements +const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements +const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements +const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements +const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements + +// Return non-const pointers to the elements + +void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements + +/* + * ------------------------------------------------------------------------ + * Dictionary (a.k.a associative array, hash, map) + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is a dictionary +bool pmt_is_dict(pmt_t obj); + +//! make an empty dictionary +pmt_t pmt_make_dict(); + +//! dict[key] = value +void pmt_dict_set(pmt_t dict, pmt_t key, pmt_t value); + +//! Return true if \p key exists in \p dict +bool pmt_dict_has_key(pmt_t dict, pmt_t key); + +//! If \p key exists in \p dict, return associated value; otherwise return \p not_found. +pmt_t pmt_dict_ref(pmt_t dict, pmt_t key, pmt_t not_found); + +//! Return list of (key . value) pairs +pmt_t pmt_dict_items(pmt_t dict); + +//! Return list of keys +pmt_t pmt_dict_keys(pmt_t dict); + +//! Return list of values +pmt_t pmt_dict_values(pmt_t dict); + +/* + * ------------------------------------------------------------------------ + * Any (wraps boost::any -- can be used to wrap pretty much anything) + * + * Cannot be serialized or used across process boundaries. + * See http://www.boost.org/doc/html/any.html + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is an any +bool pmt_is_any(pmt_t obj); + +//! make an any +pmt_t pmt_make_any(const boost::any &any); + +//! Return underlying boost::any +boost::any pmt_any_ref(pmt_t obj); + +//! Store \p any in \p obj +void pmt_any_set(pmt_t obj, const boost::any &any); + + +/* + * ------------------------------------------------------------------------ + * General functions + * ------------------------------------------------------------------------ + */ + +//! Return true if x and y are the same object; otherwise return false. +bool pmt_eq(const pmt_t& x, const pmt_t& y); + +/*! + * \brief Return true if x and y should normally be regarded as the same object, else false. + * + *
+ * eqv returns true if:
+ *   x and y are the same object.
+ *   x and y are both \#t or both \#f.
+ *   x and y are both symbols and their names are the same.
+ *   x and y are both numbers, and are numerically equal.
+ *   x and y are both the empty list (nil).
+ *   x and y are pairs or vectors that denote same location in store.
+ * 
+ */ +bool pmt_eqv(const pmt_t& x, const pmt_t& y); + +/*! + * pmt_equal recursively compares the contents of pairs and vectors, + * applying pmt_eqv on other objects such as numbers and symbols. + * pmt_equal may fail to terminate if its arguments are circular data + * structures. + */ +bool pmt_equal(const pmt_t& x, const pmt_t& y); + + +//! Return the number of elements in v +size_t pmt_length(const pmt_t& v); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assq(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assv(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assoc(pmt_t obj, pmt_t alist); + +/*! + * \brief Apply \p proc element-wise to the elements of list and returns + * a list of the results, in order. + * + * \p list must be a list. The dynamic order in which \p proc is + * applied to the elements of \p list is unspecified. + */ +pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); + +/*! + * \brief reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse(pmt_t list); + +/*! + * \brief destructively reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse_x(pmt_t list); + +/*! + * \brief (acons x y a) == (cons (cons x y) a) + */ +inline static pmt_t +pmt_acons(pmt_t x, pmt_t y, pmt_t a) +{ + return pmt_cons(pmt_cons(x, y), a); +} + +/*! + * \brief locates \p nth element of \n list where the car is the 'zeroth' element. + */ +pmt_t pmt_nth(size_t n, pmt_t list); + +/*! + * \brief returns the tail of \p list that would be obtained by calling + * cdr \p n times in succession. + */ +pmt_t pmt_nthcdr(size_t n, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memq(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memv(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_member use pmt_equal to compare \p obj with the elements of \p list. + */ +pmt_t pmt_member(pmt_t obj, pmt_t list); + +/*! + * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. + * Comparisons are done with pmt_eqv. + */ +bool pmt_subsetp(pmt_t list1, pmt_t list2); + +/*! + * \brief Return a list of length 1 containing \p x1 + */ +pmt_t pmt_list1(const pmt_t& x1); + +/*! + * \brief Return a list of length 2 containing \p x1, \p x2 + */ +pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); + +/*! + * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 + */ +pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); + +/*! + * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 + */ +pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); + +/*! + * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 + */ +pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); + +/*! + * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p + * x5, \p x6 + */ +pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); + +/*! + * \brief Return \p list with \p item added to it. + */ +pmt_t pmt_list_add(pmt_t list, const pmt_t& item); + + +/* + * ------------------------------------------------------------------------ + * read / write + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_EOF; //< The end of file object + +//! return true if obj is the EOF object, otherwise return false. +bool pmt_is_eof_object(pmt_t obj); + +/*! + * read converts external representations of pmt objects into the + * objects themselves. Read returns the next object parsable from + * the given input port, updating port to point to the first + * character past the end of the external representation of the + * object. + * + * If an end of file is encountered in the input before any + * characters are found that can begin an object, then an end of file + * object is returned. The port remains open, and further attempts + * to read will also return an end of file object. If an end of file + * is encountered after the beginning of an object's external + * representation, but the external representation is incomplete and + * therefore not parsable, an error is signaled. + */ +pmt_t pmt_read(std::istream &port); + +/*! + * Write a written representation of \p obj to the given \p port. + */ +void pmt_write(pmt_t obj, std::ostream &port); + +/*! + * Return a string representation of \p obj. + * This is the same output as would be generated by pmt_write. + */ +std::string pmt_write_string(pmt_t obj); + + +std::ostream& operator<<(std::ostream &os, pmt_t obj); + + +/* + * ------------------------------------------------------------------------ + * portable byte stream representation + * ------------------------------------------------------------------------ + */ +/*! + * \brief Write portable byte-serial representation of \p obj to \p sink + */ +bool pmt_serialize(pmt_t obj, std::streambuf &sink); + +/*! + * \brief Create obj from portable byte-serial representation + */ +pmt_t pmt_deserialize(std::streambuf &source); + + +void pmt_dump_sizeof(); // debugging + +} /* namespace gruel */ + +#endif /* INCLUDED_PMT_H */ diff --git a/gruel/src/include/gruel/pmt_pool.h b/gruel/src/include/gruel/pmt_pool.h new file mode 100644 index 000000000..18b498faa --- /dev/null +++ b/gruel/src/include/gruel/pmt_pool.h @@ -0,0 +1,72 @@ +/* -*- 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_PMT_POOL_H +#define INCLUDED_PMT_POOL_H + +#include +#include +#include + +namespace gruel { + +/*! + * \brief very simple thread-safe fixed-size allocation pool + * + * FIXME may want to go to global allocation with per-thread free list. + * This would eliminate virtually all lock contention. + */ +class pmt_pool { + + struct item { + struct item *d_next; + }; + + typedef boost::unique_lock scoped_lock; + mutable boost::mutex d_mutex; + boost::condition_variable d_cond; + + size_t d_itemsize; + size_t d_alignment; + size_t d_allocation_size; + size_t d_max_items; + size_t d_n_items; + item *d_freelist; + std::vector d_allocations; + +public: + /*! + * \param itemsize size in bytes of the items to be allocated. + * \param alignment alignment in bytes of all objects to be allocated (must be power-of-2). + * \param allocation_size number of bytes to allocate at a time from the underlying allocator. + * \param max_items is the maximum number of items to allocate. If this number is exceeded, + * the allocate blocks. 0 implies no limit. + */ + pmt_pool(size_t itemsize, size_t alignment = 16, + size_t allocation_size = 4096, size_t max_items = 0); + ~pmt_pool(); + + void *malloc(); + void free(void *p); +}; + +} /* namespace gruel */ + +#endif /* INCLUDED_PMT_POOL_H */ diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index c2a008e48..2a968d25f 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008,2009 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -21,21 +21,100 @@ include $(top_srcdir)/Makefile.common -AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(GRUEL_INCLUDES) $(WITH_INCLUDES) +AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) + +TESTS = test_pmt lib_LTLIBRARIES = libgruel.la # magic flags libgruel_la_LDFLAGS = $(NO_UNDEFINED) $(BOOST_LDFLAGS) -version-info 0:0:0 +# ---------------------------------------------------------------- +# these scripts generate code + +code_generator = \ + generate_unv.py \ + unv_template.h.t \ + unv_template.cc.t \ + unv_qa_template.cc.t + +GENERATED_H = \ + pmt_unv_int.h \ + qa_pmt_unv.h + +GENERATED_CC = \ + pmt_unv.cc \ + qa_pmt_unv.cc + +python_built_sources = $(GENERATED_H) $(GENERATED_CC) + +PMT_SERIAL_TAGS_H = $(abs_top_builddir)/gruel/src/include/gruel/pmt_serial_tags.h +BUILT_SOURCES = $(python_built_sources) $(PMT_SERIAL_TAGS_H) + +EXTRA_DIST = $(code_generator) + +# ---------------------------------------------------------------- + # These are the source files that go into the gruel shared library -libgruel_la_SOURCES = \ - realtime.cc \ - sys_pri.cc \ - thread_body_wrapper.cc \ +libgruel_la_SOURCES = \ + pmt.cc \ + pmt_io.cc \ + pmt_pool.cc \ + pmt_serialize.cc \ + pmt_unv.cc \ + realtime.cc \ + sys_pri.cc \ + thread_body_wrapper.cc \ thread_group.cc -libgruel_la_LIBADD = \ - $(BOOST_THREAD_LIB) +libgruel_la_LIBADD = \ + $(BOOST_THREAD_LIB) \ + -lstdc++ + +noinst_HEADERS = \ + $(GENERATED_H) \ + pmt_int.h \ + qa_pmt.h \ + qa_pmt_prims.h + +# Build the qa code into its own library + +noinst_LTLIBRARIES = libpmt-qa.la + +libpmt_qa_la_SOURCES = \ + qa_pmt.cc \ + qa_pmt_prims.cc \ + qa_pmt_unv.cc + +# magic flags +libpmt_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid version + +libpmt_qa_la_LIBADD = \ + libgruel.la \ + $(CPPUNIT_LIBS) \ + -lstdc++ + +noinst_PROGRAMS = \ + test_pmt + + +LIBGRUEL = libgruel.la +LIBPMTQA = libpmt-qa.la $(LIBGRUEL) + +test_pmt_SOURCES = test_pmt.cc +test_pmt_LDADD = $(LIBPMTQA) + +# Do creation and inclusion of other Makefiles last + +# common way for generating sources from templates when using +# BUILT_SOURCES, using parallel build protection. +gen_sources = $(python_built_sources) +gen_sources_deps = $(core_generator) +par_gen_command = PYTHONPATH=$(top_srcdir)/gruel/src/lib srcdir=$(srcdir) $(PYTHON) $(srcdir)/generate_unv.py +include $(top_srcdir)/Makefile.par.gen -noinst_HEADERS = +# Rule to create the build header file using GUILE +# Doesn't need parallel protections because there is a single target +$(PMT_SERIAL_TAGS_H): $(srcdir)/../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../scheme/gnuradio/pmt-serial-tags.scm + $(RUN_GUILE) $(srcdir)/../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../scheme/gnuradio/pmt-serial-tags.scm $(PMT_SERIAL_TAGS_H) diff --git a/gruel/src/lib/generate_unv.py b/gruel/src/lib/generate_unv.py new file mode 100755 index 000000000..3a7305b40 --- /dev/null +++ b/gruel/src/lib/generate_unv.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python +# +# 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. +# + +""" +Generate code for uniform numeric vectors +""" + +import re, os, os.path + + +unv_types = ( + ('u8', 'uint8_t'), + ('s8', 'int8_t'), + ('u16', 'uint16_t'), + ('s16', 'int16_t'), + ('u32', 'uint32_t'), + ('s32', 'int32_t'), + ('u64', 'uint64_t'), + ('s64', 'int64_t'), + ('f32', 'float'), + ('f64', 'double'), + ('c32', 'std::complex'), + ('c64', 'std::complex') + ) + +header = """\ +/* -*- 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. + */ +""" + +guard_tail = """ +#endif +""" + +includes = """ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include "pmt_int.h" +""" + +qa_includes = """ +#include +#include +#include +#include + +using namespace gruel; +""" + + +# set srcdir to the directory that contains Makefile.am +try: + srcdir = os.environ['srcdir'] +except KeyError, e: + srcdir = "." +srcdir = srcdir + '/' + + +def open_src (name, mode): + global srcdir + return open(os.path.join (srcdir, name), mode) + + +def guard_name(filename): + return 'INCLUDED_' + re.sub('\.', '_', filename.upper()) + +def guard_head(filename): + guard = guard_name(filename) + return """ +#ifndef %s +#define %s +""" % (guard, guard) + + +def do_substitution (d, input, out_file): + def repl (match_obj): + key = match_obj.group (1) + # print key + return d[key] + + out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, input) + out_file.write (out) + + +def generate_h(): + template = open_src('unv_template.h.t', 'r').read() + output_filename = 'pmt_unv_int.h' + output = open(output_filename, 'w') + output.write(header) + output.write(guard_head(output_filename)) + for tag, typ in unv_types: + d = { 'TAG' : tag, 'TYPE' : typ } + do_substitution(d, template, output) + output.write(guard_tail) + +def generate_cc(): + template = open_src('unv_template.cc.t', 'r').read() + output = open('pmt_unv.cc', 'w') + output.write(header) + output.write(includes) + for tag, typ in unv_types: + d = { 'TAG' : tag, 'TYPE' : typ } + do_substitution(d, template, output) + + +def generate_qa_h(): + output_filename = 'qa_pmt_unv.h' + output = open(output_filename, 'w') + output.write(header) + output.write(guard_head(output_filename)) + + output.write(''' +#include +#include + +class qa_pmt_unv : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE(qa_pmt_unv); +''') + for tag, typ in unv_types: + output.write(' CPPUNIT_TEST(test_%svector);\n' % (tag,)) + output.write('''\ + CPPUNIT_TEST_SUITE_END(); + + private: +''') + for tag, typ in unv_types: + output.write(' void test_%svector();\n' % (tag,)) + output.write('};\n') + output.write(guard_tail) + +def generate_qa_cc(): + template = open_src('unv_qa_template.cc.t', 'r').read() + output = open('qa_pmt_unv.cc', 'w') + output.write(header) + output.write(qa_includes) + for tag, typ in unv_types: + d = { 'TAG' : tag, 'TYPE' : typ } + do_substitution(d, template, output) + + +def main(): + generate_h() + generate_cc() + generate_qa_h() + generate_qa_cc() + +if __name__ == '__main__': + main() diff --git a/gruel/src/lib/pmt.cc b/gruel/src/lib/pmt.cc new file mode 100644 index 000000000..8e0c01625 --- /dev/null +++ b/gruel/src/lib/pmt.cc @@ -0,0 +1,1041 @@ +/* -*- 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. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include "pmt_int.h" +#include +#include +#include + +namespace gruel { + +static const int CACHE_LINE_SIZE = 64; // good guess + +# if (PMT_LOCAL_ALLOCATOR) + +static pmt_pool global_pmt_pool(sizeof(pmt_pair), CACHE_LINE_SIZE); + +void * +pmt_base::operator new(size_t size) +{ + void *p = global_pmt_pool.malloc(); + + // fprintf(stderr, "pmt_base::new p = %p\n", p); + assert((reinterpret_cast(p) & (CACHE_LINE_SIZE - 1)) == 0); + return p; +} + +void +pmt_base::operator delete(void *p, size_t size) +{ + global_pmt_pool.free(p); +} + +#endif + + +pmt_base::~pmt_base() +{ + // nop -- out of line virtual destructor +} + +//////////////////////////////////////////////////////////////////////////// +// Exceptions +//////////////////////////////////////////////////////////////////////////// + +pmt_exception::pmt_exception(const std::string &msg, pmt_t obj) + : logic_error(msg + ": " + pmt_write_string(obj)) +{ +} + +pmt_wrong_type::pmt_wrong_type(const std::string &msg, pmt_t obj) + : pmt_exception(msg + ": wrong_type ", obj) +{ +} + +pmt_out_of_range::pmt_out_of_range(const std::string &msg, pmt_t obj) + : pmt_exception(msg + ": out of range ", obj) +{ +} + +pmt_notimplemented::pmt_notimplemented(const std::string &msg, pmt_t obj) + : pmt_exception(msg + ": notimplemented ", obj) +{ +} + +//////////////////////////////////////////////////////////////////////////// +// Dynamic Casts +//////////////////////////////////////////////////////////////////////////// + +static pmt_symbol * +_symbol(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_integer * +_integer(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_real * +_real(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_complex * +_complex(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_pair * +_pair(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_vector * +_vector(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_uniform_vector * +_uniform_vector(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_dict * +_dict(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_any * +_any(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +//////////////////////////////////////////////////////////////////////////// +// Globals +//////////////////////////////////////////////////////////////////////////// + +const pmt_t PMT_T = pmt_t(new pmt_bool()); // singleton +const pmt_t PMT_F = pmt_t(new pmt_bool()); // singleton +const pmt_t PMT_NIL = pmt_t(new pmt_null()); // singleton +const pmt_t PMT_EOF = pmt_cons(PMT_NIL, PMT_NIL); // singleton + +//////////////////////////////////////////////////////////////////////////// +// Booleans +//////////////////////////////////////////////////////////////////////////// + +pmt_bool::pmt_bool(){} + +bool +pmt_is_true(pmt_t obj) +{ + return obj != PMT_F; +} + +bool +pmt_is_false(pmt_t obj) +{ + return obj == PMT_F; +} + +bool +pmt_is_bool(pmt_t obj) +{ + return obj->is_bool(); +} + +pmt_t +pmt_from_bool(bool val) +{ + return val ? PMT_T : PMT_F; +} + +bool +pmt_to_bool(pmt_t val) +{ + if (val == PMT_T) + return true; + if (val == PMT_F) + return false; + throw pmt_wrong_type("pmt_to_bool", val); +} + +//////////////////////////////////////////////////////////////////////////// +// Symbols +//////////////////////////////////////////////////////////////////////////// + +static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701; +static std::vector s_symbol_hash_table(SYMBOL_HASH_TABLE_SIZE); + +pmt_symbol::pmt_symbol(const std::string &name) : d_name(name){} + + +static unsigned int +hash_string(const std::string &s) +{ + unsigned int h = 0; + unsigned int g = 0; + + for (std::string::const_iterator p = s.begin(); p != s.end(); ++p){ + h = (h << 4) + (*p & 0xff); + g = h & 0xf0000000; + if (g){ + h = h ^ (g >> 24); + h = h ^ g; + } + } + return h; +} + +bool +pmt_is_symbol(const pmt_t& obj) +{ + return obj->is_symbol(); +} + +pmt_t +pmt_string_to_symbol(const std::string &name) +{ + unsigned hash = hash_string(name) % SYMBOL_HASH_TABLE_SIZE; + + // Does a symbol with this name already exist? + for (pmt_t sym = s_symbol_hash_table[hash]; sym; sym = _symbol(sym)->next()){ + if (name == _symbol(sym)->name()) + return sym; // Yes. Return it + } + + // Nope. Make a new one. + pmt_t sym = pmt_t(new pmt_symbol(name)); + _symbol(sym)->set_next(s_symbol_hash_table[hash]); + s_symbol_hash_table[hash] = sym; + return sym; +} + +// alias... +pmt_t +pmt_intern(const std::string &name) +{ + return pmt_string_to_symbol(name); +} + +const std::string +pmt_symbol_to_string(const pmt_t& sym) +{ + if (!sym->is_symbol()) + throw pmt_wrong_type("pmt_symbol_to_string", sym); + + return _symbol(sym)->name(); +} + + + +//////////////////////////////////////////////////////////////////////////// +// Number +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_is_number(pmt_t x) +{ + return x->is_number(); +} + +//////////////////////////////////////////////////////////////////////////// +// Integer +//////////////////////////////////////////////////////////////////////////// + +pmt_integer::pmt_integer(long value) : d_value(value) {} + +bool +pmt_is_integer(pmt_t x) +{ + return x->is_integer(); +} + + +pmt_t +pmt_from_long(long x) +{ + return pmt_t(new pmt_integer(x)); +} + +long +pmt_to_long(pmt_t x) +{ + pmt_integer* i = dynamic_cast(x.get()); + if ( i ) + return i->value(); + + throw pmt_wrong_type("pmt_to_long", x); +} + +//////////////////////////////////////////////////////////////////////////// +// Real +//////////////////////////////////////////////////////////////////////////// + +pmt_real::pmt_real(double value) : d_value(value) {} + +bool +pmt_is_real(pmt_t x) +{ + return x->is_real(); +} + +pmt_t +pmt_from_double(double x) +{ + return pmt_t(new pmt_real(x)); +} + +double +pmt_to_double(pmt_t x) +{ + if (x->is_real()) + return _real(x)->value(); + if (x->is_integer()) + return _integer(x)->value(); + + throw pmt_wrong_type("pmt_to_double", x); +} + +//////////////////////////////////////////////////////////////////////////// +// Complex +//////////////////////////////////////////////////////////////////////////// + +pmt_complex::pmt_complex(std::complex value) : d_value(value) {} + +bool +pmt_is_complex(pmt_t x) +{ + return x->is_complex(); +} + +pmt_t +pmt_make_rectangular(double re, double im) +{ + return pmt_t(new pmt_complex(std::complex(re, im))); +} + +std::complex +pmt_to_complex(pmt_t x) +{ + if (x->is_complex()) + return _complex(x)->value(); + if (x->is_real()) + return _real(x)->value(); + if (x->is_integer()) + return _integer(x)->value(); + + throw pmt_wrong_type("pmt_to_complex", x); +} + +//////////////////////////////////////////////////////////////////////////// +// Pairs +//////////////////////////////////////////////////////////////////////////// + +pmt_null::pmt_null() {} +pmt_pair::pmt_pair(const pmt_t& car, const pmt_t& cdr) : d_car(car), d_cdr(cdr) {} + +bool +pmt_is_null(const pmt_t& x) +{ + return x == PMT_NIL; +} + +bool +pmt_is_pair(const pmt_t& obj) +{ + return obj->is_pair(); +} + +pmt_t +pmt_cons(const pmt_t& x, const pmt_t& y) +{ + return pmt_t(new pmt_pair(x, y)); +} + +pmt_t +pmt_car(const pmt_t& pair) +{ + pmt_pair* p = dynamic_cast(pair.get()); + if ( p ) + return p->car(); + + throw pmt_wrong_type("pmt_car", pair); +} + +pmt_t +pmt_cdr(const pmt_t& pair) +{ + pmt_pair* p = dynamic_cast(pair.get()); + if ( p ) + return p->cdr(); + + throw pmt_wrong_type("pmt_cdr", pair); +} + +void +pmt_set_car(pmt_t pair, pmt_t obj) +{ + if (pair->is_pair()) + _pair(pair)->set_car(obj); + else + throw pmt_wrong_type("pmt_set_car", pair); +} + +void +pmt_set_cdr(pmt_t pair, pmt_t obj) +{ + if (pair->is_pair()) + _pair(pair)->set_cdr(obj); + else + throw pmt_wrong_type("pmt_set_cdr", pair); +} + +//////////////////////////////////////////////////////////////////////////// +// Vectors +//////////////////////////////////////////////////////////////////////////// + +pmt_vector::pmt_vector(size_t len, pmt_t fill) + : d_v(len) +{ + for (size_t i = 0; i < len; i++) + d_v[i] = fill; +} + +pmt_t +pmt_vector::ref(size_t k) const +{ + if (k >= length()) + throw pmt_out_of_range("pmt_vector_ref", pmt_from_long(k)); + return d_v[k]; +} + +void +pmt_vector::set(size_t k, pmt_t obj) +{ + if (k >= length()) + throw pmt_out_of_range("pmt_vector_set", pmt_from_long(k)); + d_v[k] = obj; +} + +void +pmt_vector::fill(pmt_t obj) +{ + for (size_t i = 0; i < length(); i++) + d_v[i] = obj; +} + +bool +pmt_is_vector(pmt_t obj) +{ + return obj->is_vector(); +} + +pmt_t +pmt_make_vector(size_t k, pmt_t fill) +{ + return pmt_t(new pmt_vector(k, fill)); +} + +pmt_t +pmt_vector_ref(pmt_t vector, size_t k) +{ + if (!vector->is_vector()) + throw pmt_wrong_type("pmt_vector_ref", vector); + return _vector(vector)->ref(k); +} + +void +pmt_vector_set(pmt_t vector, size_t k, pmt_t obj) +{ + if (!vector->is_vector()) + throw pmt_wrong_type("pmt_vector_set", vector); + _vector(vector)->set(k, obj); +} + +void +pmt_vector_fill(pmt_t vector, pmt_t obj) +{ + if (!vector->is_vector()) + throw pmt_wrong_type("pmt_vector_set", vector); + _vector(vector)->fill(obj); +} + +//////////////////////////////////////////////////////////////////////////// +// Uniform Numeric Vectors +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_is_uniform_vector(pmt_t x) +{ + return x->is_uniform_vector(); +} + +const void * +pmt_uniform_vector_elements(pmt_t vector, size_t &len) +{ + if (!vector->is_uniform_vector()) + throw pmt_wrong_type("pmt_uniform_vector_elements", vector); + return _uniform_vector(vector)->uniform_elements(len); +} + +void * +pmt_uniform_vector_writable_elements(pmt_t vector, size_t &len) +{ + if (!vector->is_uniform_vector()) + throw pmt_wrong_type("pmt_uniform_vector_writable_elements", vector); + return _uniform_vector(vector)->uniform_writable_elements(len); +} + +//////////////////////////////////////////////////////////////////////////// +// Dictionaries +//////////////////////////////////////////////////////////////////////////// + +pmt_dict::pmt_dict() + : d_alist(PMT_NIL) +{ +} + +void +pmt_dict::set(pmt_t key, pmt_t value) +{ + pmt_t p = pmt_assv(key, d_alist); // look for (key . value) pair + if (pmt_is_pair(p)){ // found existing pair... + pmt_set_cdr(p, value); // overrwrite cdr with new value + } + else { // not in the dict + d_alist = pmt_cons(pmt_cons(key, value), d_alist); // add new (key . value) pair + } +} + +pmt_t +pmt_dict::ref(pmt_t key, pmt_t not_found) const +{ + pmt_t p = pmt_assv(key, d_alist); // look for (key . value) pair + if (pmt_is_pair(p)) + return pmt_cdr(p); + else + return not_found; +} + +bool +pmt_dict::has_key(pmt_t key) const +{ + return pmt_is_pair(pmt_assv(key, d_alist)); +} + +pmt_t +pmt_dict::items() const +{ + return d_alist; +} + +pmt_t +pmt_dict::keys() const +{ + return pmt_map(pmt_car, d_alist); +} + +pmt_t +pmt_dict::values() const +{ + return pmt_map(pmt_cdr, d_alist); +} + +bool +pmt_is_dict(pmt_t obj) +{ + return obj->is_dict(); +} + +pmt_t +pmt_make_dict() +{ + return pmt_t(new pmt_dict()); +} + +void +pmt_dict_set(pmt_t dict, pmt_t key, pmt_t value) +{ + pmt_dict* d = _dict(dict); + if (!d) + throw pmt_wrong_type("pmt_dict_set", dict); + + d->set(key, value); +} + +bool +pmt_dict_has_key(pmt_t dict, pmt_t key) +{ + pmt_dict* d = _dict(dict); + if (!d) + throw pmt_wrong_type("pmt_dict_has_key", dict); + + return d->has_key(key); +} + +pmt_t +pmt_dict_ref(pmt_t dict, pmt_t key, pmt_t not_found) +{ + pmt_dict* d = _dict(dict); + if (!d) + throw pmt_wrong_type("pmt_dict_ref", dict); + + return d->ref(key, not_found); +} + +pmt_t +pmt_dict_items(pmt_t dict) +{ + if (!dict->is_dict()) + throw pmt_wrong_type("pmt_dict_items", dict); + + return _dict(dict)->items(); +} + +pmt_t +pmt_dict_keys(pmt_t dict) +{ + if (!dict->is_dict()) + throw pmt_wrong_type("pmt_dict_keys", dict); + + return _dict(dict)->keys(); +} + +pmt_t +pmt_dict_values(pmt_t dict) +{ + if (!dict->is_dict()) + throw pmt_wrong_type("pmt_dict_values", dict); + + return _dict(dict)->values(); +} + +//////////////////////////////////////////////////////////////////////////// +// Any +//////////////////////////////////////////////////////////////////////////// + +pmt_any::pmt_any(const boost::any &any) : d_any(any) {} + +bool +pmt_is_any(pmt_t obj) +{ + return obj->is_any(); +} + +pmt_t +pmt_make_any(const boost::any &any) +{ + return pmt_t(new pmt_any(any)); +} + +boost::any +pmt_any_ref(pmt_t obj) +{ + if (!obj->is_any()) + throw pmt_wrong_type("pmt_any_ref", obj); + return _any(obj)->ref(); +} + +void +pmt_any_set(pmt_t obj, const boost::any &any) +{ + if (!obj->is_any()) + throw pmt_wrong_type("pmt_any_set", obj); + _any(obj)->set(any); +} + +//////////////////////////////////////////////////////////////////////////// +// General Functions +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_eq(const pmt_t& x, const pmt_t& y) +{ + return x == y; +} + +bool +pmt_eqv(const pmt_t& x, const pmt_t& y) +{ + if (x == y) + return true; + + if (x->is_integer() && y->is_integer()) + return _integer(x)->value() == _integer(y)->value(); + + if (x->is_real() && y->is_real()) + return _real(x)->value() == _real(y)->value(); + + if (x->is_complex() && y->is_complex()) + return _complex(x)->value() == _complex(y)->value(); + + return false; +} + +bool +pmt_equal(const pmt_t& x, const pmt_t& y) +{ + if (pmt_eqv(x, y)) + return true; + + if (x->is_pair() && y->is_pair()) + return pmt_equal(pmt_car(x), pmt_car(y)) && pmt_equal(pmt_cdr(x), pmt_cdr(y)); + + if (x->is_vector() && y->is_vector()){ + pmt_vector *xv = _vector(x); + pmt_vector *yv = _vector(y); + if (xv->length() != yv->length()) + return false; + + for (unsigned i = 0; i < xv->length(); i++) + if (!pmt_equal(xv->_ref(i), yv->_ref(i))) + return false; + + return true; + } + + if (x->is_uniform_vector() && y->is_uniform_vector()){ + pmt_uniform_vector *xv = _uniform_vector(x); + pmt_uniform_vector *yv = _uniform_vector(y); + if (xv->length() != yv->length()) + return false; + + size_t len_x, len_y; + if (memcmp(xv->uniform_elements(len_x), + yv->uniform_elements(len_y), + len_x) == 0) + return true; + + return true; + } + + // FIXME add other cases here... + + return false; +} + +size_t +pmt_length(const pmt_t& x) +{ + if (x->is_vector()) + return _vector(x)->length(); + + if (x->is_uniform_vector()) + return _uniform_vector(x)->length(); + + if (x->is_null()) return 0; + + if (x->is_pair()) { + size_t length=1; + pmt_t it = pmt_cdr(x); + while (pmt_is_pair(it)){ + length++; + it = pmt_cdr(it); + } + if (pmt_is_null(it)) + return length; + + // not a proper list + throw pmt_wrong_type("pmt_length", x); + } + + // FIXME dictionary length (number of entries) + + throw pmt_wrong_type("pmt_length", x); +} + +pmt_t +pmt_assq(pmt_t obj, pmt_t alist) +{ + while (pmt_is_pair(alist)){ + pmt_t p = pmt_car(alist); + if (!pmt_is_pair(p)) // malformed alist + return PMT_F; + + if (pmt_eq(obj, pmt_car(p))) + return p; + + alist = pmt_cdr(alist); + } + return PMT_F; +} + +pmt_t +pmt_assv(pmt_t obj, pmt_t alist) +{ + while (pmt_is_pair(alist)){ + pmt_t p = pmt_car(alist); + if (!pmt_is_pair(p)) // malformed alist + return PMT_F; + + if (pmt_eqv(obj, pmt_car(p))) + return p; + + alist = pmt_cdr(alist); + } + return PMT_F; +} + +pmt_t +pmt_assoc(pmt_t obj, pmt_t alist) +{ + while (pmt_is_pair(alist)){ + pmt_t p = pmt_car(alist); + if (!pmt_is_pair(p)) // malformed alist + return PMT_F; + + if (pmt_equal(obj, pmt_car(p))) + return p; + + alist = pmt_cdr(alist); + } + return PMT_F; +} + +pmt_t +pmt_map(pmt_t proc(const pmt_t&), pmt_t list) +{ + pmt_t r = PMT_NIL; + + while(pmt_is_pair(list)){ + r = pmt_cons(proc(pmt_car(list)), r); + list = pmt_cdr(list); + } + + return pmt_reverse_x(r); +} + +pmt_t +pmt_reverse(pmt_t listx) +{ + pmt_t list = listx; + pmt_t r = PMT_NIL; + + while(pmt_is_pair(list)){ + r = pmt_cons(pmt_car(list), r); + list = pmt_cdr(list); + } + if (pmt_is_null(list)) + return r; + else + throw pmt_wrong_type("pmt_reverse", listx); +} + +pmt_t +pmt_reverse_x(pmt_t list) +{ + // FIXME do it destructively + return pmt_reverse(list); +} + +pmt_t +pmt_nth(size_t n, pmt_t list) +{ + pmt_t t = pmt_nthcdr(n, list); + if (pmt_is_pair(t)) + return pmt_car(t); + else + return PMT_NIL; +} + +pmt_t +pmt_nthcdr(size_t n, pmt_t list) +{ + if (!(pmt_is_pair(list) || pmt_is_null(list))) + throw pmt_wrong_type("pmt_nthcdr", list); + + while (n > 0){ + if (pmt_is_pair(list)){ + list = pmt_cdr(list); + n--; + continue; + } + if (pmt_is_null(list)) + return PMT_NIL; + else + throw pmt_wrong_type("pmt_nthcdr: not a LIST", list); + } + return list; +} + +pmt_t +pmt_memq(pmt_t obj, pmt_t list) +{ + while (pmt_is_pair(list)){ + if (pmt_eq(obj, pmt_car(list))) + return list; + list = pmt_cdr(list); + } + return PMT_F; +} + +pmt_t +pmt_memv(pmt_t obj, pmt_t list) +{ + while (pmt_is_pair(list)){ + if (pmt_eqv(obj, pmt_car(list))) + return list; + list = pmt_cdr(list); + } + return PMT_F; +} + +pmt_t +pmt_member(pmt_t obj, pmt_t list) +{ + while (pmt_is_pair(list)){ + if (pmt_equal(obj, pmt_car(list))) + return list; + list = pmt_cdr(list); + } + return PMT_F; +} + +bool +pmt_subsetp(pmt_t list1, pmt_t list2) +{ + while (pmt_is_pair(list1)){ + pmt_t p = pmt_car(list1); + if (pmt_is_false(pmt_memv(p, list2))) + return false; + list1 = pmt_cdr(list1); + } + return true; +} + +pmt_t +pmt_list1(const pmt_t& x1) +{ + return pmt_cons(x1, PMT_NIL); +} + +pmt_t +pmt_list2(const pmt_t& x1, const pmt_t& x2) +{ + return pmt_cons(x1, pmt_cons(x2, PMT_NIL)); +} + +pmt_t +pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3) +{ + return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, PMT_NIL))); +} + +pmt_t +pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4) +{ + return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, PMT_NIL)))); +} + +pmt_t +pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5) +{ + return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, pmt_cons(x5, PMT_NIL))))); +} + +pmt_t +pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6) +{ + return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, pmt_cons(x5, pmt_cons(x6, PMT_NIL)))))); +} + +pmt_t +pmt_list_add(pmt_t list, const pmt_t& item) +{ + return pmt_reverse(pmt_cons(item, pmt_reverse(list))); +} + +pmt_t +pmt_caar(pmt_t pair) +{ + return (pmt_car(pmt_car(pair))); +} + +pmt_t +pmt_cadr(pmt_t pair) +{ + return pmt_car(pmt_cdr(pair)); +} + +pmt_t +pmt_cdar(pmt_t pair) +{ + return pmt_cdr(pmt_car(pair)); +} + +pmt_t +pmt_cddr(pmt_t pair) +{ + return pmt_cdr(pmt_cdr(pair)); +} + +pmt_t +pmt_caddr(pmt_t pair) +{ + return pmt_car(pmt_cdr(pmt_cdr(pair))); +} + +pmt_t +pmt_cadddr(pmt_t pair) +{ + return pmt_car(pmt_cdr(pmt_cdr(pmt_cdr(pair)))); +} + +bool +pmt_is_eof_object(pmt_t obj) +{ + return pmt_eq(obj, PMT_EOF); +} + +void +pmt_dump_sizeof() +{ + printf("sizeof(pmt_t) = %3zd\n", sizeof(pmt_t)); + printf("sizeof(pmt_base) = %3zd\n", sizeof(pmt_base)); + printf("sizeof(pmt_bool) = %3zd\n", sizeof(pmt_bool)); + printf("sizeof(pmt_symbol) = %3zd\n", sizeof(pmt_symbol)); + printf("sizeof(pmt_integer) = %3zd\n", sizeof(pmt_integer)); + printf("sizeof(pmt_real) = %3zd\n", sizeof(pmt_real)); + printf("sizeof(pmt_complex) = %3zd\n", sizeof(pmt_complex)); + printf("sizeof(pmt_null) = %3zd\n", sizeof(pmt_null)); + printf("sizeof(pmt_pair) = %3zd\n", sizeof(pmt_pair)); + printf("sizeof(pmt_vector) = %3zd\n", sizeof(pmt_vector)); + printf("sizeof(pmt_dict) = %3zd\n", sizeof(pmt_dict)); + printf("sizeof(pmt_uniform_vector) = %3zd\n", sizeof(pmt_uniform_vector)); +} + +} /* namespace gruel */ diff --git a/gruel/src/lib/pmt_int.h b/gruel/src/lib/pmt_int.h new file mode 100644 index 000000000..03f0e555c --- /dev/null +++ b/gruel/src/lib/pmt_int.h @@ -0,0 +1,227 @@ +/* -*- 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. + */ +#ifndef INCLUDED_PMT_INT_H +#define INCLUDED_PMT_INT_H + +#include +#include + +/* + * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION! + * + * See pmt.h for the public interface + */ + +#define PMT_LOCAL_ALLOCATOR 0 // define to 0 or 1 +namespace gruel { + +class pmt_base : boost::noncopyable { +protected: + pmt_base(){}; + virtual ~pmt_base(); + +public: + virtual bool is_bool() const { return false; } + virtual bool is_symbol() const { return false; } + virtual bool is_number() const { return false; } + virtual bool is_integer() const { return false; } + virtual bool is_real() const { return false; } + virtual bool is_complex() const { return false; } + virtual bool is_null() const { return false; } + virtual bool is_pair() const { return false; } + virtual bool is_vector() const { return false; } + virtual bool is_dict() const { return false; } + virtual bool is_any() const { return false; } + + virtual bool is_uniform_vector() const { return false; } + virtual bool is_u8vector() const { return false; } + virtual bool is_s8vector() const { return false; } + virtual bool is_u16vector() const { return false; } + virtual bool is_s16vector() const { return false; } + virtual bool is_u32vector() const { return false; } + virtual bool is_s32vector() const { return false; } + virtual bool is_u64vector() const { return false; } + virtual bool is_s64vector() const { return false; } + virtual bool is_f32vector() const { return false; } + virtual bool is_f64vector() const { return false; } + virtual bool is_c32vector() const { return false; } + virtual bool is_c64vector() const { return false; } + +# if (PMT_LOCAL_ALLOCATOR) + void *operator new(size_t); + void operator delete(void *, size_t); +#endif +}; + +class pmt_bool : public pmt_base +{ +public: + pmt_bool(); + //~pmt_bool(){} + + bool is_bool() const { return true; } +}; + + +class pmt_symbol : public pmt_base +{ + std::string d_name; + pmt_t d_next; + +public: + pmt_symbol(const std::string &name); + //~pmt_symbol(){} + + bool is_symbol() const { return true; } + const std::string name() { return d_name; } + + pmt_t next() { return d_next; } // symbol table link + void set_next(pmt_t next) { d_next = next; } +}; + +class pmt_integer : public pmt_base +{ + long d_value; + +public: + pmt_integer(long value); + //~pmt_integer(){} + + bool is_number() const { return true; } + bool is_integer() const { return true; } + long value() const { return d_value; } +}; + +class pmt_real : public pmt_base +{ + double d_value; + +public: + pmt_real(double value); + //~pmt_real(){} + + bool is_number() const { return true; } + bool is_real() const { return true; } + double value() const { return d_value; } +}; + +class pmt_complex : public pmt_base +{ + std::complex d_value; + +public: + pmt_complex(std::complex value); + //~pmt_complex(){} + + bool is_number() const { return true; } + bool is_complex() const { return true; } + std::complex value() const { return d_value; } +}; + +class pmt_null : public pmt_base +{ +public: + pmt_null(); + //~pmt_null(){} + + bool is_null() const { return true; } +}; + +class pmt_pair : public pmt_base +{ + pmt_t d_car; + pmt_t d_cdr; + +public: + pmt_pair(const pmt_t& car, const pmt_t& cdr); + //~pmt_pair(){}; + + bool is_pair() const { return true; } + pmt_t car() const { return d_car; } + pmt_t cdr() const { return d_cdr; } + + void set_car(pmt_t car) { d_car = car; } + void set_cdr(pmt_t cdr) { d_cdr = cdr; } +}; + +class pmt_vector : public pmt_base +{ + std::vector d_v; + +public: + pmt_vector(size_t len, pmt_t fill); + //~pmt_vector(); + + bool is_vector() const { return true; } + pmt_t ref(size_t k) const; + void set(size_t k, pmt_t obj); + void fill(pmt_t fill); + size_t length() const { return d_v.size(); } + + pmt_t _ref(size_t k) const { return d_v[k]; } +}; + +class pmt_dict : public pmt_base +{ + pmt_t d_alist; // list of (key . value) pairs + +public: + pmt_dict(); + //~pmt_dict(); + + bool is_dict() const { return true; } + void set(pmt_t key, pmt_t value); + pmt_t ref(pmt_t key, pmt_t default_value) const; + bool has_key(pmt_t key) const; + pmt_t items() const; + pmt_t keys() const; + pmt_t values() const; +}; + +class pmt_any : public pmt_base +{ + boost::any d_any; + +public: + pmt_any(const boost::any &any); + //~pmt_any(); + + bool is_any() const { return true; } + const boost::any &ref() const { return d_any; } + void set(const boost::any &any) { d_any = any; } +}; + + +class pmt_uniform_vector : public pmt_base +{ +public: + bool is_uniform_vector() const { return true; } + virtual const void *uniform_elements(size_t &len) = 0; + virtual void *uniform_writable_elements(size_t &len) = 0; + virtual size_t length() const = 0; +}; + +#include "pmt_unv_int.h" + +} /* namespace gruel */ + +#endif /* INCLUDED_PMT_INT_H */ diff --git a/gruel/src/lib/pmt_io.cc b/gruel/src/lib/pmt_io.cc new file mode 100644 index 000000000..e10ea7814 --- /dev/null +++ b/gruel/src/lib/pmt_io.cc @@ -0,0 +1,141 @@ +/* -*- 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 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 +#endif +#include +#include +#include "pmt_int.h" +#include + +namespace gruel { + +static void +pmt_write_list_tail(pmt_t obj, std::ostream &port) +{ + pmt_write(pmt_car(obj), port); // write the car + obj = pmt_cdr(obj); // step to cdr + + if (pmt_is_null(obj)) // () + port << ")"; + + else if (pmt_is_pair(obj)){ // normal list + port << " "; + pmt_write_list_tail(obj, port); + } + else { // dotted pair + port << " . "; + pmt_write(obj, port); + port << ")"; + } +} + +void +pmt_write(pmt_t obj, std::ostream &port) +{ + if (pmt_is_bool(obj)){ + if (pmt_is_true(obj)) + port << "#t"; + else + port << "#f"; + } + else if (pmt_is_symbol(obj)){ + port << pmt_symbol_to_string(obj); + } + else if (pmt_is_number(obj)){ + if (pmt_is_integer(obj)) + port << pmt_to_long(obj); + else if (pmt_is_real(obj)) + port << pmt_to_double(obj); + else if (pmt_is_complex(obj)){ + std::complex c = pmt_to_complex(obj); + port << c.real() << '+' << c.imag() << 'i'; + } + else + goto error; + } + else if (pmt_is_null(obj)){ + port << "()"; + } + else if (pmt_is_pair(obj)){ + port << "("; + pmt_write_list_tail(obj, port); + } + else if (pmt_is_dict(obj)){ + // FIXME + // port << "#"; + port << "#"; + } + else if (pmt_is_vector(obj)){ + // FIXME + // port << "#"; + port << "#"; + } + else if (pmt_is_uniform_vector(obj)){ + // FIXME + // port << "#"; + port << "#"; + } + else { + error: + // FIXME + // port << "#<" << obj << ">"; + port << "#"; + } +} + +std::ostream& operator<<(std::ostream &os, pmt_t obj) +{ + pmt_write(obj, os); + return os; +} + +std::string +pmt_write_string(pmt_t obj) +{ + std::ostringstream s; + s << obj; + return s.str(); +} + +pmt_t +pmt_read(std::istream &port) +{ + throw pmt_notimplemented("notimplemented: pmt_read", PMT_NIL); +} + +void +pmt_serialize(pmt_t obj, std::ostream &sink) +{ + throw pmt_notimplemented("notimplemented: pmt_serialize", obj); +} + +/*! + * \brief Create obj from portable byte-serial representation + */ +pmt_t +pmt_deserialize(std::istream &source) +{ + throw pmt_notimplemented("notimplemented: pmt_deserialize", PMT_NIL); +} + +} /* namespace gruel */ diff --git a/gruel/src/lib/pmt_pool.cc b/gruel/src/lib/pmt_pool.cc new file mode 100644 index 000000000..79a22ea73 --- /dev/null +++ b/gruel/src/lib/pmt_pool.cc @@ -0,0 +1,112 @@ +/* -*- 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 +#endif +#include +#include +#include + +namespace gruel { + +static inline size_t +ROUNDUP(size_t x, size_t stride) +{ + return ((((x) + (stride) - 1)/(stride)) * (stride)); +} + +pmt_pool::pmt_pool(size_t itemsize, size_t alignment, + size_t allocation_size, size_t max_items) + : d_itemsize(ROUNDUP(itemsize, alignment)), + d_alignment(alignment), + d_allocation_size(std::max(allocation_size, 16 * itemsize)), + d_max_items(max_items), d_n_items(0), + d_freelist(0) +{ +} + +pmt_pool::~pmt_pool() +{ + for (unsigned int i = 0; i < d_allocations.size(); i++){ + delete [] d_allocations[i]; + } +} + +void * +pmt_pool::malloc() +{ + scoped_lock guard(d_mutex); + item *p; + + if (d_max_items != 0){ + while (d_n_items >= d_max_items) + d_cond.wait(guard); + } + + if (d_freelist){ // got something? + p = d_freelist; + d_freelist = p->d_next; + d_n_items++; + return p; + } + + // allocate a new chunk + char *alloc = new char[d_allocation_size + d_alignment - 1]; + d_allocations.push_back(alloc); + + // get the alignment we require + char *start = (char *)(((uintptr_t)alloc + d_alignment-1) & -d_alignment); + char *end = alloc + d_allocation_size + d_alignment - 1; + size_t n = (end - start) / d_itemsize; + + // link the new items onto the free list. + p = (item *) start; + for (size_t i = 0; i < n; i++){ + p->d_next = d_freelist; + d_freelist = p; + p = (item *)((char *) p + d_itemsize); + } + + // now return the first one + p = d_freelist; + d_freelist = p->d_next; + d_n_items++; + return p; +} + +void +pmt_pool::free(void *foo) +{ + if (!foo) + return; + + scoped_lock guard(d_mutex); + + item *p = (item *) foo; + p->d_next = d_freelist; + d_freelist = p; + d_n_items--; + if (d_max_items != 0) + d_cond.notify_one(); +} + +} /* namespace gruel */ diff --git a/gruel/src/lib/pmt_serialize.cc b/gruel/src/lib/pmt_serialize.cc new file mode 100644 index 000000000..b7193e811 --- /dev/null +++ b/gruel/src/lib/pmt_serialize.cc @@ -0,0 +1,357 @@ +/* -*- 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 +#endif +#include +#include +#include "pmt_int.h" +#include "gruel/pmt_serial_tags.h" + +namespace gruel { + +static pmt_t parse_pair(std::streambuf &sb); + +// ---------------------------------------------------------------- +// output primitives +// ---------------------------------------------------------------- + +static bool +serialize_untagged_u8(unsigned int i, std::streambuf &sb) +{ + return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} + +// always writes big-endian +static bool +serialize_untagged_u16(unsigned int i, std::streambuf &sb) +{ + sb.sputc((i >> 8) & 0xff); + return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} + +// always writes big-endian +static bool +serialize_untagged_u32(unsigned int i, std::streambuf &sb) +{ + sb.sputc((i >> 24) & 0xff); + sb.sputc((i >> 16) & 0xff); + sb.sputc((i >> 8) & 0xff); + return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} + +#if 0 +// always writes big-endian +static bool +serialize_untagged_u64(uint64_t i, std::streambuf &sb) +{ + sb.sputc((i >> 56) & 0xff); + sb.sputc((i >> 48) & 0xff); + sb.sputc((i >> 40) & 0xff); + sb.sputc((i >> 32) & 0xff); + sb.sputc((i >> 24) & 0xff); + sb.sputc((i >> 16) & 0xff); + sb.sputc((i >> 8) & 0xff); + return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} +#endif + +// ---------------------------------------------------------------- +// input primitives +// ---------------------------------------------------------------- + + +// always reads big-endian +static bool +deserialize_untagged_u8(uint8_t *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + int i; + + t = sb.sbumpc(); + i = t & 0xff; + + *ip = i; + return t != std::streambuf::traits_type::eof(); +} + +// always reads big-endian +static bool +deserialize_untagged_u16(uint16_t *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + int i; + + t = sb.sbumpc(); + i = t & 0xff; + + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + + *ip = i; + return t != std::streambuf::traits_type::eof(); +} + +// always reads big-endian +static bool +deserialize_untagged_u32(uint32_t *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + int i; + + t = sb.sbumpc(); + i = t & 0xff; + + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + + *ip = i; + return t != std::streambuf::traits_type::eof(); +} + +#if 0 +// always reads big-endian +static bool +deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + uint64_t i; + + t = sb.sbumpc(); + i = t & 0xff; + + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + + *ip = i; + return t != std::streambuf::traits_type::eof(); +} +#endif + +/* + * Write portable byte-serial representation of \p obj to \p sb + * + * N.B., Circular structures cause infinite recursion. + */ +bool +pmt_serialize(pmt_t obj, std::streambuf &sb) +{ + bool ok = true; + + tail_recursion: + + if (pmt_is_bool(obj)){ + if (pmt_eq(obj, PMT_T)) + return serialize_untagged_u8(PST_TRUE, sb); + else + return serialize_untagged_u8(PST_FALSE, sb); + } + + if (pmt_is_null(obj)) + return serialize_untagged_u8(PST_NULL, sb); + + if (pmt_is_symbol(obj)){ + const std::string s = pmt_symbol_to_string(obj); + size_t len = s.size(); + ok = serialize_untagged_u8(PST_SYMBOL, sb); + ok &= serialize_untagged_u16(len, sb); + for (size_t i = 0; i < len; i++) + ok &= serialize_untagged_u8(s[i], sb); + return ok; + } + + if (pmt_is_pair(obj)){ + ok = serialize_untagged_u8(PST_PAIR, sb); + ok &= pmt_serialize(pmt_car(obj), sb); + if (!ok) + return false; + obj = pmt_cdr(obj); + goto tail_recursion; + } + + if (pmt_is_number(obj)){ + + if (pmt_is_integer(obj)){ + long i = pmt_to_long(obj); + if (sizeof(long) > 4){ + if (i < -2147483647 || i > 2147483647) + throw pmt_notimplemented("pmt_serialize (64-bit integers)", obj); + } + ok = serialize_untagged_u8(PST_INT32, sb); + ok &= serialize_untagged_u32(i, sb); + return ok; + } + + if (pmt_is_real(obj)) + throw pmt_notimplemented("pmt_serialize (real)", obj); + + if (pmt_is_complex(obj)) + throw pmt_notimplemented("pmt_serialize (complex)", obj); + } + + if (pmt_is_vector(obj)) + throw pmt_notimplemented("pmt_serialize (vector)", obj); + + if (pmt_is_uniform_vector(obj)) + throw pmt_notimplemented("pmt_serialize (uniform-vector)", obj); + + if (pmt_is_dict(obj)) + throw pmt_notimplemented("pmt_serialize (dict)", obj); + + + throw pmt_notimplemented("pmt_serialize (?)", obj); +} + +/* + * Create obj from portable byte-serial representation + * + * Returns next obj from streambuf, or PMT_EOF at end of file. + * Throws exception on malformed input. + */ +pmt_t +pmt_deserialize(std::streambuf &sb) +{ + uint8_t tag; + //uint8_t u8; + uint16_t u16; + uint32_t u32; + //uint32_t u64; + static char tmpbuf[1024]; + + if (!deserialize_untagged_u8(&tag, sb)) + return PMT_EOF; + + switch (tag){ + case PST_TRUE: + return PMT_T; + + case PST_FALSE: + return PMT_F; + + case PST_NULL: + return PMT_NIL; + + case PST_SYMBOL: + if (!deserialize_untagged_u16(&u16, sb)) + goto error; + if (u16 > sizeof(tmpbuf)) + throw pmt_notimplemented("pmt_deserialize: very long symbol", + PMT_F); + if (sb.sgetn(tmpbuf, u16) != u16) + goto error; + return pmt_intern(std::string(tmpbuf, u16)); + + case PST_INT32: + if (!deserialize_untagged_u32(&u32, sb)) + goto error; + return pmt_from_long((int32_t) u32); + + case PST_PAIR: + return parse_pair(sb); + + case PST_DOUBLE: + case PST_COMPLEX: + case PST_VECTOR: + case PST_DICT: + case PST_UNIFORM_VECTOR: + case PST_COMMENT: + throw pmt_notimplemented("pmt_deserialize: tag value = ", + pmt_from_long(tag)); + + default: + throw pmt_exception("pmt_deserialize: malformed input stream, tag value = ", + pmt_from_long(tag)); + } + + error: + throw pmt_exception("pmt_deserialize: malformed input stream", PMT_F); +} + +/* + * This is a mostly non-recursive implementation that allows us to + * deserialize very long lists w/o exhausting the evaluation stack. + * + * On entry we've already eaten the PST_PAIR tag. + */ +pmt_t +parse_pair(std::streambuf &sb) +{ + uint8_t tag; + pmt_t val, expr, lastnptr, nptr; + + // + // Keep appending nodes until we get a non-PAIR cdr. + // + lastnptr = PMT_NIL; + while (1){ + expr = pmt_deserialize(sb); // read the car + + nptr = pmt_cons(expr, PMT_NIL); // build new cell + if (pmt_is_null(lastnptr)) + val = nptr; + else + pmt_set_cdr(lastnptr, nptr); + lastnptr = nptr; + + if (!deserialize_untagged_u8(&tag, sb)) // get tag of cdr + throw pmt_exception("pmt_deserialize: malformed input stream", PMT_F); + + if (tag == PST_PAIR) + continue; // keep on looping... + + if (tag == PST_NULL){ + expr = PMT_NIL; + break; + } + + // + // default: push tag back and use pmt_deserialize to get the cdr + // + sb.sungetc(); + expr = pmt_deserialize(sb); + break; + } + + // + // At this point, expr contains the value of the final cdr in the list. + // + pmt_set_cdr(lastnptr, expr); + return val; +} + +} /* namespace gruel */ diff --git a/gruel/src/lib/qa_pmt.cc b/gruel/src/lib/qa_pmt.cc new file mode 100644 index 000000000..250befafa --- /dev/null +++ b/gruel/src/lib/qa_pmt.cc @@ -0,0 +1,40 @@ +/* + * 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. + */ + +/* + * This class gathers together all the test cases for pmt into + * a single test suite. As you create new test cases, add them here. + */ + +#include +#include +#include + +CppUnit::TestSuite * +qa_pmt::suite () +{ + CppUnit::TestSuite *s = new CppUnit::TestSuite ("pmt"); + + s->addTest (qa_pmt_prims::suite ()); + s->addTest (qa_pmt_unv::suite ()); + + return s; +} diff --git a/gruel/src/lib/qa_pmt.h b/gruel/src/lib/qa_pmt.h new file mode 100644 index 000000000..43a6dbf67 --- /dev/null +++ b/gruel/src/lib/qa_pmt.h @@ -0,0 +1,36 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_QA_PMT_H +#define INCLUDED_QA_PMT_H + +#include + +//! collect all the tests for pmt + +class qa_pmt { + public: + //! return suite of tests for all of pmt + static CppUnit::TestSuite *suite (); +}; + +#endif /* INCLUDED_QA_PMT_H */ diff --git a/gruel/src/lib/qa_pmt_prims.cc b/gruel/src/lib/qa_pmt_prims.cc new file mode 100644 index 000000000..ac93f8063 --- /dev/null +++ b/gruel/src/lib/qa_pmt_prims.cc @@ -0,0 +1,438 @@ +/* -*- 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 +#include +#include +#include + +using namespace gruel; + +void +qa_pmt_prims::test_symbols() +{ + CPPUNIT_ASSERT(!pmt_is_symbol(PMT_T)); + CPPUNIT_ASSERT(!pmt_is_symbol(PMT_F)); + CPPUNIT_ASSERT_THROW(pmt_symbol_to_string(PMT_F), pmt_wrong_type); + + pmt_t sym1 = pmt_string_to_symbol("test"); + CPPUNIT_ASSERT(pmt_is_symbol(sym1)); + CPPUNIT_ASSERT_EQUAL(std::string("test"), pmt_symbol_to_string(sym1)); + CPPUNIT_ASSERT(pmt_is_true(sym1)); + CPPUNIT_ASSERT(!pmt_is_false(sym1)); + + pmt_t sym2 = pmt_string_to_symbol("foo"); + pmt_t sym3 = pmt_string_to_symbol("test"); + CPPUNIT_ASSERT_EQUAL(sym1, sym3); + CPPUNIT_ASSERT(sym1 != sym2); + CPPUNIT_ASSERT(sym1 == sym3); + + static const int N = 2048; + std::vector v1(N); + std::vector v2(N); + + // generate a bunch of symbols + for (int i = 0; i < N; i++){ + char buf[100]; + snprintf(buf, sizeof(buf), "test-%d", i); + v1[i] = pmt_string_to_symbol(buf); + } + + // confirm that they are all unique + for (int i = 0; i < N; i++) + for (int j = i + 1; j < N; j++) + CPPUNIT_ASSERT(v1[i] != v1[j]); + + // generate the same symbols again + for (int i = 0; i < N; i++){ + char buf[100]; + snprintf(buf, sizeof(buf), "test-%d", i); + v2[i] = pmt_string_to_symbol(buf); + } + + // confirm that we get the same ones back + for (int i = 0; i < N; i++) + CPPUNIT_ASSERT(v1[i] == v2[i]); +} + +void +qa_pmt_prims::test_booleans() +{ + pmt_t sym = pmt_string_to_symbol("test"); + CPPUNIT_ASSERT(pmt_is_bool(PMT_T)); + CPPUNIT_ASSERT(pmt_is_bool(PMT_F)); + CPPUNIT_ASSERT(!pmt_is_bool(sym)); + CPPUNIT_ASSERT_EQUAL(pmt_from_bool(false), PMT_F); + CPPUNIT_ASSERT_EQUAL(pmt_from_bool(true), PMT_T); + CPPUNIT_ASSERT_EQUAL(false, pmt_to_bool(PMT_F)); + CPPUNIT_ASSERT_EQUAL(true, pmt_to_bool(PMT_T)); + CPPUNIT_ASSERT_THROW(pmt_to_bool(sym), pmt_wrong_type); +} + +void +qa_pmt_prims::test_integers() +{ + pmt_t p1 = pmt_from_long(1); + pmt_t m1 = pmt_from_long(-1); + CPPUNIT_ASSERT(!pmt_is_integer(PMT_T)); + CPPUNIT_ASSERT(pmt_is_integer(p1)); + CPPUNIT_ASSERT(pmt_is_integer(m1)); + CPPUNIT_ASSERT_THROW(pmt_to_long(PMT_T), pmt_wrong_type); + CPPUNIT_ASSERT_EQUAL(-1L, pmt_to_long(m1)); + CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(p1)); +} + +void +qa_pmt_prims::test_reals() +{ + pmt_t p1 = pmt_from_double(1); + pmt_t m1 = pmt_from_double(-1); + CPPUNIT_ASSERT(!pmt_is_real(PMT_T)); + CPPUNIT_ASSERT(pmt_is_real(p1)); + CPPUNIT_ASSERT(pmt_is_real(m1)); + CPPUNIT_ASSERT_THROW(pmt_to_double(PMT_T), pmt_wrong_type); + CPPUNIT_ASSERT_EQUAL(-1.0, pmt_to_double(m1)); + CPPUNIT_ASSERT_EQUAL(1.0, pmt_to_double(p1)); + CPPUNIT_ASSERT_EQUAL(1.0, pmt_to_double(pmt_from_long(1))); +} + +void +qa_pmt_prims::test_complexes() +{ + pmt_t p1 = pmt_make_rectangular(2, -3); + pmt_t m1 = pmt_make_rectangular(-3, 2); + CPPUNIT_ASSERT(!pmt_is_complex(PMT_T)); + CPPUNIT_ASSERT(pmt_is_complex(p1)); + CPPUNIT_ASSERT(pmt_is_complex(m1)); + CPPUNIT_ASSERT_THROW(pmt_to_complex(PMT_T), pmt_wrong_type); + CPPUNIT_ASSERT_EQUAL(std::complex(2, -3), pmt_to_complex(p1)); + CPPUNIT_ASSERT_EQUAL(std::complex(-3, 2), pmt_to_complex(m1)); + CPPUNIT_ASSERT_EQUAL(std::complex(1.0, 0), pmt_to_complex(pmt_from_long(1))); + CPPUNIT_ASSERT_EQUAL(std::complex(1.0, 0), pmt_to_complex(pmt_from_double(1.0))); +} + +void +qa_pmt_prims::test_pairs() +{ + CPPUNIT_ASSERT(pmt_is_null(PMT_NIL)); + CPPUNIT_ASSERT(!pmt_is_pair(PMT_NIL)); + pmt_t s1 = pmt_string_to_symbol("s1"); + pmt_t s2 = pmt_string_to_symbol("s2"); + pmt_t s3 = pmt_string_to_symbol("s3"); + + + CPPUNIT_ASSERT_EQUAL((size_t)0, pmt_length(PMT_NIL)); + CPPUNIT_ASSERT_THROW(pmt_length(s1), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_length(pmt_from_double(42)), pmt_wrong_type); + + pmt_t c1 = pmt_cons(s1, PMT_NIL); + CPPUNIT_ASSERT(pmt_is_pair(c1)); + CPPUNIT_ASSERT(!pmt_is_pair(s1)); + CPPUNIT_ASSERT_EQUAL(s1, pmt_car(c1)); + CPPUNIT_ASSERT_EQUAL(PMT_NIL, pmt_cdr(c1)); + CPPUNIT_ASSERT_EQUAL((size_t) 1, pmt_length(c1)); + + pmt_t c3 = pmt_cons(s3, PMT_NIL); + pmt_t c2 = pmt_cons(s2, c3); + pmt_set_cdr(c1, c2); + CPPUNIT_ASSERT_EQUAL(c2, pmt_cdr(c1)); + pmt_set_car(c1, s3); + CPPUNIT_ASSERT_EQUAL(s3, pmt_car(c1)); + CPPUNIT_ASSERT_EQUAL((size_t)1, pmt_length(c3)); + CPPUNIT_ASSERT_EQUAL((size_t)2, pmt_length(c2)); + + CPPUNIT_ASSERT_THROW(pmt_cdr(PMT_NIL), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_car(PMT_NIL), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_set_car(s1, PMT_NIL), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_set_cdr(s1, PMT_NIL), pmt_wrong_type); +} + +void +qa_pmt_prims::test_vectors() +{ + static const size_t N = 3; + pmt_t v1 = pmt_make_vector(N, PMT_NIL); + CPPUNIT_ASSERT_EQUAL(N, pmt_length(v1)); + pmt_t s0 = pmt_string_to_symbol("s0"); + pmt_t s1 = pmt_string_to_symbol("s1"); + pmt_t s2 = pmt_string_to_symbol("s2"); + + pmt_vector_set(v1, 0, s0); + pmt_vector_set(v1, 1, s1); + pmt_vector_set(v1, 2, s2); + + CPPUNIT_ASSERT_EQUAL(s0, pmt_vector_ref(v1, 0)); + CPPUNIT_ASSERT_EQUAL(s1, pmt_vector_ref(v1, 1)); + CPPUNIT_ASSERT_EQUAL(s2, pmt_vector_ref(v1, 2)); + + CPPUNIT_ASSERT_THROW(pmt_vector_ref(v1, N), pmt_out_of_range); + CPPUNIT_ASSERT_THROW(pmt_vector_set(v1, N, PMT_NIL), pmt_out_of_range); + + pmt_vector_fill(v1, s0); + for (size_t i = 0; i < N; i++) + CPPUNIT_ASSERT_EQUAL(s0, pmt_vector_ref(v1, i)); +} + +void +qa_pmt_prims::test_equivalence() +{ + pmt_t s0 = pmt_string_to_symbol("s0"); + pmt_t s1 = pmt_string_to_symbol("s1"); + pmt_t s2 = pmt_string_to_symbol("s2"); + pmt_t list0 = pmt_cons(s0, pmt_cons(s1, pmt_cons(s2, PMT_NIL))); + pmt_t list1 = pmt_cons(s0, pmt_cons(s1, pmt_cons(s2, PMT_NIL))); + pmt_t i0 = pmt_from_long(42); + pmt_t i1 = pmt_from_long(42); + pmt_t r0 = pmt_from_double(42); + pmt_t r1 = pmt_from_double(42); + pmt_t r2 = pmt_from_double(43); + + CPPUNIT_ASSERT(pmt_eq(s0, s0)); + CPPUNIT_ASSERT(!pmt_eq(s0, s1)); + CPPUNIT_ASSERT(pmt_eqv(s0, s0)); + CPPUNIT_ASSERT(!pmt_eqv(s0, s1)); + + CPPUNIT_ASSERT(pmt_eqv(i0, i1)); + CPPUNIT_ASSERT(pmt_eqv(r0, r1)); + CPPUNIT_ASSERT(!pmt_eqv(r0, r2)); + CPPUNIT_ASSERT(!pmt_eqv(i0, r0)); + + CPPUNIT_ASSERT(!pmt_eq(list0, list1)); + CPPUNIT_ASSERT(!pmt_eqv(list0, list1)); + CPPUNIT_ASSERT(pmt_equal(list0, list1)); + + pmt_t v0 = pmt_make_vector(3, s0); + pmt_t v1 = pmt_make_vector(3, s0); + pmt_t v2 = pmt_make_vector(4, s0); + CPPUNIT_ASSERT(!pmt_eqv(v0, v1)); + CPPUNIT_ASSERT(pmt_equal(v0, v1)); + CPPUNIT_ASSERT(!pmt_equal(v0, v2)); + + pmt_vector_set(v0, 0, list0); + pmt_vector_set(v0, 1, list0); + pmt_vector_set(v1, 0, list1); + pmt_vector_set(v1, 1, list1); + CPPUNIT_ASSERT(pmt_equal(v0, v1)); +} + +void +qa_pmt_prims::test_misc() +{ + pmt_t k0 = pmt_string_to_symbol("k0"); + pmt_t k1 = pmt_string_to_symbol("k1"); + pmt_t k2 = pmt_string_to_symbol("k2"); + pmt_t k3 = pmt_string_to_symbol("k3"); + pmt_t v0 = pmt_string_to_symbol("v0"); + pmt_t v1 = pmt_string_to_symbol("v1"); + pmt_t v2 = pmt_string_to_symbol("v2"); + pmt_t p0 = pmt_cons(k0, v0); + pmt_t p1 = pmt_cons(k1, v1); + pmt_t p2 = pmt_cons(k2, v2); + + pmt_t alist = pmt_cons(p0, pmt_cons(p1, pmt_cons(p2, PMT_NIL))); + CPPUNIT_ASSERT(pmt_eq(p1, pmt_assv(k1, alist))); + CPPUNIT_ASSERT(pmt_eq(PMT_F, pmt_assv(k3, alist))); + + pmt_t keys = pmt_cons(k0, pmt_cons(k1, pmt_cons(k2, PMT_NIL))); + pmt_t vals = pmt_cons(v0, pmt_cons(v1, pmt_cons(v2, PMT_NIL))); + CPPUNIT_ASSERT(pmt_equal(keys, pmt_map(pmt_car, alist))); + CPPUNIT_ASSERT(pmt_equal(vals, pmt_map(pmt_cdr, alist))); +} + +void +qa_pmt_prims::test_dict() +{ + pmt_t dict = pmt_make_dict(); + CPPUNIT_ASSERT(pmt_is_dict(dict)); + + pmt_t k0 = pmt_string_to_symbol("k0"); + pmt_t k1 = pmt_string_to_symbol("k1"); + pmt_t k2 = pmt_string_to_symbol("k2"); + pmt_t k3 = pmt_string_to_symbol("k3"); + pmt_t v0 = pmt_string_to_symbol("v0"); + pmt_t v1 = pmt_string_to_symbol("v1"); + pmt_t v2 = pmt_string_to_symbol("v2"); + pmt_t v3 = pmt_string_to_symbol("v3"); + pmt_t not_found = pmt_cons(PMT_NIL, PMT_NIL); + + CPPUNIT_ASSERT(!pmt_dict_has_key(dict, k0)); + pmt_dict_set(dict, k0, v0); + CPPUNIT_ASSERT(pmt_dict_has_key(dict, k0)); + CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k0, not_found), v0)); + CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), not_found)); + pmt_dict_set(dict, k1, v1); + pmt_dict_set(dict, k2, v2); + CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), v1)); + pmt_dict_set(dict, k1, v3); + CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), v3)); + + pmt_t keys = pmt_cons(k2, pmt_cons(k1, pmt_cons(k0, PMT_NIL))); + pmt_t vals = pmt_cons(v2, pmt_cons(v3, pmt_cons(v0, PMT_NIL))); + CPPUNIT_ASSERT(pmt_equal(keys, pmt_dict_keys(dict))); + CPPUNIT_ASSERT(pmt_equal(vals, pmt_dict_values(dict))); +} + +void +qa_pmt_prims::test_io() +{ + pmt_t k0 = pmt_string_to_symbol("k0"); + pmt_t k1 = pmt_string_to_symbol("k1"); + pmt_t k2 = pmt_string_to_symbol("k2"); + pmt_t k3 = pmt_string_to_symbol("k3"); + + CPPUNIT_ASSERT_EQUAL(std::string("k0"), pmt_write_string(k0)); +} + +void +qa_pmt_prims::test_lists() +{ + pmt_t s0 = pmt_intern("s0"); + pmt_t s1 = pmt_intern("s1"); + pmt_t s2 = pmt_intern("s2"); + pmt_t s3 = pmt_intern("s3"); + + pmt_t l1 = pmt_list4(s0, s1, s2, s3); + pmt_t l2 = pmt_list3(s0, s1, s2); + pmt_t l3 = pmt_list_add(l2, s3); + CPPUNIT_ASSERT(pmt_equal(l1, l3)); +} + +// ------------------------------------------------------------------------ + +// class foo is used in test_any below. +// It can't be declared in the scope of test_any because of template +// namespace problems. + +class foo { +public: + double d_double; + int d_int; + foo(double d=0, int i=0) : d_double(d), d_int(i) {} +}; + +bool operator==(const foo &a, const foo &b) +{ + return a.d_double == b.d_double && a.d_int == b.d_int; +} + +std::ostream& operator<<(std::ostream &os, const foo obj) +{ + os << ""; + return os; +} + +void +qa_pmt_prims::test_any() +{ + boost::any a0; + boost::any a1; + boost::any a2; + + a0 = std::string("Hello!"); + a1 = 42; + a2 = foo(3.250, 21); + + pmt_t p0 = pmt_make_any(a0); + pmt_t p1 = pmt_make_any(a1); + pmt_t p2 = pmt_make_any(a2); + + CPPUNIT_ASSERT_EQUAL(std::string("Hello!"), + boost::any_cast(pmt_any_ref(p0))); + + CPPUNIT_ASSERT_EQUAL(42, + boost::any_cast(pmt_any_ref(p1))); + + CPPUNIT_ASSERT_EQUAL(foo(3.250, 21), + boost::any_cast(pmt_any_ref(p2))); +} + +// ------------------------------------------------------------------------ + +void +qa_pmt_prims::test_serialize() +{ + std::stringbuf sb; // fake channel + pmt_t a = pmt_intern("a"); + pmt_t b = pmt_intern("b"); + pmt_t c = pmt_intern("c"); + + sb.str(""); // reset channel to empty + + // write stuff to channel + + pmt_serialize(PMT_NIL, sb); + pmt_serialize(pmt_intern("foobarvia"), sb); + pmt_serialize(pmt_from_long(123456789), sb); + pmt_serialize(pmt_from_long(-123456789), sb); + pmt_serialize(pmt_cons(PMT_NIL, PMT_NIL), sb); + pmt_serialize(pmt_cons(a, b), sb); + pmt_serialize(pmt_list1(a), sb); + pmt_serialize(pmt_list2(a, b), sb); + pmt_serialize(pmt_list3(a, b, c), sb); + pmt_serialize(pmt_list3(a, pmt_list3(c, b, a), c), sb); + pmt_serialize(PMT_T, sb); + pmt_serialize(PMT_F, sb); + + // read it back + + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_NIL)); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_intern("foobarvia"))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_from_long(123456789))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_from_long(-123456789))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_cons(PMT_NIL, PMT_NIL))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_cons(a, b))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list1(a))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list2(a, b))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list3(a, b, c))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list3(a, pmt_list3(c, b, a), c))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_T)); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_F)); + + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_EOF)); // last item + + + // FIXME add tests for real, complex, vector, uniform-vector, dict + // FIXME add tests for malformed input too. + +} + +void +qa_pmt_prims::test_sets() +{ + pmt_t s1 = pmt_intern("s1"); + pmt_t s2 = pmt_intern("s2"); + pmt_t s3 = pmt_intern("s3"); + + pmt_t l1 = pmt_list1(s1); + pmt_t l2 = pmt_list2(s2,s3); + pmt_t l3 = pmt_list3(s1,s2,s3); + + CPPUNIT_ASSERT(pmt_is_pair(pmt_memq(s1,l1))); + CPPUNIT_ASSERT(pmt_is_false(pmt_memq(s3,l1))); + + CPPUNIT_ASSERT(pmt_subsetp(l1,l3)); + CPPUNIT_ASSERT(pmt_subsetp(l2,l3)); + CPPUNIT_ASSERT(!pmt_subsetp(l1,l2)); + CPPUNIT_ASSERT(!pmt_subsetp(l2,l1)); + CPPUNIT_ASSERT(!pmt_subsetp(l3,l2)); +} diff --git a/gruel/src/lib/qa_pmt_prims.h b/gruel/src/lib/qa_pmt_prims.h new file mode 100644 index 000000000..effb3a097 --- /dev/null +++ b/gruel/src/lib/qa_pmt_prims.h @@ -0,0 +1,67 @@ +/* -*- 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. + */ +#ifndef INCLUDED_QA_PMT_PRIMS_H +#define INCLUDED_QA_PMT_PRIMS_H + +#include +#include + +class qa_pmt_prims : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE(qa_pmt_prims); + CPPUNIT_TEST(test_symbols); + CPPUNIT_TEST(test_booleans); + CPPUNIT_TEST(test_integers); + CPPUNIT_TEST(test_reals); + CPPUNIT_TEST(test_complexes); + CPPUNIT_TEST(test_pairs); + CPPUNIT_TEST(test_vectors); + CPPUNIT_TEST(test_equivalence); + CPPUNIT_TEST(test_misc); + CPPUNIT_TEST(test_dict); + CPPUNIT_TEST(test_any); + CPPUNIT_TEST(test_io); + CPPUNIT_TEST(test_lists); + CPPUNIT_TEST(test_serialize); + CPPUNIT_TEST(test_sets); + CPPUNIT_TEST_SUITE_END(); + + private: + void test_symbols(); + void test_booleans(); + void test_integers(); + void test_reals(); + void test_complexes(); + void test_pairs(); + void test_vectors(); + void test_equivalence(); + void test_misc(); + void test_dict(); + void test_any(); + void test_io(); + void test_lists(); + void test_serialize(); + void test_sets(); +}; + +#endif /* INCLUDED_QA_PMT_PRIMS_H */ + diff --git a/gruel/src/lib/test_pmt.cc b/gruel/src/lib/test_pmt.cc new file mode 100644 index 000000000..034785f4e --- /dev/null +++ b/gruel/src/lib/test_pmt.cc @@ -0,0 +1,37 @@ +/* -*- 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/unv_qa_template.cc.t b/gruel/src/lib/unv_qa_template.cc.t new file mode 100644 index 000000000..1e2c8e8eb --- /dev/null +++ b/gruel/src/lib/unv_qa_template.cc.t @@ -0,0 +1,35 @@ +void +qa_pmt_unv::test_@TAG@vector() +{ + static const size_t N = 3; + pmt_t v1 = pmt_make_@TAG@vector(N, 0); + CPPUNIT_ASSERT_EQUAL(N, pmt_length(v1)); + @TYPE@ s0 = @TYPE@(10); + @TYPE@ s1 = @TYPE@(20); + @TYPE@ s2 = @TYPE@(30); + + pmt_@TAG@vector_set(v1, 0, s0); + pmt_@TAG@vector_set(v1, 1, s1); + pmt_@TAG@vector_set(v1, 2, s2); + + CPPUNIT_ASSERT_EQUAL(s0, pmt_@TAG@vector_ref(v1, 0)); + CPPUNIT_ASSERT_EQUAL(s1, pmt_@TAG@vector_ref(v1, 1)); + CPPUNIT_ASSERT_EQUAL(s2, pmt_@TAG@vector_ref(v1, 2)); + + CPPUNIT_ASSERT_THROW(pmt_@TAG@vector_ref(v1, N), pmt_out_of_range); + CPPUNIT_ASSERT_THROW(pmt_@TAG@vector_set(v1, N, @TYPE@(0)), pmt_out_of_range); + + size_t len; + const @TYPE@ *rd = pmt_@TAG@vector_elements(v1, len); + CPPUNIT_ASSERT_EQUAL(len, N); + CPPUNIT_ASSERT_EQUAL(s0, rd[0]); + CPPUNIT_ASSERT_EQUAL(s1, rd[1]); + CPPUNIT_ASSERT_EQUAL(s2, rd[2]); + + @TYPE@ *wr = pmt_@TAG@vector_writable_elements(v1, len); + CPPUNIT_ASSERT_EQUAL(len, N); + wr[0] = @TYPE@(0); + CPPUNIT_ASSERT_EQUAL(@TYPE@(0), wr[0]); + CPPUNIT_ASSERT_EQUAL(s1, wr[1]); + CPPUNIT_ASSERT_EQUAL(s2, wr[2]); +} diff --git a/gruel/src/lib/unv_template.cc.t b/gruel/src/lib/unv_template.cc.t new file mode 100644 index 000000000..b19e32d27 --- /dev/null +++ b/gruel/src/lib/unv_template.cc.t @@ -0,0 +1,122 @@ +//////////////////////////////////////////////////////////////////////////// +// pmt_@TAG@vector +//////////////////////////////////////////////////////////////////////////// + +namespace gruel { + +static pmt_@TAG@vector * +_@TAG@vector(pmt_t x) +{ + return dynamic_cast(x.get()); +} + + +pmt_@TAG@vector::pmt_@TAG@vector(size_t k, @TYPE@ fill) + : d_v(k) +{ + for (size_t i = 0; i < k; i++) + d_v[i] = fill; +} + +pmt_@TAG@vector::pmt_@TAG@vector(size_t k, const @TYPE@ *data) + : d_v(k) +{ + for (size_t i = 0; i < k; i++) + d_v[i] = data[i]; +} + +@TYPE@ +pmt_@TAG@vector::ref(size_t k) const +{ + if (k >= length()) + throw pmt_out_of_range("pmt_@TAG@vector_ref", pmt_from_long(k)); + return d_v[k]; +} + +void +pmt_@TAG@vector::set(size_t k, @TYPE@ x) +{ + if (k >= length()) + throw pmt_out_of_range("pmt_@TAG@vector_set", pmt_from_long(k)); + d_v[k] = x; +} + +const @TYPE@ * +pmt_@TAG@vector::elements(size_t &len) +{ + len = length(); + return &d_v[0]; +} + +@TYPE@ * +pmt_@TAG@vector::writable_elements(size_t &len) +{ + len = length(); + return &d_v[0]; +} + +const void* +pmt_@TAG@vector::uniform_elements(size_t &len) +{ + len = length() * sizeof(@TYPE@); + return &d_v[0]; +} + +void* +pmt_@TAG@vector::uniform_writable_elements(size_t &len) +{ + len = length() * sizeof(@TYPE@); + return &d_v[0]; +} + +bool +pmt_is_@TAG@vector(pmt_t obj) +{ + return obj->is_@TAG@vector(); +} + +pmt_t +pmt_make_@TAG@vector(size_t k, @TYPE@ fill) +{ + return pmt_t(new pmt_@TAG@vector(k, fill)); +} + +pmt_t +pmt_init_@TAG@vector(size_t k, const @TYPE@ *data) +{ + return pmt_t(new pmt_@TAG@vector(k, data)); +} + +@TYPE@ +pmt_@TAG@vector_ref(pmt_t vector, size_t k) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_ref", vector); + return _@TAG@vector(vector)->ref(k); +} + +void +pmt_@TAG@vector_set(pmt_t vector, size_t k, @TYPE@ obj) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_set", vector); + _@TAG@vector(vector)->set(k, obj); +} + +const @TYPE@ * +pmt_@TAG@vector_elements(pmt_t vector, size_t &len) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_elements", vector); + return _@TAG@vector(vector)->elements(len); +} + +@TYPE@ * +pmt_@TAG@vector_writable_elements(pmt_t vector, size_t &len) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_writable_elements", vector); + return _@TAG@vector(vector)->writable_elements(len); +} + +} /* namespace gruel */ diff --git a/gruel/src/lib/unv_template.h.t b/gruel/src/lib/unv_template.h.t new file mode 100644 index 000000000..83ba0be0f --- /dev/null +++ b/gruel/src/lib/unv_template.h.t @@ -0,0 +1,23 @@ + +//////////////////////////////////////////////////////////////////////////// +// pmt_@TAG@vector +//////////////////////////////////////////////////////////////////////////// + +class pmt_@TAG@vector : public pmt_uniform_vector +{ + std::vector< @TYPE@ > d_v; + +public: + pmt_@TAG@vector(size_t k, @TYPE@ fill); + pmt_@TAG@vector(size_t k, const @TYPE@ *data); + // ~pmt_@TAG@vector(); + + bool is_@TAG@vector() const { return true; } + size_t length() const { return d_v.size(); } + @TYPE@ ref(size_t k) const; + void set(size_t k, @TYPE@ x); + const @TYPE@ *elements(size_t &len); + @TYPE@ *writable_elements(size_t &len); + const void *uniform_elements(size_t &len); + void *uniform_writable_elements(size_t &len); +}; diff --git a/gruel/src/scheme/Makefile.am b/gruel/src/scheme/Makefile.am new file mode 100644 index 000000000..4980063d7 --- /dev/null +++ b/gruel/src/scheme/Makefile.am @@ -0,0 +1,21 @@ +# +# 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. +# + +SUBDIRS = gnuradio diff --git a/gruel/src/scheme/gnuradio/Makefile.am b/gruel/src/scheme/gnuradio/Makefile.am new file mode 100644 index 000000000..0ce01f6f8 --- /dev/null +++ b/gruel/src/scheme/gnuradio/Makefile.am @@ -0,0 +1,31 @@ +# +# 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. +# + +#pkgdatadir = $(datadir)/gnuradio + +EXTRA_DIST = \ + gen-serial-tags.scm + +# really scheme source files +dist_pkgdata_DATA = \ + pmt-serial-tags.scm \ + pmt-serialize.scm \ + macros-etc.scm + diff --git a/gruel/src/scheme/gnuradio/gen-serial-tags.scm b/gruel/src/scheme/gnuradio/gen-serial-tags.scm new file mode 100755 index 000000000..7b9087228 --- /dev/null +++ b/gruel/src/scheme/gnuradio/gen-serial-tags.scm @@ -0,0 +1,118 @@ +#!/usr/bin/guile \ +-e main -s +!# +;;; -*-scheme-*- +;;; +;;; 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. +;;; + +(use-modules (ice-9 format)) + +(defmacro when (pred . body) + `(if ,pred (begin ,@body) #f)) + +;; ---------------------------------------------------------------- + +(define (main args) + + (define (usage) + (format 0 + "usage: ~a ~%" + (car args))) + + (when (not (= (length args) 3)) + (usage) + (format 0 "args: ~s~%" args) + (exit 1)) + + (let ((i-file (open-input-file (cadr args))) + (h-file (open-output-file (caddr args)))) + + (write-header-comment h-file "// ") + (display "#ifndef INCLUDED_PMT_SERIAL_TAGS_H\n" h-file) + (display "#define INCLUDED_PMT_SERIAL_TAGS_H\n" h-file) + (newline h-file) + (display "enum pst_tags {\n" h-file) + + (for-each-in-file i-file + (lambda (form) + (let* ((name (cadr form)) + (c-name (string-upcase (c-ify name))) + (value (caddr form))) + ;;(format h-file "static const int ~a\t= 0x~x;~%" c-name value) + (format h-file " ~a\t= 0x~x,~%" c-name value)))) + + (display "};\n" h-file) + (display "#endif\n" h-file))) + +(define (c-ify name) + (list->string (map (lambda (c) + (if (eqv? c #\-) #\_ c)) + (string->list (symbol->string name))))) + + +(define (write-header-comment o-port prefix) + (for-each (lambda (comment) + (format o-port "~a~a~%" prefix comment)) + header-comment)) + +(define header-comment + '( + "" + "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." + "" + "" + "THIS FILE IS MACHINE GENERATED FROM pmt-serial-tags.scm. DO NOT EDIT BY HAND." + "See pmt-serial-tags.scm for additional commentary." + "")) + + + +(define (for-each-in-file file f) + (let ((port (if (port? file) + file + (open-input-file file)))) + (letrec + ((loop + (lambda (port form) + (cond ((eof-object? form) + (when (not (eq? port file)) + (close-input-port port)) + #t) + (else + (f form) + (set! form #f) ; for GC + (loop port (read port))))))) + (loop port (read port))))) diff --git a/gruel/src/scheme/gnuradio/macros-etc.scm b/gruel/src/scheme/gnuradio/macros-etc.scm new file mode 100644 index 000000000..ac2a4a342 --- /dev/null +++ b/gruel/src/scheme/gnuradio/macros-etc.scm @@ -0,0 +1,50 @@ +;;; -*- scheme -*- +;;; +;;; 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. +;;; + +(define-module (gnuradio macros-etc) + :export (atom? when unless for-each-in-file)) + +(define (atom? obj) + (not (pair? obj))) + +(defmacro when (pred . body) + `(if ,pred (begin ,@body) #f)) + +(defmacro unless (pred . body) + `(if (not ,pred) (begin ,@body) #f)) + + +(define (for-each-in-file file f) + (let ((port (if (port? file) + file + (open-input-file file)))) + (letrec + ((loop + (lambda (port form) + (cond ((eof-object? form) + (when (not (eq? port file)) + (close-input-port port)) + #t) + (else + (f form) + (set! form #f) ; for GC + (loop port (read port))))))) + (loop port (read port))))) diff --git a/gruel/src/scheme/gnuradio/pmt-serial-tags.scm b/gruel/src/scheme/gnuradio/pmt-serial-tags.scm new file mode 100644 index 000000000..646a751ea --- /dev/null +++ b/gruel/src/scheme/gnuradio/pmt-serial-tags.scm @@ -0,0 +1,75 @@ +;;; -*-scheme-*- +;;; +;;; 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 (define 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. +;;; + +;;; definitions of tag values used for marshalling pmt data + +(define pst-true #x00) +(define pst-false #x01) +(define pst-symbol #x02) ; untagged-int16 n; followed by n bytes of symbol name +(define pst-int32 #x03) +(define pst-double #x04) +(define pst-complex #x05) ; complex: real, imag +(define pst-null #x06) +(define pst-pair #x07) ; followed by two objects +(define pst-vector #x08) ; untagged-int32 n; followed by n objects +(define pst-dict #x09) ; untagged-int32 n; followed by n key/value tuples + +(define pst-uniform-vector #x0a) + +;; u8, s8, u16, s16, u32, s32, u64, s64, f32, f64, c32, c64 +;; +;; untagged-uint8 tag +;; untagged-uint8 uvi (define uniform vector info, see below) +;; untagged-int32 n-items +;; untagged-uint8 npad +;; npad bytes of zeros to align binary data +;; n-items binary numeric items +;; +;; uvi: +;; +-+-+-+-+-+-+-+-+ +;; |B| subtype | +;; +-+-+-+-+-+-+-+-+ +;; +;; B == 0, numeric data is little-endian. +;; B == 1, numeric data is big-endian. + + (define uvi-endian-mask #x80) + (define uvi-subtype-mask #x7f) + + (define uvi-little-endian #x00) + (define uvi-big-endian #x80) + + (define uvi-u8 #x00) + (define uvi-s8 #x01) + (define uvi-u16 #x02) + (define uvi-s16 #x03) + (define uvi-u32 #x04) + (define uvi-s32 #x05) + (define uvi-u64 #x06) + (define uvi-s64 #x07) + (define uvi-f32 #x08) + (define uvi-f64 #x09) + (define uvi-c32 #x0a) + (define uvi-c64 #x0b) + + +(define pst-comment #x3b) ; ascii ';' +(define pst-comment-end #x0a) ; ascii '\n' diff --git a/gruel/src/scheme/gnuradio/pmt-serialize.scm b/gruel/src/scheme/gnuradio/pmt-serialize.scm new file mode 100644 index 000000000..c1d32d75b --- /dev/null +++ b/gruel/src/scheme/gnuradio/pmt-serialize.scm @@ -0,0 +1,48 @@ +;;; +;;; 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. +;;; + +;;; An implementation of pmt_serialize in scheme. +;;; Currently handles only symbols and pairs. They're all we need for now. + +(define-module (gnuradio pmt-serialize) + :export (pmt-serialize)) + +(load-from-path "gnuradio/pmt-serial-tags") + +(define (pmt-serialize obj put-byte) + (define (put-u16 x) + (put-byte (logand (ash x -8) #xff)) + (put-byte (logand x #xff))) + + (cond ((null? obj) + (put-byte pst-null)) + ((symbol? obj) + (let* ((sym-as-bytes (map char->integer (string->list (symbol->string obj)))) + (len (length sym-as-bytes))) + (put-byte pst-symbol) + (put-u16 len) + (for-each put-byte sym-as-bytes))) + + ((pair? obj) + (put-byte pst-pair) + (pmt-serialize (car obj) put-byte) + (pmt-serialize (cdr obj) put-byte)) + (else + (throw 'not-implemented "pmt-serialize" obj)))) -- cgit From 4b4da4852482546157abbf8589f2a85bac6c3509 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 25 Jul 2009 17:39:00 +0000 Subject: Merge r11462:11485 from jcorgan/omni into trunk. Removes dependency on omnithreads from gnuradio-core. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11486 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/include/gruel/Makefile.am | 3 ++- gruel/src/include/gruel/thread.h | 34 +++++++++++++++++++++++++++ gruel/src/include/gruel/thread_body_wrapper.h | 4 ++-- gruel/src/include/gruel/thread_group.h | 4 ++-- 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 gruel/src/include/gruel/thread.h (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index d7354b871..622fbc2d3 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -34,4 +34,5 @@ gruelinclude_HEADERS = \ realtime.h \ sys_pri.h \ thread_body_wrapper.h \ - thread_group.h + thread_group.h \ + thread.h diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h new file mode 100644 index 000000000..0e7acaa85 --- /dev/null +++ b/gruel/src/include/gruel/thread.h @@ -0,0 +1,34 @@ +/* -*- 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_THREAD_H +#define INCLUDED_THREAD_H + +#include + +namespace gruel { + + typedef boost::mutex mutex; + typedef boost::unique_lock scoped_lock; + typedef boost::condition_variable condition_variable; + +} /* namespace gruel */ + +#endif /* INCLUDED_THREAD_H */ diff --git a/gruel/src/include/gruel/thread_body_wrapper.h b/gruel/src/include/gruel/thread_body_wrapper.h index 27dbbf7bb..b024bfdaf 100644 --- a/gruel/src/include/gruel/thread_body_wrapper.h +++ b/gruel/src/include/gruel/thread_body_wrapper.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -21,7 +21,7 @@ #ifndef INCLUDED_THREAD_BODY_WRAPPER_H #define INCLUDED_THREAD_BODY_WRAPPER_H -#include +#include #include #include diff --git a/gruel/src/include/gruel/thread_group.h b/gruel/src/include/gruel/thread_group.h index ae9a4250b..0270746e4 100644 --- a/gruel/src/include/gruel/thread_group.h +++ b/gruel/src/include/gruel/thread_group.h @@ -2,7 +2,7 @@ /* * Copyright (C) 2001-2003 William E. Kempf * Copyright (C) 2007 Anthony Williams - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -15,8 +15,8 @@ #ifndef INCLUDED_GRUEL_THREAD_GROUP_H #define INCLUDED_GRUEL_THREAD_GROUP_H +#include #include -#include #include #include -- cgit From 2bf2a8f2d2a4477818bfa91cae64fb663fdf88c3 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sun, 26 Jul 2009 20:01:02 +0000 Subject: Merged r11491:11494 from jcorgan/pmt into trunk. Moves pmt types functions into pmt:: from gruel:: Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11495 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/include/gruel/pmt.h | 4 +- gruel/src/include/gruel/pmt_pool.h | 4 +- gruel/src/lib/Makefile.am | 79 +-- gruel/src/lib/generate_unv.py | 190 ------ gruel/src/lib/pmt.cc | 1041 -------------------------------- gruel/src/lib/pmt/Makefile.am | 111 ++++ gruel/src/lib/pmt/generate_unv.py | 190 ++++++ gruel/src/lib/pmt/pmt.cc | 1041 ++++++++++++++++++++++++++++++++ gruel/src/lib/pmt/pmt_int.h | 227 +++++++ gruel/src/lib/pmt/pmt_io.cc | 141 +++++ gruel/src/lib/pmt/pmt_pool.cc | 112 ++++ gruel/src/lib/pmt/pmt_serialize.cc | 357 +++++++++++ gruel/src/lib/pmt/qa_pmt.cc | 40 ++ gruel/src/lib/pmt/qa_pmt.h | 36 ++ gruel/src/lib/pmt/qa_pmt_prims.cc | 438 ++++++++++++++ gruel/src/lib/pmt/qa_pmt_prims.h | 67 ++ gruel/src/lib/pmt/test_pmt.cc | 37 ++ gruel/src/lib/pmt/unv_qa_template.cc.t | 35 ++ gruel/src/lib/pmt/unv_template.cc.t | 122 ++++ gruel/src/lib/pmt/unv_template.h.t | 23 + gruel/src/lib/pmt_int.h | 227 ------- gruel/src/lib/pmt_io.cc | 141 ----- gruel/src/lib/pmt_pool.cc | 112 ---- gruel/src/lib/pmt_serialize.cc | 357 ----------- gruel/src/lib/qa_pmt.cc | 40 -- gruel/src/lib/qa_pmt.h | 36 -- gruel/src/lib/qa_pmt_prims.cc | 438 -------------- gruel/src/lib/qa_pmt_prims.h | 67 -- gruel/src/lib/test_pmt.cc | 37 -- gruel/src/lib/unv_qa_template.cc.t | 35 -- gruel/src/lib/unv_template.cc.t | 122 ---- gruel/src/lib/unv_template.h.t | 23 - 32 files changed, 2985 insertions(+), 2945 deletions(-) delete mode 100755 gruel/src/lib/generate_unv.py delete mode 100644 gruel/src/lib/pmt.cc create mode 100644 gruel/src/lib/pmt/Makefile.am create mode 100755 gruel/src/lib/pmt/generate_unv.py create mode 100644 gruel/src/lib/pmt/pmt.cc create mode 100644 gruel/src/lib/pmt/pmt_int.h create mode 100644 gruel/src/lib/pmt/pmt_io.cc create mode 100644 gruel/src/lib/pmt/pmt_pool.cc create mode 100644 gruel/src/lib/pmt/pmt_serialize.cc create mode 100644 gruel/src/lib/pmt/qa_pmt.cc create mode 100644 gruel/src/lib/pmt/qa_pmt.h create mode 100644 gruel/src/lib/pmt/qa_pmt_prims.cc create mode 100644 gruel/src/lib/pmt/qa_pmt_prims.h create mode 100644 gruel/src/lib/pmt/test_pmt.cc create mode 100644 gruel/src/lib/pmt/unv_qa_template.cc.t create mode 100644 gruel/src/lib/pmt/unv_template.cc.t create mode 100644 gruel/src/lib/pmt/unv_template.h.t delete mode 100644 gruel/src/lib/pmt_int.h delete mode 100644 gruel/src/lib/pmt_io.cc delete mode 100644 gruel/src/lib/pmt_pool.cc delete mode 100644 gruel/src/lib/pmt_serialize.cc delete mode 100644 gruel/src/lib/qa_pmt.cc delete mode 100644 gruel/src/lib/qa_pmt.h delete mode 100644 gruel/src/lib/qa_pmt_prims.cc delete mode 100644 gruel/src/lib/qa_pmt_prims.h delete mode 100644 gruel/src/lib/test_pmt.cc delete mode 100644 gruel/src/lib/unv_qa_template.cc.t delete mode 100644 gruel/src/lib/unv_template.cc.t delete mode 100644 gruel/src/lib/unv_template.h.t (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 6dc4508b1..de0998b5e 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -39,7 +39,7 @@ * exception that these objects are transparently reference counted. */ -namespace gruel { +namespace pmt { /*! * \brief base class of all pmt types @@ -677,6 +677,6 @@ pmt_t pmt_deserialize(std::streambuf &source); void pmt_dump_sizeof(); // debugging -} /* namespace gruel */ +} /* namespace pmt */ #endif /* INCLUDED_PMT_H */ diff --git a/gruel/src/include/gruel/pmt_pool.h b/gruel/src/include/gruel/pmt_pool.h index 18b498faa..b792523e0 100644 --- a/gruel/src/include/gruel/pmt_pool.h +++ b/gruel/src/include/gruel/pmt_pool.h @@ -25,7 +25,7 @@ #include #include -namespace gruel { +namespace pmt { /*! * \brief very simple thread-safe fixed-size allocation pool @@ -67,6 +67,6 @@ public: void free(void *p); }; -} /* namespace gruel */ +} /* namespace pmt */ #endif /* INCLUDED_PMT_POOL_H */ diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index 2a968d25f..bf1ae731a 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -21,9 +21,9 @@ include $(top_srcdir)/Makefile.common -AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) +SUBDIRS = pmt -TESTS = test_pmt +AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) lib_LTLIBRARIES = libgruel.la @@ -31,38 +31,11 @@ lib_LTLIBRARIES = libgruel.la libgruel_la_LDFLAGS = $(NO_UNDEFINED) $(BOOST_LDFLAGS) -version-info 0:0:0 # ---------------------------------------------------------------- -# these scripts generate code - -code_generator = \ - generate_unv.py \ - unv_template.h.t \ - unv_template.cc.t \ - unv_qa_template.cc.t - -GENERATED_H = \ - pmt_unv_int.h \ - qa_pmt_unv.h - -GENERATED_CC = \ - pmt_unv.cc \ - qa_pmt_unv.cc - -python_built_sources = $(GENERATED_H) $(GENERATED_CC) -PMT_SERIAL_TAGS_H = $(abs_top_builddir)/gruel/src/include/gruel/pmt_serial_tags.h -BUILT_SOURCES = $(python_built_sources) $(PMT_SERIAL_TAGS_H) - -EXTRA_DIST = $(code_generator) - -# ---------------------------------------------------------------- +PMT_LIB = pmt/libpmt.la # These are the source files that go into the gruel shared library libgruel_la_SOURCES = \ - pmt.cc \ - pmt_io.cc \ - pmt_pool.cc \ - pmt_serialize.cc \ - pmt_unv.cc \ realtime.cc \ sys_pri.cc \ thread_body_wrapper.cc \ @@ -70,51 +43,7 @@ libgruel_la_SOURCES = \ libgruel_la_LIBADD = \ $(BOOST_THREAD_LIB) \ + $(PMT_LIB) \ -lstdc++ -noinst_HEADERS = \ - $(GENERATED_H) \ - pmt_int.h \ - qa_pmt.h \ - qa_pmt_prims.h - -# Build the qa code into its own library - -noinst_LTLIBRARIES = libpmt-qa.la - -libpmt_qa_la_SOURCES = \ - qa_pmt.cc \ - qa_pmt_prims.cc \ - qa_pmt_unv.cc - -# magic flags -libpmt_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid version - -libpmt_qa_la_LIBADD = \ - libgruel.la \ - $(CPPUNIT_LIBS) \ - -lstdc++ - -noinst_PROGRAMS = \ - test_pmt - - -LIBGRUEL = libgruel.la -LIBPMTQA = libpmt-qa.la $(LIBGRUEL) - -test_pmt_SOURCES = test_pmt.cc -test_pmt_LDADD = $(LIBPMTQA) - -# Do creation and inclusion of other Makefiles last - -# common way for generating sources from templates when using -# BUILT_SOURCES, using parallel build protection. -gen_sources = $(python_built_sources) -gen_sources_deps = $(core_generator) -par_gen_command = PYTHONPATH=$(top_srcdir)/gruel/src/lib srcdir=$(srcdir) $(PYTHON) $(srcdir)/generate_unv.py -include $(top_srcdir)/Makefile.par.gen -# Rule to create the build header file using GUILE -# Doesn't need parallel protections because there is a single target -$(PMT_SERIAL_TAGS_H): $(srcdir)/../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../scheme/gnuradio/pmt-serial-tags.scm - $(RUN_GUILE) $(srcdir)/../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../scheme/gnuradio/pmt-serial-tags.scm $(PMT_SERIAL_TAGS_H) diff --git a/gruel/src/lib/generate_unv.py b/gruel/src/lib/generate_unv.py deleted file mode 100755 index 3a7305b40..000000000 --- a/gruel/src/lib/generate_unv.py +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env python -# -# 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. -# - -""" -Generate code for uniform numeric vectors -""" - -import re, os, os.path - - -unv_types = ( - ('u8', 'uint8_t'), - ('s8', 'int8_t'), - ('u16', 'uint16_t'), - ('s16', 'int16_t'), - ('u32', 'uint32_t'), - ('s32', 'int32_t'), - ('u64', 'uint64_t'), - ('s64', 'int64_t'), - ('f32', 'float'), - ('f64', 'double'), - ('c32', 'std::complex'), - ('c64', 'std::complex') - ) - -header = """\ -/* -*- 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. - */ -""" - -guard_tail = """ -#endif -""" - -includes = """ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include "pmt_int.h" -""" - -qa_includes = """ -#include -#include -#include -#include - -using namespace gruel; -""" - - -# set srcdir to the directory that contains Makefile.am -try: - srcdir = os.environ['srcdir'] -except KeyError, e: - srcdir = "." -srcdir = srcdir + '/' - - -def open_src (name, mode): - global srcdir - return open(os.path.join (srcdir, name), mode) - - -def guard_name(filename): - return 'INCLUDED_' + re.sub('\.', '_', filename.upper()) - -def guard_head(filename): - guard = guard_name(filename) - return """ -#ifndef %s -#define %s -""" % (guard, guard) - - -def do_substitution (d, input, out_file): - def repl (match_obj): - key = match_obj.group (1) - # print key - return d[key] - - out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, input) - out_file.write (out) - - -def generate_h(): - template = open_src('unv_template.h.t', 'r').read() - output_filename = 'pmt_unv_int.h' - output = open(output_filename, 'w') - output.write(header) - output.write(guard_head(output_filename)) - for tag, typ in unv_types: - d = { 'TAG' : tag, 'TYPE' : typ } - do_substitution(d, template, output) - output.write(guard_tail) - -def generate_cc(): - template = open_src('unv_template.cc.t', 'r').read() - output = open('pmt_unv.cc', 'w') - output.write(header) - output.write(includes) - for tag, typ in unv_types: - d = { 'TAG' : tag, 'TYPE' : typ } - do_substitution(d, template, output) - - -def generate_qa_h(): - output_filename = 'qa_pmt_unv.h' - output = open(output_filename, 'w') - output.write(header) - output.write(guard_head(output_filename)) - - output.write(''' -#include -#include - -class qa_pmt_unv : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_pmt_unv); -''') - for tag, typ in unv_types: - output.write(' CPPUNIT_TEST(test_%svector);\n' % (tag,)) - output.write('''\ - CPPUNIT_TEST_SUITE_END(); - - private: -''') - for tag, typ in unv_types: - output.write(' void test_%svector();\n' % (tag,)) - output.write('};\n') - output.write(guard_tail) - -def generate_qa_cc(): - template = open_src('unv_qa_template.cc.t', 'r').read() - output = open('qa_pmt_unv.cc', 'w') - output.write(header) - output.write(qa_includes) - for tag, typ in unv_types: - d = { 'TAG' : tag, 'TYPE' : typ } - do_substitution(d, template, output) - - -def main(): - generate_h() - generate_cc() - generate_qa_h() - generate_qa_cc() - -if __name__ == '__main__': - main() diff --git a/gruel/src/lib/pmt.cc b/gruel/src/lib/pmt.cc deleted file mode 100644 index 8e0c01625..000000000 --- a/gruel/src/lib/pmt.cc +++ /dev/null @@ -1,1041 +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. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include "pmt_int.h" -#include -#include -#include - -namespace gruel { - -static const int CACHE_LINE_SIZE = 64; // good guess - -# if (PMT_LOCAL_ALLOCATOR) - -static pmt_pool global_pmt_pool(sizeof(pmt_pair), CACHE_LINE_SIZE); - -void * -pmt_base::operator new(size_t size) -{ - void *p = global_pmt_pool.malloc(); - - // fprintf(stderr, "pmt_base::new p = %p\n", p); - assert((reinterpret_cast(p) & (CACHE_LINE_SIZE - 1)) == 0); - return p; -} - -void -pmt_base::operator delete(void *p, size_t size) -{ - global_pmt_pool.free(p); -} - -#endif - - -pmt_base::~pmt_base() -{ - // nop -- out of line virtual destructor -} - -//////////////////////////////////////////////////////////////////////////// -// Exceptions -//////////////////////////////////////////////////////////////////////////// - -pmt_exception::pmt_exception(const std::string &msg, pmt_t obj) - : logic_error(msg + ": " + pmt_write_string(obj)) -{ -} - -pmt_wrong_type::pmt_wrong_type(const std::string &msg, pmt_t obj) - : pmt_exception(msg + ": wrong_type ", obj) -{ -} - -pmt_out_of_range::pmt_out_of_range(const std::string &msg, pmt_t obj) - : pmt_exception(msg + ": out of range ", obj) -{ -} - -pmt_notimplemented::pmt_notimplemented(const std::string &msg, pmt_t obj) - : pmt_exception(msg + ": notimplemented ", obj) -{ -} - -//////////////////////////////////////////////////////////////////////////// -// Dynamic Casts -//////////////////////////////////////////////////////////////////////////// - -static pmt_symbol * -_symbol(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -static pmt_integer * -_integer(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -static pmt_real * -_real(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -static pmt_complex * -_complex(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -static pmt_pair * -_pair(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -static pmt_vector * -_vector(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -static pmt_uniform_vector * -_uniform_vector(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -static pmt_dict * -_dict(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -static pmt_any * -_any(pmt_t x) -{ - return dynamic_cast(x.get()); -} - -//////////////////////////////////////////////////////////////////////////// -// Globals -//////////////////////////////////////////////////////////////////////////// - -const pmt_t PMT_T = pmt_t(new pmt_bool()); // singleton -const pmt_t PMT_F = pmt_t(new pmt_bool()); // singleton -const pmt_t PMT_NIL = pmt_t(new pmt_null()); // singleton -const pmt_t PMT_EOF = pmt_cons(PMT_NIL, PMT_NIL); // singleton - -//////////////////////////////////////////////////////////////////////////// -// Booleans -//////////////////////////////////////////////////////////////////////////// - -pmt_bool::pmt_bool(){} - -bool -pmt_is_true(pmt_t obj) -{ - return obj != PMT_F; -} - -bool -pmt_is_false(pmt_t obj) -{ - return obj == PMT_F; -} - -bool -pmt_is_bool(pmt_t obj) -{ - return obj->is_bool(); -} - -pmt_t -pmt_from_bool(bool val) -{ - return val ? PMT_T : PMT_F; -} - -bool -pmt_to_bool(pmt_t val) -{ - if (val == PMT_T) - return true; - if (val == PMT_F) - return false; - throw pmt_wrong_type("pmt_to_bool", val); -} - -//////////////////////////////////////////////////////////////////////////// -// Symbols -//////////////////////////////////////////////////////////////////////////// - -static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701; -static std::vector s_symbol_hash_table(SYMBOL_HASH_TABLE_SIZE); - -pmt_symbol::pmt_symbol(const std::string &name) : d_name(name){} - - -static unsigned int -hash_string(const std::string &s) -{ - unsigned int h = 0; - unsigned int g = 0; - - for (std::string::const_iterator p = s.begin(); p != s.end(); ++p){ - h = (h << 4) + (*p & 0xff); - g = h & 0xf0000000; - if (g){ - h = h ^ (g >> 24); - h = h ^ g; - } - } - return h; -} - -bool -pmt_is_symbol(const pmt_t& obj) -{ - return obj->is_symbol(); -} - -pmt_t -pmt_string_to_symbol(const std::string &name) -{ - unsigned hash = hash_string(name) % SYMBOL_HASH_TABLE_SIZE; - - // Does a symbol with this name already exist? - for (pmt_t sym = s_symbol_hash_table[hash]; sym; sym = _symbol(sym)->next()){ - if (name == _symbol(sym)->name()) - return sym; // Yes. Return it - } - - // Nope. Make a new one. - pmt_t sym = pmt_t(new pmt_symbol(name)); - _symbol(sym)->set_next(s_symbol_hash_table[hash]); - s_symbol_hash_table[hash] = sym; - return sym; -} - -// alias... -pmt_t -pmt_intern(const std::string &name) -{ - return pmt_string_to_symbol(name); -} - -const std::string -pmt_symbol_to_string(const pmt_t& sym) -{ - if (!sym->is_symbol()) - throw pmt_wrong_type("pmt_symbol_to_string", sym); - - return _symbol(sym)->name(); -} - - - -//////////////////////////////////////////////////////////////////////////// -// Number -//////////////////////////////////////////////////////////////////////////// - -bool -pmt_is_number(pmt_t x) -{ - return x->is_number(); -} - -//////////////////////////////////////////////////////////////////////////// -// Integer -//////////////////////////////////////////////////////////////////////////// - -pmt_integer::pmt_integer(long value) : d_value(value) {} - -bool -pmt_is_integer(pmt_t x) -{ - return x->is_integer(); -} - - -pmt_t -pmt_from_long(long x) -{ - return pmt_t(new pmt_integer(x)); -} - -long -pmt_to_long(pmt_t x) -{ - pmt_integer* i = dynamic_cast(x.get()); - if ( i ) - return i->value(); - - throw pmt_wrong_type("pmt_to_long", x); -} - -//////////////////////////////////////////////////////////////////////////// -// Real -//////////////////////////////////////////////////////////////////////////// - -pmt_real::pmt_real(double value) : d_value(value) {} - -bool -pmt_is_real(pmt_t x) -{ - return x->is_real(); -} - -pmt_t -pmt_from_double(double x) -{ - return pmt_t(new pmt_real(x)); -} - -double -pmt_to_double(pmt_t x) -{ - if (x->is_real()) - return _real(x)->value(); - if (x->is_integer()) - return _integer(x)->value(); - - throw pmt_wrong_type("pmt_to_double", x); -} - -//////////////////////////////////////////////////////////////////////////// -// Complex -//////////////////////////////////////////////////////////////////////////// - -pmt_complex::pmt_complex(std::complex value) : d_value(value) {} - -bool -pmt_is_complex(pmt_t x) -{ - return x->is_complex(); -} - -pmt_t -pmt_make_rectangular(double re, double im) -{ - return pmt_t(new pmt_complex(std::complex(re, im))); -} - -std::complex -pmt_to_complex(pmt_t x) -{ - if (x->is_complex()) - return _complex(x)->value(); - if (x->is_real()) - return _real(x)->value(); - if (x->is_integer()) - return _integer(x)->value(); - - throw pmt_wrong_type("pmt_to_complex", x); -} - -//////////////////////////////////////////////////////////////////////////// -// Pairs -//////////////////////////////////////////////////////////////////////////// - -pmt_null::pmt_null() {} -pmt_pair::pmt_pair(const pmt_t& car, const pmt_t& cdr) : d_car(car), d_cdr(cdr) {} - -bool -pmt_is_null(const pmt_t& x) -{ - return x == PMT_NIL; -} - -bool -pmt_is_pair(const pmt_t& obj) -{ - return obj->is_pair(); -} - -pmt_t -pmt_cons(const pmt_t& x, const pmt_t& y) -{ - return pmt_t(new pmt_pair(x, y)); -} - -pmt_t -pmt_car(const pmt_t& pair) -{ - pmt_pair* p = dynamic_cast(pair.get()); - if ( p ) - return p->car(); - - throw pmt_wrong_type("pmt_car", pair); -} - -pmt_t -pmt_cdr(const pmt_t& pair) -{ - pmt_pair* p = dynamic_cast(pair.get()); - if ( p ) - return p->cdr(); - - throw pmt_wrong_type("pmt_cdr", pair); -} - -void -pmt_set_car(pmt_t pair, pmt_t obj) -{ - if (pair->is_pair()) - _pair(pair)->set_car(obj); - else - throw pmt_wrong_type("pmt_set_car", pair); -} - -void -pmt_set_cdr(pmt_t pair, pmt_t obj) -{ - if (pair->is_pair()) - _pair(pair)->set_cdr(obj); - else - throw pmt_wrong_type("pmt_set_cdr", pair); -} - -//////////////////////////////////////////////////////////////////////////// -// Vectors -//////////////////////////////////////////////////////////////////////////// - -pmt_vector::pmt_vector(size_t len, pmt_t fill) - : d_v(len) -{ - for (size_t i = 0; i < len; i++) - d_v[i] = fill; -} - -pmt_t -pmt_vector::ref(size_t k) const -{ - if (k >= length()) - throw pmt_out_of_range("pmt_vector_ref", pmt_from_long(k)); - return d_v[k]; -} - -void -pmt_vector::set(size_t k, pmt_t obj) -{ - if (k >= length()) - throw pmt_out_of_range("pmt_vector_set", pmt_from_long(k)); - d_v[k] = obj; -} - -void -pmt_vector::fill(pmt_t obj) -{ - for (size_t i = 0; i < length(); i++) - d_v[i] = obj; -} - -bool -pmt_is_vector(pmt_t obj) -{ - return obj->is_vector(); -} - -pmt_t -pmt_make_vector(size_t k, pmt_t fill) -{ - return pmt_t(new pmt_vector(k, fill)); -} - -pmt_t -pmt_vector_ref(pmt_t vector, size_t k) -{ - if (!vector->is_vector()) - throw pmt_wrong_type("pmt_vector_ref", vector); - return _vector(vector)->ref(k); -} - -void -pmt_vector_set(pmt_t vector, size_t k, pmt_t obj) -{ - if (!vector->is_vector()) - throw pmt_wrong_type("pmt_vector_set", vector); - _vector(vector)->set(k, obj); -} - -void -pmt_vector_fill(pmt_t vector, pmt_t obj) -{ - if (!vector->is_vector()) - throw pmt_wrong_type("pmt_vector_set", vector); - _vector(vector)->fill(obj); -} - -//////////////////////////////////////////////////////////////////////////// -// Uniform Numeric Vectors -//////////////////////////////////////////////////////////////////////////// - -bool -pmt_is_uniform_vector(pmt_t x) -{ - return x->is_uniform_vector(); -} - -const void * -pmt_uniform_vector_elements(pmt_t vector, size_t &len) -{ - if (!vector->is_uniform_vector()) - throw pmt_wrong_type("pmt_uniform_vector_elements", vector); - return _uniform_vector(vector)->uniform_elements(len); -} - -void * -pmt_uniform_vector_writable_elements(pmt_t vector, size_t &len) -{ - if (!vector->is_uniform_vector()) - throw pmt_wrong_type("pmt_uniform_vector_writable_elements", vector); - return _uniform_vector(vector)->uniform_writable_elements(len); -} - -//////////////////////////////////////////////////////////////////////////// -// Dictionaries -//////////////////////////////////////////////////////////////////////////// - -pmt_dict::pmt_dict() - : d_alist(PMT_NIL) -{ -} - -void -pmt_dict::set(pmt_t key, pmt_t value) -{ - pmt_t p = pmt_assv(key, d_alist); // look for (key . value) pair - if (pmt_is_pair(p)){ // found existing pair... - pmt_set_cdr(p, value); // overrwrite cdr with new value - } - else { // not in the dict - d_alist = pmt_cons(pmt_cons(key, value), d_alist); // add new (key . value) pair - } -} - -pmt_t -pmt_dict::ref(pmt_t key, pmt_t not_found) const -{ - pmt_t p = pmt_assv(key, d_alist); // look for (key . value) pair - if (pmt_is_pair(p)) - return pmt_cdr(p); - else - return not_found; -} - -bool -pmt_dict::has_key(pmt_t key) const -{ - return pmt_is_pair(pmt_assv(key, d_alist)); -} - -pmt_t -pmt_dict::items() const -{ - return d_alist; -} - -pmt_t -pmt_dict::keys() const -{ - return pmt_map(pmt_car, d_alist); -} - -pmt_t -pmt_dict::values() const -{ - return pmt_map(pmt_cdr, d_alist); -} - -bool -pmt_is_dict(pmt_t obj) -{ - return obj->is_dict(); -} - -pmt_t -pmt_make_dict() -{ - return pmt_t(new pmt_dict()); -} - -void -pmt_dict_set(pmt_t dict, pmt_t key, pmt_t value) -{ - pmt_dict* d = _dict(dict); - if (!d) - throw pmt_wrong_type("pmt_dict_set", dict); - - d->set(key, value); -} - -bool -pmt_dict_has_key(pmt_t dict, pmt_t key) -{ - pmt_dict* d = _dict(dict); - if (!d) - throw pmt_wrong_type("pmt_dict_has_key", dict); - - return d->has_key(key); -} - -pmt_t -pmt_dict_ref(pmt_t dict, pmt_t key, pmt_t not_found) -{ - pmt_dict* d = _dict(dict); - if (!d) - throw pmt_wrong_type("pmt_dict_ref", dict); - - return d->ref(key, not_found); -} - -pmt_t -pmt_dict_items(pmt_t dict) -{ - if (!dict->is_dict()) - throw pmt_wrong_type("pmt_dict_items", dict); - - return _dict(dict)->items(); -} - -pmt_t -pmt_dict_keys(pmt_t dict) -{ - if (!dict->is_dict()) - throw pmt_wrong_type("pmt_dict_keys", dict); - - return _dict(dict)->keys(); -} - -pmt_t -pmt_dict_values(pmt_t dict) -{ - if (!dict->is_dict()) - throw pmt_wrong_type("pmt_dict_values", dict); - - return _dict(dict)->values(); -} - -//////////////////////////////////////////////////////////////////////////// -// Any -//////////////////////////////////////////////////////////////////////////// - -pmt_any::pmt_any(const boost::any &any) : d_any(any) {} - -bool -pmt_is_any(pmt_t obj) -{ - return obj->is_any(); -} - -pmt_t -pmt_make_any(const boost::any &any) -{ - return pmt_t(new pmt_any(any)); -} - -boost::any -pmt_any_ref(pmt_t obj) -{ - if (!obj->is_any()) - throw pmt_wrong_type("pmt_any_ref", obj); - return _any(obj)->ref(); -} - -void -pmt_any_set(pmt_t obj, const boost::any &any) -{ - if (!obj->is_any()) - throw pmt_wrong_type("pmt_any_set", obj); - _any(obj)->set(any); -} - -//////////////////////////////////////////////////////////////////////////// -// General Functions -//////////////////////////////////////////////////////////////////////////// - -bool -pmt_eq(const pmt_t& x, const pmt_t& y) -{ - return x == y; -} - -bool -pmt_eqv(const pmt_t& x, const pmt_t& y) -{ - if (x == y) - return true; - - if (x->is_integer() && y->is_integer()) - return _integer(x)->value() == _integer(y)->value(); - - if (x->is_real() && y->is_real()) - return _real(x)->value() == _real(y)->value(); - - if (x->is_complex() && y->is_complex()) - return _complex(x)->value() == _complex(y)->value(); - - return false; -} - -bool -pmt_equal(const pmt_t& x, const pmt_t& y) -{ - if (pmt_eqv(x, y)) - return true; - - if (x->is_pair() && y->is_pair()) - return pmt_equal(pmt_car(x), pmt_car(y)) && pmt_equal(pmt_cdr(x), pmt_cdr(y)); - - if (x->is_vector() && y->is_vector()){ - pmt_vector *xv = _vector(x); - pmt_vector *yv = _vector(y); - if (xv->length() != yv->length()) - return false; - - for (unsigned i = 0; i < xv->length(); i++) - if (!pmt_equal(xv->_ref(i), yv->_ref(i))) - return false; - - return true; - } - - if (x->is_uniform_vector() && y->is_uniform_vector()){ - pmt_uniform_vector *xv = _uniform_vector(x); - pmt_uniform_vector *yv = _uniform_vector(y); - if (xv->length() != yv->length()) - return false; - - size_t len_x, len_y; - if (memcmp(xv->uniform_elements(len_x), - yv->uniform_elements(len_y), - len_x) == 0) - return true; - - return true; - } - - // FIXME add other cases here... - - return false; -} - -size_t -pmt_length(const pmt_t& x) -{ - if (x->is_vector()) - return _vector(x)->length(); - - if (x->is_uniform_vector()) - return _uniform_vector(x)->length(); - - if (x->is_null()) return 0; - - if (x->is_pair()) { - size_t length=1; - pmt_t it = pmt_cdr(x); - while (pmt_is_pair(it)){ - length++; - it = pmt_cdr(it); - } - if (pmt_is_null(it)) - return length; - - // not a proper list - throw pmt_wrong_type("pmt_length", x); - } - - // FIXME dictionary length (number of entries) - - throw pmt_wrong_type("pmt_length", x); -} - -pmt_t -pmt_assq(pmt_t obj, pmt_t alist) -{ - while (pmt_is_pair(alist)){ - pmt_t p = pmt_car(alist); - if (!pmt_is_pair(p)) // malformed alist - return PMT_F; - - if (pmt_eq(obj, pmt_car(p))) - return p; - - alist = pmt_cdr(alist); - } - return PMT_F; -} - -pmt_t -pmt_assv(pmt_t obj, pmt_t alist) -{ - while (pmt_is_pair(alist)){ - pmt_t p = pmt_car(alist); - if (!pmt_is_pair(p)) // malformed alist - return PMT_F; - - if (pmt_eqv(obj, pmt_car(p))) - return p; - - alist = pmt_cdr(alist); - } - return PMT_F; -} - -pmt_t -pmt_assoc(pmt_t obj, pmt_t alist) -{ - while (pmt_is_pair(alist)){ - pmt_t p = pmt_car(alist); - if (!pmt_is_pair(p)) // malformed alist - return PMT_F; - - if (pmt_equal(obj, pmt_car(p))) - return p; - - alist = pmt_cdr(alist); - } - return PMT_F; -} - -pmt_t -pmt_map(pmt_t proc(const pmt_t&), pmt_t list) -{ - pmt_t r = PMT_NIL; - - while(pmt_is_pair(list)){ - r = pmt_cons(proc(pmt_car(list)), r); - list = pmt_cdr(list); - } - - return pmt_reverse_x(r); -} - -pmt_t -pmt_reverse(pmt_t listx) -{ - pmt_t list = listx; - pmt_t r = PMT_NIL; - - while(pmt_is_pair(list)){ - r = pmt_cons(pmt_car(list), r); - list = pmt_cdr(list); - } - if (pmt_is_null(list)) - return r; - else - throw pmt_wrong_type("pmt_reverse", listx); -} - -pmt_t -pmt_reverse_x(pmt_t list) -{ - // FIXME do it destructively - return pmt_reverse(list); -} - -pmt_t -pmt_nth(size_t n, pmt_t list) -{ - pmt_t t = pmt_nthcdr(n, list); - if (pmt_is_pair(t)) - return pmt_car(t); - else - return PMT_NIL; -} - -pmt_t -pmt_nthcdr(size_t n, pmt_t list) -{ - if (!(pmt_is_pair(list) || pmt_is_null(list))) - throw pmt_wrong_type("pmt_nthcdr", list); - - while (n > 0){ - if (pmt_is_pair(list)){ - list = pmt_cdr(list); - n--; - continue; - } - if (pmt_is_null(list)) - return PMT_NIL; - else - throw pmt_wrong_type("pmt_nthcdr: not a LIST", list); - } - return list; -} - -pmt_t -pmt_memq(pmt_t obj, pmt_t list) -{ - while (pmt_is_pair(list)){ - if (pmt_eq(obj, pmt_car(list))) - return list; - list = pmt_cdr(list); - } - return PMT_F; -} - -pmt_t -pmt_memv(pmt_t obj, pmt_t list) -{ - while (pmt_is_pair(list)){ - if (pmt_eqv(obj, pmt_car(list))) - return list; - list = pmt_cdr(list); - } - return PMT_F; -} - -pmt_t -pmt_member(pmt_t obj, pmt_t list) -{ - while (pmt_is_pair(list)){ - if (pmt_equal(obj, pmt_car(list))) - return list; - list = pmt_cdr(list); - } - return PMT_F; -} - -bool -pmt_subsetp(pmt_t list1, pmt_t list2) -{ - while (pmt_is_pair(list1)){ - pmt_t p = pmt_car(list1); - if (pmt_is_false(pmt_memv(p, list2))) - return false; - list1 = pmt_cdr(list1); - } - return true; -} - -pmt_t -pmt_list1(const pmt_t& x1) -{ - return pmt_cons(x1, PMT_NIL); -} - -pmt_t -pmt_list2(const pmt_t& x1, const pmt_t& x2) -{ - return pmt_cons(x1, pmt_cons(x2, PMT_NIL)); -} - -pmt_t -pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3) -{ - return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, PMT_NIL))); -} - -pmt_t -pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4) -{ - return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, PMT_NIL)))); -} - -pmt_t -pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5) -{ - return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, pmt_cons(x5, PMT_NIL))))); -} - -pmt_t -pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6) -{ - return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, pmt_cons(x5, pmt_cons(x6, PMT_NIL)))))); -} - -pmt_t -pmt_list_add(pmt_t list, const pmt_t& item) -{ - return pmt_reverse(pmt_cons(item, pmt_reverse(list))); -} - -pmt_t -pmt_caar(pmt_t pair) -{ - return (pmt_car(pmt_car(pair))); -} - -pmt_t -pmt_cadr(pmt_t pair) -{ - return pmt_car(pmt_cdr(pair)); -} - -pmt_t -pmt_cdar(pmt_t pair) -{ - return pmt_cdr(pmt_car(pair)); -} - -pmt_t -pmt_cddr(pmt_t pair) -{ - return pmt_cdr(pmt_cdr(pair)); -} - -pmt_t -pmt_caddr(pmt_t pair) -{ - return pmt_car(pmt_cdr(pmt_cdr(pair))); -} - -pmt_t -pmt_cadddr(pmt_t pair) -{ - return pmt_car(pmt_cdr(pmt_cdr(pmt_cdr(pair)))); -} - -bool -pmt_is_eof_object(pmt_t obj) -{ - return pmt_eq(obj, PMT_EOF); -} - -void -pmt_dump_sizeof() -{ - printf("sizeof(pmt_t) = %3zd\n", sizeof(pmt_t)); - printf("sizeof(pmt_base) = %3zd\n", sizeof(pmt_base)); - printf("sizeof(pmt_bool) = %3zd\n", sizeof(pmt_bool)); - printf("sizeof(pmt_symbol) = %3zd\n", sizeof(pmt_symbol)); - printf("sizeof(pmt_integer) = %3zd\n", sizeof(pmt_integer)); - printf("sizeof(pmt_real) = %3zd\n", sizeof(pmt_real)); - printf("sizeof(pmt_complex) = %3zd\n", sizeof(pmt_complex)); - printf("sizeof(pmt_null) = %3zd\n", sizeof(pmt_null)); - printf("sizeof(pmt_pair) = %3zd\n", sizeof(pmt_pair)); - printf("sizeof(pmt_vector) = %3zd\n", sizeof(pmt_vector)); - printf("sizeof(pmt_dict) = %3zd\n", sizeof(pmt_dict)); - printf("sizeof(pmt_uniform_vector) = %3zd\n", sizeof(pmt_uniform_vector)); -} - -} /* namespace gruel */ diff --git a/gruel/src/lib/pmt/Makefile.am b/gruel/src/lib/pmt/Makefile.am new file mode 100644 index 000000000..5e9f2fac9 --- /dev/null +++ b/gruel/src/lib/pmt/Makefile.am @@ -0,0 +1,111 @@ +# +# Copyright 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) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) + +TESTS = test_pmt + +noinst_LTLIBRARIES = libpmt.la + +# ---------------------------------------------------------------- +# these scripts generate code + +code_generator = \ + generate_unv.py \ + unv_template.h.t \ + unv_template.cc.t \ + unv_qa_template.cc.t + +GENERATED_H = \ + pmt_unv_int.h \ + qa_pmt_unv.h + +GENERATED_CC = \ + pmt_unv.cc \ + qa_pmt_unv.cc + +python_built_sources = $(GENERATED_H) $(GENERATED_CC) + +PMT_SERIAL_TAGS_H = $(abs_top_builddir)/gruel/src/include/gruel/pmt_serial_tags.h +BUILT_SOURCES = $(python_built_sources) $(PMT_SERIAL_TAGS_H) + +EXTRA_DIST = $(code_generator) + +# ---------------------------------------------------------------- + +libpmt_la_SOURCES = \ + pmt.cc \ + pmt_io.cc \ + pmt_pool.cc \ + pmt_serialize.cc \ + pmt_unv.cc + +libpmt_la_LIBADD = \ + $(BOOST_THREAD_LIB) \ + -lstdc++ + +noinst_HEADERS = \ + $(GENERATED_H) \ + pmt_int.h \ + qa_pmt.h \ + qa_pmt_prims.h + +# Build the qa code into its own library + +noinst_LTLIBRARIES += libpmt-qa.la + +libpmt_qa_la_SOURCES = \ + qa_pmt.cc \ + qa_pmt_prims.cc \ + qa_pmt_unv.cc + +# magic flags +libpmt_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid version + +libpmt_qa_la_LIBADD = \ + libpmt.la \ + $(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 + +# common way for generating sources from templates when using +# BUILT_SOURCES, using parallel build protection. +gen_sources = $(python_built_sources) +gen_sources_deps = $(core_generator) +par_gen_command = PYTHONPATH=$(top_srcdir)/gruel/src/lib/pmt srcdir=$(srcdir) $(PYTHON) $(srcdir)/generate_unv.py +include $(top_srcdir)/Makefile.par.gen + +# Rule to create the build header file using GUILE +# Doesn't need parallel protections because there is a single target +$(PMT_SERIAL_TAGS_H): $(srcdir)/../../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../../scheme/gnuradio/pmt-serial-tags.scm + $(RUN_GUILE) $(srcdir)/../../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../../scheme/gnuradio/pmt-serial-tags.scm $(PMT_SERIAL_TAGS_H) diff --git a/gruel/src/lib/pmt/generate_unv.py b/gruel/src/lib/pmt/generate_unv.py new file mode 100755 index 000000000..02aace250 --- /dev/null +++ b/gruel/src/lib/pmt/generate_unv.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python +# +# 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. +# + +""" +Generate code for uniform numeric vectors +""" + +import re, os, os.path + + +unv_types = ( + ('u8', 'uint8_t'), + ('s8', 'int8_t'), + ('u16', 'uint16_t'), + ('s16', 'int16_t'), + ('u32', 'uint32_t'), + ('s32', 'int32_t'), + ('u64', 'uint64_t'), + ('s64', 'int64_t'), + ('f32', 'float'), + ('f64', 'double'), + ('c32', 'std::complex'), + ('c64', 'std::complex') + ) + +header = """\ +/* -*- 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. + */ +""" + +guard_tail = """ +#endif +""" + +includes = """ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include "pmt_int.h" +""" + +qa_includes = """ +#include +#include +#include +#include + +using namespace pmt; +""" + + +# set srcdir to the directory that contains Makefile.am +try: + srcdir = os.environ['srcdir'] +except KeyError, e: + srcdir = "." +srcdir = srcdir + '/' + + +def open_src (name, mode): + global srcdir + return open(os.path.join (srcdir, name), mode) + + +def guard_name(filename): + return 'INCLUDED_' + re.sub('\.', '_', filename.upper()) + +def guard_head(filename): + guard = guard_name(filename) + return """ +#ifndef %s +#define %s +""" % (guard, guard) + + +def do_substitution (d, input, out_file): + def repl (match_obj): + key = match_obj.group (1) + # print key + return d[key] + + out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, input) + out_file.write (out) + + +def generate_h(): + template = open_src('unv_template.h.t', 'r').read() + output_filename = 'pmt_unv_int.h' + output = open(output_filename, 'w') + output.write(header) + output.write(guard_head(output_filename)) + for tag, typ in unv_types: + d = { 'TAG' : tag, 'TYPE' : typ } + do_substitution(d, template, output) + output.write(guard_tail) + +def generate_cc(): + template = open_src('unv_template.cc.t', 'r').read() + output = open('pmt_unv.cc', 'w') + output.write(header) + output.write(includes) + for tag, typ in unv_types: + d = { 'TAG' : tag, 'TYPE' : typ } + do_substitution(d, template, output) + + +def generate_qa_h(): + output_filename = 'qa_pmt_unv.h' + output = open(output_filename, 'w') + output.write(header) + output.write(guard_head(output_filename)) + + output.write(''' +#include +#include + +class qa_pmt_unv : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE(qa_pmt_unv); +''') + for tag, typ in unv_types: + output.write(' CPPUNIT_TEST(test_%svector);\n' % (tag,)) + output.write('''\ + CPPUNIT_TEST_SUITE_END(); + + private: +''') + for tag, typ in unv_types: + output.write(' void test_%svector();\n' % (tag,)) + output.write('};\n') + output.write(guard_tail) + +def generate_qa_cc(): + template = open_src('unv_qa_template.cc.t', 'r').read() + output = open('qa_pmt_unv.cc', 'w') + output.write(header) + output.write(qa_includes) + for tag, typ in unv_types: + d = { 'TAG' : tag, 'TYPE' : typ } + do_substitution(d, template, output) + + +def main(): + generate_h() + generate_cc() + generate_qa_h() + generate_qa_cc() + +if __name__ == '__main__': + main() diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc new file mode 100644 index 000000000..fbf557be1 --- /dev/null +++ b/gruel/src/lib/pmt/pmt.cc @@ -0,0 +1,1041 @@ +/* -*- 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. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include "pmt_int.h" +#include +#include +#include + +namespace pmt { + +static const int CACHE_LINE_SIZE = 64; // good guess + +# if (PMT_LOCAL_ALLOCATOR) + +static pmt_pool global_pmt_pool(sizeof(pmt_pair), CACHE_LINE_SIZE); + +void * +pmt_base::operator new(size_t size) +{ + void *p = global_pmt_pool.malloc(); + + // fprintf(stderr, "pmt_base::new p = %p\n", p); + assert((reinterpret_cast(p) & (CACHE_LINE_SIZE - 1)) == 0); + return p; +} + +void +pmt_base::operator delete(void *p, size_t size) +{ + global_pmt_pool.free(p); +} + +#endif + + +pmt_base::~pmt_base() +{ + // nop -- out of line virtual destructor +} + +//////////////////////////////////////////////////////////////////////////// +// Exceptions +//////////////////////////////////////////////////////////////////////////// + +pmt_exception::pmt_exception(const std::string &msg, pmt_t obj) + : logic_error(msg + ": " + pmt_write_string(obj)) +{ +} + +pmt_wrong_type::pmt_wrong_type(const std::string &msg, pmt_t obj) + : pmt_exception(msg + ": wrong_type ", obj) +{ +} + +pmt_out_of_range::pmt_out_of_range(const std::string &msg, pmt_t obj) + : pmt_exception(msg + ": out of range ", obj) +{ +} + +pmt_notimplemented::pmt_notimplemented(const std::string &msg, pmt_t obj) + : pmt_exception(msg + ": notimplemented ", obj) +{ +} + +//////////////////////////////////////////////////////////////////////////// +// Dynamic Casts +//////////////////////////////////////////////////////////////////////////// + +static pmt_symbol * +_symbol(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_integer * +_integer(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_real * +_real(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_complex * +_complex(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_pair * +_pair(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_vector * +_vector(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_uniform_vector * +_uniform_vector(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_dict * +_dict(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +static pmt_any * +_any(pmt_t x) +{ + return dynamic_cast(x.get()); +} + +//////////////////////////////////////////////////////////////////////////// +// Globals +//////////////////////////////////////////////////////////////////////////// + +const pmt_t PMT_T = pmt_t(new pmt_bool()); // singleton +const pmt_t PMT_F = pmt_t(new pmt_bool()); // singleton +const pmt_t PMT_NIL = pmt_t(new pmt_null()); // singleton +const pmt_t PMT_EOF = pmt_cons(PMT_NIL, PMT_NIL); // singleton + +//////////////////////////////////////////////////////////////////////////// +// Booleans +//////////////////////////////////////////////////////////////////////////// + +pmt_bool::pmt_bool(){} + +bool +pmt_is_true(pmt_t obj) +{ + return obj != PMT_F; +} + +bool +pmt_is_false(pmt_t obj) +{ + return obj == PMT_F; +} + +bool +pmt_is_bool(pmt_t obj) +{ + return obj->is_bool(); +} + +pmt_t +pmt_from_bool(bool val) +{ + return val ? PMT_T : PMT_F; +} + +bool +pmt_to_bool(pmt_t val) +{ + if (val == PMT_T) + return true; + if (val == PMT_F) + return false; + throw pmt_wrong_type("pmt_to_bool", val); +} + +//////////////////////////////////////////////////////////////////////////// +// Symbols +//////////////////////////////////////////////////////////////////////////// + +static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701; +static std::vector s_symbol_hash_table(SYMBOL_HASH_TABLE_SIZE); + +pmt_symbol::pmt_symbol(const std::string &name) : d_name(name){} + + +static unsigned int +hash_string(const std::string &s) +{ + unsigned int h = 0; + unsigned int g = 0; + + for (std::string::const_iterator p = s.begin(); p != s.end(); ++p){ + h = (h << 4) + (*p & 0xff); + g = h & 0xf0000000; + if (g){ + h = h ^ (g >> 24); + h = h ^ g; + } + } + return h; +} + +bool +pmt_is_symbol(const pmt_t& obj) +{ + return obj->is_symbol(); +} + +pmt_t +pmt_string_to_symbol(const std::string &name) +{ + unsigned hash = hash_string(name) % SYMBOL_HASH_TABLE_SIZE; + + // Does a symbol with this name already exist? + for (pmt_t sym = s_symbol_hash_table[hash]; sym; sym = _symbol(sym)->next()){ + if (name == _symbol(sym)->name()) + return sym; // Yes. Return it + } + + // Nope. Make a new one. + pmt_t sym = pmt_t(new pmt_symbol(name)); + _symbol(sym)->set_next(s_symbol_hash_table[hash]); + s_symbol_hash_table[hash] = sym; + return sym; +} + +// alias... +pmt_t +pmt_intern(const std::string &name) +{ + return pmt_string_to_symbol(name); +} + +const std::string +pmt_symbol_to_string(const pmt_t& sym) +{ + if (!sym->is_symbol()) + throw pmt_wrong_type("pmt_symbol_to_string", sym); + + return _symbol(sym)->name(); +} + + + +//////////////////////////////////////////////////////////////////////////// +// Number +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_is_number(pmt_t x) +{ + return x->is_number(); +} + +//////////////////////////////////////////////////////////////////////////// +// Integer +//////////////////////////////////////////////////////////////////////////// + +pmt_integer::pmt_integer(long value) : d_value(value) {} + +bool +pmt_is_integer(pmt_t x) +{ + return x->is_integer(); +} + + +pmt_t +pmt_from_long(long x) +{ + return pmt_t(new pmt_integer(x)); +} + +long +pmt_to_long(pmt_t x) +{ + pmt_integer* i = dynamic_cast(x.get()); + if ( i ) + return i->value(); + + throw pmt_wrong_type("pmt_to_long", x); +} + +//////////////////////////////////////////////////////////////////////////// +// Real +//////////////////////////////////////////////////////////////////////////// + +pmt_real::pmt_real(double value) : d_value(value) {} + +bool +pmt_is_real(pmt_t x) +{ + return x->is_real(); +} + +pmt_t +pmt_from_double(double x) +{ + return pmt_t(new pmt_real(x)); +} + +double +pmt_to_double(pmt_t x) +{ + if (x->is_real()) + return _real(x)->value(); + if (x->is_integer()) + return _integer(x)->value(); + + throw pmt_wrong_type("pmt_to_double", x); +} + +//////////////////////////////////////////////////////////////////////////// +// Complex +//////////////////////////////////////////////////////////////////////////// + +pmt_complex::pmt_complex(std::complex value) : d_value(value) {} + +bool +pmt_is_complex(pmt_t x) +{ + return x->is_complex(); +} + +pmt_t +pmt_make_rectangular(double re, double im) +{ + return pmt_t(new pmt_complex(std::complex(re, im))); +} + +std::complex +pmt_to_complex(pmt_t x) +{ + if (x->is_complex()) + return _complex(x)->value(); + if (x->is_real()) + return _real(x)->value(); + if (x->is_integer()) + return _integer(x)->value(); + + throw pmt_wrong_type("pmt_to_complex", x); +} + +//////////////////////////////////////////////////////////////////////////// +// Pairs +//////////////////////////////////////////////////////////////////////////// + +pmt_null::pmt_null() {} +pmt_pair::pmt_pair(const pmt_t& car, const pmt_t& cdr) : d_car(car), d_cdr(cdr) {} + +bool +pmt_is_null(const pmt_t& x) +{ + return x == PMT_NIL; +} + +bool +pmt_is_pair(const pmt_t& obj) +{ + return obj->is_pair(); +} + +pmt_t +pmt_cons(const pmt_t& x, const pmt_t& y) +{ + return pmt_t(new pmt_pair(x, y)); +} + +pmt_t +pmt_car(const pmt_t& pair) +{ + pmt_pair* p = dynamic_cast(pair.get()); + if ( p ) + return p->car(); + + throw pmt_wrong_type("pmt_car", pair); +} + +pmt_t +pmt_cdr(const pmt_t& pair) +{ + pmt_pair* p = dynamic_cast(pair.get()); + if ( p ) + return p->cdr(); + + throw pmt_wrong_type("pmt_cdr", pair); +} + +void +pmt_set_car(pmt_t pair, pmt_t obj) +{ + if (pair->is_pair()) + _pair(pair)->set_car(obj); + else + throw pmt_wrong_type("pmt_set_car", pair); +} + +void +pmt_set_cdr(pmt_t pair, pmt_t obj) +{ + if (pair->is_pair()) + _pair(pair)->set_cdr(obj); + else + throw pmt_wrong_type("pmt_set_cdr", pair); +} + +//////////////////////////////////////////////////////////////////////////// +// Vectors +//////////////////////////////////////////////////////////////////////////// + +pmt_vector::pmt_vector(size_t len, pmt_t fill) + : d_v(len) +{ + for (size_t i = 0; i < len; i++) + d_v[i] = fill; +} + +pmt_t +pmt_vector::ref(size_t k) const +{ + if (k >= length()) + throw pmt_out_of_range("pmt_vector_ref", pmt_from_long(k)); + return d_v[k]; +} + +void +pmt_vector::set(size_t k, pmt_t obj) +{ + if (k >= length()) + throw pmt_out_of_range("pmt_vector_set", pmt_from_long(k)); + d_v[k] = obj; +} + +void +pmt_vector::fill(pmt_t obj) +{ + for (size_t i = 0; i < length(); i++) + d_v[i] = obj; +} + +bool +pmt_is_vector(pmt_t obj) +{ + return obj->is_vector(); +} + +pmt_t +pmt_make_vector(size_t k, pmt_t fill) +{ + return pmt_t(new pmt_vector(k, fill)); +} + +pmt_t +pmt_vector_ref(pmt_t vector, size_t k) +{ + if (!vector->is_vector()) + throw pmt_wrong_type("pmt_vector_ref", vector); + return _vector(vector)->ref(k); +} + +void +pmt_vector_set(pmt_t vector, size_t k, pmt_t obj) +{ + if (!vector->is_vector()) + throw pmt_wrong_type("pmt_vector_set", vector); + _vector(vector)->set(k, obj); +} + +void +pmt_vector_fill(pmt_t vector, pmt_t obj) +{ + if (!vector->is_vector()) + throw pmt_wrong_type("pmt_vector_set", vector); + _vector(vector)->fill(obj); +} + +//////////////////////////////////////////////////////////////////////////// +// Uniform Numeric Vectors +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_is_uniform_vector(pmt_t x) +{ + return x->is_uniform_vector(); +} + +const void * +pmt_uniform_vector_elements(pmt_t vector, size_t &len) +{ + if (!vector->is_uniform_vector()) + throw pmt_wrong_type("pmt_uniform_vector_elements", vector); + return _uniform_vector(vector)->uniform_elements(len); +} + +void * +pmt_uniform_vector_writable_elements(pmt_t vector, size_t &len) +{ + if (!vector->is_uniform_vector()) + throw pmt_wrong_type("pmt_uniform_vector_writable_elements", vector); + return _uniform_vector(vector)->uniform_writable_elements(len); +} + +//////////////////////////////////////////////////////////////////////////// +// Dictionaries +//////////////////////////////////////////////////////////////////////////// + +pmt_dict::pmt_dict() + : d_alist(PMT_NIL) +{ +} + +void +pmt_dict::set(pmt_t key, pmt_t value) +{ + pmt_t p = pmt_assv(key, d_alist); // look for (key . value) pair + if (pmt_is_pair(p)){ // found existing pair... + pmt_set_cdr(p, value); // overrwrite cdr with new value + } + else { // not in the dict + d_alist = pmt_cons(pmt_cons(key, value), d_alist); // add new (key . value) pair + } +} + +pmt_t +pmt_dict::ref(pmt_t key, pmt_t not_found) const +{ + pmt_t p = pmt_assv(key, d_alist); // look for (key . value) pair + if (pmt_is_pair(p)) + return pmt_cdr(p); + else + return not_found; +} + +bool +pmt_dict::has_key(pmt_t key) const +{ + return pmt_is_pair(pmt_assv(key, d_alist)); +} + +pmt_t +pmt_dict::items() const +{ + return d_alist; +} + +pmt_t +pmt_dict::keys() const +{ + return pmt_map(pmt_car, d_alist); +} + +pmt_t +pmt_dict::values() const +{ + return pmt_map(pmt_cdr, d_alist); +} + +bool +pmt_is_dict(pmt_t obj) +{ + return obj->is_dict(); +} + +pmt_t +pmt_make_dict() +{ + return pmt_t(new pmt_dict()); +} + +void +pmt_dict_set(pmt_t dict, pmt_t key, pmt_t value) +{ + pmt_dict* d = _dict(dict); + if (!d) + throw pmt_wrong_type("pmt_dict_set", dict); + + d->set(key, value); +} + +bool +pmt_dict_has_key(pmt_t dict, pmt_t key) +{ + pmt_dict* d = _dict(dict); + if (!d) + throw pmt_wrong_type("pmt_dict_has_key", dict); + + return d->has_key(key); +} + +pmt_t +pmt_dict_ref(pmt_t dict, pmt_t key, pmt_t not_found) +{ + pmt_dict* d = _dict(dict); + if (!d) + throw pmt_wrong_type("pmt_dict_ref", dict); + + return d->ref(key, not_found); +} + +pmt_t +pmt_dict_items(pmt_t dict) +{ + if (!dict->is_dict()) + throw pmt_wrong_type("pmt_dict_items", dict); + + return _dict(dict)->items(); +} + +pmt_t +pmt_dict_keys(pmt_t dict) +{ + if (!dict->is_dict()) + throw pmt_wrong_type("pmt_dict_keys", dict); + + return _dict(dict)->keys(); +} + +pmt_t +pmt_dict_values(pmt_t dict) +{ + if (!dict->is_dict()) + throw pmt_wrong_type("pmt_dict_values", dict); + + return _dict(dict)->values(); +} + +//////////////////////////////////////////////////////////////////////////// +// Any +//////////////////////////////////////////////////////////////////////////// + +pmt_any::pmt_any(const boost::any &any) : d_any(any) {} + +bool +pmt_is_any(pmt_t obj) +{ + return obj->is_any(); +} + +pmt_t +pmt_make_any(const boost::any &any) +{ + return pmt_t(new pmt_any(any)); +} + +boost::any +pmt_any_ref(pmt_t obj) +{ + if (!obj->is_any()) + throw pmt_wrong_type("pmt_any_ref", obj); + return _any(obj)->ref(); +} + +void +pmt_any_set(pmt_t obj, const boost::any &any) +{ + if (!obj->is_any()) + throw pmt_wrong_type("pmt_any_set", obj); + _any(obj)->set(any); +} + +//////////////////////////////////////////////////////////////////////////// +// General Functions +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_eq(const pmt_t& x, const pmt_t& y) +{ + return x == y; +} + +bool +pmt_eqv(const pmt_t& x, const pmt_t& y) +{ + if (x == y) + return true; + + if (x->is_integer() && y->is_integer()) + return _integer(x)->value() == _integer(y)->value(); + + if (x->is_real() && y->is_real()) + return _real(x)->value() == _real(y)->value(); + + if (x->is_complex() && y->is_complex()) + return _complex(x)->value() == _complex(y)->value(); + + return false; +} + +bool +pmt_equal(const pmt_t& x, const pmt_t& y) +{ + if (pmt_eqv(x, y)) + return true; + + if (x->is_pair() && y->is_pair()) + return pmt_equal(pmt_car(x), pmt_car(y)) && pmt_equal(pmt_cdr(x), pmt_cdr(y)); + + if (x->is_vector() && y->is_vector()){ + pmt_vector *xv = _vector(x); + pmt_vector *yv = _vector(y); + if (xv->length() != yv->length()) + return false; + + for (unsigned i = 0; i < xv->length(); i++) + if (!pmt_equal(xv->_ref(i), yv->_ref(i))) + return false; + + return true; + } + + if (x->is_uniform_vector() && y->is_uniform_vector()){ + pmt_uniform_vector *xv = _uniform_vector(x); + pmt_uniform_vector *yv = _uniform_vector(y); + if (xv->length() != yv->length()) + return false; + + size_t len_x, len_y; + if (memcmp(xv->uniform_elements(len_x), + yv->uniform_elements(len_y), + len_x) == 0) + return true; + + return true; + } + + // FIXME add other cases here... + + return false; +} + +size_t +pmt_length(const pmt_t& x) +{ + if (x->is_vector()) + return _vector(x)->length(); + + if (x->is_uniform_vector()) + return _uniform_vector(x)->length(); + + if (x->is_null()) return 0; + + if (x->is_pair()) { + size_t length=1; + pmt_t it = pmt_cdr(x); + while (pmt_is_pair(it)){ + length++; + it = pmt_cdr(it); + } + if (pmt_is_null(it)) + return length; + + // not a proper list + throw pmt_wrong_type("pmt_length", x); + } + + // FIXME dictionary length (number of entries) + + throw pmt_wrong_type("pmt_length", x); +} + +pmt_t +pmt_assq(pmt_t obj, pmt_t alist) +{ + while (pmt_is_pair(alist)){ + pmt_t p = pmt_car(alist); + if (!pmt_is_pair(p)) // malformed alist + return PMT_F; + + if (pmt_eq(obj, pmt_car(p))) + return p; + + alist = pmt_cdr(alist); + } + return PMT_F; +} + +pmt_t +pmt_assv(pmt_t obj, pmt_t alist) +{ + while (pmt_is_pair(alist)){ + pmt_t p = pmt_car(alist); + if (!pmt_is_pair(p)) // malformed alist + return PMT_F; + + if (pmt_eqv(obj, pmt_car(p))) + return p; + + alist = pmt_cdr(alist); + } + return PMT_F; +} + +pmt_t +pmt_assoc(pmt_t obj, pmt_t alist) +{ + while (pmt_is_pair(alist)){ + pmt_t p = pmt_car(alist); + if (!pmt_is_pair(p)) // malformed alist + return PMT_F; + + if (pmt_equal(obj, pmt_car(p))) + return p; + + alist = pmt_cdr(alist); + } + return PMT_F; +} + +pmt_t +pmt_map(pmt_t proc(const pmt_t&), pmt_t list) +{ + pmt_t r = PMT_NIL; + + while(pmt_is_pair(list)){ + r = pmt_cons(proc(pmt_car(list)), r); + list = pmt_cdr(list); + } + + return pmt_reverse_x(r); +} + +pmt_t +pmt_reverse(pmt_t listx) +{ + pmt_t list = listx; + pmt_t r = PMT_NIL; + + while(pmt_is_pair(list)){ + r = pmt_cons(pmt_car(list), r); + list = pmt_cdr(list); + } + if (pmt_is_null(list)) + return r; + else + throw pmt_wrong_type("pmt_reverse", listx); +} + +pmt_t +pmt_reverse_x(pmt_t list) +{ + // FIXME do it destructively + return pmt_reverse(list); +} + +pmt_t +pmt_nth(size_t n, pmt_t list) +{ + pmt_t t = pmt_nthcdr(n, list); + if (pmt_is_pair(t)) + return pmt_car(t); + else + return PMT_NIL; +} + +pmt_t +pmt_nthcdr(size_t n, pmt_t list) +{ + if (!(pmt_is_pair(list) || pmt_is_null(list))) + throw pmt_wrong_type("pmt_nthcdr", list); + + while (n > 0){ + if (pmt_is_pair(list)){ + list = pmt_cdr(list); + n--; + continue; + } + if (pmt_is_null(list)) + return PMT_NIL; + else + throw pmt_wrong_type("pmt_nthcdr: not a LIST", list); + } + return list; +} + +pmt_t +pmt_memq(pmt_t obj, pmt_t list) +{ + while (pmt_is_pair(list)){ + if (pmt_eq(obj, pmt_car(list))) + return list; + list = pmt_cdr(list); + } + return PMT_F; +} + +pmt_t +pmt_memv(pmt_t obj, pmt_t list) +{ + while (pmt_is_pair(list)){ + if (pmt_eqv(obj, pmt_car(list))) + return list; + list = pmt_cdr(list); + } + return PMT_F; +} + +pmt_t +pmt_member(pmt_t obj, pmt_t list) +{ + while (pmt_is_pair(list)){ + if (pmt_equal(obj, pmt_car(list))) + return list; + list = pmt_cdr(list); + } + return PMT_F; +} + +bool +pmt_subsetp(pmt_t list1, pmt_t list2) +{ + while (pmt_is_pair(list1)){ + pmt_t p = pmt_car(list1); + if (pmt_is_false(pmt_memv(p, list2))) + return false; + list1 = pmt_cdr(list1); + } + return true; +} + +pmt_t +pmt_list1(const pmt_t& x1) +{ + return pmt_cons(x1, PMT_NIL); +} + +pmt_t +pmt_list2(const pmt_t& x1, const pmt_t& x2) +{ + return pmt_cons(x1, pmt_cons(x2, PMT_NIL)); +} + +pmt_t +pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3) +{ + return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, PMT_NIL))); +} + +pmt_t +pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4) +{ + return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, PMT_NIL)))); +} + +pmt_t +pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5) +{ + return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, pmt_cons(x5, PMT_NIL))))); +} + +pmt_t +pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6) +{ + return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, pmt_cons(x5, pmt_cons(x6, PMT_NIL)))))); +} + +pmt_t +pmt_list_add(pmt_t list, const pmt_t& item) +{ + return pmt_reverse(pmt_cons(item, pmt_reverse(list))); +} + +pmt_t +pmt_caar(pmt_t pair) +{ + return (pmt_car(pmt_car(pair))); +} + +pmt_t +pmt_cadr(pmt_t pair) +{ + return pmt_car(pmt_cdr(pair)); +} + +pmt_t +pmt_cdar(pmt_t pair) +{ + return pmt_cdr(pmt_car(pair)); +} + +pmt_t +pmt_cddr(pmt_t pair) +{ + return pmt_cdr(pmt_cdr(pair)); +} + +pmt_t +pmt_caddr(pmt_t pair) +{ + return pmt_car(pmt_cdr(pmt_cdr(pair))); +} + +pmt_t +pmt_cadddr(pmt_t pair) +{ + return pmt_car(pmt_cdr(pmt_cdr(pmt_cdr(pair)))); +} + +bool +pmt_is_eof_object(pmt_t obj) +{ + return pmt_eq(obj, PMT_EOF); +} + +void +pmt_dump_sizeof() +{ + printf("sizeof(pmt_t) = %3zd\n", sizeof(pmt_t)); + printf("sizeof(pmt_base) = %3zd\n", sizeof(pmt_base)); + printf("sizeof(pmt_bool) = %3zd\n", sizeof(pmt_bool)); + printf("sizeof(pmt_symbol) = %3zd\n", sizeof(pmt_symbol)); + printf("sizeof(pmt_integer) = %3zd\n", sizeof(pmt_integer)); + printf("sizeof(pmt_real) = %3zd\n", sizeof(pmt_real)); + printf("sizeof(pmt_complex) = %3zd\n", sizeof(pmt_complex)); + printf("sizeof(pmt_null) = %3zd\n", sizeof(pmt_null)); + printf("sizeof(pmt_pair) = %3zd\n", sizeof(pmt_pair)); + printf("sizeof(pmt_vector) = %3zd\n", sizeof(pmt_vector)); + printf("sizeof(pmt_dict) = %3zd\n", sizeof(pmt_dict)); + printf("sizeof(pmt_uniform_vector) = %3zd\n", sizeof(pmt_uniform_vector)); +} + +} /* namespace pmt */ diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h new file mode 100644 index 000000000..9aac322a7 --- /dev/null +++ b/gruel/src/lib/pmt/pmt_int.h @@ -0,0 +1,227 @@ +/* -*- 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. + */ +#ifndef INCLUDED_PMT_INT_H +#define INCLUDED_PMT_INT_H + +#include +#include + +/* + * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION! + * + * See pmt.h for the public interface + */ + +#define PMT_LOCAL_ALLOCATOR 0 // define to 0 or 1 +namespace pmt { + +class pmt_base : boost::noncopyable { +protected: + pmt_base(){}; + virtual ~pmt_base(); + +public: + virtual bool is_bool() const { return false; } + virtual bool is_symbol() const { return false; } + virtual bool is_number() const { return false; } + virtual bool is_integer() const { return false; } + virtual bool is_real() const { return false; } + virtual bool is_complex() const { return false; } + virtual bool is_null() const { return false; } + virtual bool is_pair() const { return false; } + virtual bool is_vector() const { return false; } + virtual bool is_dict() const { return false; } + virtual bool is_any() const { return false; } + + virtual bool is_uniform_vector() const { return false; } + virtual bool is_u8vector() const { return false; } + virtual bool is_s8vector() const { return false; } + virtual bool is_u16vector() const { return false; } + virtual bool is_s16vector() const { return false; } + virtual bool is_u32vector() const { return false; } + virtual bool is_s32vector() const { return false; } + virtual bool is_u64vector() const { return false; } + virtual bool is_s64vector() const { return false; } + virtual bool is_f32vector() const { return false; } + virtual bool is_f64vector() const { return false; } + virtual bool is_c32vector() const { return false; } + virtual bool is_c64vector() const { return false; } + +# if (PMT_LOCAL_ALLOCATOR) + void *operator new(size_t); + void operator delete(void *, size_t); +#endif +}; + +class pmt_bool : public pmt_base +{ +public: + pmt_bool(); + //~pmt_bool(){} + + bool is_bool() const { return true; } +}; + + +class pmt_symbol : public pmt_base +{ + std::string d_name; + pmt_t d_next; + +public: + pmt_symbol(const std::string &name); + //~pmt_symbol(){} + + bool is_symbol() const { return true; } + const std::string name() { return d_name; } + + pmt_t next() { return d_next; } // symbol table link + void set_next(pmt_t next) { d_next = next; } +}; + +class pmt_integer : public pmt_base +{ + long d_value; + +public: + pmt_integer(long value); + //~pmt_integer(){} + + bool is_number() const { return true; } + bool is_integer() const { return true; } + long value() const { return d_value; } +}; + +class pmt_real : public pmt_base +{ + double d_value; + +public: + pmt_real(double value); + //~pmt_real(){} + + bool is_number() const { return true; } + bool is_real() const { return true; } + double value() const { return d_value; } +}; + +class pmt_complex : public pmt_base +{ + std::complex d_value; + +public: + pmt_complex(std::complex value); + //~pmt_complex(){} + + bool is_number() const { return true; } + bool is_complex() const { return true; } + std::complex value() const { return d_value; } +}; + +class pmt_null : public pmt_base +{ +public: + pmt_null(); + //~pmt_null(){} + + bool is_null() const { return true; } +}; + +class pmt_pair : public pmt_base +{ + pmt_t d_car; + pmt_t d_cdr; + +public: + pmt_pair(const pmt_t& car, const pmt_t& cdr); + //~pmt_pair(){}; + + bool is_pair() const { return true; } + pmt_t car() const { return d_car; } + pmt_t cdr() const { return d_cdr; } + + void set_car(pmt_t car) { d_car = car; } + void set_cdr(pmt_t cdr) { d_cdr = cdr; } +}; + +class pmt_vector : public pmt_base +{ + std::vector d_v; + +public: + pmt_vector(size_t len, pmt_t fill); + //~pmt_vector(); + + bool is_vector() const { return true; } + pmt_t ref(size_t k) const; + void set(size_t k, pmt_t obj); + void fill(pmt_t fill); + size_t length() const { return d_v.size(); } + + pmt_t _ref(size_t k) const { return d_v[k]; } +}; + +class pmt_dict : public pmt_base +{ + pmt_t d_alist; // list of (key . value) pairs + +public: + pmt_dict(); + //~pmt_dict(); + + bool is_dict() const { return true; } + void set(pmt_t key, pmt_t value); + pmt_t ref(pmt_t key, pmt_t default_value) const; + bool has_key(pmt_t key) const; + pmt_t items() const; + pmt_t keys() const; + pmt_t values() const; +}; + +class pmt_any : public pmt_base +{ + boost::any d_any; + +public: + pmt_any(const boost::any &any); + //~pmt_any(); + + bool is_any() const { return true; } + const boost::any &ref() const { return d_any; } + void set(const boost::any &any) { d_any = any; } +}; + + +class pmt_uniform_vector : public pmt_base +{ +public: + bool is_uniform_vector() const { return true; } + virtual const void *uniform_elements(size_t &len) = 0; + virtual void *uniform_writable_elements(size_t &len) = 0; + virtual size_t length() const = 0; +}; + +#include "pmt_unv_int.h" + +} /* namespace pmt */ + +#endif /* INCLUDED_PMT_INT_H */ diff --git a/gruel/src/lib/pmt/pmt_io.cc b/gruel/src/lib/pmt/pmt_io.cc new file mode 100644 index 000000000..f5a82de0e --- /dev/null +++ b/gruel/src/lib/pmt/pmt_io.cc @@ -0,0 +1,141 @@ +/* -*- 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 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 +#endif +#include +#include +#include "pmt_int.h" +#include + +namespace pmt { + +static void +pmt_write_list_tail(pmt_t obj, std::ostream &port) +{ + pmt_write(pmt_car(obj), port); // write the car + obj = pmt_cdr(obj); // step to cdr + + if (pmt_is_null(obj)) // () + port << ")"; + + else if (pmt_is_pair(obj)){ // normal list + port << " "; + pmt_write_list_tail(obj, port); + } + else { // dotted pair + port << " . "; + pmt_write(obj, port); + port << ")"; + } +} + +void +pmt_write(pmt_t obj, std::ostream &port) +{ + if (pmt_is_bool(obj)){ + if (pmt_is_true(obj)) + port << "#t"; + else + port << "#f"; + } + else if (pmt_is_symbol(obj)){ + port << pmt_symbol_to_string(obj); + } + else if (pmt_is_number(obj)){ + if (pmt_is_integer(obj)) + port << pmt_to_long(obj); + else if (pmt_is_real(obj)) + port << pmt_to_double(obj); + else if (pmt_is_complex(obj)){ + std::complex c = pmt_to_complex(obj); + port << c.real() << '+' << c.imag() << 'i'; + } + else + goto error; + } + else if (pmt_is_null(obj)){ + port << "()"; + } + else if (pmt_is_pair(obj)){ + port << "("; + pmt_write_list_tail(obj, port); + } + else if (pmt_is_dict(obj)){ + // FIXME + // port << "#"; + port << "#"; + } + else if (pmt_is_vector(obj)){ + // FIXME + // port << "#"; + port << "#"; + } + else if (pmt_is_uniform_vector(obj)){ + // FIXME + // port << "#"; + port << "#"; + } + else { + error: + // FIXME + // port << "#<" << obj << ">"; + port << "#"; + } +} + +std::ostream& operator<<(std::ostream &os, pmt_t obj) +{ + pmt_write(obj, os); + return os; +} + +std::string +pmt_write_string(pmt_t obj) +{ + std::ostringstream s; + s << obj; + return s.str(); +} + +pmt_t +pmt_read(std::istream &port) +{ + throw pmt_notimplemented("notimplemented: pmt_read", PMT_NIL); +} + +void +pmt_serialize(pmt_t obj, std::ostream &sink) +{ + throw pmt_notimplemented("notimplemented: pmt_serialize", obj); +} + +/*! + * \brief Create obj from portable byte-serial representation + */ +pmt_t +pmt_deserialize(std::istream &source) +{ + throw pmt_notimplemented("notimplemented: pmt_deserialize", PMT_NIL); +} + +} /* namespace pmt */ diff --git a/gruel/src/lib/pmt/pmt_pool.cc b/gruel/src/lib/pmt/pmt_pool.cc new file mode 100644 index 000000000..731d28ca7 --- /dev/null +++ b/gruel/src/lib/pmt/pmt_pool.cc @@ -0,0 +1,112 @@ +/* -*- 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 +#endif +#include +#include +#include + +namespace pmt { + +static inline size_t +ROUNDUP(size_t x, size_t stride) +{ + return ((((x) + (stride) - 1)/(stride)) * (stride)); +} + +pmt_pool::pmt_pool(size_t itemsize, size_t alignment, + size_t allocation_size, size_t max_items) + : d_itemsize(ROUNDUP(itemsize, alignment)), + d_alignment(alignment), + d_allocation_size(std::max(allocation_size, 16 * itemsize)), + d_max_items(max_items), d_n_items(0), + d_freelist(0) +{ +} + +pmt_pool::~pmt_pool() +{ + for (unsigned int i = 0; i < d_allocations.size(); i++){ + delete [] d_allocations[i]; + } +} + +void * +pmt_pool::malloc() +{ + scoped_lock guard(d_mutex); + item *p; + + if (d_max_items != 0){ + while (d_n_items >= d_max_items) + d_cond.wait(guard); + } + + if (d_freelist){ // got something? + p = d_freelist; + d_freelist = p->d_next; + d_n_items++; + return p; + } + + // allocate a new chunk + char *alloc = new char[d_allocation_size + d_alignment - 1]; + d_allocations.push_back(alloc); + + // get the alignment we require + char *start = (char *)(((uintptr_t)alloc + d_alignment-1) & -d_alignment); + char *end = alloc + d_allocation_size + d_alignment - 1; + size_t n = (end - start) / d_itemsize; + + // link the new items onto the free list. + p = (item *) start; + for (size_t i = 0; i < n; i++){ + p->d_next = d_freelist; + d_freelist = p; + p = (item *)((char *) p + d_itemsize); + } + + // now return the first one + p = d_freelist; + d_freelist = p->d_next; + d_n_items++; + return p; +} + +void +pmt_pool::free(void *foo) +{ + if (!foo) + return; + + scoped_lock guard(d_mutex); + + item *p = (item *) foo; + p->d_next = d_freelist; + d_freelist = p; + d_n_items--; + if (d_max_items != 0) + d_cond.notify_one(); +} + +} /* namespace pmt */ diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc new file mode 100644 index 000000000..937423a93 --- /dev/null +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -0,0 +1,357 @@ +/* -*- 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 +#endif +#include +#include +#include "pmt_int.h" +#include "gruel/pmt_serial_tags.h" + +namespace pmt { + +static pmt_t parse_pair(std::streambuf &sb); + +// ---------------------------------------------------------------- +// output primitives +// ---------------------------------------------------------------- + +static bool +serialize_untagged_u8(unsigned int i, std::streambuf &sb) +{ + return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} + +// always writes big-endian +static bool +serialize_untagged_u16(unsigned int i, std::streambuf &sb) +{ + sb.sputc((i >> 8) & 0xff); + return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} + +// always writes big-endian +static bool +serialize_untagged_u32(unsigned int i, std::streambuf &sb) +{ + sb.sputc((i >> 24) & 0xff); + sb.sputc((i >> 16) & 0xff); + sb.sputc((i >> 8) & 0xff); + return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} + +#if 0 +// always writes big-endian +static bool +serialize_untagged_u64(uint64_t i, std::streambuf &sb) +{ + sb.sputc((i >> 56) & 0xff); + sb.sputc((i >> 48) & 0xff); + sb.sputc((i >> 40) & 0xff); + sb.sputc((i >> 32) & 0xff); + sb.sputc((i >> 24) & 0xff); + sb.sputc((i >> 16) & 0xff); + sb.sputc((i >> 8) & 0xff); + return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} +#endif + +// ---------------------------------------------------------------- +// input primitives +// ---------------------------------------------------------------- + + +// always reads big-endian +static bool +deserialize_untagged_u8(uint8_t *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + int i; + + t = sb.sbumpc(); + i = t & 0xff; + + *ip = i; + return t != std::streambuf::traits_type::eof(); +} + +// always reads big-endian +static bool +deserialize_untagged_u16(uint16_t *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + int i; + + t = sb.sbumpc(); + i = t & 0xff; + + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + + *ip = i; + return t != std::streambuf::traits_type::eof(); +} + +// always reads big-endian +static bool +deserialize_untagged_u32(uint32_t *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + int i; + + t = sb.sbumpc(); + i = t & 0xff; + + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + + *ip = i; + return t != std::streambuf::traits_type::eof(); +} + +#if 0 +// always reads big-endian +static bool +deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + uint64_t i; + + t = sb.sbumpc(); + i = t & 0xff; + + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + t = sb.sbumpc(); + i = (i << 8) | (t & 0xff); + + *ip = i; + return t != std::streambuf::traits_type::eof(); +} +#endif + +/* + * Write portable byte-serial representation of \p obj to \p sb + * + * N.B., Circular structures cause infinite recursion. + */ +bool +pmt_serialize(pmt_t obj, std::streambuf &sb) +{ + bool ok = true; + + tail_recursion: + + if (pmt_is_bool(obj)){ + if (pmt_eq(obj, PMT_T)) + return serialize_untagged_u8(PST_TRUE, sb); + else + return serialize_untagged_u8(PST_FALSE, sb); + } + + if (pmt_is_null(obj)) + return serialize_untagged_u8(PST_NULL, sb); + + if (pmt_is_symbol(obj)){ + const std::string s = pmt_symbol_to_string(obj); + size_t len = s.size(); + ok = serialize_untagged_u8(PST_SYMBOL, sb); + ok &= serialize_untagged_u16(len, sb); + for (size_t i = 0; i < len; i++) + ok &= serialize_untagged_u8(s[i], sb); + return ok; + } + + if (pmt_is_pair(obj)){ + ok = serialize_untagged_u8(PST_PAIR, sb); + ok &= pmt_serialize(pmt_car(obj), sb); + if (!ok) + return false; + obj = pmt_cdr(obj); + goto tail_recursion; + } + + if (pmt_is_number(obj)){ + + if (pmt_is_integer(obj)){ + long i = pmt_to_long(obj); + if (sizeof(long) > 4){ + if (i < -2147483647 || i > 2147483647) + throw pmt_notimplemented("pmt_serialize (64-bit integers)", obj); + } + ok = serialize_untagged_u8(PST_INT32, sb); + ok &= serialize_untagged_u32(i, sb); + return ok; + } + + if (pmt_is_real(obj)) + throw pmt_notimplemented("pmt_serialize (real)", obj); + + if (pmt_is_complex(obj)) + throw pmt_notimplemented("pmt_serialize (complex)", obj); + } + + if (pmt_is_vector(obj)) + throw pmt_notimplemented("pmt_serialize (vector)", obj); + + if (pmt_is_uniform_vector(obj)) + throw pmt_notimplemented("pmt_serialize (uniform-vector)", obj); + + if (pmt_is_dict(obj)) + throw pmt_notimplemented("pmt_serialize (dict)", obj); + + + throw pmt_notimplemented("pmt_serialize (?)", obj); +} + +/* + * Create obj from portable byte-serial representation + * + * Returns next obj from streambuf, or PMT_EOF at end of file. + * Throws exception on malformed input. + */ +pmt_t +pmt_deserialize(std::streambuf &sb) +{ + uint8_t tag; + //uint8_t u8; + uint16_t u16; + uint32_t u32; + //uint32_t u64; + static char tmpbuf[1024]; + + if (!deserialize_untagged_u8(&tag, sb)) + return PMT_EOF; + + switch (tag){ + case PST_TRUE: + return PMT_T; + + case PST_FALSE: + return PMT_F; + + case PST_NULL: + return PMT_NIL; + + case PST_SYMBOL: + if (!deserialize_untagged_u16(&u16, sb)) + goto error; + if (u16 > sizeof(tmpbuf)) + throw pmt_notimplemented("pmt_deserialize: very long symbol", + PMT_F); + if (sb.sgetn(tmpbuf, u16) != u16) + goto error; + return pmt_intern(std::string(tmpbuf, u16)); + + case PST_INT32: + if (!deserialize_untagged_u32(&u32, sb)) + goto error; + return pmt_from_long((int32_t) u32); + + case PST_PAIR: + return parse_pair(sb); + + case PST_DOUBLE: + case PST_COMPLEX: + case PST_VECTOR: + case PST_DICT: + case PST_UNIFORM_VECTOR: + case PST_COMMENT: + throw pmt_notimplemented("pmt_deserialize: tag value = ", + pmt_from_long(tag)); + + default: + throw pmt_exception("pmt_deserialize: malformed input stream, tag value = ", + pmt_from_long(tag)); + } + + error: + throw pmt_exception("pmt_deserialize: malformed input stream", PMT_F); +} + +/* + * This is a mostly non-recursive implementation that allows us to + * deserialize very long lists w/o exhausting the evaluation stack. + * + * On entry we've already eaten the PST_PAIR tag. + */ +pmt_t +parse_pair(std::streambuf &sb) +{ + uint8_t tag; + pmt_t val, expr, lastnptr, nptr; + + // + // Keep appending nodes until we get a non-PAIR cdr. + // + lastnptr = PMT_NIL; + while (1){ + expr = pmt_deserialize(sb); // read the car + + nptr = pmt_cons(expr, PMT_NIL); // build new cell + if (pmt_is_null(lastnptr)) + val = nptr; + else + pmt_set_cdr(lastnptr, nptr); + lastnptr = nptr; + + if (!deserialize_untagged_u8(&tag, sb)) // get tag of cdr + throw pmt_exception("pmt_deserialize: malformed input stream", PMT_F); + + if (tag == PST_PAIR) + continue; // keep on looping... + + if (tag == PST_NULL){ + expr = PMT_NIL; + break; + } + + // + // default: push tag back and use pmt_deserialize to get the cdr + // + sb.sungetc(); + expr = pmt_deserialize(sb); + break; + } + + // + // At this point, expr contains the value of the final cdr in the list. + // + pmt_set_cdr(lastnptr, expr); + return val; +} + +} /* namespace pmt */ diff --git a/gruel/src/lib/pmt/qa_pmt.cc b/gruel/src/lib/pmt/qa_pmt.cc new file mode 100644 index 000000000..250befafa --- /dev/null +++ b/gruel/src/lib/pmt/qa_pmt.cc @@ -0,0 +1,40 @@ +/* + * 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. + */ + +/* + * This class gathers together all the test cases for pmt into + * a single test suite. As you create new test cases, add them here. + */ + +#include +#include +#include + +CppUnit::TestSuite * +qa_pmt::suite () +{ + CppUnit::TestSuite *s = new CppUnit::TestSuite ("pmt"); + + s->addTest (qa_pmt_prims::suite ()); + s->addTest (qa_pmt_unv::suite ()); + + return s; +} diff --git a/gruel/src/lib/pmt/qa_pmt.h b/gruel/src/lib/pmt/qa_pmt.h new file mode 100644 index 000000000..43a6dbf67 --- /dev/null +++ b/gruel/src/lib/pmt/qa_pmt.h @@ -0,0 +1,36 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_QA_PMT_H +#define INCLUDED_QA_PMT_H + +#include + +//! collect all the tests for pmt + +class qa_pmt { + public: + //! return suite of tests for all of pmt + static CppUnit::TestSuite *suite (); +}; + +#endif /* INCLUDED_QA_PMT_H */ diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc new file mode 100644 index 000000000..b81354721 --- /dev/null +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -0,0 +1,438 @@ +/* -*- 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 +#include +#include +#include + +using namespace pmt; + +void +qa_pmt_prims::test_symbols() +{ + CPPUNIT_ASSERT(!pmt_is_symbol(PMT_T)); + CPPUNIT_ASSERT(!pmt_is_symbol(PMT_F)); + CPPUNIT_ASSERT_THROW(pmt_symbol_to_string(PMT_F), pmt_wrong_type); + + pmt_t sym1 = pmt_string_to_symbol("test"); + CPPUNIT_ASSERT(pmt_is_symbol(sym1)); + CPPUNIT_ASSERT_EQUAL(std::string("test"), pmt_symbol_to_string(sym1)); + CPPUNIT_ASSERT(pmt_is_true(sym1)); + CPPUNIT_ASSERT(!pmt_is_false(sym1)); + + pmt_t sym2 = pmt_string_to_symbol("foo"); + pmt_t sym3 = pmt_string_to_symbol("test"); + CPPUNIT_ASSERT_EQUAL(sym1, sym3); + CPPUNIT_ASSERT(sym1 != sym2); + CPPUNIT_ASSERT(sym1 == sym3); + + static const int N = 2048; + std::vector v1(N); + std::vector v2(N); + + // generate a bunch of symbols + for (int i = 0; i < N; i++){ + char buf[100]; + snprintf(buf, sizeof(buf), "test-%d", i); + v1[i] = pmt_string_to_symbol(buf); + } + + // confirm that they are all unique + for (int i = 0; i < N; i++) + for (int j = i + 1; j < N; j++) + CPPUNIT_ASSERT(v1[i] != v1[j]); + + // generate the same symbols again + for (int i = 0; i < N; i++){ + char buf[100]; + snprintf(buf, sizeof(buf), "test-%d", i); + v2[i] = pmt_string_to_symbol(buf); + } + + // confirm that we get the same ones back + for (int i = 0; i < N; i++) + CPPUNIT_ASSERT(v1[i] == v2[i]); +} + +void +qa_pmt_prims::test_booleans() +{ + pmt_t sym = pmt_string_to_symbol("test"); + CPPUNIT_ASSERT(pmt_is_bool(PMT_T)); + CPPUNIT_ASSERT(pmt_is_bool(PMT_F)); + CPPUNIT_ASSERT(!pmt_is_bool(sym)); + CPPUNIT_ASSERT_EQUAL(pmt_from_bool(false), PMT_F); + CPPUNIT_ASSERT_EQUAL(pmt_from_bool(true), PMT_T); + CPPUNIT_ASSERT_EQUAL(false, pmt_to_bool(PMT_F)); + CPPUNIT_ASSERT_EQUAL(true, pmt_to_bool(PMT_T)); + CPPUNIT_ASSERT_THROW(pmt_to_bool(sym), pmt_wrong_type); +} + +void +qa_pmt_prims::test_integers() +{ + pmt_t p1 = pmt_from_long(1); + pmt_t m1 = pmt_from_long(-1); + CPPUNIT_ASSERT(!pmt_is_integer(PMT_T)); + CPPUNIT_ASSERT(pmt_is_integer(p1)); + CPPUNIT_ASSERT(pmt_is_integer(m1)); + CPPUNIT_ASSERT_THROW(pmt_to_long(PMT_T), pmt_wrong_type); + CPPUNIT_ASSERT_EQUAL(-1L, pmt_to_long(m1)); + CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(p1)); +} + +void +qa_pmt_prims::test_reals() +{ + pmt_t p1 = pmt_from_double(1); + pmt_t m1 = pmt_from_double(-1); + CPPUNIT_ASSERT(!pmt_is_real(PMT_T)); + CPPUNIT_ASSERT(pmt_is_real(p1)); + CPPUNIT_ASSERT(pmt_is_real(m1)); + CPPUNIT_ASSERT_THROW(pmt_to_double(PMT_T), pmt_wrong_type); + CPPUNIT_ASSERT_EQUAL(-1.0, pmt_to_double(m1)); + CPPUNIT_ASSERT_EQUAL(1.0, pmt_to_double(p1)); + CPPUNIT_ASSERT_EQUAL(1.0, pmt_to_double(pmt_from_long(1))); +} + +void +qa_pmt_prims::test_complexes() +{ + pmt_t p1 = pmt_make_rectangular(2, -3); + pmt_t m1 = pmt_make_rectangular(-3, 2); + CPPUNIT_ASSERT(!pmt_is_complex(PMT_T)); + CPPUNIT_ASSERT(pmt_is_complex(p1)); + CPPUNIT_ASSERT(pmt_is_complex(m1)); + CPPUNIT_ASSERT_THROW(pmt_to_complex(PMT_T), pmt_wrong_type); + CPPUNIT_ASSERT_EQUAL(std::complex(2, -3), pmt_to_complex(p1)); + CPPUNIT_ASSERT_EQUAL(std::complex(-3, 2), pmt_to_complex(m1)); + CPPUNIT_ASSERT_EQUAL(std::complex(1.0, 0), pmt_to_complex(pmt_from_long(1))); + CPPUNIT_ASSERT_EQUAL(std::complex(1.0, 0), pmt_to_complex(pmt_from_double(1.0))); +} + +void +qa_pmt_prims::test_pairs() +{ + CPPUNIT_ASSERT(pmt_is_null(PMT_NIL)); + CPPUNIT_ASSERT(!pmt_is_pair(PMT_NIL)); + pmt_t s1 = pmt_string_to_symbol("s1"); + pmt_t s2 = pmt_string_to_symbol("s2"); + pmt_t s3 = pmt_string_to_symbol("s3"); + + + CPPUNIT_ASSERT_EQUAL((size_t)0, pmt_length(PMT_NIL)); + CPPUNIT_ASSERT_THROW(pmt_length(s1), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_length(pmt_from_double(42)), pmt_wrong_type); + + pmt_t c1 = pmt_cons(s1, PMT_NIL); + CPPUNIT_ASSERT(pmt_is_pair(c1)); + CPPUNIT_ASSERT(!pmt_is_pair(s1)); + CPPUNIT_ASSERT_EQUAL(s1, pmt_car(c1)); + CPPUNIT_ASSERT_EQUAL(PMT_NIL, pmt_cdr(c1)); + CPPUNIT_ASSERT_EQUAL((size_t) 1, pmt_length(c1)); + + pmt_t c3 = pmt_cons(s3, PMT_NIL); + pmt_t c2 = pmt_cons(s2, c3); + pmt_set_cdr(c1, c2); + CPPUNIT_ASSERT_EQUAL(c2, pmt_cdr(c1)); + pmt_set_car(c1, s3); + CPPUNIT_ASSERT_EQUAL(s3, pmt_car(c1)); + CPPUNIT_ASSERT_EQUAL((size_t)1, pmt_length(c3)); + CPPUNIT_ASSERT_EQUAL((size_t)2, pmt_length(c2)); + + CPPUNIT_ASSERT_THROW(pmt_cdr(PMT_NIL), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_car(PMT_NIL), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_set_car(s1, PMT_NIL), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_set_cdr(s1, PMT_NIL), pmt_wrong_type); +} + +void +qa_pmt_prims::test_vectors() +{ + static const size_t N = 3; + pmt_t v1 = pmt_make_vector(N, PMT_NIL); + CPPUNIT_ASSERT_EQUAL(N, pmt_length(v1)); + pmt_t s0 = pmt_string_to_symbol("s0"); + pmt_t s1 = pmt_string_to_symbol("s1"); + pmt_t s2 = pmt_string_to_symbol("s2"); + + pmt_vector_set(v1, 0, s0); + pmt_vector_set(v1, 1, s1); + pmt_vector_set(v1, 2, s2); + + CPPUNIT_ASSERT_EQUAL(s0, pmt_vector_ref(v1, 0)); + CPPUNIT_ASSERT_EQUAL(s1, pmt_vector_ref(v1, 1)); + CPPUNIT_ASSERT_EQUAL(s2, pmt_vector_ref(v1, 2)); + + CPPUNIT_ASSERT_THROW(pmt_vector_ref(v1, N), pmt_out_of_range); + CPPUNIT_ASSERT_THROW(pmt_vector_set(v1, N, PMT_NIL), pmt_out_of_range); + + pmt_vector_fill(v1, s0); + for (size_t i = 0; i < N; i++) + CPPUNIT_ASSERT_EQUAL(s0, pmt_vector_ref(v1, i)); +} + +void +qa_pmt_prims::test_equivalence() +{ + pmt_t s0 = pmt_string_to_symbol("s0"); + pmt_t s1 = pmt_string_to_symbol("s1"); + pmt_t s2 = pmt_string_to_symbol("s2"); + pmt_t list0 = pmt_cons(s0, pmt_cons(s1, pmt_cons(s2, PMT_NIL))); + pmt_t list1 = pmt_cons(s0, pmt_cons(s1, pmt_cons(s2, PMT_NIL))); + pmt_t i0 = pmt_from_long(42); + pmt_t i1 = pmt_from_long(42); + pmt_t r0 = pmt_from_double(42); + pmt_t r1 = pmt_from_double(42); + pmt_t r2 = pmt_from_double(43); + + CPPUNIT_ASSERT(pmt_eq(s0, s0)); + CPPUNIT_ASSERT(!pmt_eq(s0, s1)); + CPPUNIT_ASSERT(pmt_eqv(s0, s0)); + CPPUNIT_ASSERT(!pmt_eqv(s0, s1)); + + CPPUNIT_ASSERT(pmt_eqv(i0, i1)); + CPPUNIT_ASSERT(pmt_eqv(r0, r1)); + CPPUNIT_ASSERT(!pmt_eqv(r0, r2)); + CPPUNIT_ASSERT(!pmt_eqv(i0, r0)); + + CPPUNIT_ASSERT(!pmt_eq(list0, list1)); + CPPUNIT_ASSERT(!pmt_eqv(list0, list1)); + CPPUNIT_ASSERT(pmt_equal(list0, list1)); + + pmt_t v0 = pmt_make_vector(3, s0); + pmt_t v1 = pmt_make_vector(3, s0); + pmt_t v2 = pmt_make_vector(4, s0); + CPPUNIT_ASSERT(!pmt_eqv(v0, v1)); + CPPUNIT_ASSERT(pmt_equal(v0, v1)); + CPPUNIT_ASSERT(!pmt_equal(v0, v2)); + + pmt_vector_set(v0, 0, list0); + pmt_vector_set(v0, 1, list0); + pmt_vector_set(v1, 0, list1); + pmt_vector_set(v1, 1, list1); + CPPUNIT_ASSERT(pmt_equal(v0, v1)); +} + +void +qa_pmt_prims::test_misc() +{ + pmt_t k0 = pmt_string_to_symbol("k0"); + pmt_t k1 = pmt_string_to_symbol("k1"); + pmt_t k2 = pmt_string_to_symbol("k2"); + pmt_t k3 = pmt_string_to_symbol("k3"); + pmt_t v0 = pmt_string_to_symbol("v0"); + pmt_t v1 = pmt_string_to_symbol("v1"); + pmt_t v2 = pmt_string_to_symbol("v2"); + pmt_t p0 = pmt_cons(k0, v0); + pmt_t p1 = pmt_cons(k1, v1); + pmt_t p2 = pmt_cons(k2, v2); + + pmt_t alist = pmt_cons(p0, pmt_cons(p1, pmt_cons(p2, PMT_NIL))); + CPPUNIT_ASSERT(pmt_eq(p1, pmt_assv(k1, alist))); + CPPUNIT_ASSERT(pmt_eq(PMT_F, pmt_assv(k3, alist))); + + pmt_t keys = pmt_cons(k0, pmt_cons(k1, pmt_cons(k2, PMT_NIL))); + pmt_t vals = pmt_cons(v0, pmt_cons(v1, pmt_cons(v2, PMT_NIL))); + CPPUNIT_ASSERT(pmt_equal(keys, pmt_map(pmt_car, alist))); + CPPUNIT_ASSERT(pmt_equal(vals, pmt_map(pmt_cdr, alist))); +} + +void +qa_pmt_prims::test_dict() +{ + pmt_t dict = pmt_make_dict(); + CPPUNIT_ASSERT(pmt_is_dict(dict)); + + pmt_t k0 = pmt_string_to_symbol("k0"); + pmt_t k1 = pmt_string_to_symbol("k1"); + pmt_t k2 = pmt_string_to_symbol("k2"); + pmt_t k3 = pmt_string_to_symbol("k3"); + pmt_t v0 = pmt_string_to_symbol("v0"); + pmt_t v1 = pmt_string_to_symbol("v1"); + pmt_t v2 = pmt_string_to_symbol("v2"); + pmt_t v3 = pmt_string_to_symbol("v3"); + pmt_t not_found = pmt_cons(PMT_NIL, PMT_NIL); + + CPPUNIT_ASSERT(!pmt_dict_has_key(dict, k0)); + pmt_dict_set(dict, k0, v0); + CPPUNIT_ASSERT(pmt_dict_has_key(dict, k0)); + CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k0, not_found), v0)); + CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), not_found)); + pmt_dict_set(dict, k1, v1); + pmt_dict_set(dict, k2, v2); + CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), v1)); + pmt_dict_set(dict, k1, v3); + CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), v3)); + + pmt_t keys = pmt_cons(k2, pmt_cons(k1, pmt_cons(k0, PMT_NIL))); + pmt_t vals = pmt_cons(v2, pmt_cons(v3, pmt_cons(v0, PMT_NIL))); + CPPUNIT_ASSERT(pmt_equal(keys, pmt_dict_keys(dict))); + CPPUNIT_ASSERT(pmt_equal(vals, pmt_dict_values(dict))); +} + +void +qa_pmt_prims::test_io() +{ + pmt_t k0 = pmt_string_to_symbol("k0"); + pmt_t k1 = pmt_string_to_symbol("k1"); + pmt_t k2 = pmt_string_to_symbol("k2"); + pmt_t k3 = pmt_string_to_symbol("k3"); + + CPPUNIT_ASSERT_EQUAL(std::string("k0"), pmt_write_string(k0)); +} + +void +qa_pmt_prims::test_lists() +{ + pmt_t s0 = pmt_intern("s0"); + pmt_t s1 = pmt_intern("s1"); + pmt_t s2 = pmt_intern("s2"); + pmt_t s3 = pmt_intern("s3"); + + pmt_t l1 = pmt_list4(s0, s1, s2, s3); + pmt_t l2 = pmt_list3(s0, s1, s2); + pmt_t l3 = pmt_list_add(l2, s3); + CPPUNIT_ASSERT(pmt_equal(l1, l3)); +} + +// ------------------------------------------------------------------------ + +// class foo is used in test_any below. +// It can't be declared in the scope of test_any because of template +// namespace problems. + +class foo { +public: + double d_double; + int d_int; + foo(double d=0, int i=0) : d_double(d), d_int(i) {} +}; + +bool operator==(const foo &a, const foo &b) +{ + return a.d_double == b.d_double && a.d_int == b.d_int; +} + +std::ostream& operator<<(std::ostream &os, const foo obj) +{ + os << ""; + return os; +} + +void +qa_pmt_prims::test_any() +{ + boost::any a0; + boost::any a1; + boost::any a2; + + a0 = std::string("Hello!"); + a1 = 42; + a2 = foo(3.250, 21); + + pmt_t p0 = pmt_make_any(a0); + pmt_t p1 = pmt_make_any(a1); + pmt_t p2 = pmt_make_any(a2); + + CPPUNIT_ASSERT_EQUAL(std::string("Hello!"), + boost::any_cast(pmt_any_ref(p0))); + + CPPUNIT_ASSERT_EQUAL(42, + boost::any_cast(pmt_any_ref(p1))); + + CPPUNIT_ASSERT_EQUAL(foo(3.250, 21), + boost::any_cast(pmt_any_ref(p2))); +} + +// ------------------------------------------------------------------------ + +void +qa_pmt_prims::test_serialize() +{ + std::stringbuf sb; // fake channel + pmt_t a = pmt_intern("a"); + pmt_t b = pmt_intern("b"); + pmt_t c = pmt_intern("c"); + + sb.str(""); // reset channel to empty + + // write stuff to channel + + pmt_serialize(PMT_NIL, sb); + pmt_serialize(pmt_intern("foobarvia"), sb); + pmt_serialize(pmt_from_long(123456789), sb); + pmt_serialize(pmt_from_long(-123456789), sb); + pmt_serialize(pmt_cons(PMT_NIL, PMT_NIL), sb); + pmt_serialize(pmt_cons(a, b), sb); + pmt_serialize(pmt_list1(a), sb); + pmt_serialize(pmt_list2(a, b), sb); + pmt_serialize(pmt_list3(a, b, c), sb); + pmt_serialize(pmt_list3(a, pmt_list3(c, b, a), c), sb); + pmt_serialize(PMT_T, sb); + pmt_serialize(PMT_F, sb); + + // read it back + + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_NIL)); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_intern("foobarvia"))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_from_long(123456789))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_from_long(-123456789))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_cons(PMT_NIL, PMT_NIL))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_cons(a, b))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list1(a))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list2(a, b))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list3(a, b, c))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list3(a, pmt_list3(c, b, a), c))); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_T)); + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_F)); + + CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_EOF)); // last item + + + // FIXME add tests for real, complex, vector, uniform-vector, dict + // FIXME add tests for malformed input too. + +} + +void +qa_pmt_prims::test_sets() +{ + pmt_t s1 = pmt_intern("s1"); + pmt_t s2 = pmt_intern("s2"); + pmt_t s3 = pmt_intern("s3"); + + pmt_t l1 = pmt_list1(s1); + pmt_t l2 = pmt_list2(s2,s3); + pmt_t l3 = pmt_list3(s1,s2,s3); + + CPPUNIT_ASSERT(pmt_is_pair(pmt_memq(s1,l1))); + CPPUNIT_ASSERT(pmt_is_false(pmt_memq(s3,l1))); + + CPPUNIT_ASSERT(pmt_subsetp(l1,l3)); + CPPUNIT_ASSERT(pmt_subsetp(l2,l3)); + CPPUNIT_ASSERT(!pmt_subsetp(l1,l2)); + CPPUNIT_ASSERT(!pmt_subsetp(l2,l1)); + CPPUNIT_ASSERT(!pmt_subsetp(l3,l2)); +} diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h new file mode 100644 index 000000000..effb3a097 --- /dev/null +++ b/gruel/src/lib/pmt/qa_pmt_prims.h @@ -0,0 +1,67 @@ +/* -*- 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. + */ +#ifndef INCLUDED_QA_PMT_PRIMS_H +#define INCLUDED_QA_PMT_PRIMS_H + +#include +#include + +class qa_pmt_prims : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE(qa_pmt_prims); + CPPUNIT_TEST(test_symbols); + CPPUNIT_TEST(test_booleans); + CPPUNIT_TEST(test_integers); + CPPUNIT_TEST(test_reals); + CPPUNIT_TEST(test_complexes); + CPPUNIT_TEST(test_pairs); + CPPUNIT_TEST(test_vectors); + CPPUNIT_TEST(test_equivalence); + CPPUNIT_TEST(test_misc); + CPPUNIT_TEST(test_dict); + CPPUNIT_TEST(test_any); + CPPUNIT_TEST(test_io); + CPPUNIT_TEST(test_lists); + CPPUNIT_TEST(test_serialize); + CPPUNIT_TEST(test_sets); + CPPUNIT_TEST_SUITE_END(); + + private: + void test_symbols(); + void test_booleans(); + void test_integers(); + void test_reals(); + void test_complexes(); + void test_pairs(); + void test_vectors(); + void test_equivalence(); + void test_misc(); + void test_dict(); + void test_any(); + void test_io(); + void test_lists(); + void test_serialize(); + void test_sets(); +}; + +#endif /* INCLUDED_QA_PMT_PRIMS_H */ + diff --git a/gruel/src/lib/pmt/test_pmt.cc b/gruel/src/lib/pmt/test_pmt.cc new file mode 100644 index 000000000..034785f4e --- /dev/null +++ b/gruel/src/lib/pmt/test_pmt.cc @@ -0,0 +1,37 @@ +/* -*- 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/pmt/unv_qa_template.cc.t b/gruel/src/lib/pmt/unv_qa_template.cc.t new file mode 100644 index 000000000..1e2c8e8eb --- /dev/null +++ b/gruel/src/lib/pmt/unv_qa_template.cc.t @@ -0,0 +1,35 @@ +void +qa_pmt_unv::test_@TAG@vector() +{ + static const size_t N = 3; + pmt_t v1 = pmt_make_@TAG@vector(N, 0); + CPPUNIT_ASSERT_EQUAL(N, pmt_length(v1)); + @TYPE@ s0 = @TYPE@(10); + @TYPE@ s1 = @TYPE@(20); + @TYPE@ s2 = @TYPE@(30); + + pmt_@TAG@vector_set(v1, 0, s0); + pmt_@TAG@vector_set(v1, 1, s1); + pmt_@TAG@vector_set(v1, 2, s2); + + CPPUNIT_ASSERT_EQUAL(s0, pmt_@TAG@vector_ref(v1, 0)); + CPPUNIT_ASSERT_EQUAL(s1, pmt_@TAG@vector_ref(v1, 1)); + CPPUNIT_ASSERT_EQUAL(s2, pmt_@TAG@vector_ref(v1, 2)); + + CPPUNIT_ASSERT_THROW(pmt_@TAG@vector_ref(v1, N), pmt_out_of_range); + CPPUNIT_ASSERT_THROW(pmt_@TAG@vector_set(v1, N, @TYPE@(0)), pmt_out_of_range); + + size_t len; + const @TYPE@ *rd = pmt_@TAG@vector_elements(v1, len); + CPPUNIT_ASSERT_EQUAL(len, N); + CPPUNIT_ASSERT_EQUAL(s0, rd[0]); + CPPUNIT_ASSERT_EQUAL(s1, rd[1]); + CPPUNIT_ASSERT_EQUAL(s2, rd[2]); + + @TYPE@ *wr = pmt_@TAG@vector_writable_elements(v1, len); + CPPUNIT_ASSERT_EQUAL(len, N); + wr[0] = @TYPE@(0); + CPPUNIT_ASSERT_EQUAL(@TYPE@(0), wr[0]); + CPPUNIT_ASSERT_EQUAL(s1, wr[1]); + CPPUNIT_ASSERT_EQUAL(s2, wr[2]); +} diff --git a/gruel/src/lib/pmt/unv_template.cc.t b/gruel/src/lib/pmt/unv_template.cc.t new file mode 100644 index 000000000..148965c09 --- /dev/null +++ b/gruel/src/lib/pmt/unv_template.cc.t @@ -0,0 +1,122 @@ +//////////////////////////////////////////////////////////////////////////// +// pmt_@TAG@vector +//////////////////////////////////////////////////////////////////////////// + +namespace pmt { + +static pmt_@TAG@vector * +_@TAG@vector(pmt_t x) +{ + return dynamic_cast(x.get()); +} + + +pmt_@TAG@vector::pmt_@TAG@vector(size_t k, @TYPE@ fill) + : d_v(k) +{ + for (size_t i = 0; i < k; i++) + d_v[i] = fill; +} + +pmt_@TAG@vector::pmt_@TAG@vector(size_t k, const @TYPE@ *data) + : d_v(k) +{ + for (size_t i = 0; i < k; i++) + d_v[i] = data[i]; +} + +@TYPE@ +pmt_@TAG@vector::ref(size_t k) const +{ + if (k >= length()) + throw pmt_out_of_range("pmt_@TAG@vector_ref", pmt_from_long(k)); + return d_v[k]; +} + +void +pmt_@TAG@vector::set(size_t k, @TYPE@ x) +{ + if (k >= length()) + throw pmt_out_of_range("pmt_@TAG@vector_set", pmt_from_long(k)); + d_v[k] = x; +} + +const @TYPE@ * +pmt_@TAG@vector::elements(size_t &len) +{ + len = length(); + return &d_v[0]; +} + +@TYPE@ * +pmt_@TAG@vector::writable_elements(size_t &len) +{ + len = length(); + return &d_v[0]; +} + +const void* +pmt_@TAG@vector::uniform_elements(size_t &len) +{ + len = length() * sizeof(@TYPE@); + return &d_v[0]; +} + +void* +pmt_@TAG@vector::uniform_writable_elements(size_t &len) +{ + len = length() * sizeof(@TYPE@); + return &d_v[0]; +} + +bool +pmt_is_@TAG@vector(pmt_t obj) +{ + return obj->is_@TAG@vector(); +} + +pmt_t +pmt_make_@TAG@vector(size_t k, @TYPE@ fill) +{ + return pmt_t(new pmt_@TAG@vector(k, fill)); +} + +pmt_t +pmt_init_@TAG@vector(size_t k, const @TYPE@ *data) +{ + return pmt_t(new pmt_@TAG@vector(k, data)); +} + +@TYPE@ +pmt_@TAG@vector_ref(pmt_t vector, size_t k) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_ref", vector); + return _@TAG@vector(vector)->ref(k); +} + +void +pmt_@TAG@vector_set(pmt_t vector, size_t k, @TYPE@ obj) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_set", vector); + _@TAG@vector(vector)->set(k, obj); +} + +const @TYPE@ * +pmt_@TAG@vector_elements(pmt_t vector, size_t &len) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_elements", vector); + return _@TAG@vector(vector)->elements(len); +} + +@TYPE@ * +pmt_@TAG@vector_writable_elements(pmt_t vector, size_t &len) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_writable_elements", vector); + return _@TAG@vector(vector)->writable_elements(len); +} + +} /* namespace pmt */ diff --git a/gruel/src/lib/pmt/unv_template.h.t b/gruel/src/lib/pmt/unv_template.h.t new file mode 100644 index 000000000..83ba0be0f --- /dev/null +++ b/gruel/src/lib/pmt/unv_template.h.t @@ -0,0 +1,23 @@ + +//////////////////////////////////////////////////////////////////////////// +// pmt_@TAG@vector +//////////////////////////////////////////////////////////////////////////// + +class pmt_@TAG@vector : public pmt_uniform_vector +{ + std::vector< @TYPE@ > d_v; + +public: + pmt_@TAG@vector(size_t k, @TYPE@ fill); + pmt_@TAG@vector(size_t k, const @TYPE@ *data); + // ~pmt_@TAG@vector(); + + bool is_@TAG@vector() const { return true; } + size_t length() const { return d_v.size(); } + @TYPE@ ref(size_t k) const; + void set(size_t k, @TYPE@ x); + const @TYPE@ *elements(size_t &len); + @TYPE@ *writable_elements(size_t &len); + const void *uniform_elements(size_t &len); + void *uniform_writable_elements(size_t &len); +}; diff --git a/gruel/src/lib/pmt_int.h b/gruel/src/lib/pmt_int.h deleted file mode 100644 index 03f0e555c..000000000 --- a/gruel/src/lib/pmt_int.h +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- 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. - */ -#ifndef INCLUDED_PMT_INT_H -#define INCLUDED_PMT_INT_H - -#include -#include - -/* - * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION! - * - * See pmt.h for the public interface - */ - -#define PMT_LOCAL_ALLOCATOR 0 // define to 0 or 1 -namespace gruel { - -class pmt_base : boost::noncopyable { -protected: - pmt_base(){}; - virtual ~pmt_base(); - -public: - virtual bool is_bool() const { return false; } - virtual bool is_symbol() const { return false; } - virtual bool is_number() const { return false; } - virtual bool is_integer() const { return false; } - virtual bool is_real() const { return false; } - virtual bool is_complex() const { return false; } - virtual bool is_null() const { return false; } - virtual bool is_pair() const { return false; } - virtual bool is_vector() const { return false; } - virtual bool is_dict() const { return false; } - virtual bool is_any() const { return false; } - - virtual bool is_uniform_vector() const { return false; } - virtual bool is_u8vector() const { return false; } - virtual bool is_s8vector() const { return false; } - virtual bool is_u16vector() const { return false; } - virtual bool is_s16vector() const { return false; } - virtual bool is_u32vector() const { return false; } - virtual bool is_s32vector() const { return false; } - virtual bool is_u64vector() const { return false; } - virtual bool is_s64vector() const { return false; } - virtual bool is_f32vector() const { return false; } - virtual bool is_f64vector() const { return false; } - virtual bool is_c32vector() const { return false; } - virtual bool is_c64vector() const { return false; } - -# if (PMT_LOCAL_ALLOCATOR) - void *operator new(size_t); - void operator delete(void *, size_t); -#endif -}; - -class pmt_bool : public pmt_base -{ -public: - pmt_bool(); - //~pmt_bool(){} - - bool is_bool() const { return true; } -}; - - -class pmt_symbol : public pmt_base -{ - std::string d_name; - pmt_t d_next; - -public: - pmt_symbol(const std::string &name); - //~pmt_symbol(){} - - bool is_symbol() const { return true; } - const std::string name() { return d_name; } - - pmt_t next() { return d_next; } // symbol table link - void set_next(pmt_t next) { d_next = next; } -}; - -class pmt_integer : public pmt_base -{ - long d_value; - -public: - pmt_integer(long value); - //~pmt_integer(){} - - bool is_number() const { return true; } - bool is_integer() const { return true; } - long value() const { return d_value; } -}; - -class pmt_real : public pmt_base -{ - double d_value; - -public: - pmt_real(double value); - //~pmt_real(){} - - bool is_number() const { return true; } - bool is_real() const { return true; } - double value() const { return d_value; } -}; - -class pmt_complex : public pmt_base -{ - std::complex d_value; - -public: - pmt_complex(std::complex value); - //~pmt_complex(){} - - bool is_number() const { return true; } - bool is_complex() const { return true; } - std::complex value() const { return d_value; } -}; - -class pmt_null : public pmt_base -{ -public: - pmt_null(); - //~pmt_null(){} - - bool is_null() const { return true; } -}; - -class pmt_pair : public pmt_base -{ - pmt_t d_car; - pmt_t d_cdr; - -public: - pmt_pair(const pmt_t& car, const pmt_t& cdr); - //~pmt_pair(){}; - - bool is_pair() const { return true; } - pmt_t car() const { return d_car; } - pmt_t cdr() const { return d_cdr; } - - void set_car(pmt_t car) { d_car = car; } - void set_cdr(pmt_t cdr) { d_cdr = cdr; } -}; - -class pmt_vector : public pmt_base -{ - std::vector d_v; - -public: - pmt_vector(size_t len, pmt_t fill); - //~pmt_vector(); - - bool is_vector() const { return true; } - pmt_t ref(size_t k) const; - void set(size_t k, pmt_t obj); - void fill(pmt_t fill); - size_t length() const { return d_v.size(); } - - pmt_t _ref(size_t k) const { return d_v[k]; } -}; - -class pmt_dict : public pmt_base -{ - pmt_t d_alist; // list of (key . value) pairs - -public: - pmt_dict(); - //~pmt_dict(); - - bool is_dict() const { return true; } - void set(pmt_t key, pmt_t value); - pmt_t ref(pmt_t key, pmt_t default_value) const; - bool has_key(pmt_t key) const; - pmt_t items() const; - pmt_t keys() const; - pmt_t values() const; -}; - -class pmt_any : public pmt_base -{ - boost::any d_any; - -public: - pmt_any(const boost::any &any); - //~pmt_any(); - - bool is_any() const { return true; } - const boost::any &ref() const { return d_any; } - void set(const boost::any &any) { d_any = any; } -}; - - -class pmt_uniform_vector : public pmt_base -{ -public: - bool is_uniform_vector() const { return true; } - virtual const void *uniform_elements(size_t &len) = 0; - virtual void *uniform_writable_elements(size_t &len) = 0; - virtual size_t length() const = 0; -}; - -#include "pmt_unv_int.h" - -} /* namespace gruel */ - -#endif /* INCLUDED_PMT_INT_H */ diff --git a/gruel/src/lib/pmt_io.cc b/gruel/src/lib/pmt_io.cc deleted file mode 100644 index e10ea7814..000000000 --- a/gruel/src/lib/pmt_io.cc +++ /dev/null @@ -1,141 +0,0 @@ -/* -*- 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 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 -#endif -#include -#include -#include "pmt_int.h" -#include - -namespace gruel { - -static void -pmt_write_list_tail(pmt_t obj, std::ostream &port) -{ - pmt_write(pmt_car(obj), port); // write the car - obj = pmt_cdr(obj); // step to cdr - - if (pmt_is_null(obj)) // () - port << ")"; - - else if (pmt_is_pair(obj)){ // normal list - port << " "; - pmt_write_list_tail(obj, port); - } - else { // dotted pair - port << " . "; - pmt_write(obj, port); - port << ")"; - } -} - -void -pmt_write(pmt_t obj, std::ostream &port) -{ - if (pmt_is_bool(obj)){ - if (pmt_is_true(obj)) - port << "#t"; - else - port << "#f"; - } - else if (pmt_is_symbol(obj)){ - port << pmt_symbol_to_string(obj); - } - else if (pmt_is_number(obj)){ - if (pmt_is_integer(obj)) - port << pmt_to_long(obj); - else if (pmt_is_real(obj)) - port << pmt_to_double(obj); - else if (pmt_is_complex(obj)){ - std::complex c = pmt_to_complex(obj); - port << c.real() << '+' << c.imag() << 'i'; - } - else - goto error; - } - else if (pmt_is_null(obj)){ - port << "()"; - } - else if (pmt_is_pair(obj)){ - port << "("; - pmt_write_list_tail(obj, port); - } - else if (pmt_is_dict(obj)){ - // FIXME - // port << "#"; - port << "#"; - } - else if (pmt_is_vector(obj)){ - // FIXME - // port << "#"; - port << "#"; - } - else if (pmt_is_uniform_vector(obj)){ - // FIXME - // port << "#"; - port << "#"; - } - else { - error: - // FIXME - // port << "#<" << obj << ">"; - port << "#"; - } -} - -std::ostream& operator<<(std::ostream &os, pmt_t obj) -{ - pmt_write(obj, os); - return os; -} - -std::string -pmt_write_string(pmt_t obj) -{ - std::ostringstream s; - s << obj; - return s.str(); -} - -pmt_t -pmt_read(std::istream &port) -{ - throw pmt_notimplemented("notimplemented: pmt_read", PMT_NIL); -} - -void -pmt_serialize(pmt_t obj, std::ostream &sink) -{ - throw pmt_notimplemented("notimplemented: pmt_serialize", obj); -} - -/*! - * \brief Create obj from portable byte-serial representation - */ -pmt_t -pmt_deserialize(std::istream &source) -{ - throw pmt_notimplemented("notimplemented: pmt_deserialize", PMT_NIL); -} - -} /* namespace gruel */ diff --git a/gruel/src/lib/pmt_pool.cc b/gruel/src/lib/pmt_pool.cc deleted file mode 100644 index 79a22ea73..000000000 --- a/gruel/src/lib/pmt_pool.cc +++ /dev/null @@ -1,112 +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 -#endif -#include -#include -#include - -namespace gruel { - -static inline size_t -ROUNDUP(size_t x, size_t stride) -{ - return ((((x) + (stride) - 1)/(stride)) * (stride)); -} - -pmt_pool::pmt_pool(size_t itemsize, size_t alignment, - size_t allocation_size, size_t max_items) - : d_itemsize(ROUNDUP(itemsize, alignment)), - d_alignment(alignment), - d_allocation_size(std::max(allocation_size, 16 * itemsize)), - d_max_items(max_items), d_n_items(0), - d_freelist(0) -{ -} - -pmt_pool::~pmt_pool() -{ - for (unsigned int i = 0; i < d_allocations.size(); i++){ - delete [] d_allocations[i]; - } -} - -void * -pmt_pool::malloc() -{ - scoped_lock guard(d_mutex); - item *p; - - if (d_max_items != 0){ - while (d_n_items >= d_max_items) - d_cond.wait(guard); - } - - if (d_freelist){ // got something? - p = d_freelist; - d_freelist = p->d_next; - d_n_items++; - return p; - } - - // allocate a new chunk - char *alloc = new char[d_allocation_size + d_alignment - 1]; - d_allocations.push_back(alloc); - - // get the alignment we require - char *start = (char *)(((uintptr_t)alloc + d_alignment-1) & -d_alignment); - char *end = alloc + d_allocation_size + d_alignment - 1; - size_t n = (end - start) / d_itemsize; - - // link the new items onto the free list. - p = (item *) start; - for (size_t i = 0; i < n; i++){ - p->d_next = d_freelist; - d_freelist = p; - p = (item *)((char *) p + d_itemsize); - } - - // now return the first one - p = d_freelist; - d_freelist = p->d_next; - d_n_items++; - return p; -} - -void -pmt_pool::free(void *foo) -{ - if (!foo) - return; - - scoped_lock guard(d_mutex); - - item *p = (item *) foo; - p->d_next = d_freelist; - d_freelist = p; - d_n_items--; - if (d_max_items != 0) - d_cond.notify_one(); -} - -} /* namespace gruel */ diff --git a/gruel/src/lib/pmt_serialize.cc b/gruel/src/lib/pmt_serialize.cc deleted file mode 100644 index b7193e811..000000000 --- a/gruel/src/lib/pmt_serialize.cc +++ /dev/null @@ -1,357 +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 -#endif -#include -#include -#include "pmt_int.h" -#include "gruel/pmt_serial_tags.h" - -namespace gruel { - -static pmt_t parse_pair(std::streambuf &sb); - -// ---------------------------------------------------------------- -// output primitives -// ---------------------------------------------------------------- - -static bool -serialize_untagged_u8(unsigned int i, std::streambuf &sb) -{ - return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); -} - -// always writes big-endian -static bool -serialize_untagged_u16(unsigned int i, std::streambuf &sb) -{ - sb.sputc((i >> 8) & 0xff); - return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); -} - -// always writes big-endian -static bool -serialize_untagged_u32(unsigned int i, std::streambuf &sb) -{ - sb.sputc((i >> 24) & 0xff); - sb.sputc((i >> 16) & 0xff); - sb.sputc((i >> 8) & 0xff); - return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); -} - -#if 0 -// always writes big-endian -static bool -serialize_untagged_u64(uint64_t i, std::streambuf &sb) -{ - sb.sputc((i >> 56) & 0xff); - sb.sputc((i >> 48) & 0xff); - sb.sputc((i >> 40) & 0xff); - sb.sputc((i >> 32) & 0xff); - sb.sputc((i >> 24) & 0xff); - sb.sputc((i >> 16) & 0xff); - sb.sputc((i >> 8) & 0xff); - return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); -} -#endif - -// ---------------------------------------------------------------- -// input primitives -// ---------------------------------------------------------------- - - -// always reads big-endian -static bool -deserialize_untagged_u8(uint8_t *ip, std::streambuf &sb) -{ - std::streambuf::traits_type::int_type t; - int i; - - t = sb.sbumpc(); - i = t & 0xff; - - *ip = i; - return t != std::streambuf::traits_type::eof(); -} - -// always reads big-endian -static bool -deserialize_untagged_u16(uint16_t *ip, std::streambuf &sb) -{ - std::streambuf::traits_type::int_type t; - int i; - - t = sb.sbumpc(); - i = t & 0xff; - - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - - *ip = i; - return t != std::streambuf::traits_type::eof(); -} - -// always reads big-endian -static bool -deserialize_untagged_u32(uint32_t *ip, std::streambuf &sb) -{ - std::streambuf::traits_type::int_type t; - int i; - - t = sb.sbumpc(); - i = t & 0xff; - - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - - *ip = i; - return t != std::streambuf::traits_type::eof(); -} - -#if 0 -// always reads big-endian -static bool -deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb) -{ - std::streambuf::traits_type::int_type t; - uint64_t i; - - t = sb.sbumpc(); - i = t & 0xff; - - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - t = sb.sbumpc(); - i = (i << 8) | (t & 0xff); - - *ip = i; - return t != std::streambuf::traits_type::eof(); -} -#endif - -/* - * Write portable byte-serial representation of \p obj to \p sb - * - * N.B., Circular structures cause infinite recursion. - */ -bool -pmt_serialize(pmt_t obj, std::streambuf &sb) -{ - bool ok = true; - - tail_recursion: - - if (pmt_is_bool(obj)){ - if (pmt_eq(obj, PMT_T)) - return serialize_untagged_u8(PST_TRUE, sb); - else - return serialize_untagged_u8(PST_FALSE, sb); - } - - if (pmt_is_null(obj)) - return serialize_untagged_u8(PST_NULL, sb); - - if (pmt_is_symbol(obj)){ - const std::string s = pmt_symbol_to_string(obj); - size_t len = s.size(); - ok = serialize_untagged_u8(PST_SYMBOL, sb); - ok &= serialize_untagged_u16(len, sb); - for (size_t i = 0; i < len; i++) - ok &= serialize_untagged_u8(s[i], sb); - return ok; - } - - if (pmt_is_pair(obj)){ - ok = serialize_untagged_u8(PST_PAIR, sb); - ok &= pmt_serialize(pmt_car(obj), sb); - if (!ok) - return false; - obj = pmt_cdr(obj); - goto tail_recursion; - } - - if (pmt_is_number(obj)){ - - if (pmt_is_integer(obj)){ - long i = pmt_to_long(obj); - if (sizeof(long) > 4){ - if (i < -2147483647 || i > 2147483647) - throw pmt_notimplemented("pmt_serialize (64-bit integers)", obj); - } - ok = serialize_untagged_u8(PST_INT32, sb); - ok &= serialize_untagged_u32(i, sb); - return ok; - } - - if (pmt_is_real(obj)) - throw pmt_notimplemented("pmt_serialize (real)", obj); - - if (pmt_is_complex(obj)) - throw pmt_notimplemented("pmt_serialize (complex)", obj); - } - - if (pmt_is_vector(obj)) - throw pmt_notimplemented("pmt_serialize (vector)", obj); - - if (pmt_is_uniform_vector(obj)) - throw pmt_notimplemented("pmt_serialize (uniform-vector)", obj); - - if (pmt_is_dict(obj)) - throw pmt_notimplemented("pmt_serialize (dict)", obj); - - - throw pmt_notimplemented("pmt_serialize (?)", obj); -} - -/* - * Create obj from portable byte-serial representation - * - * Returns next obj from streambuf, or PMT_EOF at end of file. - * Throws exception on malformed input. - */ -pmt_t -pmt_deserialize(std::streambuf &sb) -{ - uint8_t tag; - //uint8_t u8; - uint16_t u16; - uint32_t u32; - //uint32_t u64; - static char tmpbuf[1024]; - - if (!deserialize_untagged_u8(&tag, sb)) - return PMT_EOF; - - switch (tag){ - case PST_TRUE: - return PMT_T; - - case PST_FALSE: - return PMT_F; - - case PST_NULL: - return PMT_NIL; - - case PST_SYMBOL: - if (!deserialize_untagged_u16(&u16, sb)) - goto error; - if (u16 > sizeof(tmpbuf)) - throw pmt_notimplemented("pmt_deserialize: very long symbol", - PMT_F); - if (sb.sgetn(tmpbuf, u16) != u16) - goto error; - return pmt_intern(std::string(tmpbuf, u16)); - - case PST_INT32: - if (!deserialize_untagged_u32(&u32, sb)) - goto error; - return pmt_from_long((int32_t) u32); - - case PST_PAIR: - return parse_pair(sb); - - case PST_DOUBLE: - case PST_COMPLEX: - case PST_VECTOR: - case PST_DICT: - case PST_UNIFORM_VECTOR: - case PST_COMMENT: - throw pmt_notimplemented("pmt_deserialize: tag value = ", - pmt_from_long(tag)); - - default: - throw pmt_exception("pmt_deserialize: malformed input stream, tag value = ", - pmt_from_long(tag)); - } - - error: - throw pmt_exception("pmt_deserialize: malformed input stream", PMT_F); -} - -/* - * This is a mostly non-recursive implementation that allows us to - * deserialize very long lists w/o exhausting the evaluation stack. - * - * On entry we've already eaten the PST_PAIR tag. - */ -pmt_t -parse_pair(std::streambuf &sb) -{ - uint8_t tag; - pmt_t val, expr, lastnptr, nptr; - - // - // Keep appending nodes until we get a non-PAIR cdr. - // - lastnptr = PMT_NIL; - while (1){ - expr = pmt_deserialize(sb); // read the car - - nptr = pmt_cons(expr, PMT_NIL); // build new cell - if (pmt_is_null(lastnptr)) - val = nptr; - else - pmt_set_cdr(lastnptr, nptr); - lastnptr = nptr; - - if (!deserialize_untagged_u8(&tag, sb)) // get tag of cdr - throw pmt_exception("pmt_deserialize: malformed input stream", PMT_F); - - if (tag == PST_PAIR) - continue; // keep on looping... - - if (tag == PST_NULL){ - expr = PMT_NIL; - break; - } - - // - // default: push tag back and use pmt_deserialize to get the cdr - // - sb.sungetc(); - expr = pmt_deserialize(sb); - break; - } - - // - // At this point, expr contains the value of the final cdr in the list. - // - pmt_set_cdr(lastnptr, expr); - return val; -} - -} /* namespace gruel */ diff --git a/gruel/src/lib/qa_pmt.cc b/gruel/src/lib/qa_pmt.cc deleted file mode 100644 index 250befafa..000000000 --- a/gruel/src/lib/qa_pmt.cc +++ /dev/null @@ -1,40 +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., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * This class gathers together all the test cases for pmt into - * a single test suite. As you create new test cases, add them here. - */ - -#include -#include -#include - -CppUnit::TestSuite * -qa_pmt::suite () -{ - CppUnit::TestSuite *s = new CppUnit::TestSuite ("pmt"); - - s->addTest (qa_pmt_prims::suite ()); - s->addTest (qa_pmt_unv::suite ()); - - return s; -} diff --git a/gruel/src/lib/qa_pmt.h b/gruel/src/lib/qa_pmt.h deleted file mode 100644 index 43a6dbf67..000000000 --- a/gruel/src/lib/qa_pmt.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., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_PMT_H -#define INCLUDED_QA_PMT_H - -#include - -//! collect all the tests for pmt - -class qa_pmt { - public: - //! return suite of tests for all of pmt - static CppUnit::TestSuite *suite (); -}; - -#endif /* INCLUDED_QA_PMT_H */ diff --git a/gruel/src/lib/qa_pmt_prims.cc b/gruel/src/lib/qa_pmt_prims.cc deleted file mode 100644 index ac93f8063..000000000 --- a/gruel/src/lib/qa_pmt_prims.cc +++ /dev/null @@ -1,438 +0,0 @@ -/* -*- 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 -#include -#include -#include - -using namespace gruel; - -void -qa_pmt_prims::test_symbols() -{ - CPPUNIT_ASSERT(!pmt_is_symbol(PMT_T)); - CPPUNIT_ASSERT(!pmt_is_symbol(PMT_F)); - CPPUNIT_ASSERT_THROW(pmt_symbol_to_string(PMT_F), pmt_wrong_type); - - pmt_t sym1 = pmt_string_to_symbol("test"); - CPPUNIT_ASSERT(pmt_is_symbol(sym1)); - CPPUNIT_ASSERT_EQUAL(std::string("test"), pmt_symbol_to_string(sym1)); - CPPUNIT_ASSERT(pmt_is_true(sym1)); - CPPUNIT_ASSERT(!pmt_is_false(sym1)); - - pmt_t sym2 = pmt_string_to_symbol("foo"); - pmt_t sym3 = pmt_string_to_symbol("test"); - CPPUNIT_ASSERT_EQUAL(sym1, sym3); - CPPUNIT_ASSERT(sym1 != sym2); - CPPUNIT_ASSERT(sym1 == sym3); - - static const int N = 2048; - std::vector v1(N); - std::vector v2(N); - - // generate a bunch of symbols - for (int i = 0; i < N; i++){ - char buf[100]; - snprintf(buf, sizeof(buf), "test-%d", i); - v1[i] = pmt_string_to_symbol(buf); - } - - // confirm that they are all unique - for (int i = 0; i < N; i++) - for (int j = i + 1; j < N; j++) - CPPUNIT_ASSERT(v1[i] != v1[j]); - - // generate the same symbols again - for (int i = 0; i < N; i++){ - char buf[100]; - snprintf(buf, sizeof(buf), "test-%d", i); - v2[i] = pmt_string_to_symbol(buf); - } - - // confirm that we get the same ones back - for (int i = 0; i < N; i++) - CPPUNIT_ASSERT(v1[i] == v2[i]); -} - -void -qa_pmt_prims::test_booleans() -{ - pmt_t sym = pmt_string_to_symbol("test"); - CPPUNIT_ASSERT(pmt_is_bool(PMT_T)); - CPPUNIT_ASSERT(pmt_is_bool(PMT_F)); - CPPUNIT_ASSERT(!pmt_is_bool(sym)); - CPPUNIT_ASSERT_EQUAL(pmt_from_bool(false), PMT_F); - CPPUNIT_ASSERT_EQUAL(pmt_from_bool(true), PMT_T); - CPPUNIT_ASSERT_EQUAL(false, pmt_to_bool(PMT_F)); - CPPUNIT_ASSERT_EQUAL(true, pmt_to_bool(PMT_T)); - CPPUNIT_ASSERT_THROW(pmt_to_bool(sym), pmt_wrong_type); -} - -void -qa_pmt_prims::test_integers() -{ - pmt_t p1 = pmt_from_long(1); - pmt_t m1 = pmt_from_long(-1); - CPPUNIT_ASSERT(!pmt_is_integer(PMT_T)); - CPPUNIT_ASSERT(pmt_is_integer(p1)); - CPPUNIT_ASSERT(pmt_is_integer(m1)); - CPPUNIT_ASSERT_THROW(pmt_to_long(PMT_T), pmt_wrong_type); - CPPUNIT_ASSERT_EQUAL(-1L, pmt_to_long(m1)); - CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(p1)); -} - -void -qa_pmt_prims::test_reals() -{ - pmt_t p1 = pmt_from_double(1); - pmt_t m1 = pmt_from_double(-1); - CPPUNIT_ASSERT(!pmt_is_real(PMT_T)); - CPPUNIT_ASSERT(pmt_is_real(p1)); - CPPUNIT_ASSERT(pmt_is_real(m1)); - CPPUNIT_ASSERT_THROW(pmt_to_double(PMT_T), pmt_wrong_type); - CPPUNIT_ASSERT_EQUAL(-1.0, pmt_to_double(m1)); - CPPUNIT_ASSERT_EQUAL(1.0, pmt_to_double(p1)); - CPPUNIT_ASSERT_EQUAL(1.0, pmt_to_double(pmt_from_long(1))); -} - -void -qa_pmt_prims::test_complexes() -{ - pmt_t p1 = pmt_make_rectangular(2, -3); - pmt_t m1 = pmt_make_rectangular(-3, 2); - CPPUNIT_ASSERT(!pmt_is_complex(PMT_T)); - CPPUNIT_ASSERT(pmt_is_complex(p1)); - CPPUNIT_ASSERT(pmt_is_complex(m1)); - CPPUNIT_ASSERT_THROW(pmt_to_complex(PMT_T), pmt_wrong_type); - CPPUNIT_ASSERT_EQUAL(std::complex(2, -3), pmt_to_complex(p1)); - CPPUNIT_ASSERT_EQUAL(std::complex(-3, 2), pmt_to_complex(m1)); - CPPUNIT_ASSERT_EQUAL(std::complex(1.0, 0), pmt_to_complex(pmt_from_long(1))); - CPPUNIT_ASSERT_EQUAL(std::complex(1.0, 0), pmt_to_complex(pmt_from_double(1.0))); -} - -void -qa_pmt_prims::test_pairs() -{ - CPPUNIT_ASSERT(pmt_is_null(PMT_NIL)); - CPPUNIT_ASSERT(!pmt_is_pair(PMT_NIL)); - pmt_t s1 = pmt_string_to_symbol("s1"); - pmt_t s2 = pmt_string_to_symbol("s2"); - pmt_t s3 = pmt_string_to_symbol("s3"); - - - CPPUNIT_ASSERT_EQUAL((size_t)0, pmt_length(PMT_NIL)); - CPPUNIT_ASSERT_THROW(pmt_length(s1), pmt_wrong_type); - CPPUNIT_ASSERT_THROW(pmt_length(pmt_from_double(42)), pmt_wrong_type); - - pmt_t c1 = pmt_cons(s1, PMT_NIL); - CPPUNIT_ASSERT(pmt_is_pair(c1)); - CPPUNIT_ASSERT(!pmt_is_pair(s1)); - CPPUNIT_ASSERT_EQUAL(s1, pmt_car(c1)); - CPPUNIT_ASSERT_EQUAL(PMT_NIL, pmt_cdr(c1)); - CPPUNIT_ASSERT_EQUAL((size_t) 1, pmt_length(c1)); - - pmt_t c3 = pmt_cons(s3, PMT_NIL); - pmt_t c2 = pmt_cons(s2, c3); - pmt_set_cdr(c1, c2); - CPPUNIT_ASSERT_EQUAL(c2, pmt_cdr(c1)); - pmt_set_car(c1, s3); - CPPUNIT_ASSERT_EQUAL(s3, pmt_car(c1)); - CPPUNIT_ASSERT_EQUAL((size_t)1, pmt_length(c3)); - CPPUNIT_ASSERT_EQUAL((size_t)2, pmt_length(c2)); - - CPPUNIT_ASSERT_THROW(pmt_cdr(PMT_NIL), pmt_wrong_type); - CPPUNIT_ASSERT_THROW(pmt_car(PMT_NIL), pmt_wrong_type); - CPPUNIT_ASSERT_THROW(pmt_set_car(s1, PMT_NIL), pmt_wrong_type); - CPPUNIT_ASSERT_THROW(pmt_set_cdr(s1, PMT_NIL), pmt_wrong_type); -} - -void -qa_pmt_prims::test_vectors() -{ - static const size_t N = 3; - pmt_t v1 = pmt_make_vector(N, PMT_NIL); - CPPUNIT_ASSERT_EQUAL(N, pmt_length(v1)); - pmt_t s0 = pmt_string_to_symbol("s0"); - pmt_t s1 = pmt_string_to_symbol("s1"); - pmt_t s2 = pmt_string_to_symbol("s2"); - - pmt_vector_set(v1, 0, s0); - pmt_vector_set(v1, 1, s1); - pmt_vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt_vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt_vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt_vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt_vector_ref(v1, N), pmt_out_of_range); - CPPUNIT_ASSERT_THROW(pmt_vector_set(v1, N, PMT_NIL), pmt_out_of_range); - - pmt_vector_fill(v1, s0); - for (size_t i = 0; i < N; i++) - CPPUNIT_ASSERT_EQUAL(s0, pmt_vector_ref(v1, i)); -} - -void -qa_pmt_prims::test_equivalence() -{ - pmt_t s0 = pmt_string_to_symbol("s0"); - pmt_t s1 = pmt_string_to_symbol("s1"); - pmt_t s2 = pmt_string_to_symbol("s2"); - pmt_t list0 = pmt_cons(s0, pmt_cons(s1, pmt_cons(s2, PMT_NIL))); - pmt_t list1 = pmt_cons(s0, pmt_cons(s1, pmt_cons(s2, PMT_NIL))); - pmt_t i0 = pmt_from_long(42); - pmt_t i1 = pmt_from_long(42); - pmt_t r0 = pmt_from_double(42); - pmt_t r1 = pmt_from_double(42); - pmt_t r2 = pmt_from_double(43); - - CPPUNIT_ASSERT(pmt_eq(s0, s0)); - CPPUNIT_ASSERT(!pmt_eq(s0, s1)); - CPPUNIT_ASSERT(pmt_eqv(s0, s0)); - CPPUNIT_ASSERT(!pmt_eqv(s0, s1)); - - CPPUNIT_ASSERT(pmt_eqv(i0, i1)); - CPPUNIT_ASSERT(pmt_eqv(r0, r1)); - CPPUNIT_ASSERT(!pmt_eqv(r0, r2)); - CPPUNIT_ASSERT(!pmt_eqv(i0, r0)); - - CPPUNIT_ASSERT(!pmt_eq(list0, list1)); - CPPUNIT_ASSERT(!pmt_eqv(list0, list1)); - CPPUNIT_ASSERT(pmt_equal(list0, list1)); - - pmt_t v0 = pmt_make_vector(3, s0); - pmt_t v1 = pmt_make_vector(3, s0); - pmt_t v2 = pmt_make_vector(4, s0); - CPPUNIT_ASSERT(!pmt_eqv(v0, v1)); - CPPUNIT_ASSERT(pmt_equal(v0, v1)); - CPPUNIT_ASSERT(!pmt_equal(v0, v2)); - - pmt_vector_set(v0, 0, list0); - pmt_vector_set(v0, 1, list0); - pmt_vector_set(v1, 0, list1); - pmt_vector_set(v1, 1, list1); - CPPUNIT_ASSERT(pmt_equal(v0, v1)); -} - -void -qa_pmt_prims::test_misc() -{ - pmt_t k0 = pmt_string_to_symbol("k0"); - pmt_t k1 = pmt_string_to_symbol("k1"); - pmt_t k2 = pmt_string_to_symbol("k2"); - pmt_t k3 = pmt_string_to_symbol("k3"); - pmt_t v0 = pmt_string_to_symbol("v0"); - pmt_t v1 = pmt_string_to_symbol("v1"); - pmt_t v2 = pmt_string_to_symbol("v2"); - pmt_t p0 = pmt_cons(k0, v0); - pmt_t p1 = pmt_cons(k1, v1); - pmt_t p2 = pmt_cons(k2, v2); - - pmt_t alist = pmt_cons(p0, pmt_cons(p1, pmt_cons(p2, PMT_NIL))); - CPPUNIT_ASSERT(pmt_eq(p1, pmt_assv(k1, alist))); - CPPUNIT_ASSERT(pmt_eq(PMT_F, pmt_assv(k3, alist))); - - pmt_t keys = pmt_cons(k0, pmt_cons(k1, pmt_cons(k2, PMT_NIL))); - pmt_t vals = pmt_cons(v0, pmt_cons(v1, pmt_cons(v2, PMT_NIL))); - CPPUNIT_ASSERT(pmt_equal(keys, pmt_map(pmt_car, alist))); - CPPUNIT_ASSERT(pmt_equal(vals, pmt_map(pmt_cdr, alist))); -} - -void -qa_pmt_prims::test_dict() -{ - pmt_t dict = pmt_make_dict(); - CPPUNIT_ASSERT(pmt_is_dict(dict)); - - pmt_t k0 = pmt_string_to_symbol("k0"); - pmt_t k1 = pmt_string_to_symbol("k1"); - pmt_t k2 = pmt_string_to_symbol("k2"); - pmt_t k3 = pmt_string_to_symbol("k3"); - pmt_t v0 = pmt_string_to_symbol("v0"); - pmt_t v1 = pmt_string_to_symbol("v1"); - pmt_t v2 = pmt_string_to_symbol("v2"); - pmt_t v3 = pmt_string_to_symbol("v3"); - pmt_t not_found = pmt_cons(PMT_NIL, PMT_NIL); - - CPPUNIT_ASSERT(!pmt_dict_has_key(dict, k0)); - pmt_dict_set(dict, k0, v0); - CPPUNIT_ASSERT(pmt_dict_has_key(dict, k0)); - CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k0, not_found), v0)); - CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), not_found)); - pmt_dict_set(dict, k1, v1); - pmt_dict_set(dict, k2, v2); - CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), v1)); - pmt_dict_set(dict, k1, v3); - CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), v3)); - - pmt_t keys = pmt_cons(k2, pmt_cons(k1, pmt_cons(k0, PMT_NIL))); - pmt_t vals = pmt_cons(v2, pmt_cons(v3, pmt_cons(v0, PMT_NIL))); - CPPUNIT_ASSERT(pmt_equal(keys, pmt_dict_keys(dict))); - CPPUNIT_ASSERT(pmt_equal(vals, pmt_dict_values(dict))); -} - -void -qa_pmt_prims::test_io() -{ - pmt_t k0 = pmt_string_to_symbol("k0"); - pmt_t k1 = pmt_string_to_symbol("k1"); - pmt_t k2 = pmt_string_to_symbol("k2"); - pmt_t k3 = pmt_string_to_symbol("k3"); - - CPPUNIT_ASSERT_EQUAL(std::string("k0"), pmt_write_string(k0)); -} - -void -qa_pmt_prims::test_lists() -{ - pmt_t s0 = pmt_intern("s0"); - pmt_t s1 = pmt_intern("s1"); - pmt_t s2 = pmt_intern("s2"); - pmt_t s3 = pmt_intern("s3"); - - pmt_t l1 = pmt_list4(s0, s1, s2, s3); - pmt_t l2 = pmt_list3(s0, s1, s2); - pmt_t l3 = pmt_list_add(l2, s3); - CPPUNIT_ASSERT(pmt_equal(l1, l3)); -} - -// ------------------------------------------------------------------------ - -// class foo is used in test_any below. -// It can't be declared in the scope of test_any because of template -// namespace problems. - -class foo { -public: - double d_double; - int d_int; - foo(double d=0, int i=0) : d_double(d), d_int(i) {} -}; - -bool operator==(const foo &a, const foo &b) -{ - return a.d_double == b.d_double && a.d_int == b.d_int; -} - -std::ostream& operator<<(std::ostream &os, const foo obj) -{ - os << ""; - return os; -} - -void -qa_pmt_prims::test_any() -{ - boost::any a0; - boost::any a1; - boost::any a2; - - a0 = std::string("Hello!"); - a1 = 42; - a2 = foo(3.250, 21); - - pmt_t p0 = pmt_make_any(a0); - pmt_t p1 = pmt_make_any(a1); - pmt_t p2 = pmt_make_any(a2); - - CPPUNIT_ASSERT_EQUAL(std::string("Hello!"), - boost::any_cast(pmt_any_ref(p0))); - - CPPUNIT_ASSERT_EQUAL(42, - boost::any_cast(pmt_any_ref(p1))); - - CPPUNIT_ASSERT_EQUAL(foo(3.250, 21), - boost::any_cast(pmt_any_ref(p2))); -} - -// ------------------------------------------------------------------------ - -void -qa_pmt_prims::test_serialize() -{ - std::stringbuf sb; // fake channel - pmt_t a = pmt_intern("a"); - pmt_t b = pmt_intern("b"); - pmt_t c = pmt_intern("c"); - - sb.str(""); // reset channel to empty - - // write stuff to channel - - pmt_serialize(PMT_NIL, sb); - pmt_serialize(pmt_intern("foobarvia"), sb); - pmt_serialize(pmt_from_long(123456789), sb); - pmt_serialize(pmt_from_long(-123456789), sb); - pmt_serialize(pmt_cons(PMT_NIL, PMT_NIL), sb); - pmt_serialize(pmt_cons(a, b), sb); - pmt_serialize(pmt_list1(a), sb); - pmt_serialize(pmt_list2(a, b), sb); - pmt_serialize(pmt_list3(a, b, c), sb); - pmt_serialize(pmt_list3(a, pmt_list3(c, b, a), c), sb); - pmt_serialize(PMT_T, sb); - pmt_serialize(PMT_F, sb); - - // read it back - - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_NIL)); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_intern("foobarvia"))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_from_long(123456789))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_from_long(-123456789))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_cons(PMT_NIL, PMT_NIL))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_cons(a, b))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list1(a))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list2(a, b))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list3(a, b, c))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_list3(a, pmt_list3(c, b, a), c))); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_T)); - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_F)); - - CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_EOF)); // last item - - - // FIXME add tests for real, complex, vector, uniform-vector, dict - // FIXME add tests for malformed input too. - -} - -void -qa_pmt_prims::test_sets() -{ - pmt_t s1 = pmt_intern("s1"); - pmt_t s2 = pmt_intern("s2"); - pmt_t s3 = pmt_intern("s3"); - - pmt_t l1 = pmt_list1(s1); - pmt_t l2 = pmt_list2(s2,s3); - pmt_t l3 = pmt_list3(s1,s2,s3); - - CPPUNIT_ASSERT(pmt_is_pair(pmt_memq(s1,l1))); - CPPUNIT_ASSERT(pmt_is_false(pmt_memq(s3,l1))); - - CPPUNIT_ASSERT(pmt_subsetp(l1,l3)); - CPPUNIT_ASSERT(pmt_subsetp(l2,l3)); - CPPUNIT_ASSERT(!pmt_subsetp(l1,l2)); - CPPUNIT_ASSERT(!pmt_subsetp(l2,l1)); - CPPUNIT_ASSERT(!pmt_subsetp(l3,l2)); -} diff --git a/gruel/src/lib/qa_pmt_prims.h b/gruel/src/lib/qa_pmt_prims.h deleted file mode 100644 index effb3a097..000000000 --- a/gruel/src/lib/qa_pmt_prims.h +++ /dev/null @@ -1,67 +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. - */ -#ifndef INCLUDED_QA_PMT_PRIMS_H -#define INCLUDED_QA_PMT_PRIMS_H - -#include -#include - -class qa_pmt_prims : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_pmt_prims); - CPPUNIT_TEST(test_symbols); - CPPUNIT_TEST(test_booleans); - CPPUNIT_TEST(test_integers); - CPPUNIT_TEST(test_reals); - CPPUNIT_TEST(test_complexes); - CPPUNIT_TEST(test_pairs); - CPPUNIT_TEST(test_vectors); - CPPUNIT_TEST(test_equivalence); - CPPUNIT_TEST(test_misc); - CPPUNIT_TEST(test_dict); - CPPUNIT_TEST(test_any); - CPPUNIT_TEST(test_io); - CPPUNIT_TEST(test_lists); - CPPUNIT_TEST(test_serialize); - CPPUNIT_TEST(test_sets); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_symbols(); - void test_booleans(); - void test_integers(); - void test_reals(); - void test_complexes(); - void test_pairs(); - void test_vectors(); - void test_equivalence(); - void test_misc(); - void test_dict(); - void test_any(); - void test_io(); - void test_lists(); - void test_serialize(); - void test_sets(); -}; - -#endif /* INCLUDED_QA_PMT_PRIMS_H */ - diff --git a/gruel/src/lib/test_pmt.cc b/gruel/src/lib/test_pmt.cc deleted file mode 100644 index 034785f4e..000000000 --- a/gruel/src/lib/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/unv_qa_template.cc.t b/gruel/src/lib/unv_qa_template.cc.t deleted file mode 100644 index 1e2c8e8eb..000000000 --- a/gruel/src/lib/unv_qa_template.cc.t +++ /dev/null @@ -1,35 +0,0 @@ -void -qa_pmt_unv::test_@TAG@vector() -{ - static const size_t N = 3; - pmt_t v1 = pmt_make_@TAG@vector(N, 0); - CPPUNIT_ASSERT_EQUAL(N, pmt_length(v1)); - @TYPE@ s0 = @TYPE@(10); - @TYPE@ s1 = @TYPE@(20); - @TYPE@ s2 = @TYPE@(30); - - pmt_@TAG@vector_set(v1, 0, s0); - pmt_@TAG@vector_set(v1, 1, s1); - pmt_@TAG@vector_set(v1, 2, s2); - - CPPUNIT_ASSERT_EQUAL(s0, pmt_@TAG@vector_ref(v1, 0)); - CPPUNIT_ASSERT_EQUAL(s1, pmt_@TAG@vector_ref(v1, 1)); - CPPUNIT_ASSERT_EQUAL(s2, pmt_@TAG@vector_ref(v1, 2)); - - CPPUNIT_ASSERT_THROW(pmt_@TAG@vector_ref(v1, N), pmt_out_of_range); - CPPUNIT_ASSERT_THROW(pmt_@TAG@vector_set(v1, N, @TYPE@(0)), pmt_out_of_range); - - size_t len; - const @TYPE@ *rd = pmt_@TAG@vector_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - CPPUNIT_ASSERT_EQUAL(s0, rd[0]); - CPPUNIT_ASSERT_EQUAL(s1, rd[1]); - CPPUNIT_ASSERT_EQUAL(s2, rd[2]); - - @TYPE@ *wr = pmt_@TAG@vector_writable_elements(v1, len); - CPPUNIT_ASSERT_EQUAL(len, N); - wr[0] = @TYPE@(0); - CPPUNIT_ASSERT_EQUAL(@TYPE@(0), wr[0]); - CPPUNIT_ASSERT_EQUAL(s1, wr[1]); - CPPUNIT_ASSERT_EQUAL(s2, wr[2]); -} diff --git a/gruel/src/lib/unv_template.cc.t b/gruel/src/lib/unv_template.cc.t deleted file mode 100644 index b19e32d27..000000000 --- a/gruel/src/lib/unv_template.cc.t +++ /dev/null @@ -1,122 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// pmt_@TAG@vector -//////////////////////////////////////////////////////////////////////////// - -namespace gruel { - -static pmt_@TAG@vector * -_@TAG@vector(pmt_t x) -{ - return dynamic_cast(x.get()); -} - - -pmt_@TAG@vector::pmt_@TAG@vector(size_t k, @TYPE@ fill) - : d_v(k) -{ - for (size_t i = 0; i < k; i++) - d_v[i] = fill; -} - -pmt_@TAG@vector::pmt_@TAG@vector(size_t k, const @TYPE@ *data) - : d_v(k) -{ - for (size_t i = 0; i < k; i++) - d_v[i] = data[i]; -} - -@TYPE@ -pmt_@TAG@vector::ref(size_t k) const -{ - if (k >= length()) - throw pmt_out_of_range("pmt_@TAG@vector_ref", pmt_from_long(k)); - return d_v[k]; -} - -void -pmt_@TAG@vector::set(size_t k, @TYPE@ x) -{ - if (k >= length()) - throw pmt_out_of_range("pmt_@TAG@vector_set", pmt_from_long(k)); - d_v[k] = x; -} - -const @TYPE@ * -pmt_@TAG@vector::elements(size_t &len) -{ - len = length(); - return &d_v[0]; -} - -@TYPE@ * -pmt_@TAG@vector::writable_elements(size_t &len) -{ - len = length(); - return &d_v[0]; -} - -const void* -pmt_@TAG@vector::uniform_elements(size_t &len) -{ - len = length() * sizeof(@TYPE@); - return &d_v[0]; -} - -void* -pmt_@TAG@vector::uniform_writable_elements(size_t &len) -{ - len = length() * sizeof(@TYPE@); - return &d_v[0]; -} - -bool -pmt_is_@TAG@vector(pmt_t obj) -{ - return obj->is_@TAG@vector(); -} - -pmt_t -pmt_make_@TAG@vector(size_t k, @TYPE@ fill) -{ - return pmt_t(new pmt_@TAG@vector(k, fill)); -} - -pmt_t -pmt_init_@TAG@vector(size_t k, const @TYPE@ *data) -{ - return pmt_t(new pmt_@TAG@vector(k, data)); -} - -@TYPE@ -pmt_@TAG@vector_ref(pmt_t vector, size_t k) -{ - if (!vector->is_@TAG@vector()) - throw pmt_wrong_type("pmt_@TAG@vector_ref", vector); - return _@TAG@vector(vector)->ref(k); -} - -void -pmt_@TAG@vector_set(pmt_t vector, size_t k, @TYPE@ obj) -{ - if (!vector->is_@TAG@vector()) - throw pmt_wrong_type("pmt_@TAG@vector_set", vector); - _@TAG@vector(vector)->set(k, obj); -} - -const @TYPE@ * -pmt_@TAG@vector_elements(pmt_t vector, size_t &len) -{ - if (!vector->is_@TAG@vector()) - throw pmt_wrong_type("pmt_@TAG@vector_elements", vector); - return _@TAG@vector(vector)->elements(len); -} - -@TYPE@ * -pmt_@TAG@vector_writable_elements(pmt_t vector, size_t &len) -{ - if (!vector->is_@TAG@vector()) - throw pmt_wrong_type("pmt_@TAG@vector_writable_elements", vector); - return _@TAG@vector(vector)->writable_elements(len); -} - -} /* namespace gruel */ diff --git a/gruel/src/lib/unv_template.h.t b/gruel/src/lib/unv_template.h.t deleted file mode 100644 index 83ba0be0f..000000000 --- a/gruel/src/lib/unv_template.h.t +++ /dev/null @@ -1,23 +0,0 @@ - -//////////////////////////////////////////////////////////////////////////// -// pmt_@TAG@vector -//////////////////////////////////////////////////////////////////////////// - -class pmt_@TAG@vector : public pmt_uniform_vector -{ - std::vector< @TYPE@ > d_v; - -public: - pmt_@TAG@vector(size_t k, @TYPE@ fill); - pmt_@TAG@vector(size_t k, const @TYPE@ *data); - // ~pmt_@TAG@vector(); - - bool is_@TAG@vector() const { return true; } - size_t length() const { return d_v.size(); } - @TYPE@ ref(size_t k) const; - void set(size_t k, @TYPE@ x); - const @TYPE@ *elements(size_t &len); - @TYPE@ *writable_elements(size_t &len); - const void *uniform_elements(size_t &len); - void *uniform_writable_elements(size_t &len); -}; -- cgit From d25d747afb4f2bd404720d690677a5401449c0df Mon Sep 17 00:00:00 2001 From: eb Date: Mon, 27 Jul 2009 04:09:21 +0000 Subject: Fix for test_pmt when using --with-boost= git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11504 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/lib/pmt/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/Makefile.am b/gruel/src/lib/pmt/Makefile.am index 5e9f2fac9..2b710a598 100644 --- a/gruel/src/lib/pmt/Makefile.am +++ b/gruel/src/lib/pmt/Makefile.am @@ -64,6 +64,9 @@ libpmt_la_LIBADD = \ $(BOOST_THREAD_LIB) \ -lstdc++ +libpmt_la_LDFLAGS = \ + $(BOOST_LDFLAGS) + noinst_HEADERS = \ $(GENERATED_H) \ pmt_int.h \ -- cgit From 3556ef4080be8b0fe569d28cae6568b761edbd7b Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 1 Aug 2009 14:56:28 +0000 Subject: Merged r11500:11506 from features/msg-passing into trunk. Work-in-progress, passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11524 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/src/include/gruel/Makefile.am | 3 + gruel/src/include/gruel/msg_accepter.h | 42 ++++++++++++ gruel/src/include/gruel/msg_accepter_msgq.h | 48 +++++++++++++ gruel/src/include/gruel/msg_queue.h | 90 ++++++++++++++++++++++++ gruel/src/lib/Makefile.am | 6 +- gruel/src/lib/msg/Makefile.am | 32 +++++++++ gruel/src/lib/msg/msg_accepter.cc | 36 ++++++++++ gruel/src/lib/msg/msg_accepter_msgq.cc | 48 +++++++++++++ gruel/src/lib/msg/msg_queue.cc | 103 ++++++++++++++++++++++++++++ 9 files changed, 405 insertions(+), 3 deletions(-) create mode 100644 gruel/src/include/gruel/msg_accepter.h create mode 100644 gruel/src/include/gruel/msg_accepter_msgq.h create mode 100644 gruel/src/include/gruel/msg_queue.h create mode 100644 gruel/src/lib/msg/Makefile.am create mode 100644 gruel/src/lib/msg/msg_accepter.cc create mode 100644 gruel/src/lib/msg/msg_accepter_msgq.cc create mode 100644 gruel/src/lib/msg/msg_queue.cc (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 622fbc2d3..c38c7fa38 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -28,6 +28,9 @@ gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ $(BUILT_SOURCES) \ + msg_accepter.h \ + msg_accepter_msgq.h \ + msg_queue.h \ pmt.h \ pmt_pool.h \ pmt_serial_tags.h \ diff --git a/gruel/src/include/gruel/msg_accepter.h b/gruel/src/include/gruel/msg_accepter.h new file mode 100644 index 000000000..bc287afae --- /dev/null +++ b/gruel/src/include/gruel/msg_accepter.h @@ -0,0 +1,42 @@ +/* -*- 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_MSG_ACCEPTER_H +#define INCLUDED_MSG_ACCEPTER_H + +#include + +namespace gruel { + + /*! + * \brief Virtual base class that accepts messages + */ + class msg_accepter + { + public: + msg_accepter() {}; + virtual ~msg_accepter(); + + virtual void post(pmt::pmt_t msg) = 0; + }; + +} /* namespace gruel */ + +#endif /* INCLUDED_MSG_ACCEPTER_H */ diff --git a/gruel/src/include/gruel/msg_accepter_msgq.h b/gruel/src/include/gruel/msg_accepter_msgq.h new file mode 100644 index 000000000..b14049d54 --- /dev/null +++ b/gruel/src/include/gruel/msg_accepter_msgq.h @@ -0,0 +1,48 @@ +/* -*- 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_MSG_ACCEPTER_MSGQ_H +#define INCLUDED_MSG_ACCEPTER_MSGQ_H + +#include +#include + +namespace gruel { + + /*! + * \brief Concrete class that accepts messages and inserts them into a message queue. + */ + class msg_accepter_msgq : public msg_accepter + { + msg_queue_sptr d_msg_queue; + + public: + msg_accepter_msgq(msg_queue_sptr msgq); + ~msg_accepter_msgq(); + + void post(pmt::pmt_t msg); + + msg_queue_sptr msg_queue() const { return d_msg_queue; } + }; + +} /* namespace gruel */ + +#endif /* INCLUDED_MSG_ACCEPTER_MSGQ_H */ diff --git a/gruel/src/include/gruel/msg_queue.h b/gruel/src/include/gruel/msg_queue.h new file mode 100644 index 000000000..c24313df6 --- /dev/null +++ b/gruel/src/include/gruel/msg_queue.h @@ -0,0 +1,90 @@ +/* -*- 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_MSG_QUEUE_H +#define INCLUDED_MSG_QUEUE_H + +#include +#include +#include + +namespace gruel { + + class msg_queue; + typedef boost::shared_ptr msg_queue_sptr; + + msg_queue_sptr make_msg_queue(unsigned int limit=0); + + /*! + * \brief thread-safe message queue + */ + class msg_queue { + + gruel::mutex d_mutex; + gruel::condition_variable d_not_empty; + gruel::condition_variable d_not_full; + unsigned int d_limit; // max # of messages in queue. 0 -> unbounded + + std::deque d_msgs; + + public: + msg_queue(unsigned int limit); + ~msg_queue(); + + /*! + * \brief Insert message at tail of queue. + * \param msg message + * + * Block if queue if full. + */ + void insert_tail(pmt::pmt_t msg); + + /*! + * \brief Delete message from head of queue and return it. + * Block if no message is available. + */ + pmt::pmt_t delete_head(); + + /*! + * \brief If there's a message in the q, delete it and return it. + * If no message is available, return pmt_t(). + */ + pmt::pmt_t delete_head_nowait(); + + //! Delete all messages from the queue + void flush(); + + //! is the queue empty? + bool empty_p() const { return d_msgs.empty(); } + + //! is the queue full? + bool full_p() const { return d_limit != 0 && count() >= d_limit; } + + //! return number of messages in queue + unsigned int count() const { return d_msgs.size(); } + + //! return limit on number of message in queue. 0 -> unbounded + unsigned int limit() const { return d_limit; } + }; + +} /* namespace gruel */ + +#endif /* INCLUDED_MSG_QUEUE_H */ diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index bf1ae731a..6dfb6787c 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -21,7 +21,7 @@ include $(top_srcdir)/Makefile.common -SUBDIRS = pmt +SUBDIRS = pmt msg AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) @@ -33,6 +33,7 @@ libgruel_la_LDFLAGS = $(NO_UNDEFINED) $(BOOST_LDFLAGS) -version-info 0:0:0 # ---------------------------------------------------------------- PMT_LIB = pmt/libpmt.la +MSG_LIB = msg/libmsg.la # These are the source files that go into the gruel shared library libgruel_la_SOURCES = \ @@ -44,6 +45,5 @@ libgruel_la_SOURCES = \ libgruel_la_LIBADD = \ $(BOOST_THREAD_LIB) \ $(PMT_LIB) \ + $(MSG_LIB) \ -lstdc++ - - diff --git a/gruel/src/lib/msg/Makefile.am b/gruel/src/lib/msg/Makefile.am new file mode 100644 index 000000000..13a657067 --- /dev/null +++ b/gruel/src/lib/msg/Makefile.am @@ -0,0 +1,32 @@ +# +# 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 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) $(BOOST_CPPFLAGS) $(GRUEL_INCLUDES) $(WITH_INCLUDES) + +noinst_LTLIBRARIES = libmsg.la + +libmsg_la_SOURCES = \ + msg_accepter.cc \ + msg_accepter_msgq.cc \ + msg_queue.cc + diff --git a/gruel/src/lib/msg/msg_accepter.cc b/gruel/src/lib/msg/msg_accepter.cc new file mode 100644 index 000000000..64878f737 --- /dev/null +++ b/gruel/src/lib/msg/msg_accepter.cc @@ -0,0 +1,36 @@ +/* -*- 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +namespace gruel { + + msg_accepter::~msg_accepter() + { + // NOP, required as virtual destructor + } + +} /* namespace gruel */ diff --git a/gruel/src/lib/msg/msg_accepter_msgq.cc b/gruel/src/lib/msg/msg_accepter_msgq.cc new file mode 100644 index 000000000..64fe501d1 --- /dev/null +++ b/gruel/src/lib/msg/msg_accepter_msgq.cc @@ -0,0 +1,48 @@ +/* -*- 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. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include + +using namespace pmt; + +namespace gruel { + + msg_accepter_msgq::msg_accepter_msgq(msg_queue_sptr msgq) + : d_msg_queue(msgq) + { + } + + msg_accepter_msgq::~msg_accepter_msgq() + { + // NOP, required as virtual destructor + } + + void + msg_accepter_msgq::post(pmt_t msg) + { + d_msg_queue->insert_tail(msg); + } + +} /* namespace gruel */ diff --git a/gruel/src/lib/msg/msg_queue.cc b/gruel/src/lib/msg/msg_queue.cc new file mode 100644 index 000000000..8d15f08c5 --- /dev/null +++ b/gruel/src/lib/msg/msg_queue.cc @@ -0,0 +1,103 @@ +/* -*- 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +using namespace pmt; + +namespace gruel { + + msg_queue_sptr + make_msg_queue(unsigned int limit) + { + return msg_queue_sptr(new msg_queue(limit)); + } + + msg_queue::msg_queue(unsigned int limit) + : d_limit(limit) + { + } + + msg_queue::~msg_queue() + { + flush(); + } + + void + msg_queue::insert_tail(pmt_t msg) + { + gruel::scoped_lock guard(d_mutex); + + while (full_p()) + d_not_full.wait(guard); + + d_msgs.push_back(msg); + d_not_empty.notify_one(); + } + + pmt_t + msg_queue::delete_head() + { + gruel::scoped_lock guard(d_mutex); + + while (empty_p()) + d_not_empty.wait(guard); + + pmt_t m(d_msgs.front()); + d_msgs.pop_front(); + + if (d_limit > 0) // Unlimited length queues never block on write + d_not_full.notify_one(); + + return m; + } + + pmt_t + msg_queue::delete_head_nowait() + { + gruel::scoped_lock guard(d_mutex); + + if (empty_p()) + return pmt_t(); + + pmt_t m(d_msgs.front()); + d_msgs.pop_front(); + + if (d_limit > 0) // Unlimited length queues never block on write + d_not_full.notify_one(); + + return m; + } + + void + msg_queue::flush() + { + while (delete_head_nowait() != pmt_t()) + ; + } + +} /* namespace gruel */ -- cgit From f15982950e4674f0cad53d25d36409253661af34 Mon Sep 17 00:00:00 2001 From: git repository hosting Date: Thu, 13 Aug 2009 22:26:53 -0600 Subject: Added git ignore files auto created from svn:ignore properties. --- gruel/.gitignore | 3 +++ gruel/src/.gitignore | 2 ++ gruel/src/include/.gitignore | 2 ++ gruel/src/include/gruel/.gitignore | 4 ++++ gruel/src/lib/.gitignore | 4 ++++ gruel/src/lib/msg/.gitignore | 4 ++++ gruel/src/lib/pmt/.gitignore | 10 ++++++++++ gruel/src/scheme/.gitignore | 8 ++++++++ gruel/src/scheme/gnuradio/.gitignore | 8 ++++++++ 9 files changed, 45 insertions(+) create mode 100644 gruel/.gitignore create mode 100644 gruel/src/.gitignore create mode 100644 gruel/src/include/.gitignore create mode 100644 gruel/src/include/gruel/.gitignore create mode 100644 gruel/src/lib/.gitignore create mode 100644 gruel/src/lib/msg/.gitignore create mode 100644 gruel/src/lib/pmt/.gitignore create mode 100644 gruel/src/scheme/.gitignore create mode 100644 gruel/src/scheme/gnuradio/.gitignore (limited to 'gruel') diff --git a/gruel/.gitignore b/gruel/.gitignore new file mode 100644 index 000000000..ede973f11 --- /dev/null +++ b/gruel/.gitignore @@ -0,0 +1,3 @@ +/Makefile +/Makefile.in +/gruel.pc diff --git a/gruel/src/.gitignore b/gruel/src/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gruel/src/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gruel/src/include/.gitignore b/gruel/src/include/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gruel/src/include/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gruel/src/include/gruel/.gitignore b/gruel/src/include/gruel/.gitignore new file mode 100644 index 000000000..bbe96391c --- /dev/null +++ b/gruel/src/include/gruel/.gitignore @@ -0,0 +1,4 @@ +/Makefile +/Makefile.in +/inet.h +/pmt_serial_tags.h diff --git a/gruel/src/lib/.gitignore b/gruel/src/lib/.gitignore new file mode 100644 index 000000000..89a768d46 --- /dev/null +++ b/gruel/src/lib/.gitignore @@ -0,0 +1,4 @@ +/Makefile +/Makefile.in +/.libs +/.deps diff --git a/gruel/src/lib/msg/.gitignore b/gruel/src/lib/msg/.gitignore new file mode 100644 index 000000000..c026fd667 --- /dev/null +++ b/gruel/src/lib/msg/.gitignore @@ -0,0 +1,4 @@ +/Makefile +/Makefile.in +/.deps +/.libs diff --git a/gruel/src/lib/pmt/.gitignore b/gruel/src/lib/pmt/.gitignore new file mode 100644 index 000000000..035c0316b --- /dev/null +++ b/gruel/src/lib/pmt/.gitignore @@ -0,0 +1,10 @@ +/Makefile +/Makefile.in +/.libs +/.deps +/test_pmt +/qa_pmt_unv.cc +/qa_pmt_unv.h +/pmt_unv_int.h +/pmt_unv.cc +/stamp-sources-generate diff --git a/gruel/src/scheme/.gitignore b/gruel/src/scheme/.gitignore new file mode 100644 index 000000000..a02b6ff73 --- /dev/null +++ b/gruel/src/scheme/.gitignore @@ -0,0 +1,8 @@ +/Makefile +/Makefile.in +/.la +/.lo +/.deps +/.libs +/*.la +/*.lo diff --git a/gruel/src/scheme/gnuradio/.gitignore b/gruel/src/scheme/gnuradio/.gitignore new file mode 100644 index 000000000..a02b6ff73 --- /dev/null +++ b/gruel/src/scheme/gnuradio/.gitignore @@ -0,0 +1,8 @@ +/Makefile +/Makefile.in +/.la +/.lo +/.deps +/.libs +/*.la +/*.lo -- cgit From f67c4ff12f19490d2aeab7ff0fbe0484195037f0 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 1 Aug 2009 09:43:02 -0700 Subject: Added gr_msg_accepter class. gr_msg_accepter derives from gruel::msg_accepter_msgq and will implement in its post() a notification of the destination block thread that a message is pending. Passes distcheck. --- gruel/src/include/gruel/msg_accepter_msgq.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/msg_accepter_msgq.h b/gruel/src/include/gruel/msg_accepter_msgq.h index b14049d54..bf1762e92 100644 --- a/gruel/src/include/gruel/msg_accepter_msgq.h +++ b/gruel/src/include/gruel/msg_accepter_msgq.h @@ -32,13 +32,14 @@ namespace gruel { */ class msg_accepter_msgq : public msg_accepter { + protected: msg_queue_sptr d_msg_queue; public: msg_accepter_msgq(msg_queue_sptr msgq); ~msg_accepter_msgq(); - void post(pmt::pmt_t msg); + virtual void post(pmt::pmt_t msg); msg_queue_sptr msg_queue() const { return d_msg_queue; } }; -- cgit From 1181c2fe069075f9ceb3b66ed937115ff39aafa9 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Thu, 13 Aug 2009 21:50:06 -0700 Subject: Refactored gr_msg_accepter and gr_tpd_thread_body. Redirected gr_msg_accepter::post into gr_block::_post based on dynamic cast. --- gruel/src/include/gruel/Makefile.am | 1 + gruel/src/include/gruel/msg_accepter.h | 13 ++++++--- gruel/src/include/gruel/send.h | 49 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 gruel/src/include/gruel/send.h (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index c38c7fa38..9f50cb619 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -35,6 +35,7 @@ gruelinclude_HEADERS = \ 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_accepter.h b/gruel/src/include/gruel/msg_accepter.h index bc287afae..3afd6dde0 100644 --- a/gruel/src/include/gruel/msg_accepter.h +++ b/gruel/src/include/gruel/msg_accepter.h @@ -18,8 +18,8 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef INCLUDED_MSG_ACCEPTER_H -#define INCLUDED_MSG_ACCEPTER_H +#ifndef INCLUDED_GRUEL_MSG_ACCEPTER_H +#define INCLUDED_GRUEL_MSG_ACCEPTER_H #include @@ -34,9 +34,16 @@ namespace gruel { msg_accepter() {}; virtual ~msg_accepter(); + /*! + * \brief send \p msg to \p msg_accepter + * + * Sending a message is an asynchronous operation. The \p post + * call will not wait for the message either to arrive at the + * destination or to be received. + */ virtual void post(pmt::pmt_t msg) = 0; }; } /* namespace gruel */ -#endif /* INCLUDED_MSG_ACCEPTER_H */ +#endif /* INCLUDED_GRUEL_MSG_ACCEPTER_H */ diff --git a/gruel/src/include/gruel/send.h b/gruel/src/include/gruel/send.h new file mode 100644 index 000000000..292017d45 --- /dev/null +++ b/gruel/src/include/gruel/send.h @@ -0,0 +1,49 @@ +/* -*- 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 253018c6cdb114f5662a2d7ba8ed748c6e68e3a7 Mon Sep 17 00:00:00 2001 From: git Date: Fri, 14 Aug 2009 18:10:11 +0000 Subject: Added git ignore files auto created from svn:ignore properties. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11592 221aa14e-8319-0410-a670-987f0aec2ac5 --- gruel/.gitignore | 3 +++ gruel/src/.gitignore | 2 ++ gruel/src/include/.gitignore | 2 ++ gruel/src/include/gruel/.gitignore | 4 ++++ gruel/src/lib/.gitignore | 4 ++++ gruel/src/lib/msg/.gitignore | 4 ++++ gruel/src/lib/pmt/.gitignore | 10 ++++++++++ gruel/src/scheme/.gitignore | 8 ++++++++ gruel/src/scheme/gnuradio/.gitignore | 8 ++++++++ 9 files changed, 45 insertions(+) create mode 100644 gruel/.gitignore create mode 100644 gruel/src/.gitignore create mode 100644 gruel/src/include/.gitignore create mode 100644 gruel/src/include/gruel/.gitignore create mode 100644 gruel/src/lib/.gitignore create mode 100644 gruel/src/lib/msg/.gitignore create mode 100644 gruel/src/lib/pmt/.gitignore create mode 100644 gruel/src/scheme/.gitignore create mode 100644 gruel/src/scheme/gnuradio/.gitignore (limited to 'gruel') diff --git a/gruel/.gitignore b/gruel/.gitignore new file mode 100644 index 000000000..ede973f11 --- /dev/null +++ b/gruel/.gitignore @@ -0,0 +1,3 @@ +/Makefile +/Makefile.in +/gruel.pc diff --git a/gruel/src/.gitignore b/gruel/src/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gruel/src/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gruel/src/include/.gitignore b/gruel/src/include/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gruel/src/include/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gruel/src/include/gruel/.gitignore b/gruel/src/include/gruel/.gitignore new file mode 100644 index 000000000..bbe96391c --- /dev/null +++ b/gruel/src/include/gruel/.gitignore @@ -0,0 +1,4 @@ +/Makefile +/Makefile.in +/inet.h +/pmt_serial_tags.h diff --git a/gruel/src/lib/.gitignore b/gruel/src/lib/.gitignore new file mode 100644 index 000000000..89a768d46 --- /dev/null +++ b/gruel/src/lib/.gitignore @@ -0,0 +1,4 @@ +/Makefile +/Makefile.in +/.libs +/.deps diff --git a/gruel/src/lib/msg/.gitignore b/gruel/src/lib/msg/.gitignore new file mode 100644 index 000000000..c026fd667 --- /dev/null +++ b/gruel/src/lib/msg/.gitignore @@ -0,0 +1,4 @@ +/Makefile +/Makefile.in +/.deps +/.libs diff --git a/gruel/src/lib/pmt/.gitignore b/gruel/src/lib/pmt/.gitignore new file mode 100644 index 000000000..035c0316b --- /dev/null +++ b/gruel/src/lib/pmt/.gitignore @@ -0,0 +1,10 @@ +/Makefile +/Makefile.in +/.libs +/.deps +/test_pmt +/qa_pmt_unv.cc +/qa_pmt_unv.h +/pmt_unv_int.h +/pmt_unv.cc +/stamp-sources-generate diff --git a/gruel/src/scheme/.gitignore b/gruel/src/scheme/.gitignore new file mode 100644 index 000000000..a02b6ff73 --- /dev/null +++ b/gruel/src/scheme/.gitignore @@ -0,0 +1,8 @@ +/Makefile +/Makefile.in +/.la +/.lo +/.deps +/.libs +/*.la +/*.lo diff --git a/gruel/src/scheme/gnuradio/.gitignore b/gruel/src/scheme/gnuradio/.gitignore new file mode 100644 index 000000000..a02b6ff73 --- /dev/null +++ b/gruel/src/scheme/gnuradio/.gitignore @@ -0,0 +1,8 @@ +/Makefile +/Makefile.in +/.la +/.lo +/.deps +/.libs +/*.la +/*.lo -- cgit From ad36dccd88eafec6efb8f2428fb21f54d6894cfc Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Fri, 14 Aug 2009 14:04:11 -0700 Subject: Applied patch c1258.diff from Stephan Bruns (ticket:359) This patch changes pmt_t to use boost intrusive pointers. Patch was modified to apply to new pmt location since the original patch was created, and add missing include file. Signed-off-by: Johnathan Corgan --- gruel/src/include/gruel/pmt.h | 6 ++++-- gruel/src/lib/pmt/pmt.cc | 2 ++ gruel/src/lib/pmt/pmt_int.h | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index de0998b5e..caa12209d 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -23,7 +23,7 @@ #ifndef INCLUDED_PMT_H #define INCLUDED_PMT_H -#include +#include #include #include #include @@ -50,8 +50,10 @@ class pmt_base; * \brief typedef for shared pointer (transparent reference counting). * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm */ -typedef boost::shared_ptr pmt_t; +typedef boost::intrusive_ptr pmt_t; +extern void intrusive_ptr_add_ref(pmt_base*); +extern void intrusive_ptr_release(pmt_base*); class pmt_exception : public std::logic_error { diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index fbf557be1..fd4035f75 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -56,6 +56,8 @@ pmt_base::operator delete(void *p, size_t size) #endif +void intrusive_ptr_add_ref(pmt_base* p) { ++(p->count_); } +void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) delete p; } pmt_base::~pmt_base() { diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h index 9aac322a7..ba865b418 100644 --- a/gruel/src/lib/pmt/pmt_int.h +++ b/gruel/src/lib/pmt/pmt_int.h @@ -24,6 +24,7 @@ #include #include +#include /* * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION! @@ -35,8 +36,10 @@ namespace pmt { class pmt_base : boost::noncopyable { + mutable boost::detail::atomic_count count_; + protected: - pmt_base(){}; + pmt_base() : count_(0) {}; virtual ~pmt_base(); public: @@ -66,6 +69,9 @@ public: virtual bool is_c32vector() const { return false; } virtual bool is_c64vector() const { return false; } + friend void intrusive_ptr_add_ref(pmt_base* p); + friend void intrusive_ptr_release(pmt_base* p); + # if (PMT_LOCAL_ALLOCATOR) void *operator new(size_t); void operator delete(void *, size_t); -- cgit From 7ca21b2eb16ed1495001cdd62d58a9d51dd3f436 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Fri, 14 Aug 2009 18:53:35 -0700 Subject: Added most of the support for a new PMT type: tuple. More QA code coming soon. --- gruel/src/include/gruel/pmt.h | 36 +++++++ gruel/src/lib/pmt/pmt.cc | 208 +++++++++++++++++++++++++++++++++++++- gruel/src/lib/pmt/pmt_int.h | 17 ++++ gruel/src/lib/pmt/qa_pmt_prims.cc | 64 ++++++++++++ gruel/src/lib/pmt/qa_pmt_prims.h | 2 + 5 files changed, 325 insertions(+), 2 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index de0998b5e..ed337a885 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -235,6 +235,42 @@ pmt_t pmt_cddr(pmt_t pair); pmt_t pmt_caddr(pmt_t pair); pmt_t pmt_cadddr(pmt_t pair); +/* + * ------------------------------------------------------------------------ + * Tuples + * + * Store a fixed number of objects. Tuples are not modifiable, and thus + * are excellent for use as messages. Indexing is zero based. + * Access time to an element is O(1). + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a tuple, othewise false. +bool pmt_is_tuple(pmt_t x); + +pmt_t pmt_make_tuple(); +pmt_t pmt_make_tuple(const pmt_t &e0); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); + +/*! + * If \p x is a vector or proper list, return a tuple containing the elements of x + */ +pmt_t pmt_to_tuple(const pmt_t &x); + +/*! + * Return the contents of position \p k of \p tuple. + * \p k must be a valid index of \p tuple. + */ +pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); + /* * ------------------------------------------------------------------------ * Vectors diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index fbf557be1..8bf5b2dea 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -126,6 +126,12 @@ _vector(pmt_t x) return dynamic_cast(x.get()); } +static pmt_tuple * +_tuple(pmt_t x) +{ + return dynamic_cast(x.get()); +} + static pmt_uniform_vector * _uniform_vector(pmt_t x) { @@ -494,6 +500,200 @@ pmt_vector_fill(pmt_t vector, pmt_t obj) _vector(vector)->fill(obj); } +//////////////////////////////////////////////////////////////////////////// +// Tuples +//////////////////////////////////////////////////////////////////////////// + +pmt_tuple::pmt_tuple(size_t len) + : d_v(len) +{ +} + +pmt_t +pmt_tuple::ref(size_t k) const +{ + if (k >= length()) + throw pmt_out_of_range("pmt_tuple_ref", pmt_from_long(k)); + return d_v[k]; +} + +bool +pmt_is_tuple(pmt_t obj) +{ + return obj->is_tuple(); +} + +pmt_t +pmt_tuple_ref(const pmt_t &tuple, size_t k) +{ + if (!tuple->is_tuple()) + throw pmt_wrong_type("pmt_tuple_ref", tuple); + return _tuple(tuple)->ref(k); +} + +// for (i=0; i < 10; i++) +// make_constructor() + +pmt_t +pmt_make_tuple() +{ + return pmt_t(new pmt_tuple(0)); +} + +pmt_t +pmt_make_tuple(const pmt_t &e0) +{ + pmt_tuple *t = new pmt_tuple(1); + t->_set(0, e0); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(const pmt_t &e0, const pmt_t &e1) +{ + pmt_tuple *t = new pmt_tuple(2); + t->_set(0, e0); + t->_set(1, e1); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2) +{ + pmt_tuple *t = new pmt_tuple(3); + t->_set(0, e0); + t->_set(1, e1); + t->_set(2, e2); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3) +{ + pmt_tuple *t = new pmt_tuple(4); + t->_set(0, e0); + t->_set(1, e1); + t->_set(2, e2); + t->_set(3, e3); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4) +{ + pmt_tuple *t = new pmt_tuple(5); + t->_set(0, e0); + t->_set(1, e1); + t->_set(2, e2); + t->_set(3, e3); + t->_set(4, e4); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5) +{ + pmt_tuple *t = new pmt_tuple(6); + t->_set(0, e0); + t->_set(1, e1); + t->_set(2, e2); + t->_set(3, e3); + t->_set(4, e4); + t->_set(5, e5); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(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) +{ + pmt_tuple *t = new pmt_tuple(7); + t->_set(0, e0); + t->_set(1, e1); + t->_set(2, e2); + t->_set(3, e3); + t->_set(4, e4); + t->_set(5, e5); + t->_set(6, e6); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(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) +{ + pmt_tuple *t = new pmt_tuple(8); + t->_set(0, e0); + t->_set(1, e1); + t->_set(2, e2); + t->_set(3, e3); + t->_set(4, e4); + t->_set(5, e5); + t->_set(6, e6); + t->_set(7, e7); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(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) +{ + pmt_tuple *t = new pmt_tuple(9); + t->_set(0, e0); + t->_set(1, e1); + t->_set(2, e2); + t->_set(3, e3); + t->_set(4, e4); + t->_set(5, e5); + t->_set(6, e6); + t->_set(7, e7); + t->_set(8, e8); + return pmt_t(t); +} + +pmt_t +pmt_make_tuple(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) +{ + pmt_tuple *t = new pmt_tuple(10); + t->_set(0, e0); + t->_set(1, e1); + t->_set(2, e2); + t->_set(3, e3); + t->_set(4, e4); + t->_set(5, e5); + t->_set(6, e6); + t->_set(7, e7); + t->_set(8, e8); + t->_set(9, e9); + return pmt_t(t); +} + +pmt_t +pmt_to_tuple(const pmt_t &x) +{ + if (x->is_tuple()) // already one + return x; + + size_t len = pmt_length(x); + pmt_tuple *t = new pmt_tuple(len); + + if (x->is_vector()){ + for (size_t i = 0; i < len; i++) + t->_set(i, _vector(x)->ref(i)); + return pmt_t(t); + } + + if (x->is_pair()){ + pmt_t y = x; + for (size_t i = 0; i < len; i++){ + t->_set(i, pmt_car(y)); + y = pmt_cdr(x); + } + return pmt_t(t); + } + + throw pmt_wrong_type("pmt_to_tuple", x); +} + + + //////////////////////////////////////////////////////////////////////////// // Uniform Numeric Vectors //////////////////////////////////////////////////////////////////////////// @@ -757,11 +957,15 @@ pmt_length(const pmt_t& x) if (x->is_uniform_vector()) return _uniform_vector(x)->length(); - if (x->is_null()) return 0; + if (x->is_tuple()) + return _tuple(x)->length(); + + if (x->is_null()) + return 0; if (x->is_pair()) { size_t length=1; - pmt_t it = pmt_cdr(x); + pmt_t it = pmt_cdr(x); while (pmt_is_pair(it)){ length++; it = pmt_cdr(it); diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h index 9aac322a7..ed47249b1 100644 --- a/gruel/src/lib/pmt/pmt_int.h +++ b/gruel/src/lib/pmt/pmt_int.h @@ -48,6 +48,7 @@ public: virtual bool is_complex() const { return false; } virtual bool is_null() const { return false; } virtual bool is_pair() const { return false; } + virtual bool is_tuple() const { return false; } virtual bool is_vector() const { return false; } virtual bool is_dict() const { return false; } virtual bool is_any() const { return false; } @@ -180,6 +181,22 @@ public: pmt_t _ref(size_t k) const { return d_v[k]; } }; +class pmt_tuple : public pmt_base +{ + std::vector d_v; + +public: + pmt_tuple(size_t len); + //~pmt_tuple(); + + bool is_tuple() const { return true; } + pmt_t ref(size_t k) const; + size_t length() const { return d_v.size(); } + + pmt_t _ref(size_t k) const { return d_v[k]; } + void _set(size_t k, pmt_t v) { d_v[k] = v; } +}; + class pmt_dict : public pmt_base { pmt_t d_alist; // list of (key . value) pairs diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index b81354721..d31e3fabf 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -193,6 +193,69 @@ qa_pmt_prims::test_vectors() CPPUNIT_ASSERT_EQUAL(s0, pmt_vector_ref(v1, i)); } +static void +check_tuple(size_t len, const std::vector &s, pmt_t t) +{ + CPPUNIT_ASSERT_EQUAL(true, pmt_is_tuple(t)); + CPPUNIT_ASSERT_EQUAL(len, pmt_length(t)); + + for (size_t i = 0; i < len; i++) + CPPUNIT_ASSERT_EQUAL(s[i], pmt_tuple_ref(t, i)); + +} + +void +qa_pmt_prims::test_tuples() +{ + pmt_t t0 = pmt_make_tuple(); + CPPUNIT_ASSERT_EQUAL(size_t(0), pmt_length(t0)); + + std::vector s(10); + for (size_t i = 0; i < 10; i++){ + std::ostringstream os; + os << "s" << i; + s[i] = pmt_string_to_symbol(os.str()); + } + + pmt_t t; + + t = pmt_make_tuple(); + check_tuple(0, s, t); + + t = pmt_make_tuple(s[0]); + check_tuple(1, s, t); + + t = pmt_make_tuple(s[0], s[1]); + check_tuple(2, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2]); + check_tuple(3, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2], s[3]); + check_tuple(4, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2], s[3], s[4]); + check_tuple(5, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2], s[3], s[4], s[5]); + check_tuple(6, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2], s[3], s[4], s[5], s[6]); + check_tuple(7, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7]); + check_tuple(8, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8]); + check_tuple(9, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9]); + check_tuple(10, s, t); + + t = pmt_make_tuple(s[0], s[1], s[2]); + CPPUNIT_ASSERT_THROW(pmt_tuple_ref(t, 3), pmt_out_of_range); +} + void qa_pmt_prims::test_equivalence() { @@ -436,3 +499,4 @@ qa_pmt_prims::test_sets() CPPUNIT_ASSERT(!pmt_subsetp(l2,l1)); CPPUNIT_ASSERT(!pmt_subsetp(l3,l2)); } + diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h index effb3a097..2fe473c43 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.h +++ b/gruel/src/lib/pmt/qa_pmt_prims.h @@ -35,6 +35,7 @@ class qa_pmt_prims : public CppUnit::TestCase { CPPUNIT_TEST(test_complexes); CPPUNIT_TEST(test_pairs); CPPUNIT_TEST(test_vectors); + CPPUNIT_TEST(test_tuples); CPPUNIT_TEST(test_equivalence); CPPUNIT_TEST(test_misc); CPPUNIT_TEST(test_dict); @@ -53,6 +54,7 @@ class qa_pmt_prims : public CppUnit::TestCase { void test_complexes(); void test_pairs(); void test_vectors(); + void test_tuples(); void test_equivalence(); void test_misc(); void test_dict(); -- cgit From f8f85dcf9de45cbb42ee46b6f6e3d1e685b0103a Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sat, 15 Aug 2009 01:02:15 -0700 Subject: Additional QA for tuple. --- gruel/src/lib/pmt/pmt.cc | 20 +++++++++++++++++--- gruel/src/lib/pmt/pmt_io.cc | 5 +++++ gruel/src/lib/pmt/qa_pmt_prims.cc | 19 ++++++++++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index 8bf5b2dea..20dc4e42c 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -673,20 +673,21 @@ pmt_to_tuple(const pmt_t &x) size_t len = pmt_length(x); pmt_tuple *t = new pmt_tuple(len); + pmt_t r = pmt_t(t); if (x->is_vector()){ for (size_t i = 0; i < len; i++) t->_set(i, _vector(x)->ref(i)); - return pmt_t(t); + return r; } if (x->is_pair()){ pmt_t y = x; for (size_t i = 0; i < len; i++){ t->_set(i, pmt_car(y)); - y = pmt_cdr(x); + y = pmt_cdr(y); } - return pmt_t(t); + return r; } throw pmt_wrong_type("pmt_to_tuple", x); @@ -928,6 +929,19 @@ pmt_equal(const pmt_t& x, const pmt_t& y) return true; } + if (x->is_tuple() && y->is_tuple()){ + pmt_tuple *xv = _tuple(x); + pmt_tuple *yv = _tuple(y); + if (xv->length() != yv->length()) + return false; + + for (unsigned i = 0; i < xv->length(); i++) + if (!pmt_equal(xv->_ref(i), yv->_ref(i))) + return false; + + return true; + } + if (x->is_uniform_vector() && y->is_uniform_vector()){ pmt_uniform_vector *xv = _uniform_vector(x); pmt_uniform_vector *yv = _uniform_vector(y); diff --git a/gruel/src/lib/pmt/pmt_io.cc b/gruel/src/lib/pmt/pmt_io.cc index f5a82de0e..fbc556ab0 100644 --- a/gruel/src/lib/pmt/pmt_io.cc +++ b/gruel/src/lib/pmt/pmt_io.cc @@ -90,6 +90,11 @@ pmt_write(pmt_t obj, std::ostream &port) // port << "#"; port << "#"; } + else if (pmt_is_tuple(obj)){ + // FIXME + // port << "#"; + port << "#"; + } else if (pmt_is_uniform_vector(obj)){ // FIXME // port << "#"; diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index d31e3fabf..cf1ee0142 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -207,14 +207,13 @@ check_tuple(size_t len, const std::vector &s, pmt_t t) void qa_pmt_prims::test_tuples() { - pmt_t t0 = pmt_make_tuple(); - CPPUNIT_ASSERT_EQUAL(size_t(0), pmt_length(t0)); - + pmt_t v = pmt_make_vector(10, PMT_NIL); std::vector s(10); for (size_t i = 0; i < 10; i++){ std::ostringstream os; os << "s" << i; s[i] = pmt_string_to_symbol(os.str()); + pmt_vector_set(v, i, s[i]); } pmt_t t; @@ -254,6 +253,20 @@ qa_pmt_prims::test_tuples() t = pmt_make_tuple(s[0], s[1], s[2]); CPPUNIT_ASSERT_THROW(pmt_tuple_ref(t, 3), pmt_out_of_range); + + t = pmt_make_tuple(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9]); + check_tuple(10, s, t); + + pmt_t t2 = pmt_to_tuple(v); + CPPUNIT_ASSERT_EQUAL(size_t(10), pmt_length(v)); + CPPUNIT_ASSERT(pmt_equal(t, t2)); + + t = pmt_make_tuple(s[0], s[1], s[2]); + pmt_t list0 = pmt_list3(s[0], s[1], s[2]); + CPPUNIT_ASSERT_EQUAL(size_t(3), pmt_length(list0)); + t2 = pmt_to_tuple(list0); + CPPUNIT_ASSERT_EQUAL(size_t(3), pmt_length(t2)); + CPPUNIT_ASSERT(pmt_equal(t, t2)); } void -- cgit From 381ae7f53d9628dae5ac79bb580e1f8e62e7571b Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sat, 15 Aug 2009 01:45:52 -0700 Subject: pmt_write now displays vector and tuple elements. --- gruel/src/lib/pmt/pmt_io.cc | 30 ++++++++++++++++++++---------- gruel/src/lib/pmt/qa_pmt_prims.cc | 13 +++++++++++-- 2 files changed, 31 insertions(+), 12 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/pmt_io.cc b/gruel/src/lib/pmt/pmt_io.cc index fbc556ab0..179e6b72c 100644 --- a/gruel/src/lib/pmt/pmt_io.cc +++ b/gruel/src/lib/pmt/pmt_io.cc @@ -80,20 +80,30 @@ pmt_write(pmt_t obj, std::ostream &port) port << "("; pmt_write_list_tail(obj, port); } - else if (pmt_is_dict(obj)){ - // FIXME - // port << "#"; - port << "#"; + else if (pmt_is_tuple(obj)){ + port << "{"; + size_t len = pmt_length(obj); + if (len > 0){ + port << pmt_tuple_ref(obj, 0); + for (size_t i = 1; i < len; i++) + port << " " << pmt_tuple_ref(obj, i); + } + port << "}"; } else if (pmt_is_vector(obj)){ - // FIXME - // port << "#"; - port << "#"; + port << "#("; + size_t len = pmt_length(obj); + if (len > 0){ + port << pmt_vector_ref(obj, 0); + for (size_t i = 1; i < len; i++) + port << " " << pmt_vector_ref(obj, i); + } + port << ")"; } - else if (pmt_is_tuple(obj)){ + else if (pmt_is_dict(obj)){ // FIXME - // port << "#"; - port << "#"; + // port << "#"; + port << "#"; } else if (pmt_is_uniform_vector(obj)){ // FIXME diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index cf1ee0142..899674bbb 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -216,6 +216,7 @@ qa_pmt_prims::test_tuples() pmt_vector_set(v, i, s[i]); } + pmt_t t; t = pmt_make_tuple(); @@ -224,6 +225,11 @@ qa_pmt_prims::test_tuples() t = pmt_make_tuple(s[0]); check_tuple(1, s, t); + CPPUNIT_ASSERT(pmt_is_vector(v)); + CPPUNIT_ASSERT(!pmt_is_tuple(v)); + CPPUNIT_ASSERT(pmt_is_tuple(t)); + CPPUNIT_ASSERT(!pmt_is_vector(t)); + t = pmt_make_tuple(s[0], s[1]); check_tuple(2, s, t); @@ -253,13 +259,16 @@ qa_pmt_prims::test_tuples() t = pmt_make_tuple(s[0], s[1], s[2]); CPPUNIT_ASSERT_THROW(pmt_tuple_ref(t, 3), pmt_out_of_range); + CPPUNIT_ASSERT_THROW(pmt_vector_ref(t, 0), pmt_wrong_type); + CPPUNIT_ASSERT_THROW(pmt_tuple_ref(v, 0), pmt_wrong_type); t = pmt_make_tuple(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9]); - check_tuple(10, s, t); - pmt_t t2 = pmt_to_tuple(v); CPPUNIT_ASSERT_EQUAL(size_t(10), pmt_length(v)); CPPUNIT_ASSERT(pmt_equal(t, t2)); + //std::cout << v << std::endl; + //std::cout << t2 << std::endl; + t = pmt_make_tuple(s[0], s[1], s[2]); pmt_t list0 = pmt_list3(s[0], s[1], s[2]); -- cgit 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') 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') 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') 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') 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') 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')

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 


From 84d50d0f6ea9f3950afe0c543c983eb9a048a6fb Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Wed, 9 Sep 2009 17:09:44 -0700
Subject: Added missing file to ignores.

---
 gruel/src/lib/.gitignore | 1 +
 1 file changed, 1 insertion(+)

(limited to 'gruel')

diff --git a/gruel/src/lib/.gitignore b/gruel/src/lib/.gitignore
index 89a768d46..165e179d6 100644
--- a/gruel/src/lib/.gitignore
+++ b/gruel/src/lib/.gitignore
@@ -2,3 +2,4 @@
 /Makefile.in
 /.libs
 /.deps
+test_gruel
-- 
cgit 


From 4036435eeebee7e3653c5b8ad694c77515d5a3ea Mon Sep 17 00:00:00 2001
From: Josh Blum
Date: Fri, 25 Sep 2009 15:57:20 -0700
Subject: Reading 64 bit freq out of chunk of context packet. Where is the rest
 of my context packet? Added htonll and ntohll in gruel inet.h Fixed
 vrt/types.h freq cast

---
 gruel/src/include/gruel/inet.h.in | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

(limited to 'gruel')

diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in
index a98d83e9c..320270727 100644
--- a/gruel/src/include/gruel/inet.h.in
+++ b/gruel/src/include/gruel/inet.h.in
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008, 2009 Free Software Foundation, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,33 @@
 #ifndef INCLUDED_INET_H
 #define INCLUDED_INET_H
 
+#if 1 /* missing htonll or ntohll */
+#if @GR_ARCH_BIGENDIAN@  /* GR_ARCH_BIGENDIAN */
+// Nothing to do...
+static inline uint64_t htonll(uint64_t x){ return x;}
+static inline uint64_t ntohll(uint64_t x){ return x;}
+#else
+#if @GR_HAVE_BYTESWAP@  /* GR_HAVE_BYTESWAP */
+#include 
+#else
+
+static inline uint64_t
+bswap_64(uint64_t x)
+{
+  return ((x & 0x00000000000000ffull) << 56) | ((x & 0x000000000000ff00ull) << 40) |
+         ((x & 0x0000000000ff0000ull) << 24) | ((x & 0x00000000ff000000ull) <<  8) |
+         ((x & 0x000000ff00000000ull) >>  8) | ((x & 0x0000ff0000000000ull) >> 24) |
+         ((x & 0x00ff000000000000ull) >> 40) | ((x & 0xff00000000000000ull) >> 56);
+}
+
+#endif /* GR_HAVE_BYTESWAP */
+
+static inline uint64_t htonll(uint64_t x){ return bswap_64(x);}
+static inline uint64_t ntohll(uint64_t x){ return bswap_64(x);}
+
+#endif /* GR_ARCH_BIGENDIAN */
+#endif /* missing htonll or ntohll */ 
+
 #if @GR_HAVE_ARPA_INET@  /* GR_HAVE_ARPA_INET */
 #include 
 #elif @GR_HAVE_NETINET_IN@  /* GR_HAVE_NETINET_IN */
@@ -61,8 +88,10 @@ static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); }
 static inline uint8_t  ntohx(uint8_t  x){ return x;        }
 static inline uint16_t ntohx(uint16_t x){ return ntohs(x); }
 static inline uint32_t ntohx(uint32_t x){ return ntohl(x); }
+static inline uint64_t ntohx(uint64_t x){ return ntohll(x);}
 static inline uint8_t  htonx(uint8_t  x){ return x;        }
 static inline uint16_t htonx(uint16_t x){ return htons(x); }
 static inline uint32_t htonx(uint32_t x){ return htonl(x); }
+static inline uint64_t htonx(uint64_t x){ return htonll(x);}
 
 #endif /* INCLUDED_INET_H */
-- 
cgit 


From 85a8e6cdb0fb05b12b071c81f9eb025b380fb155 Mon Sep 17 00:00:00 2001
From: Josh Blum
Date: Mon, 28 Sep 2009 19:04:38 -0700
Subject: added access methods and parsing for caldiv if context

---
 gruel/src/include/gruel/inet.h.in | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'gruel')

diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in
index 320270727..7ac01eb56 100644
--- a/gruel/src/include/gruel/inet.h.in
+++ b/gruel/src/include/gruel/inet.h.in
@@ -19,6 +19,8 @@
 #ifndef INCLUDED_INET_H
 #define INCLUDED_INET_H
 
+#include 
+
 #if 1 /* missing htonll or ntohll */
 #if @GR_ARCH_BIGENDIAN@  /* GR_ARCH_BIGENDIAN */
 // Nothing to do...
-- 
cgit 


From 30e016dd9cf7c148d3119f01ba7dd4d6474efa50 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Wed, 7 Oct 2009 09:11:13 -0700
Subject: Applied patch from Don Ward for Cygwin platform

Add *.exe to .gitignore
Restore ac_compiler in gr_fortran.m4 even when no Fortran was found
Add $(NO_UNDEFINED) to LDFLAGS in atsc Makefile.am, so shared libraries
 will be built
Change the order of searching pmt/libpmt-qa.la and libgruel.la in gruel
 Makefile.am so references to libgruel from limpmt-qa will be resolved
---
 gruel/src/lib/Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'gruel')

diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am
index 9afa0d292..b21f8023c 100644
--- a/gruel/src/lib/Makefile.am
+++ b/gruel/src/lib/Makefile.am
@@ -58,5 +58,5 @@ libgruel_la_LIBADD = 			\
 # ----------------------------------------------------------------
 
 test_gruel_SOURCES = test_gruel.cc
-test_gruel_LDADD   = libgruel.la pmt/libpmt-qa.la
+test_gruel_LDADD   = pmt/libpmt-qa.la libgruel.la
 
-- 
cgit 


From cbbe4816f99ac934427823c43d2f6f3f1c5f7995 Mon Sep 17 00:00:00 2001
From: Eric Blossom
Date: Mon, 8 Mar 2010 17:08:09 -0800
Subject: Convert pmt_dict type into an immutable data structure.

This change allows us to safely pass dicts in messages.
---
 gruel/src/include/gruel/pmt.h     |  21 +++--
 gruel/src/lib/pmt/pmt.cc          | 176 ++++++++++++++++++++------------------
 gruel/src/lib/pmt/pmt_int.h       |  27 ++----
 gruel/src/lib/pmt/qa_pmt_prims.cc |  30 ++++---
 4 files changed, 128 insertions(+), 126 deletions(-)

(limited to 'gruel')

diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h
index 3188aad1d..c371b023b 100644
--- a/gruel/src/include/gruel/pmt.h
+++ b/gruel/src/include/gruel/pmt.h
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2009 Free Software Foundation, Inc.
+ * Copyright 2006,2009,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -465,23 +465,30 @@ std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //<
 /*
  * ------------------------------------------------------------------------
  *	   Dictionary (a.k.a associative array, hash, map)
+ *
+ * This is a functional data structure that is persistent.  Updating a
+ * functional data structure does not destroy the existing version, but
+ * rather creates a new version that coexists with the old.
  * ------------------------------------------------------------------------
  */
 
 //! Return true if \p obj is a dictionary
-bool pmt_is_dict(pmt_t obj);
+bool pmt_is_dict(const pmt_t &obj);
 
-//! make an empty dictionary
+//! Make an empty dictionary
 pmt_t pmt_make_dict();
 
-//! dict[key] = value
-void  pmt_dict_set(pmt_t dict, pmt_t key, pmt_t value);
+//! Return a new dictionary with \p key associated with \p value.
+pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value);
+
+//! Return a new dictionary with \p key removed.
+pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key);
 
 //! Return true if \p key exists in \p dict
-bool  pmt_dict_has_key(pmt_t dict, pmt_t key);
+bool  pmt_dict_has_key(const pmt_t &dict, const pmt_t &key);
 
 //! If \p key exists in \p dict, return associated value; otherwise return \p not_found.
-pmt_t pmt_dict_ref(pmt_t dict, pmt_t key, pmt_t not_found);
+pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found);
 
 //! Return list of (key . value) pairs
 pmt_t pmt_dict_items(pmt_t dict);
diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc
index e50e21838..aa1688d24 100644
--- a/gruel/src/lib/pmt/pmt.cc
+++ b/gruel/src/lib/pmt/pmt.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2009 Free Software Foundation, Inc.
+ * Copyright 2006,2009,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -141,12 +141,6 @@ _uniform_vector(pmt_t x)
   return dynamic_cast(x.get());
 }
 
-static pmt_dict *
-_dict(pmt_t x)
-{
-  return dynamic_cast(x.get());
-}
-
 static pmt_any *
 _any(pmt_t x)
 {
@@ -728,124 +722,91 @@ pmt_uniform_vector_writable_elements(pmt_t vector, size_t &len)
 //                            Dictionaries
 ////////////////////////////////////////////////////////////////////////////
 
-pmt_dict::pmt_dict()
-  : d_alist(PMT_NIL)
-{
-}
-
-void
-pmt_dict::set(pmt_t key, pmt_t value)
-{
-  pmt_t	p = pmt_assv(key, d_alist);	// look for (key . value) pair
-  if (pmt_is_pair(p)){			// found existing pair...
-    pmt_set_cdr(p, value);		// overrwrite cdr with new value
-  }
-  else {				// not in the dict
-    d_alist = pmt_cons(pmt_cons(key, value), d_alist);	// add new (key . value) pair
-  }
-}
-
-pmt_t
-pmt_dict::ref(pmt_t key, pmt_t not_found) const
-{
-  pmt_t	p = pmt_assv(key, d_alist);	// look for (key . value) pair
-  if (pmt_is_pair(p))
-    return pmt_cdr(p);
-  else
-    return not_found;
-}
+/*
+ * This is an a-list implementation.
+ *
+ * When we need better performance for large dictionaries, consider implementing
+ * persistent Red-Black trees as described in "Purely Functional Data Structures", 
+ * Chris Okasaki, 1998, section 3.3.
+ */
 
 bool
-pmt_dict::has_key(pmt_t key) const
+pmt_is_dict(const pmt_t &obj)
 {
-  return pmt_is_pair(pmt_assv(key, d_alist));
+  return pmt_is_null(obj) || pmt_is_pair(obj);
 }
 
 pmt_t
-pmt_dict::items() const
+pmt_make_dict()
 {
-  return d_alist;
+  return PMT_NIL;
 }
 
 pmt_t
-pmt_dict::keys() const
+pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value)
 {
-  return pmt_map(pmt_car, d_alist);
-}
+  if (pmt_is_null(dict))
+    return pmt_acons(key, value, PMT_NIL);
 
-pmt_t
-pmt_dict::values() const
-{
-  return pmt_map(pmt_cdr, d_alist);
-}
+  if (pmt_dict_has_key(dict, key))
+    return pmt_acons(key, value, pmt_dict_delete(dict, key));
 
-bool
-pmt_is_dict(pmt_t obj)
-{
-  return obj->is_dict();
+  return pmt_acons(key, value, dict);
 }
 
 pmt_t
-pmt_make_dict()
+pmt_dict_delete(const pmt_t &dict, const pmt_t &key)
 {
-  return pmt_t(new pmt_dict());
+  if (pmt_is_null(dict))
+    return dict;
+
+  if (pmt_eqv(pmt_caar(dict), key))
+    return pmt_cdr(dict);
+  
+  return pmt_cons(pmt_car(dict), pmt_dict_delete(pmt_cdr(dict), key));
 }
 
-void
-pmt_dict_set(pmt_t dict, pmt_t key, pmt_t value)
+pmt_t
+pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found)
 {
-  pmt_dict* d = _dict(dict);
-  if (!d)
-    throw pmt_wrong_type("pmt_dict_set", dict);
-
-  d->set(key, value);
+  pmt_t	p = pmt_assv(key, dict);	// look for (key . value) pair
+  if (pmt_is_pair(p))
+    return pmt_cdr(p);
+  else
+    return not_found;
 }
 
 bool
-pmt_dict_has_key(pmt_t dict, pmt_t key)
+pmt_dict_has_key(const pmt_t &dict, const pmt_t &key)
 {
-  pmt_dict* d = _dict(dict);
-  if (!d)
-    throw pmt_wrong_type("pmt_dict_has_key", dict);
-
-  return d->has_key(key);
-}
-
-pmt_t
-pmt_dict_ref(pmt_t dict, pmt_t key, pmt_t not_found)
-{
-  pmt_dict* d = _dict(dict);
-  if (!d)
-    throw pmt_wrong_type("pmt_dict_ref", dict);
-
-  return d->ref(key, not_found);
+  return pmt_is_pair(pmt_assv(key, dict));
 }
 
 pmt_t
 pmt_dict_items(pmt_t dict)
 {
-  if (!dict->is_dict())
-    throw pmt_wrong_type("pmt_dict_items", dict);
+  if (!pmt_is_dict(dict))
+    throw pmt_wrong_type("pmt_dict_values", dict);
 
-  return _dict(dict)->items();
+  return dict;		// equivalent to dict in the a-list case
 }
 
 pmt_t
 pmt_dict_keys(pmt_t dict)
 {
-  if (!dict->is_dict())
+  if (!pmt_is_dict(dict))
     throw pmt_wrong_type("pmt_dict_keys", dict);
 
-  return _dict(dict)->keys();
+  return pmt_map(pmt_car, dict);
 }
 
 pmt_t
 pmt_dict_values(pmt_t dict)
 {
-  if (!dict->is_dict())
-    throw pmt_wrong_type("pmt_dict_values", dict);
+  if (!pmt_is_dict(dict))
+    throw pmt_wrong_type("pmt_dict_keys", dict);
 
-  return _dict(dict)->values();
+  return pmt_map(pmt_cdr, dict);
 }
 
 ////////////////////////////////////////////////////////////////////////////
@@ -977,6 +938,24 @@ pmt_eqv(const pmt_t& x, const pmt_t& y)
   return false;
 }
 
+bool
+pmt_eqv_raw(pmt_base *x, pmt_base *y)
+{
+  if (x == y)
+    return true;
+
+  if (x->is_integer() && y->is_integer())
+    return _integer(x)->value() == _integer(y)->value();
+
+  if (x->is_real() && y->is_real())
+    return _real(x)->value() == _real(y)->value();
+
+  if (x->is_complex() && y->is_complex())
+    return _complex(x)->value() == _complex(y)->value();
+
+  return false;
+}
+
 bool
 pmt_equal(const pmt_t& x, const pmt_t& y)
 {
@@ -1082,6 +1061,35 @@ pmt_assq(pmt_t obj, pmt_t alist)
   return PMT_F;
 }
 
+/*
+ * This avoids a bunch of shared_pointer reference count manipulation.
+ */
+pmt_t
+pmt_assv_raw(pmt_base *obj, pmt_base *alist)
+{
+  while (alist->is_pair()){
+    pmt_base *p = ((pmt_pair *)alist)->d_car.get();
+    if (!p->is_pair())		// malformed alist
+      return PMT_F;
+
+    if (pmt_eqv_raw(obj, ((pmt_pair *)p)->d_car.get()))
+      return ((pmt_pair *)alist)->d_car;
+
+    alist = (((pmt_pair *)alist)->d_cdr).get();
+  }
+  return PMT_F;
+}
+
+#if 1
+
+pmt_t
+pmt_assv(pmt_t obj, pmt_t alist)
+{
+  return pmt_assv_raw(obj.get(), alist.get());
+}
+
+#else
+
 pmt_t
 pmt_assv(pmt_t obj, pmt_t alist)
 {
@@ -1098,6 +1106,9 @@ pmt_assv(pmt_t obj, pmt_t alist)
   return PMT_F;
 }
 
+#endif
+
+
 pmt_t
 pmt_assoc(pmt_t obj, pmt_t alist)
 {
@@ -1322,7 +1333,6 @@ pmt_dump_sizeof()
   printf("sizeof(pmt_null)           = %3zd\n", sizeof(pmt_null));
   printf("sizeof(pmt_pair)           = %3zd\n", sizeof(pmt_pair));
   printf("sizeof(pmt_vector)         = %3zd\n", sizeof(pmt_vector));
-  printf("sizeof(pmt_dict)           = %3zd\n", sizeof(pmt_dict));
   printf("sizeof(pmt_uniform_vector) = %3zd\n", sizeof(pmt_uniform_vector));
 }
 
diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h
index 7581845f8..50683ffb5 100644
--- a/gruel/src/lib/pmt/pmt_int.h
+++ b/gruel/src/lib/pmt/pmt_int.h
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2009 Free Software Foundation, Inc.
+ * Copyright 2006,2009,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -107,9 +107,9 @@ public:
 
 class pmt_integer : public pmt_base
 {
+public:
   long		d_value;
 
-public:
   pmt_integer(long value);
   //~pmt_integer(){}
 
@@ -120,9 +120,9 @@ public:
 
 class pmt_real : public pmt_base
 {
+public:
   double	d_value;
 
-public:
   pmt_real(double value);
   //~pmt_real(){}
 
@@ -133,9 +133,9 @@ public:
 
 class pmt_complex : public pmt_base
 {
+public:
   std::complex	d_value;
 
-public:
   pmt_complex(std::complex value);
   //~pmt_complex(){}
 
@@ -155,10 +155,10 @@ public:
 
 class pmt_pair : public pmt_base
 {
+public:
   pmt_t		d_car;
   pmt_t		d_cdr;
 
-public:
   pmt_pair(const pmt_t& car, const pmt_t& cdr);
   //~pmt_pair(){};
 
@@ -203,23 +203,6 @@ public:
   void _set(size_t k, pmt_t v) { d_v[k] = v; }
 };
 
-class pmt_dict : public pmt_base
-{
-  pmt_t		d_alist;	// list of (key . value) pairs
-
-public:
-  pmt_dict();
-  //~pmt_dict();
-
-  bool  is_dict() const { return true; }
-  void  set(pmt_t key, pmt_t value);
-  pmt_t ref(pmt_t key, pmt_t default_value) const;
-  bool  has_key(pmt_t key) const;
-  pmt_t items() const;
-  pmt_t keys() const;
-  pmt_t values() const;
-};
-
 class pmt_any : public pmt_base
 {
   boost::any	d_any;
diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc
index 59d9e14d3..3f6e2688b 100644
--- a/gruel/src/lib/pmt/qa_pmt_prims.cc
+++ b/gruel/src/lib/pmt/qa_pmt_prims.cc
@@ -351,29 +351,31 @@ qa_pmt_prims::test_dict()
   pmt_t dict = pmt_make_dict();
   CPPUNIT_ASSERT(pmt_is_dict(dict));
 
-  pmt_t k0 = pmt_string_to_symbol("k0");
-  pmt_t k1 = pmt_string_to_symbol("k1");
-  pmt_t k2 = pmt_string_to_symbol("k2");
-  pmt_t k3 = pmt_string_to_symbol("k3");
-  pmt_t v0 = pmt_string_to_symbol("v0");
-  pmt_t v1 = pmt_string_to_symbol("v1");
-  pmt_t v2 = pmt_string_to_symbol("v2");
-  pmt_t v3 = pmt_string_to_symbol("v3");
+  pmt_t k0 = mp("k0");
+  pmt_t k1 = mp("k1");
+  pmt_t k2 = mp("k2");
+  pmt_t k3 = mp("k3");
+  pmt_t v0 = mp("v0");
+  pmt_t v1 = mp("v1");
+  pmt_t v2 = mp("v2");
+  pmt_t v3 = mp("v3");
   pmt_t not_found = pmt_cons(PMT_NIL, PMT_NIL);
   
   CPPUNIT_ASSERT(!pmt_dict_has_key(dict, k0));
-  pmt_dict_set(dict, k0, v0);
+  dict = pmt_dict_add(dict, k0, v0);
   CPPUNIT_ASSERT(pmt_dict_has_key(dict, k0));
   CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k0, not_found), v0));
   CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), not_found));
-  pmt_dict_set(dict, k1, v1);
-  pmt_dict_set(dict, k2, v2);
+  dict = pmt_dict_add(dict, k1, v1);
+  dict = pmt_dict_add(dict, k2, v2);
   CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), v1));
-  pmt_dict_set(dict, k1, v3);
+  dict = pmt_dict_add(dict, k1, v3);
   CPPUNIT_ASSERT(pmt_eqv(pmt_dict_ref(dict, k1, not_found), v3));
 
-  pmt_t keys = pmt_cons(k2, pmt_cons(k1, pmt_cons(k0, PMT_NIL)));
-  pmt_t vals = pmt_cons(v2, pmt_cons(v3, pmt_cons(v0, PMT_NIL)));
+  pmt_t keys = pmt_list3(k1, k2, k0);
+  pmt_t vals = pmt_list3(v3, v2, v0);
+  //std::cout << "pmt_dict_keys:   " << pmt_dict_keys(dict) << std::endl;
+  //std::cout << "pmt_dict_values: " << pmt_dict_values(dict) << std::endl;
   CPPUNIT_ASSERT(pmt_equal(keys, pmt_dict_keys(dict)));
   CPPUNIT_ASSERT(pmt_equal(vals, pmt_dict_values(dict)));
 }
-- 
cgit 


From 18ecca1b9e57f047130a124bd8cc90cbe34feff0 Mon Sep 17 00:00:00 2001
From: Eric Blossom
Date: Mon, 8 Mar 2010 17:21:43 -0800
Subject: Replace some calls to pmt constructors with mp(foo) shorthand.

---
 gruel/src/lib/pmt/qa_pmt_prims.cc | 82 +++++++++++++++++++--------------------
 1 file changed, 41 insertions(+), 41 deletions(-)

(limited to 'gruel')

diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc
index 3f6e2688b..f2414c72c 100644
--- a/gruel/src/lib/pmt/qa_pmt_prims.cc
+++ b/gruel/src/lib/pmt/qa_pmt_prims.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2009 Free Software Foundation, Inc.
+ * Copyright 2006,2009,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -36,14 +36,14 @@ qa_pmt_prims::test_symbols()
   CPPUNIT_ASSERT(!pmt_is_symbol(PMT_F));
   CPPUNIT_ASSERT_THROW(pmt_symbol_to_string(PMT_F), pmt_wrong_type);
 
-  pmt_t sym1 = pmt_string_to_symbol("test");
+  pmt_t sym1 = mp("test");
   CPPUNIT_ASSERT(pmt_is_symbol(sym1));
   CPPUNIT_ASSERT_EQUAL(std::string("test"), pmt_symbol_to_string(sym1));
   CPPUNIT_ASSERT(pmt_is_true(sym1));
   CPPUNIT_ASSERT(!pmt_is_false(sym1));
 
-  pmt_t sym2 = pmt_string_to_symbol("foo");
-  pmt_t sym3 = pmt_string_to_symbol("test");
+  pmt_t sym2 = mp("foo");
+  pmt_t sym3 = mp("test");
   CPPUNIT_ASSERT_EQUAL(sym1, sym3);
   CPPUNIT_ASSERT(sym1 != sym2);
   CPPUNIT_ASSERT(sym1 == sym3);
@@ -56,7 +56,7 @@ qa_pmt_prims::test_symbols()
   for (int i = 0; i < N; i++){
     char buf[100];
     snprintf(buf, sizeof(buf), "test-%d", i);
-    v1[i] = pmt_string_to_symbol(buf);
+    v1[i] = mp(buf);
   }
 
   // confirm that they are all unique
@@ -68,7 +68,7 @@ qa_pmt_prims::test_symbols()
   for (int i = 0; i < N; i++){
     char buf[100];
     snprintf(buf, sizeof(buf), "test-%d", i);
-    v2[i] = pmt_string_to_symbol(buf);
+    v2[i] = mp(buf);
   }
 
   // confirm that we get the same ones back
@@ -79,7 +79,7 @@ qa_pmt_prims::test_symbols()
 void
 qa_pmt_prims::test_booleans()
 {
-  pmt_t sym = pmt_string_to_symbol("test");
+  pmt_t sym = mp("test");
   CPPUNIT_ASSERT(pmt_is_bool(PMT_T));
   CPPUNIT_ASSERT(pmt_is_bool(PMT_F));
   CPPUNIT_ASSERT(!pmt_is_bool(sym));
@@ -137,9 +137,9 @@ qa_pmt_prims::test_pairs()
 {
   CPPUNIT_ASSERT(pmt_is_null(PMT_NIL));
   CPPUNIT_ASSERT(!pmt_is_pair(PMT_NIL));
-  pmt_t s1 = pmt_string_to_symbol("s1");
-  pmt_t s2 = pmt_string_to_symbol("s2");
-  pmt_t s3 = pmt_string_to_symbol("s3");
+  pmt_t s1 = mp("s1");
+  pmt_t s2 = mp("s2");
+  pmt_t s3 = mp("s3");
 
 
   CPPUNIT_ASSERT_EQUAL((size_t)0, pmt_length(PMT_NIL));
@@ -174,9 +174,9 @@ qa_pmt_prims::test_vectors()
   static const size_t N = 3;
   pmt_t v1 = pmt_make_vector(N, PMT_NIL);
   CPPUNIT_ASSERT_EQUAL(N, pmt_length(v1));
-  pmt_t s0 = pmt_string_to_symbol("s0");
-  pmt_t s1 = pmt_string_to_symbol("s1");
-  pmt_t s2 = pmt_string_to_symbol("s2");
+  pmt_t s0 = mp("s0");
+  pmt_t s1 = mp("s1");
+  pmt_t s2 = mp("s2");
 
   pmt_vector_set(v1, 0, s0);
   pmt_vector_set(v1, 1, s1);
@@ -213,7 +213,7 @@ qa_pmt_prims::test_tuples()
   for (size_t i = 0; i < 10; i++){
     std::ostringstream os;
     os << "s" << i;
-    s[i] = pmt_string_to_symbol(os.str());
+    s[i] = mp(os.str());
     pmt_vector_set(v, i, s[i]);
   }
 
@@ -282,9 +282,9 @@ qa_pmt_prims::test_tuples()
 void
 qa_pmt_prims::test_equivalence()
 {
-  pmt_t s0 = pmt_string_to_symbol("s0");
-  pmt_t s1 = pmt_string_to_symbol("s1");
-  pmt_t s2 = pmt_string_to_symbol("s2");
+  pmt_t s0 = mp("s0");
+  pmt_t s1 = mp("s1");
+  pmt_t s2 = mp("s2");
   pmt_t list0 = pmt_cons(s0, pmt_cons(s1, pmt_cons(s2, PMT_NIL)));
   pmt_t list1 = pmt_cons(s0, pmt_cons(s1, pmt_cons(s2, PMT_NIL)));
   pmt_t i0 = pmt_from_long(42);
@@ -324,13 +324,13 @@ qa_pmt_prims::test_equivalence()
 void
 qa_pmt_prims::test_misc()
 {
-  pmt_t k0 = pmt_string_to_symbol("k0");
-  pmt_t k1 = pmt_string_to_symbol("k1");
-  pmt_t k2 = pmt_string_to_symbol("k2");
-  pmt_t k3 = pmt_string_to_symbol("k3");
-  pmt_t v0 = pmt_string_to_symbol("v0");
-  pmt_t v1 = pmt_string_to_symbol("v1");
-  pmt_t v2 = pmt_string_to_symbol("v2");
+  pmt_t k0 = mp("k0");
+  pmt_t k1 = mp("k1");
+  pmt_t k2 = mp("k2");
+  pmt_t k3 = mp("k3");
+  pmt_t v0 = mp("v0");
+  pmt_t v1 = mp("v1");
+  pmt_t v2 = mp("v2");
   pmt_t p0 = pmt_cons(k0, v0);
   pmt_t p1 = pmt_cons(k1, v1);
   pmt_t p2 = pmt_cons(k2, v2);
@@ -383,10 +383,10 @@ qa_pmt_prims::test_dict()
 void
 qa_pmt_prims::test_io()
 {
-  pmt_t k0 = pmt_string_to_symbol("k0");
-  pmt_t k1 = pmt_string_to_symbol("k1");
-  pmt_t k2 = pmt_string_to_symbol("k2");
-  pmt_t k3 = pmt_string_to_symbol("k3");
+  pmt_t k0 = mp("k0");
+  pmt_t k1 = mp("k1");
+  pmt_t k2 = mp("k2");
+  pmt_t k3 = mp("k3");
 
   CPPUNIT_ASSERT_EQUAL(std::string("k0"), pmt_write_string(k0));
 }
@@ -394,10 +394,10 @@ qa_pmt_prims::test_io()
 void
 qa_pmt_prims::test_lists()
 {
-  pmt_t s0 = pmt_intern("s0");
-  pmt_t s1 = pmt_intern("s1");
-  pmt_t s2 = pmt_intern("s2");
-  pmt_t s3 = pmt_intern("s3");
+  pmt_t s0 = mp("s0");
+  pmt_t s1 = mp("s1");
+  pmt_t s2 = mp("s2");
+  pmt_t s3 = mp("s3");
 
   pmt_t l1 = pmt_list4(s0, s1, s2, s3);
   pmt_t l2 = pmt_list3(s0, s1, s2);
@@ -468,7 +468,7 @@ qa_pmt_msg_accepter_nop::~qa_pmt_msg_accepter_nop(){}
 void
 qa_pmt_prims::test_msg_accepter()
 {
-  pmt_t sym = pmt_intern("my-symbol");
+  pmt_t sym = mp("my-symbol");
 
   boost::any a0;
   a0 = std::string("Hello!");
@@ -495,16 +495,16 @@ void
 qa_pmt_prims::test_serialize()
 {
   std::stringbuf sb;		// fake channel
-  pmt_t a = pmt_intern("a");
-  pmt_t b = pmt_intern("b");
-  pmt_t c = pmt_intern("c");
+  pmt_t a = mp("a");
+  pmt_t b = mp("b");
+  pmt_t c = mp("c");
 
   sb.str("");			// reset channel to empty
 
   // write stuff to channel
 
   pmt_serialize(PMT_NIL, sb);
-  pmt_serialize(pmt_intern("foobarvia"), sb);
+  pmt_serialize(mp("foobarvia"), sb);
   pmt_serialize(pmt_from_long(123456789), sb);
   pmt_serialize(pmt_from_long(-123456789), sb);
   pmt_serialize(pmt_cons(PMT_NIL, PMT_NIL), sb);
@@ -519,7 +519,7 @@ qa_pmt_prims::test_serialize()
   // read it back
 
   CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), PMT_NIL));
-  CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_intern("foobarvia")));
+  CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), mp("foobarvia")));
   CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_from_long(123456789)));
   CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_from_long(-123456789)));
   CPPUNIT_ASSERT(pmt_equal(pmt_deserialize(sb), pmt_cons(PMT_NIL, PMT_NIL)));
@@ -542,9 +542,9 @@ qa_pmt_prims::test_serialize()
 void
 qa_pmt_prims::test_sets()
 {
-  pmt_t s1 = pmt_intern("s1");
-  pmt_t s2 = pmt_intern("s2");
-  pmt_t s3 = pmt_intern("s3");
+  pmt_t s1 = mp("s1");
+  pmt_t s2 = mp("s2");
+  pmt_t s3 = mp("s3");
 
   pmt_t l1 = pmt_list1(s1);
   pmt_t l2 = pmt_list2(s2,s3);
-- 
cgit 


From 290fc2315a6b7f2d2bc6b98318783e3278a97453 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sun, 11 Apr 2010 13:30:45 -0700
Subject: Removed omnithreads dependency from libusrp2

---
 gruel/src/include/gruel/thread.h |  9 ++++++++-
 gruel/src/lib/Makefile.am        |  3 ++-
 gruel/src/lib/thread.cc          | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 gruel/src/lib/thread.cc

(limited to 'gruel')

diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h
index 0e7acaa85..26ca059f2 100644
--- a/gruel/src/include/gruel/thread.h
+++ b/gruel/src/include/gruel/thread.h
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2009 Free Software Foundation, Inc.
+ * Copyright 2009,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -22,12 +22,19 @@
 #define INCLUDED_THREAD_H
 
 #include 
+#include 
 
 namespace gruel {
 
   typedef boost::mutex                     mutex;
   typedef boost::unique_lock scoped_lock;
   typedef boost::condition_variable        condition_variable;
+  typedef boost::posix_time::time_duration duration;
+
+  /*!
+   * Returns absolute time 'secs' into the future
+   */
+  boost::system_time get_new_timeout(double secs);
 
 } /* namespace gruel */
 
diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am
index b21f8023c..6bde9ee27 100644
--- a/gruel/src/lib/Makefile.am
+++ b/gruel/src/lib/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2008,2009 Free Software Foundation, Inc.
+# Copyright 2008,2009,2010 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -45,6 +45,7 @@ MSG_LIB = msg/libmsg.la
 libgruel_la_SOURCES = 			\
 	realtime.cc 			\
 	sys_pri.cc 			\
+	thread.cc			\
 	thread_body_wrapper.cc 		\
 	thread_group.cc
 
diff --git a/gruel/src/lib/thread.cc b/gruel/src/lib/thread.cc
new file mode 100644
index 000000000..d8f77b506
--- /dev/null
+++ b/gruel/src/lib/thread.cc
@@ -0,0 +1,35 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2010 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 
+#endif
+#include 
+
+namespace gruel {
+
+  boost::system_time
+  get_new_timeout(double secs)
+  {
+    return boost::get_system_time() + boost::posix_time::milliseconds(long(secs*1e3));
+  }
+
+}
-- 
cgit 


From ad973608d979675755cb537f14ae0a53f71e6489 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 13 Apr 2010 13:51:33 -0700
Subject: Add gruel::thread as synonym to boost::thread for convenience

---
 gruel/src/include/gruel/thread.h | 1 +
 1 file changed, 1 insertion(+)

(limited to 'gruel')

diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h
index 26ca059f2..d72e5520c 100644
--- a/gruel/src/include/gruel/thread.h
+++ b/gruel/src/include/gruel/thread.h
@@ -26,6 +26,7 @@
 
 namespace gruel {
 
+  typedef boost::thread                    thread;
   typedef boost::mutex                     mutex;
   typedef boost::unique_lock scoped_lock;
   typedef boost::condition_variable        condition_variable;
-- 
cgit 


From ad13c00ae8cba6327851652a7d0c94a6d6316916 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Fri, 28 May 2010 20:02:38 -0700
Subject: Make C++ shared libraries versioned

---
 gruel/gruel.pc.in         | 2 +-
 gruel/src/lib/Makefile.am | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

(limited to 'gruel')

diff --git a/gruel/gruel.pc.in b/gruel/gruel.pc.in
index 6377f5bb3..504c4d949 100644
--- a/gruel/gruel.pc.in
+++ b/gruel/gruel.pc.in
@@ -6,6 +6,6 @@ includedir=@includedir@
 Name: gruel
 Description: The GNU Radio Utility Etcetera Library
 Requires: 
-Version: @VERSION@
+Version: @LIBVER@
 Libs: -L${libdir} -lgruel
 Cflags: -I${includedir}
diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am
index 6bde9ee27..1bcd26e90 100644
--- a/gruel/src/lib/Makefile.am
+++ b/gruel/src/lib/Makefile.am
@@ -34,7 +34,7 @@ noinst_PROGRAMS = test_gruel
 lib_LTLIBRARIES = libgruel.la
 
 # magic flags
-libgruel_la_LDFLAGS = $(NO_UNDEFINED) $(BOOST_LDFLAGS) -version-info 0:0:0
+libgruel_la_LDFLAGS = $(NO_UNDEFINED) $(BOOST_LDFLAGS) $(LTVERSIONFLAGS)
 
 # ----------------------------------------------------------------
 
-- 
cgit 


From c986a2add25920eabacfd620a1a2132cd7e4981d Mon Sep 17 00:00:00 2001
From: Eric Blossom
Date: Sat, 11 Sep 2010 13:06:10 -0700
Subject: Add support for uint64_t to pmt.

---
 gruel/src/include/gruel/pmt.h     | 21 +++++++++++++++++
 gruel/src/lib/pmt/pmt.cc          | 47 +++++++++++++++++++++++++++++++++++++++
 gruel/src/lib/pmt/pmt_int.h       | 14 ++++++++++++
 gruel/src/lib/pmt/pmt_io.cc       |  2 ++
 gruel/src/lib/pmt/qa_pmt_prims.cc | 13 +++++++++++
 gruel/src/lib/pmt/qa_pmt_prims.h  |  2 ++
 6 files changed, 99 insertions(+)

(limited to 'gruel')

diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h
index c371b023b..514b24d8b 100644
--- a/gruel/src/include/gruel/pmt.h
+++ b/gruel/src/include/gruel/pmt.h
@@ -163,6 +163,27 @@ pmt_t pmt_from_long(long x);
  */
 long pmt_to_long(pmt_t x);
 
+/*
+ * ------------------------------------------------------------------------
+ *			       uint64_t
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if \p x is an uint64 number, else false
+bool pmt_is_uint64(pmt_t x);
+
+//! Return the pmt value that represents the uint64 \p x.
+pmt_t pmt_from_uint64(uint64_t x);
+
+/*!
+ * \brief Convert pmt to uint64 if possible.
+ *
+ * When \p x represents an exact integer that fits in a uint64,
+ * return that uint64.  Else raise an exception, either wrong_type
+ * when x is not an exact uint64, or out_of_range when it doesn't fit.
+ */
+uint64_t pmt_to_uint64(pmt_t x);
+
 /*
  * ------------------------------------------------------------------------
  *				Reals
diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc
index aa1688d24..f9cf6b4bf 100644
--- a/gruel/src/lib/pmt/pmt.cc
+++ b/gruel/src/lib/pmt/pmt.cc
@@ -105,6 +105,12 @@ _integer(pmt_t x)
   return dynamic_cast(x.get());
 }
 
+static pmt_uint64 *
+_uint64(pmt_t x)
+{
+  return dynamic_cast(x.get());
+}
+
 static pmt_real *
 _real(pmt_t x)
 {
@@ -304,6 +310,40 @@ pmt_to_long(pmt_t x)
   throw pmt_wrong_type("pmt_to_long", x);
 }
 
+////////////////////////////////////////////////////////////////////////////
+//                             Uint64
+////////////////////////////////////////////////////////////////////////////
+
+pmt_uint64::pmt_uint64(uint64_t value) : d_value(value) {}
+
+bool
+pmt_is_uint64(pmt_t x)
+{
+  return x->is_uint64();
+}
+
+
+pmt_t
+pmt_from_uint64(uint64_t x)
+{
+  return pmt_t(new pmt_uint64(x));
+}
+
+uint64_t
+pmt_to_uint64(pmt_t x)
+{
+  if(x->is_uint64())
+    return _uint64(x)->value();
+  if(x->is_integer())
+    {
+    long tmp = _integer(x)->value();
+    if(tmp >= 0)
+        return (uint64_t) tmp;
+    }
+
+  throw pmt_wrong_type("pmt_to_uint64", x);
+}
+
 ////////////////////////////////////////////////////////////////////////////
 //                              Real
 ////////////////////////////////////////////////////////////////////////////
@@ -929,6 +969,9 @@ pmt_eqv(const pmt_t& x, const pmt_t& y)
   if (x->is_integer() && y->is_integer())
     return _integer(x)->value() == _integer(y)->value();
 
+  if (x->is_uint64() && y->is_uint64())
+    return _uint64(x)->value() == _uint64(y)->value();
+
   if (x->is_real() && y->is_real())
     return _real(x)->value() == _real(y)->value();
 
@@ -947,6 +990,9 @@ pmt_eqv_raw(pmt_base *x, pmt_base *y)
   if (x->is_integer() && y->is_integer())
     return _integer(x)->value() == _integer(y)->value();
 
+  if (x->is_uint64() && y->is_uint64())
+    return _uint64(x)->value() == _uint64(y)->value();
+
   if (x->is_real() && y->is_real())
     return _real(x)->value() == _real(y)->value();
 
@@ -1328,6 +1374,7 @@ pmt_dump_sizeof()
   printf("sizeof(pmt_bool)           = %3zd\n", sizeof(pmt_bool));
   printf("sizeof(pmt_symbol)         = %3zd\n", sizeof(pmt_symbol));
   printf("sizeof(pmt_integer)        = %3zd\n", sizeof(pmt_integer));
+  printf("sizeof(pmt_uint64)         = %3zd\n", sizeof(pmt_uint64));
   printf("sizeof(pmt_real)           = %3zd\n", sizeof(pmt_real));
   printf("sizeof(pmt_complex)        = %3zd\n", sizeof(pmt_complex));
   printf("sizeof(pmt_null)           = %3zd\n", sizeof(pmt_null));
diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h
index 50683ffb5..ea28e37b4 100644
--- a/gruel/src/lib/pmt/pmt_int.h
+++ b/gruel/src/lib/pmt/pmt_int.h
@@ -47,6 +47,7 @@ public:
   virtual bool is_symbol()  const { return false; }
   virtual bool is_number()  const { return false; }
   virtual bool is_integer() const { return false; }
+  virtual bool is_uint64()  const { return false; }
   virtual bool is_real()    const { return false; }
   virtual bool is_complex() const { return false; }
   virtual bool is_null()    const { return false; }
@@ -118,6 +119,19 @@ public:
   long value() const { return d_value; }
 };
 
+class pmt_uint64 : public pmt_base
+{
+public:
+  uint64_t		d_value;
+
+  pmt_uint64(uint64_t value);
+  //~pmt_uint64(){}
+
+  bool is_number()  const { return true; }
+  bool is_uint64() const { return true; }
+  uint64_t value() const { return d_value; }
+};
+
 class pmt_real : public pmt_base
 {
 public:
diff --git a/gruel/src/lib/pmt/pmt_io.cc b/gruel/src/lib/pmt/pmt_io.cc
index 179e6b72c..b909c1b64 100644
--- a/gruel/src/lib/pmt/pmt_io.cc
+++ b/gruel/src/lib/pmt/pmt_io.cc
@@ -64,6 +64,8 @@ pmt_write(pmt_t obj, std::ostream &port)
   else if (pmt_is_number(obj)){
     if (pmt_is_integer(obj))
       port << pmt_to_long(obj);
+    else if (pmt_is_uint64(obj))
+      port << pmt_to_uint64(obj);
     else if (pmt_is_real(obj))
       port << pmt_to_double(obj);
     else if (pmt_is_complex(obj)){
diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc
index f2414c72c..985361f13 100644
--- a/gruel/src/lib/pmt/qa_pmt_prims.cc
+++ b/gruel/src/lib/pmt/qa_pmt_prims.cc
@@ -103,6 +103,19 @@ qa_pmt_prims::test_integers()
   CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(p1));
 }
 
+void
+qa_pmt_prims::test_uint64s()
+{
+  pmt_t p1 = pmt_from_uint64((uint64_t)1);
+  pmt_t m1 = pmt_from_uint64((uint64_t)8589934592ULL);
+  CPPUNIT_ASSERT(!pmt_is_uint64(PMT_T));
+  CPPUNIT_ASSERT(pmt_is_uint64(p1));
+  CPPUNIT_ASSERT(pmt_is_uint64(m1));
+  CPPUNIT_ASSERT_THROW(pmt_to_uint64(PMT_T), pmt_wrong_type);
+  CPPUNIT_ASSERT_EQUAL((uint64_t)8589934592ULL, (uint64_t)pmt_to_uint64(m1));
+  CPPUNIT_ASSERT_EQUAL((uint64_t)1ULL, (uint64_t)pmt_to_uint64(p1));
+}
+
 void
 qa_pmt_prims::test_reals()
 {
diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h
index 29ba02f11..efc5c6050 100644
--- a/gruel/src/lib/pmt/qa_pmt_prims.h
+++ b/gruel/src/lib/pmt/qa_pmt_prims.h
@@ -31,6 +31,7 @@ class qa_pmt_prims : public CppUnit::TestCase {
   CPPUNIT_TEST(test_symbols);
   CPPUNIT_TEST(test_booleans);
   CPPUNIT_TEST(test_integers);
+  CPPUNIT_TEST(test_uint64s);
   CPPUNIT_TEST(test_reals);
   CPPUNIT_TEST(test_complexes);
   CPPUNIT_TEST(test_pairs);
@@ -52,6 +53,7 @@ class qa_pmt_prims : public CppUnit::TestCase {
   void test_symbols();
   void test_booleans();
   void test_integers();
+  void test_uint64s();
   void test_reals();
   void test_complexes();
   void test_pairs();
-- 
cgit 


From 036a42c08eadbd0a2c462ca61d9d883996be8042 Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Thu, 30 Sep 2010 16:08:53 -0400
Subject: Adding an XML outputter for the CPP Unit tests. This is to a) store
 the output information but also b) for integration with Hudson for logging
 and displaying the results during the build stages. This only covers a few
 cases so far and I need to define a better place to save the output files.

---
 gruel/src/lib/test_gruel.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'gruel')

diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc
index 669303447..cb5f2d36b 100644
--- a/gruel/src/lib/test_gruel.cc
+++ b/gruel/src/lib/test_gruel.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2009 Free Software Foundation, Inc.
+ * Copyright 2006,2009,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -21,6 +21,7 @@
  */
 
 #include 
+#include 
 #include "pmt/qa_pmt.h"
 
 int 
@@ -28,8 +29,11 @@ main(int argc, char **argv)
 {
   
   CppUnit::TextTestRunner	runner;
+  std::ofstream xmlfile("cppunit_gruel.xml");
+  CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile);
 
   runner.addTest(qa_pmt::suite ());
+  runner.setOutputter(xmlout);
   
   bool was_successful = runner.run("", false);
 
-- 
cgit 


From 2b8bd0d2fa7c76282a772b75cb99e7bd5f2be13f Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Sat, 2 Oct 2010 17:16:04 -0400
Subject: Moving XML output files from cppunit tests to
 $HOME/.gnuradio/unittests. This also adds a new utility gr_unittests.h, which
 sets up the path for output files.

---
 gruel/src/lib/test_gruel.cc | 53 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

(limited to 'gruel')

diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc
index cb5f2d36b..f4b9fc4e2 100644
--- a/gruel/src/lib/test_gruel.cc
+++ b/gruel/src/lib/test_gruel.cc
@@ -22,14 +22,22 @@
 
 #include 
 #include 
+
+#include 
+#include 
+
 #include "pmt/qa_pmt.h"
 
+static void get_unittest_path (const char *filename, char *fullpath, size_t pathsize);
+
 int 
 main(int argc, char **argv)
 {
+  char path[200];
+  get_unittest_path ("gruel.xml", path, 200);
   
-  CppUnit::TextTestRunner	runner;
-  std::ofstream xmlfile("cppunit_gruel.xml");
+  CppUnit::TextTestRunner runner;
+  std::ofstream xmlfile(path);
   CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile);
 
   runner.addTest(qa_pmt::suite ());
@@ -39,3 +47,44 @@ main(int argc, char **argv)
 
   return was_successful ? 0 : 1;
 }
+
+
+// NOTE: These are defined in gr_unittest.h for the rest of the project;
+// rewriting here since we don't depend on gnuradio-core in gruel
+
+#ifdef MKDIR_TAKES_ONE_ARG
+#define gr_mkdir(pathname, mode) mkdir(pathname)
+#else
+#define gr_mkdir(pathname, mode) mkdir((pathname), (mode))
+#endif
+
+/*
+ * Mostly taken from gr_preferences.cc/h
+ * The simplest thing that could possibly work:
+ *  the key is the filename; the value is the file contents.
+ */
+
+static void
+ensure_unittest_path (const char *grpath, const char *path)
+{
+  struct stat statbuf;
+  if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
+    return;
+
+  // blindly try to make it 	// FIXME make this robust. C++ SUCKS!
+  gr_mkdir (grpath, 0750);
+  gr_mkdir (path, 0750);
+}
+
+static void
+get_unittest_path (const char *filename, char *fullpath, size_t pathsize)
+{
+  char path[200];
+  char grpath[200];
+  snprintf (grpath, sizeof(grpath), "%s/.gnuradio", getenv ("HOME"));
+  snprintf (path, sizeof(path), "%s/unittests", grpath);
+  snprintf (fullpath, pathsize, "%s/%s", path, filename);
+
+  ensure_unittest_path(grpath, path);
+}
+
-- 
cgit 


From cb2fa9a58c9a52f3501881964ee4f59992c5d84d Mon Sep 17 00:00:00 2001
From: Michael Dickens
Date: Sat, 9 Oct 2010 16:11:03 -0400
Subject: rearrange includes to always be: internal GR, external, with GR.

---
 gruel/src/lib/Makefile.am     | 4 ++--
 gruel/src/lib/msg/Makefile.am | 5 +++--
 gruel/src/lib/pmt/Makefile.am | 6 +++---
 3 files changed, 8 insertions(+), 7 deletions(-)

(limited to 'gruel')

diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am
index 1bcd26e90..5c3302f19 100644
--- a/gruel/src/lib/Makefile.am
+++ b/gruel/src/lib/Makefile.am
@@ -23,8 +23,8 @@ include $(top_srcdir)/Makefile.common
 
 SUBDIRS = pmt msg
 
-AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES)
-
+AM_CPPFLAGS = $(DEFINES) $(GRUEL_INCLUDES) $(BOOST_CPPFLAGS) \
+	$(CPPUNIT_INCLUDES) $(WITH_INCLUDES)
 
 TESTS = test_gruel
 
diff --git a/gruel/src/lib/msg/Makefile.am b/gruel/src/lib/msg/Makefile.am
index 13a657067..9dbaf10f5 100644
--- a/gruel/src/lib/msg/Makefile.am
+++ b/gruel/src/lib/msg/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2009 Free Software Foundation, Inc.
+# Copyright 2009,2010 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -21,7 +21,8 @@
 
 include $(top_srcdir)/Makefile.common
 
-AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(GRUEL_INCLUDES) $(WITH_INCLUDES)
+AM_CPPFLAGS = $(DEFINES) $(GRUEL_INCLUDES) \
+	$(BOOST_CPPFLAGS) $(WITH_INCLUDES)
 
 noinst_LTLIBRARIES = libmsg.la
 
diff --git a/gruel/src/lib/pmt/Makefile.am b/gruel/src/lib/pmt/Makefile.am
index 8750cbdf8..d3efc1afa 100644
--- a/gruel/src/lib/pmt/Makefile.am
+++ b/gruel/src/lib/pmt/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2008,2009 Free Software Foundation, Inc.
+# Copyright 2008,2009,2010 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -21,8 +21,8 @@
 
 include $(top_srcdir)/Makefile.common
 
-AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES)
-
+AM_CPPFLAGS = $(DEFINES) $(GRUEL_INCLUDES) $(BOOST_CPPFLAGS) \
+	$(CPPUNIT_INCLUDES) $(WITH_INCLUDES)
 
 noinst_LTLIBRARIES = libpmt.la
 
-- 
cgit 


From d692a41f98e7b888c745efbb9fcbbb0400f39025 Mon Sep 17 00:00:00 2001
From: Eric Blossom
Date: Wed, 24 Nov 2010 17:29:11 -0800
Subject: Major Makefile.am housecleaning.  Passes distcheck.

Move all occurrences of swig_built_sources out of Makefile.am's.
Move all SWIG related use of BUILT_SOURCES out of Makefile.am's.
Clean up 'if PYTHON' conditionalization in gr-*

Still left to do: fix Makefile.swig CLEANFILES and no_dist_files
such that they remove exactly the generated files.
---
 gruel/Makefile.am                     | 4 ++--
 gruel/src/include/gruel/Makefile.am   | 5 ++---
 gruel/src/lib/pmt/Makefile.am         | 2 +-
 gruel/src/scheme/gnuradio/Makefile.am | 8 +++++---
 4 files changed, 10 insertions(+), 9 deletions(-)

(limited to 'gruel')

diff --git a/gruel/Makefile.am b/gruel/Makefile.am
index 93f56a7db..c43e461f2 100644
--- a/gruel/Makefile.am
+++ b/gruel/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2008 Free Software Foundation, Inc.
+# Copyright 2008,2010 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -21,7 +21,7 @@
 
 include $(top_srcdir)/Makefile.common
 
-EXTRA_DIST = \
+EXTRA_DIST += \
     gruel.pc.in
 
 SUBDIRS = src
diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am
index 67dd12995..d7ac3d332 100644
--- a/gruel/src/include/gruel/Makefile.am
+++ b/gruel/src/include/gruel/Makefile.am
@@ -21,13 +21,12 @@
 
 include $(top_srcdir)/Makefile.common
 
-BUILT_SOURCES = \
-	inet.h
+EXTRA_DIST += inet.h.in
 
 gruelincludedir = $(prefix)/include/gruel
 
 gruelinclude_HEADERS = \
-	$(BUILT_SOURCES) \
+	inet.h \
 	msg_accepter.h \
 	msg_accepter_msgq.h \
 	msg_queue.h \
diff --git a/gruel/src/lib/pmt/Makefile.am b/gruel/src/lib/pmt/Makefile.am
index d3efc1afa..7a1f2e7d4 100644
--- a/gruel/src/lib/pmt/Makefile.am
+++ b/gruel/src/lib/pmt/Makefile.am
@@ -48,7 +48,7 @@ python_built_sources = $(GENERATED_H) $(GENERATED_CC)
 PMT_SERIAL_TAGS_H = $(abs_top_builddir)/gruel/src/include/gruel/pmt_serial_tags.h
 BUILT_SOURCES = $(python_built_sources) $(PMT_SERIAL_TAGS_H)
 
-EXTRA_DIST = $(code_generator)
+EXTRA_DIST += $(code_generator)
 
 # ----------------------------------------------------------------
 
diff --git a/gruel/src/scheme/gnuradio/Makefile.am b/gruel/src/scheme/gnuradio/Makefile.am
index 0ce01f6f8..2f8e5c8d2 100644
--- a/gruel/src/scheme/gnuradio/Makefile.am
+++ b/gruel/src/scheme/gnuradio/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2007,2009 Free Software Foundation, Inc.
+# Copyright 2007,2009,2010 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -18,12 +18,14 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
 
+include $(top_srcdir)/Makefile.common
+
 #pkgdatadir = $(datadir)/gnuradio
 
-EXTRA_DIST = 				\
+EXTRA_DIST += \
 	gen-serial-tags.scm
 
-# really scheme source files
+# really scheme source files FIXME wrong location
 dist_pkgdata_DATA =			\
 	pmt-serial-tags.scm		\
 	pmt-serialize.scm		\
-- 
cgit 


From 153de8c41caa9c478bec2f10b8a1167952809eed Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Thu, 23 Dec 2010 18:31:28 -0500
Subject: Modifying the unittest output. XML files are no longer written
 outside of the build tree.

---
 gruel/src/lib/test_gruel.cc | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

(limited to 'gruel')

diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc
index f4b9fc4e2..2c9528b0a 100644
--- a/gruel/src/lib/test_gruel.cc
+++ b/gruel/src/lib/test_gruel.cc
@@ -65,14 +65,13 @@ main(int argc, char **argv)
  */
 
 static void
-ensure_unittest_path (const char *grpath, const char *path)
+ensure_unittest_path (const char *path)
 {
   struct stat statbuf;
   if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
     return;
 
   // blindly try to make it 	// FIXME make this robust. C++ SUCKS!
-  gr_mkdir (grpath, 0750);
   gr_mkdir (path, 0750);
 }
 
@@ -80,11 +79,9 @@ static void
 get_unittest_path (const char *filename, char *fullpath, size_t pathsize)
 {
   char path[200];
-  char grpath[200];
-  snprintf (grpath, sizeof(grpath), "%s/.gnuradio", getenv ("HOME"));
-  snprintf (path, sizeof(path), "%s/unittests", grpath);
+  snprintf (path, sizeof(path), "./.unittests");
   snprintf (fullpath, pathsize, "%s/%s", path, filename);
 
-  ensure_unittest_path(grpath, path);
+  ensure_unittest_path(path);
 }
 
-- 
cgit 


From 05cc02cec03507c47846a668c92e6dcc4ba2e71e Mon Sep 17 00:00:00 2001
From: Josh Blum
Date: Tue, 18 Jan 2011 01:00:15 -0800
Subject: cleanup mkdir usage with boost filesystem:

Replaced copy/pasted code and MKDIR_TAKES_ONE_ARG #ifdefs
with portable boost filesystem path and directory creation.

Gets the correct home directory on windows systems: APPDATA.
Replaces large amounts of copypasta with single lines of code.
Removes MKDIR_TAKES_ONE_ARG configuration checks from m4 files.
Adds boost filesystem and system library as build dependencies.
---
 gruel/src/lib/Makefile.am   |  2 ++
 gruel/src/lib/test_gruel.cc | 51 +++++++--------------------------------------
 2 files changed, 10 insertions(+), 43 deletions(-)

(limited to 'gruel')

diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am
index 5c3302f19..876e7ab3d 100644
--- a/gruel/src/lib/Makefile.am
+++ b/gruel/src/lib/Makefile.am
@@ -51,6 +51,8 @@ libgruel_la_SOURCES = 			\
 
 libgruel_la_LIBADD = 			\
 	$(BOOST_THREAD_LIB) 		\
+	$(BOOST_SYSTEM_LIB) 		\
+	$(BOOST_FILESYSTEM_LIB) 	\
 	$(PMT_LIB)			\
 	$(MSG_LIB)			\
 	-lstdc++
diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc
index 2c9528b0a..efb6cb777 100644
--- a/gruel/src/lib/test_gruel.cc
+++ b/gruel/src/lib/test_gruel.cc
@@ -28,16 +28,19 @@
 
 #include "pmt/qa_pmt.h"
 
-static void get_unittest_path (const char *filename, char *fullpath, size_t pathsize);
+#include 
+#include 
+namespace fs = boost::filesystem;
 
 int 
 main(int argc, char **argv)
 {
-  char path[200];
-  get_unittest_path ("gruel.xml", path, 200);
-  
+  fs::path path = fs::current_path() / ".unittests";
+  if (!fs::is_directory(path)) fs::create_directory(path);
+  path = path / "gruel.xml";
+
   CppUnit::TextTestRunner runner;
-  std::ofstream xmlfile(path);
+  std::ofstream xmlfile(path.string().c_str());
   CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile);
 
   runner.addTest(qa_pmt::suite ());
@@ -47,41 +50,3 @@ main(int argc, char **argv)
 
   return was_successful ? 0 : 1;
 }
-
-
-// NOTE: These are defined in gr_unittest.h for the rest of the project;
-// rewriting here since we don't depend on gnuradio-core in gruel
-
-#ifdef MKDIR_TAKES_ONE_ARG
-#define gr_mkdir(pathname, mode) mkdir(pathname)
-#else
-#define gr_mkdir(pathname, mode) mkdir((pathname), (mode))
-#endif
-
-/*
- * Mostly taken from gr_preferences.cc/h
- * The simplest thing that could possibly work:
- *  the key is the filename; the value is the file contents.
- */
-
-static void
-ensure_unittest_path (const char *path)
-{
-  struct stat statbuf;
-  if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
-    return;
-
-  // blindly try to make it 	// FIXME make this robust. C++ SUCKS!
-  gr_mkdir (path, 0750);
-}
-
-static void
-get_unittest_path (const char *filename, char *fullpath, size_t pathsize)
-{
-  char path[200];
-  snprintf (path, sizeof(path), "./.unittests");
-  snprintf (fullpath, pathsize, "%s/%s", path, filename);
-
-  ensure_unittest_path(path);
-}
-
-- 
cgit 


From ebb0f56da62e9ff16928b32cc525f24c93a99e0b Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Sat, 22 Jan 2011 14:54:20 -0500
Subject: Updating copyright.

---
 gruel/src/lib/Makefile.am   | 2 +-
 gruel/src/lib/test_gruel.cc | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

(limited to 'gruel')

diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am
index 876e7ab3d..b9b35ae10 100644
--- a/gruel/src/lib/Makefile.am
+++ b/gruel/src/lib/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2008,2009,2010 Free Software Foundation, Inc.
+# Copyright 2008,2009,2010,2011 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc
index efb6cb777..7ef3520e6 100644
--- a/gruel/src/lib/test_gruel.cc
+++ b/gruel/src/lib/test_gruel.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2009,2010 Free Software Foundation, Inc.
+ * Copyright 2006,2009,2010,2011 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
-- 
cgit 


From cb35c3e28f277717d8f9f849636768d57720487f Mon Sep 17 00:00:00 2001
From: Josh Blum
Date: Wed, 2 Feb 2011 19:40:16 -0800
Subject: gruel: generate pmt_serial_tags with python, removes guile dependency

---
 gruel/src/lib/pmt/Makefile.am                 |   8 +-
 gruel/src/scheme/gnuradio/Makefile.am         |   4 +-
 gruel/src/scheme/gnuradio/gen-serial-tags.py  |  53 ++++++++++++
 gruel/src/scheme/gnuradio/gen-serial-tags.scm | 118 --------------------------
 4 files changed, 59 insertions(+), 124 deletions(-)
 create mode 100644 gruel/src/scheme/gnuradio/gen-serial-tags.py
 delete mode 100755 gruel/src/scheme/gnuradio/gen-serial-tags.scm

(limited to 'gruel')

diff --git a/gruel/src/lib/pmt/Makefile.am b/gruel/src/lib/pmt/Makefile.am
index 7a1f2e7d4..0c8e12dc3 100644
--- a/gruel/src/lib/pmt/Makefile.am
+++ b/gruel/src/lib/pmt/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2008,2009,2010 Free Software Foundation, Inc.
+# Copyright 2008,2009,2010,2011 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -99,7 +99,7 @@ gen_sources_deps = $(core_generator)
 par_gen_command = PYTHONPATH=$(top_srcdir)/gruel/src/lib/pmt srcdir=$(srcdir) $(PYTHON) $(srcdir)/generate_unv.py
 include $(top_srcdir)/Makefile.par.gen
 
-# Rule to create the build header file using GUILE
+# Rule to create the build header file using python
 # Doesn't need parallel protections because there is a single target
-$(PMT_SERIAL_TAGS_H): $(srcdir)/../../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../../scheme/gnuradio/pmt-serial-tags.scm
-	$(RUN_GUILE) $(srcdir)/../../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../../scheme/gnuradio/pmt-serial-tags.scm $(PMT_SERIAL_TAGS_H)
+$(PMT_SERIAL_TAGS_H): $(top_srcdir)/gruel/src/scheme/gnuradio/gen-serial-tags.py $(top_srcdir)/gruel/src/scheme/gnuradio/pmt-serial-tags.scm
+	$(PYTHON) $^ $@
diff --git a/gruel/src/scheme/gnuradio/Makefile.am b/gruel/src/scheme/gnuradio/Makefile.am
index 2f8e5c8d2..e7b6bf744 100644
--- a/gruel/src/scheme/gnuradio/Makefile.am
+++ b/gruel/src/scheme/gnuradio/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2007,2009,2010 Free Software Foundation, Inc.
+# Copyright 2007,2009,2010,2011 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -23,7 +23,7 @@ include $(top_srcdir)/Makefile.common
 #pkgdatadir = $(datadir)/gnuradio
 
 EXTRA_DIST += \
-	gen-serial-tags.scm
+	gen-serial-tags.py
 
 # really scheme source files FIXME wrong location
 dist_pkgdata_DATA =			\
diff --git a/gruel/src/scheme/gnuradio/gen-serial-tags.py b/gruel/src/scheme/gnuradio/gen-serial-tags.py
new file mode 100644
index 000000000..18e927beb
--- /dev/null
+++ b/gruel/src/scheme/gnuradio/gen-serial-tags.py
@@ -0,0 +1,53 @@
+"""
+//
+// Copyright 2011 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.
+//
+//
+// THIS FILE IS MACHINE GENERATED FROM %s. DO NOT EDIT BY HAND.
+// See %s for additional commentary.
+//
+
+#ifndef INCLUDED_PMT_SERIAL_TAGS_H
+#define INCLUDED_PMT_SERIAL_TAGS_H
+
+enum pst_tags {
+%s
+};
+#endif /* INCLUDED_PMT_SERIAL_TAGS_H */
+"""
+
+import sys, os, re
+
+if __name__ == '__main__':
+    if len(sys.argv) != 3:
+        print "Usage %s  "%__file__
+        exit()
+    input_scm_file, output_hdr_file = sys.argv[1:]
+    enums = list()
+    for line in open(input_scm_file).readlines():
+        match = re.match('^\s*\(define\s+([\w|-]+)\s+#x([0-9a-fA-F]+)\)', line)
+        if not match: continue
+        name, value = match.groups()
+        name = name.upper().replace('-', '_')
+        enums.append('    %s = 0x%s'%(name, value))
+    open(output_hdr_file, 'w').write(__doc__%(
+        os.path.basename(__file__),
+        os.path.basename(input_scm_file),
+        ',\n'.join(enums),
+    ))
diff --git a/gruel/src/scheme/gnuradio/gen-serial-tags.scm b/gruel/src/scheme/gnuradio/gen-serial-tags.scm
deleted file mode 100755
index 7b9087228..000000000
--- a/gruel/src/scheme/gnuradio/gen-serial-tags.scm
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/usr/bin/guile \
--e main -s
-!#
-;;; -*-scheme-*-
-;;;
-;;; 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.
-;;;
-
-(use-modules (ice-9 format))
-
-(defmacro when (pred . body)
-  `(if ,pred (begin ,@body) #f))
-
-;; ----------------------------------------------------------------
-
-(define (main args)
-
-  (define (usage)
-    (format 0
-	    "usage: ~a  ~%"
-	    (car args)))
-
-  (when (not (= (length args) 3))
-	(usage)
-	(format 0 "args: ~s~%" args)
-	(exit 1))
-      
-  (let ((i-file (open-input-file (cadr args)))
-	(h-file (open-output-file (caddr args))))
-
-      (write-header-comment h-file "// ")
-      (display "#ifndef INCLUDED_PMT_SERIAL_TAGS_H\n" h-file)
-      (display "#define INCLUDED_PMT_SERIAL_TAGS_H\n" h-file)
-      (newline h-file)
-      (display "enum pst_tags {\n" h-file)
-
-      (for-each-in-file i-file
-       (lambda (form)
-	 (let* ((name (cadr form))
-		(c-name (string-upcase (c-ify name)))
-		(value (caddr form)))
-	   ;;(format h-file   "static const int ~a\t= 0x~x;~%" c-name value)
-	   (format h-file   "  ~a\t= 0x~x,~%" c-name value))))
-
-      (display "};\n" h-file)
-      (display "#endif\n" h-file)))
-
-(define (c-ify name)
-  (list->string (map (lambda (c)
-		       (if (eqv? c #\-) #\_ c))
-		     (string->list (symbol->string name)))))
-
-
-(define (write-header-comment o-port prefix)
-  (for-each (lambda (comment)
-	      (format o-port "~a~a~%" prefix comment))
-	    header-comment))
-
-(define header-comment
-  '(
-    ""
-    "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."
-    ""
-    ""
-    "THIS FILE IS MACHINE GENERATED FROM pmt-serial-tags.scm. DO NOT EDIT BY HAND."
-    "See pmt-serial-tags.scm for additional commentary."
-    ""))
-
-
-
-(define (for-each-in-file file f)
-  (let ((port (if (port? file)
-		  file
-		  (open-input-file file))))
-    (letrec
-     ((loop
-       (lambda (port form)
-	 (cond ((eof-object? form)
-		(when (not (eq? port file))
-		      (close-input-port port))
-		#t)
-	       (else
-		(f form)
-		(set! form #f)		; for GC
-		(loop port (read port)))))))
-     (loop port (read port)))))
-- 
cgit 


From e73c25fb9226029f0e50052b1ffacedb3a78622b Mon Sep 17 00:00:00 2001
From: Josh Blum
Date: Mon, 24 Jan 2011 00:34:28 -0800
Subject: gruel thread simplification:

Removed get_new_timeout from thread.h (usrp2_vrt carryover) Basically it was created because of a misunderstanding of the time types; and its only ever called once. This also removes thread.cc

Call posix_time::milliseconds in usrp2 control.cc. Notice that it passes a time_duration rather than a ptime (aka system time).

Added #include  to gr_buffer.h. It turns out that boost posix_time.hpp implicitly included the deque header which was missing from gr_buffer.h

Replaced the include for thread.hpp with only the includes for the boost thread types mentioned in gruel/thread.h. Also, making use of the scoped_lock typedef that comes with boost thread locks. boost 3.5 safe.
---
 gruel/src/include/gruel/thread.h | 16 ++++++----------
 gruel/src/lib/Makefile.am        |  1 -
 gruel/src/lib/thread.cc          | 35 -----------------------------------
 3 files changed, 6 insertions(+), 46 deletions(-)
 delete mode 100644 gruel/src/lib/thread.cc

(limited to 'gruel')

diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h
index d72e5520c..5a8ab1876 100644
--- a/gruel/src/include/gruel/thread.h
+++ b/gruel/src/include/gruel/thread.h
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2009,2010 Free Software Foundation, Inc.
+ * Copyright 2009,2010,2011 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -21,21 +21,17 @@
 #ifndef INCLUDED_THREAD_H
 #define INCLUDED_THREAD_H
 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
 
 namespace gruel {
 
   typedef boost::thread                    thread;
   typedef boost::mutex                     mutex;
-  typedef boost::unique_lock scoped_lock;
+  typedef boost::mutex::scoped_lock        scoped_lock;
   typedef boost::condition_variable        condition_variable;
-  typedef boost::posix_time::time_duration duration;
-
-  /*!
-   * Returns absolute time 'secs' into the future
-   */
-  boost::system_time get_new_timeout(double secs);
 
 } /* namespace gruel */
 
diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am
index b9b35ae10..f37ab27a1 100644
--- a/gruel/src/lib/Makefile.am
+++ b/gruel/src/lib/Makefile.am
@@ -45,7 +45,6 @@ MSG_LIB = msg/libmsg.la
 libgruel_la_SOURCES = 			\
 	realtime.cc 			\
 	sys_pri.cc 			\
-	thread.cc			\
 	thread_body_wrapper.cc 		\
 	thread_group.cc
 
diff --git a/gruel/src/lib/thread.cc b/gruel/src/lib/thread.cc
deleted file mode 100644
index d8f77b506..000000000
--- a/gruel/src/lib/thread.cc
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2010 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 
-#endif
-#include 
-
-namespace gruel {
-
-  boost::system_time
-  get_new_timeout(double secs)
-  {
-    return boost::get_system_time() + boost::posix_time::milliseconds(long(secs*1e3));
-  }
-
-}
-- 
cgit 


From bf9c13870fa9766b68dbfeda9307c4a0aa5e2963 Mon Sep 17 00:00:00 2001
From: Josh Blum
Date: Mon, 14 Mar 2011 11:23:19 -0700
Subject: created gruel/attributes.h to house compiler specific attribute
 macros

replaced instances of __attribute__ with __GR_ATTR from attributes.h

what else has compiler specific attributes?
volk - volk is stand-alone, needs its own attributes.h
gcell - not touching that, probably gcc only anyways
usrp2 firmware - does not matter to host build
---
 gruel/src/include/gruel/Makefile.am  |  3 +-
 gruel/src/include/gruel/attributes.h | 56 ++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 gruel/src/include/gruel/attributes.h

(limited to 'gruel')

diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am
index d7ac3d332..89a9da7f0 100644
--- a/gruel/src/include/gruel/Makefile.am
+++ b/gruel/src/include/gruel/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2008,2009 Free Software Foundation, Inc.
+# Copyright 2008-2011 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -26,6 +26,7 @@ EXTRA_DIST += inet.h.in
 gruelincludedir = $(prefix)/include/gruel
 
 gruelinclude_HEADERS = \
+	attributes.h \
 	inet.h \
 	msg_accepter.h \
 	msg_accepter_msgq.h \
diff --git a/gruel/src/include/gruel/attributes.h b/gruel/src/include/gruel/attributes.h
new file mode 100644
index 000000000..fdf48c977
--- /dev/null
+++ b/gruel/src/include/gruel/attributes.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2010 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.
+ */
+
+#ifndef INCLUDED_GRUEL_ATTRIBUTES_H
+#define INCLUDED_GRUEL_ATTRIBUTES_H
+
+////////////////////////////////////////////////////////////////////////
+// Cross-platform attribute macros
+////////////////////////////////////////////////////////////////////////
+#if defined __GNUC__
+#  define __GR_ATTR_ALIGNED(x) __attribute__((aligned(x)))
+#  define __GR_ATTR_UNUSED     __attribute__((unused))
+#  define __GR_ATTR_INLINE     __attribute__((always_inline))
+#  define __GR_ATTR_DEPRECATED __attribute__((deprecated))
+#  if __GNUC__ >= 4
+#    define __GR_ATTR_EXPORT   __attribute__((visibility("default")))
+#    define __GR_ATTR_IMPORT   __attribute__((visibility("default")))
+#  else
+#    define __GR_ATTR_EXPORT
+#    define __GR_ATTR_IMPORT
+#  endif
+#elif _MSC_VER
+#  define __GR_ATTR_ALIGNED(x) __declspec(align(x))
+#  define __GR_ATTR_UNUSED
+#  define __GR_ATTR_INLINE     __forceinline
+#  define __GR_ATTR_DEPRECATED __declspec(deprecated)
+#  define __GR_ATTR_EXPORT     __declspec(dllexport)
+#  define __GR_ATTR_IMPORT     __declspec(dllimport)
+#else
+#  define __GR_ATTR_ALIGNED(x)
+#  define __GR_ATTR_UNUSED
+#  define __GR_ATTR_INLINE
+#  define __GR_ATTR_DEPRECATED
+#  define __GR_ATTR_EXPORT
+#  define __GR_ATTR_IMPORT
+#endif
+
+#endif /* INCLUDED_GRUEL_ATTRIBUTES_H */
-- 
cgit 


From a611da7044175fede5f8ecfe13a055f5680fd3f9 Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Mon, 14 Mar 2011 19:33:03 -0400
Subject: gruel: SWIGing Gruel into Python to access PMTs.

---
 gruel/src/Makefile.am              |   8 +-
 gruel/src/include/gruel/pmt.h      |  16 +-
 gruel/src/lib/pmt/pmt_io.cc        |  10 +
 gruel/src/lib/pmt/pmt_serialize.cc | 107 +++++-
 gruel/src/python/Makefile.am       |  39 ++
 gruel/src/python/__init__.py       |   1 +
 gruel/src/python/qa_pmt.py         |  14 +
 gruel/src/python/run_tests.in      |  17 +
 gruel/src/swig/Makefile.am         |  71 ++++
 gruel/src/swig/Makefile.swig.gen   | 115 ++++++
 gruel/src/swig/__init__.py         |   0
 gruel/src/swig/pmt.i               | 759 +++++++++++++++++++++++++++++++++++++
 12 files changed, 1150 insertions(+), 7 deletions(-)
 create mode 100644 gruel/src/python/Makefile.am
 create mode 100644 gruel/src/python/__init__.py
 create mode 100755 gruel/src/python/qa_pmt.py
 create mode 100644 gruel/src/python/run_tests.in
 create mode 100644 gruel/src/swig/Makefile.am
 create mode 100644 gruel/src/swig/Makefile.swig.gen
 create mode 100644 gruel/src/swig/__init__.py
 create mode 100644 gruel/src/swig/pmt.i

(limited to 'gruel')

diff --git a/gruel/src/Makefile.am b/gruel/src/Makefile.am
index 71bdd8573..93b17d6db 100644
--- a/gruel/src/Makefile.am
+++ b/gruel/src/Makefile.am
@@ -19,5 +19,11 @@
 # Boston, MA 02110-1301, USA.
 # 
 
-SUBDIRS = lib include scheme
+SUBDIRS = lib include scheme 
+
+if PYTHON
+
+SUBDIRS += . swig python
+
+endif
 
diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h
index 514b24d8b..2948abb39 100644
--- a/gruel/src/include/gruel/pmt.h
+++ b/gruel/src/include/gruel/pmt.h
@@ -770,6 +770,11 @@ std::string pmt_write_string(pmt_t obj);
 
 std::ostream& operator<<(std::ostream &os, pmt_t obj);
 
+/*!
+ * \brief Write pmt string representation to stdout.
+ */
+void pmt_print(pmt_t v);
+
 
 /*
  * ------------------------------------------------------------------------
@@ -789,8 +794,17 @@ pmt_t pmt_deserialize(std::streambuf &source);
 
 void pmt_dump_sizeof();	// debugging
 
-} /* namespace pmt */
+/*!
+ * \brief Provide a simple string generating interface to pmt's serialize function
+ */
+std::string pmt_serialize_str(pmt_t obj);
 
+/*!
+ * \brief Provide a simple string generating interface to pmt's deserialize function
+ */
+pmt_t pmt_deserialize_str(std::string str);
+
+} /* namespace pmt */
 
 #include 
 
diff --git a/gruel/src/lib/pmt/pmt_io.cc b/gruel/src/lib/pmt/pmt_io.cc
index b909c1b64..1214ff588 100644
--- a/gruel/src/lib/pmt/pmt_io.cc
+++ b/gruel/src/lib/pmt/pmt_io.cc
@@ -26,6 +26,7 @@
 #include 
 #include "pmt_int.h"
 #include 
+#include 
 
 namespace pmt {
 
@@ -156,3 +157,12 @@ pmt_deserialize(std::istream &source)
 }
 
 } /* namespace pmt */
+
+
+void 
+pmt::pmt_print(pmt_t v)
+{
+  std::cout << pmt_write_string(v) << std::endl;
+}
+
+
diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc
index 937423a93..184a31e6b 100644
--- a/gruel/src/lib/pmt/pmt_serialize.cc
+++ b/gruel/src/lib/pmt/pmt_serialize.cc
@@ -59,6 +59,26 @@ serialize_untagged_u32(unsigned int i, std::streambuf &sb)
   return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof();
 }
 
+static bool
+serialize_untagged_f64(double i, std::streambuf &sb)
+{
+ typedef union {
+	double id;
+	uint64_t ii;
+	} iu_t;
+  iu_t iu;
+  iu.id = i;
+  sb.sputc((iu.ii >> 56) & 0xff);
+  sb.sputc((iu.ii >> 48) & 0xff);
+  sb.sputc((iu.ii >> 40) & 0xff);
+  sb.sputc((iu.ii >> 32) & 0xff);
+  sb.sputc((iu.ii >> 24) & 0xff);
+  sb.sputc((iu.ii >> 16) & 0xff);
+  sb.sputc((iu.ii >>  8) & 0xff);
+  return sb.sputc((iu.ii >>  0) & 0xff) != std::streambuf::traits_type::eof();
+}
+
+
 #if 0
 // always writes big-endian
 static bool
@@ -163,6 +183,41 @@ deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb)
 }
 #endif
 
+static bool
+deserialize_untagged_f64(double *ip, std::streambuf &sb)
+{
+  std::streambuf::traits_type::int_type t;
+
+  typedef union {
+    double id;
+    uint64_t ii;
+  } iu_t;
+
+  iu_t iu;
+
+  t = sb.sbumpc();
+  iu.ii = t & 0xff;
+
+  t = sb.sbumpc();
+  iu.ii = (iu.ii<<8) | (t & 0xff);
+  t = sb.sbumpc();
+  iu.ii = (iu.ii<<8) | (t & 0xff);
+  t = sb.sbumpc();
+  iu.ii = (iu.ii<<8) | (t & 0xff);
+  t = sb.sbumpc();
+  iu.ii = (iu.ii<<8) | (t & 0xff);
+  t = sb.sbumpc();
+  iu.ii = (iu.ii<<8) | (t & 0xff);
+  t = sb.sbumpc();
+  iu.ii = (iu.ii<<8) | (t & 0xff);
+  t = sb.sbumpc();
+  iu.ii = (iu.ii<<8) | (t & 0xff);
+
+  *ip = iu.id;
+  return t != std::streambuf::traits_type::eof();
+}
+ 
+
 /*
  * Write portable byte-serial representation of \p obj to \p sb
  *
@@ -172,7 +227,7 @@ bool
 pmt_serialize(pmt_t obj, std::streambuf &sb)
 {
   bool ok = true;
-
+  
  tail_recursion:
 
   if (pmt_is_bool(obj)){
@@ -217,11 +272,21 @@ pmt_serialize(pmt_t obj, std::streambuf &sb)
       return ok;
     }
 
-    if (pmt_is_real(obj))
-      throw pmt_notimplemented("pmt_serialize (real)", obj);
+    if (pmt_is_real(obj)){
+      float i = pmt_to_double(obj);
+      ok = serialize_untagged_u8(PST_DOUBLE, sb);
+      ok &= serialize_untagged_f64(i, sb);
+      return ok;
+    }
+
+    if (pmt_is_complex(obj)){
+      std::complex i = pmt_to_complex(obj);
+      ok = serialize_untagged_u8(PST_COMPLEX, sb);
+      ok &= serialize_untagged_f64(i.real(), sb);
+      ok &= serialize_untagged_f64(i.imag(), sb);
+      return ok;
+    }
 
-    if (pmt_is_complex(obj))
-      throw pmt_notimplemented("pmt_serialize (complex)", obj);
   }
 
   if (pmt_is_vector(obj))
@@ -251,6 +316,7 @@ pmt_deserialize(std::streambuf &sb)
   uint16_t	u16;
   uint32_t	u32;
   //uint32_t	u64;
+  double	f64;
   static char   tmpbuf[1024];
 
   if (!deserialize_untagged_u8(&tag, sb))
@@ -285,7 +351,18 @@ pmt_deserialize(std::streambuf &sb)
     return parse_pair(sb);
 
   case PST_DOUBLE:
+    if(!deserialize_untagged_f64(&f64, sb))
+      goto error;
+    return pmt_from_double( f64 );
+
   case PST_COMPLEX:
+    {
+    double r,i;
+    if(!deserialize_untagged_f64(&r, sb) && !deserialize_untagged_f64(&i, sb))
+      goto error;
+    return pmt_make_rectangular( r,i );
+    }
+
   case PST_VECTOR:
   case PST_DICT:
   case PST_UNIFORM_VECTOR:
@@ -302,6 +379,26 @@ pmt_deserialize(std::streambuf &sb)
   throw pmt_exception("pmt_deserialize: malformed input stream", PMT_F);
 }
 
+
+/*
+ * provide a simple string accessor to the serialized pmt form
+ */
+std::string pmt_serialize_str(pmt_t obj){
+  std::stringbuf sb;
+  pmt_serialize(obj, sb);
+  return sb.str();
+}
+
+
+/*
+ * provide a simple string accessor to the deserialized pmt form
+ */
+pmt_t pmt_deserialize_str(std::string s){
+  std::stringbuf sb(s);
+  return pmt_deserialize(sb);
+}
+
+
 /*
  * This is a mostly non-recursive implementation that allows us to
  * deserialize very long lists w/o exhausting the evaluation stack.
diff --git a/gruel/src/python/Makefile.am b/gruel/src/python/Makefile.am
new file mode 100644
index 000000000..0eeaa9ad7
--- /dev/null
+++ b/gruel/src/python/Makefile.am
@@ -0,0 +1,39 @@
+#
+# Copyright 2004,2005,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 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
+
+TESTS =
+EXTRA_DIST += run_tests.in
+
+if PYTHON
+TESTS += run_tests
+
+grueldir = $(pythondir)/gruel
+
+noinst_PYTHON = \
+    qa_pmt.py
+
+gruel_PYTHON = \
+    __init__.py 
+
+endif
+
diff --git a/gruel/src/python/__init__.py b/gruel/src/python/__init__.py
new file mode 100644
index 000000000..a4917cf64
--- /dev/null
+++ b/gruel/src/python/__init__.py
@@ -0,0 +1 @@
+# make this a package
diff --git a/gruel/src/python/qa_pmt.py b/gruel/src/python/qa_pmt.py
new file mode 100755
index 000000000..fa6e680ec
--- /dev/null
+++ b/gruel/src/python/qa_pmt.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+import sys;
+sys.path.append("../swig/");
+sys.path.append("../swig/.libs/");
+from gruel import pmt;
+
+a = pmt.pmt_intern("a");
+b = pmt.pmt_from_double(123765);
+d1 = pmt.pmt_make_dict();
+d2 = pmt.pmt_dict_add(d1, a, b);
+pmt.pmt_print(d2);
+print pmt.pmt_serialize_str(d2);
+
diff --git a/gruel/src/python/run_tests.in b/gruel/src/python/run_tests.in
new file mode 100644
index 000000000..5f7bdc067
--- /dev/null
+++ b/gruel/src/python/run_tests.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# 1st parameter is absolute path to component source directory
+# 2nd parameter is absolute path to component build directory
+# 3rd parameter is path to Python QA directory
+
+# For OS/X
+DYLD_LIBRARY_PATH=@abs_top_builddir@/gruel/src/lib/:@abs_top_builddir@/gruel/src/swig/.libs:$DYLD_LIBRARY_PATH
+export DYLD_LIBRARY_PATH
+
+# For Win32
+PATH=@abs_top_builddir@/gruel/:@abs_top_builddir@/gruel/.libs:$PATH
+
+@top_builddir@/run_tests.sh \
+    @abs_top_srcdir@/gruel \
+    @abs_top_builddir@/gruel \
+    @srcdir@
diff --git a/gruel/src/swig/Makefile.am b/gruel/src/swig/Makefile.am
new file mode 100644
index 000000000..c6e9246e5
--- /dev/null
+++ b/gruel/src/swig/Makefile.am
@@ -0,0 +1,71 @@
+#
+# Copyright 2001,2003,2004,2005,2006,2007,2008,2009,2010 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
+include $(top_srcdir)/Makefile.swig
+
+AM_CPPFLAGS = -I$(srcdir) $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS) \
+	 $(WITH_INCLUDES)
+
+TOP_SWIG_IFILES =		\
+	pmt.i
+
+
+# SWIG headers get installed in ${prefix}/include/gnuradio/swig
+swiginclude_HEADERS =			\
+	pmt.i			
+
+# SWIG headers that get installed in ${prefix}/include/gnuradio/swig/...
+nobase_swiginclude_HEADERS = 
+
+
+# special install for this top-level Python script which includes all
+# of the split Python libraries.
+ourpythondir = $(pythondir)/gruel
+ourpython_PYTHON =  \
+    pmt.py      \
+    __init__.py
+
+# ----------------------------------------------------------------
+# FIXME As of swig 1.3.31, this still seems to be required...
+# gnuradio_swig_bug_workaround.h : gnuradio_core_runtime.py $(srcdir)/gen-swig-bug-fix
+#	$(PYTHON) $(srcdir)/gen-swig-bug-fix python/gnuradio_core_runtime.cc $@
+
+EXTRA_DIST += gen-swig-bug-fix
+
+# C/C++ headers get installed in ${prefix}/include/gnuradio
+#grinclude_HEADERS = gnuradio_swig_bug_workaround.h
+grinclude_HEADERS = 
+
+
+# Install so that they end up available as:
+#   import gnuradio.gr
+# This ends up at:
+#   ${prefix}/lib/python${python_version}/site-packages/gnuradio/gr
+pmt_pythondir_category = gruel
+
+# additional libraries for linking with each SWIG-generated library
+pmt_la_swig_libadd = $(GRUEL_LA)
+
+SWIG_GUILE_FLAGS += -DIN_GNURADIO_CORE
+
+
+
diff --git a/gruel/src/swig/Makefile.swig.gen b/gruel/src/swig/Makefile.swig.gen
new file mode 100644
index 000000000..9b4f62f77
--- /dev/null
+++ b/gruel/src/swig/Makefile.swig.gen
@@ -0,0 +1,115 @@
+# -*- Makefile -*-
+#
+# 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 GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+# Makefile.swig.gen for gnuradio_core_runtime.i
+
+## Default install locations for these files:
+##
+## Default location for the Python directory is:
+##  ${prefix}/lib/python${python_version}/site-packages/[category]/gnuradio_core_runtime
+## Default location for the Python exec directory is:
+##  ${exec_prefix}/lib/python${python_version}/site-packages/[category]/gnuradio_core_runtime
+##
+## The following can be overloaded to change the install location, but
+## this has to be done in the including Makefile.am -before-
+## Makefile.swig is included.
+
+pmt_pythondir_category ?= gruel/pmt
+pmt_pylibdir_category ?= $(pmt_pythondir_category)
+pmt_pythondir = $(pythondir)/$(pmt_pythondir_category)
+pmt_pylibdir = $(pyexecdir)/$(pmt_pylibdir_category)
+
+# The .so libraries for the guile modules get installed whereever guile
+# is installed, usually /usr/lib/guile/gnuradio/
+# FIXME: determince whether these should be installed with gnuradio.
+pmt_scmlibdir = $(libdir)
+
+# The scm files for the guile modules get installed where ever guile
+# is installed, usually /usr/share/guile/site/gnuradio_core_runtime
+# FIXME: determince whether these should be installed with gnuradio.
+pmt_scmdir = $(guiledir)
+
+## SWIG headers are always installed into the same directory.
+
+pmt_swigincludedir = $(swigincludedir)
+
+## This is a template file for a "generated" Makefile addition (in
+## this case, "Makefile.swig.gen").  By including the top-level
+## Makefile.swig, this file will be used to generate the SWIG
+## dependencies.  Assign the variable TOP_SWIG_FILES to be the list of
+## SWIG .i files to generated wrappings for; there can be more than 1
+## so long as the names are unique (no sorting is done on the
+## TOP_SWIG_FILES list). This file explicitly assumes that a SWIG .i
+## file will generate .cc, .py, and possibly .h files -- meaning that
+## all of these files will have the same base name (that provided for
+## the SWIG .i file).
+##
+## This code is setup to ensure parallel MAKE ("-j" or "-jN") does the
+## right thing.  For more info, see <
+## http://sources.redhat.com/automake/automake.html#Multiple-Outputs >
+
+## Other cleaned files: dependency files generated by SWIG or this Makefile
+
+MOSTLYCLEANFILES += $(DEPDIR)/*.S*
+
+## Various SWIG variables.  These can be overloaded in the including
+## Makefile.am by setting the variable value there, then including
+## Makefile.swig .
+
+pmt_swiginclude_HEADERS =		\
+	pmt.i			\
+	$(pmt_swiginclude_headers)
+
+if PYTHON
+pmt_pylib_LTLIBRARIES =		\
+	_pmt.la
+
+_pmt_la_SOURCES = 			\
+	python/pmt.cc		\
+	$(pmt_la_swig_sources)
+
+pmt_python_PYTHON =			\
+	pmt.py			\
+	$(pmt_python)
+
+_pmt_la_LIBADD =			\
+	$(STD_SWIG_LA_LIB_ADD)		\
+	$(pmt_la_swig_libadd)
+
+_pmt_la_LDFLAGS =			\
+	$(STD_SWIG_LA_LD_FLAGS)		\
+	$(pmt_la_swig_ldflags)
+
+_pmt_la_CXXFLAGS =			\
+	$(STD_SWIG_CXX_FLAGS)		\
+	-I$(top_builddir) 		\
+	$(pmt_la_swig_cxxflags)
+
+python/pmt.cc: pmt.py
+pmt.py: pmt.i
+
+# Include the python dependencies for this file
+-include python/pmt.d
+
+endif		# end of if python
+
+
diff --git a/gruel/src/swig/__init__.py b/gruel/src/swig/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/gruel/src/swig/pmt.i b/gruel/src/swig/pmt.i
new file mode 100644
index 000000000..e5f9ba0a2
--- /dev/null
+++ b/gruel/src/swig/pmt.i
@@ -0,0 +1,759 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2009,2010 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.
+ */
+
+%module pmt
+%include "std_string.i"
+%include "stdint.i"
+%{
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+using namespace pmt;
+%}
+
+
+
+/*
+ * ------------------------------------------------------------------------
+ * Booleans.  Two constants, #t and #f.
+ *
+ * In predicates, anything that is not #f is considered true.
+ * I.e., there is a single false value, #f.
+ * ------------------------------------------------------------------------
+ */
+extern const pmt_t PMT_T;
+extern const pmt_t PMT_F;
+
+//! Return true if obj is \#t or \#f, else return false.
+bool pmt_is_bool(pmt_t obj);
+
+//! Return false if obj is \#f, else return true.
+bool pmt_is_true(pmt_t obj);
+
+//! Return true if obj is \#f, else return true.
+bool pmt_is_false(pmt_t obj);
+
+//! Return \#f is val is false, else return \#t.
+pmt_t pmt_from_bool(bool val);
+
+//! Return true if val is PMT_T, return false when val is PMT_F, 
+// else raise wrong_type exception.
+bool pmt_to_bool(pmt_t val);
+
+/*
+ * ------------------------------------------------------------------------
+ *			       Symbols
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if obj is a symbol, else false.
+bool pmt_is_symbol(const pmt_t& obj);
+
+//! Return the symbol whose name is \p s.
+pmt_t pmt_string_to_symbol(const std::string &s);
+
+//! Alias for pmt_string_to_symbol
+pmt_t pmt_intern(const std::string &s);
+
+
+/*!
+ * If \p is a symbol, return the name of the symbol as a string.
+ * Otherwise, raise the wrong_type exception.
+ */
+const std::string pmt_symbol_to_string(const pmt_t& sym);
+
+/*
+ * ------------------------------------------------------------------------
+ *           Numbers: we support integer, real and complex
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if obj is any kind of number, else false.
+bool pmt_is_number(pmt_t obj);
+
+/*
+ * ------------------------------------------------------------------------
+ *			       Integers
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if \p x is an integer number, else false
+bool pmt_is_integer(pmt_t x);
+
+//! Return the pmt value that represents the integer \p x.
+pmt_t pmt_from_long(long x);
+
+/*!
+ * \brief Convert pmt to long if possible.
+ *
+ * When \p x represents an exact integer that fits in a long,
+ * return that integer.  Else raise an exception, either wrong_type
+ * when x is not an exact integer, or out_of_range when it doesn't fit.
+ */
+long pmt_to_long(pmt_t x);
+
+/*
+ * ------------------------------------------------------------------------
+ *			       uint64_t
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if \p x is an uint64 number, else false
+bool pmt_is_uint64(pmt_t x);
+
+//! Return the pmt value that represents the uint64 \p x.
+pmt_t pmt_from_uint64(uint64_t x);
+
+/*!
+ * \brief Convert pmt to uint64 if possible.
+ *
+ * When \p x represents an exact integer that fits in a uint64,
+ * return that uint64.  Else raise an exception, either wrong_type
+ * when x is not an exact uint64, or out_of_range when it doesn't fit.
+ */
+uint64_t pmt_to_uint64(pmt_t x);
+
+/*
+ * ------------------------------------------------------------------------
+ *				Reals
+ * ------------------------------------------------------------------------
+ */
+
+/*
+ * \brief Return true if \p obj is a real number, else false.
+ */
+bool pmt_is_real(pmt_t obj);
+
+//! Return the pmt value that represents double \p x.
+pmt_t pmt_from_double(double x);
+
+/*!
+ * \brief Convert pmt to double if possible.
+ *
+ * Returns the number closest to \p val that is representable
+ * as a double.  The argument \p val must be a real or integer, otherwise
+ * a wrong_type exception is raised.
+ */
+double pmt_to_double(pmt_t x);
+
+/*
+ * ------------------------------------------------------------------------
+ *			       Complex
+ * ------------------------------------------------------------------------
+ */
+
+/*!
+ * \brief return true if \p obj is a complex number, false otherwise.
+ */
+bool pmt_is_complex(pmt_t obj);
+
+//! Return a complex number constructed of the given real and imaginary parts.
+pmt_t pmt_make_rectangular(double re, double im);
+
+/*!
+ * If \p z is complex, real or integer, return the closest complex.
+ * Otherwise, raise the wrong_type exception.
+ */
+std::complex pmt_to_complex(pmt_t z);
+
+/*
+ * ------------------------------------------------------------------------
+ *				Pairs
+ * ------------------------------------------------------------------------
+ */
+
+extern const pmt_t PMT_NIL;	//< the empty list
+
+//! Return true if \p x is the empty list, otherwise return false.
+bool pmt_is_null(const pmt_t& x);
+
+//! Return true if \p obj is a pair, else false.
+bool pmt_is_pair(const pmt_t& obj);
+
+//! Return a newly allocated pair whose car is \p x and whose cdr is \p y.
+pmt_t pmt_cons(const pmt_t& x, const pmt_t& y);
+
+//! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type.
+pmt_t pmt_car(const pmt_t& pair);
+
+//! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type.
+pmt_t pmt_cdr(const pmt_t& pair);
+
+//! Stores \p value in the car field of \p pair.
+void pmt_set_car(pmt_t pair, pmt_t value);
+
+//! Stores \p value in the cdr field of \p pair.
+void pmt_set_cdr(pmt_t pair, pmt_t value);
+
+pmt_t pmt_caar(pmt_t pair);
+pmt_t pmt_cadr(pmt_t pair);
+pmt_t pmt_cdar(pmt_t pair);
+pmt_t pmt_cddr(pmt_t pair);
+pmt_t pmt_caddr(pmt_t pair);
+pmt_t pmt_cadddr(pmt_t pair);
+
+/*
+ * ------------------------------------------------------------------------
+ *			          Tuples
+ *
+ * Store a fixed number of objects.  Tuples are not modifiable, and thus
+ * are excellent for use as messages.  Indexing is zero based.
+ * Access time to an element is O(1).
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if \p x is a tuple, othewise false.
+bool pmt_is_tuple(pmt_t x);
+
+pmt_t pmt_make_tuple();
+pmt_t pmt_make_tuple(const pmt_t &e0);
+pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1);
+pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2);
+pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3);
+pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4);
+pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5);
+pmt_t pmt_make_tuple(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);
+pmt_t pmt_make_tuple(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);
+pmt_t pmt_make_tuple(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);
+pmt_t pmt_make_tuple(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);
+
+/*!
+ * If \p x is a vector or proper list, return a tuple containing the elements of x
+ */
+pmt_t pmt_to_tuple(const pmt_t &x);
+
+/*!
+ * Return the contents of position \p k of \p tuple.
+ * \p k must be a valid index of \p tuple.
+ */
+pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k);
+
+/*
+ * ------------------------------------------------------------------------
+ *			       Vectors
+ *
+ * These vectors can hold any kind of objects.  Indexing is zero based.
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if \p x is a vector, othewise false.
+bool pmt_is_vector(pmt_t x);
+
+//! Make a vector of length \p k, with initial values set to \p fill
+pmt_t pmt_make_vector(size_t k, pmt_t fill);
+
+/*!
+ * Return the contents of position \p k of \p vector.
+ * \p k must be a valid index of \p vector.
+ */
+pmt_t pmt_vector_ref(pmt_t vector, size_t k);
+
+//! Store \p obj in position \p k.
+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);
+
+/*!
+ * 
+ * ------------------------------------------------------------------------
+ *		       Uniform Numeric Vectors
+ *
+ * A uniform numeric vector is a vector whose elements are all of single
+ * numeric type.  pmt offers uniform numeric vectors for signed and
+ * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
+ * floating point values, and complex floating-point numbers of these
+ * two sizes.  Indexing is zero based.
+ *
+ * The names of the functions include these tags in their names:
+ *
+ *    u8  unsigned 8-bit integers
+ *    s8  signed 8-bit integers
+ *   u16  unsigned 16-bit integers
+ *   s16  signed 16-bit integers
+ *   u32  unsigned 32-bit integers
+ *   s32  signed 32-bit integers
+ *   u64  unsigned 64-bit integers
+ *   s64  signed 64-bit integers
+ *   f32  the C++ type float
+ *   f64  the C++ type double
+ *   c32  the C++ type complex
+ *   c64  the C++ type complex
+ * ------------------------------------------------------------------------
+ * 
+ */ + +//! true if \p x is any kind of uniform numeric vector +bool pmt_is_uniform_vector(pmt_t x); + +bool pmt_is_u8vector(pmt_t x); +bool pmt_is_s8vector(pmt_t x); +bool pmt_is_u16vector(pmt_t x); +bool pmt_is_s16vector(pmt_t x); +bool pmt_is_u32vector(pmt_t x); +bool pmt_is_s32vector(pmt_t x); +bool pmt_is_u64vector(pmt_t x); +bool pmt_is_s64vector(pmt_t x); +bool pmt_is_f32vector(pmt_t x); +bool pmt_is_f64vector(pmt_t x); +bool pmt_is_c32vector(pmt_t x); +bool pmt_is_c64vector(pmt_t x); + +pmt_t pmt_make_u8vector(size_t k, uint8_t fill); +pmt_t pmt_make_s8vector(size_t k, int8_t fill); +pmt_t pmt_make_u16vector(size_t k, uint16_t fill); +pmt_t pmt_make_s16vector(size_t k, int16_t fill); +pmt_t pmt_make_u32vector(size_t k, uint32_t fill); +pmt_t pmt_make_s32vector(size_t k, int32_t fill); +pmt_t pmt_make_u64vector(size_t k, uint64_t fill); +pmt_t pmt_make_s64vector(size_t k, int64_t fill); +pmt_t pmt_make_f32vector(size_t k, float fill); +pmt_t pmt_make_f64vector(size_t k, double fill); +pmt_t pmt_make_c32vector(size_t k, std::complex fill); +pmt_t pmt_make_c64vector(size_t k, std::complex fill); + +pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); +pmt_t pmt_init_s8vector(size_t k, const int8_t *data); +pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); +pmt_t pmt_init_s16vector(size_t k, const int16_t *data); +pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); +pmt_t pmt_init_s32vector(size_t k, const int32_t *data); +pmt_t pmt_init_f32vector(size_t k, const float *data); +pmt_t pmt_init_f64vector(size_t k, const double *data); +pmt_t pmt_init_c32vector(size_t k, const std::complex *data); +pmt_t pmt_init_c64vector(size_t k, const std::complex *data); + +uint8_t pmt_u8vector_ref(pmt_t v, size_t k); +int8_t pmt_s8vector_ref(pmt_t v, size_t k); +uint16_t pmt_u16vector_ref(pmt_t v, size_t k); +int16_t pmt_s16vector_ref(pmt_t v, size_t k); +uint32_t pmt_u32vector_ref(pmt_t v, size_t k); +int32_t pmt_s32vector_ref(pmt_t v, size_t k); +uint64_t pmt_u64vector_ref(pmt_t v, size_t k); +int64_t pmt_s64vector_ref(pmt_t v, size_t k); +float pmt_f32vector_ref(pmt_t v, size_t k); +double pmt_f64vector_ref(pmt_t v, size_t k); +std::complex pmt_c32vector_ref(pmt_t v, size_t k); +std::complex pmt_c64vector_ref(pmt_t v, size_t k); + +void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x); //< v[k] = x +void pmt_s8vector_set(pmt_t v, size_t k, int8_t x); +void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x); +void pmt_s16vector_set(pmt_t v, size_t k, int16_t x); +void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x); +void pmt_s32vector_set(pmt_t v, size_t k, int32_t x); +void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x); +void pmt_s64vector_set(pmt_t v, size_t k, int64_t x); +void pmt_f32vector_set(pmt_t v, size_t k, float x); +void pmt_f64vector_set(pmt_t v, size_t k, double x); +void pmt_c32vector_set(pmt_t v, size_t k, std::complex x); +void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); + +// Return const pointers to the elements + +const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements +const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements +const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements +const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements +const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements +const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements +const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements + +// Return non-const pointers to the elements + +void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements + +/* + * ------------------------------------------------------------------------ + * Dictionary (a.k.a associative array, hash, map) + * + * This is a functional data structure that is persistent. Updating a + * functional data structure does not destroy the existing version, but + * rather creates a new version that coexists with the old. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is a dictionary +bool pmt_is_dict(const pmt_t &obj); + +//! Make an empty dictionary +pmt_t pmt_make_dict(); + +//! Return a new dictionary with \p key associated with \p value. +pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value); + +//! Return a new dictionary with \p key removed. +pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key); + +//! Return true if \p key exists in \p dict +bool pmt_dict_has_key(const pmt_t &dict, const pmt_t &key); + +//! If \p key exists in \p dict, return associated value; otherwise return \p not_found. +pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found); + +//! Return list of (key . value) pairs +pmt_t pmt_dict_items(pmt_t dict); + +//! Return list of keys +pmt_t pmt_dict_keys(pmt_t dict); + +//! Return list of values +pmt_t pmt_dict_values(pmt_t dict); + +/* + * ------------------------------------------------------------------------ + * Any (wraps boost::any -- can be used to wrap pretty much anything) + * + * Cannot be serialized or used across process boundaries. + * See http://www.boost.org/doc/html/any.html + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is an any +bool pmt_is_any(pmt_t obj); + +//! make an any +pmt_t pmt_make_any(const boost::any &any); + +//! Return underlying boost::any +boost::any pmt_any_ref(pmt_t obj); + +//! Store \p any in \p 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 + * ------------------------------------------------------------------------ + */ + +//! Return true if x and y are the same object; otherwise return false. +bool pmt_eq(const pmt_t& x, const pmt_t& y); + +/*! + * \brief Return true if x and y should normally be regarded as the same object, else false. + * + *
+ * eqv returns true if:
+ *   x and y are the same object.
+ *   x and y are both \#t or both \#f.
+ *   x and y are both symbols and their names are the same.
+ *   x and y are both numbers, and are numerically equal.
+ *   x and y are both the empty list (nil).
+ *   x and y are pairs or vectors that denote same location in store.
+ * 
+ */ +bool pmt_eqv(const pmt_t& x, const pmt_t& y); + +/*! + * pmt_equal recursively compares the contents of pairs and vectors, + * applying pmt_eqv on other objects such as numbers and symbols. + * pmt_equal may fail to terminate if its arguments are circular data + * structures. + */ +bool pmt_equal(const pmt_t& x, const pmt_t& y); + + +//! Return the number of elements in v +size_t pmt_length(const pmt_t& v); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assq(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assv(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assoc(pmt_t obj, pmt_t alist); + +/*! + * \brief Apply \p proc element-wise to the elements of list and returns + * a list of the results, in order. + * + * \p list must be a list. The dynamic order in which \p proc is + * applied to the elements of \p list is unspecified. + */ +pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); + +/*! + * \brief reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse(pmt_t list); + +/*! + * \brief destructively reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse_x(pmt_t list); + +/*! + * \brief (acons x y a) == (cons (cons x y) a) + */ +inline static pmt_t +pmt_acons(pmt_t x, pmt_t y, pmt_t a) +{ + return pmt_cons(pmt_cons(x, y), a); +} + +/*! + * \brief locates \p nth element of \n list where the car is the 'zeroth' element. + */ +pmt_t pmt_nth(size_t n, pmt_t list); + +/*! + * \brief returns the tail of \p list that would be obtained by calling + * cdr \p n times in succession. + */ +pmt_t pmt_nthcdr(size_t n, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memq(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memv(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_member use pmt_equal to compare \p obj with the elements of \p list. + */ +pmt_t pmt_member(pmt_t obj, pmt_t list); + +/*! + * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. + * Comparisons are done with pmt_eqv. + */ +bool pmt_subsetp(pmt_t list1, pmt_t list2); + +/*! + * \brief Return a list of length 1 containing \p x1 + */ +pmt_t pmt_list1(const pmt_t& x1); + +/*! + * \brief Return a list of length 2 containing \p x1, \p x2 + */ +pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); + +/*! + * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 + */ +pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); + +/*! + * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 + */ +pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); + +/*! + * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 + */ +pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); + +/*! + * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p + * x5, \p x6 + */ +pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); + +/*! + * \brief Return \p list with \p item added to it. + */ +pmt_t pmt_list_add(pmt_t list, const pmt_t& item); + + +/* + * ------------------------------------------------------------------------ + * read / write + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_EOF; //< The end of file object + +//! return true if obj is the EOF object, otherwise return false. +bool pmt_is_eof_object(pmt_t obj); + +/*! + * read converts external representations of pmt objects into the + * objects themselves. Read returns the next object parsable from + * the given input port, updating port to point to the first + * character past the end of the external representation of the + * object. + * + * If an end of file is encountered in the input before any + * characters are found that can begin an object, then an end of file + * object is returned. The port remains open, and further attempts + * to read will also return an end of file object. If an end of file + * is encountered after the beginning of an object's external + * representation, but the external representation is incomplete and + * therefore not parsable, an error is signaled. + */ +pmt_t pmt_read(std::istream &port); + +/*! + * Write a written representation of \p obj to the given \p port. + */ +void pmt_write(pmt_t obj, std::ostream &port); + +/*! + * Return a string representation of \p obj. + * This is the same output as would be generated by pmt_write. + */ +std::string pmt_write_string(pmt_t obj); + + +/*! + * \brief Write pmt string representation to stdout. + */ +void pmt_print(pmt_t v); + + +/* + * ------------------------------------------------------------------------ + * portable byte stream representation + * ------------------------------------------------------------------------ + */ +/*! + * \brief Write portable byte-serial representation of \p obj to \p sink + */ +bool pmt_serialize(pmt_t obj, std::streambuf &sink); + +/*! + * \brief Create obj from portable byte-serial representation + */ +pmt_t pmt_deserialize(std::streambuf &source); + + +void pmt_dump_sizeof(); // debugging + +/*! + * \brief Provide a simple string generating interface to pmt's serialize function + */ +std::string pmt_serialize_str(pmt_t obj); + +/*! + * \brief Provide a simple string generating interface to pmt's deserialize function + */ +pmt_t pmt_deserialize_str(std::string str); + + + + -- cgit From ee849707c09335f4c682151044a0e65321f7939d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 14 Mar 2011 21:00:13 -0400 Subject: gruel: fixing structure. Passes make check. --- gruel/src/python/Makefile.am | 2 +- gruel/src/python/__init__.py | 26 +- gruel/src/python/qa_pmt.py | 48 ++- gruel/src/python/run_tests.in | 4 +- gruel/src/swig/Makefile.am | 60 ++-- gruel/src/swig/Makefile.swig.gen | 54 +-- gruel/src/swig/pmt.i | 759 --------------------------------------- gruel/src/swig/pmt_swig.i | 755 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 870 insertions(+), 838 deletions(-) delete mode 100644 gruel/src/swig/pmt.i create mode 100644 gruel/src/swig/pmt_swig.i (limited to 'gruel') diff --git a/gruel/src/python/Makefile.am b/gruel/src/python/Makefile.am index 0eeaa9ad7..5a45510d5 100644 --- a/gruel/src/python/Makefile.am +++ b/gruel/src/python/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2004,2005,2006,2008,2009 Free Software Foundation, Inc. +# Copyright 2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # diff --git a/gruel/src/python/__init__.py b/gruel/src/python/__init__.py index a4917cf64..421a9aaa8 100644 --- a/gruel/src/python/__init__.py +++ b/gruel/src/python/__init__.py @@ -1 +1,25 @@ -# make this a package +# +# Copyright 2011 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. +# + +# The presence of this file turns this directory into a Python package + +from pmt_swig import * + diff --git a/gruel/src/python/qa_pmt.py b/gruel/src/python/qa_pmt.py index fa6e680ec..00cdb064e 100755 --- a/gruel/src/python/qa_pmt.py +++ b/gruel/src/python/qa_pmt.py @@ -1,14 +1,42 @@ #!/usr/bin/env python +# +# Copyright 2011 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. +# -import sys; -sys.path.append("../swig/"); -sys.path.append("../swig/.libs/"); -from gruel import pmt; +import unittest +import pmt_swig -a = pmt.pmt_intern("a"); -b = pmt.pmt_from_double(123765); -d1 = pmt.pmt_make_dict(); -d2 = pmt.pmt_dict_add(d1, a, b); -pmt.pmt_print(d2); -print pmt.pmt_serialize_str(d2); +class test_gruel_pmt(unittest.TestCase): + def test01 (self): + a = pmt_swig.pmt_intern("a") + b = pmt_swig.pmt_from_double(123765) + d1 = pmt_swig.pmt_make_dict() + d2 = pmt_swig.pmt_dict_add(d1, a, b) + pmt_swig.pmt_print(d2) + + def test02 (self): + const = 123765 + x_pmt = pmt_swig.pmt_from_double(const) + x_int = pmt_swig.pmt_to_double(x_pmt) + self.assertEqual(x_int, const) + +if __name__ == '__main__': + unittest.main() diff --git a/gruel/src/python/run_tests.in b/gruel/src/python/run_tests.in index 5f7bdc067..ff399bcc6 100644 --- a/gruel/src/python/run_tests.in +++ b/gruel/src/python/run_tests.in @@ -12,6 +12,6 @@ export DYLD_LIBRARY_PATH PATH=@abs_top_builddir@/gruel/:@abs_top_builddir@/gruel/.libs:$PATH @top_builddir@/run_tests.sh \ - @abs_top_srcdir@/gruel \ - @abs_top_builddir@/gruel \ + @abs_top_srcdir@/gruel/src \ + @abs_top_builddir@/gruel/src \ @srcdir@ diff --git a/gruel/src/swig/Makefile.am b/gruel/src/swig/Makefile.am index c6e9246e5..294045567 100644 --- a/gruel/src/swig/Makefile.am +++ b/gruel/src/swig/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2001,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. +# Copyright 2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -22,50 +22,34 @@ include $(top_srcdir)/Makefile.common include $(top_srcdir)/Makefile.swig -AM_CPPFLAGS = -I$(srcdir) $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS) \ - $(WITH_INCLUDES) - -TOP_SWIG_IFILES = \ - pmt.i - - -# SWIG headers get installed in ${prefix}/include/gnuradio/swig -swiginclude_HEADERS = \ - pmt.i - -# SWIG headers that get installed in ${prefix}/include/gnuradio/swig/... -nobase_swiginclude_HEADERS = +TESTS = +AM_CPPFLAGS = \ + -I$(top_srcdir)/gruel/src/lib \ + $(STD_DEFINES_AND_INCLUDES) \ + $(PYTHON_CPPFLAGS) \ + $(WITH_INCLUDES) -# special install for this top-level Python script which includes all -# of the split Python libraries. -ourpythondir = $(pythondir)/gruel -ourpython_PYTHON = \ - pmt.py \ - __init__.py - -# ---------------------------------------------------------------- -# FIXME As of swig 1.3.31, this still seems to be required... -# gnuradio_swig_bug_workaround.h : gnuradio_core_runtime.py $(srcdir)/gen-swig-bug-fix -# $(PYTHON) $(srcdir)/gen-swig-bug-fix python/gnuradio_core_runtime.cc $@ - -EXTRA_DIST += gen-swig-bug-fix - -# C/C++ headers get installed in ${prefix}/include/gnuradio -#grinclude_HEADERS = gnuradio_swig_bug_workaround.h -grinclude_HEADERS = +TOP_SWIG_IFILES = \ + pmt_swig.i +############################## +# SWIG interface and library +TOP_SWIG_IFILES = \ + pmt_swig.i # Install so that they end up available as: -# import gnuradio.gr +# import gruel.pmt # This ends up at: -# ${prefix}/lib/python${python_version}/site-packages/gnuradio/gr -pmt_pythondir_category = gruel - -# additional libraries for linking with each SWIG-generated library -pmt_la_swig_libadd = $(GRUEL_LA) +# ${prefix}/lib/python${python_version}/site-packages/gruel/pmt +pmt_swig_pythondir_category = \ + gruel/pmt -SWIG_GUILE_FLAGS += -DIN_GNURADIO_CORE +# additional libraries for linking with the SWIG-generated library +pmt_swig_la_swig_libadd = \ + $(abs_top_builddir)/gruel/src/lib/pmt/libpmt.la +# additional SWIG files to be installed +pmt_swig_swiginclude_headers = diff --git a/gruel/src/swig/Makefile.swig.gen b/gruel/src/swig/Makefile.swig.gen index 9b4f62f77..c6a2fb956 100644 --- a/gruel/src/swig/Makefile.swig.gen +++ b/gruel/src/swig/Makefile.swig.gen @@ -33,24 +33,24 @@ ## this has to be done in the including Makefile.am -before- ## Makefile.swig is included. -pmt_pythondir_category ?= gruel/pmt -pmt_pylibdir_category ?= $(pmt_pythondir_category) -pmt_pythondir = $(pythondir)/$(pmt_pythondir_category) -pmt_pylibdir = $(pyexecdir)/$(pmt_pylibdir_category) +pmt_swig_pythondir_category ?= gruel/pmt_swig +pmt_swig_pylibdir_category ?= $(pmt_swig_pythondir_category) +pmt_swig_pythondir = $(pythondir)/$(pmt_swig_pythondir_category) +pmt_swig_pylibdir = $(pyexecdir)/$(pmt_swig_pylibdir_category) # The .so libraries for the guile modules get installed whereever guile # is installed, usually /usr/lib/guile/gnuradio/ # FIXME: determince whether these should be installed with gnuradio. -pmt_scmlibdir = $(libdir) +pmt_swig_scmlibdir = $(libdir) # The scm files for the guile modules get installed where ever guile # is installed, usually /usr/share/guile/site/gnuradio_core_runtime # FIXME: determince whether these should be installed with gnuradio. -pmt_scmdir = $(guiledir) +pmt_swig_scmdir = $(guiledir) ## SWIG headers are always installed into the same directory. -pmt_swigincludedir = $(swigincludedir) +pmt_swig_swigincludedir = $(swigincludedir) ## This is a template file for a "generated" Makefile addition (in ## this case, "Makefile.swig.gen"). By including the top-level @@ -75,40 +75,40 @@ MOSTLYCLEANFILES += $(DEPDIR)/*.S* ## Makefile.am by setting the variable value there, then including ## Makefile.swig . -pmt_swiginclude_HEADERS = \ - pmt.i \ - $(pmt_swiginclude_headers) +pmt_swig_swiginclude_HEADERS = \ + pmt_swig.i \ + $(pmt_swig_swiginclude_headers) if PYTHON -pmt_pylib_LTLIBRARIES = \ - _pmt.la +pmt_swig_pylib_LTLIBRARIES = \ + _pmt_swig.la -_pmt_la_SOURCES = \ - python/pmt.cc \ - $(pmt_la_swig_sources) +_pmt_swig_la_SOURCES = \ + python/pmt_swig.cc \ + $(pmt_swig_la_swig_sources) -pmt_python_PYTHON = \ - pmt.py \ - $(pmt_python) +pmt_swig_python_PYTHON = \ + pmt_swig.py \ + $(pmt_swig_python) -_pmt_la_LIBADD = \ +_pmt_swig_la_LIBADD = \ $(STD_SWIG_LA_LIB_ADD) \ - $(pmt_la_swig_libadd) + $(pmt_swig_la_swig_libadd) -_pmt_la_LDFLAGS = \ +_pmt_swig_la_LDFLAGS = \ $(STD_SWIG_LA_LD_FLAGS) \ - $(pmt_la_swig_ldflags) + $(pmt_swig_la_swig_ldflags) -_pmt_la_CXXFLAGS = \ +_pmt_swig_la_CXXFLAGS = \ $(STD_SWIG_CXX_FLAGS) \ -I$(top_builddir) \ - $(pmt_la_swig_cxxflags) + $(pmt_swig_la_swig_cxxflags) -python/pmt.cc: pmt.py -pmt.py: pmt.i +python/pmt_swig.cc: pmt_swig.py +pmt_swig.py: pmt_swig.i # Include the python dependencies for this file --include python/pmt.d +-include python/pmt_swig.d endif # end of if python diff --git a/gruel/src/swig/pmt.i b/gruel/src/swig/pmt.i deleted file mode 100644 index e5f9ba0a2..000000000 --- a/gruel/src/swig/pmt.i +++ /dev/null @@ -1,759 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2009,2010 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. - */ - -%module pmt -%include "std_string.i" -%include "stdint.i" -%{ -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace pmt; -%} - - - -/* - * ------------------------------------------------------------------------ - * Booleans. Two constants, #t and #f. - * - * In predicates, anything that is not #f is considered true. - * I.e., there is a single false value, #f. - * ------------------------------------------------------------------------ - */ -extern const pmt_t PMT_T; -extern const pmt_t PMT_F; - -//! Return true if obj is \#t or \#f, else return false. -bool pmt_is_bool(pmt_t obj); - -//! Return false if obj is \#f, else return true. -bool pmt_is_true(pmt_t obj); - -//! Return true if obj is \#f, else return true. -bool pmt_is_false(pmt_t obj); - -//! Return \#f is val is false, else return \#t. -pmt_t pmt_from_bool(bool val); - -//! Return true if val is PMT_T, return false when val is PMT_F, -// else raise wrong_type exception. -bool pmt_to_bool(pmt_t val); - -/* - * ------------------------------------------------------------------------ - * Symbols - * ------------------------------------------------------------------------ - */ - -//! Return true if obj is a symbol, else false. -bool pmt_is_symbol(const pmt_t& obj); - -//! Return the symbol whose name is \p s. -pmt_t pmt_string_to_symbol(const std::string &s); - -//! Alias for pmt_string_to_symbol -pmt_t pmt_intern(const std::string &s); - - -/*! - * If \p is a symbol, return the name of the symbol as a string. - * Otherwise, raise the wrong_type exception. - */ -const std::string pmt_symbol_to_string(const pmt_t& sym); - -/* - * ------------------------------------------------------------------------ - * Numbers: we support integer, real and complex - * ------------------------------------------------------------------------ - */ - -//! Return true if obj is any kind of number, else false. -bool pmt_is_number(pmt_t obj); - -/* - * ------------------------------------------------------------------------ - * Integers - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is an integer number, else false -bool pmt_is_integer(pmt_t x); - -//! Return the pmt value that represents the integer \p x. -pmt_t pmt_from_long(long x); - -/*! - * \brief Convert pmt to long if possible. - * - * When \p x represents an exact integer that fits in a long, - * return that integer. Else raise an exception, either wrong_type - * when x is not an exact integer, or out_of_range when it doesn't fit. - */ -long pmt_to_long(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * uint64_t - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is an uint64 number, else false -bool pmt_is_uint64(pmt_t x); - -//! Return the pmt value that represents the uint64 \p x. -pmt_t pmt_from_uint64(uint64_t x); - -/*! - * \brief Convert pmt to uint64 if possible. - * - * When \p x represents an exact integer that fits in a uint64, - * return that uint64. Else raise an exception, either wrong_type - * when x is not an exact uint64, or out_of_range when it doesn't fit. - */ -uint64_t pmt_to_uint64(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * Reals - * ------------------------------------------------------------------------ - */ - -/* - * \brief Return true if \p obj is a real number, else false. - */ -bool pmt_is_real(pmt_t obj); - -//! Return the pmt value that represents double \p x. -pmt_t pmt_from_double(double x); - -/*! - * \brief Convert pmt to double if possible. - * - * Returns the number closest to \p val that is representable - * as a double. The argument \p val must be a real or integer, otherwise - * a wrong_type exception is raised. - */ -double pmt_to_double(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * Complex - * ------------------------------------------------------------------------ - */ - -/*! - * \brief return true if \p obj is a complex number, false otherwise. - */ -bool pmt_is_complex(pmt_t obj); - -//! Return a complex number constructed of the given real and imaginary parts. -pmt_t pmt_make_rectangular(double re, double im); - -/*! - * If \p z is complex, real or integer, return the closest complex. - * Otherwise, raise the wrong_type exception. - */ -std::complex pmt_to_complex(pmt_t z); - -/* - * ------------------------------------------------------------------------ - * Pairs - * ------------------------------------------------------------------------ - */ - -extern const pmt_t PMT_NIL; //< the empty list - -//! Return true if \p x is the empty list, otherwise return false. -bool pmt_is_null(const pmt_t& x); - -//! Return true if \p obj is a pair, else false. -bool pmt_is_pair(const pmt_t& obj); - -//! Return a newly allocated pair whose car is \p x and whose cdr is \p y. -pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); - -//! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. -pmt_t pmt_car(const pmt_t& pair); - -//! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. -pmt_t pmt_cdr(const pmt_t& pair); - -//! Stores \p value in the car field of \p pair. -void pmt_set_car(pmt_t pair, pmt_t value); - -//! Stores \p value in the cdr field of \p pair. -void pmt_set_cdr(pmt_t pair, pmt_t value); - -pmt_t pmt_caar(pmt_t pair); -pmt_t pmt_cadr(pmt_t pair); -pmt_t pmt_cdar(pmt_t pair); -pmt_t pmt_cddr(pmt_t pair); -pmt_t pmt_caddr(pmt_t pair); -pmt_t pmt_cadddr(pmt_t pair); - -/* - * ------------------------------------------------------------------------ - * Tuples - * - * Store a fixed number of objects. Tuples are not modifiable, and thus - * are excellent for use as messages. Indexing is zero based. - * Access time to an element is O(1). - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is a tuple, othewise false. -bool pmt_is_tuple(pmt_t x); - -pmt_t pmt_make_tuple(); -pmt_t pmt_make_tuple(const pmt_t &e0); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); - -/*! - * If \p x is a vector or proper list, return a tuple containing the elements of x - */ -pmt_t pmt_to_tuple(const pmt_t &x); - -/*! - * Return the contents of position \p k of \p tuple. - * \p k must be a valid index of \p tuple. - */ -pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); - -/* - * ------------------------------------------------------------------------ - * Vectors - * - * These vectors can hold any kind of objects. Indexing is zero based. - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is a vector, othewise false. -bool pmt_is_vector(pmt_t x); - -//! Make a vector of length \p k, with initial values set to \p fill -pmt_t pmt_make_vector(size_t k, pmt_t fill); - -/*! - * Return the contents of position \p k of \p vector. - * \p k must be a valid index of \p vector. - */ -pmt_t pmt_vector_ref(pmt_t vector, size_t k); - -//! Store \p obj in position \p k. -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); - -/*! - *
- * ------------------------------------------------------------------------
- *		       Uniform Numeric Vectors
- *
- * A uniform numeric vector is a vector whose elements are all of single
- * numeric type.  pmt offers uniform numeric vectors for signed and
- * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
- * floating point values, and complex floating-point numbers of these
- * two sizes.  Indexing is zero based.
- *
- * The names of the functions include these tags in their names:
- *
- *    u8  unsigned 8-bit integers
- *    s8  signed 8-bit integers
- *   u16  unsigned 16-bit integers
- *   s16  signed 16-bit integers
- *   u32  unsigned 32-bit integers
- *   s32  signed 32-bit integers
- *   u64  unsigned 64-bit integers
- *   s64  signed 64-bit integers
- *   f32  the C++ type float
- *   f64  the C++ type double
- *   c32  the C++ type complex
- *   c64  the C++ type complex
- * ------------------------------------------------------------------------
- * 
- */ - -//! true if \p x is any kind of uniform numeric vector -bool pmt_is_uniform_vector(pmt_t x); - -bool pmt_is_u8vector(pmt_t x); -bool pmt_is_s8vector(pmt_t x); -bool pmt_is_u16vector(pmt_t x); -bool pmt_is_s16vector(pmt_t x); -bool pmt_is_u32vector(pmt_t x); -bool pmt_is_s32vector(pmt_t x); -bool pmt_is_u64vector(pmt_t x); -bool pmt_is_s64vector(pmt_t x); -bool pmt_is_f32vector(pmt_t x); -bool pmt_is_f64vector(pmt_t x); -bool pmt_is_c32vector(pmt_t x); -bool pmt_is_c64vector(pmt_t x); - -pmt_t pmt_make_u8vector(size_t k, uint8_t fill); -pmt_t pmt_make_s8vector(size_t k, int8_t fill); -pmt_t pmt_make_u16vector(size_t k, uint16_t fill); -pmt_t pmt_make_s16vector(size_t k, int16_t fill); -pmt_t pmt_make_u32vector(size_t k, uint32_t fill); -pmt_t pmt_make_s32vector(size_t k, int32_t fill); -pmt_t pmt_make_u64vector(size_t k, uint64_t fill); -pmt_t pmt_make_s64vector(size_t k, int64_t fill); -pmt_t pmt_make_f32vector(size_t k, float fill); -pmt_t pmt_make_f64vector(size_t k, double fill); -pmt_t pmt_make_c32vector(size_t k, std::complex fill); -pmt_t pmt_make_c64vector(size_t k, std::complex fill); - -pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); -pmt_t pmt_init_s8vector(size_t k, const int8_t *data); -pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); -pmt_t pmt_init_s16vector(size_t k, const int16_t *data); -pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); -pmt_t pmt_init_s32vector(size_t k, const int32_t *data); -pmt_t pmt_init_f32vector(size_t k, const float *data); -pmt_t pmt_init_f64vector(size_t k, const double *data); -pmt_t pmt_init_c32vector(size_t k, const std::complex *data); -pmt_t pmt_init_c64vector(size_t k, const std::complex *data); - -uint8_t pmt_u8vector_ref(pmt_t v, size_t k); -int8_t pmt_s8vector_ref(pmt_t v, size_t k); -uint16_t pmt_u16vector_ref(pmt_t v, size_t k); -int16_t pmt_s16vector_ref(pmt_t v, size_t k); -uint32_t pmt_u32vector_ref(pmt_t v, size_t k); -int32_t pmt_s32vector_ref(pmt_t v, size_t k); -uint64_t pmt_u64vector_ref(pmt_t v, size_t k); -int64_t pmt_s64vector_ref(pmt_t v, size_t k); -float pmt_f32vector_ref(pmt_t v, size_t k); -double pmt_f64vector_ref(pmt_t v, size_t k); -std::complex pmt_c32vector_ref(pmt_t v, size_t k); -std::complex pmt_c64vector_ref(pmt_t v, size_t k); - -void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x); //< v[k] = x -void pmt_s8vector_set(pmt_t v, size_t k, int8_t x); -void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x); -void pmt_s16vector_set(pmt_t v, size_t k, int16_t x); -void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x); -void pmt_s32vector_set(pmt_t v, size_t k, int32_t x); -void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x); -void pmt_s64vector_set(pmt_t v, size_t k, int64_t x); -void pmt_f32vector_set(pmt_t v, size_t k, float x); -void pmt_f64vector_set(pmt_t v, size_t k, double x); -void pmt_c32vector_set(pmt_t v, size_t k, std::complex x); -void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); - -// Return const pointers to the elements - -const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements -const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements -const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements -const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements -const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements -const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements -const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements - -// Return non-const pointers to the elements - -void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements - -/* - * ------------------------------------------------------------------------ - * Dictionary (a.k.a associative array, hash, map) - * - * This is a functional data structure that is persistent. Updating a - * functional data structure does not destroy the existing version, but - * rather creates a new version that coexists with the old. - * ------------------------------------------------------------------------ - */ - -//! Return true if \p obj is a dictionary -bool pmt_is_dict(const pmt_t &obj); - -//! Make an empty dictionary -pmt_t pmt_make_dict(); - -//! Return a new dictionary with \p key associated with \p value. -pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value); - -//! Return a new dictionary with \p key removed. -pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key); - -//! Return true if \p key exists in \p dict -bool pmt_dict_has_key(const pmt_t &dict, const pmt_t &key); - -//! If \p key exists in \p dict, return associated value; otherwise return \p not_found. -pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found); - -//! Return list of (key . value) pairs -pmt_t pmt_dict_items(pmt_t dict); - -//! Return list of keys -pmt_t pmt_dict_keys(pmt_t dict); - -//! Return list of values -pmt_t pmt_dict_values(pmt_t dict); - -/* - * ------------------------------------------------------------------------ - * Any (wraps boost::any -- can be used to wrap pretty much anything) - * - * Cannot be serialized or used across process boundaries. - * See http://www.boost.org/doc/html/any.html - * ------------------------------------------------------------------------ - */ - -//! Return true if \p obj is an any -bool pmt_is_any(pmt_t obj); - -//! make an any -pmt_t pmt_make_any(const boost::any &any); - -//! Return underlying boost::any -boost::any pmt_any_ref(pmt_t obj); - -//! Store \p any in \p 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 - * ------------------------------------------------------------------------ - */ - -//! Return true if x and y are the same object; otherwise return false. -bool pmt_eq(const pmt_t& x, const pmt_t& y); - -/*! - * \brief Return true if x and y should normally be regarded as the same object, else false. - * - *
- * eqv returns true if:
- *   x and y are the same object.
- *   x and y are both \#t or both \#f.
- *   x and y are both symbols and their names are the same.
- *   x and y are both numbers, and are numerically equal.
- *   x and y are both the empty list (nil).
- *   x and y are pairs or vectors that denote same location in store.
- * 
- */ -bool pmt_eqv(const pmt_t& x, const pmt_t& y); - -/*! - * pmt_equal recursively compares the contents of pairs and vectors, - * applying pmt_eqv on other objects such as numbers and symbols. - * pmt_equal may fail to terminate if its arguments are circular data - * structures. - */ -bool pmt_equal(const pmt_t& x, const pmt_t& y); - - -//! Return the number of elements in v -size_t pmt_length(const pmt_t& v); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assq(pmt_t obj, pmt_t alist); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assv(pmt_t obj, pmt_t alist); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assoc(pmt_t obj, pmt_t alist); - -/*! - * \brief Apply \p proc element-wise to the elements of list and returns - * a list of the results, in order. - * - * \p list must be a list. The dynamic order in which \p proc is - * applied to the elements of \p list is unspecified. - */ -pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); - -/*! - * \brief reverse \p list. - * - * \p list must be a proper list. - */ -pmt_t pmt_reverse(pmt_t list); - -/*! - * \brief destructively reverse \p list. - * - * \p list must be a proper list. - */ -pmt_t pmt_reverse_x(pmt_t list); - -/*! - * \brief (acons x y a) == (cons (cons x y) a) - */ -inline static pmt_t -pmt_acons(pmt_t x, pmt_t y, pmt_t a) -{ - return pmt_cons(pmt_cons(x, y), a); -} - -/*! - * \brief locates \p nth element of \n list where the car is the 'zeroth' element. - */ -pmt_t pmt_nth(size_t n, pmt_t list); - -/*! - * \brief returns the tail of \p list that would be obtained by calling - * cdr \p n times in succession. - */ -pmt_t pmt_nthcdr(size_t n, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. - */ -pmt_t pmt_memq(pmt_t obj, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. - */ -pmt_t pmt_memv(pmt_t obj, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_member use pmt_equal to compare \p obj with the elements of \p list. - */ -pmt_t pmt_member(pmt_t obj, pmt_t list); - -/*! - * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. - * Comparisons are done with pmt_eqv. - */ -bool pmt_subsetp(pmt_t list1, pmt_t list2); - -/*! - * \brief Return a list of length 1 containing \p x1 - */ -pmt_t pmt_list1(const pmt_t& x1); - -/*! - * \brief Return a list of length 2 containing \p x1, \p x2 - */ -pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); - -/*! - * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 - */ -pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); - -/*! - * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 - */ -pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); - -/*! - * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 - */ -pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); - -/*! - * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p - * x5, \p x6 - */ -pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); - -/*! - * \brief Return \p list with \p item added to it. - */ -pmt_t pmt_list_add(pmt_t list, const pmt_t& item); - - -/* - * ------------------------------------------------------------------------ - * read / write - * ------------------------------------------------------------------------ - */ -extern const pmt_t PMT_EOF; //< The end of file object - -//! return true if obj is the EOF object, otherwise return false. -bool pmt_is_eof_object(pmt_t obj); - -/*! - * read converts external representations of pmt objects into the - * objects themselves. Read returns the next object parsable from - * the given input port, updating port to point to the first - * character past the end of the external representation of the - * object. - * - * If an end of file is encountered in the input before any - * characters are found that can begin an object, then an end of file - * object is returned. The port remains open, and further attempts - * to read will also return an end of file object. If an end of file - * is encountered after the beginning of an object's external - * representation, but the external representation is incomplete and - * therefore not parsable, an error is signaled. - */ -pmt_t pmt_read(std::istream &port); - -/*! - * Write a written representation of \p obj to the given \p port. - */ -void pmt_write(pmt_t obj, std::ostream &port); - -/*! - * Return a string representation of \p obj. - * This is the same output as would be generated by pmt_write. - */ -std::string pmt_write_string(pmt_t obj); - - -/*! - * \brief Write pmt string representation to stdout. - */ -void pmt_print(pmt_t v); - - -/* - * ------------------------------------------------------------------------ - * portable byte stream representation - * ------------------------------------------------------------------------ - */ -/*! - * \brief Write portable byte-serial representation of \p obj to \p sink - */ -bool pmt_serialize(pmt_t obj, std::streambuf &sink); - -/*! - * \brief Create obj from portable byte-serial representation - */ -pmt_t pmt_deserialize(std::streambuf &source); - - -void pmt_dump_sizeof(); // debugging - -/*! - * \brief Provide a simple string generating interface to pmt's serialize function - */ -std::string pmt_serialize_str(pmt_t obj); - -/*! - * \brief Provide a simple string generating interface to pmt's deserialize function - */ -pmt_t pmt_deserialize_str(std::string str); - - - - diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i new file mode 100644 index 000000000..54b50660d --- /dev/null +++ b/gruel/src/swig/pmt_swig.i @@ -0,0 +1,755 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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. + */ + +%module pmt +%include "std_string.i" +%include "stdint.i" +%{ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace pmt; +%} + + + +/* + * ------------------------------------------------------------------------ + * Booleans. Two constants, #t and #f. + * + * In predicates, anything that is not #f is considered true. + * I.e., there is a single false value, #f. + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_T; +extern const pmt_t PMT_F; + +//! Return true if obj is \#t or \#f, else return false. +bool pmt_is_bool(pmt_t obj); + +//! Return false if obj is \#f, else return true. +bool pmt_is_true(pmt_t obj); + +//! Return true if obj is \#f, else return true. +bool pmt_is_false(pmt_t obj); + +//! Return \#f is val is false, else return \#t. +pmt_t pmt_from_bool(bool val); + +//! Return true if val is PMT_T, return false when val is PMT_F, +// else raise wrong_type exception. +bool pmt_to_bool(pmt_t val); + +/* + * ------------------------------------------------------------------------ + * Symbols + * ------------------------------------------------------------------------ + */ + +//! Return true if obj is a symbol, else false. +bool pmt_is_symbol(const pmt_t& obj); + +//! Return the symbol whose name is \p s. +pmt_t pmt_string_to_symbol(const std::string &s); + +//! Alias for pmt_string_to_symbol +pmt_t pmt_intern(const std::string &s); + + +/*! + * If \p is a symbol, return the name of the symbol as a string. + * Otherwise, raise the wrong_type exception. + */ +const std::string pmt_symbol_to_string(const pmt_t& sym); + +/* + * ------------------------------------------------------------------------ + * Numbers: we support integer, real and complex + * ------------------------------------------------------------------------ + */ + +//! Return true if obj is any kind of number, else false. +bool pmt_is_number(pmt_t obj); + +/* + * ------------------------------------------------------------------------ + * Integers + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is an integer number, else false +bool pmt_is_integer(pmt_t x); + +//! Return the pmt value that represents the integer \p x. +pmt_t pmt_from_long(long x); + +/*! + * \brief Convert pmt to long if possible. + * + * When \p x represents an exact integer that fits in a long, + * return that integer. Else raise an exception, either wrong_type + * when x is not an exact integer, or out_of_range when it doesn't fit. + */ +long pmt_to_long(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * uint64_t + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is an uint64 number, else false +bool pmt_is_uint64(pmt_t x); + +//! Return the pmt value that represents the uint64 \p x. +pmt_t pmt_from_uint64(uint64_t x); + +/*! + * \brief Convert pmt to uint64 if possible. + * + * When \p x represents an exact integer that fits in a uint64, + * return that uint64. Else raise an exception, either wrong_type + * when x is not an exact uint64, or out_of_range when it doesn't fit. + */ +uint64_t pmt_to_uint64(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * Reals + * ------------------------------------------------------------------------ + */ + +/* + * \brief Return true if \p obj is a real number, else false. + */ +bool pmt_is_real(pmt_t obj); + +//! Return the pmt value that represents double \p x. +pmt_t pmt_from_double(double x); + +/*! + * \brief Convert pmt to double if possible. + * + * Returns the number closest to \p val that is representable + * as a double. The argument \p val must be a real or integer, otherwise + * a wrong_type exception is raised. + */ +double pmt_to_double(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * Complex + * ------------------------------------------------------------------------ + */ + +/*! + * \brief return true if \p obj is a complex number, false otherwise. + */ +bool pmt_is_complex(pmt_t obj); + +//! Return a complex number constructed of the given real and imaginary parts. +pmt_t pmt_make_rectangular(double re, double im); + +/*! + * If \p z is complex, real or integer, return the closest complex. + * Otherwise, raise the wrong_type exception. + */ +std::complex pmt_to_complex(pmt_t z); + +/* + * ------------------------------------------------------------------------ + * Pairs + * ------------------------------------------------------------------------ + */ + +extern const pmt_t PMT_NIL; //< the empty list + +//! Return true if \p x is the empty list, otherwise return false. +bool pmt_is_null(const pmt_t& x); + +//! Return true if \p obj is a pair, else false. +bool pmt_is_pair(const pmt_t& obj); + +//! Return a newly allocated pair whose car is \p x and whose cdr is \p y. +pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); + +//! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. +pmt_t pmt_car(const pmt_t& pair); + +//! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. +pmt_t pmt_cdr(const pmt_t& pair); + +//! Stores \p value in the car field of \p pair. +void pmt_set_car(pmt_t pair, pmt_t value); + +//! Stores \p value in the cdr field of \p pair. +void pmt_set_cdr(pmt_t pair, pmt_t value); + +pmt_t pmt_caar(pmt_t pair); +pmt_t pmt_cadr(pmt_t pair); +pmt_t pmt_cdar(pmt_t pair); +pmt_t pmt_cddr(pmt_t pair); +pmt_t pmt_caddr(pmt_t pair); +pmt_t pmt_cadddr(pmt_t pair); + +/* + * ------------------------------------------------------------------------ + * Tuples + * + * Store a fixed number of objects. Tuples are not modifiable, and thus + * are excellent for use as messages. Indexing is zero based. + * Access time to an element is O(1). + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a tuple, othewise false. +bool pmt_is_tuple(pmt_t x); + +pmt_t pmt_make_tuple(); +pmt_t pmt_make_tuple(const pmt_t &e0); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); + +/*! + * If \p x is a vector or proper list, return a tuple containing the elements of x + */ +pmt_t pmt_to_tuple(const pmt_t &x); + +/*! + * Return the contents of position \p k of \p tuple. + * \p k must be a valid index of \p tuple. + */ +pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); + +/* + * ------------------------------------------------------------------------ + * Vectors + * + * These vectors can hold any kind of objects. Indexing is zero based. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a vector, othewise false. +bool pmt_is_vector(pmt_t x); + +//! Make a vector of length \p k, with initial values set to \p fill +pmt_t pmt_make_vector(size_t k, pmt_t fill); + +/*! + * Return the contents of position \p k of \p vector. + * \p k must be a valid index of \p vector. + */ +pmt_t pmt_vector_ref(pmt_t vector, size_t k); + +//! Store \p obj in position \p k. +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); + +/*! + *
+ * ------------------------------------------------------------------------
+ *		       Uniform Numeric Vectors
+ *
+ * A uniform numeric vector is a vector whose elements are all of single
+ * numeric type.  pmt offers uniform numeric vectors for signed and
+ * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
+ * floating point values, and complex floating-point numbers of these
+ * two sizes.  Indexing is zero based.
+ *
+ * The names of the functions include these tags in their names:
+ *
+ *    u8  unsigned 8-bit integers
+ *    s8  signed 8-bit integers
+ *   u16  unsigned 16-bit integers
+ *   s16  signed 16-bit integers
+ *   u32  unsigned 32-bit integers
+ *   s32  signed 32-bit integers
+ *   u64  unsigned 64-bit integers
+ *   s64  signed 64-bit integers
+ *   f32  the C++ type float
+ *   f64  the C++ type double
+ *   c32  the C++ type complex
+ *   c64  the C++ type complex
+ * ------------------------------------------------------------------------
+ * 
+ */ + +//! true if \p x is any kind of uniform numeric vector +bool pmt_is_uniform_vector(pmt_t x); + +bool pmt_is_u8vector(pmt_t x); +bool pmt_is_s8vector(pmt_t x); +bool pmt_is_u16vector(pmt_t x); +bool pmt_is_s16vector(pmt_t x); +bool pmt_is_u32vector(pmt_t x); +bool pmt_is_s32vector(pmt_t x); +bool pmt_is_u64vector(pmt_t x); +bool pmt_is_s64vector(pmt_t x); +bool pmt_is_f32vector(pmt_t x); +bool pmt_is_f64vector(pmt_t x); +bool pmt_is_c32vector(pmt_t x); +bool pmt_is_c64vector(pmt_t x); + +pmt_t pmt_make_u8vector(size_t k, uint8_t fill); +pmt_t pmt_make_s8vector(size_t k, int8_t fill); +pmt_t pmt_make_u16vector(size_t k, uint16_t fill); +pmt_t pmt_make_s16vector(size_t k, int16_t fill); +pmt_t pmt_make_u32vector(size_t k, uint32_t fill); +pmt_t pmt_make_s32vector(size_t k, int32_t fill); +pmt_t pmt_make_u64vector(size_t k, uint64_t fill); +pmt_t pmt_make_s64vector(size_t k, int64_t fill); +pmt_t pmt_make_f32vector(size_t k, float fill); +pmt_t pmt_make_f64vector(size_t k, double fill); +pmt_t pmt_make_c32vector(size_t k, std::complex fill); +pmt_t pmt_make_c64vector(size_t k, std::complex fill); + +pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); +pmt_t pmt_init_s8vector(size_t k, const int8_t *data); +pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); +pmt_t pmt_init_s16vector(size_t k, const int16_t *data); +pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); +pmt_t pmt_init_s32vector(size_t k, const int32_t *data); +pmt_t pmt_init_f32vector(size_t k, const float *data); +pmt_t pmt_init_f64vector(size_t k, const double *data); +pmt_t pmt_init_c32vector(size_t k, const std::complex *data); +pmt_t pmt_init_c64vector(size_t k, const std::complex *data); + +uint8_t pmt_u8vector_ref(pmt_t v, size_t k); +int8_t pmt_s8vector_ref(pmt_t v, size_t k); +uint16_t pmt_u16vector_ref(pmt_t v, size_t k); +int16_t pmt_s16vector_ref(pmt_t v, size_t k); +uint32_t pmt_u32vector_ref(pmt_t v, size_t k); +int32_t pmt_s32vector_ref(pmt_t v, size_t k); +uint64_t pmt_u64vector_ref(pmt_t v, size_t k); +int64_t pmt_s64vector_ref(pmt_t v, size_t k); +float pmt_f32vector_ref(pmt_t v, size_t k); +double pmt_f64vector_ref(pmt_t v, size_t k); +std::complex pmt_c32vector_ref(pmt_t v, size_t k); +std::complex pmt_c64vector_ref(pmt_t v, size_t k); + +void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x); //< v[k] = x +void pmt_s8vector_set(pmt_t v, size_t k, int8_t x); +void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x); +void pmt_s16vector_set(pmt_t v, size_t k, int16_t x); +void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x); +void pmt_s32vector_set(pmt_t v, size_t k, int32_t x); +void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x); +void pmt_s64vector_set(pmt_t v, size_t k, int64_t x); +void pmt_f32vector_set(pmt_t v, size_t k, float x); +void pmt_f64vector_set(pmt_t v, size_t k, double x); +void pmt_c32vector_set(pmt_t v, size_t k, std::complex x); +void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); + +// Return const pointers to the elements + +const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements +const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements +const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements +const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements +const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements +const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements +const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements + +// Return non-const pointers to the elements + +void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements + +/* + * ------------------------------------------------------------------------ + * Dictionary (a.k.a associative array, hash, map) + * + * This is a functional data structure that is persistent. Updating a + * functional data structure does not destroy the existing version, but + * rather creates a new version that coexists with the old. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is a dictionary +bool pmt_is_dict(const pmt_t &obj); + +//! Make an empty dictionary +pmt_t pmt_make_dict(); + +//! Return a new dictionary with \p key associated with \p value. +pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value); + +//! Return a new dictionary with \p key removed. +pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key); + +//! Return true if \p key exists in \p dict +bool pmt_dict_has_key(const pmt_t &dict, const pmt_t &key); + +//! If \p key exists in \p dict, return associated value; otherwise return \p not_found. +pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found); + +//! Return list of (key . value) pairs +pmt_t pmt_dict_items(pmt_t dict); + +//! Return list of keys +pmt_t pmt_dict_keys(pmt_t dict); + +//! Return list of values +pmt_t pmt_dict_values(pmt_t dict); + +/* + * ------------------------------------------------------------------------ + * Any (wraps boost::any -- can be used to wrap pretty much anything) + * + * Cannot be serialized or used across process boundaries. + * See http://www.boost.org/doc/html/any.html + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is an any +bool pmt_is_any(pmt_t obj); + +//! make an any +pmt_t pmt_make_any(const boost::any &any); + +//! Return underlying boost::any +boost::any pmt_any_ref(pmt_t obj); + +//! Store \p any in \p 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 + * ------------------------------------------------------------------------ + */ + +//! Return true if x and y are the same object; otherwise return false. +bool pmt_eq(const pmt_t& x, const pmt_t& y); + +/*! + * \brief Return true if x and y should normally be regarded as the same object, else false. + * + *
+ * eqv returns true if:
+ *   x and y are the same object.
+ *   x and y are both \#t or both \#f.
+ *   x and y are both symbols and their names are the same.
+ *   x and y are both numbers, and are numerically equal.
+ *   x and y are both the empty list (nil).
+ *   x and y are pairs or vectors that denote same location in store.
+ * 
+ */ +bool pmt_eqv(const pmt_t& x, const pmt_t& y); + +/*! + * pmt_equal recursively compares the contents of pairs and vectors, + * applying pmt_eqv on other objects such as numbers and symbols. + * pmt_equal may fail to terminate if its arguments are circular data + * structures. + */ +bool pmt_equal(const pmt_t& x, const pmt_t& y); + + +//! Return the number of elements in v +size_t pmt_length(const pmt_t& v); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assq(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assv(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assoc(pmt_t obj, pmt_t alist); + +/*! + * \brief Apply \p proc element-wise to the elements of list and returns + * a list of the results, in order. + * + * \p list must be a list. The dynamic order in which \p proc is + * applied to the elements of \p list is unspecified. + */ +pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); + +/*! + * \brief reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse(pmt_t list); + +/*! + * \brief destructively reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse_x(pmt_t list); + +/*! + * \brief (acons x y a) == (cons (cons x y) a) + */ +inline static pmt_t +pmt_acons(pmt_t x, pmt_t y, pmt_t a) +{ + return pmt_cons(pmt_cons(x, y), a); +} + +/*! + * \brief locates \p nth element of \n list where the car is the 'zeroth' element. + */ +pmt_t pmt_nth(size_t n, pmt_t list); + +/*! + * \brief returns the tail of \p list that would be obtained by calling + * cdr \p n times in succession. + */ +pmt_t pmt_nthcdr(size_t n, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memq(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memv(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_member use pmt_equal to compare \p obj with the elements of \p list. + */ +pmt_t pmt_member(pmt_t obj, pmt_t list); + +/*! + * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. + * Comparisons are done with pmt_eqv. + */ +bool pmt_subsetp(pmt_t list1, pmt_t list2); + +/*! + * \brief Return a list of length 1 containing \p x1 + */ +pmt_t pmt_list1(const pmt_t& x1); + +/*! + * \brief Return a list of length 2 containing \p x1, \p x2 + */ +pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); + +/*! + * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 + */ +pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); + +/*! + * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 + */ +pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); + +/*! + * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 + */ +pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); + +/*! + * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p + * x5, \p x6 + */ +pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); + +/*! + * \brief Return \p list with \p item added to it. + */ +pmt_t pmt_list_add(pmt_t list, const pmt_t& item); + + +/* + * ------------------------------------------------------------------------ + * read / write + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_EOF; //< The end of file object + +//! return true if obj is the EOF object, otherwise return false. +bool pmt_is_eof_object(pmt_t obj); + +/*! + * read converts external representations of pmt objects into the + * objects themselves. Read returns the next object parsable from + * the given input port, updating port to point to the first + * character past the end of the external representation of the + * object. + * + * If an end of file is encountered in the input before any + * characters are found that can begin an object, then an end of file + * object is returned. The port remains open, and further attempts + * to read will also return an end of file object. If an end of file + * is encountered after the beginning of an object's external + * representation, but the external representation is incomplete and + * therefore not parsable, an error is signaled. + */ +pmt_t pmt_read(std::istream &port); + +/*! + * Write a written representation of \p obj to the given \p port. + */ +void pmt_write(pmt_t obj, std::ostream &port); + +/*! + * Return a string representation of \p obj. + * This is the same output as would be generated by pmt_write. + */ +std::string pmt_write_string(pmt_t obj); + + +/*! + * \brief Write pmt string representation to stdout. + */ +void pmt_print(pmt_t v); + + +/* + * ------------------------------------------------------------------------ + * portable byte stream representation + * ------------------------------------------------------------------------ + */ +/*! + * \brief Write portable byte-serial representation of \p obj to \p sink + */ +bool pmt_serialize(pmt_t obj, std::streambuf &sink); + +/*! + * \brief Create obj from portable byte-serial representation + */ +pmt_t pmt_deserialize(std::streambuf &source); + + +void pmt_dump_sizeof(); // debugging + +/*! + * \brief Provide a simple string generating interface to pmt's serialize function + */ +std::string pmt_serialize_str(pmt_t obj); + +/*! + * \brief Provide a simple string generating interface to pmt's deserialize function + */ +pmt_t pmt_deserialize_str(std::string str); -- cgit From eb3a4fe528452415eb877b2b76e1006fc47bc655 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 15 Mar 2011 12:30:27 -0400 Subject: gruel: fixed swig interface file to dereference pmt_t. --- gruel/src/swig/pmt_swig.i | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gruel') diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 54b50660d..6435e03cc 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -36,7 +36,12 @@ using namespace pmt; %} +// Template intrusive_ptr for Swig to avoid dereferencing issues +class pmt_base; +%import +%template(swig_int_ptr) boost::intrusive_ptr; +typedef boost::intrusive_ptr pmt_t; /* * ------------------------------------------------------------------------ -- cgit From 1d70ed2bd928d52a383e688949cc7f747dd584fa Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 15 Mar 2011 21:04:24 -0700 Subject: gruel: added missing ignores --- gruel/src/python/.gitignore | 2 ++ gruel/src/swig/.gitignore | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 gruel/src/python/.gitignore create mode 100644 gruel/src/swig/.gitignore (limited to 'gruel') diff --git a/gruel/src/python/.gitignore b/gruel/src/python/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gruel/src/python/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gruel/src/swig/.gitignore b/gruel/src/swig/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gruel/src/swig/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in -- cgit From dd97932abfd35e60e9374f202aa6c69afcfb35ca Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 26 Mar 2011 18:06:56 -0400 Subject: gruel: using a copy of swig's intrusive_ptr.i to support the PMT wrapping. --- gruel/src/swig/Makefile.am | 7 +-- gruel/src/swig/gr_intrusive_ptr.i | 102 ++++++++++++++++++++++++++++++++++++++ gruel/src/swig/pmt_swig.i | 3 +- 3 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 gruel/src/swig/gr_intrusive_ptr.i (limited to 'gruel') diff --git a/gruel/src/swig/Makefile.am b/gruel/src/swig/Makefile.am index 294045567..3261e47c2 100644 --- a/gruel/src/swig/Makefile.am +++ b/gruel/src/swig/Makefile.am @@ -30,9 +30,6 @@ AM_CPPFLAGS = \ $(PYTHON_CPPFLAGS) \ $(WITH_INCLUDES) -TOP_SWIG_IFILES = \ - pmt_swig.i - ############################## # SWIG interface and library TOP_SWIG_IFILES = \ @@ -50,6 +47,6 @@ pmt_swig_la_swig_libadd = \ $(abs_top_builddir)/gruel/src/lib/pmt/libpmt.la # additional SWIG files to be installed -pmt_swig_swiginclude_headers = - +pmt_swig_swiginclude_headers = \ + gr_intrusive_ptr.i diff --git a/gruel/src/swig/gr_intrusive_ptr.i b/gruel/src/swig/gr_intrusive_ptr.i new file mode 100644 index 000000000..eef5bc84d --- /dev/null +++ b/gruel/src/swig/gr_intrusive_ptr.i @@ -0,0 +1,102 @@ +// This file was borrowed from the SWIG project to allow use to +// wrap PMTs that use intrusive pointers. This is only necessary +// to support backwards compatability with older distributions of +// Linux that do not natively support a new enough version of SWIG. +// We do this to prevent having to update our dependency on a new +// SWIG. Eventually, the need for this should go away. + +// Allow for different namespaces for shared_ptr / intrusive_ptr - they could be boost or std or std::tr1 +// For example for std::tr1, use: +// #define SWIG_SHARED_PTR_NAMESPACE std +// #define SWIG_SHARED_PTR_SUBNAMESPACE tr1 +// #define SWIG_INTRUSIVE_PTR_NAMESPACE boost +// #define SWIG_INTRUSIVE_PTR_SUBNAMESPACE + +#if !defined(SWIG_INTRUSIVE_PTR_NAMESPACE) +# define SWIG_INTRUSIVE_PTR_NAMESPACE boost +#endif + +#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) +# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE::SWIG_INTRUSIVE_PTR_SUBNAMESPACE +#else +# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE +#endif + +namespace SWIG_INTRUSIVE_PTR_NAMESPACE { +#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) + namespace SWIG_INTRUSIVE_PTR_SUBNAMESPACE { +#endif + template class intrusive_ptr { + }; +#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE) + } +#endif +} + +%fragment("SWIG_intrusive_deleter", "header") { +template struct SWIG_intrusive_deleter { + void operator()(T *p) { + if (p) + intrusive_ptr_release(p); + } +}; +} + +%fragment("SWIG_null_deleter", "header") { +struct SWIG_null_deleter { + void operator() (void const *) const { + } +}; +%#define SWIG_NO_NULL_DELETER_0 , SWIG_null_deleter() +%#define SWIG_NO_NULL_DELETER_1 +} + +// Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types +// For plain classes, do not use for derived classes +%define SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE...) +SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, , TYPE) +SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, const, TYPE) +%enddef + +// Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types +// For derived classes +%define SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...) +SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, , TYPE) +SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, const, TYPE) +%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > = SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >) %{ + *newmemory = SWIG_CAST_NEW_MEMORY; + return (void *) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >(*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *)$from); + %} +%extend TYPE { + static SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) { + return swigSharedPtrUpcast; + } +} +%enddef + +// Extra user macro for including classes in intrusive_ptr typemaps for both const and non-const pointer types +// This caters for classes which cannot be wrapped by intrusive_ptrs but are still part of the class hierarchy +// For plain classes, do not use for derived classes +%define SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE...) +SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, , TYPE) +SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, const, TYPE) +%enddef + +// Extra user macro for including classes in intrusive_ptr typemaps for both const and non-const pointer types +// This caters for classes which cannot be wrapped by intrusive_ptrs but are still part of the class hierarchy +// For derived classes +%define SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE...) +SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, , TYPE) +SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, const, TYPE) +%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > = SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >) %{ + *newmemory = SWIG_CAST_NEW_MEMORY; + return (void *) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >(*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *)$from); +%} +%extend TYPE { + static SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) { + return swigSharedPtrUpcast; + } +} +%enddef + + diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 6435e03cc..3b0eb45c8 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -38,7 +38,8 @@ using namespace pmt; // Template intrusive_ptr for Swig to avoid dereferencing issues class pmt_base; -%import +//%import +%import %template(swig_int_ptr) boost::intrusive_ptr; typedef boost::intrusive_ptr pmt_t; -- cgit From 0966037079d9e2af5778f1418c17d29352286406 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 1 Apr 2011 10:02:21 -0400 Subject: build: updating Makefiles for newer linker requirements. --- gruel/src/lib/Makefile.am | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index f37ab27a1..773f3aefd 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -60,5 +60,9 @@ libgruel_la_LIBADD = \ # ---------------------------------------------------------------- test_gruel_SOURCES = test_gruel.cc -test_gruel_LDADD = pmt/libpmt-qa.la libgruel.la +test_gruel_LDADD = \ + $(BOOST_THREAD_LIB) \ + $(BOOST_SYSTEM_LIB) \ + $(BOOST_FILESYSTEM_LIB) \ + pmt/libpmt-qa.la libgruel.la -- cgit From bdd0bd405c2ea645395917c1abb91c964210c4d9 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 8 May 2011 17:04:32 +0100 Subject: build: committing updated Makefile.swig.gen files. --- gruel/src/swig/Makefile.swig.gen | 42 ++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'gruel') diff --git a/gruel/src/swig/Makefile.swig.gen b/gruel/src/swig/Makefile.swig.gen index c6a2fb956..97aff8104 100644 --- a/gruel/src/swig/Makefile.swig.gen +++ b/gruel/src/swig/Makefile.swig.gen @@ -20,20 +20,20 @@ # Boston, MA 02110-1301, USA. # -# Makefile.swig.gen for gnuradio_core_runtime.i +# Makefile.swig.gen for pmt_swig.i ## Default install locations for these files: ## ## Default location for the Python directory is: -## ${prefix}/lib/python${python_version}/site-packages/[category]/gnuradio_core_runtime +## ${prefix}/lib/python${python_version}/site-packages/[category]/pmt_swig ## Default location for the Python exec directory is: -## ${exec_prefix}/lib/python${python_version}/site-packages/[category]/gnuradio_core_runtime +## ${exec_prefix}/lib/python${python_version}/site-packages/[category]/pmt_swig ## ## The following can be overloaded to change the install location, but ## this has to be done in the including Makefile.am -before- ## Makefile.swig is included. -pmt_swig_pythondir_category ?= gruel/pmt_swig +pmt_swig_pythondir_category ?= gnuradio/pmt_swig pmt_swig_pylibdir_category ?= $(pmt_swig_pythondir_category) pmt_swig_pythondir = $(pythondir)/$(pmt_swig_pythondir_category) pmt_swig_pylibdir = $(pyexecdir)/$(pmt_swig_pylibdir_category) @@ -44,7 +44,7 @@ pmt_swig_pylibdir = $(pyexecdir)/$(pmt_swig_pylibdir_category) pmt_swig_scmlibdir = $(libdir) # The scm files for the guile modules get installed where ever guile -# is installed, usually /usr/share/guile/site/gnuradio_core_runtime +# is installed, usually /usr/share/guile/site/pmt_swig # FIXME: determince whether these should be installed with gnuradio. pmt_swig_scmdir = $(guiledir) @@ -105,11 +105,41 @@ _pmt_swig_la_CXXFLAGS = \ $(pmt_swig_la_swig_cxxflags) python/pmt_swig.cc: pmt_swig.py -pmt_swig.py: pmt_swig.i +pmt_swig.py: pmt_swig.i # Include the python dependencies for this file -include python/pmt_swig.d endif # end of if python +if GUILE + +pmt_swig_scmlib_LTLIBRARIES = \ + libguile-gnuradio-pmt_swig.la +libguile_gnuradio_pmt_swig_la_SOURCES = \ + guile/pmt_swig.cc \ + $(pmt_swig_la_swig_sources) +nobase_pmt_swig_scm_DATA = \ + gnuradio/pmt_swig.scm \ + gnuradio/pmt_swig-primitive.scm +libguile_gnuradio_pmt_swig_la_LIBADD = \ + $(STD_SWIG_LA_LIB_ADD) \ + $(pmt_swig_la_swig_libadd) +libguile_gnuradio_pmt_swig_la_LDFLAGS = \ + $(STD_SWIG_LA_LD_FLAGS) \ + $(pmt_swig_la_swig_ldflags) +libguile_gnuradio_pmt_swig_la_CXXFLAGS = \ + $(STD_SWIG_CXX_FLAGS) \ + -I$(top_builddir) \ + $(pmt_swig_la_swig_cxxflags) + +guile/pmt_swig.cc: gnuradio/pmt_swig.scm +gnuradio/pmt_swig.scm: pmt_swig.i +gnuradio/pmt_swig-primitive.scm: gnuradio/pmt_swig.scm + +# Include the guile dependencies for this file +-include guile/pmt_swig.d + +endif # end of GUILE + -- cgit From 1ba972517c6aa00270382f51e76bdc125f626746 Mon Sep 17 00:00:00 2001 From: tttx Date: Tue, 24 May 2011 15:20:21 -0400 Subject: fixing pmt swig python installed files --- gruel/src/python/pmt/__init__.py | 25 ++ gruel/src/swig/pmt/pmt_swig.i | 761 +++++++++++++++++++++++++++++++++++++++ gruel/src/swig/pmt_swig.i | 761 --------------------------------------- 3 files changed, 786 insertions(+), 761 deletions(-) create mode 100644 gruel/src/python/pmt/__init__.py create mode 100644 gruel/src/swig/pmt/pmt_swig.i delete mode 100644 gruel/src/swig/pmt_swig.i (limited to 'gruel') diff --git a/gruel/src/python/pmt/__init__.py b/gruel/src/python/pmt/__init__.py new file mode 100644 index 000000000..421a9aaa8 --- /dev/null +++ b/gruel/src/python/pmt/__init__.py @@ -0,0 +1,25 @@ +# +# Copyright 2011 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. +# + +# The presence of this file turns this directory into a Python package + +from pmt_swig import * + diff --git a/gruel/src/swig/pmt/pmt_swig.i b/gruel/src/swig/pmt/pmt_swig.i new file mode 100644 index 000000000..3b0eb45c8 --- /dev/null +++ b/gruel/src/swig/pmt/pmt_swig.i @@ -0,0 +1,761 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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. + */ + +%module pmt +%include "std_string.i" +%include "stdint.i" +%{ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace pmt; +%} + +// Template intrusive_ptr for Swig to avoid dereferencing issues +class pmt_base; +//%import +%import +%template(swig_int_ptr) boost::intrusive_ptr; + +typedef boost::intrusive_ptr pmt_t; + +/* + * ------------------------------------------------------------------------ + * Booleans. Two constants, #t and #f. + * + * In predicates, anything that is not #f is considered true. + * I.e., there is a single false value, #f. + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_T; +extern const pmt_t PMT_F; + +//! Return true if obj is \#t or \#f, else return false. +bool pmt_is_bool(pmt_t obj); + +//! Return false if obj is \#f, else return true. +bool pmt_is_true(pmt_t obj); + +//! Return true if obj is \#f, else return true. +bool pmt_is_false(pmt_t obj); + +//! Return \#f is val is false, else return \#t. +pmt_t pmt_from_bool(bool val); + +//! Return true if val is PMT_T, return false when val is PMT_F, +// else raise wrong_type exception. +bool pmt_to_bool(pmt_t val); + +/* + * ------------------------------------------------------------------------ + * Symbols + * ------------------------------------------------------------------------ + */ + +//! Return true if obj is a symbol, else false. +bool pmt_is_symbol(const pmt_t& obj); + +//! Return the symbol whose name is \p s. +pmt_t pmt_string_to_symbol(const std::string &s); + +//! Alias for pmt_string_to_symbol +pmt_t pmt_intern(const std::string &s); + + +/*! + * If \p is a symbol, return the name of the symbol as a string. + * Otherwise, raise the wrong_type exception. + */ +const std::string pmt_symbol_to_string(const pmt_t& sym); + +/* + * ------------------------------------------------------------------------ + * Numbers: we support integer, real and complex + * ------------------------------------------------------------------------ + */ + +//! Return true if obj is any kind of number, else false. +bool pmt_is_number(pmt_t obj); + +/* + * ------------------------------------------------------------------------ + * Integers + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is an integer number, else false +bool pmt_is_integer(pmt_t x); + +//! Return the pmt value that represents the integer \p x. +pmt_t pmt_from_long(long x); + +/*! + * \brief Convert pmt to long if possible. + * + * When \p x represents an exact integer that fits in a long, + * return that integer. Else raise an exception, either wrong_type + * when x is not an exact integer, or out_of_range when it doesn't fit. + */ +long pmt_to_long(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * uint64_t + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is an uint64 number, else false +bool pmt_is_uint64(pmt_t x); + +//! Return the pmt value that represents the uint64 \p x. +pmt_t pmt_from_uint64(uint64_t x); + +/*! + * \brief Convert pmt to uint64 if possible. + * + * When \p x represents an exact integer that fits in a uint64, + * return that uint64. Else raise an exception, either wrong_type + * when x is not an exact uint64, or out_of_range when it doesn't fit. + */ +uint64_t pmt_to_uint64(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * Reals + * ------------------------------------------------------------------------ + */ + +/* + * \brief Return true if \p obj is a real number, else false. + */ +bool pmt_is_real(pmt_t obj); + +//! Return the pmt value that represents double \p x. +pmt_t pmt_from_double(double x); + +/*! + * \brief Convert pmt to double if possible. + * + * Returns the number closest to \p val that is representable + * as a double. The argument \p val must be a real or integer, otherwise + * a wrong_type exception is raised. + */ +double pmt_to_double(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * Complex + * ------------------------------------------------------------------------ + */ + +/*! + * \brief return true if \p obj is a complex number, false otherwise. + */ +bool pmt_is_complex(pmt_t obj); + +//! Return a complex number constructed of the given real and imaginary parts. +pmt_t pmt_make_rectangular(double re, double im); + +/*! + * If \p z is complex, real or integer, return the closest complex. + * Otherwise, raise the wrong_type exception. + */ +std::complex pmt_to_complex(pmt_t z); + +/* + * ------------------------------------------------------------------------ + * Pairs + * ------------------------------------------------------------------------ + */ + +extern const pmt_t PMT_NIL; //< the empty list + +//! Return true if \p x is the empty list, otherwise return false. +bool pmt_is_null(const pmt_t& x); + +//! Return true if \p obj is a pair, else false. +bool pmt_is_pair(const pmt_t& obj); + +//! Return a newly allocated pair whose car is \p x and whose cdr is \p y. +pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); + +//! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. +pmt_t pmt_car(const pmt_t& pair); + +//! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. +pmt_t pmt_cdr(const pmt_t& pair); + +//! Stores \p value in the car field of \p pair. +void pmt_set_car(pmt_t pair, pmt_t value); + +//! Stores \p value in the cdr field of \p pair. +void pmt_set_cdr(pmt_t pair, pmt_t value); + +pmt_t pmt_caar(pmt_t pair); +pmt_t pmt_cadr(pmt_t pair); +pmt_t pmt_cdar(pmt_t pair); +pmt_t pmt_cddr(pmt_t pair); +pmt_t pmt_caddr(pmt_t pair); +pmt_t pmt_cadddr(pmt_t pair); + +/* + * ------------------------------------------------------------------------ + * Tuples + * + * Store a fixed number of objects. Tuples are not modifiable, and thus + * are excellent for use as messages. Indexing is zero based. + * Access time to an element is O(1). + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a tuple, othewise false. +bool pmt_is_tuple(pmt_t x); + +pmt_t pmt_make_tuple(); +pmt_t pmt_make_tuple(const pmt_t &e0); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); + +/*! + * If \p x is a vector or proper list, return a tuple containing the elements of x + */ +pmt_t pmt_to_tuple(const pmt_t &x); + +/*! + * Return the contents of position \p k of \p tuple. + * \p k must be a valid index of \p tuple. + */ +pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); + +/* + * ------------------------------------------------------------------------ + * Vectors + * + * These vectors can hold any kind of objects. Indexing is zero based. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a vector, othewise false. +bool pmt_is_vector(pmt_t x); + +//! Make a vector of length \p k, with initial values set to \p fill +pmt_t pmt_make_vector(size_t k, pmt_t fill); + +/*! + * Return the contents of position \p k of \p vector. + * \p k must be a valid index of \p vector. + */ +pmt_t pmt_vector_ref(pmt_t vector, size_t k); + +//! Store \p obj in position \p k. +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); + +/*! + *
+ * ------------------------------------------------------------------------
+ *		       Uniform Numeric Vectors
+ *
+ * A uniform numeric vector is a vector whose elements are all of single
+ * numeric type.  pmt offers uniform numeric vectors for signed and
+ * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
+ * floating point values, and complex floating-point numbers of these
+ * two sizes.  Indexing is zero based.
+ *
+ * The names of the functions include these tags in their names:
+ *
+ *    u8  unsigned 8-bit integers
+ *    s8  signed 8-bit integers
+ *   u16  unsigned 16-bit integers
+ *   s16  signed 16-bit integers
+ *   u32  unsigned 32-bit integers
+ *   s32  signed 32-bit integers
+ *   u64  unsigned 64-bit integers
+ *   s64  signed 64-bit integers
+ *   f32  the C++ type float
+ *   f64  the C++ type double
+ *   c32  the C++ type complex
+ *   c64  the C++ type complex
+ * ------------------------------------------------------------------------
+ * 
+ */ + +//! true if \p x is any kind of uniform numeric vector +bool pmt_is_uniform_vector(pmt_t x); + +bool pmt_is_u8vector(pmt_t x); +bool pmt_is_s8vector(pmt_t x); +bool pmt_is_u16vector(pmt_t x); +bool pmt_is_s16vector(pmt_t x); +bool pmt_is_u32vector(pmt_t x); +bool pmt_is_s32vector(pmt_t x); +bool pmt_is_u64vector(pmt_t x); +bool pmt_is_s64vector(pmt_t x); +bool pmt_is_f32vector(pmt_t x); +bool pmt_is_f64vector(pmt_t x); +bool pmt_is_c32vector(pmt_t x); +bool pmt_is_c64vector(pmt_t x); + +pmt_t pmt_make_u8vector(size_t k, uint8_t fill); +pmt_t pmt_make_s8vector(size_t k, int8_t fill); +pmt_t pmt_make_u16vector(size_t k, uint16_t fill); +pmt_t pmt_make_s16vector(size_t k, int16_t fill); +pmt_t pmt_make_u32vector(size_t k, uint32_t fill); +pmt_t pmt_make_s32vector(size_t k, int32_t fill); +pmt_t pmt_make_u64vector(size_t k, uint64_t fill); +pmt_t pmt_make_s64vector(size_t k, int64_t fill); +pmt_t pmt_make_f32vector(size_t k, float fill); +pmt_t pmt_make_f64vector(size_t k, double fill); +pmt_t pmt_make_c32vector(size_t k, std::complex fill); +pmt_t pmt_make_c64vector(size_t k, std::complex fill); + +pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); +pmt_t pmt_init_s8vector(size_t k, const int8_t *data); +pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); +pmt_t pmt_init_s16vector(size_t k, const int16_t *data); +pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); +pmt_t pmt_init_s32vector(size_t k, const int32_t *data); +pmt_t pmt_init_f32vector(size_t k, const float *data); +pmt_t pmt_init_f64vector(size_t k, const double *data); +pmt_t pmt_init_c32vector(size_t k, const std::complex *data); +pmt_t pmt_init_c64vector(size_t k, const std::complex *data); + +uint8_t pmt_u8vector_ref(pmt_t v, size_t k); +int8_t pmt_s8vector_ref(pmt_t v, size_t k); +uint16_t pmt_u16vector_ref(pmt_t v, size_t k); +int16_t pmt_s16vector_ref(pmt_t v, size_t k); +uint32_t pmt_u32vector_ref(pmt_t v, size_t k); +int32_t pmt_s32vector_ref(pmt_t v, size_t k); +uint64_t pmt_u64vector_ref(pmt_t v, size_t k); +int64_t pmt_s64vector_ref(pmt_t v, size_t k); +float pmt_f32vector_ref(pmt_t v, size_t k); +double pmt_f64vector_ref(pmt_t v, size_t k); +std::complex pmt_c32vector_ref(pmt_t v, size_t k); +std::complex pmt_c64vector_ref(pmt_t v, size_t k); + +void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x); //< v[k] = x +void pmt_s8vector_set(pmt_t v, size_t k, int8_t x); +void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x); +void pmt_s16vector_set(pmt_t v, size_t k, int16_t x); +void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x); +void pmt_s32vector_set(pmt_t v, size_t k, int32_t x); +void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x); +void pmt_s64vector_set(pmt_t v, size_t k, int64_t x); +void pmt_f32vector_set(pmt_t v, size_t k, float x); +void pmt_f64vector_set(pmt_t v, size_t k, double x); +void pmt_c32vector_set(pmt_t v, size_t k, std::complex x); +void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); + +// Return const pointers to the elements + +const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements +const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements +const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements +const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements +const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements +const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements +const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements + +// Return non-const pointers to the elements + +void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements + +/* + * ------------------------------------------------------------------------ + * Dictionary (a.k.a associative array, hash, map) + * + * This is a functional data structure that is persistent. Updating a + * functional data structure does not destroy the existing version, but + * rather creates a new version that coexists with the old. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is a dictionary +bool pmt_is_dict(const pmt_t &obj); + +//! Make an empty dictionary +pmt_t pmt_make_dict(); + +//! Return a new dictionary with \p key associated with \p value. +pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value); + +//! Return a new dictionary with \p key removed. +pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key); + +//! Return true if \p key exists in \p dict +bool pmt_dict_has_key(const pmt_t &dict, const pmt_t &key); + +//! If \p key exists in \p dict, return associated value; otherwise return \p not_found. +pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found); + +//! Return list of (key . value) pairs +pmt_t pmt_dict_items(pmt_t dict); + +//! Return list of keys +pmt_t pmt_dict_keys(pmt_t dict); + +//! Return list of values +pmt_t pmt_dict_values(pmt_t dict); + +/* + * ------------------------------------------------------------------------ + * Any (wraps boost::any -- can be used to wrap pretty much anything) + * + * Cannot be serialized or used across process boundaries. + * See http://www.boost.org/doc/html/any.html + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is an any +bool pmt_is_any(pmt_t obj); + +//! make an any +pmt_t pmt_make_any(const boost::any &any); + +//! Return underlying boost::any +boost::any pmt_any_ref(pmt_t obj); + +//! Store \p any in \p 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 + * ------------------------------------------------------------------------ + */ + +//! Return true if x and y are the same object; otherwise return false. +bool pmt_eq(const pmt_t& x, const pmt_t& y); + +/*! + * \brief Return true if x and y should normally be regarded as the same object, else false. + * + *
+ * eqv returns true if:
+ *   x and y are the same object.
+ *   x and y are both \#t or both \#f.
+ *   x and y are both symbols and their names are the same.
+ *   x and y are both numbers, and are numerically equal.
+ *   x and y are both the empty list (nil).
+ *   x and y are pairs or vectors that denote same location in store.
+ * 
+ */ +bool pmt_eqv(const pmt_t& x, const pmt_t& y); + +/*! + * pmt_equal recursively compares the contents of pairs and vectors, + * applying pmt_eqv on other objects such as numbers and symbols. + * pmt_equal may fail to terminate if its arguments are circular data + * structures. + */ +bool pmt_equal(const pmt_t& x, const pmt_t& y); + + +//! Return the number of elements in v +size_t pmt_length(const pmt_t& v); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assq(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assv(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assoc(pmt_t obj, pmt_t alist); + +/*! + * \brief Apply \p proc element-wise to the elements of list and returns + * a list of the results, in order. + * + * \p list must be a list. The dynamic order in which \p proc is + * applied to the elements of \p list is unspecified. + */ +pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); + +/*! + * \brief reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse(pmt_t list); + +/*! + * \brief destructively reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse_x(pmt_t list); + +/*! + * \brief (acons x y a) == (cons (cons x y) a) + */ +inline static pmt_t +pmt_acons(pmt_t x, pmt_t y, pmt_t a) +{ + return pmt_cons(pmt_cons(x, y), a); +} + +/*! + * \brief locates \p nth element of \n list where the car is the 'zeroth' element. + */ +pmt_t pmt_nth(size_t n, pmt_t list); + +/*! + * \brief returns the tail of \p list that would be obtained by calling + * cdr \p n times in succession. + */ +pmt_t pmt_nthcdr(size_t n, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memq(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memv(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_member use pmt_equal to compare \p obj with the elements of \p list. + */ +pmt_t pmt_member(pmt_t obj, pmt_t list); + +/*! + * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. + * Comparisons are done with pmt_eqv. + */ +bool pmt_subsetp(pmt_t list1, pmt_t list2); + +/*! + * \brief Return a list of length 1 containing \p x1 + */ +pmt_t pmt_list1(const pmt_t& x1); + +/*! + * \brief Return a list of length 2 containing \p x1, \p x2 + */ +pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); + +/*! + * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 + */ +pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); + +/*! + * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 + */ +pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); + +/*! + * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 + */ +pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); + +/*! + * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p + * x5, \p x6 + */ +pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); + +/*! + * \brief Return \p list with \p item added to it. + */ +pmt_t pmt_list_add(pmt_t list, const pmt_t& item); + + +/* + * ------------------------------------------------------------------------ + * read / write + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_EOF; //< The end of file object + +//! return true if obj is the EOF object, otherwise return false. +bool pmt_is_eof_object(pmt_t obj); + +/*! + * read converts external representations of pmt objects into the + * objects themselves. Read returns the next object parsable from + * the given input port, updating port to point to the first + * character past the end of the external representation of the + * object. + * + * If an end of file is encountered in the input before any + * characters are found that can begin an object, then an end of file + * object is returned. The port remains open, and further attempts + * to read will also return an end of file object. If an end of file + * is encountered after the beginning of an object's external + * representation, but the external representation is incomplete and + * therefore not parsable, an error is signaled. + */ +pmt_t pmt_read(std::istream &port); + +/*! + * Write a written representation of \p obj to the given \p port. + */ +void pmt_write(pmt_t obj, std::ostream &port); + +/*! + * Return a string representation of \p obj. + * This is the same output as would be generated by pmt_write. + */ +std::string pmt_write_string(pmt_t obj); + + +/*! + * \brief Write pmt string representation to stdout. + */ +void pmt_print(pmt_t v); + + +/* + * ------------------------------------------------------------------------ + * portable byte stream representation + * ------------------------------------------------------------------------ + */ +/*! + * \brief Write portable byte-serial representation of \p obj to \p sink + */ +bool pmt_serialize(pmt_t obj, std::streambuf &sink); + +/*! + * \brief Create obj from portable byte-serial representation + */ +pmt_t pmt_deserialize(std::streambuf &source); + + +void pmt_dump_sizeof(); // debugging + +/*! + * \brief Provide a simple string generating interface to pmt's serialize function + */ +std::string pmt_serialize_str(pmt_t obj); + +/*! + * \brief Provide a simple string generating interface to pmt's deserialize function + */ +pmt_t pmt_deserialize_str(std::string str); diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i deleted file mode 100644 index 3b0eb45c8..000000000 --- a/gruel/src/swig/pmt_swig.i +++ /dev/null @@ -1,761 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2011 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. - */ - -%module pmt -%include "std_string.i" -%include "stdint.i" -%{ -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace pmt; -%} - -// Template intrusive_ptr for Swig to avoid dereferencing issues -class pmt_base; -//%import -%import -%template(swig_int_ptr) boost::intrusive_ptr; - -typedef boost::intrusive_ptr pmt_t; - -/* - * ------------------------------------------------------------------------ - * Booleans. Two constants, #t and #f. - * - * In predicates, anything that is not #f is considered true. - * I.e., there is a single false value, #f. - * ------------------------------------------------------------------------ - */ -extern const pmt_t PMT_T; -extern const pmt_t PMT_F; - -//! Return true if obj is \#t or \#f, else return false. -bool pmt_is_bool(pmt_t obj); - -//! Return false if obj is \#f, else return true. -bool pmt_is_true(pmt_t obj); - -//! Return true if obj is \#f, else return true. -bool pmt_is_false(pmt_t obj); - -//! Return \#f is val is false, else return \#t. -pmt_t pmt_from_bool(bool val); - -//! Return true if val is PMT_T, return false when val is PMT_F, -// else raise wrong_type exception. -bool pmt_to_bool(pmt_t val); - -/* - * ------------------------------------------------------------------------ - * Symbols - * ------------------------------------------------------------------------ - */ - -//! Return true if obj is a symbol, else false. -bool pmt_is_symbol(const pmt_t& obj); - -//! Return the symbol whose name is \p s. -pmt_t pmt_string_to_symbol(const std::string &s); - -//! Alias for pmt_string_to_symbol -pmt_t pmt_intern(const std::string &s); - - -/*! - * If \p is a symbol, return the name of the symbol as a string. - * Otherwise, raise the wrong_type exception. - */ -const std::string pmt_symbol_to_string(const pmt_t& sym); - -/* - * ------------------------------------------------------------------------ - * Numbers: we support integer, real and complex - * ------------------------------------------------------------------------ - */ - -//! Return true if obj is any kind of number, else false. -bool pmt_is_number(pmt_t obj); - -/* - * ------------------------------------------------------------------------ - * Integers - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is an integer number, else false -bool pmt_is_integer(pmt_t x); - -//! Return the pmt value that represents the integer \p x. -pmt_t pmt_from_long(long x); - -/*! - * \brief Convert pmt to long if possible. - * - * When \p x represents an exact integer that fits in a long, - * return that integer. Else raise an exception, either wrong_type - * when x is not an exact integer, or out_of_range when it doesn't fit. - */ -long pmt_to_long(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * uint64_t - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is an uint64 number, else false -bool pmt_is_uint64(pmt_t x); - -//! Return the pmt value that represents the uint64 \p x. -pmt_t pmt_from_uint64(uint64_t x); - -/*! - * \brief Convert pmt to uint64 if possible. - * - * When \p x represents an exact integer that fits in a uint64, - * return that uint64. Else raise an exception, either wrong_type - * when x is not an exact uint64, or out_of_range when it doesn't fit. - */ -uint64_t pmt_to_uint64(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * Reals - * ------------------------------------------------------------------------ - */ - -/* - * \brief Return true if \p obj is a real number, else false. - */ -bool pmt_is_real(pmt_t obj); - -//! Return the pmt value that represents double \p x. -pmt_t pmt_from_double(double x); - -/*! - * \brief Convert pmt to double if possible. - * - * Returns the number closest to \p val that is representable - * as a double. The argument \p val must be a real or integer, otherwise - * a wrong_type exception is raised. - */ -double pmt_to_double(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * Complex - * ------------------------------------------------------------------------ - */ - -/*! - * \brief return true if \p obj is a complex number, false otherwise. - */ -bool pmt_is_complex(pmt_t obj); - -//! Return a complex number constructed of the given real and imaginary parts. -pmt_t pmt_make_rectangular(double re, double im); - -/*! - * If \p z is complex, real or integer, return the closest complex. - * Otherwise, raise the wrong_type exception. - */ -std::complex pmt_to_complex(pmt_t z); - -/* - * ------------------------------------------------------------------------ - * Pairs - * ------------------------------------------------------------------------ - */ - -extern const pmt_t PMT_NIL; //< the empty list - -//! Return true if \p x is the empty list, otherwise return false. -bool pmt_is_null(const pmt_t& x); - -//! Return true if \p obj is a pair, else false. -bool pmt_is_pair(const pmt_t& obj); - -//! Return a newly allocated pair whose car is \p x and whose cdr is \p y. -pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); - -//! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. -pmt_t pmt_car(const pmt_t& pair); - -//! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. -pmt_t pmt_cdr(const pmt_t& pair); - -//! Stores \p value in the car field of \p pair. -void pmt_set_car(pmt_t pair, pmt_t value); - -//! Stores \p value in the cdr field of \p pair. -void pmt_set_cdr(pmt_t pair, pmt_t value); - -pmt_t pmt_caar(pmt_t pair); -pmt_t pmt_cadr(pmt_t pair); -pmt_t pmt_cdar(pmt_t pair); -pmt_t pmt_cddr(pmt_t pair); -pmt_t pmt_caddr(pmt_t pair); -pmt_t pmt_cadddr(pmt_t pair); - -/* - * ------------------------------------------------------------------------ - * Tuples - * - * Store a fixed number of objects. Tuples are not modifiable, and thus - * are excellent for use as messages. Indexing is zero based. - * Access time to an element is O(1). - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is a tuple, othewise false. -bool pmt_is_tuple(pmt_t x); - -pmt_t pmt_make_tuple(); -pmt_t pmt_make_tuple(const pmt_t &e0); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); - -/*! - * If \p x is a vector or proper list, return a tuple containing the elements of x - */ -pmt_t pmt_to_tuple(const pmt_t &x); - -/*! - * Return the contents of position \p k of \p tuple. - * \p k must be a valid index of \p tuple. - */ -pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); - -/* - * ------------------------------------------------------------------------ - * Vectors - * - * These vectors can hold any kind of objects. Indexing is zero based. - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is a vector, othewise false. -bool pmt_is_vector(pmt_t x); - -//! Make a vector of length \p k, with initial values set to \p fill -pmt_t pmt_make_vector(size_t k, pmt_t fill); - -/*! - * Return the contents of position \p k of \p vector. - * \p k must be a valid index of \p vector. - */ -pmt_t pmt_vector_ref(pmt_t vector, size_t k); - -//! Store \p obj in position \p k. -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); - -/*! - *
- * ------------------------------------------------------------------------
- *		       Uniform Numeric Vectors
- *
- * A uniform numeric vector is a vector whose elements are all of single
- * numeric type.  pmt offers uniform numeric vectors for signed and
- * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
- * floating point values, and complex floating-point numbers of these
- * two sizes.  Indexing is zero based.
- *
- * The names of the functions include these tags in their names:
- *
- *    u8  unsigned 8-bit integers
- *    s8  signed 8-bit integers
- *   u16  unsigned 16-bit integers
- *   s16  signed 16-bit integers
- *   u32  unsigned 32-bit integers
- *   s32  signed 32-bit integers
- *   u64  unsigned 64-bit integers
- *   s64  signed 64-bit integers
- *   f32  the C++ type float
- *   f64  the C++ type double
- *   c32  the C++ type complex
- *   c64  the C++ type complex
- * ------------------------------------------------------------------------
- * 
- */ - -//! true if \p x is any kind of uniform numeric vector -bool pmt_is_uniform_vector(pmt_t x); - -bool pmt_is_u8vector(pmt_t x); -bool pmt_is_s8vector(pmt_t x); -bool pmt_is_u16vector(pmt_t x); -bool pmt_is_s16vector(pmt_t x); -bool pmt_is_u32vector(pmt_t x); -bool pmt_is_s32vector(pmt_t x); -bool pmt_is_u64vector(pmt_t x); -bool pmt_is_s64vector(pmt_t x); -bool pmt_is_f32vector(pmt_t x); -bool pmt_is_f64vector(pmt_t x); -bool pmt_is_c32vector(pmt_t x); -bool pmt_is_c64vector(pmt_t x); - -pmt_t pmt_make_u8vector(size_t k, uint8_t fill); -pmt_t pmt_make_s8vector(size_t k, int8_t fill); -pmt_t pmt_make_u16vector(size_t k, uint16_t fill); -pmt_t pmt_make_s16vector(size_t k, int16_t fill); -pmt_t pmt_make_u32vector(size_t k, uint32_t fill); -pmt_t pmt_make_s32vector(size_t k, int32_t fill); -pmt_t pmt_make_u64vector(size_t k, uint64_t fill); -pmt_t pmt_make_s64vector(size_t k, int64_t fill); -pmt_t pmt_make_f32vector(size_t k, float fill); -pmt_t pmt_make_f64vector(size_t k, double fill); -pmt_t pmt_make_c32vector(size_t k, std::complex fill); -pmt_t pmt_make_c64vector(size_t k, std::complex fill); - -pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); -pmt_t pmt_init_s8vector(size_t k, const int8_t *data); -pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); -pmt_t pmt_init_s16vector(size_t k, const int16_t *data); -pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); -pmt_t pmt_init_s32vector(size_t k, const int32_t *data); -pmt_t pmt_init_f32vector(size_t k, const float *data); -pmt_t pmt_init_f64vector(size_t k, const double *data); -pmt_t pmt_init_c32vector(size_t k, const std::complex *data); -pmt_t pmt_init_c64vector(size_t k, const std::complex *data); - -uint8_t pmt_u8vector_ref(pmt_t v, size_t k); -int8_t pmt_s8vector_ref(pmt_t v, size_t k); -uint16_t pmt_u16vector_ref(pmt_t v, size_t k); -int16_t pmt_s16vector_ref(pmt_t v, size_t k); -uint32_t pmt_u32vector_ref(pmt_t v, size_t k); -int32_t pmt_s32vector_ref(pmt_t v, size_t k); -uint64_t pmt_u64vector_ref(pmt_t v, size_t k); -int64_t pmt_s64vector_ref(pmt_t v, size_t k); -float pmt_f32vector_ref(pmt_t v, size_t k); -double pmt_f64vector_ref(pmt_t v, size_t k); -std::complex pmt_c32vector_ref(pmt_t v, size_t k); -std::complex pmt_c64vector_ref(pmt_t v, size_t k); - -void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x); //< v[k] = x -void pmt_s8vector_set(pmt_t v, size_t k, int8_t x); -void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x); -void pmt_s16vector_set(pmt_t v, size_t k, int16_t x); -void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x); -void pmt_s32vector_set(pmt_t v, size_t k, int32_t x); -void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x); -void pmt_s64vector_set(pmt_t v, size_t k, int64_t x); -void pmt_f32vector_set(pmt_t v, size_t k, float x); -void pmt_f64vector_set(pmt_t v, size_t k, double x); -void pmt_c32vector_set(pmt_t v, size_t k, std::complex x); -void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); - -// Return const pointers to the elements - -const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements -const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements -const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements -const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements -const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements -const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements -const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements - -// Return non-const pointers to the elements - -void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements - -/* - * ------------------------------------------------------------------------ - * Dictionary (a.k.a associative array, hash, map) - * - * This is a functional data structure that is persistent. Updating a - * functional data structure does not destroy the existing version, but - * rather creates a new version that coexists with the old. - * ------------------------------------------------------------------------ - */ - -//! Return true if \p obj is a dictionary -bool pmt_is_dict(const pmt_t &obj); - -//! Make an empty dictionary -pmt_t pmt_make_dict(); - -//! Return a new dictionary with \p key associated with \p value. -pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value); - -//! Return a new dictionary with \p key removed. -pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key); - -//! Return true if \p key exists in \p dict -bool pmt_dict_has_key(const pmt_t &dict, const pmt_t &key); - -//! If \p key exists in \p dict, return associated value; otherwise return \p not_found. -pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found); - -//! Return list of (key . value) pairs -pmt_t pmt_dict_items(pmt_t dict); - -//! Return list of keys -pmt_t pmt_dict_keys(pmt_t dict); - -//! Return list of values -pmt_t pmt_dict_values(pmt_t dict); - -/* - * ------------------------------------------------------------------------ - * Any (wraps boost::any -- can be used to wrap pretty much anything) - * - * Cannot be serialized or used across process boundaries. - * See http://www.boost.org/doc/html/any.html - * ------------------------------------------------------------------------ - */ - -//! Return true if \p obj is an any -bool pmt_is_any(pmt_t obj); - -//! make an any -pmt_t pmt_make_any(const boost::any &any); - -//! Return underlying boost::any -boost::any pmt_any_ref(pmt_t obj); - -//! Store \p any in \p 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 - * ------------------------------------------------------------------------ - */ - -//! Return true if x and y are the same object; otherwise return false. -bool pmt_eq(const pmt_t& x, const pmt_t& y); - -/*! - * \brief Return true if x and y should normally be regarded as the same object, else false. - * - *
- * eqv returns true if:
- *   x and y are the same object.
- *   x and y are both \#t or both \#f.
- *   x and y are both symbols and their names are the same.
- *   x and y are both numbers, and are numerically equal.
- *   x and y are both the empty list (nil).
- *   x and y are pairs or vectors that denote same location in store.
- * 
- */ -bool pmt_eqv(const pmt_t& x, const pmt_t& y); - -/*! - * pmt_equal recursively compares the contents of pairs and vectors, - * applying pmt_eqv on other objects such as numbers and symbols. - * pmt_equal may fail to terminate if its arguments are circular data - * structures. - */ -bool pmt_equal(const pmt_t& x, const pmt_t& y); - - -//! Return the number of elements in v -size_t pmt_length(const pmt_t& v); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assq(pmt_t obj, pmt_t alist); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assv(pmt_t obj, pmt_t alist); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assoc(pmt_t obj, pmt_t alist); - -/*! - * \brief Apply \p proc element-wise to the elements of list and returns - * a list of the results, in order. - * - * \p list must be a list. The dynamic order in which \p proc is - * applied to the elements of \p list is unspecified. - */ -pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); - -/*! - * \brief reverse \p list. - * - * \p list must be a proper list. - */ -pmt_t pmt_reverse(pmt_t list); - -/*! - * \brief destructively reverse \p list. - * - * \p list must be a proper list. - */ -pmt_t pmt_reverse_x(pmt_t list); - -/*! - * \brief (acons x y a) == (cons (cons x y) a) - */ -inline static pmt_t -pmt_acons(pmt_t x, pmt_t y, pmt_t a) -{ - return pmt_cons(pmt_cons(x, y), a); -} - -/*! - * \brief locates \p nth element of \n list where the car is the 'zeroth' element. - */ -pmt_t pmt_nth(size_t n, pmt_t list); - -/*! - * \brief returns the tail of \p list that would be obtained by calling - * cdr \p n times in succession. - */ -pmt_t pmt_nthcdr(size_t n, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. - */ -pmt_t pmt_memq(pmt_t obj, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. - */ -pmt_t pmt_memv(pmt_t obj, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_member use pmt_equal to compare \p obj with the elements of \p list. - */ -pmt_t pmt_member(pmt_t obj, pmt_t list); - -/*! - * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. - * Comparisons are done with pmt_eqv. - */ -bool pmt_subsetp(pmt_t list1, pmt_t list2); - -/*! - * \brief Return a list of length 1 containing \p x1 - */ -pmt_t pmt_list1(const pmt_t& x1); - -/*! - * \brief Return a list of length 2 containing \p x1, \p x2 - */ -pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); - -/*! - * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 - */ -pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); - -/*! - * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 - */ -pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); - -/*! - * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 - */ -pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); - -/*! - * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p - * x5, \p x6 - */ -pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); - -/*! - * \brief Return \p list with \p item added to it. - */ -pmt_t pmt_list_add(pmt_t list, const pmt_t& item); - - -/* - * ------------------------------------------------------------------------ - * read / write - * ------------------------------------------------------------------------ - */ -extern const pmt_t PMT_EOF; //< The end of file object - -//! return true if obj is the EOF object, otherwise return false. -bool pmt_is_eof_object(pmt_t obj); - -/*! - * read converts external representations of pmt objects into the - * objects themselves. Read returns the next object parsable from - * the given input port, updating port to point to the first - * character past the end of the external representation of the - * object. - * - * If an end of file is encountered in the input before any - * characters are found that can begin an object, then an end of file - * object is returned. The port remains open, and further attempts - * to read will also return an end of file object. If an end of file - * is encountered after the beginning of an object's external - * representation, but the external representation is incomplete and - * therefore not parsable, an error is signaled. - */ -pmt_t pmt_read(std::istream &port); - -/*! - * Write a written representation of \p obj to the given \p port. - */ -void pmt_write(pmt_t obj, std::ostream &port); - -/*! - * Return a string representation of \p obj. - * This is the same output as would be generated by pmt_write. - */ -std::string pmt_write_string(pmt_t obj); - - -/*! - * \brief Write pmt string representation to stdout. - */ -void pmt_print(pmt_t v); - - -/* - * ------------------------------------------------------------------------ - * portable byte stream representation - * ------------------------------------------------------------------------ - */ -/*! - * \brief Write portable byte-serial representation of \p obj to \p sink - */ -bool pmt_serialize(pmt_t obj, std::streambuf &sink); - -/*! - * \brief Create obj from portable byte-serial representation - */ -pmt_t pmt_deserialize(std::streambuf &source); - - -void pmt_dump_sizeof(); // debugging - -/*! - * \brief Provide a simple string generating interface to pmt's serialize function - */ -std::string pmt_serialize_str(pmt_t obj); - -/*! - * \brief Provide a simple string generating interface to pmt's deserialize function - */ -pmt_t pmt_deserialize_str(std::string str); -- cgit From 4598466e739c458e4fc54724411634ad3867c75a Mon Sep 17 00:00:00 2001 From: tttx Date: Tue, 24 May 2011 15:21:39 -0400 Subject: fixing file tracking --- gruel/src/swig/pmt/pmt_swig.i | 761 ------------------------------------------ gruel/src/swig/pmt_swig.i | 761 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 761 insertions(+), 761 deletions(-) delete mode 100644 gruel/src/swig/pmt/pmt_swig.i create mode 100644 gruel/src/swig/pmt_swig.i (limited to 'gruel') diff --git a/gruel/src/swig/pmt/pmt_swig.i b/gruel/src/swig/pmt/pmt_swig.i deleted file mode 100644 index 3b0eb45c8..000000000 --- a/gruel/src/swig/pmt/pmt_swig.i +++ /dev/null @@ -1,761 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2011 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. - */ - -%module pmt -%include "std_string.i" -%include "stdint.i" -%{ -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace pmt; -%} - -// Template intrusive_ptr for Swig to avoid dereferencing issues -class pmt_base; -//%import -%import -%template(swig_int_ptr) boost::intrusive_ptr; - -typedef boost::intrusive_ptr pmt_t; - -/* - * ------------------------------------------------------------------------ - * Booleans. Two constants, #t and #f. - * - * In predicates, anything that is not #f is considered true. - * I.e., there is a single false value, #f. - * ------------------------------------------------------------------------ - */ -extern const pmt_t PMT_T; -extern const pmt_t PMT_F; - -//! Return true if obj is \#t or \#f, else return false. -bool pmt_is_bool(pmt_t obj); - -//! Return false if obj is \#f, else return true. -bool pmt_is_true(pmt_t obj); - -//! Return true if obj is \#f, else return true. -bool pmt_is_false(pmt_t obj); - -//! Return \#f is val is false, else return \#t. -pmt_t pmt_from_bool(bool val); - -//! Return true if val is PMT_T, return false when val is PMT_F, -// else raise wrong_type exception. -bool pmt_to_bool(pmt_t val); - -/* - * ------------------------------------------------------------------------ - * Symbols - * ------------------------------------------------------------------------ - */ - -//! Return true if obj is a symbol, else false. -bool pmt_is_symbol(const pmt_t& obj); - -//! Return the symbol whose name is \p s. -pmt_t pmt_string_to_symbol(const std::string &s); - -//! Alias for pmt_string_to_symbol -pmt_t pmt_intern(const std::string &s); - - -/*! - * If \p is a symbol, return the name of the symbol as a string. - * Otherwise, raise the wrong_type exception. - */ -const std::string pmt_symbol_to_string(const pmt_t& sym); - -/* - * ------------------------------------------------------------------------ - * Numbers: we support integer, real and complex - * ------------------------------------------------------------------------ - */ - -//! Return true if obj is any kind of number, else false. -bool pmt_is_number(pmt_t obj); - -/* - * ------------------------------------------------------------------------ - * Integers - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is an integer number, else false -bool pmt_is_integer(pmt_t x); - -//! Return the pmt value that represents the integer \p x. -pmt_t pmt_from_long(long x); - -/*! - * \brief Convert pmt to long if possible. - * - * When \p x represents an exact integer that fits in a long, - * return that integer. Else raise an exception, either wrong_type - * when x is not an exact integer, or out_of_range when it doesn't fit. - */ -long pmt_to_long(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * uint64_t - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is an uint64 number, else false -bool pmt_is_uint64(pmt_t x); - -//! Return the pmt value that represents the uint64 \p x. -pmt_t pmt_from_uint64(uint64_t x); - -/*! - * \brief Convert pmt to uint64 if possible. - * - * When \p x represents an exact integer that fits in a uint64, - * return that uint64. Else raise an exception, either wrong_type - * when x is not an exact uint64, or out_of_range when it doesn't fit. - */ -uint64_t pmt_to_uint64(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * Reals - * ------------------------------------------------------------------------ - */ - -/* - * \brief Return true if \p obj is a real number, else false. - */ -bool pmt_is_real(pmt_t obj); - -//! Return the pmt value that represents double \p x. -pmt_t pmt_from_double(double x); - -/*! - * \brief Convert pmt to double if possible. - * - * Returns the number closest to \p val that is representable - * as a double. The argument \p val must be a real or integer, otherwise - * a wrong_type exception is raised. - */ -double pmt_to_double(pmt_t x); - -/* - * ------------------------------------------------------------------------ - * Complex - * ------------------------------------------------------------------------ - */ - -/*! - * \brief return true if \p obj is a complex number, false otherwise. - */ -bool pmt_is_complex(pmt_t obj); - -//! Return a complex number constructed of the given real and imaginary parts. -pmt_t pmt_make_rectangular(double re, double im); - -/*! - * If \p z is complex, real or integer, return the closest complex. - * Otherwise, raise the wrong_type exception. - */ -std::complex pmt_to_complex(pmt_t z); - -/* - * ------------------------------------------------------------------------ - * Pairs - * ------------------------------------------------------------------------ - */ - -extern const pmt_t PMT_NIL; //< the empty list - -//! Return true if \p x is the empty list, otherwise return false. -bool pmt_is_null(const pmt_t& x); - -//! Return true if \p obj is a pair, else false. -bool pmt_is_pair(const pmt_t& obj); - -//! Return a newly allocated pair whose car is \p x and whose cdr is \p y. -pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); - -//! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. -pmt_t pmt_car(const pmt_t& pair); - -//! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. -pmt_t pmt_cdr(const pmt_t& pair); - -//! Stores \p value in the car field of \p pair. -void pmt_set_car(pmt_t pair, pmt_t value); - -//! Stores \p value in the cdr field of \p pair. -void pmt_set_cdr(pmt_t pair, pmt_t value); - -pmt_t pmt_caar(pmt_t pair); -pmt_t pmt_cadr(pmt_t pair); -pmt_t pmt_cdar(pmt_t pair); -pmt_t pmt_cddr(pmt_t pair); -pmt_t pmt_caddr(pmt_t pair); -pmt_t pmt_cadddr(pmt_t pair); - -/* - * ------------------------------------------------------------------------ - * Tuples - * - * Store a fixed number of objects. Tuples are not modifiable, and thus - * are excellent for use as messages. Indexing is zero based. - * Access time to an element is O(1). - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is a tuple, othewise false. -bool pmt_is_tuple(pmt_t x); - -pmt_t pmt_make_tuple(); -pmt_t pmt_make_tuple(const pmt_t &e0); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); - -/*! - * If \p x is a vector or proper list, return a tuple containing the elements of x - */ -pmt_t pmt_to_tuple(const pmt_t &x); - -/*! - * Return the contents of position \p k of \p tuple. - * \p k must be a valid index of \p tuple. - */ -pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); - -/* - * ------------------------------------------------------------------------ - * Vectors - * - * These vectors can hold any kind of objects. Indexing is zero based. - * ------------------------------------------------------------------------ - */ - -//! Return true if \p x is a vector, othewise false. -bool pmt_is_vector(pmt_t x); - -//! Make a vector of length \p k, with initial values set to \p fill -pmt_t pmt_make_vector(size_t k, pmt_t fill); - -/*! - * Return the contents of position \p k of \p vector. - * \p k must be a valid index of \p vector. - */ -pmt_t pmt_vector_ref(pmt_t vector, size_t k); - -//! Store \p obj in position \p k. -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); - -/*! - *
- * ------------------------------------------------------------------------
- *		       Uniform Numeric Vectors
- *
- * A uniform numeric vector is a vector whose elements are all of single
- * numeric type.  pmt offers uniform numeric vectors for signed and
- * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
- * floating point values, and complex floating-point numbers of these
- * two sizes.  Indexing is zero based.
- *
- * The names of the functions include these tags in their names:
- *
- *    u8  unsigned 8-bit integers
- *    s8  signed 8-bit integers
- *   u16  unsigned 16-bit integers
- *   s16  signed 16-bit integers
- *   u32  unsigned 32-bit integers
- *   s32  signed 32-bit integers
- *   u64  unsigned 64-bit integers
- *   s64  signed 64-bit integers
- *   f32  the C++ type float
- *   f64  the C++ type double
- *   c32  the C++ type complex
- *   c64  the C++ type complex
- * ------------------------------------------------------------------------
- * 
- */ - -//! true if \p x is any kind of uniform numeric vector -bool pmt_is_uniform_vector(pmt_t x); - -bool pmt_is_u8vector(pmt_t x); -bool pmt_is_s8vector(pmt_t x); -bool pmt_is_u16vector(pmt_t x); -bool pmt_is_s16vector(pmt_t x); -bool pmt_is_u32vector(pmt_t x); -bool pmt_is_s32vector(pmt_t x); -bool pmt_is_u64vector(pmt_t x); -bool pmt_is_s64vector(pmt_t x); -bool pmt_is_f32vector(pmt_t x); -bool pmt_is_f64vector(pmt_t x); -bool pmt_is_c32vector(pmt_t x); -bool pmt_is_c64vector(pmt_t x); - -pmt_t pmt_make_u8vector(size_t k, uint8_t fill); -pmt_t pmt_make_s8vector(size_t k, int8_t fill); -pmt_t pmt_make_u16vector(size_t k, uint16_t fill); -pmt_t pmt_make_s16vector(size_t k, int16_t fill); -pmt_t pmt_make_u32vector(size_t k, uint32_t fill); -pmt_t pmt_make_s32vector(size_t k, int32_t fill); -pmt_t pmt_make_u64vector(size_t k, uint64_t fill); -pmt_t pmt_make_s64vector(size_t k, int64_t fill); -pmt_t pmt_make_f32vector(size_t k, float fill); -pmt_t pmt_make_f64vector(size_t k, double fill); -pmt_t pmt_make_c32vector(size_t k, std::complex fill); -pmt_t pmt_make_c64vector(size_t k, std::complex fill); - -pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); -pmt_t pmt_init_s8vector(size_t k, const int8_t *data); -pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); -pmt_t pmt_init_s16vector(size_t k, const int16_t *data); -pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); -pmt_t pmt_init_s32vector(size_t k, const int32_t *data); -pmt_t pmt_init_f32vector(size_t k, const float *data); -pmt_t pmt_init_f64vector(size_t k, const double *data); -pmt_t pmt_init_c32vector(size_t k, const std::complex *data); -pmt_t pmt_init_c64vector(size_t k, const std::complex *data); - -uint8_t pmt_u8vector_ref(pmt_t v, size_t k); -int8_t pmt_s8vector_ref(pmt_t v, size_t k); -uint16_t pmt_u16vector_ref(pmt_t v, size_t k); -int16_t pmt_s16vector_ref(pmt_t v, size_t k); -uint32_t pmt_u32vector_ref(pmt_t v, size_t k); -int32_t pmt_s32vector_ref(pmt_t v, size_t k); -uint64_t pmt_u64vector_ref(pmt_t v, size_t k); -int64_t pmt_s64vector_ref(pmt_t v, size_t k); -float pmt_f32vector_ref(pmt_t v, size_t k); -double pmt_f64vector_ref(pmt_t v, size_t k); -std::complex pmt_c32vector_ref(pmt_t v, size_t k); -std::complex pmt_c64vector_ref(pmt_t v, size_t k); - -void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x); //< v[k] = x -void pmt_s8vector_set(pmt_t v, size_t k, int8_t x); -void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x); -void pmt_s16vector_set(pmt_t v, size_t k, int16_t x); -void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x); -void pmt_s32vector_set(pmt_t v, size_t k, int32_t x); -void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x); -void pmt_s64vector_set(pmt_t v, size_t k, int64_t x); -void pmt_f32vector_set(pmt_t v, size_t k, float x); -void pmt_f64vector_set(pmt_t v, size_t k, double x); -void pmt_c32vector_set(pmt_t v, size_t k, std::complex x); -void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); - -// Return const pointers to the elements - -const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements -const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements -const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements -const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements -const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements -const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements -const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements - -// Return non-const pointers to the elements - -void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements - -/* - * ------------------------------------------------------------------------ - * Dictionary (a.k.a associative array, hash, map) - * - * This is a functional data structure that is persistent. Updating a - * functional data structure does not destroy the existing version, but - * rather creates a new version that coexists with the old. - * ------------------------------------------------------------------------ - */ - -//! Return true if \p obj is a dictionary -bool pmt_is_dict(const pmt_t &obj); - -//! Make an empty dictionary -pmt_t pmt_make_dict(); - -//! Return a new dictionary with \p key associated with \p value. -pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value); - -//! Return a new dictionary with \p key removed. -pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key); - -//! Return true if \p key exists in \p dict -bool pmt_dict_has_key(const pmt_t &dict, const pmt_t &key); - -//! If \p key exists in \p dict, return associated value; otherwise return \p not_found. -pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found); - -//! Return list of (key . value) pairs -pmt_t pmt_dict_items(pmt_t dict); - -//! Return list of keys -pmt_t pmt_dict_keys(pmt_t dict); - -//! Return list of values -pmt_t pmt_dict_values(pmt_t dict); - -/* - * ------------------------------------------------------------------------ - * Any (wraps boost::any -- can be used to wrap pretty much anything) - * - * Cannot be serialized or used across process boundaries. - * See http://www.boost.org/doc/html/any.html - * ------------------------------------------------------------------------ - */ - -//! Return true if \p obj is an any -bool pmt_is_any(pmt_t obj); - -//! make an any -pmt_t pmt_make_any(const boost::any &any); - -//! Return underlying boost::any -boost::any pmt_any_ref(pmt_t obj); - -//! Store \p any in \p 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 - * ------------------------------------------------------------------------ - */ - -//! Return true if x and y are the same object; otherwise return false. -bool pmt_eq(const pmt_t& x, const pmt_t& y); - -/*! - * \brief Return true if x and y should normally be regarded as the same object, else false. - * - *
- * eqv returns true if:
- *   x and y are the same object.
- *   x and y are both \#t or both \#f.
- *   x and y are both symbols and their names are the same.
- *   x and y are both numbers, and are numerically equal.
- *   x and y are both the empty list (nil).
- *   x and y are pairs or vectors that denote same location in store.
- * 
- */ -bool pmt_eqv(const pmt_t& x, const pmt_t& y); - -/*! - * pmt_equal recursively compares the contents of pairs and vectors, - * applying pmt_eqv on other objects such as numbers and symbols. - * pmt_equal may fail to terminate if its arguments are circular data - * structures. - */ -bool pmt_equal(const pmt_t& x, const pmt_t& y); - - -//! Return the number of elements in v -size_t pmt_length(const pmt_t& v); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assq(pmt_t obj, pmt_t alist); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assv(pmt_t obj, pmt_t alist); - -/*! - * \brief Find the first pair in \p alist whose car field is \p obj - * and return that pair. - * - * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then \#f is returned. - * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. - */ -pmt_t pmt_assoc(pmt_t obj, pmt_t alist); - -/*! - * \brief Apply \p proc element-wise to the elements of list and returns - * a list of the results, in order. - * - * \p list must be a list. The dynamic order in which \p proc is - * applied to the elements of \p list is unspecified. - */ -pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); - -/*! - * \brief reverse \p list. - * - * \p list must be a proper list. - */ -pmt_t pmt_reverse(pmt_t list); - -/*! - * \brief destructively reverse \p list. - * - * \p list must be a proper list. - */ -pmt_t pmt_reverse_x(pmt_t list); - -/*! - * \brief (acons x y a) == (cons (cons x y) a) - */ -inline static pmt_t -pmt_acons(pmt_t x, pmt_t y, pmt_t a) -{ - return pmt_cons(pmt_cons(x, y), a); -} - -/*! - * \brief locates \p nth element of \n list where the car is the 'zeroth' element. - */ -pmt_t pmt_nth(size_t n, pmt_t list); - -/*! - * \brief returns the tail of \p list that would be obtained by calling - * cdr \p n times in succession. - */ -pmt_t pmt_nthcdr(size_t n, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. - */ -pmt_t pmt_memq(pmt_t obj, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. - */ -pmt_t pmt_memv(pmt_t obj, pmt_t list); - -/*! - * \brief Return the first sublist of \p list whose car is \p obj. - * If \p obj does not occur in \p list, then \#f is returned. - * pmt_member use pmt_equal to compare \p obj with the elements of \p list. - */ -pmt_t pmt_member(pmt_t obj, pmt_t list); - -/*! - * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. - * Comparisons are done with pmt_eqv. - */ -bool pmt_subsetp(pmt_t list1, pmt_t list2); - -/*! - * \brief Return a list of length 1 containing \p x1 - */ -pmt_t pmt_list1(const pmt_t& x1); - -/*! - * \brief Return a list of length 2 containing \p x1, \p x2 - */ -pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); - -/*! - * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 - */ -pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); - -/*! - * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 - */ -pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); - -/*! - * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 - */ -pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); - -/*! - * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p - * x5, \p x6 - */ -pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); - -/*! - * \brief Return \p list with \p item added to it. - */ -pmt_t pmt_list_add(pmt_t list, const pmt_t& item); - - -/* - * ------------------------------------------------------------------------ - * read / write - * ------------------------------------------------------------------------ - */ -extern const pmt_t PMT_EOF; //< The end of file object - -//! return true if obj is the EOF object, otherwise return false. -bool pmt_is_eof_object(pmt_t obj); - -/*! - * read converts external representations of pmt objects into the - * objects themselves. Read returns the next object parsable from - * the given input port, updating port to point to the first - * character past the end of the external representation of the - * object. - * - * If an end of file is encountered in the input before any - * characters are found that can begin an object, then an end of file - * object is returned. The port remains open, and further attempts - * to read will also return an end of file object. If an end of file - * is encountered after the beginning of an object's external - * representation, but the external representation is incomplete and - * therefore not parsable, an error is signaled. - */ -pmt_t pmt_read(std::istream &port); - -/*! - * Write a written representation of \p obj to the given \p port. - */ -void pmt_write(pmt_t obj, std::ostream &port); - -/*! - * Return a string representation of \p obj. - * This is the same output as would be generated by pmt_write. - */ -std::string pmt_write_string(pmt_t obj); - - -/*! - * \brief Write pmt string representation to stdout. - */ -void pmt_print(pmt_t v); - - -/* - * ------------------------------------------------------------------------ - * portable byte stream representation - * ------------------------------------------------------------------------ - */ -/*! - * \brief Write portable byte-serial representation of \p obj to \p sink - */ -bool pmt_serialize(pmt_t obj, std::streambuf &sink); - -/*! - * \brief Create obj from portable byte-serial representation - */ -pmt_t pmt_deserialize(std::streambuf &source); - - -void pmt_dump_sizeof(); // debugging - -/*! - * \brief Provide a simple string generating interface to pmt's serialize function - */ -std::string pmt_serialize_str(pmt_t obj); - -/*! - * \brief Provide a simple string generating interface to pmt's deserialize function - */ -pmt_t pmt_deserialize_str(std::string str); diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i new file mode 100644 index 000000000..3b0eb45c8 --- /dev/null +++ b/gruel/src/swig/pmt_swig.i @@ -0,0 +1,761 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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. + */ + +%module pmt +%include "std_string.i" +%include "stdint.i" +%{ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace pmt; +%} + +// Template intrusive_ptr for Swig to avoid dereferencing issues +class pmt_base; +//%import +%import +%template(swig_int_ptr) boost::intrusive_ptr; + +typedef boost::intrusive_ptr pmt_t; + +/* + * ------------------------------------------------------------------------ + * Booleans. Two constants, #t and #f. + * + * In predicates, anything that is not #f is considered true. + * I.e., there is a single false value, #f. + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_T; +extern const pmt_t PMT_F; + +//! Return true if obj is \#t or \#f, else return false. +bool pmt_is_bool(pmt_t obj); + +//! Return false if obj is \#f, else return true. +bool pmt_is_true(pmt_t obj); + +//! Return true if obj is \#f, else return true. +bool pmt_is_false(pmt_t obj); + +//! Return \#f is val is false, else return \#t. +pmt_t pmt_from_bool(bool val); + +//! Return true if val is PMT_T, return false when val is PMT_F, +// else raise wrong_type exception. +bool pmt_to_bool(pmt_t val); + +/* + * ------------------------------------------------------------------------ + * Symbols + * ------------------------------------------------------------------------ + */ + +//! Return true if obj is a symbol, else false. +bool pmt_is_symbol(const pmt_t& obj); + +//! Return the symbol whose name is \p s. +pmt_t pmt_string_to_symbol(const std::string &s); + +//! Alias for pmt_string_to_symbol +pmt_t pmt_intern(const std::string &s); + + +/*! + * If \p is a symbol, return the name of the symbol as a string. + * Otherwise, raise the wrong_type exception. + */ +const std::string pmt_symbol_to_string(const pmt_t& sym); + +/* + * ------------------------------------------------------------------------ + * Numbers: we support integer, real and complex + * ------------------------------------------------------------------------ + */ + +//! Return true if obj is any kind of number, else false. +bool pmt_is_number(pmt_t obj); + +/* + * ------------------------------------------------------------------------ + * Integers + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is an integer number, else false +bool pmt_is_integer(pmt_t x); + +//! Return the pmt value that represents the integer \p x. +pmt_t pmt_from_long(long x); + +/*! + * \brief Convert pmt to long if possible. + * + * When \p x represents an exact integer that fits in a long, + * return that integer. Else raise an exception, either wrong_type + * when x is not an exact integer, or out_of_range when it doesn't fit. + */ +long pmt_to_long(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * uint64_t + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is an uint64 number, else false +bool pmt_is_uint64(pmt_t x); + +//! Return the pmt value that represents the uint64 \p x. +pmt_t pmt_from_uint64(uint64_t x); + +/*! + * \brief Convert pmt to uint64 if possible. + * + * When \p x represents an exact integer that fits in a uint64, + * return that uint64. Else raise an exception, either wrong_type + * when x is not an exact uint64, or out_of_range when it doesn't fit. + */ +uint64_t pmt_to_uint64(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * Reals + * ------------------------------------------------------------------------ + */ + +/* + * \brief Return true if \p obj is a real number, else false. + */ +bool pmt_is_real(pmt_t obj); + +//! Return the pmt value that represents double \p x. +pmt_t pmt_from_double(double x); + +/*! + * \brief Convert pmt to double if possible. + * + * Returns the number closest to \p val that is representable + * as a double. The argument \p val must be a real or integer, otherwise + * a wrong_type exception is raised. + */ +double pmt_to_double(pmt_t x); + +/* + * ------------------------------------------------------------------------ + * Complex + * ------------------------------------------------------------------------ + */ + +/*! + * \brief return true if \p obj is a complex number, false otherwise. + */ +bool pmt_is_complex(pmt_t obj); + +//! Return a complex number constructed of the given real and imaginary parts. +pmt_t pmt_make_rectangular(double re, double im); + +/*! + * If \p z is complex, real or integer, return the closest complex. + * Otherwise, raise the wrong_type exception. + */ +std::complex pmt_to_complex(pmt_t z); + +/* + * ------------------------------------------------------------------------ + * Pairs + * ------------------------------------------------------------------------ + */ + +extern const pmt_t PMT_NIL; //< the empty list + +//! Return true if \p x is the empty list, otherwise return false. +bool pmt_is_null(const pmt_t& x); + +//! Return true if \p obj is a pair, else false. +bool pmt_is_pair(const pmt_t& obj); + +//! Return a newly allocated pair whose car is \p x and whose cdr is \p y. +pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); + +//! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. +pmt_t pmt_car(const pmt_t& pair); + +//! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. +pmt_t pmt_cdr(const pmt_t& pair); + +//! Stores \p value in the car field of \p pair. +void pmt_set_car(pmt_t pair, pmt_t value); + +//! Stores \p value in the cdr field of \p pair. +void pmt_set_cdr(pmt_t pair, pmt_t value); + +pmt_t pmt_caar(pmt_t pair); +pmt_t pmt_cadr(pmt_t pair); +pmt_t pmt_cdar(pmt_t pair); +pmt_t pmt_cddr(pmt_t pair); +pmt_t pmt_caddr(pmt_t pair); +pmt_t pmt_cadddr(pmt_t pair); + +/* + * ------------------------------------------------------------------------ + * Tuples + * + * Store a fixed number of objects. Tuples are not modifiable, and thus + * are excellent for use as messages. Indexing is zero based. + * Access time to an element is O(1). + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a tuple, othewise false. +bool pmt_is_tuple(pmt_t x); + +pmt_t pmt_make_tuple(); +pmt_t pmt_make_tuple(const pmt_t &e0); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); +pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); +pmt_t pmt_make_tuple(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); + +/*! + * If \p x is a vector or proper list, return a tuple containing the elements of x + */ +pmt_t pmt_to_tuple(const pmt_t &x); + +/*! + * Return the contents of position \p k of \p tuple. + * \p k must be a valid index of \p tuple. + */ +pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); + +/* + * ------------------------------------------------------------------------ + * Vectors + * + * These vectors can hold any kind of objects. Indexing is zero based. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p x is a vector, othewise false. +bool pmt_is_vector(pmt_t x); + +//! Make a vector of length \p k, with initial values set to \p fill +pmt_t pmt_make_vector(size_t k, pmt_t fill); + +/*! + * Return the contents of position \p k of \p vector. + * \p k must be a valid index of \p vector. + */ +pmt_t pmt_vector_ref(pmt_t vector, size_t k); + +//! Store \p obj in position \p k. +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); + +/*! + *
+ * ------------------------------------------------------------------------
+ *		       Uniform Numeric Vectors
+ *
+ * A uniform numeric vector is a vector whose elements are all of single
+ * numeric type.  pmt offers uniform numeric vectors for signed and
+ * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
+ * floating point values, and complex floating-point numbers of these
+ * two sizes.  Indexing is zero based.
+ *
+ * The names of the functions include these tags in their names:
+ *
+ *    u8  unsigned 8-bit integers
+ *    s8  signed 8-bit integers
+ *   u16  unsigned 16-bit integers
+ *   s16  signed 16-bit integers
+ *   u32  unsigned 32-bit integers
+ *   s32  signed 32-bit integers
+ *   u64  unsigned 64-bit integers
+ *   s64  signed 64-bit integers
+ *   f32  the C++ type float
+ *   f64  the C++ type double
+ *   c32  the C++ type complex
+ *   c64  the C++ type complex
+ * ------------------------------------------------------------------------
+ * 
+ */ + +//! true if \p x is any kind of uniform numeric vector +bool pmt_is_uniform_vector(pmt_t x); + +bool pmt_is_u8vector(pmt_t x); +bool pmt_is_s8vector(pmt_t x); +bool pmt_is_u16vector(pmt_t x); +bool pmt_is_s16vector(pmt_t x); +bool pmt_is_u32vector(pmt_t x); +bool pmt_is_s32vector(pmt_t x); +bool pmt_is_u64vector(pmt_t x); +bool pmt_is_s64vector(pmt_t x); +bool pmt_is_f32vector(pmt_t x); +bool pmt_is_f64vector(pmt_t x); +bool pmt_is_c32vector(pmt_t x); +bool pmt_is_c64vector(pmt_t x); + +pmt_t pmt_make_u8vector(size_t k, uint8_t fill); +pmt_t pmt_make_s8vector(size_t k, int8_t fill); +pmt_t pmt_make_u16vector(size_t k, uint16_t fill); +pmt_t pmt_make_s16vector(size_t k, int16_t fill); +pmt_t pmt_make_u32vector(size_t k, uint32_t fill); +pmt_t pmt_make_s32vector(size_t k, int32_t fill); +pmt_t pmt_make_u64vector(size_t k, uint64_t fill); +pmt_t pmt_make_s64vector(size_t k, int64_t fill); +pmt_t pmt_make_f32vector(size_t k, float fill); +pmt_t pmt_make_f64vector(size_t k, double fill); +pmt_t pmt_make_c32vector(size_t k, std::complex fill); +pmt_t pmt_make_c64vector(size_t k, std::complex fill); + +pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); +pmt_t pmt_init_s8vector(size_t k, const int8_t *data); +pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); +pmt_t pmt_init_s16vector(size_t k, const int16_t *data); +pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); +pmt_t pmt_init_s32vector(size_t k, const int32_t *data); +pmt_t pmt_init_f32vector(size_t k, const float *data); +pmt_t pmt_init_f64vector(size_t k, const double *data); +pmt_t pmt_init_c32vector(size_t k, const std::complex *data); +pmt_t pmt_init_c64vector(size_t k, const std::complex *data); + +uint8_t pmt_u8vector_ref(pmt_t v, size_t k); +int8_t pmt_s8vector_ref(pmt_t v, size_t k); +uint16_t pmt_u16vector_ref(pmt_t v, size_t k); +int16_t pmt_s16vector_ref(pmt_t v, size_t k); +uint32_t pmt_u32vector_ref(pmt_t v, size_t k); +int32_t pmt_s32vector_ref(pmt_t v, size_t k); +uint64_t pmt_u64vector_ref(pmt_t v, size_t k); +int64_t pmt_s64vector_ref(pmt_t v, size_t k); +float pmt_f32vector_ref(pmt_t v, size_t k); +double pmt_f64vector_ref(pmt_t v, size_t k); +std::complex pmt_c32vector_ref(pmt_t v, size_t k); +std::complex pmt_c64vector_ref(pmt_t v, size_t k); + +void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x); //< v[k] = x +void pmt_s8vector_set(pmt_t v, size_t k, int8_t x); +void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x); +void pmt_s16vector_set(pmt_t v, size_t k, int16_t x); +void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x); +void pmt_s32vector_set(pmt_t v, size_t k, int32_t x); +void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x); +void pmt_s64vector_set(pmt_t v, size_t k, int64_t x); +void pmt_f32vector_set(pmt_t v, size_t k, float x); +void pmt_f64vector_set(pmt_t v, size_t k, double x); +void pmt_c32vector_set(pmt_t v, size_t k, std::complex x); +void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); + +// Return const pointers to the elements + +const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements +const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements +const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements +const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements +const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements +const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements +const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements +const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements +const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements + +// Return non-const pointers to the elements + +void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements + +/* + * ------------------------------------------------------------------------ + * Dictionary (a.k.a associative array, hash, map) + * + * This is a functional data structure that is persistent. Updating a + * functional data structure does not destroy the existing version, but + * rather creates a new version that coexists with the old. + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is a dictionary +bool pmt_is_dict(const pmt_t &obj); + +//! Make an empty dictionary +pmt_t pmt_make_dict(); + +//! Return a new dictionary with \p key associated with \p value. +pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value); + +//! Return a new dictionary with \p key removed. +pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key); + +//! Return true if \p key exists in \p dict +bool pmt_dict_has_key(const pmt_t &dict, const pmt_t &key); + +//! If \p key exists in \p dict, return associated value; otherwise return \p not_found. +pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found); + +//! Return list of (key . value) pairs +pmt_t pmt_dict_items(pmt_t dict); + +//! Return list of keys +pmt_t pmt_dict_keys(pmt_t dict); + +//! Return list of values +pmt_t pmt_dict_values(pmt_t dict); + +/* + * ------------------------------------------------------------------------ + * Any (wraps boost::any -- can be used to wrap pretty much anything) + * + * Cannot be serialized or used across process boundaries. + * See http://www.boost.org/doc/html/any.html + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is an any +bool pmt_is_any(pmt_t obj); + +//! make an any +pmt_t pmt_make_any(const boost::any &any); + +//! Return underlying boost::any +boost::any pmt_any_ref(pmt_t obj); + +//! Store \p any in \p 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 + * ------------------------------------------------------------------------ + */ + +//! Return true if x and y are the same object; otherwise return false. +bool pmt_eq(const pmt_t& x, const pmt_t& y); + +/*! + * \brief Return true if x and y should normally be regarded as the same object, else false. + * + *
+ * eqv returns true if:
+ *   x and y are the same object.
+ *   x and y are both \#t or both \#f.
+ *   x and y are both symbols and their names are the same.
+ *   x and y are both numbers, and are numerically equal.
+ *   x and y are both the empty list (nil).
+ *   x and y are pairs or vectors that denote same location in store.
+ * 
+ */ +bool pmt_eqv(const pmt_t& x, const pmt_t& y); + +/*! + * pmt_equal recursively compares the contents of pairs and vectors, + * applying pmt_eqv on other objects such as numbers and symbols. + * pmt_equal may fail to terminate if its arguments are circular data + * structures. + */ +bool pmt_equal(const pmt_t& x, const pmt_t& y); + + +//! Return the number of elements in v +size_t pmt_length(const pmt_t& v); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assq(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assv(pmt_t obj, pmt_t alist); + +/*! + * \brief Find the first pair in \p alist whose car field is \p obj + * and return that pair. + * + * \p alist (for "association list") must be a list of pairs. If no pair + * in \p alist has \p obj as its car then \#f is returned. + * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. + */ +pmt_t pmt_assoc(pmt_t obj, pmt_t alist); + +/*! + * \brief Apply \p proc element-wise to the elements of list and returns + * a list of the results, in order. + * + * \p list must be a list. The dynamic order in which \p proc is + * applied to the elements of \p list is unspecified. + */ +pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); + +/*! + * \brief reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse(pmt_t list); + +/*! + * \brief destructively reverse \p list. + * + * \p list must be a proper list. + */ +pmt_t pmt_reverse_x(pmt_t list); + +/*! + * \brief (acons x y a) == (cons (cons x y) a) + */ +inline static pmt_t +pmt_acons(pmt_t x, pmt_t y, pmt_t a) +{ + return pmt_cons(pmt_cons(x, y), a); +} + +/*! + * \brief locates \p nth element of \n list where the car is the 'zeroth' element. + */ +pmt_t pmt_nth(size_t n, pmt_t list); + +/*! + * \brief returns the tail of \p list that would be obtained by calling + * cdr \p n times in succession. + */ +pmt_t pmt_nthcdr(size_t n, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memq(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memv(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_member use pmt_equal to compare \p obj with the elements of \p list. + */ +pmt_t pmt_member(pmt_t obj, pmt_t list); + +/*! + * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. + * Comparisons are done with pmt_eqv. + */ +bool pmt_subsetp(pmt_t list1, pmt_t list2); + +/*! + * \brief Return a list of length 1 containing \p x1 + */ +pmt_t pmt_list1(const pmt_t& x1); + +/*! + * \brief Return a list of length 2 containing \p x1, \p x2 + */ +pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); + +/*! + * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 + */ +pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); + +/*! + * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 + */ +pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); + +/*! + * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 + */ +pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); + +/*! + * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p + * x5, \p x6 + */ +pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); + +/*! + * \brief Return \p list with \p item added to it. + */ +pmt_t pmt_list_add(pmt_t list, const pmt_t& item); + + +/* + * ------------------------------------------------------------------------ + * read / write + * ------------------------------------------------------------------------ + */ +extern const pmt_t PMT_EOF; //< The end of file object + +//! return true if obj is the EOF object, otherwise return false. +bool pmt_is_eof_object(pmt_t obj); + +/*! + * read converts external representations of pmt objects into the + * objects themselves. Read returns the next object parsable from + * the given input port, updating port to point to the first + * character past the end of the external representation of the + * object. + * + * If an end of file is encountered in the input before any + * characters are found that can begin an object, then an end of file + * object is returned. The port remains open, and further attempts + * to read will also return an end of file object. If an end of file + * is encountered after the beginning of an object's external + * representation, but the external representation is incomplete and + * therefore not parsable, an error is signaled. + */ +pmt_t pmt_read(std::istream &port); + +/*! + * Write a written representation of \p obj to the given \p port. + */ +void pmt_write(pmt_t obj, std::ostream &port); + +/*! + * Return a string representation of \p obj. + * This is the same output as would be generated by pmt_write. + */ +std::string pmt_write_string(pmt_t obj); + + +/*! + * \brief Write pmt string representation to stdout. + */ +void pmt_print(pmt_t v); + + +/* + * ------------------------------------------------------------------------ + * portable byte stream representation + * ------------------------------------------------------------------------ + */ +/*! + * \brief Write portable byte-serial representation of \p obj to \p sink + */ +bool pmt_serialize(pmt_t obj, std::streambuf &sink); + +/*! + * \brief Create obj from portable byte-serial representation + */ +pmt_t pmt_deserialize(std::streambuf &source); + + +void pmt_dump_sizeof(); // debugging + +/*! + * \brief Provide a simple string generating interface to pmt's serialize function + */ +std::string pmt_serialize_str(pmt_t obj); + +/*! + * \brief Provide a simple string generating interface to pmt's deserialize function + */ +pmt_t pmt_deserialize_str(std::string str); -- cgit From ee852007b1c0dbeeed6edeb9d5b8b07fed13df91 Mon Sep 17 00:00:00 2001 From: tttx Date: Tue, 24 May 2011 15:22:13 -0400 Subject: update python installed files --- gruel/src/python/Makefile.am | 4 ++++ gruel/src/python/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/python/Makefile.am b/gruel/src/python/Makefile.am index 5a45510d5..80cb04b24 100644 --- a/gruel/src/python/Makefile.am +++ b/gruel/src/python/Makefile.am @@ -35,5 +35,9 @@ noinst_PYTHON = \ gruel_PYTHON = \ __init__.py +gruelpmtdir = $(pythondir)/gruel/pmt + +gruelpmt_PYTHON = pmt/__init__.py + endif diff --git a/gruel/src/python/__init__.py b/gruel/src/python/__init__.py index 421a9aaa8..14014cc5a 100644 --- a/gruel/src/python/__init__.py +++ b/gruel/src/python/__init__.py @@ -21,5 +21,5 @@ # The presence of this file turns this directory into a Python package -from pmt_swig import * +import pmt; -- cgit From b8a8ed2c47556986f1f76abcfc8e6948c5053505 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 7 Jun 2011 22:27:02 -0400 Subject: gruel: adding high resolution timer to gruel --- gruel/src/include/gruel/Makefile.am | 1 + gruel/src/include/gruel/high_res_timer.h | 124 +++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 gruel/src/include/gruel/high_res_timer.h (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 89a9da7f0..96aed326e 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -27,6 +27,7 @@ gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ attributes.h \ + high_res_timer.h \ inet.h \ msg_accepter.h \ msg_accepter_msgq.h \ diff --git a/gruel/src/include/gruel/high_res_timer.h b/gruel/src/include/gruel/high_res_timer.h new file mode 100644 index 000000000..fe9ae763f --- /dev/null +++ b/gruel/src/include/gruel/high_res_timer.h @@ -0,0 +1,124 @@ +/* + * Copyright 2011 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_HIGH_RES_TIMER_H +#define INCLUDED_GRUEL_HIGH_RES_TIMER_H + +namespace gruel { + //! Typedef for the timer tick count + typedef signed long long high_res_timer_type; + + //! Get the current time in ticks + high_res_timer_type high_res_timer_now(void); + + //! Get the number of ticks per second + high_res_timer_type high_res_timer_tps(void); + + //! Get the tick count at the epoch + high_res_timer_type high_res_timer_epoch(void); + +} /* namespace gruel */ + +//////////////////////////////////////////////////////////////////////// +// Use architecture defines to determine the implementation +//////////////////////////////////////////////////////////////////////// +#if defined(linux) || defined(__linux) || defined(__linux__) + #define GRUEL_HRT_USE_CLOCK_GETTIME +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) + #define GRUEL_HRT_USE_QUERY_PERFORMANCE_COUNTER +#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) + #define GRUEL_HRT_USE_MACH_ABSOLUTE_TIME +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) + #define GRUEL_HRT_USE_MACH_ABSOLUTE_TIME +#else + #define GRUEL_HRT_USE_MICROSEC_CLOCK +#endif + +//////////////////////////////////////////////////////////////////////// +#ifdef GRUEL_HRT_USE_CLOCK_GETTIME + #include + + inline gruel::high_res_timer_type gruel::high_res_timer_now(void){ + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return high_res_timer_type(ts.tv_sec*1000000000UL) + ts.tv_nsec; + } + + inline gruel::high_res_timer_type gruel::high_res_timer_tps(void){ + return 1000000000UL; + } +#endif /* GRUEL_HRT_USE_CLOCK_GETTIME */ + +//////////////////////////////////////////////////////////////////////// +#ifdef GRUEL_HRT_USE_MACH_ABSOLUTE_TIME + #include + + inline gruel::high_res_timer_type gruel::high_res_timer_now(void){ + return mach_absolute_time(); + } + + inline gruel::high_res_timer_type gruel::high_res_timer_tps(void){ + mach_timebase_info_data_t info; + mach_timebase_info(&info); + return gruel::high_res_timer_type(info.numer*1000000000UL)/info.denom; + } +#endif + +//////////////////////////////////////////////////////////////////////// +#ifdef GRUEL_HRT_USE_QUERY_PERFORMANCE_COUNTER + #include + + inline gruel::high_res_timer_type gruel::high_res_timer_now(void){ + LARGE_INTEGER counts; + QueryPerformanceCounter(&counts); + return counts.QuadPart; + } + + inline gruel::high_res_timer_type gruel::high_res_timer_tps(void){ + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + return freq.QuadPart; + } +#endif + +//////////////////////////////////////////////////////////////////////// +#ifdef GRUEL_HRT_USE_MICROSEC_CLOCK + #include + + inline gruel::high_res_timer_type gruel::high_res_timer_now(void){ + static const boost::posix_time::ptime epoch(boost::posix_time::from_time_t(0)); + return (boost::posix_time::microsec_clock::universal_time() - epoch).ticks(); + } + + inline gruel::high_res_timer_type gruel::high_res_timer_tps(void){ + return boost::posix_time::time_duration::ticks_per_second(); + } +#endif + +//////////////////////////////////////////////////////////////////////// +#include + +inline gruel::high_res_timer_type gruel::high_res_timer_epoch(void){ + static const double hrt_ticks_per_utc_ticks = gruel::high_res_timer_tps()/double(boost::posix_time::time_duration::ticks_per_second()); + boost::posix_time::time_duration utc = boost::posix_time::microsec_clock::universal_time() - boost::posix_time::from_time_t(0); + return gruel::high_res_timer_now() - utc.ticks()*hrt_ticks_per_utc_ticks; +} + +#endif /* INCLUDED_GRUEL_HIGH_RES_TIMER_H */ -- cgit From f6fedf278c08fb0083808c6baf42ba2972a43ef1 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 3 Jul 2011 11:35:55 -0700 Subject: gr: added to the .gitignores to various components for in-tree builds --- gruel/src/python/.gitignore | 1 + gruel/src/swig/.gitignore | 2 ++ 2 files changed, 3 insertions(+) (limited to 'gruel') diff --git a/gruel/src/python/.gitignore b/gruel/src/python/.gitignore index b336cc7ce..604b402c5 100644 --- a/gruel/src/python/.gitignore +++ b/gruel/src/python/.gitignore @@ -1,2 +1,3 @@ /Makefile /Makefile.in +/run_tests diff --git a/gruel/src/swig/.gitignore b/gruel/src/swig/.gitignore index b336cc7ce..f99fdb19b 100644 --- a/gruel/src/swig/.gitignore +++ b/gruel/src/swig/.gitignore @@ -1,2 +1,4 @@ /Makefile /Makefile.in +/python +/pmt_swig.py -- cgit From 2ed243a36f9f19d10a552a350f856726e8e64b30 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 12:20:40 -0700 Subject: gr: replaced uses of snprintf with boost format in common code build by MSVC --- gruel/src/lib/pmt/qa_pmt_prims.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 985361f13..7dec30d56 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 #include @@ -54,9 +55,8 @@ qa_pmt_prims::test_symbols() // generate a bunch of symbols for (int i = 0; i < N; i++){ - char buf[100]; - snprintf(buf, sizeof(buf), "test-%d", i); - v1[i] = mp(buf); + std::string buf = str(boost::format("test-%d") % i); + v1[i] = mp(buf.c_str()); } // confirm that they are all unique @@ -66,9 +66,8 @@ qa_pmt_prims::test_symbols() // generate the same symbols again for (int i = 0; i < N; i++){ - char buf[100]; - snprintf(buf, sizeof(buf), "test-%d", i); - v2[i] = mp(buf); + std::string buf = str(boost::format("test-%d") % i); + v2[i] = mp(buf.c_str()); } // confirm that we get the same ones back -- cgit From 947ae1cf5c16f5b3c6222b6ee9ad1a3b4075dd25 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 17:55:28 -0700 Subject: gruel: API declaration macros for gruel class and function symbols --- gruel/src/include/gruel/Makefile.am | 1 + gruel/src/include/gruel/api.h | 33 ++ gruel/src/include/gruel/attributes.h | 11 + gruel/src/include/gruel/inet.h.in | 1 + gruel/src/include/gruel/msg_accepter.h | 3 +- gruel/src/include/gruel/msg_accepter_msgq.h | 3 +- gruel/src/include/gruel/msg_passing.h | 1 + gruel/src/include/gruel/msg_queue.h | 3 +- gruel/src/include/gruel/pmt.h | 425 +++++++++++++------------- gruel/src/include/gruel/pmt_pool.h | 5 +- gruel/src/include/gruel/realtime.h | 5 +- gruel/src/include/gruel/sys_pri.h | 3 +- gruel/src/include/gruel/thread.h | 1 + gruel/src/include/gruel/thread_body_wrapper.h | 3 +- gruel/src/include/gruel/thread_group.h | 3 +- gruel/src/lib/Makefile.am | 2 +- gruel/src/lib/pmt/pmt_int.h | 2 +- gruel/src/lib/pmt/qa_pmt.h | 3 +- gruel/src/lib/pmt/qa_pmt_prims.h | 4 +- 19 files changed, 286 insertions(+), 226 deletions(-) create mode 100644 gruel/src/include/gruel/api.h (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 96aed326e..fce739f08 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -26,6 +26,7 @@ EXTRA_DIST += inet.h.in gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ + api.h \ attributes.h \ high_res_timer.h \ inet.h \ diff --git a/gruel/src/include/gruel/api.h b/gruel/src/include/gruel/api.h new file mode 100644 index 000000000..945814d43 --- /dev/null +++ b/gruel/src/include/gruel/api.h @@ -0,0 +1,33 @@ +/* + * Copyright 2010 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. + */ + +#ifndef INCLUDED_GRUEL_API_H +#define INCLUDED_GRUEL_API_H + +#include + +#ifdef gruel_EXPORTS +# define GRUEL_API __GR_ATTR_EXPORT +#else +# define GRUEL_API __GR_ATTR_IMPORT +#endif + +#endif /* INCLUDED_GRUEL_API_H */ diff --git a/gruel/src/include/gruel/attributes.h b/gruel/src/include/gruel/attributes.h index fdf48c977..8c9a57b47 100644 --- a/gruel/src/include/gruel/attributes.h +++ b/gruel/src/include/gruel/attributes.h @@ -53,4 +53,15 @@ # define __GR_ATTR_IMPORT #endif +//////////////////////////////////////////////////////////////////////// +// suppress warnings +//////////////////////////////////////////////////////////////////////// +#ifdef _MSC_VER +# pragma warning(disable: 4251) // class 'A' needs to have dll-interface to be used by clients of class 'B' +# pragma warning(disable: 4275) // non dll-interface class ... used as base for dll-interface class ... +# pragma warning(disable: 4244) // conversion from 'double' to 'float', possible loss of data +# pragma warning(disable: 4305) // 'initializing' : truncation from 'double' to 'float' +# pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + #endif /* INCLUDED_GRUEL_ATTRIBUTES_H */ diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in index 7ac01eb56..8545aeea9 100644 --- a/gruel/src/include/gruel/inet.h.in +++ b/gruel/src/include/gruel/inet.h.in @@ -19,6 +19,7 @@ #ifndef INCLUDED_INET_H #define INCLUDED_INET_H +#include #include #if 1 /* missing htonll or ntohll */ diff --git a/gruel/src/include/gruel/msg_accepter.h b/gruel/src/include/gruel/msg_accepter.h index 70ac846f5..3dfc8bcf8 100644 --- a/gruel/src/include/gruel/msg_accepter.h +++ b/gruel/src/include/gruel/msg_accepter.h @@ -21,6 +21,7 @@ #ifndef INCLUDED_GRUEL_MSG_ACCEPTER_H #define INCLUDED_GRUEL_MSG_ACCEPTER_H +#include #include #include @@ -29,7 +30,7 @@ namespace gruel { /*! * \brief Virtual base class that accepts messages */ - class msg_accepter + class GRUEL_API msg_accepter { public: msg_accepter() {}; diff --git a/gruel/src/include/gruel/msg_accepter_msgq.h b/gruel/src/include/gruel/msg_accepter_msgq.h index bf1762e92..22a1855cf 100644 --- a/gruel/src/include/gruel/msg_accepter_msgq.h +++ b/gruel/src/include/gruel/msg_accepter_msgq.h @@ -22,6 +22,7 @@ #ifndef INCLUDED_MSG_ACCEPTER_MSGQ_H #define INCLUDED_MSG_ACCEPTER_MSGQ_H +#include #include #include @@ -30,7 +31,7 @@ namespace gruel { /*! * \brief Concrete class that accepts messages and inserts them into a message queue. */ - class msg_accepter_msgq : public msg_accepter + class GRUEL_API msg_accepter_msgq : public msg_accepter { protected: msg_queue_sptr d_msg_queue; diff --git a/gruel/src/include/gruel/msg_passing.h b/gruel/src/include/gruel/msg_passing.h index ebbeca815..51268967a 100644 --- a/gruel/src/include/gruel/msg_passing.h +++ b/gruel/src/include/gruel/msg_passing.h @@ -25,6 +25,7 @@ * \brief Include this header to use the message passing features */ +#include #include #include diff --git a/gruel/src/include/gruel/msg_queue.h b/gruel/src/include/gruel/msg_queue.h index c24313df6..8608842da 100644 --- a/gruel/src/include/gruel/msg_queue.h +++ b/gruel/src/include/gruel/msg_queue.h @@ -22,6 +22,7 @@ #ifndef INCLUDED_MSG_QUEUE_H #define INCLUDED_MSG_QUEUE_H +#include #include #include #include @@ -36,7 +37,7 @@ namespace gruel { /*! * \brief thread-safe message queue */ - class msg_queue { + class GRUEL_API msg_queue { gruel::mutex d_mutex; gruel::condition_variable d_not_empty; diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 2948abb39..58533e54e 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_PMT_H #define INCLUDED_PMT_H +#include #include #include #include @@ -57,28 +58,28 @@ class pmt_base; */ typedef boost::intrusive_ptr pmt_t; -extern void intrusive_ptr_add_ref(pmt_base*); -extern void intrusive_ptr_release(pmt_base*); +extern GRUEL_API void intrusive_ptr_add_ref(pmt_base*); +extern GRUEL_API void intrusive_ptr_release(pmt_base*); -class pmt_exception : public std::logic_error +class GRUEL_API pmt_exception : public std::logic_error { public: pmt_exception(const std::string &msg, pmt_t obj); }; -class pmt_wrong_type : public pmt_exception +class GRUEL_API pmt_wrong_type : public pmt_exception { public: pmt_wrong_type(const std::string &msg, pmt_t obj); }; -class pmt_out_of_range : public pmt_exception +class GRUEL_API pmt_out_of_range : public pmt_exception { public: pmt_out_of_range(const std::string &msg, pmt_t obj); }; -class pmt_notimplemented : public pmt_exception +class GRUEL_API pmt_notimplemented : public pmt_exception { public: pmt_notimplemented(const std::string &msg, pmt_t obj); @@ -92,24 +93,24 @@ public: * I.e., there is a single false value, #f. * ------------------------------------------------------------------------ */ -extern const pmt_t PMT_T; //< \#t : boolean true constant -extern const pmt_t PMT_F; //< \#f : boolean false constant +extern GRUEL_API const pmt_t PMT_T; //< \#t : boolean true constant +extern GRUEL_API const pmt_t PMT_F; //< \#f : boolean false constant //! Return true if obj is \#t or \#f, else return false. -bool pmt_is_bool(pmt_t obj); +GRUEL_API bool pmt_is_bool(pmt_t obj); //! Return false if obj is \#f, else return true. -bool pmt_is_true(pmt_t obj); +GRUEL_API bool pmt_is_true(pmt_t obj); //! Return true if obj is \#f, else return true. -bool pmt_is_false(pmt_t obj); +GRUEL_API bool pmt_is_false(pmt_t obj); //! Return \#f is val is false, else return \#t. -pmt_t pmt_from_bool(bool val); +GRUEL_API pmt_t pmt_from_bool(bool val); //! Return true if val is PMT_T, return false when val is PMT_F, // else raise wrong_type exception. -bool pmt_to_bool(pmt_t val); +GRUEL_API bool pmt_to_bool(pmt_t val); /* * ------------------------------------------------------------------------ @@ -118,20 +119,20 @@ bool pmt_to_bool(pmt_t val); */ //! Return true if obj is a symbol, else false. -bool pmt_is_symbol(const pmt_t& obj); +GRUEL_API bool pmt_is_symbol(const pmt_t& obj); //! Return the symbol whose name is \p s. -pmt_t pmt_string_to_symbol(const std::string &s); +GRUEL_API pmt_t pmt_string_to_symbol(const std::string &s); //! Alias for pmt_string_to_symbol -pmt_t pmt_intern(const std::string &s); +GRUEL_API pmt_t pmt_intern(const std::string &s); /*! * If \p is a symbol, return the name of the symbol as a string. * Otherwise, raise the wrong_type exception. */ -const std::string pmt_symbol_to_string(const pmt_t& sym); +GRUEL_API const std::string pmt_symbol_to_string(const pmt_t& sym); /* * ------------------------------------------------------------------------ @@ -140,7 +141,7 @@ const std::string pmt_symbol_to_string(const pmt_t& sym); */ //! Return true if obj is any kind of number, else false. -bool pmt_is_number(pmt_t obj); +GRUEL_API bool pmt_is_number(pmt_t obj); /* * ------------------------------------------------------------------------ @@ -149,10 +150,10 @@ bool pmt_is_number(pmt_t obj); */ //! Return true if \p x is an integer number, else false -bool pmt_is_integer(pmt_t x); +GRUEL_API bool pmt_is_integer(pmt_t x); //! Return the pmt value that represents the integer \p x. -pmt_t pmt_from_long(long x); +GRUEL_API pmt_t pmt_from_long(long x); /*! * \brief Convert pmt to long if possible. @@ -161,7 +162,7 @@ pmt_t pmt_from_long(long x); * return that integer. Else raise an exception, either wrong_type * when x is not an exact integer, or out_of_range when it doesn't fit. */ -long pmt_to_long(pmt_t x); +GRUEL_API long pmt_to_long(pmt_t x); /* * ------------------------------------------------------------------------ @@ -170,10 +171,10 @@ long pmt_to_long(pmt_t x); */ //! Return true if \p x is an uint64 number, else false -bool pmt_is_uint64(pmt_t x); +GRUEL_API bool pmt_is_uint64(pmt_t x); //! Return the pmt value that represents the uint64 \p x. -pmt_t pmt_from_uint64(uint64_t x); +GRUEL_API pmt_t pmt_from_uint64(uint64_t x); /*! * \brief Convert pmt to uint64 if possible. @@ -182,7 +183,7 @@ pmt_t pmt_from_uint64(uint64_t x); * return that uint64. Else raise an exception, either wrong_type * when x is not an exact uint64, or out_of_range when it doesn't fit. */ -uint64_t pmt_to_uint64(pmt_t x); +GRUEL_API uint64_t pmt_to_uint64(pmt_t x); /* * ------------------------------------------------------------------------ @@ -193,10 +194,10 @@ uint64_t pmt_to_uint64(pmt_t x); /* * \brief Return true if \p obj is a real number, else false. */ -bool pmt_is_real(pmt_t obj); +GRUEL_API bool pmt_is_real(pmt_t obj); //! Return the pmt value that represents double \p x. -pmt_t pmt_from_double(double x); +GRUEL_API pmt_t pmt_from_double(double x); /*! * \brief Convert pmt to double if possible. @@ -205,7 +206,7 @@ pmt_t pmt_from_double(double x); * as a double. The argument \p val must be a real or integer, otherwise * a wrong_type exception is raised. */ -double pmt_to_double(pmt_t x); +GRUEL_API double pmt_to_double(pmt_t x); /* * ------------------------------------------------------------------------ @@ -216,16 +217,16 @@ double pmt_to_double(pmt_t x); /*! * \brief return true if \p obj is a complex number, false otherwise. */ -bool pmt_is_complex(pmt_t obj); +GRUEL_API bool pmt_is_complex(pmt_t obj); //! Return a complex number constructed of the given real and imaginary parts. -pmt_t pmt_make_rectangular(double re, double im); +GRUEL_API pmt_t pmt_make_rectangular(double re, double im); /*! * If \p z is complex, real or integer, return the closest complex. * Otherwise, raise the wrong_type exception. */ -std::complex pmt_to_complex(pmt_t z); +GRUEL_API std::complex pmt_to_complex(pmt_t z); /* * ------------------------------------------------------------------------ @@ -233,35 +234,35 @@ std::complex pmt_to_complex(pmt_t z); * ------------------------------------------------------------------------ */ -extern const pmt_t PMT_NIL; //< the empty list +extern GRUEL_API const pmt_t PMT_NIL; //< the empty list //! Return true if \p x is the empty list, otherwise return false. -bool pmt_is_null(const pmt_t& x); +GRUEL_API bool pmt_is_null(const pmt_t& x); //! Return true if \p obj is a pair, else false. -bool pmt_is_pair(const pmt_t& obj); +GRUEL_API bool pmt_is_pair(const pmt_t& obj); //! Return a newly allocated pair whose car is \p x and whose cdr is \p y. -pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); +GRUEL_API pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); //! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. -pmt_t pmt_car(const pmt_t& pair); +GRUEL_API pmt_t pmt_car(const pmt_t& pair); //! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. -pmt_t pmt_cdr(const pmt_t& pair); +GRUEL_API pmt_t pmt_cdr(const pmt_t& pair); //! Stores \p value in the car field of \p pair. -void pmt_set_car(pmt_t pair, pmt_t value); +GRUEL_API void pmt_set_car(pmt_t pair, pmt_t value); //! Stores \p value in the cdr field of \p pair. -void pmt_set_cdr(pmt_t pair, pmt_t value); +GRUEL_API void pmt_set_cdr(pmt_t pair, pmt_t value); -pmt_t pmt_caar(pmt_t pair); -pmt_t pmt_cadr(pmt_t pair); -pmt_t pmt_cdar(pmt_t pair); -pmt_t pmt_cddr(pmt_t pair); -pmt_t pmt_caddr(pmt_t pair); -pmt_t pmt_cadddr(pmt_t pair); +GRUEL_API pmt_t pmt_caar(pmt_t pair); +GRUEL_API pmt_t pmt_cadr(pmt_t pair); +GRUEL_API pmt_t pmt_cdar(pmt_t pair); +GRUEL_API pmt_t pmt_cddr(pmt_t pair); +GRUEL_API pmt_t pmt_caddr(pmt_t pair); +GRUEL_API pmt_t pmt_cadddr(pmt_t pair); /* * ------------------------------------------------------------------------ @@ -274,30 +275,30 @@ pmt_t pmt_cadddr(pmt_t pair); */ //! Return true if \p x is a tuple, othewise false. -bool pmt_is_tuple(pmt_t x); +GRUEL_API bool pmt_is_tuple(pmt_t x); -pmt_t pmt_make_tuple(); -pmt_t pmt_make_tuple(const pmt_t &e0); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); -pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); -pmt_t pmt_make_tuple(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); +GRUEL_API pmt_t pmt_make_tuple(); +GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0); +GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1); +GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2); +GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3); +GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4); +GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5); +GRUEL_API pmt_t pmt_make_tuple(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); +GRUEL_API pmt_t pmt_make_tuple(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); +GRUEL_API pmt_t pmt_make_tuple(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); +GRUEL_API pmt_t pmt_make_tuple(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); /*! * If \p x is a vector or proper list, return a tuple containing the elements of x */ -pmt_t pmt_to_tuple(const pmt_t &x); +GRUEL_API pmt_t pmt_to_tuple(const pmt_t &x); /*! * Return the contents of position \p k of \p tuple. * \p k must be a valid index of \p tuple. */ -pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); +GRUEL_API pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); /* * ------------------------------------------------------------------------ @@ -308,22 +309,22 @@ pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k); */ //! Return true if \p x is a vector, othewise false. -bool pmt_is_vector(pmt_t x); +GRUEL_API bool pmt_is_vector(pmt_t x); //! Make a vector of length \p k, with initial values set to \p fill -pmt_t pmt_make_vector(size_t k, pmt_t fill); +GRUEL_API pmt_t pmt_make_vector(size_t k, pmt_t fill); /*! * Return the contents of position \p k of \p vector. * \p k must be a valid index of \p vector. */ -pmt_t pmt_vector_ref(pmt_t vector, size_t k); +GRUEL_API pmt_t pmt_vector_ref(pmt_t vector, size_t k); //! Store \p obj in position \p k. -void pmt_vector_set(pmt_t vector, size_t k, pmt_t obj); +GRUEL_API 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); +GRUEL_API void pmt_vector_fill(pmt_t vector, pmt_t fill); /* * ------------------------------------------------------------------------ @@ -334,7 +335,7 @@ void pmt_vector_fill(pmt_t vector, pmt_t fill); */ //! Return true if \p x is a blob, othewise false. -bool pmt_is_blob(pmt_t x); +GRUEL_API bool pmt_is_blob(pmt_t x); /*! * \brief Make a blob given a pointer and length in bytes @@ -344,13 +345,13 @@ bool pmt_is_blob(pmt_t x); * * The data is copied into the blob. */ -pmt_t pmt_make_blob(const void *buf, size_t len); +GRUEL_API 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); +GRUEL_API const void *pmt_blob_data(pmt_t blob); //! Return the blob's length in bytes -size_t pmt_blob_length(pmt_t blob); +GRUEL_API size_t pmt_blob_length(pmt_t blob); /*! *
@@ -382,106 +383,106 @@ size_t pmt_blob_length(pmt_t blob);
  */
 
 //! true if \p x is any kind of uniform numeric vector
-bool pmt_is_uniform_vector(pmt_t x);  
-
-bool pmt_is_u8vector(pmt_t x);
-bool pmt_is_s8vector(pmt_t x);
-bool pmt_is_u16vector(pmt_t x);
-bool pmt_is_s16vector(pmt_t x);
-bool pmt_is_u32vector(pmt_t x);
-bool pmt_is_s32vector(pmt_t x);
-bool pmt_is_u64vector(pmt_t x);
-bool pmt_is_s64vector(pmt_t x);
-bool pmt_is_f32vector(pmt_t x);
-bool pmt_is_f64vector(pmt_t x);
-bool pmt_is_c32vector(pmt_t x);
-bool pmt_is_c64vector(pmt_t x);
-
-pmt_t pmt_make_u8vector(size_t k, uint8_t fill);
-pmt_t pmt_make_s8vector(size_t k, int8_t fill);
-pmt_t pmt_make_u16vector(size_t k, uint16_t fill);
-pmt_t pmt_make_s16vector(size_t k, int16_t fill);
-pmt_t pmt_make_u32vector(size_t k, uint32_t fill);
-pmt_t pmt_make_s32vector(size_t k, int32_t fill);
-pmt_t pmt_make_u64vector(size_t k, uint64_t fill);
-pmt_t pmt_make_s64vector(size_t k, int64_t fill);
-pmt_t pmt_make_f32vector(size_t k, float fill);
-pmt_t pmt_make_f64vector(size_t k, double fill);
-pmt_t pmt_make_c32vector(size_t k, std::complex fill);
-pmt_t pmt_make_c64vector(size_t k, std::complex fill);
-
-pmt_t pmt_init_u8vector(size_t k, const uint8_t *data);
-pmt_t pmt_init_s8vector(size_t k, const int8_t *data);
-pmt_t pmt_init_u16vector(size_t k, const uint16_t *data);
-pmt_t pmt_init_s16vector(size_t k, const int16_t *data);
-pmt_t pmt_init_u32vector(size_t k, const uint32_t *data);
-pmt_t pmt_init_s32vector(size_t k, const int32_t *data);
-pmt_t pmt_init_u64vector(size_t k, const uint64_t *data);
-pmt_t pmt_init_s64vector(size_t k, const int64_t *data);
-pmt_t pmt_init_f32vector(size_t k, const float *data);
-pmt_t pmt_init_f64vector(size_t k, const double *data);
-pmt_t pmt_init_c32vector(size_t k, const std::complex *data);
-pmt_t pmt_init_c64vector(size_t k, const std::complex *data);
-
-uint8_t  pmt_u8vector_ref(pmt_t v, size_t k);
-int8_t   pmt_s8vector_ref(pmt_t v, size_t k);
-uint16_t pmt_u16vector_ref(pmt_t v, size_t k);
-int16_t  pmt_s16vector_ref(pmt_t v, size_t k);
-uint32_t pmt_u32vector_ref(pmt_t v, size_t k);
-int32_t  pmt_s32vector_ref(pmt_t v, size_t k);
-uint64_t pmt_u64vector_ref(pmt_t v, size_t k);
-int64_t  pmt_s64vector_ref(pmt_t v, size_t k);
-float    pmt_f32vector_ref(pmt_t v, size_t k);
-double   pmt_f64vector_ref(pmt_t v, size_t k);
-std::complex  pmt_c32vector_ref(pmt_t v, size_t k);
-std::complex pmt_c64vector_ref(pmt_t v, size_t k);
-
-void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x);  //< v[k] = x
-void pmt_s8vector_set(pmt_t v, size_t k, int8_t x);
-void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x);
-void pmt_s16vector_set(pmt_t v, size_t k, int16_t x);
-void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x);
-void pmt_s32vector_set(pmt_t v, size_t k, int32_t x);
-void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x);
-void pmt_s64vector_set(pmt_t v, size_t k, int64_t x);
-void pmt_f32vector_set(pmt_t v, size_t k, float x);
-void pmt_f64vector_set(pmt_t v, size_t k, double x);
-void pmt_c32vector_set(pmt_t v, size_t k, std::complex x);
-void pmt_c64vector_set(pmt_t v, size_t k, std::complex x);
+GRUEL_API bool pmt_is_uniform_vector(pmt_t x);  
+
+GRUEL_API bool pmt_is_u8vector(pmt_t x);
+GRUEL_API bool pmt_is_s8vector(pmt_t x);
+GRUEL_API bool pmt_is_u16vector(pmt_t x);
+GRUEL_API bool pmt_is_s16vector(pmt_t x);
+GRUEL_API bool pmt_is_u32vector(pmt_t x);
+GRUEL_API bool pmt_is_s32vector(pmt_t x);
+GRUEL_API bool pmt_is_u64vector(pmt_t x);
+GRUEL_API bool pmt_is_s64vector(pmt_t x);
+GRUEL_API bool pmt_is_f32vector(pmt_t x);
+GRUEL_API bool pmt_is_f64vector(pmt_t x);
+GRUEL_API bool pmt_is_c32vector(pmt_t x);
+GRUEL_API bool pmt_is_c64vector(pmt_t x);
+
+GRUEL_API pmt_t pmt_make_u8vector(size_t k, uint8_t fill);
+GRUEL_API pmt_t pmt_make_s8vector(size_t k, int8_t fill);
+GRUEL_API pmt_t pmt_make_u16vector(size_t k, uint16_t fill);
+GRUEL_API pmt_t pmt_make_s16vector(size_t k, int16_t fill);
+GRUEL_API pmt_t pmt_make_u32vector(size_t k, uint32_t fill);
+GRUEL_API pmt_t pmt_make_s32vector(size_t k, int32_t fill);
+GRUEL_API pmt_t pmt_make_u64vector(size_t k, uint64_t fill);
+GRUEL_API pmt_t pmt_make_s64vector(size_t k, int64_t fill);
+GRUEL_API pmt_t pmt_make_f32vector(size_t k, float fill);
+GRUEL_API pmt_t pmt_make_f64vector(size_t k, double fill);
+GRUEL_API pmt_t pmt_make_c32vector(size_t k, std::complex fill);
+GRUEL_API pmt_t pmt_make_c64vector(size_t k, std::complex fill);
+
+GRUEL_API pmt_t pmt_init_u8vector(size_t k, const uint8_t *data);
+GRUEL_API pmt_t pmt_init_s8vector(size_t k, const int8_t *data);
+GRUEL_API pmt_t pmt_init_u16vector(size_t k, const uint16_t *data);
+GRUEL_API pmt_t pmt_init_s16vector(size_t k, const int16_t *data);
+GRUEL_API pmt_t pmt_init_u32vector(size_t k, const uint32_t *data);
+GRUEL_API pmt_t pmt_init_s32vector(size_t k, const int32_t *data);
+GRUEL_API pmt_t pmt_init_u64vector(size_t k, const uint64_t *data);
+GRUEL_API pmt_t pmt_init_s64vector(size_t k, const int64_t *data);
+GRUEL_API pmt_t pmt_init_f32vector(size_t k, const float *data);
+GRUEL_API pmt_t pmt_init_f64vector(size_t k, const double *data);
+GRUEL_API pmt_t pmt_init_c32vector(size_t k, const std::complex *data);
+GRUEL_API pmt_t pmt_init_c64vector(size_t k, const std::complex *data);
+
+GRUEL_API uint8_t  pmt_u8vector_ref(pmt_t v, size_t k);
+GRUEL_API int8_t   pmt_s8vector_ref(pmt_t v, size_t k);
+GRUEL_API uint16_t pmt_u16vector_ref(pmt_t v, size_t k);
+GRUEL_API int16_t  pmt_s16vector_ref(pmt_t v, size_t k);
+GRUEL_API uint32_t pmt_u32vector_ref(pmt_t v, size_t k);
+GRUEL_API int32_t  pmt_s32vector_ref(pmt_t v, size_t k);
+GRUEL_API uint64_t pmt_u64vector_ref(pmt_t v, size_t k);
+GRUEL_API int64_t  pmt_s64vector_ref(pmt_t v, size_t k);
+GRUEL_API float    pmt_f32vector_ref(pmt_t v, size_t k);
+GRUEL_API double   pmt_f64vector_ref(pmt_t v, size_t k);
+GRUEL_API std::complex  pmt_c32vector_ref(pmt_t v, size_t k);
+GRUEL_API std::complex pmt_c64vector_ref(pmt_t v, size_t k);
+
+GRUEL_API void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x);  //< v[k] = x
+GRUEL_API void pmt_s8vector_set(pmt_t v, size_t k, int8_t x);
+GRUEL_API void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x);
+GRUEL_API void pmt_s16vector_set(pmt_t v, size_t k, int16_t x);
+GRUEL_API void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x);
+GRUEL_API void pmt_s32vector_set(pmt_t v, size_t k, int32_t x);
+GRUEL_API void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x);
+GRUEL_API void pmt_s64vector_set(pmt_t v, size_t k, int64_t x);
+GRUEL_API void pmt_f32vector_set(pmt_t v, size_t k, float x);
+GRUEL_API void pmt_f64vector_set(pmt_t v, size_t k, double x);
+GRUEL_API void pmt_c32vector_set(pmt_t v, size_t k, std::complex x);
+GRUEL_API void pmt_c64vector_set(pmt_t v, size_t k, std::complex x);
 
 // Return const pointers to the elements
 
-const void *pmt_uniform_vector_elements(pmt_t v, size_t &len);  //< works with any; len is in bytes
-
-const uint8_t  *pmt_u8vector_elements(pmt_t v, size_t &len);  //< len is in elements
-const int8_t   *pmt_s8vector_elements(pmt_t v, size_t &len);  //< len is in elements
-const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements
-const int16_t  *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements
-const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements
-const int32_t  *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements
-const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements
-const int64_t  *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements
-const float    *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements
-const double   *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements
-const std::complex  *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements
-const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const void *pmt_uniform_vector_elements(pmt_t v, size_t &len);  //< works with any; len is in bytes
+
+GRUEL_API const uint8_t  *pmt_u8vector_elements(pmt_t v, size_t &len);  //< len is in elements
+GRUEL_API const int8_t   *pmt_s8vector_elements(pmt_t v, size_t &len);  //< len is in elements
+GRUEL_API const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const int16_t  *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const int32_t  *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const int64_t  *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const float    *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const double   *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const std::complex  *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements
 
 // Return non-const pointers to the elements
 
-void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len);  //< works with any; len is in bytes
-
-uint8_t  *pmt_u8vector_writable_elements(pmt_t v, size_t &len);  //< len is in elements
-int8_t   *pmt_s8vector_writable_elements(pmt_t v, size_t &len);  //< len is in elements
-uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-int16_t  *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-int32_t  *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-int64_t  *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-float    *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-double   *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-std::complex  *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
-std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len);  //< works with any; len is in bytes
+
+GRUEL_API uint8_t  *pmt_u8vector_writable_elements(pmt_t v, size_t &len);  //< len is in elements
+GRUEL_API int8_t   *pmt_s8vector_writable_elements(pmt_t v, size_t &len);  //< len is in elements
+GRUEL_API uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API int16_t  *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API int32_t  *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API int64_t  *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API float    *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API double   *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API std::complex  *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+GRUEL_API std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
 
 /*
  * ------------------------------------------------------------------------
@@ -494,31 +495,31 @@ std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //<
  */
 
 //! Return true if \p obj is a dictionary
-bool pmt_is_dict(const pmt_t &obj);
+GRUEL_API bool pmt_is_dict(const pmt_t &obj);
 
 //! Make an empty dictionary
-pmt_t pmt_make_dict();
+GRUEL_API pmt_t pmt_make_dict();
 
 //! Return a new dictionary with \p key associated with \p value.
-pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value);
+GRUEL_API pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value);
 
 //! Return a new dictionary with \p key removed.
-pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key);
+GRUEL_API pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key);
 
 //! Return true if \p key exists in \p dict
-bool  pmt_dict_has_key(const pmt_t &dict, const pmt_t &key);
+GRUEL_API bool  pmt_dict_has_key(const pmt_t &dict, const pmt_t &key);
 
 //! If \p key exists in \p dict, return associated value; otherwise return \p not_found.
-pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found);
+GRUEL_API pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found);
 
 //! Return list of (key . value) pairs
-pmt_t pmt_dict_items(pmt_t dict);
+GRUEL_API pmt_t pmt_dict_items(pmt_t dict);
 
 //! Return list of keys
-pmt_t pmt_dict_keys(pmt_t dict);
+GRUEL_API pmt_t pmt_dict_keys(pmt_t dict);
 
 //! Return list of values
-pmt_t pmt_dict_values(pmt_t dict);
+GRUEL_API pmt_t pmt_dict_values(pmt_t dict);
 
 /*
  * ------------------------------------------------------------------------
@@ -530,16 +531,16 @@ pmt_t pmt_dict_values(pmt_t dict);
  */
 
 //! Return true if \p obj is an any
-bool pmt_is_any(pmt_t obj);
+GRUEL_API bool pmt_is_any(pmt_t obj);
 
 //! make an any
-pmt_t pmt_make_any(const boost::any &any);
+GRUEL_API pmt_t pmt_make_any(const boost::any &any);
 
 //! Return underlying boost::any
-boost::any pmt_any_ref(pmt_t obj);
+GRUEL_API boost::any pmt_any_ref(pmt_t obj);
 
 //! Store \p any in \p obj
-void pmt_any_set(pmt_t obj, const boost::any &any);
+GRUEL_API void pmt_any_set(pmt_t obj, const boost::any &any);
 
 
 /*
@@ -548,13 +549,13 @@ void pmt_any_set(pmt_t obj, const boost::any &any);
  * ------------------------------------------------------------------------
  */
 //! Return true if \p obj is a msg_accepter
-bool pmt_is_msg_accepter(const pmt_t &obj);
+GRUEL_API bool pmt_is_msg_accepter(const pmt_t &obj);
 
 //! make a msg_accepter
-pmt_t pmt_make_msg_accepter(boost::shared_ptr ma);
+GRUEL_API 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);
+GRUEL_API boost::shared_ptr pmt_msg_accepter_ref(const pmt_t &obj);
 
 /*
  * ------------------------------------------------------------------------
@@ -563,7 +564,7 @@ boost::shared_ptr pmt_msg_accepter_ref(const pmt_t &obj);
  */
 
 //! Return true if x and y are the same object; otherwise return false.
-bool pmt_eq(const pmt_t& x, const pmt_t& y);
+GRUEL_API bool pmt_eq(const pmt_t& x, const pmt_t& y);
 
 /*!
  * \brief Return true if x and y should normally be regarded as the same object, else false.
@@ -578,7 +579,7 @@ bool pmt_eq(const pmt_t& x, const pmt_t& y);
  *   x and y are pairs or vectors that denote same location in store.
  * 
*/ -bool pmt_eqv(const pmt_t& x, const pmt_t& y); +GRUEL_API bool pmt_eqv(const pmt_t& x, const pmt_t& y); /*! * pmt_equal recursively compares the contents of pairs and vectors, @@ -586,11 +587,11 @@ bool pmt_eqv(const pmt_t& x, const pmt_t& y); * pmt_equal may fail to terminate if its arguments are circular data * structures. */ -bool pmt_equal(const pmt_t& x, const pmt_t& y); +GRUEL_API bool pmt_equal(const pmt_t& x, const pmt_t& y); //! Return the number of elements in v -size_t pmt_length(const pmt_t& v); +GRUEL_API size_t pmt_length(const pmt_t& v); /*! * \brief Find the first pair in \p alist whose car field is \p obj @@ -600,7 +601,7 @@ size_t pmt_length(const pmt_t& v); * in \p alist has \p obj as its car then \#f is returned. * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. */ -pmt_t pmt_assq(pmt_t obj, pmt_t alist); +GRUEL_API pmt_t pmt_assq(pmt_t obj, pmt_t alist); /*! * \brief Find the first pair in \p alist whose car field is \p obj @@ -610,7 +611,7 @@ pmt_t pmt_assq(pmt_t obj, pmt_t alist); * in \p alist has \p obj as its car then \#f is returned. * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. */ -pmt_t pmt_assv(pmt_t obj, pmt_t alist); +GRUEL_API pmt_t pmt_assv(pmt_t obj, pmt_t alist); /*! * \brief Find the first pair in \p alist whose car field is \p obj @@ -620,7 +621,7 @@ pmt_t pmt_assv(pmt_t obj, pmt_t alist); * in \p alist has \p obj as its car then \#f is returned. * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. */ -pmt_t pmt_assoc(pmt_t obj, pmt_t alist); +GRUEL_API pmt_t pmt_assoc(pmt_t obj, pmt_t alist); /*! * \brief Apply \p proc element-wise to the elements of list and returns @@ -629,21 +630,21 @@ pmt_t pmt_assoc(pmt_t obj, pmt_t alist); * \p list must be a list. The dynamic order in which \p proc is * applied to the elements of \p list is unspecified. */ -pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); +GRUEL_API pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); /*! * \brief reverse \p list. * * \p list must be a proper list. */ -pmt_t pmt_reverse(pmt_t list); +GRUEL_API pmt_t pmt_reverse(pmt_t list); /*! * \brief destructively reverse \p list. * * \p list must be a proper list. */ -pmt_t pmt_reverse_x(pmt_t list); +GRUEL_API pmt_t pmt_reverse_x(pmt_t list); /*! * \brief (acons x y a) == (cons (cons x y) a) @@ -657,76 +658,76 @@ pmt_acons(pmt_t x, pmt_t y, pmt_t a) /*! * \brief locates \p nth element of \n list where the car is the 'zeroth' element. */ -pmt_t pmt_nth(size_t n, pmt_t list); +GRUEL_API pmt_t pmt_nth(size_t n, pmt_t list); /*! * \brief returns the tail of \p list that would be obtained by calling * cdr \p n times in succession. */ -pmt_t pmt_nthcdr(size_t n, pmt_t list); +GRUEL_API pmt_t pmt_nthcdr(size_t n, pmt_t list); /*! * \brief Return the first sublist of \p list whose car is \p obj. * If \p obj does not occur in \p list, then \#f is returned. * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. */ -pmt_t pmt_memq(pmt_t obj, pmt_t list); +GRUEL_API pmt_t pmt_memq(pmt_t obj, pmt_t list); /*! * \brief Return the first sublist of \p list whose car is \p obj. * If \p obj does not occur in \p list, then \#f is returned. * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. */ -pmt_t pmt_memv(pmt_t obj, pmt_t list); +GRUEL_API pmt_t pmt_memv(pmt_t obj, pmt_t list); /*! * \brief Return the first sublist of \p list whose car is \p obj. * If \p obj does not occur in \p list, then \#f is returned. * pmt_member use pmt_equal to compare \p obj with the elements of \p list. */ -pmt_t pmt_member(pmt_t obj, pmt_t list); +GRUEL_API pmt_t pmt_member(pmt_t obj, pmt_t list); /*! * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. * Comparisons are done with pmt_eqv. */ -bool pmt_subsetp(pmt_t list1, pmt_t list2); +GRUEL_API bool pmt_subsetp(pmt_t list1, pmt_t list2); /*! * \brief Return a list of length 1 containing \p x1 */ -pmt_t pmt_list1(const pmt_t& x1); +GRUEL_API pmt_t pmt_list1(const pmt_t& x1); /*! * \brief Return a list of length 2 containing \p x1, \p x2 */ -pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); +GRUEL_API pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); /*! * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 */ -pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); +GRUEL_API pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); /*! * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 */ -pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); +GRUEL_API pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); /*! * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 */ -pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); +GRUEL_API pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); /*! * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p * x5, \p x6 */ -pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); +GRUEL_API pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6); /*! * \brief Return \p list with \p item added to it. */ -pmt_t pmt_list_add(pmt_t list, const pmt_t& item); +GRUEL_API pmt_t pmt_list_add(pmt_t list, const pmt_t& item); /* @@ -734,10 +735,10 @@ pmt_t pmt_list_add(pmt_t list, const pmt_t& item); * read / write * ------------------------------------------------------------------------ */ -extern const pmt_t PMT_EOF; //< The end of file object +extern GRUEL_API const pmt_t PMT_EOF; //< The end of file object //! return true if obj is the EOF object, otherwise return false. -bool pmt_is_eof_object(pmt_t obj); +GRUEL_API bool pmt_is_eof_object(pmt_t obj); /*! * read converts external representations of pmt objects into the @@ -754,26 +755,26 @@ bool pmt_is_eof_object(pmt_t obj); * representation, but the external representation is incomplete and * therefore not parsable, an error is signaled. */ -pmt_t pmt_read(std::istream &port); +GRUEL_API pmt_t pmt_read(std::istream &port); /*! * Write a written representation of \p obj to the given \p port. */ -void pmt_write(pmt_t obj, std::ostream &port); +GRUEL_API void pmt_write(pmt_t obj, std::ostream &port); /*! * Return a string representation of \p obj. * This is the same output as would be generated by pmt_write. */ -std::string pmt_write_string(pmt_t obj); +GRUEL_API std::string pmt_write_string(pmt_t obj); -std::ostream& operator<<(std::ostream &os, pmt_t obj); +GRUEL_API std::ostream& operator<<(std::ostream &os, pmt_t obj); /*! * \brief Write pmt string representation to stdout. */ -void pmt_print(pmt_t v); +GRUEL_API void pmt_print(pmt_t v); /* @@ -784,25 +785,25 @@ void pmt_print(pmt_t v); /*! * \brief Write portable byte-serial representation of \p obj to \p sink */ -bool pmt_serialize(pmt_t obj, std::streambuf &sink); +GRUEL_API bool pmt_serialize(pmt_t obj, std::streambuf &sink); /*! * \brief Create obj from portable byte-serial representation */ -pmt_t pmt_deserialize(std::streambuf &source); +GRUEL_API pmt_t pmt_deserialize(std::streambuf &source); -void pmt_dump_sizeof(); // debugging +GRUEL_API void pmt_dump_sizeof(); // debugging /*! * \brief Provide a simple string generating interface to pmt's serialize function */ -std::string pmt_serialize_str(pmt_t obj); +GRUEL_API std::string pmt_serialize_str(pmt_t obj); /*! * \brief Provide a simple string generating interface to pmt's deserialize function */ -pmt_t pmt_deserialize_str(std::string str); +GRUEL_API pmt_t pmt_deserialize_str(std::string str); } /* namespace pmt */ diff --git a/gruel/src/include/gruel/pmt_pool.h b/gruel/src/include/gruel/pmt_pool.h index b792523e0..2b227ce6a 100644 --- a/gruel/src/include/gruel/pmt_pool.h +++ b/gruel/src/include/gruel/pmt_pool.h @@ -21,6 +21,7 @@ #ifndef INCLUDED_PMT_POOL_H #define INCLUDED_PMT_POOL_H +#include #include #include #include @@ -33,9 +34,9 @@ namespace pmt { * FIXME may want to go to global allocation with per-thread free list. * This would eliminate virtually all lock contention. */ -class pmt_pool { +class GRUEL_API pmt_pool { - struct item { + struct GRUEL_API item { struct item *d_next; }; diff --git a/gruel/src/include/gruel/realtime.h b/gruel/src/include/gruel/realtime.h index d110ec956..87f2b0f74 100644 --- a/gruel/src/include/gruel/realtime.h +++ b/gruel/src/include/gruel/realtime.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GRUEL_REALTIME_H #define INCLUDED_GRUEL_REALTIME_H +#include #include /*! @@ -58,7 +59,7 @@ namespace gruel { static inline int rt_priority_max() { return 15; } static inline int rt_priority_default() { return 1; } - struct rt_sched_param { + struct GRUEL_API rt_sched_param { int priority; rt_sched_policy policy; @@ -88,7 +89,7 @@ namespace gruel { // NOTE: If you change this, you need to change the code in // gnuradio-core/src/lib/runtime/gr_realtime.i, see note there. rt_status_t - enable_realtime_scheduling(rt_sched_param = rt_sched_param()); + GRUEL_API enable_realtime_scheduling(rt_sched_param = rt_sched_param()); } // namespace gruel diff --git a/gruel/src/include/gruel/sys_pri.h b/gruel/src/include/gruel/sys_pri.h index b0fd83654..a29b051bf 100644 --- a/gruel/src/include/gruel/sys_pri.h +++ b/gruel/src/include/gruel/sys_pri.h @@ -22,6 +22,7 @@ #ifndef INCLUDED_GRUEL_SYS_PRI_H #define INCLUDED_GRUEL_SYS_PRI_H +#include #include /* @@ -29,7 +30,7 @@ */ namespace gruel { - struct sys_pri { + struct GRUEL_API sys_pri { static rt_sched_param python(); // python code static rt_sched_param normal(); // normal blocks static rt_sched_param gcell_event_handler(); diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 5a8ab1876..c6031d88d 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -21,6 +21,7 @@ #ifndef INCLUDED_THREAD_H #define INCLUDED_THREAD_H +#include #include #include #include diff --git a/gruel/src/include/gruel/thread_body_wrapper.h b/gruel/src/include/gruel/thread_body_wrapper.h index b024bfdaf..ae0feda08 100644 --- a/gruel/src/include/gruel/thread_body_wrapper.h +++ b/gruel/src/include/gruel/thread_body_wrapper.h @@ -21,6 +21,7 @@ #ifndef INCLUDED_THREAD_BODY_WRAPPER_H #define INCLUDED_THREAD_BODY_WRAPPER_H +#include #include #include #include @@ -28,7 +29,7 @@ namespace gruel { - void mask_signals(); + GRUEL_API void mask_signals(); template class thread_body_wrapper diff --git a/gruel/src/include/gruel/thread_group.h b/gruel/src/include/gruel/thread_group.h index 0270746e4..e1658dd1f 100644 --- a/gruel/src/include/gruel/thread_group.h +++ b/gruel/src/include/gruel/thread_group.h @@ -15,6 +15,7 @@ #ifndef INCLUDED_GRUEL_THREAD_GROUP_H #define INCLUDED_GRUEL_THREAD_GROUP_H +#include #include #include #include @@ -22,7 +23,7 @@ namespace gruel { - class thread_group : public boost::noncopyable + class GRUEL_API thread_group : public boost::noncopyable { public: thread_group(); diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index 773f3aefd..10ec7a44d 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -24,7 +24,7 @@ include $(top_srcdir)/Makefile.common SUBDIRS = pmt msg AM_CPPFLAGS = $(DEFINES) $(GRUEL_INCLUDES) $(BOOST_CPPFLAGS) \ - $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) + $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) -Dgruel_EXPORTS TESTS = test_gruel diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h index ea28e37b4..3a5cd382b 100644 --- a/gruel/src/lib/pmt/pmt_int.h +++ b/gruel/src/lib/pmt/pmt_int.h @@ -35,7 +35,7 @@ #define PMT_LOCAL_ALLOCATOR 0 // define to 0 or 1 namespace pmt { -class pmt_base : boost::noncopyable { +class GRUEL_API pmt_base : boost::noncopyable { mutable boost::detail::atomic_count count_; protected: diff --git a/gruel/src/lib/pmt/qa_pmt.h b/gruel/src/lib/pmt/qa_pmt.h index 43a6dbf67..424c1065b 100644 --- a/gruel/src/lib/pmt/qa_pmt.h +++ b/gruel/src/lib/pmt/qa_pmt.h @@ -23,11 +23,12 @@ #ifndef INCLUDED_QA_PMT_H #define INCLUDED_QA_PMT_H +#include #include //! collect all the tests for pmt -class qa_pmt { +class __GR_ATTR_EXPORT qa_pmt { public: //! return suite of tests for all of pmt static CppUnit::TestSuite *suite (); diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h index efc5c6050..cc1409ee6 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.h +++ b/gruel/src/lib/pmt/qa_pmt_prims.h @@ -22,10 +22,12 @@ #ifndef INCLUDED_QA_PMT_PRIMS_H #define INCLUDED_QA_PMT_PRIMS_H +#include +#include //reason: suppress warnings #include #include -class qa_pmt_prims : public CppUnit::TestCase { +class __GR_ATTR_EXPORT qa_pmt_prims : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(qa_pmt_prims); CPPUNIT_TEST(test_symbols); -- cgit From ed950948ea424f3670be1f5ffc96be922ab5e3c9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 17:56:41 -0700 Subject: gruel: support for windows API set realtime scheduling --- gruel/src/lib/realtime.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'gruel') diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc index 7397cf3d3..96351f812 100644 --- a/gruel/src/lib/realtime.cc +++ b/gruel/src/lib/realtime.cc @@ -132,6 +132,38 @@ namespace gruel { } // namespace gruel +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) + +#include + +namespace gruel { + + rt_status_t enable_realtime_scheduling(rt_sched_param p){ + + //set the priority class on the process + int pri_class = (true)? REALTIME_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; + if (SetPriorityClass(GetCurrentProcess(), pri_class) == 0) + return RT_OTHER_ERROR; + + //scale the priority value to the constants + int priorities[] = { + THREAD_PRIORITY_IDLE, THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_BELOW_NORMAL, THREAD_PRIORITY_NORMAL, + THREAD_PRIORITY_ABOVE_NORMAL, THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_TIME_CRITICAL + }; + const double priority = double(p.priority)/(rt_priority_max() - rt_priority_min()); + size_t pri_index = size_t((priority+1.0)*6/2.0); // -1 -> 0, +1 -> 6 + pri_index %= sizeof(priorities)/sizeof(*priorities); //range check + + //set the thread priority on the thread + if (SetThreadPriority(GetCurrentThread(), priorities[pri_index]) == 0) + return RT_OTHER_ERROR; + + //printf("SetPriorityClass + SetThreadPriority\n"); + return RT_OK; + } + +} // namespace gruel + #else namespace gruel { -- cgit From accb9f2fe8fd8f6a1e114adac5b15304b0e0012d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 19:04:32 -0700 Subject: gr: squashed cmakelists.txt into one commit --- gruel/CMakeLists.txt | 105 +++++++++++++++++++++++++++++ gruel/src/include/gruel/CMakeLists.txt | 56 ++++++++++++++++ gruel/src/include/gruel/Makefile.am | 2 + gruel/src/lib/CMakeLists.txt | 110 +++++++++++++++++++++++++++++++ gruel/src/lib/Makefile.am | 2 +- gruel/src/lib/msg/CMakeLists.txt | 28 ++++++++ gruel/src/lib/pmt/CMakeLists.txt | 90 +++++++++++++++++++++++++ gruel/src/python/CMakeLists.txt | 52 +++++++++++++++ gruel/src/scheme/gnuradio/CMakeLists.txt | 26 ++++++++ gruel/src/swig/CMakeLists.txt | 41 ++++++++++++ 10 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 gruel/CMakeLists.txt create mode 100644 gruel/src/include/gruel/CMakeLists.txt create mode 100644 gruel/src/lib/CMakeLists.txt create mode 100644 gruel/src/lib/msg/CMakeLists.txt create mode 100644 gruel/src/lib/pmt/CMakeLists.txt create mode 100644 gruel/src/python/CMakeLists.txt create mode 100644 gruel/src/scheme/gnuradio/CMakeLists.txt create mode 100644 gruel/src/swig/CMakeLists.txt (limited to 'gruel') diff --git a/gruel/CMakeLists.txt b/gruel/CMakeLists.txt new file mode 100644 index 000000000..04be4486e --- /dev/null +++ b/gruel/CMakeLists.txt @@ -0,0 +1,105 @@ +# Copyright 2010-2011 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. + +######################################################################## +# Setup dependencies +######################################################################## +INCLUDE(GrBoost) + +INCLUDE(GrPython) #used for code generation + +######################################################################## +# Register component +######################################################################## +INCLUDE(GrComponent) +GR_REGISTER_COMPONENT("gruel" ENABLE_GRUEL + Boost_FOUND + PYTHONINTERP_FOUND +) + +INCLUDE(GrMiscUtils) +GR_SET_GLOBAL(GRUEL_INCLUDE_DIRS + ${Boost_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/src/include + ${CMAKE_CURRENT_BINARY_DIR}/src/include +) + +######################################################################## +# Begin conditional configuration +######################################################################## +IF(ENABLE_GRUEL) + +######################################################################## +# Setup CPack components +######################################################################## +INCLUDE(GrPackage) +CPACK_SET(CPACK_COMPONENT_GROUP_GRUEL_DESCRIPTION "The GNU Radio Utility Etcetera Library") + +CPACK_COMPONENT("gruel_runtime" + GROUP "Gruel" + DISPLAY_NAME "Runtime" + DESCRIPTION "Dynamic link libraries" +) + +CPACK_COMPONENT("gruel_devel" + GROUP "Gruel" + DISPLAY_NAME "Development" + DESCRIPTION "C++ headers, package config, import libraries" +) + +CPACK_COMPONENT("gruel_python" + GROUP "Gruel" + DISPLAY_NAME "Python" + DESCRIPTION "Python modules for runtime" + DEPENDS "gruel_runtime" +) + +CPACK_COMPONENT("gruel_swig" + GROUP "Gruel" + DISPLAY_NAME "SWIG" + DESCRIPTION "SWIG development .i files" + DEPENDS "gruel_python;gruel_devel" +) + +######################################################################## +# Add subdirectories +######################################################################## +ADD_SUBDIRECTORY(src/include/gruel) +ADD_SUBDIRECTORY(src/scheme/gnuradio) +ADD_SUBDIRECTORY(src/lib) +IF(ENABLE_PYTHON) + ADD_SUBDIRECTORY(src/swig) + ADD_SUBDIRECTORY(src/python) +ENDIF(ENABLE_PYTHON) + +######################################################################## +# Create Pkg Config File +######################################################################## +CONFIGURE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/gruel.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/gruel.pc +@ONLY) + +INSTALL( + FILES ${CMAKE_CURRENT_BINARY_DIR}/gruel.pc + DESTINATION ${GR_LIBRARY_DIR}/pkgconfig + COMPONENT "gruel_devel" +) + +ENDIF(ENABLE_GRUEL) diff --git a/gruel/src/include/gruel/CMakeLists.txt b/gruel/src/include/gruel/CMakeLists.txt new file mode 100644 index 000000000..2f80043a4 --- /dev/null +++ b/gruel/src/include/gruel/CMakeLists.txt @@ -0,0 +1,56 @@ +# Copyright 2010-2011 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. + +######################################################################## +# Generate inet.h header file +######################################################################## +INCLUDE(TestBigEndian) +ENABLE_LANGUAGE(C) +TEST_BIG_ENDIAN(GR_ARCH_BIGENDIAN) + +INCLUDE(CheckIncludeFileCXX) +CHECK_INCLUDE_FILE_CXX(byteswap.h GR_HAVE_BYTESWAP) +CHECK_INCLUDE_FILE_CXX(arpa/inet.h GR_HAVE_ARPA_INET) + +CONFIGURE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/inet.h.in + ${CMAKE_CURRENT_BINARY_DIR}/inet.h +@ONLY) + +######################################################################## +# Install the headers +######################################################################## +INSTALL(FILES + api.h + attributes.h + high_res_timer.h + ${CMAKE_CURRENT_BINARY_DIR}/inet.h + msg_accepter.h + msg_accepter_msgq.h + msg_queue.h + msg_passing.h + pmt.h + pmt_pool.h + pmt_sugar.h + realtime.h + sys_pri.h + thread_body_wrapper.h + thread_group.h + thread.h +DESTINATION ${GR_INCLUDE_DIR}/gruel COMPONENT "gruel_devel") diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index fce739f08..d258f0379 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -26,6 +26,8 @@ EXTRA_DIST += inet.h.in gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ +<<<<<<< HEAD + $(BUILT_SOURCES) \ api.h \ attributes.h \ high_res_timer.h \ diff --git a/gruel/src/lib/CMakeLists.txt b/gruel/src/lib/CMakeLists.txt new file mode 100644 index 000000000..d078e52f9 --- /dev/null +++ b/gruel/src/lib/CMakeLists.txt @@ -0,0 +1,110 @@ +# Copyright 2010-2011 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 subdirs rather to populate to the sources lists. +######################################################################## +INCLUDE(GrMiscUtils) +INCLUDE(CheckCXXSourceCompiles) + +GR_CHECK_HDR_N_DEF(signal.h HAVE_SIGNAL_H) +GR_CHECK_HDR_N_DEF(sched.h HAVE_SCHED_H) + +SET(CMAKE_REQUIRED_LIBRARIES -lpthread) +CHECK_CXX_SOURCE_COMPILES(" + #include + int main(){pthread_sigmask(0, 0, 0); return 0;} + " HAVE_PTHREAD_SIGMASK +) +GR_ADD_COND_DEF(HAVE_PTHREAD_SIGMASK) + +SET(CMAKE_REQUIRED_LIBRARIES -lpthread) +CHECK_CXX_SOURCE_COMPILES(" + #include + int main(){ + pthread_t pthread; + pthread_setschedparam(pthread, 0, 0); + return 0; + } " HAVE_PTHREAD_SETSCHEDPARAM +) +GR_ADD_COND_DEF(HAVE_PTHREAD_SETSCHEDPARAM) + +CHECK_CXX_SOURCE_COMPILES(" + #include + int main(){ + pid_t pid; + sched_setscheduler(pid, 0, 0); + return 0; + } " HAVE_SCHED_SETSCHEDULER +) +GR_ADD_COND_DEF(HAVE_SCHED_SETSCHEDULER) + +######################################################################## +# Include subdirs rather to populate to the sources lists. +######################################################################## +GR_INCLUDE_SUBDIRECTORY(msg) +GR_INCLUDE_SUBDIRECTORY(pmt) + +######################################################################## +# Setup the include and linker paths +######################################################################## +INCLUDE_DIRECTORIES(${GRUEL_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) +LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) + +######################################################################## +# Setup library +######################################################################## +LIST(APPEND gruel_sources + realtime.cc + sys_pri.cc + thread_body_wrapper.cc + thread_group.cc +) + +ADD_LIBRARY(gruel SHARED ${gruel_sources}) +TARGET_LINK_LIBRARIES(gruel ${Boost_LIBRARIES}) +SET_TARGET_PROPERTIES(gruel PROPERTIES DEFINE_SYMBOL "gruel_EXPORTS") +SET_TARGET_PROPERTIES(gruel PROPERTIES SOVERSION ${LIBVER}) + +INSTALL(TARGETS gruel + LIBRARY DESTINATION ${GR_LIBRARY_DIR} COMPONENT "gruel_runtime" # .so/.dylib file + ARCHIVE DESTINATION ${GR_LIBRARY_DIR} COMPONENT "gruel_devel" # .lib file + RUNTIME DESTINATION ${GR_RUNTIME_DIR} COMPONENT "gruel_runtime" # .dll file +) + +######################################################################## +# Setup tests +# Set the test environment so the build libs will be found under MSVC. +######################################################################## +IF(ENABLE_TESTING) + +INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIRS}) +LINK_DIRECTORIES(${CPPUNIT_LIBRARY_DIRS}) + +INCLUDE(GrTest) +SET(GR_TEST_TARGET_DEPS gruel) +LIST(APPEND test_gruel_sources test_gruel.cc) +ADD_EXECUTABLE(test_gruel ${test_gruel_sources}) +TARGET_LINK_LIBRARIES(test_gruel gruel ${CPPUNIT_LIBRARIES}) +GR_ADD_TEST(gruel-test test_gruel) + +ENDIF(ENABLE_TESTING) diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index 10ec7a44d..773f3aefd 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -24,7 +24,7 @@ include $(top_srcdir)/Makefile.common SUBDIRS = pmt msg AM_CPPFLAGS = $(DEFINES) $(GRUEL_INCLUDES) $(BOOST_CPPFLAGS) \ - $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) -Dgruel_EXPORTS + $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) TESTS = test_gruel diff --git a/gruel/src/lib/msg/CMakeLists.txt b/gruel/src/lib/msg/CMakeLists.txt new file mode 100644 index 000000000..877cc2909 --- /dev/null +++ b/gruel/src/lib/msg/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright 2010 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. + +######################################################################## +# This file included, use CMake directory variables +######################################################################## + +LIST(APPEND gruel_sources + ${CMAKE_CURRENT_SOURCE_DIR}/msg_accepter.cc + ${CMAKE_CURRENT_SOURCE_DIR}/msg_accepter_msgq.cc + ${CMAKE_CURRENT_SOURCE_DIR}/msg_queue.cc +) diff --git a/gruel/src/lib/pmt/CMakeLists.txt b/gruel/src/lib/pmt/CMakeLists.txt new file mode 100644 index 000000000..797db475a --- /dev/null +++ b/gruel/src/lib/pmt/CMakeLists.txt @@ -0,0 +1,90 @@ +# Copyright 2010 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. + +######################################################################## +# This file included, use CMake directory variables +######################################################################## +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + +######################################################################## +# Generate serial tags header file +######################################################################## +GET_FILENAME_COMPONENT(SCHEME_DIR + ${CMAKE_CURRENT_SOURCE_DIR}/../../scheme/gnuradio ABSOLUTE +) + +GET_FILENAME_COMPONENT(PMT_SERIAL_TAGS_H + ${CMAKE_CURRENT_BINARY_DIR}/../../include/gruel/pmt_serial_tags.h ABSOLUTE +) + +ADD_CUSTOM_COMMAND( + OUTPUT ${PMT_SERIAL_TAGS_H} + DEPENDS ${SCHEME_DIR}/gen-serial-tags.py + DEPENDS ${SCHEME_DIR}/pmt-serial-tags.scm + COMMAND ${PYTHON_EXECUTABLE} + ${SCHEME_DIR}/gen-serial-tags.py + ${SCHEME_DIR}/pmt-serial-tags.scm + ${PMT_SERIAL_TAGS_H} +) + +INSTALL( + FILES ${PMT_SERIAL_TAGS_H} + DESTINATION ${GR_INCLUDE_DIR}/gruel + COMPONENT "gruel_devel" +) + +INCLUDE(AddFileDependencies) +ADD_FILE_DEPENDENCIES( + ${CMAKE_CURRENT_SOURCE_DIR}/pmt_serialize.cc + ${PMT_SERIAL_TAGS_H} +) + +######################################################################## +# Generate other pmt stuff +######################################################################## +ADD_CUSTOM_COMMAND( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/pmt_unv_int.h + ${CMAKE_CURRENT_BINARY_DIR}/qa_pmt_unv.h + ${CMAKE_CURRENT_BINARY_DIR}/pmt_unv.cc + ${CMAKE_CURRENT_BINARY_DIR}/qa_pmt_unv.cc + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/generate_unv.py + ${CMAKE_CURRENT_SOURCE_DIR}/unv_template.h.t + ${CMAKE_CURRENT_SOURCE_DIR}/unv_template.cc.t + ${CMAKE_CURRENT_SOURCE_DIR}/unv_qa_template.cc.t + COMMAND ${PYTHON_EXECUTABLE} -B -c + \"import os,sys\;srcdir='${CMAKE_CURRENT_SOURCE_DIR}'\;sys.path.append(srcdir)\;os.environ['srcdir']=srcdir\;from generate_unv import main\;main()\" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +LIST(APPEND gruel_sources + ${CMAKE_CURRENT_BINARY_DIR}/pmt_unv.cc + ${CMAKE_CURRENT_SOURCE_DIR}/pmt.cc + ${CMAKE_CURRENT_SOURCE_DIR}/pmt_io.cc + ${CMAKE_CURRENT_SOURCE_DIR}/pmt_pool.cc + ${CMAKE_CURRENT_SOURCE_DIR}/pmt_serialize.cc +) + +LIST(APPEND test_gruel_sources + ${CMAKE_CURRENT_BINARY_DIR}/qa_pmt_unv.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_pmt_prims.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_pmt.cc +) diff --git a/gruel/src/python/CMakeLists.txt b/gruel/src/python/CMakeLists.txt new file mode 100644 index 000000000..491763cd7 --- /dev/null +++ b/gruel/src/python/CMakeLists.txt @@ -0,0 +1,52 @@ +# Copyright 2011 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(GrPython) + +######################################################################## +# Install python files +######################################################################## +GR_PYTHON_INSTALL( + FILES __init__.py + DESTINATION ${GR_PYTHON_DIR}/gruel + COMPONENT "gruel_python" +) + +GR_PYTHON_INSTALL( + FILES pmt/__init__.py + DESTINATION ${GR_PYTHON_DIR}/gruel/pmt + COMPONENT "gruel_python" +) + +######################################################################## +# Setup unit tests +######################################################################## +IF(ENABLE_TESTING) +INCLUDE(GrTest) +FILE(GLOB py_qa_test_files "qa_*.py") +FOREACH(py_qa_test_file ${py_qa_test_files}) + GET_FILENAME_COMPONENT(py_qa_test_name ${py_qa_test_file} NAME_WE) + SET(GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gruel/src/python + ${CMAKE_BINARY_DIR}/gruel/src/swig + ) + SET(GR_TEST_TARGET_DEPS gruel gnuradio-core) + GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${py_qa_test_file}) +ENDFOREACH(py_qa_test_file) +ENDIF(ENABLE_TESTING) diff --git a/gruel/src/scheme/gnuradio/CMakeLists.txt b/gruel/src/scheme/gnuradio/CMakeLists.txt new file mode 100644 index 000000000..bfa2a415f --- /dev/null +++ b/gruel/src/scheme/gnuradio/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright 2010 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. + +######################################################################## + +INSTALL(FILES + pmt-serial-tags.scm + pmt-serialize.scm + macros-etc.scm +DESTINATION ${GR_PKG_DATA_DIR} COMPONENT "gruel_swig") diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt new file mode 100644 index 000000000..05f875451 --- /dev/null +++ b/gruel/src/swig/CMakeLists.txt @@ -0,0 +1,41 @@ +# Copyright 2011 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. + +######################################################################## +# Setup swig generation +######################################################################## +INCLUDE(GrPython) +INCLUDE(GrSwig) + +SET(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS}) +SET(GR_SWIG_LIBRARIES gruel) + +GR_SWIG_MAKE(pmt_swig pmt_swig.i) + +GR_SWIG_INSTALL( + TARGETS pmt_swig + DESTINATION ${GR_PYTHON_DIR}/gruel/pmt + COMPONENT "gruel_python" +) + +INSTALL( + FILES gr_intrusive_ptr.i + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig + COMPONENT "gruel_swig" +) -- cgit From fbe4a14d8fb6d6696bd0ac8a4921ba1269601d78 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 2 Aug 2011 12:45:26 -0700 Subject: cmake: language tweak for component group description --- gruel/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/CMakeLists.txt b/gruel/CMakeLists.txt index 04be4486e..933e74b2f 100644 --- a/gruel/CMakeLists.txt +++ b/gruel/CMakeLists.txt @@ -49,7 +49,7 @@ IF(ENABLE_GRUEL) # Setup CPack components ######################################################################## INCLUDE(GrPackage) -CPACK_SET(CPACK_COMPONENT_GROUP_GRUEL_DESCRIPTION "The GNU Radio Utility Etcetera Library") +CPACK_SET(CPACK_COMPONENT_GROUP_GRUEL_DESCRIPTION "GNU Radio Utility Etcetera Library") CPACK_COMPONENT("gruel_runtime" GROUP "Gruel" -- cgit From f19b9b8b2f0366af4e61cb7b831960b826c5cce9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 3 Aug 2011 01:58:49 -0700 Subject: atsc: did work on symbol visibility and minor tweaks in qa code for MSVC --- gruel/src/include/gruel/attributes.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/attributes.h b/gruel/src/include/gruel/attributes.h index 8c9a57b47..baa5521c8 100644 --- a/gruel/src/include/gruel/attributes.h +++ b/gruel/src/include/gruel/attributes.h @@ -53,6 +53,13 @@ # define __GR_ATTR_IMPORT #endif +//////////////////////////////////////////////////////////////////////// +// define inline when building C +//////////////////////////////////////////////////////////////////////// +#if defined(_MSC_VER) && !defined(__cplusplus) && !defined(inline) +# define inline __inline +#endif + //////////////////////////////////////////////////////////////////////// // suppress warnings //////////////////////////////////////////////////////////////////////// -- cgit From be41f9cce02a3955e392e02fdc5e3fe7e69e1f7e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 19 Aug 2011 15:57:24 -0700 Subject: gruel: removed merge junk in makefile --- gruel/src/include/gruel/Makefile.am | 2 -- 1 file changed, 2 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index d258f0379..fce739f08 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -26,8 +26,6 @@ EXTRA_DIST += inet.h.in gruelincludedir = $(prefix)/include/gruel gruelinclude_HEADERS = \ -<<<<<<< HEAD - $(BUILT_SOURCES) \ api.h \ attributes.h \ high_res_timer.h \ -- cgit From 4aa4411f2a3f184760ff5f534eec015f557f80c9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 24 Sep 2011 20:38:19 -0700 Subject: gruel: added missing pmt swig install rule --- gruel/src/swig/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index 05f875451..5b256a793 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -35,7 +35,7 @@ GR_SWIG_INSTALL( ) INSTALL( - FILES gr_intrusive_ptr.i + FILES gr_intrusive_ptr.i pmt_swig.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "gruel_swig" ) -- cgit From 5b1c7b73d0cb2dbbf944c3be670a7f2d74547e0f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Sep 2011 21:22:13 -0700 Subject: swig: language independent exception handler --- gruel/src/swig/pmt_swig.i | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gruel') diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 3b0eb45c8..34c7d4b7c 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -36,6 +36,24 @@ using namespace pmt; %} +//////////////////////////////////////////////////////////////////////// +// Language independent exception handler +//////////////////////////////////////////////////////////////////////// +%include exception.i + +%exception { + try { + $action + } + catch(std::exception &e) { + SWIG_exception(SWIG_RuntimeError, e.what()); + } + catch(...) { + SWIG_exception(SWIG_RuntimeError, "Unknown exception"); + } + +} + // Template intrusive_ptr for Swig to avoid dereferencing issues class pmt_base; //%import -- cgit From 71c0f14a46f85027b95f2f5f6d3d219cc9e3783e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 8 Oct 2011 17:11:12 -0700 Subject: gr: the CMakeLists.txt took a chill pill --- gruel/CMakeLists.txt | 32 +++++++++++----------- gruel/src/include/gruel/CMakeLists.txt | 10 +++---- gruel/src/lib/CMakeLists.txt | 46 ++++++++++++++++---------------- gruel/src/lib/msg/CMakeLists.txt | 2 +- gruel/src/lib/pmt/CMakeLists.txt | 20 +++++++------- gruel/src/python/CMakeLists.txt | 20 +++++++------- gruel/src/scheme/gnuradio/CMakeLists.txt | 2 +- gruel/src/swig/CMakeLists.txt | 10 +++---- 8 files changed, 71 insertions(+), 71 deletions(-) (limited to 'gruel') diff --git a/gruel/CMakeLists.txt b/gruel/CMakeLists.txt index 933e74b2f..b33217c14 100644 --- a/gruel/CMakeLists.txt +++ b/gruel/CMakeLists.txt @@ -20,20 +20,20 @@ ######################################################################## # Setup dependencies ######################################################################## -INCLUDE(GrBoost) +include(GrBoost) -INCLUDE(GrPython) #used for code generation +include(GrPython) #used for code generation ######################################################################## # Register component ######################################################################## -INCLUDE(GrComponent) +include(GrComponent) GR_REGISTER_COMPONENT("gruel" ENABLE_GRUEL Boost_FOUND PYTHONINTERP_FOUND ) -INCLUDE(GrMiscUtils) +include(GrMiscUtils) GR_SET_GLOBAL(GRUEL_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src/include @@ -43,12 +43,12 @@ GR_SET_GLOBAL(GRUEL_INCLUDE_DIRS ######################################################################## # Begin conditional configuration ######################################################################## -IF(ENABLE_GRUEL) +if(ENABLE_GRUEL) ######################################################################## # Setup CPack components ######################################################################## -INCLUDE(GrPackage) +include(GrPackage) CPACK_SET(CPACK_COMPONENT_GROUP_GRUEL_DESCRIPTION "GNU Radio Utility Etcetera Library") CPACK_COMPONENT("gruel_runtime" @@ -80,26 +80,26 @@ CPACK_COMPONENT("gruel_swig" ######################################################################## # Add subdirectories ######################################################################## -ADD_SUBDIRECTORY(src/include/gruel) -ADD_SUBDIRECTORY(src/scheme/gnuradio) -ADD_SUBDIRECTORY(src/lib) -IF(ENABLE_PYTHON) - ADD_SUBDIRECTORY(src/swig) - ADD_SUBDIRECTORY(src/python) -ENDIF(ENABLE_PYTHON) +add_subdirectory(src/include/gruel) +add_subdirectory(src/scheme/gnuradio) +add_subdirectory(src/lib) +if(ENABLE_PYTHON) + add_subdirectory(src/swig) + add_subdirectory(src/python) +endif(ENABLE_PYTHON) ######################################################################## # Create Pkg Config File ######################################################################## -CONFIGURE_FILE( +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/gruel.pc.in ${CMAKE_CURRENT_BINARY_DIR}/gruel.pc @ONLY) -INSTALL( +install( FILES ${CMAKE_CURRENT_BINARY_DIR}/gruel.pc DESTINATION ${GR_LIBRARY_DIR}/pkgconfig COMPONENT "gruel_devel" ) -ENDIF(ENABLE_GRUEL) +endif(ENABLE_GRUEL) diff --git a/gruel/src/include/gruel/CMakeLists.txt b/gruel/src/include/gruel/CMakeLists.txt index 2f80043a4..811856b98 100644 --- a/gruel/src/include/gruel/CMakeLists.txt +++ b/gruel/src/include/gruel/CMakeLists.txt @@ -20,15 +20,15 @@ ######################################################################## # Generate inet.h header file ######################################################################## -INCLUDE(TestBigEndian) -ENABLE_LANGUAGE(C) +include(TestBigEndian) +enable_language(C) TEST_BIG_ENDIAN(GR_ARCH_BIGENDIAN) -INCLUDE(CheckIncludeFileCXX) +include(CheckIncludeFileCXX) CHECK_INCLUDE_FILE_CXX(byteswap.h GR_HAVE_BYTESWAP) CHECK_INCLUDE_FILE_CXX(arpa/inet.h GR_HAVE_ARPA_INET) -CONFIGURE_FILE( +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/inet.h.in ${CMAKE_CURRENT_BINARY_DIR}/inet.h @ONLY) @@ -36,7 +36,7 @@ CONFIGURE_FILE( ######################################################################## # Install the headers ######################################################################## -INSTALL(FILES +install(FILES api.h attributes.h high_res_timer.h diff --git a/gruel/src/lib/CMakeLists.txt b/gruel/src/lib/CMakeLists.txt index d078e52f9..b54e644bc 100644 --- a/gruel/src/lib/CMakeLists.txt +++ b/gruel/src/lib/CMakeLists.txt @@ -20,13 +20,13 @@ ######################################################################## # Include subdirs rather to populate to the sources lists. ######################################################################## -INCLUDE(GrMiscUtils) -INCLUDE(CheckCXXSourceCompiles) +include(GrMiscUtils) +include(CheckCXXSourceCompiles) GR_CHECK_HDR_N_DEF(signal.h HAVE_SIGNAL_H) GR_CHECK_HDR_N_DEF(sched.h HAVE_SCHED_H) -SET(CMAKE_REQUIRED_LIBRARIES -lpthread) +set(CMAKE_REQUIRED_LIBRARIES -lpthread) CHECK_CXX_SOURCE_COMPILES(" #include int main(){pthread_sigmask(0, 0, 0); return 0;} @@ -34,7 +34,7 @@ CHECK_CXX_SOURCE_COMPILES(" ) GR_ADD_COND_DEF(HAVE_PTHREAD_SIGMASK) -SET(CMAKE_REQUIRED_LIBRARIES -lpthread) +set(CMAKE_REQUIRED_LIBRARIES -lpthread) CHECK_CXX_SOURCE_COMPILES(" #include int main(){ @@ -64,28 +64,28 @@ GR_INCLUDE_SUBDIRECTORY(pmt) ######################################################################## # Setup the include and linker paths ######################################################################## -INCLUDE_DIRECTORIES(${GRUEL_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${GRUEL_INCLUDE_DIRS}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) -LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) +include_directories(${Boost_INCLUDE_DIRS}) +link_directories(${Boost_LIBRARY_DIRS}) ######################################################################## # Setup library ######################################################################## -LIST(APPEND gruel_sources +list(APPEND gruel_sources realtime.cc sys_pri.cc thread_body_wrapper.cc thread_group.cc ) -ADD_LIBRARY(gruel SHARED ${gruel_sources}) -TARGET_LINK_LIBRARIES(gruel ${Boost_LIBRARIES}) -SET_TARGET_PROPERTIES(gruel PROPERTIES DEFINE_SYMBOL "gruel_EXPORTS") -SET_TARGET_PROPERTIES(gruel PROPERTIES SOVERSION ${LIBVER}) +add_library(gruel SHARED ${gruel_sources}) +target_link_libraries(gruel ${Boost_LIBRARIES}) +set_target_properties(gruel PROPERTIES DEFINE_SYMBOL "gruel_EXPORTS") +set_target_properties(gruel PROPERTIES SOVERSION ${LIBVER}) -INSTALL(TARGETS gruel +install(TARGETS gruel LIBRARY DESTINATION ${GR_LIBRARY_DIR} COMPONENT "gruel_runtime" # .so/.dylib file ARCHIVE DESTINATION ${GR_LIBRARY_DIR} COMPONENT "gruel_devel" # .lib file RUNTIME DESTINATION ${GR_RUNTIME_DIR} COMPONENT "gruel_runtime" # .dll file @@ -95,16 +95,16 @@ INSTALL(TARGETS gruel # Setup tests # Set the test environment so the build libs will be found under MSVC. ######################################################################## -IF(ENABLE_TESTING) +if(ENABLE_TESTING) -INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIRS}) -LINK_DIRECTORIES(${CPPUNIT_LIBRARY_DIRS}) +include_directories(${CPPUNIT_INCLUDE_DIRS}) +link_directories(${CPPUNIT_LIBRARY_DIRS}) -INCLUDE(GrTest) -SET(GR_TEST_TARGET_DEPS gruel) -LIST(APPEND test_gruel_sources test_gruel.cc) -ADD_EXECUTABLE(test_gruel ${test_gruel_sources}) -TARGET_LINK_LIBRARIES(test_gruel gruel ${CPPUNIT_LIBRARIES}) +include(GrTest) +set(GR_TEST_TARGET_DEPS gruel) +list(APPEND test_gruel_sources test_gruel.cc) +add_executable(test_gruel ${test_gruel_sources}) +target_link_libraries(test_gruel gruel ${CPPUNIT_LIBRARIES}) GR_ADD_TEST(gruel-test test_gruel) -ENDIF(ENABLE_TESTING) +endif(ENABLE_TESTING) diff --git a/gruel/src/lib/msg/CMakeLists.txt b/gruel/src/lib/msg/CMakeLists.txt index 877cc2909..116d2c67f 100644 --- a/gruel/src/lib/msg/CMakeLists.txt +++ b/gruel/src/lib/msg/CMakeLists.txt @@ -21,7 +21,7 @@ # This file included, use CMake directory variables ######################################################################## -LIST(APPEND gruel_sources +list(APPEND gruel_sources ${CMAKE_CURRENT_SOURCE_DIR}/msg_accepter.cc ${CMAKE_CURRENT_SOURCE_DIR}/msg_accepter_msgq.cc ${CMAKE_CURRENT_SOURCE_DIR}/msg_queue.cc diff --git a/gruel/src/lib/pmt/CMakeLists.txt b/gruel/src/lib/pmt/CMakeLists.txt index 797db475a..a708fa7ad 100644 --- a/gruel/src/lib/pmt/CMakeLists.txt +++ b/gruel/src/lib/pmt/CMakeLists.txt @@ -20,21 +20,21 @@ ######################################################################## # This file included, use CMake directory variables ######################################################################## -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) ######################################################################## # Generate serial tags header file ######################################################################## -GET_FILENAME_COMPONENT(SCHEME_DIR +get_filename_component(SCHEME_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../scheme/gnuradio ABSOLUTE ) -GET_FILENAME_COMPONENT(PMT_SERIAL_TAGS_H +get_filename_component(PMT_SERIAL_TAGS_H ${CMAKE_CURRENT_BINARY_DIR}/../../include/gruel/pmt_serial_tags.h ABSOLUTE ) -ADD_CUSTOM_COMMAND( +add_custom_command( OUTPUT ${PMT_SERIAL_TAGS_H} DEPENDS ${SCHEME_DIR}/gen-serial-tags.py DEPENDS ${SCHEME_DIR}/pmt-serial-tags.scm @@ -44,13 +44,13 @@ ADD_CUSTOM_COMMAND( ${PMT_SERIAL_TAGS_H} ) -INSTALL( +install( FILES ${PMT_SERIAL_TAGS_H} DESTINATION ${GR_INCLUDE_DIR}/gruel COMPONENT "gruel_devel" ) -INCLUDE(AddFileDependencies) +include(AddFileDependencies) ADD_FILE_DEPENDENCIES( ${CMAKE_CURRENT_SOURCE_DIR}/pmt_serialize.cc ${PMT_SERIAL_TAGS_H} @@ -59,7 +59,7 @@ ADD_FILE_DEPENDENCIES( ######################################################################## # Generate other pmt stuff ######################################################################## -ADD_CUSTOM_COMMAND( +add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pmt_unv_int.h ${CMAKE_CURRENT_BINARY_DIR}/qa_pmt_unv.h @@ -75,7 +75,7 @@ ADD_CUSTOM_COMMAND( WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) -LIST(APPEND gruel_sources +list(APPEND gruel_sources ${CMAKE_CURRENT_BINARY_DIR}/pmt_unv.cc ${CMAKE_CURRENT_SOURCE_DIR}/pmt.cc ${CMAKE_CURRENT_SOURCE_DIR}/pmt_io.cc @@ -83,7 +83,7 @@ LIST(APPEND gruel_sources ${CMAKE_CURRENT_SOURCE_DIR}/pmt_serialize.cc ) -LIST(APPEND test_gruel_sources +list(APPEND test_gruel_sources ${CMAKE_CURRENT_BINARY_DIR}/qa_pmt_unv.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_pmt_prims.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_pmt.cc diff --git a/gruel/src/python/CMakeLists.txt b/gruel/src/python/CMakeLists.txt index 491763cd7..be5ac956e 100644 --- a/gruel/src/python/CMakeLists.txt +++ b/gruel/src/python/CMakeLists.txt @@ -17,7 +17,7 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -INCLUDE(GrPython) +include(GrPython) ######################################################################## # Install python files @@ -37,16 +37,16 @@ GR_PYTHON_INSTALL( ######################################################################## # Setup unit tests ######################################################################## -IF(ENABLE_TESTING) -INCLUDE(GrTest) -FILE(GLOB py_qa_test_files "qa_*.py") -FOREACH(py_qa_test_file ${py_qa_test_files}) - GET_FILENAME_COMPONENT(py_qa_test_name ${py_qa_test_file} NAME_WE) - SET(GR_TEST_PYTHON_DIRS +if(ENABLE_TESTING) +include(GrTest) +file(GLOB py_qa_test_files "qa_*.py") +foreach(py_qa_test_file ${py_qa_test_files}) + get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) + set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/gruel/src/python ${CMAKE_BINARY_DIR}/gruel/src/swig ) - SET(GR_TEST_TARGET_DEPS gruel gnuradio-core) + set(GR_TEST_TARGET_DEPS gruel gnuradio-core) GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${py_qa_test_file}) -ENDFOREACH(py_qa_test_file) -ENDIF(ENABLE_TESTING) +endforeach(py_qa_test_file) +endif(ENABLE_TESTING) diff --git a/gruel/src/scheme/gnuradio/CMakeLists.txt b/gruel/src/scheme/gnuradio/CMakeLists.txt index bfa2a415f..4ff4f7feb 100644 --- a/gruel/src/scheme/gnuradio/CMakeLists.txt +++ b/gruel/src/scheme/gnuradio/CMakeLists.txt @@ -19,7 +19,7 @@ ######################################################################## -INSTALL(FILES +install(FILES pmt-serial-tags.scm pmt-serialize.scm macros-etc.scm diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index 5b256a793..c2769ae27 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -20,11 +20,11 @@ ######################################################################## # Setup swig generation ######################################################################## -INCLUDE(GrPython) -INCLUDE(GrSwig) +include(GrPython) +include(GrSwig) -SET(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS}) -SET(GR_SWIG_LIBRARIES gruel) +set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS}) +set(GR_SWIG_LIBRARIES gruel) GR_SWIG_MAKE(pmt_swig pmt_swig.i) @@ -34,7 +34,7 @@ GR_SWIG_INSTALL( COMPONENT "gruel_python" ) -INSTALL( +install( FILES gr_intrusive_ptr.i pmt_swig.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "gruel_swig" -- cgit From e30b824e9165bff69f09121631c3d5a706cbbd39 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 19 Oct 2011 15:10:58 -0700 Subject: Removing usrp, usrp2, gr-usrp, gr-usrp2. Everything is moving to using UHD. Also removes related M4 and dependency requirements for USRP-related libs. --- gruel/README | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'gruel') diff --git a/gruel/README b/gruel/README index 585cf026a..647dc843b 100644 --- a/gruel/README +++ b/gruel/README @@ -22,9 +22,8 @@ The GNU Radio Utility Etcetera Library, a collection of low-level routines to avoid dependencies on the full GNU Radio core or other libraries. -Over time, some code from libgnuradio-core, libpmt, libmblock, libusrp, -and libusrp2 will migrate here, to avoid duplication of code and simplify -dependencies. +Over time, some code from libgnuradio-core and libpmt will migrate +here, to avoid duplication of code and simplify dependencies. By design, this library will not have dependencies on any other part of GNU Radio, but may have external dependencies such as Boost. -- cgit From 7b1c5abe410470d25e49d0dadd265c430aaca1ec Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 20 Oct 2011 22:36:24 -0700 Subject: pmt: fix #446 by putting pmt swig into namespace --- gruel/src/swig/pmt_swig.i | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'gruel') diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 34c7d4b7c..276d232a4 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -20,7 +20,6 @@ * Boston, MA 02110-1301, USA. */ -%module pmt %include "std_string.i" %include "stdint.i" %{ @@ -33,7 +32,6 @@ #include #include #include -using namespace pmt; %} //////////////////////////////////////////////////////////////////////// @@ -55,10 +53,14 @@ using namespace pmt; } // Template intrusive_ptr for Swig to avoid dereferencing issues -class pmt_base; +namespace pmt{ + class pmt_base; +} //%import %import -%template(swig_int_ptr) boost::intrusive_ptr; +%template(swig_int_ptr) boost::intrusive_ptr; + +namespace pmt{ typedef boost::intrusive_ptr pmt_t; @@ -777,3 +779,5 @@ std::string pmt_serialize_str(pmt_t obj); * \brief Provide a simple string generating interface to pmt's deserialize function */ pmt_t pmt_deserialize_str(std::string str); + +} //namespace pmt -- cgit From faf7dea043728056bed5a7eb0529162eb7d9f932 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 23 Oct 2011 15:43:03 -0700 Subject: the libraries --- gruel/src/lib/CMakeLists.txt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/CMakeLists.txt b/gruel/src/lib/CMakeLists.txt index b54e644bc..a6aa1d992 100644 --- a/gruel/src/lib/CMakeLists.txt +++ b/gruel/src/lib/CMakeLists.txt @@ -82,14 +82,7 @@ list(APPEND gruel_sources add_library(gruel SHARED ${gruel_sources}) target_link_libraries(gruel ${Boost_LIBRARIES}) -set_target_properties(gruel PROPERTIES DEFINE_SYMBOL "gruel_EXPORTS") -set_target_properties(gruel PROPERTIES SOVERSION ${LIBVER}) - -install(TARGETS gruel - LIBRARY DESTINATION ${GR_LIBRARY_DIR} COMPONENT "gruel_runtime" # .so/.dylib file - ARCHIVE DESTINATION ${GR_LIBRARY_DIR} COMPONENT "gruel_devel" # .lib file - RUNTIME DESTINATION ${GR_RUNTIME_DIR} COMPONENT "gruel_runtime" # .dll file -) +GR_LIBRARY_FOO(gruel RUNTIME_COMPONENT "gruel_runtime" DEVEL_COMPONENT "gruel_devel") ######################################################################## # Setup tests -- cgit From 640e859f564361270d8cd30d7fbff582ad228110 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 1 Nov 2011 18:32:31 -0400 Subject: high_res_timer: Fix high_res_timer_now() for E100. Signed-off-by: Philip Balister --- gruel/src/include/gruel/high_res_timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/high_res_timer.h b/gruel/src/include/gruel/high_res_timer.h index fe9ae763f..9be524624 100644 --- a/gruel/src/include/gruel/high_res_timer.h +++ b/gruel/src/include/gruel/high_res_timer.h @@ -58,7 +58,7 @@ namespace gruel { inline gruel::high_res_timer_type gruel::high_res_timer_now(void){ timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return high_res_timer_type(ts.tv_sec*1000000000UL) + ts.tv_nsec; + return ts.tv_sec*high_res_timer_tps() + ts.tv_nsec; } inline gruel::high_res_timer_type gruel::high_res_timer_tps(void){ -- cgit From ea013f3566f8277ed3742e8e17a8c9b9f60939da Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 30 Oct 2011 18:33:53 -0700 Subject: gruel: added missing check GR_HAVE_NETINET_IN --- gruel/src/include/gruel/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/CMakeLists.txt b/gruel/src/include/gruel/CMakeLists.txt index 811856b98..9db810cae 100644 --- a/gruel/src/include/gruel/CMakeLists.txt +++ b/gruel/src/include/gruel/CMakeLists.txt @@ -27,6 +27,7 @@ TEST_BIG_ENDIAN(GR_ARCH_BIGENDIAN) include(CheckIncludeFileCXX) CHECK_INCLUDE_FILE_CXX(byteswap.h GR_HAVE_BYTESWAP) CHECK_INCLUDE_FILE_CXX(arpa/inet.h GR_HAVE_ARPA_INET) +CHECK_INCLUDE_FILE_CXX(netinet/in.h GR_HAVE_NETINET_IN) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/inet.h.in -- cgit From 40e8e55f47d201a2d74e674df39d5e19c82f3e1a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 3 Dec 2011 12:12:52 -0500 Subject: docs: adding a doc string for the gruel and gruel.pmt python modules. --- gruel/src/python/__init__.py | 4 ++++ gruel/src/python/pmt/__init__.py | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'gruel') diff --git a/gruel/src/python/__init__.py b/gruel/src/python/__init__.py index 14014cc5a..082ea26f2 100644 --- a/gruel/src/python/__init__.py +++ b/gruel/src/python/__init__.py @@ -21,5 +21,9 @@ # The presence of this file turns this directory into a Python package +''' +The GNU Radio Utility Etcetera Library. +''' + import pmt; diff --git a/gruel/src/python/pmt/__init__.py b/gruel/src/python/pmt/__init__.py index 421a9aaa8..2c4d33b59 100644 --- a/gruel/src/python/pmt/__init__.py +++ b/gruel/src/python/pmt/__init__.py @@ -21,5 +21,9 @@ # The presence of this file turns this directory into a Python package +''' +The GNU Radio Utility Etcetera Library's Polymorphic Types for Python. +''' + from pmt_swig import * -- cgit From 2f48e2a60e76072e5436dde860cd602c3882ce5c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 3 Dec 2011 12:13:23 -0500 Subject: docs: adding Python docstrings to gruel/pmt in cmake; dummy file make for autotools to build. --- gruel/src/swig/CMakeLists.txt | 3 +++ gruel/src/swig/Makefile.am | 12 ++++++++++++ gruel/src/swig/pmt_swig.i | 11 +++++++++++ 3 files changed, 26 insertions(+) (limited to 'gruel') diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index c2769ae27..c9651eb3f 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -26,6 +26,9 @@ include(GrSwig) set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS}) set(GR_SWIG_LIBRARIES gruel) +set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i) +set(GR_SWIG_DOC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../include/gruel ${CMAKE_CURRENT_BINARY_DIR}/../include/gruel) + GR_SWIG_MAKE(pmt_swig pmt_swig.i) GR_SWIG_INSTALL( diff --git a/gruel/src/swig/Makefile.am b/gruel/src/swig/Makefile.am index 3261e47c2..bf43e01fa 100644 --- a/gruel/src/swig/Makefile.am +++ b/gruel/src/swig/Makefile.am @@ -35,6 +35,18 @@ AM_CPPFLAGS = \ TOP_SWIG_IFILES = \ pmt_swig.i +TOP_SWIG_DOC_IFILES = \ + pmt_swig_doc.i + +BUILT_SOURCES += \ + $(TOP_SWIG_DOC_IFILES) + +$(TOP_SWIG_DOC_IFILES): + `echo "" > $@` + +install-data-local: + cp -p $(TOP_SWIG_DOC_IFILES) $(swigincludedir) + # Install so that they end up available as: # import gruel.pmt # This ends up at: diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 276d232a4..afc80433a 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -34,6 +34,9 @@ #include %} +//load generated python docstrings +%include "pmt_swig_doc.i" + //////////////////////////////////////////////////////////////////////// // Language independent exception handler //////////////////////////////////////////////////////////////////////// @@ -52,6 +55,14 @@ } +/*! + * \brief this is a test function. + * + * this is only a test. + */ +bool test_pmt_is_symbol(void); + + // Template intrusive_ptr for Swig to avoid dereferencing issues namespace pmt{ class pmt_base; -- cgit From f536b394f20ef88b426bf4bb6e9b69f6efb9847e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 4 Dec 2011 11:12:51 -0500 Subject: docs: install gruel swig docs and other swig files into include/gruel/swig instead of include/gnuradio/swig. --- gruel/src/swig/CMakeLists.txt | 1 + gruel/src/swig/Makefile.am | 10 ++++++---- gruel/src/swig/Makefile.swig.gen | 2 +- gruel/src/swig/pmt_swig.i | 8 -------- 4 files changed, 8 insertions(+), 13 deletions(-) (limited to 'gruel') diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index c9651eb3f..7d69ee549 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -39,6 +39,7 @@ GR_SWIG_INSTALL( install( FILES gr_intrusive_ptr.i pmt_swig.i + ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "gruel_swig" ) diff --git a/gruel/src/swig/Makefile.am b/gruel/src/swig/Makefile.am index bf43e01fa..9953d5566 100644 --- a/gruel/src/swig/Makefile.am +++ b/gruel/src/swig/Makefile.am @@ -33,6 +33,7 @@ AM_CPPFLAGS = \ ############################## # SWIG interface and library TOP_SWIG_IFILES = \ + pmt_swig_doc.i \ pmt_swig.i TOP_SWIG_DOC_IFILES = \ @@ -41,12 +42,12 @@ TOP_SWIG_DOC_IFILES = \ BUILT_SOURCES += \ $(TOP_SWIG_DOC_IFILES) +EXTRA_DIST += \ + $(TOP_SWIG_DOC_IFILES) + $(TOP_SWIG_DOC_IFILES): `echo "" > $@` -install-data-local: - cp -p $(TOP_SWIG_DOC_IFILES) $(swigincludedir) - # Install so that they end up available as: # import gruel.pmt # This ends up at: @@ -60,5 +61,6 @@ pmt_swig_la_swig_libadd = \ # additional SWIG files to be installed pmt_swig_swiginclude_headers = \ - gr_intrusive_ptr.i + gr_intrusive_ptr.i \ + $(TOP_SWIG_DOC_IFILES) diff --git a/gruel/src/swig/Makefile.swig.gen b/gruel/src/swig/Makefile.swig.gen index 97aff8104..0abba0299 100644 --- a/gruel/src/swig/Makefile.swig.gen +++ b/gruel/src/swig/Makefile.swig.gen @@ -50,7 +50,7 @@ pmt_swig_scmdir = $(guiledir) ## SWIG headers are always installed into the same directory. -pmt_swig_swigincludedir = $(swigincludedir) +pmt_swig_swigincludedir = $(gruelswigincludedir) ## This is a template file for a "generated" Makefile addition (in ## this case, "Makefile.swig.gen"). By including the top-level diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index afc80433a..0c937edfc 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -55,14 +55,6 @@ } -/*! - * \brief this is a test function. - * - * this is only a test. - */ -bool test_pmt_is_symbol(void); - - // Template intrusive_ptr for Swig to avoid dereferencing issues namespace pmt{ class pmt_base; -- cgit From 00420d32081d8252bb37142b2be19a8a7c4dc4c4 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 8 Dec 2011 13:48:48 -0800 Subject: Removed autotools, gr-waveform, some cleanup Nick Foster owes Nick Corgan a six-pack of beer! --- gruel/.gitignore | 3 - gruel/Makefile.am | 30 ---------- gruel/src/.gitignore | 2 - gruel/src/Makefile.am | 29 ---------- gruel/src/include/.gitignore | 2 - gruel/src/include/Makefile.am | 22 ------- gruel/src/include/gruel/.gitignore | 4 -- gruel/src/include/gruel/Makefile.am | 45 --------------- gruel/src/lib/.gitignore | 5 -- gruel/src/lib/Makefile.am | 68 ---------------------- gruel/src/lib/msg/.gitignore | 4 -- gruel/src/lib/msg/Makefile.am | 33 ----------- gruel/src/lib/pmt/.gitignore | 10 ---- gruel/src/lib/pmt/Makefile.am | 105 ---------------------------------- gruel/src/python/.gitignore | 3 - gruel/src/python/Makefile.am | 43 -------------- gruel/src/python/run_tests.in | 17 ------ gruel/src/scheme/.gitignore | 8 --- gruel/src/scheme/Makefile.am | 21 ------- gruel/src/scheme/gnuradio/.gitignore | 8 --- gruel/src/scheme/gnuradio/Makefile.am | 33 ----------- gruel/src/swig/.gitignore | 4 -- gruel/src/swig/Makefile.am | 66 --------------------- 23 files changed, 565 deletions(-) delete mode 100644 gruel/.gitignore delete mode 100644 gruel/Makefile.am delete mode 100644 gruel/src/.gitignore delete mode 100644 gruel/src/Makefile.am delete mode 100644 gruel/src/include/.gitignore delete mode 100644 gruel/src/include/Makefile.am delete mode 100644 gruel/src/include/gruel/.gitignore delete mode 100644 gruel/src/include/gruel/Makefile.am delete mode 100644 gruel/src/lib/.gitignore delete mode 100644 gruel/src/lib/Makefile.am delete mode 100644 gruel/src/lib/msg/.gitignore delete mode 100644 gruel/src/lib/msg/Makefile.am delete mode 100644 gruel/src/lib/pmt/.gitignore delete mode 100644 gruel/src/lib/pmt/Makefile.am delete mode 100644 gruel/src/python/.gitignore delete mode 100644 gruel/src/python/Makefile.am delete mode 100644 gruel/src/python/run_tests.in delete mode 100644 gruel/src/scheme/.gitignore delete mode 100644 gruel/src/scheme/Makefile.am delete mode 100644 gruel/src/scheme/gnuradio/.gitignore delete mode 100644 gruel/src/scheme/gnuradio/Makefile.am delete mode 100644 gruel/src/swig/.gitignore delete mode 100644 gruel/src/swig/Makefile.am (limited to 'gruel') diff --git a/gruel/.gitignore b/gruel/.gitignore deleted file mode 100644 index ede973f11..000000000 --- a/gruel/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/Makefile -/Makefile.in -/gruel.pc diff --git a/gruel/Makefile.am b/gruel/Makefile.am deleted file mode 100644 index c43e461f2..000000000 --- a/gruel/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -# -# Copyright 2008,2010 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 - -EXTRA_DIST += \ - gruel.pc.in - -SUBDIRS = src - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = gruel.pc diff --git a/gruel/src/.gitignore b/gruel/src/.gitignore deleted file mode 100644 index b336cc7ce..000000000 --- a/gruel/src/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/gruel/src/Makefile.am b/gruel/src/Makefile.am deleted file mode 100644 index 93b17d6db..000000000 --- a/gruel/src/Makefile.am +++ /dev/null @@ -1,29 +0,0 @@ -# -# Copyright 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., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -SUBDIRS = lib include scheme - -if PYTHON - -SUBDIRS += . swig python - -endif - diff --git a/gruel/src/include/.gitignore b/gruel/src/include/.gitignore deleted file mode 100644 index b336cc7ce..000000000 --- a/gruel/src/include/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/gruel/src/include/Makefile.am b/gruel/src/include/Makefile.am deleted file mode 100644 index 7a178810a..000000000 --- a/gruel/src/include/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright 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., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -SUBDIRS = gruel diff --git a/gruel/src/include/gruel/.gitignore b/gruel/src/include/gruel/.gitignore deleted file mode 100644 index bbe96391c..000000000 --- a/gruel/src/include/gruel/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/Makefile -/Makefile.in -/inet.h -/pmt_serial_tags.h diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am deleted file mode 100644 index fce739f08..000000000 --- a/gruel/src/include/gruel/Makefile.am +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright 2008-2011 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 - -EXTRA_DIST += inet.h.in - -gruelincludedir = $(prefix)/include/gruel - -gruelinclude_HEADERS = \ - api.h \ - attributes.h \ - high_res_timer.h \ - inet.h \ - 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 \ - sys_pri.h \ - thread_body_wrapper.h \ - thread_group.h \ - thread.h diff --git a/gruel/src/lib/.gitignore b/gruel/src/lib/.gitignore deleted file mode 100644 index 165e179d6..000000000 --- a/gruel/src/lib/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/Makefile -/Makefile.in -/.libs -/.deps -test_gruel diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am deleted file mode 100644 index 773f3aefd..000000000 --- a/gruel/src/lib/Makefile.am +++ /dev/null @@ -1,68 +0,0 @@ -# -# Copyright 2008,2009,2010,2011 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 - -SUBDIRS = pmt msg - -AM_CPPFLAGS = $(DEFINES) $(GRUEL_INCLUDES) $(BOOST_CPPFLAGS) \ - $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) - -TESTS = test_gruel - -noinst_PROGRAMS = test_gruel - - -lib_LTLIBRARIES = libgruel.la - -# magic flags -libgruel_la_LDFLAGS = $(NO_UNDEFINED) $(BOOST_LDFLAGS) $(LTVERSIONFLAGS) - -# ---------------------------------------------------------------- - -PMT_LIB = pmt/libpmt.la -MSG_LIB = msg/libmsg.la - -# These are the source files that go into the gruel shared library -libgruel_la_SOURCES = \ - realtime.cc \ - sys_pri.cc \ - thread_body_wrapper.cc \ - thread_group.cc - -libgruel_la_LIBADD = \ - $(BOOST_THREAD_LIB) \ - $(BOOST_SYSTEM_LIB) \ - $(BOOST_FILESYSTEM_LIB) \ - $(PMT_LIB) \ - $(MSG_LIB) \ - -lstdc++ - - -# ---------------------------------------------------------------- - -test_gruel_SOURCES = test_gruel.cc -test_gruel_LDADD = \ - $(BOOST_THREAD_LIB) \ - $(BOOST_SYSTEM_LIB) \ - $(BOOST_FILESYSTEM_LIB) \ - pmt/libpmt-qa.la libgruel.la - diff --git a/gruel/src/lib/msg/.gitignore b/gruel/src/lib/msg/.gitignore deleted file mode 100644 index c026fd667..000000000 --- a/gruel/src/lib/msg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs diff --git a/gruel/src/lib/msg/Makefile.am b/gruel/src/lib/msg/Makefile.am deleted file mode 100644 index 9dbaf10f5..000000000 --- a/gruel/src/lib/msg/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright 2009,2010 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) $(GRUEL_INCLUDES) \ - $(BOOST_CPPFLAGS) $(WITH_INCLUDES) - -noinst_LTLIBRARIES = libmsg.la - -libmsg_la_SOURCES = \ - msg_accepter.cc \ - msg_accepter_msgq.cc \ - msg_queue.cc - diff --git a/gruel/src/lib/pmt/.gitignore b/gruel/src/lib/pmt/.gitignore deleted file mode 100644 index 035c0316b..000000000 --- a/gruel/src/lib/pmt/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -/Makefile -/Makefile.in -/.libs -/.deps -/test_pmt -/qa_pmt_unv.cc -/qa_pmt_unv.h -/pmt_unv_int.h -/pmt_unv.cc -/stamp-sources-generate diff --git a/gruel/src/lib/pmt/Makefile.am b/gruel/src/lib/pmt/Makefile.am deleted file mode 100644 index 0c8e12dc3..000000000 --- a/gruel/src/lib/pmt/Makefile.am +++ /dev/null @@ -1,105 +0,0 @@ -# -# Copyright 2008,2009,2010,2011 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) $(GRUEL_INCLUDES) $(BOOST_CPPFLAGS) \ - $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) - -noinst_LTLIBRARIES = libpmt.la - -# ---------------------------------------------------------------- -# these scripts generate code - -code_generator = \ - generate_unv.py \ - unv_template.h.t \ - unv_template.cc.t \ - unv_qa_template.cc.t - -GENERATED_H = \ - pmt_unv_int.h \ - qa_pmt_unv.h - -GENERATED_CC = \ - pmt_unv.cc \ - qa_pmt_unv.cc - -python_built_sources = $(GENERATED_H) $(GENERATED_CC) - -PMT_SERIAL_TAGS_H = $(abs_top_builddir)/gruel/src/include/gruel/pmt_serial_tags.h -BUILT_SOURCES = $(python_built_sources) $(PMT_SERIAL_TAGS_H) - -EXTRA_DIST += $(code_generator) - -# ---------------------------------------------------------------- - -libpmt_la_SOURCES = \ - pmt.cc \ - pmt_io.cc \ - pmt_pool.cc \ - pmt_serialize.cc \ - pmt_unv.cc - -libpmt_la_LIBADD = \ - $(BOOST_THREAD_LIB) \ - -lstdc++ - -libpmt_la_LDFLAGS = \ - $(BOOST_LDFLAGS) - -noinst_HEADERS = \ - $(GENERATED_H) \ - pmt_int.h \ - qa_pmt.h \ - qa_pmt_prims.h - -# Build the qa code into its own library - -noinst_LTLIBRARIES += libpmt-qa.la - -libpmt_qa_la_SOURCES = \ - qa_pmt.cc \ - qa_pmt_prims.cc \ - qa_pmt_unv.cc - -# magic flags -libpmt_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid version - -libpmt_qa_la_LIBADD = \ - libpmt.la \ - $(CPPUNIT_LIBS) \ - -lstdc++ - - -# Do creation and inclusion of other Makefiles last - -# common way for generating sources from templates when using -# BUILT_SOURCES, using parallel build protection. -gen_sources = $(python_built_sources) -gen_sources_deps = $(core_generator) -par_gen_command = PYTHONPATH=$(top_srcdir)/gruel/src/lib/pmt srcdir=$(srcdir) $(PYTHON) $(srcdir)/generate_unv.py -include $(top_srcdir)/Makefile.par.gen - -# Rule to create the build header file using python -# Doesn't need parallel protections because there is a single target -$(PMT_SERIAL_TAGS_H): $(top_srcdir)/gruel/src/scheme/gnuradio/gen-serial-tags.py $(top_srcdir)/gruel/src/scheme/gnuradio/pmt-serial-tags.scm - $(PYTHON) $^ $@ diff --git a/gruel/src/python/.gitignore b/gruel/src/python/.gitignore deleted file mode 100644 index 604b402c5..000000000 --- a/gruel/src/python/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/Makefile -/Makefile.in -/run_tests diff --git a/gruel/src/python/Makefile.am b/gruel/src/python/Makefile.am deleted file mode 100644 index 80cb04b24..000000000 --- a/gruel/src/python/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright 2011 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 - -TESTS = -EXTRA_DIST += run_tests.in - -if PYTHON -TESTS += run_tests - -grueldir = $(pythondir)/gruel - -noinst_PYTHON = \ - qa_pmt.py - -gruel_PYTHON = \ - __init__.py - -gruelpmtdir = $(pythondir)/gruel/pmt - -gruelpmt_PYTHON = pmt/__init__.py - -endif - diff --git a/gruel/src/python/run_tests.in b/gruel/src/python/run_tests.in deleted file mode 100644 index ff399bcc6..000000000 --- a/gruel/src/python/run_tests.in +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -# 1st parameter is absolute path to component source directory -# 2nd parameter is absolute path to component build directory -# 3rd parameter is path to Python QA directory - -# For OS/X -DYLD_LIBRARY_PATH=@abs_top_builddir@/gruel/src/lib/:@abs_top_builddir@/gruel/src/swig/.libs:$DYLD_LIBRARY_PATH -export DYLD_LIBRARY_PATH - -# For Win32 -PATH=@abs_top_builddir@/gruel/:@abs_top_builddir@/gruel/.libs:$PATH - -@top_builddir@/run_tests.sh \ - @abs_top_srcdir@/gruel/src \ - @abs_top_builddir@/gruel/src \ - @srcdir@ diff --git a/gruel/src/scheme/.gitignore b/gruel/src/scheme/.gitignore deleted file mode 100644 index a02b6ff73..000000000 --- a/gruel/src/scheme/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo diff --git a/gruel/src/scheme/Makefile.am b/gruel/src/scheme/Makefile.am deleted file mode 100644 index 4980063d7..000000000 --- a/gruel/src/scheme/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -# -# 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. -# - -SUBDIRS = gnuradio diff --git a/gruel/src/scheme/gnuradio/.gitignore b/gruel/src/scheme/gnuradio/.gitignore deleted file mode 100644 index a02b6ff73..000000000 --- a/gruel/src/scheme/gnuradio/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo diff --git a/gruel/src/scheme/gnuradio/Makefile.am b/gruel/src/scheme/gnuradio/Makefile.am deleted file mode 100644 index e7b6bf744..000000000 --- a/gruel/src/scheme/gnuradio/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright 2007,2009,2010,2011 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 $(top_srcdir)/Makefile.common - -#pkgdatadir = $(datadir)/gnuradio - -EXTRA_DIST += \ - gen-serial-tags.py - -# really scheme source files FIXME wrong location -dist_pkgdata_DATA = \ - pmt-serial-tags.scm \ - pmt-serialize.scm \ - macros-etc.scm - diff --git a/gruel/src/swig/.gitignore b/gruel/src/swig/.gitignore deleted file mode 100644 index f99fdb19b..000000000 --- a/gruel/src/swig/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/Makefile -/Makefile.in -/python -/pmt_swig.py diff --git a/gruel/src/swig/Makefile.am b/gruel/src/swig/Makefile.am deleted file mode 100644 index 9953d5566..000000000 --- a/gruel/src/swig/Makefile.am +++ /dev/null @@ -1,66 +0,0 @@ -# -# Copyright 2011 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 -include $(top_srcdir)/Makefile.swig - -TESTS = - -AM_CPPFLAGS = \ - -I$(top_srcdir)/gruel/src/lib \ - $(STD_DEFINES_AND_INCLUDES) \ - $(PYTHON_CPPFLAGS) \ - $(WITH_INCLUDES) - -############################## -# SWIG interface and library -TOP_SWIG_IFILES = \ - pmt_swig_doc.i \ - pmt_swig.i - -TOP_SWIG_DOC_IFILES = \ - pmt_swig_doc.i - -BUILT_SOURCES += \ - $(TOP_SWIG_DOC_IFILES) - -EXTRA_DIST += \ - $(TOP_SWIG_DOC_IFILES) - -$(TOP_SWIG_DOC_IFILES): - `echo "" > $@` - -# Install so that they end up available as: -# import gruel.pmt -# This ends up at: -# ${prefix}/lib/python${python_version}/site-packages/gruel/pmt -pmt_swig_pythondir_category = \ - gruel/pmt - -# additional libraries for linking with the SWIG-generated library -pmt_swig_la_swig_libadd = \ - $(abs_top_builddir)/gruel/src/lib/pmt/libpmt.la - -# additional SWIG files to be installed -pmt_swig_swiginclude_headers = \ - gr_intrusive_ptr.i \ - $(TOP_SWIG_DOC_IFILES) - -- cgit From 7850d5f25168db322d76da9bc6cf3730c5d88d3e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 17 Jan 2012 15:48:02 -0800 Subject: gruel: hrt under bsd should use clock gettime --- gruel/src/include/gruel/high_res_timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/high_res_timer.h b/gruel/src/include/gruel/high_res_timer.h index 9be524624..63841f612 100644 --- a/gruel/src/include/gruel/high_res_timer.h +++ b/gruel/src/include/gruel/high_res_timer.h @@ -46,7 +46,7 @@ namespace gruel { #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) #define GRUEL_HRT_USE_MACH_ABSOLUTE_TIME #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - #define GRUEL_HRT_USE_MACH_ABSOLUTE_TIME + #define GRUEL_HRT_USE_CLOCK_GETTIME #else #define GRUEL_HRT_USE_MICROSEC_CLOCK #endif -- cgit From efa8df3c9c5db9dccef96305e6b702602661793d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 16 Mar 2012 12:45:59 -0700 Subject: gruel: run qa tests with -B (fix from gruel_work_squashed) --- gruel/src/python/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/python/CMakeLists.txt b/gruel/src/python/CMakeLists.txt index be5ac956e..13f2111ba 100644 --- a/gruel/src/python/CMakeLists.txt +++ b/gruel/src/python/CMakeLists.txt @@ -47,6 +47,6 @@ foreach(py_qa_test_file ${py_qa_test_files}) ${CMAKE_BINARY_DIR}/gruel/src/swig ) set(GR_TEST_TARGET_DEPS gruel gnuradio-core) - GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${py_qa_test_file}) + GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) endforeach(py_qa_test_file) endif(ENABLE_TESTING) -- cgit From f9a07338b9c7c0af19d64d24c47eaa9f7fe1ba38 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 16 Mar 2012 13:09:23 -0700 Subject: gruel: created common swig include file This work taken from gruel_work_squashed Common swig file includes: * Language independent exception handler * Wrapper for python calls that may block Benefits: * More common swig code, less copy pasta * Wrapper for blocking python calls handles the case where the call throws, python is not left in a bad state --- gruel/src/swig/CMakeLists.txt | 2 +- gruel/src/swig/Makefile.am | 1 + gruel/src/swig/gruel_common.i | 66 +++++++++++++++++++++++++++++++++++++++++++ gruel/src/swig/pmt_swig.i | 17 ++--------- 4 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 gruel/src/swig/gruel_common.i (limited to 'gruel') diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index 7d69ee549..6f636fc3f 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -38,7 +38,7 @@ GR_SWIG_INSTALL( ) install( - FILES gr_intrusive_ptr.i pmt_swig.i + FILES gr_intrusive_ptr.i pmt_swig.i gruel_common.i ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "gruel_swig" diff --git a/gruel/src/swig/Makefile.am b/gruel/src/swig/Makefile.am index 9953d5566..ce0a32513 100644 --- a/gruel/src/swig/Makefile.am +++ b/gruel/src/swig/Makefile.am @@ -61,6 +61,7 @@ pmt_swig_la_swig_libadd = \ # additional SWIG files to be installed pmt_swig_swiginclude_headers = \ + gruel_common.i \ gr_intrusive_ptr.i \ $(TOP_SWIG_DOC_IFILES) diff --git a/gruel/src/swig/gruel_common.i b/gruel/src/swig/gruel_common.i new file mode 100644 index 000000000..e4261cbfa --- /dev/null +++ b/gruel/src/swig/gruel_common.i @@ -0,0 +1,66 @@ +/* + * Copyright 2011 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. + */ + +#ifndef GRUEL_COMMON_I +#define GRUEL_COMMON_I + +//////////////////////////////////////////////////////////////////////// +// Language independent exception handler +//////////////////////////////////////////////////////////////////////// +%include exception.i + +%exception { + try { + $action + } + catch(std::exception &e) { + SWIG_exception(SWIG_RuntimeError, e.what()); + } + catch(...) { + SWIG_exception(SWIG_RuntimeError, "Unknown exception"); + } + +} + +//////////////////////////////////////////////////////////////////////// +// Wrapper for python calls that may block +//////////////////////////////////////////////////////////////////////// + +/*! + * Use GR_PYTHON_BLOCKING_CODE when calling code that blocks. + * + * The try/catch is to save us from boost::thread::interrupt: + * If a thread from the scheduler (or any other boost thread) + * is blocking the routine and throws an interrupt exception. + */ +%{ + +#define GR_PYTHON_BLOCKING_CODE(code) { \ + PyThreadState *_save; \ + _save = PyEval_SaveThread(); \ + try{code} \ + catch(...){PyEval_RestoreThread(_save); throw;} \ + PyEval_RestoreThread(_save); \ +} + +%} + +#endif /*GRUEL_COMMON_I*/ diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 0c937edfc..954501863 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2011 Free Software Foundation, Inc. + * Copyright 2011-2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -34,26 +34,13 @@ #include %} +%include "gruel_common.i" //load generated python docstrings %include "pmt_swig_doc.i" //////////////////////////////////////////////////////////////////////// // Language independent exception handler //////////////////////////////////////////////////////////////////////// -%include exception.i - -%exception { - try { - $action - } - catch(std::exception &e) { - SWIG_exception(SWIG_RuntimeError, e.what()); - } - catch(...) { - SWIG_exception(SWIG_RuntimeError, "Unknown exception"); - } - -} // Template intrusive_ptr for Swig to avoid dereferencing issues namespace pmt{ -- cgit From f95a0abbd501142468b33d63bda0ca69e56cea5b Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Fri, 23 Mar 2012 12:06:53 -0700 Subject: cmake: fix include path order in gruel --- gruel/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/CMakeLists.txt b/gruel/CMakeLists.txt index b33217c14..5fdc2b218 100644 --- a/gruel/CMakeLists.txt +++ b/gruel/CMakeLists.txt @@ -35,9 +35,9 @@ GR_REGISTER_COMPONENT("gruel" ENABLE_GRUEL include(GrMiscUtils) GR_SET_GLOBAL(GRUEL_INCLUDE_DIRS - ${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src/include ${CMAKE_CURRENT_BINARY_DIR}/src/include + ${Boost_INCLUDE_DIRS} ) ######################################################################## -- cgit From 2bf64459036916258dcf3269cec47904fdeba8f6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 1 Apr 2012 16:13:42 -0400 Subject: Removes all references to guile and scheme, which are no longer needed. The remaining pmt_serial_tags.scm is parsed by Python already. Future modifications could change this format to not confuse the point. --- gruel/CMakeLists.txt | 1 - gruel/src/lib/pmt/CMakeLists.txt | 11 +- gruel/src/lib/pmt/gen-serial-tags.py | 53 ++++++++++ gruel/src/lib/pmt/pmt-serial-tags.scm | 75 +++++++++++++ gruel/src/scheme/gnuradio/CMakeLists.txt | 26 ----- gruel/src/scheme/gnuradio/gen-serial-tags.py | 53 ---------- gruel/src/scheme/gnuradio/macros-etc.scm | 50 --------- gruel/src/scheme/gnuradio/pmt-serial-tags.scm | 75 ------------- gruel/src/scheme/gnuradio/pmt-serialize.scm | 48 --------- gruel/src/swig/Makefile.swig.gen | 145 -------------------------- 10 files changed, 132 insertions(+), 405 deletions(-) create mode 100644 gruel/src/lib/pmt/gen-serial-tags.py create mode 100644 gruel/src/lib/pmt/pmt-serial-tags.scm delete mode 100644 gruel/src/scheme/gnuradio/CMakeLists.txt delete mode 100644 gruel/src/scheme/gnuradio/gen-serial-tags.py delete mode 100644 gruel/src/scheme/gnuradio/macros-etc.scm delete mode 100644 gruel/src/scheme/gnuradio/pmt-serial-tags.scm delete mode 100644 gruel/src/scheme/gnuradio/pmt-serialize.scm delete mode 100644 gruel/src/swig/Makefile.swig.gen (limited to 'gruel') diff --git a/gruel/CMakeLists.txt b/gruel/CMakeLists.txt index 5fdc2b218..558248d08 100644 --- a/gruel/CMakeLists.txt +++ b/gruel/CMakeLists.txt @@ -81,7 +81,6 @@ CPACK_COMPONENT("gruel_swig" # Add subdirectories ######################################################################## add_subdirectory(src/include/gruel) -add_subdirectory(src/scheme/gnuradio) add_subdirectory(src/lib) if(ENABLE_PYTHON) add_subdirectory(src/swig) diff --git a/gruel/src/lib/pmt/CMakeLists.txt b/gruel/src/lib/pmt/CMakeLists.txt index a708fa7ad..a8e15cac6 100644 --- a/gruel/src/lib/pmt/CMakeLists.txt +++ b/gruel/src/lib/pmt/CMakeLists.txt @@ -26,9 +26,6 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) ######################################################################## # Generate serial tags header file ######################################################################## -get_filename_component(SCHEME_DIR - ${CMAKE_CURRENT_SOURCE_DIR}/../../scheme/gnuradio ABSOLUTE -) get_filename_component(PMT_SERIAL_TAGS_H ${CMAKE_CURRENT_BINARY_DIR}/../../include/gruel/pmt_serial_tags.h ABSOLUTE @@ -36,11 +33,11 @@ get_filename_component(PMT_SERIAL_TAGS_H add_custom_command( OUTPUT ${PMT_SERIAL_TAGS_H} - DEPENDS ${SCHEME_DIR}/gen-serial-tags.py - DEPENDS ${SCHEME_DIR}/pmt-serial-tags.scm + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gen-serial-tags.py + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pmt-serial-tags.scm COMMAND ${PYTHON_EXECUTABLE} - ${SCHEME_DIR}/gen-serial-tags.py - ${SCHEME_DIR}/pmt-serial-tags.scm + ${CMAKE_CURRENT_SOURCE_DIR}/gen-serial-tags.py + ${CMAKE_CURRENT_SOURCE_DIR}/pmt-serial-tags.scm ${PMT_SERIAL_TAGS_H} ) diff --git a/gruel/src/lib/pmt/gen-serial-tags.py b/gruel/src/lib/pmt/gen-serial-tags.py new file mode 100644 index 000000000..18e927beb --- /dev/null +++ b/gruel/src/lib/pmt/gen-serial-tags.py @@ -0,0 +1,53 @@ +""" +// +// Copyright 2011 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. +// +// +// THIS FILE IS MACHINE GENERATED FROM %s. DO NOT EDIT BY HAND. +// See %s for additional commentary. +// + +#ifndef INCLUDED_PMT_SERIAL_TAGS_H +#define INCLUDED_PMT_SERIAL_TAGS_H + +enum pst_tags { +%s +}; +#endif /* INCLUDED_PMT_SERIAL_TAGS_H */ +""" + +import sys, os, re + +if __name__ == '__main__': + if len(sys.argv) != 3: + print "Usage %s "%__file__ + exit() + input_scm_file, output_hdr_file = sys.argv[1:] + enums = list() + for line in open(input_scm_file).readlines(): + match = re.match('^\s*\(define\s+([\w|-]+)\s+#x([0-9a-fA-F]+)\)', line) + if not match: continue + name, value = match.groups() + name = name.upper().replace('-', '_') + enums.append(' %s = 0x%s'%(name, value)) + open(output_hdr_file, 'w').write(__doc__%( + os.path.basename(__file__), + os.path.basename(input_scm_file), + ',\n'.join(enums), + )) diff --git a/gruel/src/lib/pmt/pmt-serial-tags.scm b/gruel/src/lib/pmt/pmt-serial-tags.scm new file mode 100644 index 000000000..646a751ea --- /dev/null +++ b/gruel/src/lib/pmt/pmt-serial-tags.scm @@ -0,0 +1,75 @@ +;;; -*-scheme-*- +;;; +;;; 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 (define 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. +;;; + +;;; definitions of tag values used for marshalling pmt data + +(define pst-true #x00) +(define pst-false #x01) +(define pst-symbol #x02) ; untagged-int16 n; followed by n bytes of symbol name +(define pst-int32 #x03) +(define pst-double #x04) +(define pst-complex #x05) ; complex: real, imag +(define pst-null #x06) +(define pst-pair #x07) ; followed by two objects +(define pst-vector #x08) ; untagged-int32 n; followed by n objects +(define pst-dict #x09) ; untagged-int32 n; followed by n key/value tuples + +(define pst-uniform-vector #x0a) + +;; u8, s8, u16, s16, u32, s32, u64, s64, f32, f64, c32, c64 +;; +;; untagged-uint8 tag +;; untagged-uint8 uvi (define uniform vector info, see below) +;; untagged-int32 n-items +;; untagged-uint8 npad +;; npad bytes of zeros to align binary data +;; n-items binary numeric items +;; +;; uvi: +;; +-+-+-+-+-+-+-+-+ +;; |B| subtype | +;; +-+-+-+-+-+-+-+-+ +;; +;; B == 0, numeric data is little-endian. +;; B == 1, numeric data is big-endian. + + (define uvi-endian-mask #x80) + (define uvi-subtype-mask #x7f) + + (define uvi-little-endian #x00) + (define uvi-big-endian #x80) + + (define uvi-u8 #x00) + (define uvi-s8 #x01) + (define uvi-u16 #x02) + (define uvi-s16 #x03) + (define uvi-u32 #x04) + (define uvi-s32 #x05) + (define uvi-u64 #x06) + (define uvi-s64 #x07) + (define uvi-f32 #x08) + (define uvi-f64 #x09) + (define uvi-c32 #x0a) + (define uvi-c64 #x0b) + + +(define pst-comment #x3b) ; ascii ';' +(define pst-comment-end #x0a) ; ascii '\n' diff --git a/gruel/src/scheme/gnuradio/CMakeLists.txt b/gruel/src/scheme/gnuradio/CMakeLists.txt deleted file mode 100644 index 4ff4f7feb..000000000 --- a/gruel/src/scheme/gnuradio/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2010 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. - -######################################################################## - -install(FILES - pmt-serial-tags.scm - pmt-serialize.scm - macros-etc.scm -DESTINATION ${GR_PKG_DATA_DIR} COMPONENT "gruel_swig") diff --git a/gruel/src/scheme/gnuradio/gen-serial-tags.py b/gruel/src/scheme/gnuradio/gen-serial-tags.py deleted file mode 100644 index 18e927beb..000000000 --- a/gruel/src/scheme/gnuradio/gen-serial-tags.py +++ /dev/null @@ -1,53 +0,0 @@ -""" -// -// Copyright 2011 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. -// -// -// THIS FILE IS MACHINE GENERATED FROM %s. DO NOT EDIT BY HAND. -// See %s for additional commentary. -// - -#ifndef INCLUDED_PMT_SERIAL_TAGS_H -#define INCLUDED_PMT_SERIAL_TAGS_H - -enum pst_tags { -%s -}; -#endif /* INCLUDED_PMT_SERIAL_TAGS_H */ -""" - -import sys, os, re - -if __name__ == '__main__': - if len(sys.argv) != 3: - print "Usage %s "%__file__ - exit() - input_scm_file, output_hdr_file = sys.argv[1:] - enums = list() - for line in open(input_scm_file).readlines(): - match = re.match('^\s*\(define\s+([\w|-]+)\s+#x([0-9a-fA-F]+)\)', line) - if not match: continue - name, value = match.groups() - name = name.upper().replace('-', '_') - enums.append(' %s = 0x%s'%(name, value)) - open(output_hdr_file, 'w').write(__doc__%( - os.path.basename(__file__), - os.path.basename(input_scm_file), - ',\n'.join(enums), - )) diff --git a/gruel/src/scheme/gnuradio/macros-etc.scm b/gruel/src/scheme/gnuradio/macros-etc.scm deleted file mode 100644 index ac2a4a342..000000000 --- a/gruel/src/scheme/gnuradio/macros-etc.scm +++ /dev/null @@ -1,50 +0,0 @@ -;;; -*- scheme -*- -;;; -;;; 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. -;;; - -(define-module (gnuradio macros-etc) - :export (atom? when unless for-each-in-file)) - -(define (atom? obj) - (not (pair? obj))) - -(defmacro when (pred . body) - `(if ,pred (begin ,@body) #f)) - -(defmacro unless (pred . body) - `(if (not ,pred) (begin ,@body) #f)) - - -(define (for-each-in-file file f) - (let ((port (if (port? file) - file - (open-input-file file)))) - (letrec - ((loop - (lambda (port form) - (cond ((eof-object? form) - (when (not (eq? port file)) - (close-input-port port)) - #t) - (else - (f form) - (set! form #f) ; for GC - (loop port (read port))))))) - (loop port (read port))))) diff --git a/gruel/src/scheme/gnuradio/pmt-serial-tags.scm b/gruel/src/scheme/gnuradio/pmt-serial-tags.scm deleted file mode 100644 index 646a751ea..000000000 --- a/gruel/src/scheme/gnuradio/pmt-serial-tags.scm +++ /dev/null @@ -1,75 +0,0 @@ -;;; -*-scheme-*- -;;; -;;; 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 (define 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. -;;; - -;;; definitions of tag values used for marshalling pmt data - -(define pst-true #x00) -(define pst-false #x01) -(define pst-symbol #x02) ; untagged-int16 n; followed by n bytes of symbol name -(define pst-int32 #x03) -(define pst-double #x04) -(define pst-complex #x05) ; complex: real, imag -(define pst-null #x06) -(define pst-pair #x07) ; followed by two objects -(define pst-vector #x08) ; untagged-int32 n; followed by n objects -(define pst-dict #x09) ; untagged-int32 n; followed by n key/value tuples - -(define pst-uniform-vector #x0a) - -;; u8, s8, u16, s16, u32, s32, u64, s64, f32, f64, c32, c64 -;; -;; untagged-uint8 tag -;; untagged-uint8 uvi (define uniform vector info, see below) -;; untagged-int32 n-items -;; untagged-uint8 npad -;; npad bytes of zeros to align binary data -;; n-items binary numeric items -;; -;; uvi: -;; +-+-+-+-+-+-+-+-+ -;; |B| subtype | -;; +-+-+-+-+-+-+-+-+ -;; -;; B == 0, numeric data is little-endian. -;; B == 1, numeric data is big-endian. - - (define uvi-endian-mask #x80) - (define uvi-subtype-mask #x7f) - - (define uvi-little-endian #x00) - (define uvi-big-endian #x80) - - (define uvi-u8 #x00) - (define uvi-s8 #x01) - (define uvi-u16 #x02) - (define uvi-s16 #x03) - (define uvi-u32 #x04) - (define uvi-s32 #x05) - (define uvi-u64 #x06) - (define uvi-s64 #x07) - (define uvi-f32 #x08) - (define uvi-f64 #x09) - (define uvi-c32 #x0a) - (define uvi-c64 #x0b) - - -(define pst-comment #x3b) ; ascii ';' -(define pst-comment-end #x0a) ; ascii '\n' diff --git a/gruel/src/scheme/gnuradio/pmt-serialize.scm b/gruel/src/scheme/gnuradio/pmt-serialize.scm deleted file mode 100644 index c1d32d75b..000000000 --- a/gruel/src/scheme/gnuradio/pmt-serialize.scm +++ /dev/null @@ -1,48 +0,0 @@ -;;; -;;; 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. -;;; - -;;; An implementation of pmt_serialize in scheme. -;;; Currently handles only symbols and pairs. They're all we need for now. - -(define-module (gnuradio pmt-serialize) - :export (pmt-serialize)) - -(load-from-path "gnuradio/pmt-serial-tags") - -(define (pmt-serialize obj put-byte) - (define (put-u16 x) - (put-byte (logand (ash x -8) #xff)) - (put-byte (logand x #xff))) - - (cond ((null? obj) - (put-byte pst-null)) - ((symbol? obj) - (let* ((sym-as-bytes (map char->integer (string->list (symbol->string obj)))) - (len (length sym-as-bytes))) - (put-byte pst-symbol) - (put-u16 len) - (for-each put-byte sym-as-bytes))) - - ((pair? obj) - (put-byte pst-pair) - (pmt-serialize (car obj) put-byte) - (pmt-serialize (cdr obj) put-byte)) - (else - (throw 'not-implemented "pmt-serialize" obj)))) diff --git a/gruel/src/swig/Makefile.swig.gen b/gruel/src/swig/Makefile.swig.gen deleted file mode 100644 index 0abba0299..000000000 --- a/gruel/src/swig/Makefile.swig.gen +++ /dev/null @@ -1,145 +0,0 @@ -# -*- Makefile -*- -# -# 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -# Makefile.swig.gen for pmt_swig.i - -## Default install locations for these files: -## -## Default location for the Python directory is: -## ${prefix}/lib/python${python_version}/site-packages/[category]/pmt_swig -## Default location for the Python exec directory is: -## ${exec_prefix}/lib/python${python_version}/site-packages/[category]/pmt_swig -## -## The following can be overloaded to change the install location, but -## this has to be done in the including Makefile.am -before- -## Makefile.swig is included. - -pmt_swig_pythondir_category ?= gnuradio/pmt_swig -pmt_swig_pylibdir_category ?= $(pmt_swig_pythondir_category) -pmt_swig_pythondir = $(pythondir)/$(pmt_swig_pythondir_category) -pmt_swig_pylibdir = $(pyexecdir)/$(pmt_swig_pylibdir_category) - -# The .so libraries for the guile modules get installed whereever guile -# is installed, usually /usr/lib/guile/gnuradio/ -# FIXME: determince whether these should be installed with gnuradio. -pmt_swig_scmlibdir = $(libdir) - -# The scm files for the guile modules get installed where ever guile -# is installed, usually /usr/share/guile/site/pmt_swig -# FIXME: determince whether these should be installed with gnuradio. -pmt_swig_scmdir = $(guiledir) - -## SWIG headers are always installed into the same directory. - -pmt_swig_swigincludedir = $(gruelswigincludedir) - -## This is a template file for a "generated" Makefile addition (in -## this case, "Makefile.swig.gen"). By including the top-level -## Makefile.swig, this file will be used to generate the SWIG -## dependencies. Assign the variable TOP_SWIG_FILES to be the list of -## SWIG .i files to generated wrappings for; there can be more than 1 -## so long as the names are unique (no sorting is done on the -## TOP_SWIG_FILES list). This file explicitly assumes that a SWIG .i -## file will generate .cc, .py, and possibly .h files -- meaning that -## all of these files will have the same base name (that provided for -## the SWIG .i file). -## -## This code is setup to ensure parallel MAKE ("-j" or "-jN") does the -## right thing. For more info, see < -## http://sources.redhat.com/automake/automake.html#Multiple-Outputs > - -## Other cleaned files: dependency files generated by SWIG or this Makefile - -MOSTLYCLEANFILES += $(DEPDIR)/*.S* - -## Various SWIG variables. These can be overloaded in the including -## Makefile.am by setting the variable value there, then including -## Makefile.swig . - -pmt_swig_swiginclude_HEADERS = \ - pmt_swig.i \ - $(pmt_swig_swiginclude_headers) - -if PYTHON -pmt_swig_pylib_LTLIBRARIES = \ - _pmt_swig.la - -_pmt_swig_la_SOURCES = \ - python/pmt_swig.cc \ - $(pmt_swig_la_swig_sources) - -pmt_swig_python_PYTHON = \ - pmt_swig.py \ - $(pmt_swig_python) - -_pmt_swig_la_LIBADD = \ - $(STD_SWIG_LA_LIB_ADD) \ - $(pmt_swig_la_swig_libadd) - -_pmt_swig_la_LDFLAGS = \ - $(STD_SWIG_LA_LD_FLAGS) \ - $(pmt_swig_la_swig_ldflags) - -_pmt_swig_la_CXXFLAGS = \ - $(STD_SWIG_CXX_FLAGS) \ - -I$(top_builddir) \ - $(pmt_swig_la_swig_cxxflags) - -python/pmt_swig.cc: pmt_swig.py -pmt_swig.py: pmt_swig.i - -# Include the python dependencies for this file --include python/pmt_swig.d - -endif # end of if python - -if GUILE - -pmt_swig_scmlib_LTLIBRARIES = \ - libguile-gnuradio-pmt_swig.la -libguile_gnuradio_pmt_swig_la_SOURCES = \ - guile/pmt_swig.cc \ - $(pmt_swig_la_swig_sources) -nobase_pmt_swig_scm_DATA = \ - gnuradio/pmt_swig.scm \ - gnuradio/pmt_swig-primitive.scm -libguile_gnuradio_pmt_swig_la_LIBADD = \ - $(STD_SWIG_LA_LIB_ADD) \ - $(pmt_swig_la_swig_libadd) -libguile_gnuradio_pmt_swig_la_LDFLAGS = \ - $(STD_SWIG_LA_LD_FLAGS) \ - $(pmt_swig_la_swig_ldflags) -libguile_gnuradio_pmt_swig_la_CXXFLAGS = \ - $(STD_SWIG_CXX_FLAGS) \ - -I$(top_builddir) \ - $(pmt_swig_la_swig_cxxflags) - -guile/pmt_swig.cc: gnuradio/pmt_swig.scm -gnuradio/pmt_swig.scm: pmt_swig.i -gnuradio/pmt_swig-primitive.scm: gnuradio/pmt_swig.scm - -# Include the guile dependencies for this file --include guile/pmt_swig.d - -endif # end of GUILE - - -- cgit From 6cf6dc9c76bbacbecdb808c451ede9031668b34c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 3 Apr 2012 14:50:06 -0700 Subject: pmt: added advanded pmt_set_deleter (c++ only) --- gruel/src/include/gruel/pmt.h | 19 +++++++++++++++++++ gruel/src/lib/pmt/pmt.cc | 14 +++++++++++++- gruel/src/lib/pmt/pmt_int.h | 9 ++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 58533e54e..f904d37e1 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace gruel { class msg_accepter; @@ -805,6 +806,24 @@ GRUEL_API std::string pmt_serialize_str(pmt_t obj); */ GRUEL_API pmt_t pmt_deserialize_str(std::string str); +/* + * ------------------------------------------------------------------------ + * advanced + * ------------------------------------------------------------------------ + */ + +#define GRUEL_PMT_HAVE_PMT_SET_DELETER + +/*! + * Set a deleter function to be called when the PMT dereferences. + * User beware! This function is for extremely advanced use. + * Use boost bind to bind extra parameters into the deleter function. + * Set an empty function type to reset the PMT to the default deleter. + * \param obj the pmt object in which to set the deleter function + * \param deleter a function that gets an opaque PMT pointer type + */ +GRUEL_API void pmt_set_deleter(pmt_t obj, boost::function &deleter); + } /* namespace pmt */ #include diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index f9cf6b4bf..57b66b1a4 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -58,7 +58,7 @@ pmt_base::operator delete(void *p, size_t size) #endif void intrusive_ptr_add_ref(pmt_base* p) { ++(p->count_); } -void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) delete p; } +void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) p->deleter_(p); } pmt_base::~pmt_base() { @@ -1383,4 +1383,16 @@ pmt_dump_sizeof() printf("sizeof(pmt_uniform_vector) = %3zd\n", sizeof(pmt_uniform_vector)); } +/* + * ------------------------------------------------------------------------ + * advanced + * ------------------------------------------------------------------------ + */ + +void +pmt_set_deleter(pmt_t obj, boost::function &deleter) +{ + obj->deleter_ = (deleter)? deleter : &pmt_base::default_deleter; +} + } /* namespace pmt */ diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h index 3a5cd382b..745dbc666 100644 --- a/gruel/src/lib/pmt/pmt_int.h +++ b/gruel/src/lib/pmt/pmt_int.h @@ -38,8 +38,15 @@ namespace pmt { class GRUEL_API pmt_base : boost::noncopyable { mutable boost::detail::atomic_count count_; +public: + static void default_deleter(pmt_base *p){ + delete p; + } + + boost::function deleter_; + protected: - pmt_base() : count_(0) {}; + pmt_base() : count_(0), deleter_(&pmt::pmt_base::default_deleter) {}; virtual ~pmt_base(); public: -- cgit From aaa98c095a85724a8782a28717162c1d30d865c2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 7 Apr 2012 20:03:25 -0400 Subject: gruel and howto: install gruel .i files in gruel dest. Howto will use that dir during build. howto under both cmake and autotools can be built off cmake or autotools gnuradio builds. --- gruel/src/swig/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index 7d69ee549..8b4defc20 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -40,6 +40,6 @@ GR_SWIG_INSTALL( install( FILES gr_intrusive_ptr.i pmt_swig.i ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i - DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig + DESTINATION ${GR_INCLUDE_DIR}/gruel/swig COMPONENT "gruel_swig" ) -- cgit From f919f9dcbb54a08e6e26d6c229ce92fb784fa1b2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 13 Apr 2012 18:36:53 -0400 Subject: Removed whitespace and added dtools/bin/remove-whitespace as a tool to do this in the future. The sed script was provided by Moritz Fischer. --- gruel/CMakeLists.txt | 8 +++---- gruel/README | 10 ++++----- gruel/gruel.pc.in | 2 +- gruel/src/include/gruel/CMakeLists.txt | 8 +++---- gruel/src/include/gruel/high_res_timer.h | 8 +++---- gruel/src/include/gruel/inet.h.in | 2 +- gruel/src/include/gruel/msg_accepter.h | 8 +++---- gruel/src/include/gruel/msg_accepter_msgq.h | 10 ++++----- gruel/src/include/gruel/msg_passing.h | 8 +++---- gruel/src/include/gruel/msg_queue.h | 16 +++++++------- gruel/src/include/gruel/pmt.h | 16 +++++++------- gruel/src/include/gruel/pmt_pool.h | 12 +++++------ gruel/src/include/gruel/pmt_sugar.h | 10 ++++----- gruel/src/include/gruel/realtime.h | 10 ++++----- gruel/src/include/gruel/sys_pri.h | 8 +++---- gruel/src/include/gruel/thread.h | 8 +++---- gruel/src/include/gruel/thread_body_wrapper.h | 10 ++++----- gruel/src/include/gruel/thread_group.h | 2 +- gruel/src/lib/CMakeLists.txt | 8 +++---- gruel/src/lib/msg/CMakeLists.txt | 8 +++---- gruel/src/lib/msg/msg_accepter.cc | 8 +++---- gruel/src/lib/msg/msg_accepter_msgq.cc | 8 +++---- gruel/src/lib/msg/msg_queue.cc | 14 ++++++------- gruel/src/lib/pmt/CMakeLists.txt | 8 +++---- gruel/src/lib/pmt/generate_unv.py | 24 ++++++++++----------- gruel/src/lib/pmt/pmt-serial-tags.scm | 8 +++---- gruel/src/lib/pmt/pmt.cc | 30 +++++++++++++-------------- gruel/src/lib/pmt/pmt_int.h | 10 ++++----- gruel/src/lib/pmt/pmt_io.cc | 14 ++++++------- gruel/src/lib/pmt/pmt_pool.cc | 8 +++---- gruel/src/lib/pmt/pmt_serialize.cc | 22 ++++++++++---------- gruel/src/lib/pmt/qa_pmt.cc | 10 ++++----- gruel/src/lib/pmt/qa_pmt.h | 8 +++---- gruel/src/lib/pmt/qa_pmt_prims.cc | 18 ++++++++-------- gruel/src/lib/pmt/qa_pmt_prims.h | 8 +++---- gruel/src/lib/pmt/unv_template.cc.t | 2 +- gruel/src/lib/realtime.cc | 12 +++++------ gruel/src/lib/sys_pri.cc | 8 +++---- gruel/src/lib/test_gruel.cc | 12 +++++------ gruel/src/lib/thread_body_wrapper.cc | 10 ++++----- gruel/src/lib/thread_group.cc | 2 +- gruel/src/python/__init__.py | 10 ++++----- gruel/src/python/pmt/__init__.py | 10 ++++----- gruel/src/python/qa_pmt.py | 10 ++++----- gruel/src/swig/gr_intrusive_ptr.i | 6 +++--- gruel/src/swig/gruel_common.i | 8 +++---- gruel/src/swig/pmt_swig.i | 14 ++++++------- 47 files changed, 237 insertions(+), 237 deletions(-) (limited to 'gruel') diff --git a/gruel/CMakeLists.txt b/gruel/CMakeLists.txt index 558248d08..3e8c5166e 100644 --- a/gruel/CMakeLists.txt +++ b/gruel/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2010-2011 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, diff --git a/gruel/README b/gruel/README index 647dc843b..90dc4eeb4 100644 --- a/gruel/README +++ b/gruel/README @@ -1,23 +1,23 @@ # # Copyright 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., 51 Franklin Street, # Boston, MA 02110-1301, USA. -# +# The GNU Radio Utility Etcetera Library, a collection of low-level routines to avoid dependencies on the full GNU Radio core or other libraries. diff --git a/gruel/gruel.pc.in b/gruel/gruel.pc.in index 504c4d949..7f3f821fe 100644 --- a/gruel/gruel.pc.in +++ b/gruel/gruel.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: gruel Description: The GNU Radio Utility Etcetera Library -Requires: +Requires: Version: @LIBVER@ Libs: -L${libdir} -lgruel Cflags: -I${includedir} diff --git a/gruel/src/include/gruel/CMakeLists.txt b/gruel/src/include/gruel/CMakeLists.txt index 9db810cae..9818f1c09 100644 --- a/gruel/src/include/gruel/CMakeLists.txt +++ b/gruel/src/include/gruel/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2010-2011 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, diff --git a/gruel/src/include/gruel/high_res_timer.h b/gruel/src/include/gruel/high_res_timer.h index 63841f612..a885520b6 100644 --- a/gruel/src/include/gruel/high_res_timer.h +++ b/gruel/src/include/gruel/high_res_timer.h @@ -1,18 +1,18 @@ /* * Copyright 2011 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. diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in index 8545aeea9..74f14bd92 100644 --- a/gruel/src/include/gruel/inet.h.in +++ b/gruel/src/include/gruel/inet.h.in @@ -47,7 +47,7 @@ static inline uint64_t htonll(uint64_t x){ return bswap_64(x);} static inline uint64_t ntohll(uint64_t x){ return bswap_64(x);} #endif /* GR_ARCH_BIGENDIAN */ -#endif /* missing htonll or ntohll */ +#endif /* missing htonll or ntohll */ #if @GR_HAVE_ARPA_INET@ /* GR_HAVE_ARPA_INET */ #include diff --git a/gruel/src/include/gruel/msg_accepter.h b/gruel/src/include/gruel/msg_accepter.h index 3dfc8bcf8..2dc1a6859 100644 --- a/gruel/src/include/gruel/msg_accepter.h +++ b/gruel/src/include/gruel/msg_accepter.h @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gruel/src/include/gruel/msg_accepter_msgq.h b/gruel/src/include/gruel/msg_accepter_msgq.h index 22a1855cf..6b9bcf4db 100644 --- a/gruel/src/include/gruel/msg_accepter_msgq.h +++ b/gruel/src/include/gruel/msg_accepter_msgq.h @@ -1,19 +1,19 @@ /* -*- 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. @@ -35,7 +35,7 @@ namespace gruel { { protected: msg_queue_sptr d_msg_queue; - + public: msg_accepter_msgq(msg_queue_sptr msgq); ~msg_accepter_msgq(); diff --git a/gruel/src/include/gruel/msg_passing.h b/gruel/src/include/gruel/msg_passing.h index 51268967a..0cc0cd111 100644 --- a/gruel/src/include/gruel/msg_passing.h +++ b/gruel/src/include/gruel/msg_passing.h @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gruel/src/include/gruel/msg_queue.h b/gruel/src/include/gruel/msg_queue.h index 8608842da..f038ca325 100644 --- a/gruel/src/include/gruel/msg_queue.h +++ b/gruel/src/include/gruel/msg_queue.h @@ -1,19 +1,19 @@ /* -*- 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -63,22 +63,22 @@ namespace gruel { * Block if no message is available. */ pmt::pmt_t delete_head(); - + /*! * \brief If there's a message in the q, delete it and return it. * If no message is available, return pmt_t(). */ pmt::pmt_t delete_head_nowait(); - + //! Delete all messages from the queue void flush(); //! is the queue empty? bool empty_p() const { return d_msgs.empty(); } - + //! is the queue full? bool full_p() const { return d_limit != 0 && count() >= d_limit; } - + //! return number of messages in queue unsigned int count() const { return d_msgs.size(); } diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index f904d37e1..92af1eba6 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2009,2010 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, @@ -52,7 +52,7 @@ namespace pmt { * \brief base class of all pmt types */ class pmt_base; - + /*! * \brief typedef for shared pointer (transparent reference counting). * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm @@ -109,7 +109,7 @@ GRUEL_API bool pmt_is_false(pmt_t obj); //! Return \#f is val is false, else return \#t. GRUEL_API pmt_t pmt_from_bool(bool val); -//! Return true if val is PMT_T, return false when val is PMT_F, +//! Return true if val is PMT_T, return false when val is PMT_F, // else raise wrong_type exception. GRUEL_API bool pmt_to_bool(pmt_t val); @@ -384,7 +384,7 @@ GRUEL_API size_t pmt_blob_length(pmt_t blob); */ //! true if \p x is any kind of uniform numeric vector -GRUEL_API bool pmt_is_uniform_vector(pmt_t x); +GRUEL_API bool pmt_is_uniform_vector(pmt_t x); GRUEL_API bool pmt_is_u8vector(pmt_t x); GRUEL_API bool pmt_is_s8vector(pmt_t x); @@ -584,7 +584,7 @@ GRUEL_API bool pmt_eqv(const pmt_t& x, const pmt_t& y); /*! * pmt_equal recursively compares the contents of pairs and vectors, - * applying pmt_eqv on other objects such as numbers and symbols. + * applying pmt_eqv on other objects such as numbers and symbols. * pmt_equal may fail to terminate if its arguments are circular data * structures. */ diff --git a/gruel/src/include/gruel/pmt_pool.h b/gruel/src/include/gruel/pmt_pool.h index 2b227ce6a..93c5290ad 100644 --- a/gruel/src/include/gruel/pmt_pool.h +++ b/gruel/src/include/gruel/pmt_pool.h @@ -1,19 +1,19 @@ /* -*- 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. @@ -39,11 +39,11 @@ class GRUEL_API pmt_pool { struct GRUEL_API item { struct item *d_next; }; - + typedef boost::unique_lock scoped_lock; mutable boost::mutex d_mutex; boost::condition_variable d_cond; - + size_t d_itemsize; size_t d_alignment; size_t d_allocation_size; diff --git a/gruel/src/include/gruel/pmt_sugar.h b/gruel/src/include/gruel/pmt_sugar.h index 92bcb5fe5..1d2b38ff1 100644 --- a/gruel/src/include/gruel/pmt_sugar.h +++ b/gruel/src/include/gruel/pmt_sugar.h @@ -1,19 +1,19 @@ /* -*- 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. @@ -59,7 +59,7 @@ namespace pmt { mp(double x){ return pmt_from_double(x); } - + //! Make pmt complex static inline pmt_t mp(std::complex z) diff --git a/gruel/src/include/gruel/realtime.h b/gruel/src/include/gruel/realtime.h index 87f2b0f74..13673ecb3 100644 --- a/gruel/src/include/gruel/realtime.h +++ b/gruel/src/include/gruel/realtime.h @@ -1,19 +1,19 @@ /* -*- 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -86,7 +86,7 @@ namespace gruel { * it's possible to hang the system. */ - // NOTE: If you change this, you need to change the code in + // NOTE: If you change this, you need to change the code in // gnuradio-core/src/lib/runtime/gr_realtime.i, see note there. rt_status_t GRUEL_API enable_realtime_scheduling(rt_sched_param = rt_sched_param()); diff --git a/gruel/src/include/gruel/sys_pri.h b/gruel/src/include/gruel/sys_pri.h index a29b051bf..c0751e52c 100644 --- a/gruel/src/include/gruel/sys_pri.h +++ b/gruel/src/include/gruel/sys_pri.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 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. diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index c6031d88d..63143c8b4 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2009,2010,2011 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. diff --git a/gruel/src/include/gruel/thread_body_wrapper.h b/gruel/src/include/gruel/thread_body_wrapper.h index ae0feda08..e09a43e68 100644 --- a/gruel/src/include/gruel/thread_body_wrapper.h +++ b/gruel/src/include/gruel/thread_body_wrapper.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 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. @@ -26,7 +26,7 @@ #include #include -namespace gruel +namespace gruel { GRUEL_API void mask_signals(); diff --git a/gruel/src/include/gruel/thread_group.h b/gruel/src/include/gruel/thread_group.h index e1658dd1f..1b8a0a4bf 100644 --- a/gruel/src/include/gruel/thread_group.h +++ b/gruel/src/include/gruel/thread_group.h @@ -4,7 +4,7 @@ * Copyright (C) 2007 Anthony Williams * Copyright 2008,2009 Free Software Foundation, Inc. * - * Distributed under the Boost Software License, Version 1.0. (See accompanying + * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ diff --git a/gruel/src/lib/CMakeLists.txt b/gruel/src/lib/CMakeLists.txt index a6aa1d992..cd7b7abf4 100644 --- a/gruel/src/lib/CMakeLists.txt +++ b/gruel/src/lib/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2010-2011 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, diff --git a/gruel/src/lib/msg/CMakeLists.txt b/gruel/src/lib/msg/CMakeLists.txt index 116d2c67f..74010af7e 100644 --- a/gruel/src/lib/msg/CMakeLists.txt +++ b/gruel/src/lib/msg/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2010 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, diff --git a/gruel/src/lib/msg/msg_accepter.cc b/gruel/src/lib/msg/msg_accepter.cc index 64878f737..5acd98aa2 100644 --- a/gruel/src/lib/msg/msg_accepter.cc +++ b/gruel/src/lib/msg/msg_accepter.cc @@ -1,19 +1,19 @@ /* -*- 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gruel/src/lib/msg/msg_accepter_msgq.cc b/gruel/src/lib/msg/msg_accepter_msgq.cc index 64fe501d1..2ae3537b8 100644 --- a/gruel/src/lib/msg/msg_accepter_msgq.cc +++ b/gruel/src/lib/msg/msg_accepter_msgq.cc @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gruel/src/lib/msg/msg_queue.cc b/gruel/src/lib/msg/msg_queue.cc index 8d15f08c5..a0b120e40 100644 --- a/gruel/src/lib/msg/msg_queue.cc +++ b/gruel/src/lib/msg/msg_queue.cc @@ -1,19 +1,19 @@ /* -*- 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -36,12 +36,12 @@ namespace gruel { { return msg_queue_sptr(new msg_queue(limit)); } - + msg_queue::msg_queue(unsigned int limit) : d_limit(limit) { } - + msg_queue::~msg_queue() { flush(); @@ -83,7 +83,7 @@ namespace gruel { if (empty_p()) return pmt_t(); - + pmt_t m(d_msgs.front()); d_msgs.pop_front(); diff --git a/gruel/src/lib/pmt/CMakeLists.txt b/gruel/src/lib/pmt/CMakeLists.txt index a8e15cac6..dc70f03d7 100644 --- a/gruel/src/lib/pmt/CMakeLists.txt +++ b/gruel/src/lib/pmt/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2010 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, diff --git a/gruel/src/lib/pmt/generate_unv.py b/gruel/src/lib/pmt/generate_unv.py index 02aace250..42b57e245 100755 --- a/gruel/src/lib/pmt/generate_unv.py +++ b/gruel/src/lib/pmt/generate_unv.py @@ -1,24 +1,24 @@ #!/usr/bin/env python # # 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. -# +# """ Generate code for uniform numeric vectors @@ -46,19 +46,19 @@ header = """\ /* -*- 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, @@ -118,7 +118,7 @@ def do_substitution (d, input, out_file): key = match_obj.group (1) # print key return d[key] - + out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, input) out_file.write (out) @@ -164,7 +164,7 @@ class qa_pmt_unv : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_END(); private: -''') +''') for tag, typ in unv_types: output.write(' void test_%svector();\n' % (tag,)) output.write('};\n') @@ -178,7 +178,7 @@ def generate_qa_cc(): for tag, typ in unv_types: d = { 'TAG' : tag, 'TYPE' : typ } do_substitution(d, template, output) - + def main(): generate_h() diff --git a/gruel/src/lib/pmt/pmt-serial-tags.scm b/gruel/src/lib/pmt/pmt-serial-tags.scm index 646a751ea..ca25a43a8 100644 --- a/gruel/src/lib/pmt/pmt-serial-tags.scm +++ b/gruel/src/lib/pmt/pmt-serial-tags.scm @@ -1,19 +1,19 @@ ;;; -*-scheme-*- ;;; ;;; 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 (define 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. diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index 57b66b1a4..a7e0fd19f 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2009,2010 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, @@ -229,13 +229,13 @@ hash_string(const std::string &s) return h; } -bool +bool pmt_is_symbol(const pmt_t& obj) { return obj->is_symbol(); } -pmt_t +pmt_t pmt_string_to_symbol(const std::string &name) { unsigned hash = hash_string(name) % SYMBOL_HASH_TABLE_SIZE; @@ -350,7 +350,7 @@ pmt_to_uint64(pmt_t x) pmt_real::pmt_real(double value) : d_value(value) {} -bool +bool pmt_is_real(pmt_t x) { return x->is_real(); @@ -379,7 +379,7 @@ pmt_to_double(pmt_t x) pmt_complex::pmt_complex(std::complex value) : d_value(value) {} -bool +bool pmt_is_complex(pmt_t x) { return x->is_complex(); @@ -435,7 +435,7 @@ pmt_car(const pmt_t& pair) pmt_pair* p = dynamic_cast(pair.get()); if ( p ) return p->car(); - + throw pmt_wrong_type("pmt_car", pair); } @@ -445,7 +445,7 @@ pmt_cdr(const pmt_t& pair) pmt_pair* p = dynamic_cast(pair.get()); if ( p ) return p->cdr(); - + throw pmt_wrong_type("pmt_cdr", pair); } @@ -766,7 +766,7 @@ pmt_uniform_vector_writable_elements(pmt_t vector, size_t &len) * This is an a-list implementation. * * When we need better performance for large dictionaries, consider implementing - * persistent Red-Black trees as described in "Purely Functional Data Structures", + * persistent Red-Black trees as described in "Purely Functional Data Structures", * Chris Okasaki, 1998, section 3.3. */ @@ -802,7 +802,7 @@ pmt_dict_delete(const pmt_t &dict, const pmt_t &key) if (pmt_eqv(pmt_caar(dict), key)) return pmt_cdr(dict); - + return pmt_cons(pmt_car(dict), pmt_dict_delete(pmt_cdr(dict), key)); } @@ -887,7 +887,7 @@ pmt_any_set(pmt_t obj, const boost::any &any) // msg_accepter -- built from "any" //////////////////////////////////////////////////////////////////////////// -bool +bool pmt_is_msg_accepter(const pmt_t &obj) { if (!pmt_is_any(obj)) @@ -1222,7 +1222,7 @@ pmt_nthcdr(size_t n, pmt_t list) { if (!(pmt_is_pair(list) || pmt_is_null(list))) throw pmt_wrong_type("pmt_nthcdr", list); - + while (n > 0){ if (pmt_is_pair(list)){ list = pmt_cdr(list); @@ -1359,7 +1359,7 @@ pmt_cadddr(pmt_t pair) { return pmt_car(pmt_cdr(pmt_cdr(pmt_cdr(pair)))); } - + bool pmt_is_eof_object(pmt_t obj) { diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h index 745dbc666..bd2b5fe5a 100644 --- a/gruel/src/lib/pmt/pmt_int.h +++ b/gruel/src/lib/pmt/pmt_int.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2009,2010 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, @@ -101,7 +101,7 @@ class pmt_symbol : public pmt_base { std::string d_name; pmt_t d_next; - + public: pmt_symbol(const std::string &name); //~pmt_symbol(){} diff --git a/gruel/src/lib/pmt/pmt_io.cc b/gruel/src/lib/pmt/pmt_io.cc index 1214ff588..4bac4a0ec 100644 --- a/gruel/src/lib/pmt/pmt_io.cc +++ b/gruel/src/lib/pmt/pmt_io.cc @@ -1,19 +1,19 @@ /* -*- 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 this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -127,7 +127,7 @@ std::ostream& operator<<(std::ostream &os, pmt_t obj) return os; } -std::string +std::string pmt_write_string(pmt_t obj) { std::ostringstream s; @@ -150,7 +150,7 @@ pmt_serialize(pmt_t obj, std::ostream &sink) /*! * \brief Create obj from portable byte-serial representation */ -pmt_t +pmt_t pmt_deserialize(std::istream &source) { throw pmt_notimplemented("notimplemented: pmt_deserialize", PMT_NIL); @@ -159,7 +159,7 @@ pmt_deserialize(std::istream &source) } /* namespace pmt */ -void +void pmt::pmt_print(pmt_t v) { std::cout << pmt_write_string(v) << std::endl; diff --git a/gruel/src/lib/pmt/pmt_pool.cc b/gruel/src/lib/pmt/pmt_pool.cc index 731d28ca7..63a681abf 100644 --- a/gruel/src/lib/pmt/pmt_pool.cc +++ b/gruel/src/lib/pmt/pmt_pool.cc @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc index 184a31e6b..de9644c3c 100644 --- a/gruel/src/lib/pmt/pmt_serialize.cc +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -1,19 +1,19 @@ /* -*- 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. @@ -216,7 +216,7 @@ deserialize_untagged_f64(double *ip, std::streambuf &sb) *ip = iu.id; return t != std::streambuf::traits_type::eof(); } - + /* * Write portable byte-serial representation of \p obj to \p sb @@ -227,7 +227,7 @@ bool pmt_serialize(pmt_t obj, std::streambuf &sb) { bool ok = true; - + tail_recursion: if (pmt_is_bool(obj)){ @@ -236,7 +236,7 @@ pmt_serialize(pmt_t obj, std::streambuf &sb) else return serialize_untagged_u8(PST_FALSE, sb); } - + if (pmt_is_null(obj)) return serialize_untagged_u8(PST_NULL, sb); @@ -294,10 +294,10 @@ pmt_serialize(pmt_t obj, std::streambuf &sb) if (pmt_is_uniform_vector(obj)) throw pmt_notimplemented("pmt_serialize (uniform-vector)", obj); - + if (pmt_is_dict(obj)) throw pmt_notimplemented("pmt_serialize (dict)", obj); - + throw pmt_notimplemented("pmt_serialize (?)", obj); } @@ -325,7 +325,7 @@ pmt_deserialize(std::streambuf &sb) switch (tag){ case PST_TRUE: return PMT_T; - + case PST_FALSE: return PMT_F; @@ -369,7 +369,7 @@ pmt_deserialize(std::streambuf &sb) case PST_COMMENT: throw pmt_notimplemented("pmt_deserialize: tag value = ", pmt_from_long(tag)); - + default: throw pmt_exception("pmt_deserialize: malformed input stream, tag value = ", pmt_from_long(tag)); diff --git a/gruel/src/lib/pmt/qa_pmt.cc b/gruel/src/lib/pmt/qa_pmt.cc index 250befafa..27c617e74 100644 --- a/gruel/src/lib/pmt/qa_pmt.cc +++ b/gruel/src/lib/pmt/qa_pmt.cc @@ -1,18 +1,18 @@ /* * 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, @@ -35,6 +35,6 @@ qa_pmt::suite () s->addTest (qa_pmt_prims::suite ()); s->addTest (qa_pmt_unv::suite ()); - + return s; } diff --git a/gruel/src/lib/pmt/qa_pmt.h b/gruel/src/lib/pmt/qa_pmt.h index 424c1065b..3de5872c7 100644 --- a/gruel/src/lib/pmt/qa_pmt.h +++ b/gruel/src/lib/pmt/qa_pmt.h @@ -1,19 +1,19 @@ /* -*- 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, diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 7dec30d56..6212b8ea4 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2009,2010 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, @@ -173,7 +173,7 @@ qa_pmt_prims::test_pairs() CPPUNIT_ASSERT_EQUAL(s3, pmt_car(c1)); CPPUNIT_ASSERT_EQUAL((size_t)1, pmt_length(c3)); CPPUNIT_ASSERT_EQUAL((size_t)2, pmt_length(c2)); - + CPPUNIT_ASSERT_THROW(pmt_cdr(PMT_NIL), pmt_wrong_type); CPPUNIT_ASSERT_THROW(pmt_car(PMT_NIL), pmt_wrong_type); CPPUNIT_ASSERT_THROW(pmt_set_car(s1, PMT_NIL), pmt_wrong_type); @@ -282,7 +282,7 @@ qa_pmt_prims::test_tuples() //std::cout << v << std::endl; //std::cout << t2 << std::endl; - + t = pmt_make_tuple(s[0], s[1], s[2]); pmt_t list0 = pmt_list3(s[0], s[1], s[2]); CPPUNIT_ASSERT_EQUAL(size_t(3), pmt_length(list0)); @@ -346,11 +346,11 @@ qa_pmt_prims::test_misc() pmt_t p0 = pmt_cons(k0, v0); pmt_t p1 = pmt_cons(k1, v1); pmt_t p2 = pmt_cons(k2, v2); - + pmt_t alist = pmt_cons(p0, pmt_cons(p1, pmt_cons(p2, PMT_NIL))); CPPUNIT_ASSERT(pmt_eq(p1, pmt_assv(k1, alist))); CPPUNIT_ASSERT(pmt_eq(PMT_F, pmt_assv(k3, alist))); - + pmt_t keys = pmt_cons(k0, pmt_cons(k1, pmt_cons(k2, PMT_NIL))); pmt_t vals = pmt_cons(v0, pmt_cons(v1, pmt_cons(v2, PMT_NIL))); CPPUNIT_ASSERT(pmt_equal(keys, pmt_map(pmt_car, alist))); @@ -372,7 +372,7 @@ qa_pmt_prims::test_dict() pmt_t v2 = mp("v2"); pmt_t v3 = mp("v3"); pmt_t not_found = pmt_cons(PMT_NIL, PMT_NIL); - + CPPUNIT_ASSERT(!pmt_dict_has_key(dict, k0)); dict = pmt_dict_add(dict, k0, v0); CPPUNIT_ASSERT(pmt_dict_has_key(dict, k0)); diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h index cc1409ee6..a407509b2 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.h +++ b/gruel/src/lib/pmt/qa_pmt_prims.h @@ -1,19 +1,19 @@ /* -*- 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, diff --git a/gruel/src/lib/pmt/unv_template.cc.t b/gruel/src/lib/pmt/unv_template.cc.t index 148965c09..566168c3d 100644 --- a/gruel/src/lib/pmt/unv_template.cc.t +++ b/gruel/src/lib/pmt/unv_template.cc.t @@ -33,7 +33,7 @@ pmt_@TAG@vector::ref(size_t k) const return d_v[k]; } -void +void pmt_@TAG@vector::set(size_t k, @TYPE@ x) { if (k >= length()) diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc index 96351f812..e01c6c53d 100644 --- a/gruel/src/lib/realtime.cc +++ b/gruel/src/lib/realtime.cc @@ -1,19 +1,19 @@ /* -*- 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., 51 Franklin Street, @@ -90,7 +90,7 @@ namespace gruel { return RT_OTHER_ERROR; } } - + //printf("SCHED_FIFO enabled with priority = %d\n", pri); return RT_OK; } @@ -125,7 +125,7 @@ namespace gruel { return RT_OTHER_ERROR; } } - + //printf("SCHED_FIFO enabled with priority = %d\n", pri); return RT_OK; } diff --git a/gruel/src/lib/sys_pri.cc b/gruel/src/lib/sys_pri.cc index dc0164d70..c8a505341 100644 --- a/gruel/src/lib/sys_pri.cc +++ b/gruel/src/lib/sys_pri.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 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. diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc index 7ef3520e6..f32e3f341 100644 --- a/gruel/src/lib/test_gruel.cc +++ b/gruel/src/lib/test_gruel.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2009,2010,2011 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, @@ -32,7 +32,7 @@ #include namespace fs = boost::filesystem; -int +int main(int argc, char **argv) { fs::path path = fs::current_path() / ".unittests"; @@ -45,7 +45,7 @@ main(int argc, char **argv) runner.addTest(qa_pmt::suite ()); runner.setOutputter(xmlout); - + bool was_successful = runner.run("", false); return was_successful ? 0 : 1; diff --git a/gruel/src/lib/thread_body_wrapper.cc b/gruel/src/lib/thread_body_wrapper.cc index 86c4edb5b..019eaa342 100644 --- a/gruel/src/lib/thread_body_wrapper.cc +++ b/gruel/src/lib/thread_body_wrapper.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 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. @@ -37,7 +37,7 @@ namespace gruel { sigset_t new_set; int r; - sigemptyset(&new_set); + sigemptyset(&new_set); sigaddset(&new_set, SIGHUP); // block these... sigaddset(&new_set, SIGINT); sigaddset(&new_set, SIGPIPE); diff --git a/gruel/src/lib/thread_group.cc b/gruel/src/lib/thread_group.cc index fa78567ec..9e8ded4df 100644 --- a/gruel/src/lib/thread_group.cc +++ b/gruel/src/lib/thread_group.cc @@ -4,7 +4,7 @@ * Copyright (C) 2007 Anthony Williams * Copyright 2008 Free Software Foundation, Inc. * - * Distributed under the Boost Software License, Version 1.0. (See accompanying + * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ diff --git a/gruel/src/python/__init__.py b/gruel/src/python/__init__.py index 082ea26f2..976b2ed1e 100644 --- a/gruel/src/python/__init__.py +++ b/gruel/src/python/__init__.py @@ -1,23 +1,23 @@ # # Copyright 2011 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. -# +# # The presence of this file turns this directory into a Python package diff --git a/gruel/src/python/pmt/__init__.py b/gruel/src/python/pmt/__init__.py index 2c4d33b59..0862af0eb 100644 --- a/gruel/src/python/pmt/__init__.py +++ b/gruel/src/python/pmt/__init__.py @@ -1,23 +1,23 @@ # # Copyright 2011 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. -# +# # The presence of this file turns this directory into a Python package diff --git a/gruel/src/python/qa_pmt.py b/gruel/src/python/qa_pmt.py index 00cdb064e..1ef4fed15 100755 --- a/gruel/src/python/qa_pmt.py +++ b/gruel/src/python/qa_pmt.py @@ -1,24 +1,24 @@ #!/usr/bin/env python # # Copyright 2011 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. -# +# import unittest import pmt_swig diff --git a/gruel/src/swig/gr_intrusive_ptr.i b/gruel/src/swig/gr_intrusive_ptr.i index eef5bc84d..40c438d00 100644 --- a/gruel/src/swig/gr_intrusive_ptr.i +++ b/gruel/src/swig/gr_intrusive_ptr.i @@ -1,4 +1,4 @@ -// This file was borrowed from the SWIG project to allow use to +// This file was borrowed from the SWIG project to allow use to // wrap PMTs that use intrusive pointers. This is only necessary // to support backwards compatability with older distributions of // Linux that do not natively support a new enough version of SWIG. @@ -10,7 +10,7 @@ // #define SWIG_SHARED_PTR_NAMESPACE std // #define SWIG_SHARED_PTR_SUBNAMESPACE tr1 // #define SWIG_INTRUSIVE_PTR_NAMESPACE boost -// #define SWIG_INTRUSIVE_PTR_SUBNAMESPACE +// #define SWIG_INTRUSIVE_PTR_SUBNAMESPACE #if !defined(SWIG_INTRUSIVE_PTR_NAMESPACE) # define SWIG_INTRUSIVE_PTR_NAMESPACE boost @@ -36,7 +36,7 @@ namespace SWIG_INTRUSIVE_PTR_NAMESPACE { %fragment("SWIG_intrusive_deleter", "header") { template struct SWIG_intrusive_deleter { void operator()(T *p) { - if (p) + if (p) intrusive_ptr_release(p); } }; diff --git a/gruel/src/swig/gruel_common.i b/gruel/src/swig/gruel_common.i index e4261cbfa..3a4d841d6 100644 --- a/gruel/src/swig/gruel_common.i +++ b/gruel/src/swig/gruel_common.i @@ -1,18 +1,18 @@ /* * Copyright 2011 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, diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 954501863..45cfceadc 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2011-2012 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, @@ -77,7 +77,7 @@ bool pmt_is_false(pmt_t obj); //! Return \#f is val is false, else return \#t. pmt_t pmt_from_bool(bool val); -//! Return true if val is PMT_T, return false when val is PMT_F, +//! Return true if val is PMT_T, return false when val is PMT_F, // else raise wrong_type exception. bool pmt_to_bool(pmt_t val); @@ -352,7 +352,7 @@ size_t pmt_blob_length(pmt_t blob); */ //! true if \p x is any kind of uniform numeric vector -bool pmt_is_uniform_vector(pmt_t x); +bool pmt_is_uniform_vector(pmt_t x); bool pmt_is_u8vector(pmt_t x); bool pmt_is_s8vector(pmt_t x); @@ -550,7 +550,7 @@ bool pmt_eqv(const pmt_t& x, const pmt_t& y); /*! * pmt_equal recursively compares the contents of pairs and vectors, - * applying pmt_eqv on other objects such as numbers and symbols. + * applying pmt_eqv on other objects such as numbers and symbols. * pmt_equal may fail to terminate if its arguments are circular data * structures. */ -- cgit From eba5deff498acba7fbc91c2bd00a2389d3fc0194 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sun, 15 Apr 2012 09:06:29 -0700 Subject: pmt: fix segfault in deleter --- gruel/src/lib/pmt/pmt.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index 57b66b1a4..c100611be 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -58,7 +58,13 @@ pmt_base::operator delete(void *p, size_t size) #endif void intrusive_ptr_add_ref(pmt_base* p) { ++(p->count_); } -void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) p->deleter_(p); } +void intrusive_ptr_release(pmt_base* p) { + if (--(p->count_) == 0 ){ + //make a copy of deleter before we delete its container, p + boost::function deleter = p->deleter_; + deleter(p); + } +} pmt_base::~pmt_base() { -- cgit From e53e231e50b66f9ab9a1ab5a3c7da894736be000 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 16 Apr 2012 16:20:29 -0700 Subject: Revert "Merge branch 'test/fix-pmt-deleter' into maint" This reverts commit 04e2ebb979942cada74f10ea022342716c6851bf, reversing changes made to 25d687550a0322ffaf270f25faf2b4a78a97142c. --- gruel/src/lib/pmt/pmt.cc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index c100611be..57b66b1a4 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -58,13 +58,7 @@ pmt_base::operator delete(void *p, size_t size) #endif void intrusive_ptr_add_ref(pmt_base* p) { ++(p->count_); } -void intrusive_ptr_release(pmt_base* p) { - if (--(p->count_) == 0 ){ - //make a copy of deleter before we delete its container, p - boost::function deleter = p->deleter_; - deleter(p); - } -} +void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) p->deleter_(p); } pmt_base::~pmt_base() { -- cgit From 54f27eed4991daa41ccba37789a250abdab020a9 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 16 Apr 2012 16:21:58 -0700 Subject: Revert "Merge remote branch 'jblum-github/pmt_set_deleter'" This reverts commit f88b8cf5508d3ba446cb94f800c56d34279cf91e, reversing changes made to a87ac60f15c2593ececb02ba16ab842c20e760d2. --- gruel/src/include/gruel/pmt.h | 19 ------------------- gruel/src/lib/pmt/pmt.cc | 14 +------------- gruel/src/lib/pmt/pmt_int.h | 9 +-------- 3 files changed, 2 insertions(+), 40 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index f904d37e1..58533e54e 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -32,7 +32,6 @@ #include #include #include -#include namespace gruel { class msg_accepter; @@ -806,24 +805,6 @@ GRUEL_API std::string pmt_serialize_str(pmt_t obj); */ GRUEL_API pmt_t pmt_deserialize_str(std::string str); -/* - * ------------------------------------------------------------------------ - * advanced - * ------------------------------------------------------------------------ - */ - -#define GRUEL_PMT_HAVE_PMT_SET_DELETER - -/*! - * Set a deleter function to be called when the PMT dereferences. - * User beware! This function is for extremely advanced use. - * Use boost bind to bind extra parameters into the deleter function. - * Set an empty function type to reset the PMT to the default deleter. - * \param obj the pmt object in which to set the deleter function - * \param deleter a function that gets an opaque PMT pointer type - */ -GRUEL_API void pmt_set_deleter(pmt_t obj, boost::function &deleter); - } /* namespace pmt */ #include diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index 57b66b1a4..f9cf6b4bf 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -58,7 +58,7 @@ pmt_base::operator delete(void *p, size_t size) #endif void intrusive_ptr_add_ref(pmt_base* p) { ++(p->count_); } -void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) p->deleter_(p); } +void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) delete p; } pmt_base::~pmt_base() { @@ -1383,16 +1383,4 @@ pmt_dump_sizeof() printf("sizeof(pmt_uniform_vector) = %3zd\n", sizeof(pmt_uniform_vector)); } -/* - * ------------------------------------------------------------------------ - * advanced - * ------------------------------------------------------------------------ - */ - -void -pmt_set_deleter(pmt_t obj, boost::function &deleter) -{ - obj->deleter_ = (deleter)? deleter : &pmt_base::default_deleter; -} - } /* namespace pmt */ diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h index 745dbc666..3a5cd382b 100644 --- a/gruel/src/lib/pmt/pmt_int.h +++ b/gruel/src/lib/pmt/pmt_int.h @@ -38,15 +38,8 @@ namespace pmt { class GRUEL_API pmt_base : boost::noncopyable { mutable boost::detail::atomic_count count_; -public: - static void default_deleter(pmt_base *p){ - delete p; - } - - boost::function deleter_; - protected: - pmt_base() : count_(0), deleter_(&pmt::pmt_base::default_deleter) {}; + pmt_base() : count_(0) {}; virtual ~pmt_base(); public: -- cgit From 4c589268b7145d782194d99c4eade83bc04eaae5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 23 Apr 2012 19:09:22 -0400 Subject: Various fixes for using Python 2.5. --- gruel/src/lib/pmt/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/CMakeLists.txt b/gruel/src/lib/pmt/CMakeLists.txt index dc70f03d7..72bd27a04 100644 --- a/gruel/src/lib/pmt/CMakeLists.txt +++ b/gruel/src/lib/pmt/CMakeLists.txt @@ -67,7 +67,7 @@ add_custom_command( ${CMAKE_CURRENT_SOURCE_DIR}/unv_template.h.t ${CMAKE_CURRENT_SOURCE_DIR}/unv_template.cc.t ${CMAKE_CURRENT_SOURCE_DIR}/unv_qa_template.cc.t - COMMAND ${PYTHON_EXECUTABLE} -B -c + COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B} -c \"import os,sys\;srcdir='${CMAKE_CURRENT_SOURCE_DIR}'\;sys.path.append(srcdir)\;os.environ['srcdir']=srcdir\;from generate_unv import main\;main()\" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) -- cgit From 9bab2daba836ad6c121b5237af287efb7dc5968e Mon Sep 17 00:00:00 2001 From: Tim Oshea Date: Mon, 30 Apr 2012 15:57:41 -0700 Subject: gruel: fix linker assumption made explicit on Ubuntu 12.04 --- gruel/src/lib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/lib/CMakeLists.txt b/gruel/src/lib/CMakeLists.txt index cd7b7abf4..2a96163ce 100644 --- a/gruel/src/lib/CMakeLists.txt +++ b/gruel/src/lib/CMakeLists.txt @@ -81,7 +81,7 @@ list(APPEND gruel_sources ) add_library(gruel SHARED ${gruel_sources}) -target_link_libraries(gruel ${Boost_LIBRARIES}) +target_link_libraries(gruel ${Boost_LIBRARIES} -lpthread) GR_LIBRARY_FOO(gruel RUNTIME_COMPONENT "gruel_runtime" DEVEL_COMPONENT "gruel_devel") ######################################################################## -- cgit From 29ed15d3acaf8c778ea6aff41a636892e362f7a3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 2 May 2012 22:00:45 -0700 Subject: gruel: conditional linking for pthread --- gruel/src/lib/CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/lib/CMakeLists.txt b/gruel/src/lib/CMakeLists.txt index 2a96163ce..e7713536c 100644 --- a/gruel/src/lib/CMakeLists.txt +++ b/gruel/src/lib/CMakeLists.txt @@ -80,8 +80,14 @@ list(APPEND gruel_sources thread_group.cc ) +list(APPEND gruel_libs ${Boost_LIBRARIES}) + +if(HAVE_PTHREAD_SETSCHEDPARAM) + list(APPEND gruel_libs pthread) +endif() + add_library(gruel SHARED ${gruel_sources}) -target_link_libraries(gruel ${Boost_LIBRARIES} -lpthread) +target_link_libraries(gruel ${gruel_libs}) GR_LIBRARY_FOO(gruel RUNTIME_COMPONENT "gruel_runtime" DEVEL_COMPONENT "gruel_devel") ######################################################################## -- cgit From e7ea4f2f5f21bc745fd3b3a92b1cee176c00c551 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Wed, 13 Jun 2012 16:26:52 -0400 Subject: New Features: added support for pmt_serialize and pmt_deserialize for uint64_t type pmts added gr_add_const_bb typed block to gr_add_const_XX gengen --- gruel/src/lib/pmt/pmt-serial-tags.scm | 1 + gruel/src/lib/pmt/pmt_serialize.cc | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/pmt-serial-tags.scm b/gruel/src/lib/pmt/pmt-serial-tags.scm index ca25a43a8..a78d87681 100644 --- a/gruel/src/lib/pmt/pmt-serial-tags.scm +++ b/gruel/src/lib/pmt/pmt-serial-tags.scm @@ -33,6 +33,7 @@ (define pst-dict #x09) ; untagged-int32 n; followed by n key/value tuples (define pst-uniform-vector #x0a) +(define pst-uint64 #x0b) ;; u8, s8, u16, s16, u32, s32, u64, s64, f32, f64, c32, c64 ;; diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc index de9644c3c..05140bb42 100644 --- a/gruel/src/lib/pmt/pmt_serialize.cc +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -79,7 +79,6 @@ serialize_untagged_f64(double i, std::streambuf &sb) } -#if 0 // always writes big-endian static bool serialize_untagged_u64(uint64_t i, std::streambuf &sb) @@ -93,7 +92,6 @@ serialize_untagged_u64(uint64_t i, std::streambuf &sb) sb.sputc((i >> 8) & 0xff); return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); } -#endif // ---------------------------------------------------------------- // input primitives @@ -152,7 +150,6 @@ deserialize_untagged_u32(uint32_t *ip, std::streambuf &sb) return t != std::streambuf::traits_type::eof(); } -#if 0 // always reads big-endian static bool deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb) @@ -181,7 +178,6 @@ deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb) *ip = i; return t != std::streambuf::traits_type::eof(); } -#endif static bool deserialize_untagged_f64(double *ip, std::streambuf &sb) @@ -260,7 +256,13 @@ pmt_serialize(pmt_t obj, std::streambuf &sb) } if (pmt_is_number(obj)){ - + + if (pmt_is_uint64(obj)){ + uint64_t i = pmt_to_uint64(obj); + ok = serialize_untagged_u8(PST_UINT64, sb); + ok &= serialize_untagged_u64(i, sb); + return ok; + } else if (pmt_is_integer(obj)){ long i = pmt_to_long(obj); if (sizeof(long) > 4){ @@ -315,7 +317,7 @@ pmt_deserialize(std::streambuf &sb) //uint8_t u8; uint16_t u16; uint32_t u32; - //uint32_t u64; + uint64_t u64; double f64; static char tmpbuf[1024]; @@ -347,6 +349,11 @@ pmt_deserialize(std::streambuf &sb) goto error; return pmt_from_long((int32_t) u32); + case PST_UINT64: + if(!deserialize_untagged_u64(&u64, sb)) + goto error; + return pmt_from_uint64(u64); + case PST_PAIR: return parse_pair(sb); -- cgit From e42a6889a2966d8e9fd4e6b2b1bb3dd28c9794c9 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Wed, 20 Jun 2012 11:58:40 -0400 Subject: 1. handle pmt serialize and deserialize for tuples 2. fix offset checking in pmt_annotator_raw --- gruel/src/lib/pmt/pmt-serial-tags.scm | 1 + gruel/src/lib/pmt/pmt_serialize.cc | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/pmt-serial-tags.scm b/gruel/src/lib/pmt/pmt-serial-tags.scm index a78d87681..4f06bf75f 100644 --- a/gruel/src/lib/pmt/pmt-serial-tags.scm +++ b/gruel/src/lib/pmt/pmt-serial-tags.scm @@ -34,6 +34,7 @@ (define pst-uniform-vector #x0a) (define pst-uint64 #x0b) +(define pst-tuple #x0c) ;; u8, s8, u16, s16, u32, s32, u64, s64, f32, f64, c32, c64 ;; diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc index 05140bb42..8c9dd12b3 100644 --- a/gruel/src/lib/pmt/pmt_serialize.cc +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -24,6 +24,7 @@ #endif #include #include +#include #include "pmt_int.h" #include "gruel/pmt_serial_tags.h" @@ -213,6 +214,28 @@ deserialize_untagged_f64(double *ip, std::streambuf &sb) return t != std::streambuf::traits_type::eof(); } +static bool +deserialize_tuple(pmt_t *tuple, std::streambuf &sb) +{ + std::cout << "deserialize_tuple\n"; + uint32_t nitems; + bool ok = deserialize_untagged_u32(&nitems, sb); + pmt_t list(PMT_NIL); + std::cout << "nitems: " << nitems << "\n"; + for(uint32_t i=0; i #include -#include #include "pmt_int.h" #include "gruel/pmt_serial_tags.h" @@ -217,13 +216,10 @@ deserialize_untagged_f64(double *ip, std::streambuf &sb) static bool deserialize_tuple(pmt_t *tuple, std::streambuf &sb) { - std::cout << "deserialize_tuple\n"; uint32_t nitems; bool ok = deserialize_untagged_u32(&nitems, sb); pmt_t list(PMT_NIL); - std::cout << "nitems: " << nitems << "\n"; for(uint32_t i=0; i. - */ - -#ifndef INCLUDED_INET_H -#define INCLUDED_INET_H - -#include -#include - -#if 1 /* missing htonll or ntohll */ -#if @GR_ARCH_BIGENDIAN@ /* GR_ARCH_BIGENDIAN */ -// Nothing to do... -static inline uint64_t htonll(uint64_t x){ return x;} -static inline uint64_t ntohll(uint64_t x){ return x;} -#else -#if @GR_HAVE_BYTESWAP@ /* GR_HAVE_BYTESWAP */ -#include -#else - -static inline uint64_t -bswap_64(uint64_t x) -{ - return ((x & 0x00000000000000ffull) << 56) | ((x & 0x000000000000ff00ull) << 40) | - ((x & 0x0000000000ff0000ull) << 24) | ((x & 0x00000000ff000000ull) << 8) | - ((x & 0x000000ff00000000ull) >> 8) | ((x & 0x0000ff0000000000ull) >> 24) | - ((x & 0x00ff000000000000ull) >> 40) | ((x & 0xff00000000000000ull) >> 56); -} - -#endif /* GR_HAVE_BYTESWAP */ - -static inline uint64_t htonll(uint64_t x){ return bswap_64(x);} -static inline uint64_t ntohll(uint64_t x){ return bswap_64(x);} - -#endif /* GR_ARCH_BIGENDIAN */ -#endif /* missing htonll or ntohll */ - -#if @GR_HAVE_ARPA_INET@ /* GR_HAVE_ARPA_INET */ -#include -#elif @GR_HAVE_NETINET_IN@ /* GR_HAVE_NETINET_IN */ -#include -#else -#include - -#if @GR_ARCH_BIGENDIAN@ /* GR_ARCH_BIGENDIAN */ -// Nothing to do... -static inline uint32_t htonl(uint32_t x){ return x; } -static inline uint16_t htons(uint16_t x){ return x; } -static inline uint32_t ntohl(uint32_t x){ return x; } -static inline uint16_t ntohs(uint16_t x){ return x; } -#else -#if @GR_HAVE_BYTESWAP@ /* GR_HAVE_BYTESWAP */ -#include -#else -static inline uint16_t -bswap_16 (uint16_t x) -{ - return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); -} - -static inline uint32_t -bswap_32 (uint32_t x) -{ - return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ - | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); -} -#endif /* GR_HAVE_BYTESWAP */ - -static inline uint32_t htonl(uint32_t x){ return bswap_32(x); } -static inline uint16_t htons(uint16_t x){ return bswap_16(x); } -static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); } -static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); } -#endif /* GR_ARCH_BIGENDIAN */ - -#endif /* !(GR_HAVE_NETINET_IN || GR_HAVE_ARPA_INET) */ - -static inline uint8_t ntohx(uint8_t x){ return x; } -static inline uint16_t ntohx(uint16_t x){ return ntohs(x); } -static inline uint32_t ntohx(uint32_t x){ return ntohl(x); } -static inline uint64_t ntohx(uint64_t x){ return ntohll(x);} -static inline uint8_t htonx(uint8_t x){ return x; } -static inline uint16_t htonx(uint16_t x){ return htons(x); } -static inline uint32_t htonx(uint32_t x){ return htonl(x); } -static inline uint64_t htonx(uint64_t x){ return htonll(x);} - -#endif /* INCLUDED_INET_H */ diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index f9d1758ec..a0f84c832 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2011 Free Software Foundation, Inc. +# Copyright 2011-2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -23,7 +23,7 @@ include(GrPython) include(GrSwig) -set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS}) +set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) set(GR_SWIG_LIBRARIES gruel) set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i) -- cgit From 82f6a4ee66ce37b67a62af8924b1727e77c68816 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Thu, 21 Jun 2012 20:44:59 -0700 Subject: gruel: removed inet.h from install headers --- gruel/src/include/gruel/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/CMakeLists.txt b/gruel/src/include/gruel/CMakeLists.txt index 3fba90afc..d4c36eddb 100644 --- a/gruel/src/include/gruel/CMakeLists.txt +++ b/gruel/src/include/gruel/CMakeLists.txt @@ -24,7 +24,6 @@ install(FILES api.h attributes.h high_res_timer.h - ${CMAKE_CURRENT_BINARY_DIR}/inet.h msg_accepter.h msg_accepter_msgq.h msg_queue.h -- cgit From 76258270f53da9a7b6bdeed0b38dde735956012e Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 3 Jul 2012 14:21:05 -0700 Subject: swig: added additional swig dependencies gruel/core pmt swig gen depends upon the generated header core depends upon pmt swig custom target Conflicts: gruel/src/swig/CMakeLists.txt --- gruel/src/lib/pmt/CMakeLists.txt | 4 +++- gruel/src/swig/CMakeLists.txt | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/CMakeLists.txt b/gruel/src/lib/pmt/CMakeLists.txt index 72bd27a04..6ea616e10 100644 --- a/gruel/src/lib/pmt/CMakeLists.txt +++ b/gruel/src/lib/pmt/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2010 Free Software Foundation, Inc. +# Copyright 2010-2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -53,6 +53,8 @@ ADD_FILE_DEPENDENCIES( ${PMT_SERIAL_TAGS_H} ) +add_custom_target(pmt_generated DEPENDS ${PMT_SERIAL_TAGS_H}) + ######################################################################## # Generate other pmt stuff ######################################################################## diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index f9d1758ec..968622587 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -23,7 +23,8 @@ include(GrPython) include(GrSwig) -set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS}) +set(GR_SWIG_TARGET_DEPS pmt_generated) +set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) set(GR_SWIG_LIBRARIES gruel) set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i) @@ -43,3 +44,5 @@ install( DESTINATION ${GR_INCLUDE_DIR}/gruel/swig COMPONENT "gruel_swig" ) + +add_custom_target(pmt_swig DEPENDS ${SWIG_MODULE_pmt_swig_REAL_NAME}) -- cgit From be0c7ca9854734b228067d3515b2d032362e966b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 1 Oct 2012 20:48:42 -0400 Subject: gruel: added unsigned long long int support to the PMT sugar functions. --- gruel/src/include/gruel/pmt_sugar.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt_sugar.h b/gruel/src/include/gruel/pmt_sugar.h index 1d2b38ff1..bde7f716d 100644 --- a/gruel/src/include/gruel/pmt_sugar.h +++ b/gruel/src/include/gruel/pmt_sugar.h @@ -48,6 +48,12 @@ namespace pmt { return pmt_from_long(x); } + //! Make pmt long + static inline pmt_t + mp(long long unsigned x){ + return pmt_from_long(x); + } + //! Make pmt long static inline pmt_t mp(int x){ -- cgit From 1294d9b540b9f68f038b18f706867d87c08be4c8 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 22 Nov 2012 10:51:26 -0800 Subject: gruel: remove erroneous include path from cmake --- gruel/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) (limited to 'gruel') diff --git a/gruel/CMakeLists.txt b/gruel/CMakeLists.txt index 3e8c5166e..627135abe 100644 --- a/gruel/CMakeLists.txt +++ b/gruel/CMakeLists.txt @@ -37,7 +37,6 @@ include(GrMiscUtils) GR_SET_GLOBAL(GRUEL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/include ${CMAKE_CURRENT_BINARY_DIR}/src/include - ${Boost_INCLUDE_DIRS} ) ######################################################################## -- cgit From d6bcc93a6965b9f2fd226a5bb05b051e95cd625d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 28 Nov 2012 20:06:49 -0800 Subject: build: set Boost_INCLUDE_DIRS for components (mostly for OSX and Windows). --- gruel/src/swig/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index 332d5866f..a5e3f9399 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -24,7 +24,7 @@ include(GrPython) include(GrSwig) set(GR_SWIG_TARGET_DEPS pmt_generated) -set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) +set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIRS}) set(GR_SWIG_LIBRARIES gruel) set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i) -- cgit From 92cfb0240005675f4e7a55a81552f4c7a5128cd8 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Wed, 28 Nov 2012 15:15:58 -0800 Subject: core: adding msg_connect, updating msg interface, adding symbolic block names --- gruel/src/include/gruel/msg_accepter.h | 2 +- gruel/src/include/gruel/msg_passing.h | 16 ++++++++-------- gruel/src/include/gruel/pmt.h | 13 +++++++++++++ gruel/src/lib/pmt/pmt.cc | 16 ++++++++++++++++ gruel/src/lib/pmt/qa_pmt_prims.cc | 9 +++++---- gruel/src/swig/pmt_swig.i | 4 ++++ 6 files changed, 47 insertions(+), 13 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/msg_accepter.h b/gruel/src/include/gruel/msg_accepter.h index 2dc1a6859..65abd5a6b 100644 --- a/gruel/src/include/gruel/msg_accepter.h +++ b/gruel/src/include/gruel/msg_accepter.h @@ -43,7 +43,7 @@ namespace gruel { * call will not wait for the message either to arrive at the * destination or to be received. */ - virtual void post(pmt::pmt_t msg) = 0; + virtual void post(pmt::pmt_t which_port, pmt::pmt_t msg) = 0; }; typedef boost::shared_ptr msg_accepter_sptr; diff --git a/gruel/src/include/gruel/msg_passing.h b/gruel/src/include/gruel/msg_passing.h index 0cc0cd111..7230dfc5b 100644 --- a/gruel/src/include/gruel/msg_passing.h +++ b/gruel/src/include/gruel/msg_passing.h @@ -45,9 +45,9 @@ namespace gruel { * \returns msg */ static inline pmt::pmt_t - send(msg_accepter_sptr accepter, const pmt::pmt_t &msg) + send(msg_accepter_sptr accepter, const pmt::pmt_t &which_port, const pmt::pmt_t &msg) { - accepter->post(msg); + accepter->post(which_port, msg); return msg; } @@ -64,9 +64,9 @@ namespace gruel { * \returns msg */ static inline pmt::pmt_t - send(msg_accepter *accepter, const pmt::pmt_t &msg) + send(msg_accepter *accepter, const pmt::pmt_t &which_port, const pmt::pmt_t &msg) { - accepter->post(msg); + accepter->post(which_port, msg); return msg; } @@ -83,9 +83,9 @@ namespace gruel { * \returns msg */ static inline pmt::pmt_t - send(msg_accepter &accepter, const pmt::pmt_t &msg) + send(msg_accepter &accepter, const pmt::pmt_t &which_port, const pmt::pmt_t &msg) { - accepter.post(msg); + accepter.post(which_port, msg); return msg; } @@ -102,9 +102,9 @@ namespace gruel { * \returns msg */ static inline pmt::pmt_t - send(pmt::pmt_t accepter, const pmt::pmt_t &msg) + send(pmt::pmt_t accepter, const pmt::pmt_t &which_port, const pmt::pmt_t &msg) { - return send(pmt_msg_accepter_ref(accepter), msg); + return send(pmt_msg_accepter_ref(accepter), which_port, msg); } } /* namespace gruel */ diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 1e8b38627..a462155c5 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -729,6 +729,10 @@ GRUEL_API pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, con */ GRUEL_API pmt_t pmt_list_add(pmt_t list, const pmt_t& item); +/*! + * \brief Return \p list with \p item removed from it. + */ +GRUEL_API pmt_t pmt_list_rm(pmt_t list, const pmt_t& item); /* * ------------------------------------------------------------------------ @@ -805,6 +809,15 @@ GRUEL_API std::string pmt_serialize_str(pmt_t obj); */ GRUEL_API pmt_t pmt_deserialize_str(std::string str); +/*! + * \brief Provide a comparator function object to allow pmt use in stl types + */ +class pmt_comperator { + public: + bool operator()(pmt::pmt_t const& p1, pmt::pmt_t const& p2) const + { return pmt::pmt_eqv(p1,p2)?false:p1.get()>p2.get(); } + }; + } /* namespace pmt */ #include diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index 1d9125d4e..3eb39ed7b 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -1324,6 +1324,22 @@ pmt_list_add(pmt_t list, const pmt_t& item) return pmt_reverse(pmt_cons(item, pmt_reverse(list))); } +pmt_t +pmt_list_rm(pmt_t list, const pmt_t& item) +{ + if(pmt_is_pair(list)){ + pmt_t left = pmt_car(list); + pmt_t right = pmt_cdr(list); + if(!pmt_equal(left, item)){ + return pmt_cons(left, pmt_list_rm(right, item)); + } else { + return pmt_list_rm(right, item); + } + } else { + return list; + } +} + pmt_t pmt_caar(pmt_t pair) { diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 6212b8ea4..1bf5fcfb1 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -472,7 +472,7 @@ 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){}; + void post(pmt_t,pmt_t){}; }; qa_pmt_msg_accepter_nop::~qa_pmt_msg_accepter_nop(){} @@ -495,9 +495,10 @@ qa_pmt_prims::test_msg_accepter() 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); + pmt_t port(pmt_intern("port")); + gruel::send(ma0.get(), port, sym); + gruel::send(ma0, port, sym); + gruel::send(p1, port, sym); } diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 45cfceadc..d46143424 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -696,6 +696,10 @@ pmt_t pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& */ pmt_t pmt_list_add(pmt_t list, const pmt_t& item); +/*! + * \brief Return \p list with \p item removed + */ +pmt_t pmt_list_rm(pmt_t list, const pmt_t& item); /* * ------------------------------------------------------------------------ -- cgit From 6cc818260128df57c51a41e4e6aa459de5faf4fe Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Fri, 30 Nov 2012 22:31:43 -0800 Subject: core: gr_blocks can now have only message ports with no general_work() * msg only blocks now get thread context * added blocking msg queue delete call * added gr_message_strobe block * added grc definitions for message_debug, message_strobe, pdu_to_tagged_stream, tagged_stream_to_pdu. * allow message fan-in connections in GRC --- gruel/src/include/gruel/msg_accepter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/msg_accepter.h b/gruel/src/include/gruel/msg_accepter.h index 65abd5a6b..45acb3c78 100644 --- a/gruel/src/include/gruel/msg_accepter.h +++ b/gruel/src/include/gruel/msg_accepter.h @@ -37,7 +37,7 @@ namespace gruel { virtual ~msg_accepter(); /*! - * \brief send \p msg to \p msg_accepter + * \brief send \p msg to \p msg_accepter on port \p which_port * * Sending a message is an asynchronous operation. The \p post * call will not wait for the message either to arrive at the -- cgit From 197aa3c917c8750729e20ead831bb3a3dbce322e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 3 Dec 2012 14:57:00 -0500 Subject: Docs: Fixing Doxygen markup for missing constructor parameters. --- gruel/src/include/gruel/msg_passing.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/msg_passing.h b/gruel/src/include/gruel/msg_passing.h index 7230dfc5b..25f30118f 100644 --- a/gruel/src/include/gruel/msg_passing.h +++ b/gruel/src/include/gruel/msg_passing.h @@ -36,6 +36,7 @@ namespace gruel { * \brief send message to msg_accepter * * \param accepter is the target of the send. + * \param which_port A pmt symbol describing the port by name. * \param msg is the message to send. It's usually a pmt tuple. * * Sending a message is an asynchronous operation. The \p send @@ -55,6 +56,7 @@ namespace gruel { * \brief send message to msg_accepter * * \param accepter is the target of the send. + * \param which_port A pmt symbol describing the port by name. * \param msg is the message to send. It's usually a pmt tuple. * * Sending a message is an asynchronous operation. The \p send @@ -74,6 +76,7 @@ namespace gruel { * \brief send message to msg_accepter * * \param accepter is the target of the send. + * \param which_port A pmt symbol describing the port by name. * \param msg is the message to send. It's usually a pmt tuple. * * Sending a message is an asynchronous operation. The \p send @@ -93,6 +96,7 @@ namespace gruel { * \brief send message to msg_accepter * * \param accepter is the target of the send. precond: pmt_is_msg_accepter(accepter) + * \param which_port A pmt symbol describing the port by name. * \param msg is the message to send. It's usually a pmt tuple. * * Sending a message is an asynchronous operation. The \p send -- cgit From 52ca5e2765b7a4532d26502b5b76b7c85c5019d7 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Fri, 7 Dec 2012 09:28:41 -0800 Subject: core: added gr_tuntap_pdu, gr_socket_pdu, and msg passing enhancements --- gruel/src/include/gruel/pmt.h | 6 ++++++ gruel/src/lib/pmt/pmt.cc | 16 ++++++++++++++++ gruel/src/swig/pmt_swig.i | 5 +++++ 3 files changed, 27 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index a462155c5..d09686783 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -734,6 +734,12 @@ GRUEL_API pmt_t pmt_list_add(pmt_t list, const pmt_t& item); */ GRUEL_API pmt_t pmt_list_rm(pmt_t list, const pmt_t& item); +/*! + * \brief Return bool of \p list contains \p item + */ +GRUEL_API bool pmt_list_has(pmt_t list, const pmt_t& item); + + /* * ------------------------------------------------------------------------ * read / write diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index 3eb39ed7b..e5baca98a 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -1340,6 +1340,22 @@ pmt_list_rm(pmt_t list, const pmt_t& item) } } +bool +pmt_list_has(pmt_t list, const pmt_t& item) +{ + if(pmt_is_pair(list)){ + pmt_t left = pmt_car(list); + pmt_t right = pmt_cdr(list); + if(pmt_equal(left,item)) + return true; + return pmt_list_has(right, item); + } else { + if(pmt_is_null(list)) + return false; + throw std::runtime_error("list contains invalid format!"); + } +} + pmt_t pmt_caar(pmt_t pair) { diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index d46143424..b1628c998 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -701,6 +701,11 @@ pmt_t pmt_list_add(pmt_t list, const pmt_t& item); */ pmt_t pmt_list_rm(pmt_t list, const pmt_t& item); +/*! + * \brief Return bool of \p list contains \p item + */ +bool pmt_list_has(pmt_t list, const pmt_t& item); + /* * ------------------------------------------------------------------------ * read / write -- cgit From ecd62ef7b948d9ab14817a8df205373284362f0e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 13 Dec 2012 18:08:14 -0500 Subject: gruel: allow us to use pmt_init_Xvector methods in python. --- gruel/src/include/gruel/pmt.h | 13 ++++++++++++ gruel/src/lib/pmt/unv_template.cc.t | 7 +++++++ gruel/src/swig/pmt_swig.i | 42 ++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 10 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index d09686783..1dd8eb74b 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace gruel { class msg_accepter; @@ -412,17 +413,29 @@ GRUEL_API pmt_t pmt_make_c32vector(size_t k, std::complex fill); GRUEL_API pmt_t pmt_make_c64vector(size_t k, std::complex fill); GRUEL_API pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); +GRUEL_API pmt_t pmt_init_u8vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_s8vector(size_t k, const int8_t *data); +GRUEL_API pmt_t pmt_init_s8vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); +GRUEL_API pmt_t pmt_init_u16vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_s16vector(size_t k, const int16_t *data); +GRUEL_API pmt_t pmt_init_s16vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); +GRUEL_API pmt_t pmt_init_u32vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_s32vector(size_t k, const int32_t *data); +GRUEL_API pmt_t pmt_init_s32vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_u64vector(size_t k, const uint64_t *data); +GRUEL_API pmt_t pmt_init_u64vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_s64vector(size_t k, const int64_t *data); +GRUEL_API pmt_t pmt_init_s64vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_f32vector(size_t k, const float *data); +GRUEL_API pmt_t pmt_init_f32vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_f64vector(size_t k, const double *data); +GRUEL_API pmt_t pmt_init_f64vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_c32vector(size_t k, const std::complex *data); +GRUEL_API pmt_t pmt_init_c32vector(size_t k, const std::vector< std::complex > &data); GRUEL_API pmt_t pmt_init_c64vector(size_t k, const std::complex *data); +GRUEL_API pmt_t pmt_init_c64vector(size_t k, const std::vector< std::complex > &data); GRUEL_API uint8_t pmt_u8vector_ref(pmt_t v, size_t k); GRUEL_API int8_t pmt_s8vector_ref(pmt_t v, size_t k); diff --git a/gruel/src/lib/pmt/unv_template.cc.t b/gruel/src/lib/pmt/unv_template.cc.t index 566168c3d..f74397421 100644 --- a/gruel/src/lib/pmt/unv_template.cc.t +++ b/gruel/src/lib/pmt/unv_template.cc.t @@ -87,6 +87,13 @@ pmt_init_@TAG@vector(size_t k, const @TYPE@ *data) return pmt_t(new pmt_@TAG@vector(k, data)); } +pmt_t +pmt_init_@TAG@vector(size_t k, const std::vector< @TYPE@ > &data) +{ + + return pmt_t(new pmt_@TAG@vector(k, &data[0])); +} + @TYPE@ pmt_@TAG@vector_ref(pmt_t vector, size_t k) { diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index b1628c998..67dda5c3f 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -38,6 +38,27 @@ //load generated python docstrings %include "pmt_swig_doc.i" +%include +%include +%include + +namespace std { + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector; + %template() vector< complex >; + %template() vector< complex >; +}; + //////////////////////////////////////////////////////////////////////// // Language independent exception handler //////////////////////////////////////////////////////////////////////// @@ -380,16 +401,17 @@ pmt_t pmt_make_f64vector(size_t k, double fill); pmt_t pmt_make_c32vector(size_t k, std::complex fill); pmt_t pmt_make_c64vector(size_t k, std::complex fill); -pmt_t pmt_init_u8vector(size_t k, const uint8_t *data); -pmt_t pmt_init_s8vector(size_t k, const int8_t *data); -pmt_t pmt_init_u16vector(size_t k, const uint16_t *data); -pmt_t pmt_init_s16vector(size_t k, const int16_t *data); -pmt_t pmt_init_u32vector(size_t k, const uint32_t *data); -pmt_t pmt_init_s32vector(size_t k, const int32_t *data); -pmt_t pmt_init_f32vector(size_t k, const float *data); -pmt_t pmt_init_f64vector(size_t k, const double *data); -pmt_t pmt_init_c32vector(size_t k, const std::complex *data); -pmt_t pmt_init_c64vector(size_t k, const std::complex *data); + +pmt_t pmt_init_u8vector(size_t k, const std::vector &data); +pmt_t pmt_init_s8vector(size_t k, const std::vector &data); +pmt_t pmt_init_u16vector(size_t k, const std::vector &data); +pmt_t pmt_init_s16vector(size_t k, const std::vector &data); +pmt_t pmt_init_u32vector(size_t k, const std::vector &data); +pmt_t pmt_init_s32vector(size_t k, const std::vector &data); +pmt_t pmt_init_f32vector(size_t k, const std::vector &data); +pmt_t pmt_init_f64vector(size_t k, const std::vector &data); +pmt_t pmt_init_c32vector(size_t k, const std::vector< std::complex > &data); +pmt_t pmt_init_c64vector(size_t k, const std::vector< std::complex > &data); uint8_t pmt_u8vector_ref(pmt_t v, size_t k); int8_t pmt_s8vector_ref(pmt_t v, size_t k); -- cgit From 8e8ed231cd2469e1a39c5ae6af23ac9b29264af7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Dec 2012 16:00:27 -0500 Subject: gruel: Enabling serialize/deserialize for PMT vectors. --- gruel/src/include/gruel/pmt.h | 4 +- gruel/src/lib/pmt/pmt_serialize.cc | 344 ++++++++++++++++++++++++++++++++++++- gruel/src/python/qa_pmt.py | 76 +++++++- gruel/src/swig/pmt_swig.i | 8 +- 4 files changed, 412 insertions(+), 20 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 1dd8eb74b..68b122105 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -433,9 +433,9 @@ GRUEL_API pmt_t pmt_init_f32vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_f64vector(size_t k, const double *data); GRUEL_API pmt_t pmt_init_f64vector(size_t k, const std::vector &data); GRUEL_API pmt_t pmt_init_c32vector(size_t k, const std::complex *data); -GRUEL_API pmt_t pmt_init_c32vector(size_t k, const std::vector< std::complex > &data); +GRUEL_API pmt_t pmt_init_c32vector(size_t k, const std::vector > &data); GRUEL_API pmt_t pmt_init_c64vector(size_t k, const std::complex *data); -GRUEL_API pmt_t pmt_init_c64vector(size_t k, const std::vector< std::complex > &data); +GRUEL_API pmt_t pmt_init_c64vector(size_t k, const std::vector > &data); GRUEL_API uint8_t pmt_u8vector_ref(pmt_t v, size_t k); GRUEL_API int8_t pmt_s8vector_ref(pmt_t v, size_t k); diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc index a19809a66..1ee7ca1fe 100644 --- a/gruel/src/lib/pmt/pmt_serialize.cc +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -309,11 +309,192 @@ pmt_serialize(pmt_t obj, std::streambuf &sb) } - if (pmt_is_vector(obj)) - throw pmt_notimplemented("pmt_serialize (vector)", obj); + if (pmt_is_vector(obj)) { + size_t vec_len = pmt::pmt_length(obj); + ok = serialize_untagged_u8(PST_VECTOR, sb); + ok &= serialize_untagged_u32(vec_len, sb); + for(size_t i=0; i c = pmt_c32vector_ref(obj, i); + ok &= serialize_untagged_f64(c.real(), sb); + ok &= serialize_untagged_f64(c.imag(), sb); + } + return ok; + } + + if(pmt_is_c64vector(obj)) { + ok = serialize_untagged_u8(PST_UNIFORM_VECTOR, sb); + ok &= serialize_untagged_u8(UVI_C64, sb); + ok &= serialize_untagged_u32(vec_len, sb); + ok &= serialize_untagged_u8(npad, sb); + for(size_t i=0; i c = pmt_c64vector_ref(obj, i); + ok &= serialize_untagged_f64(c.real(), sb); + ok &= serialize_untagged_f64(c.imag(), sb); + } + return ok; + } + } if (pmt_is_dict(obj)) throw pmt_notimplemented("pmt_serialize (dict)", obj); @@ -342,7 +523,7 @@ pmt_t pmt_deserialize(std::streambuf &sb) { uint8_t tag; - //uint8_t u8; + uint8_t u8; uint16_t u16; uint32_t u32; uint64_t u64; @@ -408,8 +589,159 @@ pmt_deserialize(std::streambuf &sb) } case PST_VECTOR: - case PST_DICT: + { + uint32_t nitems; + if(!deserialize_untagged_u32(&nitems, sb)) + goto error; + pmt_t vec = pmt_make_vector(nitems, PMT_NIL); + for(uint32_t i=0; i(f64)); + } + return vec; + } + case(UVI_F64): + { + pmt_t vec = pmt_make_f64vector(nitems, 0); + for(uint32_t i=0; i c; + deserialize_untagged_f64(&f64, sb); + c.real(static_cast(f64)); + deserialize_untagged_f64(&f64, sb); + c.imag(static_cast(f64)); + pmt_c32vector_set(vec, i, c); + } + return vec; + } + + case(UVI_C64): + { + pmt_t vec = pmt_make_c64vector(nitems, 0); + for(uint32_t i=0; i c; + deserialize_untagged_f64(&f64, sb); + c.real(f64); + deserialize_untagged_f64(&f64, sb); + c.imag(f64); + pmt_c64vector_set(vec, i, c); + } + return vec; + } + + default: + throw pmt_exception("pmt_deserialize: malformed input stream, tag value = ", + pmt_from_long(tag)); + } + } + + case PST_DICT: case PST_COMMENT: throw pmt_notimplemented("pmt_deserialize: tag value = ", pmt_from_long(tag)); diff --git a/gruel/src/python/qa_pmt.py b/gruel/src/python/qa_pmt.py index 1ef4fed15..59a5725fc 100755 --- a/gruel/src/python/qa_pmt.py +++ b/gruel/src/python/qa_pmt.py @@ -21,22 +21,82 @@ # import unittest -import pmt_swig +import pmt_swig as pmt class test_gruel_pmt(unittest.TestCase): def test01 (self): - a = pmt_swig.pmt_intern("a") - b = pmt_swig.pmt_from_double(123765) - d1 = pmt_swig.pmt_make_dict() - d2 = pmt_swig.pmt_dict_add(d1, a, b) - pmt_swig.pmt_print(d2) + a = pmt.pmt_intern("a") + b = pmt.pmt_from_double(123765) + d1 = pmt.pmt_make_dict() + d2 = pmt.pmt_dict_add(d1, a, b) + pmt.pmt_print(d2) def test02 (self): const = 123765 - x_pmt = pmt_swig.pmt_from_double(const) - x_int = pmt_swig.pmt_to_double(x_pmt) + x_pmt = pmt.pmt_from_double(const) + x_int = pmt.pmt_to_double(x_pmt) self.assertEqual(x_int, const) + def test03(self): + v = pmt.pmt_init_f32vector(3, [11, -22, 33]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test04(self): + v = pmt.pmt_init_f64vector(3, [11, -22, 33]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test05(self): + v = pmt.pmt_init_u8vector(3, [11, 22, 33]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test06(self): + v = pmt.pmt_init_s8vector(3, [11, -22, 33]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test07(self): + v = pmt.pmt_init_u16vector(3, [11, 22, 33]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test08(self): + v = pmt.pmt_init_s16vector(3, [11, -22, 33]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test09(self): + v = pmt.pmt_init_u32vector(3, [11, 22, 33]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test10(self): + v = pmt.pmt_init_s32vector(3, [11, -22, 33]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test11(self): + v = pmt.pmt_init_c32vector(3, [11 + -101j, -22 + 202j, 33 + -303j]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + + def test12(self): + v = pmt.pmt_init_c64vector(3, [11 + -101j, -22 + 202j, 33 + -303j]) + s = pmt.pmt_serialize_str(v) + d = pmt.pmt_deserialize_str(s) + self.assertTrue(pmt.pmt_equal(v, d)) + if __name__ == '__main__': unittest.main() diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 67dda5c3f..b65857167 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -55,8 +55,8 @@ namespace std { %template() vector; %template() vector; %template() vector; - %template() vector< complex >; - %template() vector< complex >; + %template() vector< std::complex >; + %template() vector< std::complex >; }; //////////////////////////////////////////////////////////////////////// @@ -410,8 +410,8 @@ pmt_t pmt_init_u32vector(size_t k, const std::vector &data); pmt_t pmt_init_s32vector(size_t k, const std::vector &data); pmt_t pmt_init_f32vector(size_t k, const std::vector &data); pmt_t pmt_init_f64vector(size_t k, const std::vector &data); -pmt_t pmt_init_c32vector(size_t k, const std::vector< std::complex > &data); -pmt_t pmt_init_c64vector(size_t k, const std::vector< std::complex > &data); +pmt_t pmt_init_c32vector(size_t k, const std::vector > &data); +pmt_t pmt_init_c64vector(size_t k, const std::vector > &data); uint8_t pmt_u8vector_ref(pmt_t v, size_t k); int8_t pmt_s8vector_ref(pmt_t v, size_t k); -- cgit From 92bbf34ce7f8a8c2e335b5ee244b1269175929b2 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Fri, 14 Dec 2012 15:03:08 -0800 Subject: Revert "gruel: remove erroneous include path from cmake" This reverts commit 1294d9b540b9f68f038b18f706867d87c08be4c8. --- gruel/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'gruel') diff --git a/gruel/CMakeLists.txt b/gruel/CMakeLists.txt index 627135abe..3e8c5166e 100644 --- a/gruel/CMakeLists.txt +++ b/gruel/CMakeLists.txt @@ -37,6 +37,7 @@ include(GrMiscUtils) GR_SET_GLOBAL(GRUEL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/include ${CMAKE_CURRENT_BINARY_DIR}/src/include + ${Boost_INCLUDE_DIRS} ) ######################################################################## -- cgit From b15b38df132ae662c1b9e3ebe5ea5ba4f7180afa Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 17 Dec 2012 16:09:34 -0500 Subject: gruel: changing PMT (de)serialize of complex to make more portable (apparently; for OSX). --- gruel/src/lib/pmt/pmt_serialize.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc index 1ee7ca1fe..24be6b772 100644 --- a/gruel/src/lib/pmt/pmt_serialize.cc +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -711,12 +711,12 @@ pmt_deserialize(std::streambuf &sb) { pmt_t vec = pmt_make_c32vector(nitems, 0); for(uint32_t i=0; i c; + float re, im; deserialize_untagged_f64(&f64, sb); - c.real(static_cast(f64)); + re = static_cast(f64); deserialize_untagged_f64(&f64, sb); - c.imag(static_cast(f64)); - pmt_c32vector_set(vec, i, c); + im = static_cast(f64); + pmt_c32vector_set(vec, i, std::complex(re, im)); } return vec; } @@ -725,12 +725,12 @@ pmt_deserialize(std::streambuf &sb) { pmt_t vec = pmt_make_c64vector(nitems, 0); for(uint32_t i=0; i c; + double re, im; deserialize_untagged_f64(&f64, sb); - c.real(f64); + re = f64; deserialize_untagged_f64(&f64, sb); - c.imag(f64); - pmt_c64vector_set(vec, i, c); + im = f64; + pmt_c64vector_set(vec, i, std::complex(re, im)); } return vec; } -- cgit From eff53a185e1c25fc54768f480e1be1a02bba699e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 19 Dec 2012 18:03:49 -0500 Subject: gruel: pmt_Xvector_elements can be used in Python to return a Python tuple. --- gruel/src/include/gruel/pmt.h | 14 +++++++++++ gruel/src/lib/pmt/unv_template.cc.t | 12 ++++++++++ gruel/src/swig/pmt_swig.i | 48 +++++++++++++------------------------ 3 files changed, 43 insertions(+), 31 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 68b122105..468fa3d28 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -480,6 +480,20 @@ GRUEL_API const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len GRUEL_API const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements GRUEL_API const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements +// len is in elements +GRUEL_API const std::vector pmt_u8vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_s8vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_u16vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_s16vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_u32vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_s32vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_u64vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_s64vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_f32vector_elements(pmt_t v); +GRUEL_API const std::vector pmt_f64vector_elements(pmt_t v); +GRUEL_API const std::vector > pmt_c32vector_elements(pmt_t v); +GRUEL_API const std::vector > pmt_c64vector_elements(pmt_t v); + // Return non-const pointers to the elements GRUEL_API void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes diff --git a/gruel/src/lib/pmt/unv_template.cc.t b/gruel/src/lib/pmt/unv_template.cc.t index f74397421..1ed505e29 100644 --- a/gruel/src/lib/pmt/unv_template.cc.t +++ b/gruel/src/lib/pmt/unv_template.cc.t @@ -118,6 +118,18 @@ pmt_@TAG@vector_elements(pmt_t vector, size_t &len) return _@TAG@vector(vector)->elements(len); } +const std::vector< @TYPE@ > +pmt_@TAG@vector_elements(pmt_t vector) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_elements", vector); + size_t len; + const @TYPE@ *array = _@TAG@vector(vector)->elements(len); + const std::vector< @TYPE@ > vec(array, array+len); + return vec; +} + + @TYPE@ * pmt_@TAG@vector_writable_elements(pmt_t vector, size_t &len) { diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index b65857167..1541e6f4f 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -441,37 +441,23 @@ void pmt_c64vector_set(pmt_t v, size_t k, std::complex x); // Return const pointers to the elements -const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements -const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements -const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements -const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements -const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements -const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements -const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements - -// Return non-const pointers to the elements - -void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +%apply size_t & INOUT { size_t &len }; + +// works with any; len is in bytes +// Returns an opaque Python type +const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); + +// Returns a Python tuple +const std::vector pmt_u8vector_elements(pmt_t v); +const std::vector pmt_s8vector_elements(pmt_t v); +const std::vector pmt_u16vector_elements(pmt_t v); +const std::vector pmt_s16vector_elements(pmt_t v); +const std::vector pmt_u32vector_elements(pmt_t v); +const std::vector pmt_s32vector_elements(pmt_t v); +const std::vector pmt_f32vector_elements(pmt_t v); +const std::vector pmt_f64vector_elements(pmt_t v); +const std::vector > pmt_c32vector_elements(pmt_t v); +const std::vector > pmt_c64vector_elements(pmt_t v); /* * ------------------------------------------------------------------------ -- cgit From b60396ab638534aff05fa5b0c8b8c0b334b4e58e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 20 Dec 2012 11:54:22 -0500 Subject: gruel: adding a 'pmt_from_complex' call (more clear than pmt_make_rectangular). --- gruel/src/include/gruel/pmt.h | 6 ++++++ gruel/src/lib/pmt/pmt.cc | 10 ++++++++++ gruel/src/lib/pmt/qa_pmt_prims.cc | 12 ++++++++++++ gruel/src/swig/pmt_swig.i | 2 ++ 4 files changed, 30 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 468fa3d28..383a1d44d 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -223,6 +223,12 @@ GRUEL_API bool pmt_is_complex(pmt_t obj); //! Return a complex number constructed of the given real and imaginary parts. GRUEL_API pmt_t pmt_make_rectangular(double re, double im); +//! Return a complex number constructed of the given real and imaginary parts. +GRUEL_API pmt_t pmt_from_complex(double re, double im); + +//! Return a complex number constructed of the given a complex number. +GRUEL_API pmt_t pmt_from_complex(const std::complex &z); + /*! * If \p z is complex, real or integer, return the closest complex. * Otherwise, raise the wrong_type exception. diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index e5baca98a..1d1e9ba7c 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -387,10 +387,20 @@ pmt_is_complex(pmt_t x) pmt_t pmt_make_rectangular(double re, double im) +{ + return pmt_from_complex(re, im); +} + +pmt_t pmt_from_complex(double re, double im) { return pmt_t(new pmt_complex(std::complex(re, im))); } +pmt_t pmt_from_complex(const std::complex &z) +{ + return pmt_t(new pmt_complex(z)); +} + std::complex pmt_to_complex(pmt_t x) { diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 1bf5fcfb1..3ae4d70b6 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -134,12 +134,24 @@ qa_pmt_prims::test_complexes() { pmt_t p1 = pmt_make_rectangular(2, -3); pmt_t m1 = pmt_make_rectangular(-3, 2); + pmt_t p2 = pmt_from_complex(2, -3); + pmt_t m2 = pmt_from_complex(-3, 2); + pmt_t p3 = pmt_from_complex(std::complex(2, -3)); + pmt_t m3 = pmt_from_complex(std::complex(-3, 2)); CPPUNIT_ASSERT(!pmt_is_complex(PMT_T)); CPPUNIT_ASSERT(pmt_is_complex(p1)); CPPUNIT_ASSERT(pmt_is_complex(m1)); + CPPUNIT_ASSERT(pmt_is_complex(p2)); + CPPUNIT_ASSERT(pmt_is_complex(m2)); + CPPUNIT_ASSERT(pmt_is_complex(p3)); + CPPUNIT_ASSERT(pmt_is_complex(m3)); CPPUNIT_ASSERT_THROW(pmt_to_complex(PMT_T), pmt_wrong_type); CPPUNIT_ASSERT_EQUAL(std::complex(2, -3), pmt_to_complex(p1)); CPPUNIT_ASSERT_EQUAL(std::complex(-3, 2), pmt_to_complex(m1)); + CPPUNIT_ASSERT_EQUAL(std::complex(2, -3), pmt_to_complex(p2)); + CPPUNIT_ASSERT_EQUAL(std::complex(-3, 2), pmt_to_complex(m2)); + CPPUNIT_ASSERT_EQUAL(std::complex(2, -3), pmt_to_complex(p3)); + CPPUNIT_ASSERT_EQUAL(std::complex(-3, 2), pmt_to_complex(m3)); CPPUNIT_ASSERT_EQUAL(std::complex(1.0, 0), pmt_to_complex(pmt_from_long(1))); CPPUNIT_ASSERT_EQUAL(std::complex(1.0, 0), pmt_to_complex(pmt_from_double(1.0))); } diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 1541e6f4f..84f48b099 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -212,6 +212,8 @@ bool pmt_is_complex(pmt_t obj); //! Return a complex number constructed of the given real and imaginary parts. pmt_t pmt_make_rectangular(double re, double im); +pmt_t pmt_from_complex(const std::complex &z); + /*! * If \p z is complex, real or integer, return the closest complex. * Otherwise, raise the wrong_type exception. -- cgit From e788c523d4f8de3efd64a64f148ac1bf25ea032d Mon Sep 17 00:00:00 2001 From: Michael L Dickens Date: Tue, 1 Jan 2013 21:42:23 -0500 Subject: Tweak INCLUDE dirs such that INCLUDE_DIRECTORIES and LINK_DIRECTORIES are ordered as: internal build and source for this component, other components (internal build and source, or already installed), non-project non-system dependencies (e.g., Qt, Boost, Python), system dependencies (e.g., CoreAudio). --- gruel/src/lib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/lib/CMakeLists.txt b/gruel/src/lib/CMakeLists.txt index e7713536c..e33b80d64 100644 --- a/gruel/src/lib/CMakeLists.txt +++ b/gruel/src/lib/CMakeLists.txt @@ -64,8 +64,8 @@ GR_INCLUDE_SUBDIRECTORY(pmt) ######################################################################## # Setup the include and linker paths ######################################################################## -include_directories(${GRUEL_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${GRUEL_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) -- cgit From baaf2b6cf06f464a710c3f36db4c9275dd915d92 Mon Sep 17 00:00:00 2001 From: Michael L Dickens Date: Thu, 3 Jan 2013 10:30:33 -0500 Subject: Reorder SWIG_INCLUDE_DIRS --- gruel/src/swig/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index a5e3f9399..aeceaa605 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -24,7 +24,11 @@ include(GrPython) include(GrSwig) set(GR_SWIG_TARGET_DEPS pmt_generated) -set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIRS}) +set(GR_SWIG_INCLUDE_DIRS + ${CMAKE_CURRENT_BINARY_DIR} + ${GRUEL_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} +) set(GR_SWIG_LIBRARIES gruel) set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i) -- cgit From a2c6f4d49049f86c0cc867368194d2e08812379a Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 1 Feb 2013 20:20:54 +0100 Subject: pmt: added python converters --- gruel/src/python/CMakeLists.txt | 5 +- gruel/src/python/pmt/__init__.py | 2 + gruel/src/python/pmt/pmt_to_python.py | 97 +++++++++++++++++++++++++++++++++++ gruel/src/python/qa_pmt_to_python.py | 34 ++++++++++++ 4 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 gruel/src/python/pmt/pmt_to_python.py create mode 100755 gruel/src/python/qa_pmt_to_python.py (limited to 'gruel') diff --git a/gruel/src/python/CMakeLists.txt b/gruel/src/python/CMakeLists.txt index 13f2111ba..f5c4ac47a 100644 --- a/gruel/src/python/CMakeLists.txt +++ b/gruel/src/python/CMakeLists.txt @@ -28,8 +28,9 @@ GR_PYTHON_INSTALL( COMPONENT "gruel_python" ) -GR_PYTHON_INSTALL( - FILES pmt/__init__.py +GR_PYTHON_INSTALL(FILES + pmt/__init__.py + pmt/pmt_to_python.py DESTINATION ${GR_PYTHON_DIR}/gruel/pmt COMPONENT "gruel_python" ) diff --git a/gruel/src/python/pmt/__init__.py b/gruel/src/python/pmt/__init__.py index 0862af0eb..bc933e80a 100644 --- a/gruel/src/python/pmt/__init__.py +++ b/gruel/src/python/pmt/__init__.py @@ -26,4 +26,6 @@ The GNU Radio Utility Etcetera Library's Polymorphic Types for Python. ''' from pmt_swig import * +from pmt_to_python import pmt_to_python as to_python +from pmt_to_python import python_to_pmt as to_pmt diff --git a/gruel/src/python/pmt/pmt_to_python.py b/gruel/src/python/pmt/pmt_to_python.py new file mode 100644 index 000000000..030c1c11d --- /dev/null +++ b/gruel/src/python/pmt/pmt_to_python.py @@ -0,0 +1,97 @@ +# Copyright 2012,2013 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. + +try: import pmt_swig as pmt +except: import pmt +import numpy + +#define missing +def pmt_to_tuple(p): + elems = list() + for i in range(pmt.pmt_length(p)): + elem = pmt.pmt_tuple_ref(p, i) + elems.append(pmt_to_python(elem)) + return tuple(elems) + +def pmt_from_tuple(p): + args = map(python_to_pmt, p) + return pmt.pmt_make_tuple(*args) + +def pmt_to_vector(p): + v = list() + for i in range(pmt.pmt_length(p)): + elem = pmt.pmt_vector_ref(p, i) + v.append(pmt_to_python(elem)) + return v + +def pmt_from_vector(p): + v = pmt.pmt_make_vector(len(p), pmt.PMT_NIL) + for i, elem in enumerate(p): + pmt.pmt_vector_set(v, i, python_to_pmt(elem)) + return v + +def pmt_to_dict(p): + d = dict() + items = pmt.pmt_dict_items(p) + for i in range(pmt.pmt_length(items)): + pair = pmt.pmt_nth(i, items) + k = pmt.pmt_car(pair) + v = pmt.pmt_cdr(pair) + d[pmt_to_python(k)] = pmt_to_python(v) + return d + +def pmt_from_dict(p): + d = pmt.pmt_make_dict() + for k, v in p.iteritems(): + #dict is immutable -> therefore pmt_dict_add returns the new dict + d = pmt.pmt_dict_add(d, python_to_pmt(k), python_to_pmt(v)) + return d + +def numpy_to_blob(p): + p = p.view(numpy.uint8) + b = pmt.pmt_make_blob(len(p)) + pmt.pmt_blob_data(b)[:] = p + return b + +THE_TABLE = ( #python type, check pmt type, to python, from python + (None, pmt.pmt_is_null, lambda x: None, lambda x: pmt.PMT_NIL), + (bool, pmt.pmt_is_bool, pmt.pmt_to_bool, pmt.pmt_from_bool), + (str, pmt.pmt_is_symbol, pmt.pmt_symbol_to_string, pmt.pmt_string_to_symbol), + (int, pmt.pmt_is_integer, pmt.pmt_to_long, pmt.pmt_from_long), + (long, pmt.pmt_is_uint64, lambda x: long(pmt.pmt_to_uint64(x)), pmt.pmt_from_uint64), + (float, pmt.pmt_is_real, pmt.pmt_to_double, pmt.pmt_from_double), + (complex, pmt.pmt_is_complex, pmt.pmt_to_complex, pmt.pmt_from_complex), + (tuple, pmt.pmt_is_tuple, pmt_to_tuple, pmt_from_tuple), + (list, pmt.pmt_is_vector, pmt_to_vector, pmt_from_vector), + (dict, pmt.pmt_is_dict, pmt_to_dict, pmt_from_dict), + (numpy.ndarray, pmt.pmt_is_blob, pmt.pmt_blob_data, numpy_to_blob), +) + +def pmt_to_python(p): + for python_type, pmt_check, to_python, from_python in THE_TABLE: + if pmt_check(p): return to_python(p) + return p #give up, we return the same + +def python_to_pmt(p): + for python_type, pmt_check, to_python, from_python in THE_TABLE: + if python_type is None: + if p == None: return from_python(p) + elif isinstance(p, python_type): return from_python(p) + return p #give up, we return the same + diff --git a/gruel/src/python/qa_pmt_to_python.py b/gruel/src/python/qa_pmt_to_python.py new file mode 100755 index 000000000..c63403a52 --- /dev/null +++ b/gruel/src/python/qa_pmt_to_python.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# +# Copyright 2013 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. +# + +import unittest +import pmt + +class test_gruel_pmt_to_python(unittest.TestCase): + + def test01 (self): + b = pmt.pmt_from_double(123765) + self.assertEqual(pmt.to_python(b), 123765) + t = pmt.to_pmt(range(5)) + +if __name__ == '__main__': + unittest.main() -- cgit From 7bc415bd2875132ce321c5913950d23e7c9ad8b1 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 19 Dec 2012 13:37:39 -0500 Subject: gruel: adding wrapper layer for gruel threads to enable setting thread affinity. Working in Linux; programmed for Windows (but untested); nops for OSX. --- gruel/src/include/gruel/thread.h | 19 +++- gruel/src/lib/CMakeLists.txt | 1 + gruel/src/lib/thread.cc | 223 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 gruel/src/lib/thread.cc (limited to 'gruel') diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 63143c8b4..72499808c 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009,2010,2011 Free Software Foundation, Inc. + * Copyright 2009-2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,6 +26,7 @@ #include #include #include +#include namespace gruel { @@ -34,6 +35,22 @@ namespace gruel { typedef boost::mutex::scoped_lock scoped_lock; typedef boost::condition_variable condition_variable; +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) + typedef HANDLE gr_thread_t; +#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) + typedef pthread_t gr_thread_t; +#else + typedef pthread_t gr_thread_t; +#endif + + GRUEL_API gr_thread_t get_current_thread_id(); + GRUEL_API void thread_bind_to_processor(const std::vector &mask); + GRUEL_API void thread_bind_to_processor(unsigned int n); + GRUEL_API void thread_bind_to_processor(gr_thread_t thread, const std::vector &mask); + GRUEL_API void thread_bind_to_processor(gr_thread_t thread, unsigned int n); + GRUEL_API void thread_unbind(); + GRUEL_API void thread_unbind(gr_thread_t thread); + } /* namespace gruel */ #endif /* INCLUDED_THREAD_H */ diff --git a/gruel/src/lib/CMakeLists.txt b/gruel/src/lib/CMakeLists.txt index e33b80d64..717d56660 100644 --- a/gruel/src/lib/CMakeLists.txt +++ b/gruel/src/lib/CMakeLists.txt @@ -76,6 +76,7 @@ link_directories(${Boost_LIBRARY_DIRS}) list(APPEND gruel_sources realtime.cc sys_pri.cc + thread.cc thread_body_wrapper.cc thread_group.cc ) diff --git a/gruel/src/lib/thread.cc b/gruel/src/lib/thread.cc new file mode 100644 index 000000000..46ba1745a --- /dev/null +++ b/gruel/src/lib/thread.cc @@ -0,0 +1,223 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 +#endif + +#include + +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) + +#include + +namespace gruel { + + gr_thread_t + get_current_thread_id() + { + return GetCurrentThread(); + } + + void + thread_bind_to_processor(unsigned int n) + { + std::vector mask(1, n); + thread_bind_to_processor(get_current_thread_id(), mask); + } + + void + thread_bind_to_processor(const std::vector &mask) + { + thread_bind_to_processor(get_current_thread_id(), mask); + } + + void + thread_bind_to_processor(gr_thread_t thread, unsigned int n) + { + std::vector mask(1, n); + thread_bind_to_processor(thread, mask); + } + + void + thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + { + //DWORD_PTR mask = (1 << n); + DWORD_PTR mask = 0; + + std::vector _mask = mask; + std::vector::iterator itr; + for(itr = _mask.begin(); itr != _mask.end(); itr++) + mask |= (1 << (*itr)); + + DWORD_PTR ret = SetThreadAffinityMask(thread, mask); + if(ret == 0) { + std::stringstream s; + s << "thread_bind_to_processor failed with error: " << GetLastError() << std::endl; + throw std::runtime_error(s.str()); + } + } + + void + thread_unbind() + { + thread_bind_unbind(get_current_thread_id()); + } + + void + thread_unbind(gr_thread_t thread) + { + DWORD_PTR mask = sizeof(DWORD_PTR) - 1; + DWORD_PTR ret = SetThreadAffinityMask(thread, mask); + if(ret == 0) { + std::stringstream s; + s << "thread_unbind failed with error: " << GetLastError() << std::endl; + throw std::runtime_error(s.str()); + } + } +} /* namespace gruel */ + +#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) + +namespace gruel { + + gr_thread_t + get_current_thread_id() + { + // Not implemented on OSX + } + + void + thread_bind_to_processor(unsigned int n) + { + // Not implemented on OSX + } + + void + thread_bind_to_processor(gr_thread_t thread, unsigned int n) + { + // Not implemented on OSX + } + + void + thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + { + // Not implemented on OSX + } + + void + thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + + void + thread_unbind() + { + // Not implemented on OSX + } + + void + thread_unbind(gr_thread_t thread) + { + // Not implemented on OSX + } +} /* namespace gruel */ + +#else + +#include +#include +#include + +namespace gruel { + + gr_thread_t + get_current_thread_id() + { + return pthread_self(); + } + + void + thread_bind_to_processor(unsigned int n) + { + std::vector mask(1, n); + thread_bind_to_processor(get_current_thread_id(), mask); + } + + void + thread_bind_to_processor(const std::vector &mask) + { + thread_bind_to_processor(get_current_thread_id(), mask); + } + + void + thread_bind_to_processor(gr_thread_t thread, unsigned int n) + { + std::vector mask(1, n); + thread_bind_to_processor(thread, mask); + } + + void + thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + { + cpu_set_t set; + size_t len = sizeof(cpu_set_t); + std::vector _mask = mask; + std::vector::iterator itr; + + CPU_ZERO(&set); + for(itr = _mask.begin(); itr != _mask.end(); itr++) + CPU_SET(*itr, &set); + + int ret = pthread_setaffinity_np(thread, len, &set); + if(ret != 0) { + std::stringstream s; + s << "thread_bind_to_processor failed with error: " << ret << std::endl; + throw std::runtime_error(s.str()); + } + } + + void + thread_unbind() + { + thread_unbind(get_current_thread_id()); + } + + void + thread_unbind(gr_thread_t thread) + { + cpu_set_t set; + size_t len = sizeof(cpu_set_t); + + CPU_ZERO(&set); + long ncpus = sysconf(_SC_NPROCESSORS_ONLN); + for(long n = 0; n < ncpus; n++) { + CPU_SET(n, &set); + } + + int ret = pthread_setaffinity_np(thread, len, &set); + if(ret != 0) { + std::stringstream s; + s << "thread_unbind failed with error: " << ret << std::endl; + throw std::runtime_error(s.str()); + } + } +} /* namespace gruel */ + +#endif -- cgit From 01eab0c7e283db9c1cfff0a26296a49128062cca Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 19 Dec 2012 13:38:24 -0500 Subject: core: working thread affinity concept into gr_blocks. Example in gnuradio-core/src/examples/mp-sched/affinity_set.py Documentation describing API in docs/doxygen/other/thread_affinity.dox --- gruel/src/lib/thread.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/lib/thread.cc b/gruel/src/lib/thread.cc index 46ba1745a..ab022c0bd 100644 --- a/gruel/src/lib/thread.cc +++ b/gruel/src/lib/thread.cc @@ -118,13 +118,16 @@ namespace gruel { } void - thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + thread_bind_to_processor(const std::vector &mask) { // Not implemented on OSX } void thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + { + // Not implemented on OSX + } void thread_unbind() -- cgit From 8bf083a99c8a0d43d365bdd9ad90e3d840c582e7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 24 Jan 2013 09:26:19 -0500 Subject: gruel: need to include windows.h to know about HANDLE. --- gruel/src/include/gruel/thread.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 72499808c..0427a8efc 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -28,6 +28,10 @@ #include #include +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +#include +#endif + namespace gruel { typedef boost::thread thread; -- cgit From 8511ee7f22f197526e0345554842a9ac422974ae Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 27 Jan 2013 13:32:20 -0500 Subject: sched: added documentation for affinity setting functions. --- gruel/src/include/gruel/thread.h | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 0427a8efc..595b7b1ac 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -39,6 +39,8 @@ namespace gruel { typedef boost::mutex::scoped_lock scoped_lock; typedef boost::condition_variable condition_variable; + /*! \brief a system-dependent typedef for the underlying thread type. + */ #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) typedef HANDLE gr_thread_t; #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) @@ -47,12 +49,83 @@ namespace gruel { typedef pthread_t gr_thread_t; #endif + /*! \brief Get the current thread's ID as a gr_thread_t + * + * We use this when setting the thread affinity or any other + * low-level thread settings. Can be called withing a GNU Radio + * block to get a reference to its current thread ID. + */ GRUEL_API gr_thread_t get_current_thread_id(); + + /*! \brief Bind the current thread to a set of cores. + * + * Wrapper for system-dependent calls to set the affinity of the + * current thread to the processor mask. The mask is simply a + * 1-demensional vector containing the processor or core number from + * 0 to N-1 for N cores. + * + * Note: this does not work on OSX; it is a nop call since OSX does + * not support the concept of thread affinity (and what they do + * support in this way since 10.5 is not what we want or can use in + * this fashion). + */ GRUEL_API void thread_bind_to_processor(const std::vector &mask); + + /*! \brief Convineince function to bind the current thread to a single core. + * + * Wrapper for system-dependent calls to set the affinity of the + * current thread to a given core from 0 to N-1 for N cores. + * + * Note: this does not work on OSX; it is a nop call since OSX does + * not support the concept of thread affinity (and what they do + * support in this way since 10.5 is not what we want or can use in + * this fashion). + */ GRUEL_API void thread_bind_to_processor(unsigned int n); + + /*! \brief Bind a thread to a set of cores. + * + * Wrapper for system-dependent calls to set the affinity of the + * given thread ID to the processor mask. The mask is simply a + * 1-demensional vector containing the processor or core number from + * 0 to N-1 for N cores. + * + * Note: this does not work on OSX; it is a nop call since OSX does + * not support the concept of thread affinity (and what they do + * support in this way since 10.5 is not what we want or can use in + * this fashion). + */ GRUEL_API void thread_bind_to_processor(gr_thread_t thread, const std::vector &mask); + + + /*! \brief Convineince function to bind the a thread to a single core. + * + * Wrapper for system-dependent calls to set the affinity of the + * given thread ID to a given core from 0 to N-1 for N cores. + * + * Note: this does not work on OSX; it is a nop call since OSX does + * not support the concept of thread affinity (and what they do + * support in this way since 10.5 is not what we want or can use in + * this fashion). + */ GRUEL_API void thread_bind_to_processor(gr_thread_t thread, unsigned int n); + + /*! \brief Remove any thread-processor affinity for the current thread. + * + * Note: this does not work on OSX; it is a nop call since OSX does + * not support the concept of thread affinity (and what they do + * support in this way since 10.5 is not what we want or can use in + * this fashion). + */ GRUEL_API void thread_unbind(); + + /*! \brief Remove any thread-processor affinity for a given thread ID. + * + * Note: this does not work on OSX; it is a nop call since OSX does + * not support the concept of thread affinity (and what they do + * support in this way since 10.5 is not what we want or can use in + * this fashion). + */ GRUEL_API void thread_unbind(gr_thread_t thread); } /* namespace gruel */ -- cgit From 0c46b36ed5c52f0003f0cd45195bdee1193a2a33 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Wed, 6 Feb 2013 12:36:13 -0800 Subject: gruel: renamed mask to dword_mask --- gruel/src/lib/thread.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gruel') diff --git a/gruel/src/lib/thread.cc b/gruel/src/lib/thread.cc index ab022c0bd..8ebe822fb 100644 --- a/gruel/src/lib/thread.cc +++ b/gruel/src/lib/thread.cc @@ -61,14 +61,14 @@ namespace gruel { thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) { //DWORD_PTR mask = (1 << n); - DWORD_PTR mask = 0; + DWORD_PTR dword_mask = 0; std::vector _mask = mask; std::vector::iterator itr; for(itr = _mask.begin(); itr != _mask.end(); itr++) - mask |= (1 << (*itr)); + dword_mask |= (1 << (*itr)); - DWORD_PTR ret = SetThreadAffinityMask(thread, mask); + DWORD_PTR ret = SetThreadAffinityMask(thread, dword_mask); if(ret == 0) { std::stringstream s; s << "thread_bind_to_processor failed with error: " << GetLastError() << std::endl; @@ -79,14 +79,14 @@ namespace gruel { void thread_unbind() { - thread_bind_unbind(get_current_thread_id()); + thread_unbind(get_current_thread_id()); } void thread_unbind(gr_thread_t thread) { - DWORD_PTR mask = sizeof(DWORD_PTR) - 1; - DWORD_PTR ret = SetThreadAffinityMask(thread, mask); + DWORD_PTR dword_mask = sizeof(DWORD_PTR) - 1; + DWORD_PTR ret = SetThreadAffinityMask(thread, dword_mask); if(ret == 0) { std::stringstream s; s << "thread_unbind failed with error: " << GetLastError() << std::endl; -- cgit From e05c3cd81e2b3e60a6d09ebd1afbb641c33c8ea9 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Wed, 6 Feb 2013 14:21:11 -0800 Subject: gruel: Added WIN32_LEAN_AND_MEAN definition before windows.h include --- gruel/src/include/gruel/thread.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gruel') diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 595b7b1ac..2172e90d3 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -29,7 +29,13 @@ #include #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + #include + #endif namespace gruel { -- cgit From f27346b27085ea1a78bdada66a1a8e77bbf8a299 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 23 Jan 2013 09:43:49 -0800 Subject: gruel: change scoped_lock mutex to account for Boost deprecation boost::mutex::scoped_lock is going away someday boost::unique_lock is a drop-in replacement --- gruel/src/include/gruel/thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 63143c8b4..c0b54b0a4 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -31,7 +31,7 @@ namespace gruel { typedef boost::thread thread; typedef boost::mutex mutex; - typedef boost::mutex::scoped_lock scoped_lock; + typedef boost::unique_lock scoped_lock; typedef boost::condition_variable condition_variable; } /* namespace gruel */ -- cgit From 78cd4026c0a9b902162e94905b60a9dd44a07bb7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 29 Mar 2013 13:12:36 -0400 Subject: core: addressing issue #529. Using vector instead of vector for affinity mask vector. This is wrong as the mask should be unsigned, but necessary for SWIG to work cleanly on both 32-bit and 64-bit platforms. --- gruel/src/include/gruel/thread.h | 6 +++--- gruel/src/lib/thread.cc | 40 ++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 23 deletions(-) (limited to 'gruel') diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 60832675c..10c6c38cc 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -75,7 +75,7 @@ namespace gruel { * support in this way since 10.5 is not what we want or can use in * this fashion). */ - GRUEL_API void thread_bind_to_processor(const std::vector &mask); + GRUEL_API void thread_bind_to_processor(const std::vector &mask); /*! \brief Convineince function to bind the current thread to a single core. * @@ -87,7 +87,7 @@ namespace gruel { * support in this way since 10.5 is not what we want or can use in * this fashion). */ - GRUEL_API void thread_bind_to_processor(unsigned int n); + GRUEL_API void thread_bind_to_processor(int n); /*! \brief Bind a thread to a set of cores. * @@ -101,7 +101,7 @@ namespace gruel { * support in this way since 10.5 is not what we want or can use in * this fashion). */ - GRUEL_API void thread_bind_to_processor(gr_thread_t thread, const std::vector &mask); + GRUEL_API void thread_bind_to_processor(gr_thread_t thread, const std::vector &mask); /*! \brief Convineince function to bind the a thread to a single core. diff --git a/gruel/src/lib/thread.cc b/gruel/src/lib/thread.cc index 8ebe822fb..a5116b687 100644 --- a/gruel/src/lib/thread.cc +++ b/gruel/src/lib/thread.cc @@ -38,33 +38,33 @@ namespace gruel { } void - thread_bind_to_processor(unsigned int n) + thread_bind_to_processor(int n) { - std::vector mask(1, n); + std::vector mask(1, n); thread_bind_to_processor(get_current_thread_id(), mask); } void - thread_bind_to_processor(const std::vector &mask) + thread_bind_to_processor(const std::vector &mask) { thread_bind_to_processor(get_current_thread_id(), mask); } void - thread_bind_to_processor(gr_thread_t thread, unsigned int n) + thread_bind_to_processor(gr_thread_t thread, int n) { - std::vector mask(1, n); + std::vector mask(1, n); thread_bind_to_processor(thread, mask); } void - thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) { //DWORD_PTR mask = (1 << n); DWORD_PTR dword_mask = 0; - std::vector _mask = mask; - std::vector::iterator itr; + std::vector _mask = mask; + std::vector::iterator itr; for(itr = _mask.begin(); itr != _mask.end(); itr++) dword_mask |= (1 << (*itr)); @@ -106,25 +106,25 @@ namespace gruel { } void - thread_bind_to_processor(unsigned int n) + thread_bind_to_processor(int n) { // Not implemented on OSX } void - thread_bind_to_processor(gr_thread_t thread, unsigned int n) + thread_bind_to_processor(gr_thread_t thread, int n) { // Not implemented on OSX } void - thread_bind_to_processor(const std::vector &mask) + thread_bind_to_processor(const std::vector &mask) { // Not implemented on OSX } void - thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) { // Not implemented on OSX } @@ -157,32 +157,32 @@ namespace gruel { } void - thread_bind_to_processor(unsigned int n) + thread_bind_to_processor(int n) { - std::vector mask(1, n); + std::vector mask(1, n); thread_bind_to_processor(get_current_thread_id(), mask); } void - thread_bind_to_processor(const std::vector &mask) + thread_bind_to_processor(const std::vector &mask) { thread_bind_to_processor(get_current_thread_id(), mask); } void - thread_bind_to_processor(gr_thread_t thread, unsigned int n) + thread_bind_to_processor(gr_thread_t thread, int n) { - std::vector mask(1, n); + std::vector mask(1, n); thread_bind_to_processor(thread, mask); } void - thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) + thread_bind_to_processor(gr_thread_t thread, const std::vector &mask) { cpu_set_t set; size_t len = sizeof(cpu_set_t); - std::vector _mask = mask; - std::vector::iterator itr; + std::vector _mask = mask; + std::vector::iterator itr; CPU_ZERO(&set); for(itr = _mask.begin(); itr != _mask.end(); itr++) -- cgit From dbd4f93ee7d67a93bdf59a138dc8fc7df443a136 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 14 Apr 2013 22:10:58 -0700 Subject: gruel: added include guards for gr_intrusive_ptr.i --- gruel/src/swig/gr_intrusive_ptr.i | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gruel') diff --git a/gruel/src/swig/gr_intrusive_ptr.i b/gruel/src/swig/gr_intrusive_ptr.i index 40c438d00..dc6004f44 100644 --- a/gruel/src/swig/gr_intrusive_ptr.i +++ b/gruel/src/swig/gr_intrusive_ptr.i @@ -1,3 +1,5 @@ +#ifndef SWIG_INTRUSIVE_PTR_NAMESPACE + // This file was borrowed from the SWIG project to allow use to // wrap PMTs that use intrusive pointers. This is only necessary // to support backwards compatability with older distributions of @@ -99,4 +101,4 @@ SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, const, TYPE) } %enddef - +#endif //SWIG_INTRUSIVE_PTR_NAMESPACE -- cgit