commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 07/12: android: runtime: issues related to


From: git
Subject: [Commit-gnuradio] [gnuradio] 07/12: android: runtime: issues related to vmcircbuf; only mmap_tmpfile version working currently.
Date: Fri, 19 Feb 2016 13:58:39 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch android
in repository gnuradio.

commit eb381a5a4c63605b43fc02b8b246a0cd4c4f88ce
Author: Tom Rondeau <address@hidden>
Date:   Fri Jan 2 17:35:28 2015 -0500

    android: runtime: issues related to vmcircbuf; only mmap_tmpfile version 
working currently.
    
    - updated checks in sysv_shm circbuf to protect when shm.h exists but 
shmget doesn't.
    
    - fixed mmap_tmpfile circbuf class to work better with android.
    
      - open parameters set for Android (does not support O_EXCL).
    
      - The gr::tmp_path() works only if the TMP env var is defined, which we 
have to do specially through the Java app we create.
    
      - Use GR_X log methods for logger info
---
 gnuradio-runtime/lib/vmcircbuf.cc              | 10 +++++++-
 gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc | 32 +++++++++++++++++---------
 gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc     |  4 ++--
 3 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/gnuradio-runtime/lib/vmcircbuf.cc 
b/gnuradio-runtime/lib/vmcircbuf.cc
index 05f08ce..cfc0f2c 100644
--- a/gnuradio-runtime/lib/vmcircbuf.cc
+++ b/gnuradio-runtime/lib/vmcircbuf.cc
@@ -68,8 +68,16 @@ namespace gr {
 
     std::vector<gr::vmcircbuf_factory *> all = all_factories ();
 
+    // FIXME: Clean up between Android/normal
+    #if ANDROID
+    int ret = 35;
+    char name[35] = "gr::vmcircbuf_mmap_tmpfile_factory";
+    #else
     char name[1024];
-    if (gr::vmcircbuf_prefs::get(FACTORY_PREF_KEY, name, sizeof(name)) >= 0) {
+    int ret = gr::vmcircbuf_prefs::get(FACTORY_PREF_KEY, name, sizeof(name));
+    #endif
+
+    if(ret) {
       for(unsigned int i = 0; i < all.size (); i++) {
         if(strncmp(name, all[i]->name(), strlen(all[i]->name())) == 0) {
           s_default_factory = all[i];
diff --git a/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc 
b/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc
index 7a02fe2..5e9abc7 100644
--- a/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc
+++ b/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc
@@ -41,6 +41,7 @@
 #include <string.h>
 #include "pagesize.h"
 #include <gnuradio/sys_paths.h>
+#include <gnuradio/logger.h>
 
 namespace gr {
 
@@ -48,13 +49,13 @@ namespace gr {
     : gr::vmcircbuf (size)
   {
 #if !defined(HAVE_MMAP)
-    fprintf(stderr, "gr::vmcircbuf_mmap_tmpfile: mmap or mkstemp is not 
available\n");
+    GR_ERROR("gr_log", "gr::vmcircbuf_mmap_tmpfile: mmap or mkstemp is not 
available");
     throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
 #else
     gr::thread::scoped_lock guard(s_vm_mutex);
 
     if(size <= 0 || (size % gr::pagesize ()) != 0) {
-      fprintf(stderr, "gr::vmcircbuf_mmap_tmpfile: invalid size = %d\n", size);
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile:  invalid 
size = %1%") % size);
       throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
     }
 
@@ -69,7 +70,14 @@ namespace gr {
                "%s/gnuradio-%d-%d-XXXXXX", gr::tmp_path(), getpid(), 
s_seg_counter);
       s_seg_counter++;
 
+#ifndef ANDROID
       seg_fd = open(seg_name, O_RDWR | O_CREAT | O_EXCL, 0600);
+#else
+      seg_fd = open(seg_name, O_RDWR | O_CREAT, 0600);
+#endif /* ANDROID */
+
+      GR_INFO("gr_log", boost::format("gr::mvcircbuf_mmap_tmpfile: opened: 
%1%") % seg_fd);
+
       if(seg_fd == -1) {
         if(errno == EEXIST) // File already exists (shouldn't happen).  Try 
again
           continue;
@@ -77,14 +85,15 @@ namespace gr {
         char msg[1024];
         snprintf(msg, sizeof (msg),
                  "gr::vmcircbuf_mmap_tmpfile: open [%s]", seg_name);
-        perror(msg);
+        GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: open 
failed [%1%], errno: %1%") \
+                 % seg_name % (strerror(errno)));
         throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
       }
       break;
     }
 
     if(unlink (seg_name) == -1) {
-      perror("gr::vmcircbuf_mmap_tmpfile: unlink");
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: unlink, 
errno: %1%") % (strerror(errno)));
       throw std::runtime_error ("gr::vmcircbuf_mmap_tmpfile");
     }
 
@@ -92,7 +101,8 @@ namespace gr {
     // Now set it's length to 2x what we really want and mmap it in.
     if(ftruncate (seg_fd, (off_t) 2 * size) == -1) {
       close(seg_fd);                                           // cleanup
-      perror("gr::vmcircbuf_mmap_tmpfile: ftruncate (1)");
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: ftruncate 
(1), errno: %1%") \
+               % (strerror(errno)));
       throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
     }
 
@@ -102,14 +112,14 @@ namespace gr {
 
     if(first_copy == MAP_FAILED) {
       close(seg_fd);                                           // cleanup
-      perror("gr::vmcircbuf_mmap_tmpfile: mmap (1)");
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: mmap (1), 
errno: %1%") % (strerror(errno)));
       throw std::runtime_error ("gr::vmcircbuf_mmap_tmpfile");
     }
 
     // unmap the 2nd half
     if(munmap ((char *) first_copy + size, size) == -1) {
       close(seg_fd);                                           // cleanup
-      perror("gr::vmcircbuf_mmap_tmpfile: munmap (1)");
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: munmap 
(1), errno: %1%") % (strerror(errno)));
       throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
     }
 
@@ -122,7 +132,7 @@ namespace gr {
     if(second_copy == MAP_FAILED) {
       munmap(first_copy, size);                                        // 
cleanup
       close(seg_fd);
-      perror("gr::vmcircbuf_mmap_tmpfile: mmap(2)");
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: mmap (2), 
errno: %1%") % (strerror(errno)));
       throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
     }
 
@@ -131,7 +141,7 @@ namespace gr {
       munmap(first_copy, size);                                        // 
cleanup
       munmap(second_copy, size);
       close(seg_fd);
-      perror("gr::vmcircbuf_mmap_tmpfile: non-contiguous second copy");
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: 
non-contiguous second copy, errno: %1%")  % (strerror(errno)));
       throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
     }
 
@@ -140,7 +150,7 @@ namespace gr {
       munmap(first_copy, size);                                        // 
cleanup
       munmap(second_copy, size);
       close(seg_fd);
-      perror("gr::vmcircbuf_mmap_tmpfile: ftruncate (2)");
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: ftruncate 
(2), errno: %1%") % (strerror(errno)));
       throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
     }
 
@@ -159,7 +169,7 @@ namespace gr {
     gr::thread::scoped_lock guard(s_vm_mutex);
 
     if(munmap(d_base, 2 * d_size) == -1) {
-      perror("gr::vmcircbuf_mmap_tmpfile: munmap(2)");
+      GR_ERROR("gr_log", boost::format("gr::vmcircbuf_mmap_tmpfile: munmap 
(2), errno: %1%") % (strerror(errno)));
     }
 #endif
   }
diff --git a/gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc 
b/gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc
index c368128..f1c742c 100644
--- a/gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc
+++ b/gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc
@@ -47,7 +47,7 @@ namespace gr {
   vmcircbuf_sysv_shm::vmcircbuf_sysv_shm(int size)
     : gr::vmcircbuf(size)
   {
-#if !defined(HAVE_SYS_SHM_H)
+#if !defined(HAVE_SHM_OPEN)
     fprintf(stderr, "gr::vmcircbuf_sysv_shm: sysv shared memory is not 
available\n");
     throw std::runtime_error("gr::vmcircbuf_sysv_shm");
 #else
@@ -162,7 +162,7 @@ namespace gr {
 
   vmcircbuf_sysv_shm::~vmcircbuf_sysv_shm()
   {
-#if defined(HAVE_SYS_SHM_H)
+#if defined(HAVE_SHM_OPEN)
     gr::thread::scoped_lock guard(s_vm_mutex);
 
     if(shmdt(d_base - gr::pagesize()) == -1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]