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

« back to all changes in this revision

Viewing changes to libcore/LoadVariablesThread.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
// 
 
2
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
3
//
 
4
// This program is free software; you can redistribute it and/or modify
 
5
// it under the terms of the GNU General Public License as published by
 
6
// the Free Software Foundation; either version 3 of the License, or
 
7
// (at your option) any later version.
 
8
//
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
// GNU General Public License for more details.
 
13
//
 
14
// You should have received a copy of the GNU General Public License
 
15
// along with this program; if not, write to the Free Software
 
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
//
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
#include "gnashconfig.h"
 
21
#endif
 
22
 
 
23
#include "LoadVariablesThread.h"
 
24
#include "IOChannel.h"
 
25
#include "log.h"
 
26
#include "GnashException.h"
 
27
#include "utf8.h"
 
28
 
 
29
#include <string>
 
30
#include <boost/scoped_array.hpp>
 
31
 
 
32
//#define DEBUG_LOAD_VARIABLES 1
 
33
 
 
34
namespace gnash {
 
35
 
 
36
void
 
37
LoadVariablesThread::completeLoad()
 
38
{
 
39
#ifdef DEBUG_LOAD_VARIABLES
 
40
        log_debug("completeLoad called");
 
41
#endif
 
42
 
 
43
 
 
44
        // TODO: how to set _bytesTotal ?
 
45
 
 
46
        // this is going to override any previous setting,
 
47
        // better do this inside a subclass (in a separate thread)
 
48
        _bytesLoaded = 0;
 
49
        _bytesTotal = _stream->size();
 
50
 
 
51
        std::string toparse;
 
52
 
 
53
        const size_t chunkSize = 1024;
 
54
        boost::scoped_array<char> buf(new char[chunkSize]);
 
55
        unsigned int parsedLines = 0;
 
56
        // TODO: use read_string ?
 
57
        while ( size_t bytesRead = _stream->read(buf.get(), chunkSize) )
 
58
        {
 
59
#ifdef DEBUG_LOAD_VARIABLES
 
60
                log_debug("Read %u bytes", bytesRead);
 
61
#endif
 
62
 
 
63
                if ( _bytesLoaded )
 
64
                {
 
65
                        std::string chunk(buf.get(), bytesRead);
 
66
                        toparse += chunk;
 
67
                }
 
68
                else
 
69
                {
 
70
                        size_t dataSize = bytesRead;
 
71
                        utf8::TextEncoding encoding;
 
72
                        char* ptr = utf8::stripBOM(buf.get(), dataSize,
 
73
                                        encoding);
 
74
                        if ( encoding != utf8::encUTF8 &&
 
75
                             encoding != utf8::encUNSPECIFIED )
 
76
                        {
 
77
                                log_unimpl("%s to utf8 conversion in "
 
78
                                            "MovieClip.loadVariables "
 
79
                                            "input parsing",
 
80
                                            utf8::textEncodingName(encoding));
 
81
                        }
 
82
                        std::string chunk(ptr, dataSize);
 
83
                        toparse += chunk;
 
84
                }
 
85
 
 
86
#ifdef DEBUG_LOAD_VARIABLES
 
87
                log_debug("toparse: %s", toparse);
 
88
#endif
 
89
 
 
90
                // parse remainder
 
91
                size_t lastamp = toparse.rfind('&');
 
92
                if ( lastamp != std::string::npos )
 
93
                {
 
94
                        std::string parseable = toparse.substr(0, lastamp);
 
95
#ifdef DEBUG_LOAD_VARIABLES
 
96
                        log_debug("parseable: %s", parseable);
 
97
#endif
 
98
                        parse(parseable);
 
99
                        toparse = toparse.substr(lastamp+1);
 
100
#ifdef DEBUG_LOAD_VARIABLES
 
101
                        log_debug("toparse nextline: %s", toparse);
 
102
#endif
 
103
                        ++parsedLines;
 
104
                }
 
105
 
 
106
                _bytesLoaded += bytesRead;
 
107
                //dispatchDataEvent();
 
108
 
 
109
                // eof, get out !
 
110
                if ( _stream->eof() ) break;
 
111
 
 
112
                if ( cancelRequested() )
 
113
                {
 
114
                        log_debug("Cancelling LoadVariables download thread...");
 
115
                        _stream.reset();
 
116
                        return;
 
117
                }
 
118
        }
 
119
 
 
120
        if ( ! toparse.empty() )
 
121
        {
 
122
                parse(toparse);
 
123
        }
 
124
 
 
125
        _stream->go_to_end();
 
126
        _bytesLoaded = _stream->tell();
 
127
        if ( _bytesTotal !=  _bytesLoaded )
 
128
        {
 
129
                log_error("Size of stream variables were loaded from advertised to be %d bytes long,"
 
130
                         " but turned out to be only %d bytes long",
 
131
                        _bytesTotal, _bytesLoaded);
 
132
                _bytesTotal = _bytesLoaded;
 
133
        }
 
134
 
 
135
        _stream.reset(); // we don't need the IOChannel anymore
 
136
 
 
137
        //dispatchLoadEvent();
 
138
        setCompleted();
 
139
}
 
140
 
 
141
LoadVariablesThread::LoadVariablesThread(const URL& url, const std::string& postdata)
 
142
        :
 
143
        _stream(StreamProvider::getDefaultInstance().getStream(url, postdata)),
 
144
        _completed(false),
 
145
        _canceled(false)
 
146
{
 
147
        if ( ! _stream.get() )
 
148
        {
 
149
                throw NetworkException();
 
150
        }
 
151
}
 
152
 
 
153
LoadVariablesThread::LoadVariablesThread(const URL& url)
 
154
        :
 
155
        _stream(StreamProvider::getDefaultInstance().getStream(url)),
 
156
        _completed(false),
 
157
        _canceled(false)
 
158
{
 
159
        if ( ! _stream.get() )
 
160
        {
 
161
                throw NetworkException();
 
162
        }
 
163
}
 
164
 
 
165
void
 
166
LoadVariablesThread::cancel()
 
167
{
 
168
        boost::mutex::scoped_lock lock(_mutex);
 
169
        _canceled = true;
 
170
}
 
171
 
 
172
bool
 
173
LoadVariablesThread::cancelRequested()
 
174
{
 
175
        boost::mutex::scoped_lock lock(_mutex);
 
176
        return _canceled;
 
177
}
 
178
 
 
179
LoadVariablesThread::~LoadVariablesThread()
 
180
{
 
181
        if ( _thread.get() )
 
182
        {
 
183
                cancel();
 
184
                _thread->join();
 
185
                _thread.reset();
 
186
        }
 
187
}
 
188
 
 
189
 
 
190
} // namespace gnash