~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libbase/IOChannel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// IOChannel.cpp - a virtual IO channel, for Gnash
 
2
//
 
3
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
4
//
 
5
// This program is free software; you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation; either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program; if not, write to the Free Software
 
17
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
//
 
19
 
 
20
 
 
21
#include "IOChannel.h"
 
22
 
 
23
#include <boost/static_assert.hpp>
 
24
 
 
25
namespace gnash
 
26
{
 
27
 
 
28
boost::uint32_t
 
29
IOChannel::read_le32() 
 
30
{
 
31
        // read_byte() is boost::uint8_t, so no masks with 0xff are required.
 
32
        boost::uint32_t result = static_cast<boost::uint32_t>(read_byte());
 
33
        result |= static_cast<boost::uint32_t>(read_byte()) << 8;
 
34
        result |= static_cast<boost::uint32_t>(read_byte()) << 16;
 
35
        result |= static_cast<boost::uint32_t>(read_byte()) << 24;
 
36
        return(result);
 
37
}
 
38
 
 
39
long double
 
40
IOChannel::read_le_double64() 
 
41
{
 
42
        return static_cast<long double> (
 
43
                static_cast<boost::int64_t> (read_le32()) |
 
44
                static_cast<boost::int64_t> (read_le32()) << 32
 
45
        );
 
46
}
 
47
 
 
48
boost::uint16_t
 
49
IOChannel::read_le16()
 
50
{
 
51
        boost::uint16_t result = static_cast<boost::uint16_t>(read_byte());
 
52
        result |= static_cast<boost::uint16_t>(read_byte()) << 8;
 
53
        return(result);
 
54
}
 
55
 
 
56
void
 
57
IOChannel::write_le32(boost::uint32_t u)
 
58
{
 
59
        write_byte(static_cast<boost::int8_t>(u));
 
60
        write_byte(static_cast<boost::int8_t>(u>>8));
 
61
        write_byte(static_cast<boost::int8_t>(u>>16));
 
62
        write_byte(static_cast<boost::int8_t>(u>>24));
 
63
}
 
64
 
 
65
void
 
66
IOChannel::write_le16(boost::uint16_t u)
 
67
{
 
68
        write_byte(static_cast<boost::int8_t>(u));
 
69
        write_byte(static_cast<boost::int8_t>(u>>8));
 
70
}
 
71
 
 
72
void
 
73
IOChannel::write_string(const char* src)
 
74
{
 
75
        for (;;)
 
76
        {
 
77
                write_byte(*src);
 
78
                if (*src == 0) break;
 
79
                src++;
 
80
        }
 
81
}
 
82
 
 
83
int
 
84
IOChannel::read_string(char* dst, int max_length) 
 
85
{
 
86
        int i=0;
 
87
        while (i<max_length)
 
88
        {
 
89
                dst[i] = read_byte();
 
90
                if (dst[i]=='\0') return i;
 
91
                i++;
 
92
        }
 
93
    
 
94
        dst[max_length - 1] = '\0';     // force termination.
 
95
    
 
96
        return -1;
 
97
}
 
98
 
 
99
void
 
100
IOChannel::write_float32(float value)
 
101
{
 
102
    union alias {
 
103
        float   f;
 
104
        boost::uint32_t i;
 
105
    } u;
 
106
 
 
107
    BOOST_STATIC_ASSERT(sizeof(alias) == sizeof(boost::uint32_t));
 
108
    
 
109
    u.f = value;
 
110
    write_le32(u.i);
 
111
}
 
112
 
 
113
float
 
114
IOChannel::read_float32()
 
115
{
 
116
    union {
 
117
        float   f;
 
118
        boost::uint32_t i;
 
119
    } u;
 
120
 
 
121
    BOOST_STATIC_ASSERT(sizeof(u) == sizeof(u.i));
 
122
    
 
123
    u.i = read_le32();
 
124
    return u.f;
 
125
}
 
126
 
 
127
boost::uint8_t
 
128
IOChannel::read_byte()
 
129
{
 
130
        boost::uint8_t u;
 
131
        if ( read(&u, 1) == -1 )
 
132
        {
 
133
                throw IOException("Could not read a single byte from input");
 
134
        }
 
135
        return u;
 
136
}
 
137
 
 
138
void
 
139
IOChannel::write_byte(boost::uint8_t u)
 
140
{
 
141
        write(&u, 1); // will trhow on error it seems
 
142
}
 
143
 
 
144
int
 
145
IOChannel::write(const void* /*src*/, int /*num*/)
 
146
{
 
147
        throw IOException("This IOChannel implementation doesn't support output");
 
148
}
 
149
 
 
150
} // namespace gnash