Merged -r8639:8641 from jcorgan/gruel into trunk. Adds libgruel, the GNU Radio Utili...
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 20 Jun 2008 18:14:47 +0000 (18:14 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 20 Jun 2008 18:14:47 +0000 (18:14 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8642 221aa14e-8319-0410-a670-987f0aec2ac5

15 files changed:
Makefile.common
config/Makefile.am
config/grc_gruel.m4 [new file with mode: 0644]
configure.ac
gruel/AUTHORS [new file with mode: 0644]
gruel/ChangeLog [new file with mode: 0644]
gruel/Makefile.am [new file with mode: 0644]
gruel/README [new file with mode: 0644]
gruel/gruel.pc.in [new file with mode: 0644]
gruel/src/Makefile.am [new file with mode: 0644]
gruel/src/include/Makefile.am [new file with mode: 0644]
gruel/src/include/gruel/Makefile.am [new file with mode: 0644]
gruel/src/include/gruel/realtime.h [new file with mode: 0644]
gruel/src/lib/Makefile.am [new file with mode: 0644]
gruel/src/lib/realtime.cc [new file with mode: 0644]

index 0ee6f2bf3affe5b1b9b563cfd4e8d0afdad4ca0a..a4a3139c647bf277ece1a4f645b4fb95436fd19d 100644 (file)
@@ -72,6 +72,10 @@ GNURADIO_CORE_LA = @gnuradio_core_LA@
 # This is a dependency for many swig operations
 GNURADIO_I = @gnuradio_core_I@
 
+# How to link in the USRP library from inside the tree
+GRUEL_INCLUDES = @gruel_INCLUDES@
+GRUEL_LA = @gruel_LA@
+
 # How to link in the USRP library from inside the tree
 USRP_INCLUDES = @usrp_INCLUDES@
 USRP_LA = @usrp_LA@
index 4e87bc4589a4cd843db12e271e893e55d2fa55d8..310568bfb05d54837e881f658dbd648d12ce33a5 100644 (file)
@@ -53,6 +53,7 @@ m4macros = \
        grc_gr_video_sdl.m4 \
        grc_gr_wxgui.m4 \
        grc_mblock.m4 \
+       grc_gruel.m4 \
        gr_check_createfilemapping.m4 \
        gr_check_mc4020.m4 \
        gr_check_shm_open.m4 \
diff --git a/config/grc_gruel.m4 b/config/grc_gruel.m4
new file mode 100644 (file)
index 0000000..81f53ce
--- /dev/null
@@ -0,0 +1,44 @@
+dnl Copyright 2001,2002,2003,2004,2005,2006,2008 Free Software Foundation, Inc.
+dnl 
+dnl This file is part of GNU Radio
+dnl 
+dnl GNU Radio is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 3, or (at your option)
+dnl any later version.
+dnl 
+dnl GNU Radio is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl 
+dnl You should have received a copy of the GNU General Public License
+dnl along with GNU Radio; see the file COPYING.  If not, write to
+dnl the Free Software Foundation, Inc., 51 Franklin Street,
+dnl Boston, MA 02110-1301, USA.
+
+AC_DEFUN([GRC_GRUEL],[
+    GRC_ENABLE(gruel)
+    GRC_WITH(gruel)
+
+    dnl If execution gets to here, $passed will be:
+    dnl   with : if the --with code didn't error out
+    dnl   yes  : if the --enable code passed muster and all dependencies are met
+    dnl   no   : otherwise
+    if test $passed != with; then
+       dnl how and where to find INCLUDES and LA
+       gruel_INCLUDES="-I\${abs_top_srcdir}/gruel/src/include"
+        gruel_LA="\${abs_top_builddir}/gruel/src/lib/libgruel.la"
+    fi
+
+    AC_CONFIG_FILES([\
+        gruel/Makefile \
+        gruel/gruel.pc \
+        gruel/src/Makefile \
+        gruel/src/include/Makefile \
+        gruel/src/include/gruel/Makefile \
+        gruel/src/lib/Makefile \
+    ])
+
+    GRC_BUILD_CONDITIONAL(gruel,[])
+])
index 9160b4ca442ad1240feaf35a2f52244dafee2eca..f20ca9e4e99c670fac53c2e2c4f1660bcb8cc5e0 100644 (file)
@@ -239,6 +239,7 @@ AC_ARG_ENABLE(
 )
 
 build_dirs="config"
+GRC_GRUEL                       dnl must come first
 GRC_OMNITHREAD                 dnl must come before gnuradio-core and mblock
 GRC_GCELL
 GRC_GNURADIO_CORE
diff --git a/gruel/AUTHORS b/gruel/AUTHORS
new file mode 100644 (file)
index 0000000..18e03c4
--- /dev/null
@@ -0,0 +1 @@
+Johnathan Corgan <jcorgan@corganenterprises.com>
diff --git a/gruel/ChangeLog b/gruel/ChangeLog
new file mode 100644 (file)
index 0000000..b185665
--- /dev/null
@@ -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 (file)
index 0000000..93f56a7
--- /dev/null
@@ -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 (file)
index 0000000..585cf02
--- /dev/null
@@ -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 (file)
index 0000000..6377f5b
--- /dev/null
@@ -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 (file)
index 0000000..90c0f88
--- /dev/null
@@ -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 (file)
index 0000000..7a17881
--- /dev/null
@@ -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 (file)
index 0000000..8ea484c
--- /dev/null
@@ -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 (file)
index 0000000..ded70ed
--- /dev/null
@@ -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 (file)
index 0000000..972ff4c
--- /dev/null
@@ -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 (file)
index 0000000..bdcb31a
--- /dev/null
@@ -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 <config.h>
+#endif
+
+#include <gruel/realtime.h>
+
+#ifdef HAVE_SCHED_H
+#include <sched.h>
+#endif
+
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#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(&param, 0, sizeof(param));
+    param.sched_priority = pri;
+    int result = sched_setscheduler(pid, policy, &param);
+    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 <pthread.h>
+#include <stdio.h>
+
+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 (&param, 0, sizeof (param));
+    param.sched_priority = pri;
+    int result = pthread_setschedparam (this_thread, policy, &param);
+    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