commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r5592 - gnuradio/branches/features/ofdm/receiver/gnura


From: eb
Subject: [Commit-gnuradio] r5592 - gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io
Date: Fri, 1 Jun 2007 11:10:17 -0600 (MDT)

Author: eb
Date: 2007-06-01 11:10:17 -0600 (Fri, 01 Jun 2007)
New Revision: 5592

Added:
   
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.cc
   
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.h
   
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.i
Modified:
   gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/Makefile.am
   
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.cc
   
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.h
   
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.i
   gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/io.i
Log:
refactored gr_file_sink to use gr_file_sink_base

Modified: 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/Makefile.am
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/Makefile.am   
    2007-06-01 16:55:00 UTC (rev 5591)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/Makefile.am   
    2007-06-01 17:10:17 UTC (rev 5592)
@@ -29,6 +29,7 @@
 
 libio_la_SOURCES =                     \
        gr_file_sink.cc                 \
+       gr_file_sink_base.cc            \
        gr_file_source.cc               \
        gr_file_descriptor_sink.cc      \
        gr_file_descriptor_source.cc    \
@@ -57,6 +58,7 @@
 
 grinclude_HEADERS =                    \
        gr_file_sink.h                  \
+       gr_file_sink_base.h             \
        gr_file_source.h                \
        gr_file_descriptor_sink.h       \
        gr_file_descriptor_source.h     \

Modified: 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.cc
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.cc
   2007-06-01 16:55:00 UTC (rev 5591)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.cc
   2007-06-01 17:10:17 UTC (rev 5592)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004,2006 Free Software Foundation, Inc.
+ * Copyright 2004,2006,2007 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -26,93 +26,30 @@
 
 #include <gr_file_sink.h>
 #include <gr_io_signature.h>
-#include <cstdio>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <stdexcept>
 
-// win32 (mingw/msvc) specific
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-#ifdef O_BINARY
-#define        OUR_O_BINARY O_BINARY
-#else
-#define        OUR_O_BINARY 0
-#endif
 
-// should be handled via configure
-#ifdef O_LARGEFILE
-#define        OUR_O_LARGEFILE O_LARGEFILE
-#else
-#define        OUR_O_LARGEFILE 0
-#endif
+gr_file_sink_sptr
+gr_make_file_sink (size_t itemsize, const char *filename)
+{
+  return gr_file_sink_sptr (new gr_file_sink (itemsize, filename));
+}
 
 gr_file_sink::gr_file_sink(size_t itemsize, const char *filename)
   : gr_sync_block ("file_sink",
                   gr_make_io_signature(1, 1, itemsize),
                   gr_make_io_signature(0, 0, 0)),
-    d_itemsize(itemsize), d_fp(0), d_new_fp(0), d_updated(false)
+    gr_file_sink_base(filename, true),
+    d_itemsize(itemsize)
 {
   if (!open(filename))
     throw std::runtime_error ("can't open file");
 }
 
-gr_file_sink_sptr
-gr_make_file_sink (size_t itemsize, const char *filename)
-{
-  return gr_file_sink_sptr (new gr_file_sink (itemsize, filename));
-}
-
 gr_file_sink::~gr_file_sink ()
 {
-  close();
-  if (d_fp){
-    fclose((FILE *) d_fp);
-    d_fp = 0;
-  }
 }
 
