gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog libbase/Makefile.am libbase/tu_...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libbase/Makefile.am libbase/tu_...
Date: Mon, 09 Jun 2008 11:21:00 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/06/09 11:21:00

Modified files:
        .              : ChangeLog 
        libbase        : Makefile.am tu_file.cpp tu_file.h 
Added files:
        libbase        : IOChannel.cpp IOChannel.h 

Log message:
        * libbase/: Makefile.am, IOChannel.{cpp,h}: initial draft for a virtual
          IO class (to replace tu_file).
        * libbase/tu_file.{cpp,h}: make tu_file derive from IOChannel.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6860&r2=1.6861
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/Makefile.am?cvsroot=gnash&r1=1.117&r2=1.118
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_file.cpp?cvsroot=gnash&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_file.h?cvsroot=gnash&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/IOChannel.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/IOChannel.h?cvsroot=gnash&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6860
retrieving revision 1.6861
diff -u -b -r1.6860 -r1.6861
--- ChangeLog   9 Jun 2008 10:18:18 -0000       1.6860
+++ ChangeLog   9 Jun 2008 11:20:57 -0000       1.6861
@@ -1,5 +1,11 @@
 2008-06-09 Sandro Santilli <address@hidden>
 
+       * libbase/: Makefile.am, IOChannel.{cpp,h}: initial draft for a virtual
+         IO class (to replace tu_file).
+       * libbase/tu_file.{cpp,h}: make tu_file derive from IOChannel.
+
+2008-06-09 Sandro Santilli <address@hidden>
+
        * lots of files: renames gnash::stream to gnash::SWFStream.
 
 2008-06-09 Sandro Santilli <address@hidden>

Index: libbase/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/libbase/Makefile.am,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -b -r1.117 -r1.118
--- libbase/Makefile.am 9 Jun 2008 08:43:56 -0000       1.117
+++ libbase/Makefile.am 9 Jun 2008 11:21:00 -0000       1.118
@@ -107,6 +107,7 @@
        sharedlib.cpp \
        string_table.cpp \
        tu_file.cpp \
+       IOChannel.cpp \
        ClockTime.cpp \
        WallClockTimer.cpp \
        utf8.cpp \
@@ -142,6 +143,7 @@
        tree.hh \
        dsodefs.h \
        tu_file.h \
+       IOChannel.h \
        tu_opengl_includes.h \
        ClockTime.h \
        WallClockTimer.h \

Index: libbase/tu_file.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/tu_file.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- libbase/tu_file.cpp 6 Jun 2008 10:51:40 -0000       1.29
+++ libbase/tu_file.cpp 9 Jun 2008 11:21:00 -0000       1.30
@@ -285,35 +285,6 @@
     return byte_count;
 }
 
-void
-tu_file::write_string(const char* src)
-{
-    for (;;) {
-       write8(*src);
-       if (*src == 0) {
-           break;
-       }
-       src++;
-    }
-}
-
-int
-tu_file::read_string(char* dst, int max_length) 
-{
-    int i=0;
-    while (i<max_length) {
-       dst[i] = read8();
-       if (dst[i]=='\0') {
-           return i;
-       }
-       i++;
-    }
-    
-    dst[max_length - 1] = '\0';        // force termination.
-    
-    return -1;
-}
-
 // Local Variables:
 // mode: C++
 // indent-tabs-mode: t

Index: libbase/tu_file.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/tu_file.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- libbase/tu_file.h   6 Jun 2008 10:51:40 -0000       1.23
+++ libbase/tu_file.h   9 Jun 2008 11:21:00 -0000       1.24
@@ -11,27 +11,15 @@
 
 #include "dsodefs.h" // DSOEXPORT
 #include "utility.h"
+#include "IOChannel.h" // for inheritance
 
 #include <cstdio>
 
-//class membuf;
-
-enum
-{
-    TU_FILE_NO_ERROR = 0,
-    TU_FILE_OPEN_ERROR,
-    TU_FILE_READ_ERROR,
-    TU_FILE_WRITE_ERROR,
-    TU_FILE_SEEK_ERROR,
-    TU_FILE_CLOSE_ERROR
-};
-
-
 // a file abstraction that can be customized with callbacks.
 // Designed to be easy to hook up to FILE*, SDL_RWops*, or
 // whatever stream type(s) you might use in your game or
 // libraries.
