summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src/lib/runtime')
-rw-r--r--gnuradio-core/src/lib/runtime/Makefile.am6
-rw-r--r--gnuradio-core/src/lib/runtime/gr_buffer.cc3
-rw-r--r--gnuradio-core/src/lib/runtime/gr_preferences.cc34
-rw-r--r--gnuradio-core/src/lib/runtime/gr_sys_paths.cc55
-rw-r--r--gnuradio-core/src/lib/runtime/gr_sys_paths.h (renamed from gnuradio-core/src/lib/runtime/gr_tmp_path.h)18
-rw-r--r--gnuradio-core/src/lib/runtime/gr_tmp_path.cc52
-rw-r--r--gnuradio-core/src/lib/runtime/gr_unittests.h40
-rw-r--r--gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc3
-rw-r--r--gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc4
-rw-r--r--gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc4
10 files changed, 93 insertions, 126 deletions
diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am
index 3dd2b42f5..eca92e526 100644
--- a/gnuradio-core/src/lib/runtime/Makefile.am
+++ b/gnuradio-core/src/lib/runtime/Makefile.am
@@ -1,5 +1,5 @@
#
-# Copyright 2003,2004,2007,2008,2009,2010 Free Software Foundation, Inc.
+# Copyright 2003,2004,2007,2008,2009,2010,2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -58,7 +58,7 @@ libruntime_la_SOURCES = \
gr_sync_block.cc \
gr_sync_decimator.cc \
gr_sync_interpolator.cc \
- gr_tmp_path.cc \
+ gr_sys_paths.cc \
gr_top_block.cc \
gr_top_block_impl.cc \
gr_tpb_detail.cc \
@@ -121,7 +121,7 @@ grinclude_HEADERS = \
gr_tpb_detail.h \
gr_tpb_thread_body.h \
gr_timer.h \
- gr_tmp_path.h \
+ gr_sys_paths.h \
gr_types.h \
gr_unittests.h \
gr_vmcircbuf.h \
diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc
index 03d5a8738..fa3722714 100644
--- a/gnuradio-core/src/lib/runtime/gr_buffer.cc
+++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc
@@ -31,6 +31,7 @@
#include <iostream>
#include <assert.h>
#include <algorithm>
+#include <boost/math/common_factor_rt.hpp>
static long s_buffer_count = 0; // counts for debugging storage mgmt
static long s_buffer_reader_count = 0;
@@ -73,7 +74,7 @@ static long s_buffer_reader_count = 0;
static long
minimum_buffer_items (long type_size, long page_size)
{
- return page_size / gr_gcd (type_size, page_size);
+ return page_size / boost::math::gcd (type_size, page_size);
}
diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc
index 5f7412248..c2ca047a8 100644
--- a/gnuradio-core/src/lib/runtime/gr_preferences.cc
+++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2003,2010 Free Software Foundation, Inc.
+ * Copyright 2003,2010,2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -25,6 +25,7 @@
#endif
#include <gr_preferences.h>
+#include <gr_sys_paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -33,12 +34,9 @@
#include <unistd.h>
#include <string.h>
-
-#ifdef MKDIR_TAKES_ONE_ARG
-#define gr_mkdir(pathname, mode) mkdir(pathname)
-#else
-#define gr_mkdir(pathname, mode) mkdir((pathname), (mode))
-#endif
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+namespace fs = boost::filesystem;
/*
* The simplest thing that could possibly work:
@@ -48,27 +46,19 @@
static const char *
pathname (const char *key)
{
- static char buf[200];
- snprintf (buf, sizeof (buf), "%s/.gnuradio/prefs/%s", getenv ("HOME"), key);
- return buf;
+ static fs::path path;
+ path = fs::path(gr_appdata_path()) / ".gnuradio" / "prefs" / key;
+ return path.string().c_str();
}
static void
ensure_dir_path ()
{
- char path[200];
- struct stat statbuf;
-
- snprintf (path, sizeof (path), "%s/.gnuradio/prefs", getenv ("HOME"));
- if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
- return;
-
- // blindly try to make it // FIXME make this robust. C++ SUCKS!
+ fs::path path = fs::path(gr_appdata_path()) / ".gnuradio";
+ if (!fs::is_directory(path)) fs::create_directory(path);
- snprintf (path, sizeof (path), "%s/.gnuradio", getenv ("HOME"));
- gr_mkdir (path, 0750);
- snprintf (path, sizeof (path), "%s/.gnuradio/prefs", getenv ("HOME"));
- gr_mkdir (path, 0750);
+ path = path / "prefs";
+ if (!fs::is_directory(path)) fs::create_directory(path);
}
const char *
diff --git a/gnuradio-core/src/lib/runtime/gr_sys_paths.cc b/gnuradio-core/src/lib/runtime/gr_sys_paths.cc
new file mode 100644
index 000000000..9d10a3ccd
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.cc
@@ -0,0 +1,55 @@
+/*
+ * 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 <gr_sys_paths.h>
+#include <cstdlib> //getenv
+#include <cstdio> //P_tmpdir (maybe)
+
+const char *gr_tmp_path(){
+ const char *path;
+
+ //first case, try TMP environment variable
+ path = getenv("TMP");
+ if (path) return path;
+
+ //second case, try P_tmpdir when its defined
+ #ifdef P_tmpdir
+ if (P_tmpdir) return P_tmpdir;
+ #endif /*P_tmpdir*/
+
+ //fall-through case, nothing worked
+ return "/tmp";
+}
+
+const char *gr_appdata_path(){
+ const char *path;
+
+ //first case, try HOME environment variable (unix)
+ path = getenv("HOME");
+ if (path) return path;
+
+ //second case, try APPDATA environment variable (windows)
+ path = getenv("APPDATA");
+ if (path) return path;
+
+ //fall-through case, nothing worked
+ return gr_tmp_path();
+}
diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.h b/gnuradio-core/src/lib/runtime/gr_sys_paths.h
index 3d02043c7..aa8249775 100644
--- a/gnuradio-core/src/lib/runtime/gr_tmp_path.h
+++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.h
@@ -1,6 +1,5 @@
-/* -*- c++ -*- */
/*
- * Copyright 2003 Free Software Foundation, Inc.
+ * Copyright 2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -20,12 +19,13 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef _GR_TMP_PATH_H_
-#define _GR_TMP_PATH_H_
+#ifndef _GR_SYS_PATHS_H_
+#define _GR_SYS_PATHS_H_
-/*!
- * \brief return directory portion of pathname used for temporary files.
- */
-const char *gr_tmp_path ();
+//! directory to create temporary files
+const char *gr_tmp_path();
+
+//! directory to store application data
+const char *gr_appdata_path();
-#endif /* _GR_TMP_PATH_H_ */
+#endif /* _GR_SYS_PATHS_H_ */
diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc
deleted file mode 100644
index 1f0c830cd..000000000
--- a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2003 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 <gr_tmp_path.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-const char *
-gr_tmp_path ()
-{
- static char *pp = 0;
-
- if (pp)
- return pp;
-
- char *s = getenv ("TMP");
- if (s){
- pp = strdup (s);
- return pp;
- }
-
-#ifdef P_tmpdir
- if (P_tmpdir){
- pp = strdup (P_tmpdir);
- return pp;
- }
-#endif
-
- pp = strdup ("/tmp");
- return pp;
-}
-
diff --git a/gnuradio-core/src/lib/runtime/gr_unittests.h b/gnuradio-core/src/lib/runtime/gr_unittests.h
index 70aa6f294..59149bb2e 100644
--- a/gnuradio-core/src/lib/runtime/gr_unittests.h
+++ b/gnuradio-core/src/lib/runtime/gr_unittests.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2010 Free Software Foundation, Inc.
+ * Copyright 2010,2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -31,37 +31,11 @@
#include <sys/stat.h>
#include <unistd.h>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
-#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 std::string get_unittest_path(const std::string &filename){
+ boost::filesystem::path path = boost::filesystem::current_path() / ".unittests";
+ if (!boost::filesystem::is_directory(path)) boost::filesystem::create_directory(path);
+ return (path / filename).string();
}
-
-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);
-}
-
diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc
index 65fe0c488..42c459484 100644
--- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc
+++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2003,2005 Free Software Foundation, Inc.
+ * Copyright 2003,2005,2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -36,7 +36,6 @@
#include <errno.h>
#include <stdio.h>
#include <gr_pagesize.h>
-#include <gr_tmp_path.h>
#include <gr_vmcircbuf_createfilemapping.h>
#ifdef HAVE_CREATEFILEMAPPING
diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc
index 3017036ef..4f7ae39cd 100644
--- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc
+++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2003 Free Software Foundation, Inc.
+ * Copyright 2003,2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -37,7 +37,7 @@
#include <errno.h>
#include <stdio.h>
#include <gr_pagesize.h>
-#include <gr_tmp_path.h>
+#include <gr_sys_paths.h>
gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size)
diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc
index faae4b396..ee8b0c485 100644
--- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc
+++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2003 Free Software Foundation, Inc.
+ * Copyright 2003,2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -39,7 +39,7 @@
#include <stdio.h>
#include <string.h>
#include <gr_pagesize.h>
-#include <gr_tmp_path.h>
+#include <gr_sys_paths.h>
gr_vmcircbuf_mmap_tmpfile::gr_vmcircbuf_mmap_tmpfile (int size)
: gr_vmcircbuf (size)