commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4833 - gnuradio/branches/developers/eb/ibu/pmt/src/li


From: eb
Subject: [Commit-gnuradio] r4833 - gnuradio/branches/developers/eb/ibu/pmt/src/lib
Date: Sat, 31 Mar 2007 18:14:27 -0600 (MDT)

Author: eb
Date: 2007-03-31 18:14:27 -0600 (Sat, 31 Mar 2007)
New Revision: 4833

Added:
   gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt_serialize.cc
Modified:
   gnuradio/branches/developers/eb/ibu/pmt/src/lib/Makefile.am
   gnuradio/branches/developers/eb/ibu/pmt/src/lib/gen_serial_tags.scm
   gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.cc
   gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.h
Log:
work-in-progress on pmt marshalling

Modified: gnuradio/branches/developers/eb/ibu/pmt/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/ibu/pmt/src/lib/Makefile.am 2007-03-31 
21:18:27 UTC (rev 4832)
+++ gnuradio/branches/developers/eb/ibu/pmt/src/lib/Makefile.am 2007-04-01 
00:14:27 UTC (rev 4833)
@@ -48,18 +48,23 @@
 $(GENERATED_H) $(GENERATED_I) $(GENERATED_CC): $(CODE_GENERATOR)
        PYTHONPATH=$(top_srcdir)/pmt/src/lib srcdir=$(srcdir) $(PYTHON) 
$(srcdir)/generate_unv.py
 
-BUILT_SOURCES = $(GENERATED_H) $(GENERATED_CC)
+pmt_serial_tags.h pmt_serial_tags.scm: gen_serial_tags.scm pmt_serial_tags.dat
+       $(srcdir)/gen_serial_tags.scm $(srcdir)/pmt_serial_tags.dat 
pmt_serial_tags.h pmt_serial_tags.scm
 
+BUILT_SOURCES = $(GENERATED_H) $(GENERATED_CC) pmt_serial_tags.h 
pmt_serial_tags.scm
+
 # ----------------------------------------------------------------
 
 EXTRA_DIST =                           \
-       $(CODE_GENERATOR)
+       $(CODE_GENERATOR)               \
+       gen_serial_tags.scm             \
+       pmt_serial_tags.dat             
 
-
 # These are the source files that go into the pmt shared library
 libpmt_la_SOURCES =                    \
        pmt.cc                          \
        pmt_io.cc                       \
+       pmt_serialize.cc                \
        pmt_unv.cc                      
 
 # magic flags
@@ -70,7 +75,8 @@
        -lstdc++                        
 
 include_HEADERS =                      \
-       pmt.h
+       pmt.h                           \
+       pmt_serial_tags.h               
 
 noinst_HEADERS =                       \
        $(GENERATED_H)                  \

Modified: gnuradio/branches/developers/eb/ibu/pmt/src/lib/gen_serial_tags.scm
===================================================================
--- gnuradio/branches/developers/eb/ibu/pmt/src/lib/gen_serial_tags.scm 
2007-03-31 21:18:27 UTC (rev 4832)
+++ gnuradio/branches/developers/eb/ibu/pmt/src/lib/gen_serial_tags.scm 
2007-04-01 00:14:27 UTC (rev 4833)
@@ -33,7 +33,7 @@
 
   (define (usage)
     (format 0
-           "usage: ~a <pmt-serial-tags.dat> <pmt-serial-tags.h> 
<pmt-serial-tags.scm>~%"
+           "usage: ~a <pmt_serial_tags.dat> <pmt_serial_tags.h> 
<pmt_serial_tags.scm>~%"
            (car args)))
 
   (when (not (= (length args) 4))
@@ -45,8 +45,8 @@
        (scm-file (open-output-file (cadddr args))))
 
       (write-header-comment h-file "// ")
-      (display "#ifndef INCLUDED_SERIAL_TAGS_H\n" h-file)
-      (display "#define INCLUDED_SERIAL_TAGS_H\n" 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)
 