-class DSOEXPORT tu_file
+class DSOEXPORT tu_file : public gnash::IOChannel
 {
 public:
     typedef int (* read_func)(void* dst, int bytes, void* appdata);
@@ -183,39 +171,6 @@
         return m_write(src, num, m_data);
     }
     
-    /// \brief Write a 0-terminated string to a stream.
-    //
-    /// TODO: define what happens when the stream
-    ///       is in error condition, see get_error().
-    ///
-    void write_string(const char* src);
-    
-    /// \brief
-    /// Read up to max_length characters, returns the number of characters 
-    /// read, or -1 if the string length is longer than max_length.
-    //
-    /// Stops at the first \0 character if it comes before max_length.
-    ///
-    /// Guarantees termination of the string.
-    ///
-    /// @return ??
-    ///
-    /// TODO: define what to return when the stream
-    ///       is in error condition, see get_error().
-    ///
-    int        read_string(char* dst, int max_length);
-    
-    /// \brief Write a 32-bit float to a stream.
-    //
-    /// TODO: define what to return when the stream
-    ///       is in error condition, see get_error().
-    void       write_float32(float value);
-
-    /// \brief Read a 32-bit float from a stream.
-    /// TODO: define what to return when the stream
-    ///       is in error condition, see get_error().
-    float      read_float32();
-
     /// \brief Return current stream position
     //
     /// TODO: define what to return when the stream
@@ -244,7 +199,7 @@
     /// TODO: define what to return when in error condition
     /// see get_error().
     ///
-    bool get_eof() { return m_get_eof(m_data); }
+    bool get_eof() const { return m_get_eof(m_data); }
     
     /// \brief Return non-zero if the stream is in an error state
     //
@@ -254,11 +209,11 @@
     /// There are some rough meaning for possible returned values
     /// but I don't think they make much sense currently.
     ///
-    int        get_error() { return m_get_err(m_data); }
+    int        get_error() const { return m_get_err(m_data); }
     
 
     /// \brief Get the size of the stream
-    int get_size() { return m_get_stream_size(m_data); }
+    int get_size() const { return m_get_stream_size(m_data); }
     
     // \brief UNSAFE back door, for testing only.
     void* get_app_data_DEBUG() { return m_data; }
@@ -328,46 +283,6 @@
     close_func         m_close;
 };
 
-
-//
-// Some inline stuff.
-//
-
-
-/// \brief Write a 32-bit float to a stream in little-endian order.
-/// @@ This currently relies on host FP format being the same as the Flash one
-/// (presumably IEEE 754).
-inline void    tu_file::write_float32(float value)
-{
-    union alias {
-        float  f;
-        boost::uint32_t        i;
-    } u;
-
-    compiler_assert(sizeof(alias) == sizeof(boost::uint32_t));
-    
-    u.f = value;
-    write_le32(u.i);
-}
-
-
-/// \brief Read a 32-bit float from a little-endian stream.
-/// @@ This currently relies on host FP format being the same as the Flash one
-/// (presumably IEEE 754).
-inline float   tu_file::read_float32()
-// Read a 32-bit little-endian float from this file.
-{
-    union {
-        float  f;
-        boost::uint32_t        i;
-    } u;
-
-    compiler_assert(sizeof(u) == sizeof(u.i));
-    
-    u.i = read_le32();
-    return u.f;
-}
-
 #endif // TU_FILE_H
 
 