-bool
-gr_file_sink::open(const char *filename)
-{
-  omni_mutex_lock      l(d_mutex);     // hold mutex for duration of this 
function
-
-  // we use the open system call to get access to the O_LARGEFILE flag.
-  int fd;
-  if ((fd = ::open (filename,
-                   O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, 
0664)) < 0){
-    perror (filename);
-    return false;
-  }
-
-  if (d_new_fp){               // if we've already got a new one open, close it
-    fclose((FILE *) d_new_fp);
-    d_new_fp = 0;
-  }
-
-  if ((d_new_fp = fdopen (fd, "wb")) == NULL){
-    perror (filename);
-    ::close(fd);               // don't leak file descriptor if fdopen fails.
-  }
-
-  d_updated = true;
-  return d_new_fp != 0;
-}
-
-void
-gr_file_sink::close()
-{
-  omni_mutex_lock      l(d_mutex);     // hold mutex for duration of this 
function
-
-  if (d_new_fp){
-    fclose((FILE *) d_new_fp);
-    d_new_fp = 0;
-  }
-  d_updated = true;
-}
-
 int 
 gr_file_sink::work (int noutput_items,
                    gr_vector_const_void_star &input_items,
@@ -121,20 +58,13 @@
   char *inbuf = (char *) input_items[0];
   int  nwritten = 0;
 
-  if (d_updated){
-    omni_mutex_lock    l(d_mutex);     // hold mutex for duration of this block
-    if (d_fp)
-      fclose((FILE *)d_fp);
-    d_fp = d_new_fp;                   // install new file pointer
-    d_new_fp = 0;
-    d_updated = false;
-  }
+  do_update();                         // update d_fp is reqd
   
   if (!d_fp)
     return noutput_items;              // drop output on the floor
 
   while (nwritten < noutput_items){
-    int count = fwrite (inbuf, d_itemsize, noutput_items - nwritten, (FILE *) 
d_fp);
+    int count = fwrite (inbuf, d_itemsize, noutput_items - nwritten, d_fp);
     if (count == 0)    // FIXME add error handling
       break;
     nwritten += count;

Modified: 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.h
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.h
    2007-06-01 16:55:00 UTC (rev 5591)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.h
    2007-06-01 17:10:17 UTC (rev 5592)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2007 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -24,7 +24,7 @@
 #define INCLUDED_GR_FILE_SINK_H
 
 #include <gr_sync_block.h>
-#include <omnithread.h>
+#include <gr_file_sink_base.h>
 
 class gr_file_sink;
 typedef boost::shared_ptr<gr_file_sink> gr_file_sink_sptr;
@@ -36,16 +36,12 @@
  * \ingroup sink
  */
 
-class gr_file_sink : public gr_sync_block
+class gr_file_sink : public gr_sync_block, public gr_file_sink_base
 {
   friend gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char 
*filename);
 
  private:
   size_t       d_itemsize;
-  void        *d_fp;           // current FILE pointer
-  void        *d_new_fp;       // new FILE pointer
-  bool         d_updated;      // is there a new FILE pointer?
-  omni_mutex   d_mutex;
 
  protected:
   gr_file_sink(size_t itemsize, const char *filename);
@@ -53,23 +49,9 @@
  public:
   ~gr_file_sink();
 
-  /*! 
-   * \brief Open filename and begin output to it.
-   */
-  bool open(const char *filename);
-
-  /*!
-   * \brief Close current output file.
-   *
-   * Closes current output file and ignores any output until
-   * open is called to connect to another file.
-   */
-  void close();
-
   int work(int noutput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
 };
 
-
 #endif /* INCLUDED_GR_FILE_SINK_H */

Modified: 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.i
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.i
    2007-06-01 16:55:00 UTC (rev 5591)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.i
    2007-06-01 17:10:17 UTC (rev 5592)
@@ -25,7 +25,7 @@
 gr_file_sink_sptr 
 gr_make_file_sink (size_t itemsize, const char *filename);
 
-class gr_file_sink : public gr_sync_block
+class gr_file_sink : public gr_sync_block, public gr_file_sink_base
 {
  protected:
   gr_file_sink (size_t itemsize, const char *filename);

Copied: 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.cc
 (from rev 5584, 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.cc)
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.cc
                              (rev 0)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.cc
      2007-06-01 17:10:17 UTC (rev 5592)
@@ -0,0 +1,118 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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 2, 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 <gr_file_sink_base.h>
+#include <cstdio>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+
+// win32 (mingw/msvc) specific
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+#ifdef O_BINARY
+#define        OUR_O_BINARY O_BINARY
+#else
+#define        OUR_O_BINARY 0
+#endif
+
+// should be handled via configure
+#ifdef O_LARGEFILE
+#define        OUR_O_LARGEFILE O_LARGEFILE
+#else
+#define        OUR_O_LARGEFILE 0
+#endif
+
+gr_file_sink_base::gr_file_sink_base(const char *filename, bool is_binary)
+  : d_fp(0), d_new_fp(0), d_updated(false), d_is_binary(is_binary)
+{
+  if (!open(filename))
+    throw std::runtime_error ("can't open file");
+}
+
+gr_file_sink_base::~gr_file_sink_base ()
+{
+  close();
+  if (d_fp){
+    fclose(d_fp);
+    d_fp = 0;
+  }
+}
+
+bool
+gr_file_sink_base::open(const char *filename)
+{
+  omni_mutex_lock      l(d_mutex);     // hold mutex for duration of this 
function
+
+  // we use the open system call to get access to the O_LARGEFILE flag.
+  int fd;
+  if ((fd = ::open (filename,
+                   O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY,
+                   0664)) < 0){
+    perror (filename);
+    return false;
+  }
+
+  if (d_new_fp){               // if we've already got a new one open, close it
+    fclose(d_new_fp);
+    d_new_fp = 0;
+  }
+
+  if ((d_new_fp = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL){
+    perror (filename);
+    ::close(fd);               // don't leak file descriptor if fdopen fails.
+  }
+
+  d_updated = true;
+  return d_new_fp != 0;
+}
+
+void
+gr_file_sink_base::close()
+{
+  omni_mutex_lock      l(d_mutex);     // hold mutex for duration of this 
function
+
+  if (d_new_fp){
+    fclose(d_new_fp);
+    d_new_fp = 0;
+  }
+  d_updated = true;
+}
+
+void
+gr_file_sink_base::do_update()
+{
+  if (d_updated){
+    omni_mutex_lock    l(d_mutex);     // hold mutex for duration of this block
+    if (d_fp)
+      fclose(d_fp);
+    d_fp = d_new_fp;                   // install new file pointer
+    d_new_fp = 0;
+    d_updated = false;
+  }
+}  

Copied: 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.h
 (from rev 5584, 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink.h)
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.h
                               (rev 0)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.h
       2007-06-01 17:10:17 UTC (rev 5592)
@@ -0,0 +1,67 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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 2, 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_GR_FILE_SINK_BASE_H
+#define INCLUDED_GR_FILE_SINK_BASE_H
+
+#include <omnithread.h>
+#include <cstdio>
+
+/*!
+ * \brief Common base class for file sinks
+ */
+class gr_file_sink_base 
+{
+ protected:
+  FILE        *d_fp;           // current FILE pointer
+  FILE        *d_new_fp;       // new FILE pointer
+  bool         d_updated;      // is there a new FILE pointer?
+  bool         d_is_binary;
+  omni_mutex   d_mutex;
+
+ protected:
+  gr_file_sink_base(const char *filename, bool is_binary);
+
+ public:
+  ~gr_file_sink_base();
+
+  /*! 
+   * \brief Open filename and begin output to it.
+   */
+  bool open(const char *filename);
+
+  /*!
+   * \brief Close current output file.
+   *
+   * Closes current output file and ignores any output until
+   * open is called to connect to another file.
+   */
+  void close();
+
+  /*!
+   * \brief if we've had an update, do it now.
+   */
+  void do_update();
+};
+
+
+#endif /* INCLUDED_GR_FILE_SINK_BASE_H */

Added: 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.i
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.i
                               (rev 0)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/gr_file_sink_base.i
       2007-06-01 17:10:17 UTC (rev 5592)
@@ -0,0 +1,46 @@
+/* -*- 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 2, 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.
+ */
+class gr_file_sink_base 
+{
+ protected:
+  gr_file_sink_base(const char *filename, bool is_binary);
+
+ public:
+  ~gr_file_sink_base();
+
+  /*! 
+   * \brief Open filename and begin output to it.
+   */
+  bool open(const char *filename);
+
+  /*!
+   * \brief Close current output file.
+   *
+   * Closes current output file and ignores any output until
+   * open is called to connect to another file.
+   */
+  void close();
+
+  /*!
+   * \brief if we've had an update, do it now.
+   */
+  void do_update();
+};

Modified: gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/io.i
===================================================================
--- gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/io.i      
2007-06-01 16:55:00 UTC (rev 5591)
+++ gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/io/io.i      
2007-06-01 17:10:17 UTC (rev 5592)
@@ -40,6 +40,7 @@
 
 %}
 
+%include "gr_file_sink_base.i"
 %include "gr_file_sink.i"
 %include "gr_file_source.i"
 %include "gr_file_descriptor_sink.i"





reply via email to

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