@@ -55,7 +55,7 @@
       (for-each-in-file i-file
        (lambda (form)
         (let* ((name (car form))
-               (c-name (c-ify name))
+               (c-name (string-upcase (c-ify name)))
                (value (cadr form)))
           ;;(format h-file   "static const int ~a\t= 0x~x;~%" c-name value)
           (format h-file   "  ~a\t= 0x~x,~%" c-name value)
@@ -97,7 +97,8 @@
     "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."
     ""
     ""
-    "THIS FILE IS MACHINE GENERATED FROM gen-serial-tags.dat. DO NOT EDIT BY 
HAND"
+    "THIS FILE IS MACHINE GENERATED FROM pmt_serial_tags.dat. DO NOT EDIT BY 
HAND."
+    "See pmt_serial_tags.dat for additional commentary."
     ""))
 
 

Modified: gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.cc      2007-03-31 
21:18:27 UTC (rev 4832)
+++ gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.cc      2007-04-01 
00:14:27 UTC (rev 4833)
@@ -109,12 +109,18 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////
-//                           Booleans
+//                           Globals
 ////////////////////////////////////////////////////////////////////////////
 
 const pmt_t PMT_BOOL_T = pmt_t(new pmt_bool());                // singleton
 const pmt_t PMT_BOOL_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
@@ -322,8 +328,6 @@
 //                              Pairs
 ////////////////////////////////////////////////////////////////////////////
 
-const pmt_t PMT_NIL = pmt_t(new pmt_null());           // singleton
-
 pmt_null::pmt_null() {}
 pmt_pair::pmt_pair(pmt_t car, pmt_t cdr) : d_car(car), d_cdr(cdr) {}
 

Modified: gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.h       2007-03-31 
21:18:27 UTC (rev 4832)
+++ gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.h       2007-04-01 
00:14:27 UTC (rev 4833)
@@ -618,11 +618,11 @@
 /*!
  * \brief Write portable byte-serial representation of \p obj to \p sink
  */
-void pmt_serialize(pmt_t obj, std::ostream &sink);
+bool pmt_serialize(pmt_t obj, std::streambuf &sink);
 
 /*!
  * \brief Create obj from portable byte-serial representation
  */
-pmt_t pmt_deserialize(std::istream &source);
+pmt_t pmt_deserialize(std::streambuf &source);
 
 #endif /* INCLUDED_PMT_H */

Added: gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt_serialize.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt_serialize.cc            
                (rev 0)
+++ gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt_serialize.cc    
2007-04-01 00:14:27 UTC (rev 4833)
@@ -0,0 +1,215 @@
+/* -*- c++ -*- */
+/*
+ * 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 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <vector>
+#include <pmt.h>
+#include "pmt_int.h"
+#include "pmt_serial_tags.h"
+
+// ----------------------------------------------------------------
+// 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();
+}
+
+// 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();
+}
+
+// ----------------------------------------------------------------
+// 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();
+}
+
+// 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();
+}
+
+/*
+ * Write portable byte-serial representation of \p obj to \p sb
+ */
+bool
+pmt_serialize(pmt_t obj, std::streambuf &sb)
+{
+  bool ok = true;
+
+  // tail_recursion:
+
+  if (pmt_eq(obj, PMT_BOOL_T))
+    return serialize_untagged_u8(PST_TRUE, sb);
+    
+  if (pmt_eq(obj, PMT_BOOL_F))
+    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_number(obj)){
+
+    if (pmt_is_integer(obj)){
+      int i = (int) pmt_to_long(obj);  // FIXME: trouble on values bigger than 
32-bits
+      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 for real", obj);
+
+    if (pmt_is_complex(obj))
+      throw pmt_notimplemented("pmt_serialize for complex", obj);
+
+  }
+
+  throw pmt_notimplemented("pmt_serialize for ???", obj);
+}
+
+
+/*
+ * Create obj from portable byte-serial representation
+ */
+pmt_t
+pmt_deserialize(std::streambuf &sb)
+{
+  return PMT_EOF;
+}





reply via email to

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