Index: libbase/IOChannel.cpp
===================================================================
RCS file: libbase/IOChannel.cpp
diff -N libbase/IOChannel.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libbase/IOChannel.cpp       9 Jun 2008 11:20:59 -0000       1.1
@@ -0,0 +1,126 @@
+// IOChannel.cpp - a virtual IO channel, for Gnash
+//
+//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+//
+// This program 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 of the License, or
+// (at your option) any later version.
+//
+// This program 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+
+#include "IOChannel.h"
+
+namespace gnash
+{
+
+boost::uint32_t
+IOChannel::read_le32() 
+{
+       // read_byte() is boost::uint8_t, so no masks with 0xff are required.
+       boost::uint32_t result = static_cast<boost::uint32_t>(read_byte());
+       result |= static_cast<boost::uint32_t>(read_byte()) << 8;
+       result |= static_cast<boost::uint32_t>(read_byte()) << 16;
+       result |= static_cast<boost::uint32_t>(read_byte()) << 24;
+       return(result);
+}
+
+long double
+IOChannel::read_le_double64() 
+{
+       return static_cast<long double> (
+               static_cast<boost::int64_t> (read_le32()) |
+               static_cast<boost::int64_t> (read_le32()) << 32
+       );
+}
+
+boost::uint16_t
+IOChannel::read_le16()
+{
+       boost::uint16_t result = static_cast<boost::uint16_t>(read_byte());
+       result |= static_cast<boost::uint16_t>(read_byte()) << 8;
+       return(result);
+}
+
+void
+IOChannel::write_le32(boost::uint32_t u)
+{
+        write_byte(static_cast<boost::int8_t>(u));
+        write_byte(static_cast<boost::int8_t>(u>>8));
+        write_byte(static_cast<boost::int8_t>(u>>16));
+        write_byte(static_cast<boost::int8_t>(u>>24));
+}
+
+void
+IOChannel::write_le16(boost::uint16_t u)
+{
+       write_byte(static_cast<boost::int8_t>(u));
+       write_byte(static_cast<boost::int8_t>(u>>8));
+}
+
+void
+IOChannel::write_string(const char* src)
+{
+       for (;;)
+       {
+               write_byte(*src);
+               if (*src == 0) break;
+               src++;
+       }
+}
+
+int
+IOChannel::read_string(char* dst, int max_length) 
+{
+       int i=0;
+       while (i<max_length)
+       {
+               dst[i] = read_byte();
+               if (dst[i]=='\0') return i;
+               i++;
+       }
+    
+       dst[max_length - 1] = '\0';     // force termination.
+    
+       return -1;
+}
+
+void
+IOChannel::write_float32(float value)
+{
+    union alias {
+        float  f;
+        boost::uint32_t        i;
+    } u;
+
+    compiler_assert(sizeof(alias) == sizeof(boost::uint32_t));
+    
+    u.f = value;
+    write_le32(u.i);
+}
+
+float
+IOChannel::read_float32()
+{
+    union {
+        float  f;
+        boost::uint32_t        i;
+    } u;
+
+    compiler_assert(sizeof(u) == sizeof(u.i));
+    
+    u.i = read_le32();
+    return u.f;
+}
+
+
+} // namespace gnash

Index: libbase/IOChannel.h
===================================================================
RCS file: libbase/IOChannel.h
diff -N libbase/IOChannel.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libbase/IOChannel.h 9 Jun 2008 11:20:59 -0000       1.1
@@ -0,0 +1,221 @@
+// IOChannel.h - a virtual IO channel, for Gnash
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+// 
+// This program 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 of the License, or
+// (at your option) any later version.
+// 
+// This program 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+#ifndef GNASH_IOCHANNEL_H
+#define GNASH_IOCHANNEL_H
+
+#include "dsodefs.h" // DSOEXPORT
+#include "utility.h"
+
+#include <cstdio>
+
+//class membuf;
+
+// temp hack to avoid changing all callers
+// TODO: update all callers ...
+enum
+{
+    TU_FILE_NO_ERROR = 0,
+    TU_FILE_OPEN_ERROR = -1,
+    TU_FILE_READ_ERROR = -1,
+    TU_FILE_WRITE_ERROR = -1,
+    TU_FILE_SEEK_ERROR = -1,
+    TU_FILE_CLOSE_ERROR = -1
+};
+
+namespace gnash {
+
+/// A virtual IO channel
+class DSOEXPORT IOChannel
+{
+public:
+
+       virtual ~IOChannel() {}
+
+       /// \brief Read a 32-bit word from a little-endian stream.
+       ///     returning it as a native-endian word.
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       boost::uint32_t read_le32();
+
+       /// \brief Read a 64-bit word from a little-ending stream,
+       /// returning it as a native-endian word.
+       //
+       /// TODO: define what happens when the stream is in
+       ///       error condition, see get_error().
+       /// TODO: define a platform-neutral type for 64 bits.
+       ///
+       long double read_le_double64();
+
+       /// Read a 16-bit word from a little-endian stream.
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       boost::uint16_t read_le16();
+
+       /// Write a 32-bit word to a little-endian stream.
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       void write_le32(boost::uint32_t u);
+
+       /// \brief Write a 16-bit word to a little-endian stream.
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       void write_le16(boost::uint16_t u);
+
+       /// Read a single byte from the stream
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       virtual boost::uint8_t read_byte() =0;
+
+       /// write a single byte to the stream
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       virtual void write_byte(boost::uint8_t u)=0;
+
+       /// Read the given number of bytes from the stream
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       virtual int read_bytes(void* dst, int num)=0;
+
+       /// \brief Write the given number of bytes to the stream
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       virtual int write_bytes(const void* src, int num)=0;
+
+       /// \brief Write a 0-terminated string to a stream.
+       //
+       /// TODO: define what happens when the stream
+       ///       is in error condition, see get_error().
+       ///
+       void write_string(const char* src);
+
+       /// \brief
+       /// Read up to max_length characters, returns the number of characters 
+       /// read, or -1 if the string length is longer than max_length.
+       //
+       /// Stops at the first \0 character if it comes before max_length.
+       ///
+       /// Guarantees termination of the string.
+       ///
+       /// @return the number of characters read, or -1 no null-termination
+       ///         was found within max_length
+       ///
+       /// TODO: define what to return when the stream
+       ///       is in error condition, see get_error().
+       ///
+       int     read_string(char* dst, int max_length);
+
+       /// Write a 32-bit float to a stream in little-endian order.
+       //
+       /// NOTE: this currently relies on host FP format being the same as the 
Flash one
+       ///       (presumably IEEE 754).
+       ///
+       /// TODO: define what to return when the stream
+       ///       is in error condition, see get_error().
+       ///
+       void    write_float32(float value);
+
+       /// Read a 32-bit float from a little-endian stream.
+       //
+       /// NOTE: this currently relies on host FP format being the same as the 
Flash one
+       /// (presumably IEEE 754).
+       ///
+       /// TODO: define what to return when the stream
+       ///       is in error condition, see get_error().
+       ///
+       float   read_float32();
+
+       /// Return current stream position
+       //
+       /// TODO: define what to return when the stream
+       ///       is in error condition, see get_error().
+       ///
+       virtual int get_position() const=0;
+
+       /// Seek to the specified position
+       //
+       /// 
+       /// TODO: define what happens when an error occurs, or
+       ///       when we're already in an error condition
+       ///
+       /// @return 0 on success, or -1 on failure.
+       ///
+       virtual int set_position(int p)=0;
+
+       /// Seek to the end of the stream
+       //
+       /// TODO: define what happens when an error occurs
+       ///
+       virtual void go_to_end()=0;
+
+       /// Return true if the end of the stream has been reached.
+       //
+       /// TODO: define what to return when in error condition
+       /// see get_error().
+       ///
+       virtual bool get_eof() const=0;
+    
+       /// Return non-zero if the stream is in an error state
+       //
+       /// When the stream is in an error state there's nothing
+       /// you can do about it, just delete it and log the error.
+       ///
+       /// There are some rough meaning for possible returned values
+       /// but I don't think they make much sense currently.
+       ///
+       virtual int get_error() const=0;
+    
+       /// Get the size of the stream (unreliably).
+       //
+       /// Size of steram is unreliable as not all input
+       /// channels have a mechanism to advertise size,
+       /// and some have one but isn't necessarely truthful
+       /// (a few HTTP severs are bogus in this reguard).
+       ///
+       /// @return unreliable input size. 
+       ///
+       virtual int get_size() const=0;
+   
+};
+
+} // namespace gnash
+
+#endif // GNASH_IOCHANNEL_H
+
+
+// Local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:




reply via email to

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