[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10566: Rework NamingPolicy to use b
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10566: Rework NamingPolicy to use base URL for ease of finding saved media. |
Date: |
Mon, 09 Feb 2009 12:12:43 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10566
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2009-02-09 12:12:43 +0100
message:
Rework NamingPolicy to use base URL for ease of finding saved media.
Move StreamProvider and NamingPolicy functionality out of the core to the
hosting application to keep libcore clean. Improve interfaces.
added:
libbase/NamingPolicy.cpp
libbase/NamingPolicy.h
modified:
cygnal/cvm.cpp
gui/Player.cpp
gui/Player.h
gui/gtk.cpp
gui/gtk_glue.h
gui/gtk_glue_agg.cpp
gui/gtk_glue_agg.h
libbase/GnashImage.h
libbase/Makefile.am
libcore/LoadVariablesThread.cpp
libcore/LoadVariablesThread.h
libcore/MovieClip.cpp
libcore/RunInfo.h
libcore/StreamProvider.cpp
libcore/StreamProvider.h
libcore/asobj/NetConnection_as.cpp
libcore/asobj/Sound_as.cpp
libcore/impl.cpp
testsuite/MovieTester.cpp
testsuite/MovieTester.h
utilities/processor.cpp
------------------------------------------------------------
revno: 10565.1.1
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2009-02-09 10:29:52 +0100
message:
Move NamingPolicy to its own files in libbase.
StreamProvider is no longer a singleton and must be passed to the RunInfo.
The NamingPolicy for cache files may be passed to the StreamProvider
(either
in the ctor or using setNamingPolicy()).
RunInfo pointers are now shared_ptrs to signify shared ownership; this
reduces the importance of construction/destruction order and should
make future refactoring easier.
LoadVariablesThread takes a StreamProvider in the ctor in order to fetch
its stream.
modified:
cygnal/cvm.cpp
gui/Player.cpp
gui/Player.h
gui/gtk.cpp
gui/gtk_glue.h
gui/gtk_glue_agg.cpp
gui/gtk_glue_agg.h
libbase/GnashImage.h
libbase/Makefile.am
libcore/LoadVariablesThread.cpp
libcore/LoadVariablesThread.h
libcore/MovieClip.cpp
libcore/RunInfo.h
libcore/StreamProvider.cpp
libcore/StreamProvider.h
libcore/asobj/NetConnection_as.cpp
libcore/asobj/Sound_as.cpp
libcore/impl.cpp
testsuite/MovieTester.cpp
testsuite/MovieTester.h
utilities/processor.cpp
------------------------------------------------------------
revno: 10565.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2009-02-09 11:08:23 +0100
message:
StreamProvider owns the NamingPolicy object (no obvious need for
shared ownership).
Add NamingPolicy files.
added:
libbase/NamingPolicy.cpp
libbase/NamingPolicy.h
modified:
gui/Player.cpp
libcore/StreamProvider.cpp
libcore/StreamProvider.h
------------------------------------------------------------
revno: 10565.1.3
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2009-02-09 11:18:56 +0100
message:
Drop obsolete code from GTK gui, revert some unfinished work on GTK gui
that
wasn't intended for committing.
modified:
gui/gtk.cpp
gui/gtk_glue.h
gui/gtk_glue_agg.cpp
gui/gtk_glue_agg.h
=== modified file 'cygnal/cvm.cpp'
--- a/cygnal/cvm.cpp 2008-11-01 15:15:52 +0000
+++ b/cygnal/cvm.cpp 2009-02-09 09:29:52 +0000
@@ -351,7 +351,7 @@
#endif
gnash::media::MediaHandler::set(handler);
- std::auto_ptr<sound::sound_handler> soundHandler(
+ boost::shared_ptr<sound::sound_handler> soundHandler(
new sound::NullSoundHandler());
std::vector<movie_data> data;
@@ -362,7 +362,7 @@
{
RunInfo runInfo(*i);
- runInfo.setSoundHandler(soundHandler.get());
+ runInfo.setSoundHandler(soundHandler);
boost::intrusive_ptr<gnash::movie_definition> m =
play_movie(*i, runInfo);
=== modified file 'gui/Player.cpp'
--- a/gui/Player.cpp 2009-02-06 15:28:57 +0000
+++ b/gui/Player.cpp 2009-02-09 10:08:23 +0000
@@ -34,7 +34,9 @@
#include "MovieClip.h" // for setting FlashVars
#include "movie_root.h"
#include "Player.h"
+#include "StreamProvider.h"
+#include "NamingPolicy.h"
#include "StringPredicates.h"
#include "URL.h"
#include "rc.h"
@@ -372,7 +374,12 @@
/// The RunInfo should be populated before parsing.
_runInfo.reset(new RunInfo(baseURL.str()));
- _runInfo->setSoundHandler(_soundHandler.get());
+ _runInfo->setSoundHandler(_soundHandler);
+
+ std::auto_ptr<NamingPolicy> np(new IncrementalRename(_baseurl));
+ boost::shared_ptr<StreamProvider> sp(new StreamProvider(np));
+
+ _runInfo->setStreamProvider(sp);
// Load the actual movie.
_movieDef = load_movie();
=== modified file 'gui/Player.h'
--- a/gui/Player.h 2009-02-06 15:28:57 +0000
+++ b/gui/Player.h 2009-02-09 09:29:52 +0000
@@ -33,6 +33,7 @@
#include "RunInfo.h" // for passing handlers and other data to the core.
#include <string>
+#include <boost/shared_ptr.hpp>
#include <map>
// Forward declarations
@@ -252,7 +253,7 @@
/// @todo This is hairy, and the core should be sorted out so that
/// sound_sample knows about its sound::sound_handler without
/// needing a RunInfo.
- std::auto_ptr<sound::sound_handler> _soundHandler;
+ boost::shared_ptr<sound::sound_handler> _soundHandler;
std::auto_ptr<media::MediaHandler> _mediaHandler;
=== modified file 'gui/gtk.cpp'
--- a/gui/gtk.cpp 2009-02-06 15:28:57 +0000
+++ b/gui/gtk.cpp 2009-02-09 10:18:56 +0000
@@ -112,9 +112,8 @@
bool
GtkGui::init(int argc, char **argv[])
{
- //GNASH_REPORT_FUNCTION;
- gtk_init (&argc, argv);
+ gtk_init(&argc, argv);
#ifdef GUI_HILDON
_hildon_program = hildon_program_get_instance();
@@ -232,22 +231,6 @@
// Kick-start before setting the interval timeout
advance_movie(this);
-#if 0
- // From
http://www.idt.mdh.se/kurser/cd5040/ht02/gtk/glib/glib-the-main-event-loop.html#G-TIMEOUT-ADD-FULL
- //
- // Note that timeout functions may be delayed, due to the
- // processing of other event sources. Thus they should not be
- // relied on for precise timing. After each call to the timeout
- // function, the time of the next timeout is recalculated based
- // on the current time and the given interval (it does not try to
- // 'catch up' time lost in delays).
- //
- // NOTE: this is OK (research on 'elastic frame rate').
- //
- _advanceSourceTimer = g_timeout_add_full (G_PRIORITY_LOW, _interval,
(GSourceFunc)advance_movie,
- this, NULL);
-#endif
-
gtk_main();
return true;
}
@@ -559,11 +542,12 @@
{
g_source_remove(_advanceSourceTimer);
}
-#if 1
- _advanceSourceTimer = g_timeout_add_full (G_PRIORITY_LOW, _interval,
(GSourceFunc)advance_movie,
- this, NULL);
- log_debug("Advance interval timer set to %d ms (~ %d FPS)", _interval,
1000/_interval);
-#endif
+
+ _advanceSourceTimer = g_timeout_add_full(G_PRIORITY_LOW, _interval,
+ (GSourceFunc)advance_movie, this, NULL);
+
+ log_debug("Advance interval timer set to %d ms (~ %d FPS)",
+ _interval, 1000/_interval);
}
///////////////////////////////////////////////////////////////////////////////
=== modified file 'gui/gtk_glue.h'
--- a/gui/gtk_glue.h 2008-07-22 09:22:24 +0000
+++ b/gui/gtk_glue.h 2009-02-09 10:18:56 +0000
@@ -35,13 +35,19 @@
virtual void prepDrawingArea(GtkWidget *drawing_area) = 0;
virtual render_handler* createRenderHandler() = 0;
- virtual void setRenderHandlerSize(int /*width*/, int /*height*/) { };
+ virtual void setRenderHandlerSize(int /*width*/, int /*height*/) {}
virtual void render() = 0;
+
virtual void render(int /*minx*/, int /*miny*/, int /*maxx*/, int /*maxy*/)
- { render(); };
+ {
+ render();
+ }
+
virtual void configure(GtkWidget *const widget,
- GdkEventConfigure *const event) = 0;
- virtual void beforeRendering() { /* nop */ };
+ GdkEventConfigure *const event) = 0;
+
+ virtual void beforeRendering() {};
+
protected:
GtkWidget *_drawing_area;
};
=== modified file 'gui/gtk_glue_agg.cpp'
--- a/gui/gtk_glue_agg.cpp 2008-11-13 20:55:48 +0000
+++ b/gui/gtk_glue_agg.cpp 2009-02-09 10:18:56 +0000
@@ -51,7 +51,7 @@
}
bool
-GtkAggGlue::init(int /*argc*/, char **/*argv*/[])
+GtkAggGlue::init(int /*argc*/, char ** /*argv*/[])
{
return true;
}
@@ -132,6 +132,7 @@
render(0, 0, _offscreenbuf->width, _offscreenbuf->height);
}
+
void
GtkAggGlue::render(int minx, int miny, int maxx, int maxy)
{
=== modified file 'gui/gtk_glue_agg.h'
--- a/gui/gtk_glue_agg.h 2008-11-13 20:55:48 +0000
+++ b/gui/gtk_glue_agg.h 2009-02-09 10:18:56 +0000
@@ -43,7 +43,7 @@
void render();
void render(int minx, int miny, int maxx, int maxy);
void configure(GtkWidget *const widget, GdkEventConfigure *const event);
-
+
private:
GdkImage* _offscreenbuf;
render_handler *_agg_renderer;
=== modified file 'libbase/GnashImage.h'
--- a/libbase/GnashImage.h 2008-11-14 00:46:35 +0000
+++ b/libbase/GnashImage.h 2009-02-09 09:29:52 +0000
@@ -394,9 +394,11 @@
/// @param type The image format to write in (see libcore/gnash.h)
/// @param out The IOChannel to write to.
/// @param image The image to write.
- /// @param quality The quality of the image output (not used for all
formats)
- static void writeImageData(FileType type,
boost::shared_ptr<gnash::IOChannel> out,
- const GnashImage& image, int quality);
+ /// @param quality The quality of the image output (not used for all
+ /// formats)
+ static void writeImageData(FileType type,
+ boost::shared_ptr<gnash::IOChannel> out, const GnashImage& image,
+ int quality);
protected:
=== modified file 'libbase/Makefile.am'
--- a/libbase/Makefile.am 2009-01-27 12:23:12 +0000
+++ b/libbase/Makefile.am 2009-02-09 09:29:52 +0000
@@ -112,6 +112,7 @@
tu_file.cpp \
IOChannel.cpp \
ClockTime.cpp \
+ NamingPolicy.cpp \
WallClockTimer.cpp \
utf8.cpp \
curl_adapter.cpp \
@@ -157,6 +158,7 @@
tu_opengl_includes.h \
GnashSystemIOHeaders.h \
GnashFileUtilities.h \
+ NamingPolicy.h \
ClockTime.h \
WallClockTimer.h \
utf8.h \
=== added file 'libbase/NamingPolicy.cpp'
--- a/libbase/NamingPolicy.cpp 1970-01-01 00:00:00 +0000
+++ b/libbase/NamingPolicy.cpp 2009-02-09 10:08:23 +0000
@@ -0,0 +1,123 @@
+
+#include "NamingPolicy.h"
+#include "gnashconfig.h"
+#include "URL.h"
+#include "GnashFileUtilities.h"
+#include "rc.h"
+#include "log.h"
+
+#include <sstream>
+#include <string>
+#include <limits>
+#include <boost/algorithm/string/replace.hpp>
+
+namespace gnash {
+
+
+namespace {
+ std::string urlToDirectory(const std::string& path);
+}
+
+
+std::string
+OverwriteExisting::operator()(const URL& url) const
+{
+ std::string path = url.path().substr(1);
+
+ // Replace all slashes with a _ for a flat directory structure.
+ boost::replace_all(path, "/", "_");
+
+ const std::string& dir = urlToDirectory(url.hostname() + "/");
+
+ if (dir.empty()) return std::string();
+
+ return dir + path;
+}
+
+
+IncrementalRename::IncrementalRename(const URL& baseURL)
+ :
+ _baseURL(baseURL)
+{
+}
+
+
+std::string
+IncrementalRename::operator()(const URL& url) const
+{
+
+ const std::string& path = url.path();
+ assert(!path.empty());
+ assert(path[0] == '/');
+
+ // Find the last dot, but not if it's first in the path (after the
+ // initial '/').
+ std::string::size_type dot = path.rfind('.');
+ if (dot == 1) dot = std::string::npos;
+
+ // Take the path from after the initial '/' to the last '.' for
+ // manipulation. It doesn't matter if dot is npos.
+ std::string pre = path.substr(1, dot - 1);
+
+ // Replace all slashes with a _ for a flat directory structure.
+ boost::replace_all(pre, "/", "_");
+
+ const std::string& suffix = (dot == std::string::npos) ? "" :
+ path.substr(dot);
+
+ // Add a trailing slash.
+ const std::string& hostname = _baseURL.hostname().empty() ? "localhost" :
+ _baseURL.hostname();
+
+ const std::string& dir = urlToDirectory(hostname + "/");
+ if (dir.empty()) return std::string();
+
+ std::ostringstream s(dir + pre + suffix);
+
+ size_t i = 0;
+
+ const size_t m = std::numeric_limits<size_t>::max();
+
+ struct stat st;
+ while (stat(s.str().c_str(), &st) >= 0 && i < m) {
+ s.str("");
+ s << dir << pre << i << suffix;
+ ++i;
+ }
+
+ // If there are no options left, return an empty string.
+ if (i == m) {
+ return std::string();
+ }
+
+ return s.str();
+
+}
+
+namespace {
+
+/// Transform a URL into a directory and create it.
+//
+/// @return an empty string if the directory cannot be created, otherwise
+/// the name of the created directory with a trailing slash.
+/// @param url The path to transform. Anything after the last '/' is ignored.
+std::string
+urlToDirectory(const std::string& path)
+{
+
+ const RcInitFile& rcfile = RcInitFile::getDefaultInstance();
+ const std::string& dir = rcfile.getMediaDir() + "/" + path;
+
+ // Create the user-specified directory if possible.
+ // An alternative would be to use the 'host' part and create a
+ // directory tree.
+ if (!mkdirRecursive(dir)) {
+ return std::string();
+ }
+
+ return dir;
+
+}
+
+} // anonymous namespace
+} // namespace gnash
=== added file 'libbase/NamingPolicy.h'
--- a/libbase/NamingPolicy.h 1970-01-01 00:00:00 +0000
+++ b/libbase/NamingPolicy.h 2009-02-09 10:08:23 +0000
@@ -0,0 +1,44 @@
+
+
+
+#ifndef GNASH_NAMINGPOLICY_H
+#define GNASH_NAMINGPOLICY_H
+
+#include "URL.h"
+
+#include <string>
+
+namespace gnash {
+
+
+struct NamingPolicy
+{
+ NamingPolicy() {}
+ virtual ~NamingPolicy() {}
+ virtual std::string operator()(const URL&) const
+ {
+ return std::string();
+ }
+};
+
+
+/// Make a non-unique cachefile name from the supplied name.
+/// If the directory cannot be created, return an empty string.
+struct OverwriteExisting : public NamingPolicy
+{
+ virtual std::string operator()(const URL&) const;
+};
+
+/// Make a unique cachefile name from the supplied name.
+/// If all possible filenames are taken, return an empty string.
+struct IncrementalRename : public NamingPolicy
+{
+ IncrementalRename(const URL& baseURL);
+ virtual std::string operator()(const URL& url) const;
+private:
+ const URL _baseURL;
+};
+
+} // namespace gnash
+
+#endif
=== modified file 'libcore/LoadVariablesThread.cpp'
--- a/libcore/LoadVariablesThread.cpp 2008-11-22 16:33:02 +0000
+++ b/libcore/LoadVariablesThread.cpp 2009-02-09 09:29:52 +0000
@@ -138,9 +138,10 @@
setCompleted();
}
-LoadVariablesThread::LoadVariablesThread(const URL& url, const std::string&
postdata)
+LoadVariablesThread::LoadVariablesThread(const StreamProvider& sp,
+ const URL& url, const std::string& postdata)
:
- _stream(StreamProvider::getDefaultInstance().getStream(url, postdata)),
+ _stream(sp.getStream(url, postdata)),
_completed(false),
_canceled(false)
{
@@ -150,9 +151,10 @@
}
}
-LoadVariablesThread::LoadVariablesThread(const URL& url)
+LoadVariablesThread::LoadVariablesThread(const StreamProvider& sp,
+ const URL& url)
:
- _stream(StreamProvider::getDefaultInstance().getStream(url)),
+ _stream(sp.getStream(url)),
_completed(false),
_canceled(false)
{
=== modified file 'libcore/LoadVariablesThread.h'
--- a/libcore/LoadVariablesThread.h 2008-06-09 13:31:51 +0000
+++ b/libcore/LoadVariablesThread.h 2009-02-09 09:29:52 +0000
@@ -61,7 +61,7 @@
/// @param url
/// URL to post to and fetch from
///
- LoadVariablesThread(const URL& url);
+ LoadVariablesThread(const StreamProvider& sp, const URL& url);
/// \brief
/// Construct a LoadVariablesThread opening a stream for the given URL,
@@ -75,7 +75,8 @@
/// @param postdata
/// Url-encoded post data.
///
- LoadVariablesThread(const URL& url, const std::string& postdata);
+ LoadVariablesThread(const StreamProvider& sp, const URL& url,
+ const std::string& postdata);
/// Destroy the LoadVariablesThread, joining the thread if spawned
~LoadVariablesThread();
@@ -91,7 +92,8 @@
{
assert(!_thread.get());
assert(_stream.get());
- _thread.reset( new
boost::thread(boost::bind(LoadVariablesThread::execLoadingThread, this)) );
+ _thread.reset(new boost::thread(
+ boost::bind(LoadVariablesThread::execLoadingThread, this)));
}
/// Cancel a download in progress
=== modified file 'libcore/MovieClip.cpp'
--- a/libcore/MovieClip.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/MovieClip.cpp 2009-02-09 09:29:52 +0000
@@ -2484,11 +2484,13 @@
try
{
+ const StreamProvider& sp = _vm.getRoot().runInfo().streamProvider();
+
if (sendVarsMethod == METHOD_POST)
{
// use POST method
_loadVariableRequests.push_back(
- new LoadVariablesThread(url, postdata));
+ new LoadVariablesThread(sp, url, postdata));
}
else
{
@@ -2500,7 +2502,7 @@
if (qs.empty()) url.set_querystring(postdata);
else url.set_querystring(qs + "&" + postdata);
}
- _loadVariableRequests.push_back(new LoadVariablesThread(url));
+ _loadVariableRequests.push_back(new LoadVariablesThread(sp, url));
}
_loadVariableRequests.back()->process();
}
=== modified file 'libcore/RunInfo.h'
--- a/libcore/RunInfo.h 2008-10-29 09:45:23 +0000
+++ b/libcore/RunInfo.h 2009-02-09 09:29:52 +0000
@@ -20,8 +20,9 @@
#ifndef GNASH_RUN_INFO_H
#define GNASH_RUN_INFO_H
+#include "StreamProvider.h"
#include <string>
-#include "StreamProvider.h"
+#include <boost/shared_ptr.hpp>
namespace gnash {
@@ -50,9 +51,7 @@
/// construction.
RunInfo(const std::string& baseURL)
:
- _baseURL(baseURL),
- _streamProvider(StreamProvider::getDefaultInstance()),
- _soundHandler(0)
+ _baseURL(baseURL)
{
}
@@ -61,13 +60,24 @@
/// @return The base URL set at construction.
const std::string& baseURL() const { return _baseURL; }
+ /// Set the StreamProvider.
+ //
+ /// This can probably be changed during a run without ill effects.
+ void setStreamProvider(boost::shared_ptr<StreamProvider> sp)
+ {
+ _streamProvider = sp;
+ }
+
/// Get a StreamProvider instance.
//
/// This isn't optional. It must always be available, or nothing
/// can be loaded.
//
/// @return A StreamProvider (presently a global singleton).
- StreamProvider& streamProvider() const { return _streamProvider; }
+ const StreamProvider& streamProvider() const {
+ assert (_streamProvider.get());
+ return *_streamProvider;
+ }
/// Set the sound::sound_handler.
//
@@ -76,7 +86,7 @@
//
/// This is cached in various places, so changing it during a run will
/// lead to unexpected behaviour.
- void setSoundHandler(sound::sound_handler* s) {
+ void setSoundHandler(boost::shared_ptr<sound::sound_handler> s) {
_soundHandler = s;
}
@@ -84,15 +94,17 @@
//
/// @return A pointer to a sound::sound_handler, or NULL if none
/// has yet been set.
- sound::sound_handler* soundHandler() const { return _soundHandler; }
+ sound::sound_handler* soundHandler() const {
+ return _soundHandler.get();
+ }
private:
- std::string _baseURL;
-
- StreamProvider& _streamProvider;
-
- sound::sound_handler* _soundHandler;
+ const std::string _baseURL;
+
+ boost::shared_ptr<StreamProvider> _streamProvider;
+
+ boost::shared_ptr<sound::sound_handler> _soundHandler;
};
=== modified file 'libcore/StreamProvider.cpp'
--- a/libcore/StreamProvider.cpp 2009-01-29 16:45:09 +0000
+++ b/libcore/StreamProvider.cpp 2009-02-09 10:08:23 +0000
@@ -30,44 +30,25 @@
#include "URLAccessManager.h"
#include "log.h"
#include "rc.h" // for rcfile
+#include "NamingPolicy.h"
#include <cstdio>
#include <map>
#include <string>
#include <vector>
-#include <boost/algorithm/string/replace.hpp>
+#include <boost/shared_ptr.hpp>
namespace gnash {
-namespace {
-
- std::string urlToDirectory(const std::string& path);
-
- /// Make a unique cachefile name from the supplied name.
- /// If all possible filenames are taken, return an empty string.
- std::string incrementalRename(const URL& url);
-
- /// Make a non-unique cachefile name from the supplied name.
- /// If the directory cannot be created, return an empty string.
- std::string overwriteExisting(const URL& url);
-}
-
-StreamProvider&
-StreamProvider::getDefaultInstance()
-{
- static StreamProvider inst;
- return inst;
-}
-
-StreamProvider::NamingPolicy
-StreamProvider::currentNamingPolicy() const
-{
- //return overwriteExisting;
- return incrementalRename;
-}
+StreamProvider::StreamProvider(std::auto_ptr<NamingPolicy> np)
+ :
+ _namingPolicy(np)
+{
+}
+
std::auto_ptr<IOChannel>
-StreamProvider::getStream(const URL& url, NamingPolicy np)
+StreamProvider::getStream(const URL& url, bool namedCacheFile) const
{
std::auto_ptr<IOChannel> stream;
@@ -106,8 +87,8 @@
else
{
if (URLAccessManager::allow(url)) {
- stream = NetworkAdapter::makeStream(url.str(),
- np ? np(url) : std::string());
+ stream = NetworkAdapter::makeStream(url.str(),
+ namedCacheFile ? namingPolicy()(url) : "");
}
// Will return 0 auto_ptr if not allowed.
@@ -117,7 +98,8 @@
std::auto_ptr<IOChannel>
StreamProvider::getStream(const URL& url, const std::string& postdata,
- const NetworkAdapter::RequestHeaders& headers, NamingPolicy np)
+ const NetworkAdapter::RequestHeaders& headers, bool namedCacheFile)
+ const
{
if (url.protocol() == "file")
@@ -132,7 +114,7 @@
if ( URLAccessManager::allow(url) ) {
return NetworkAdapter::makeStream(url.str(), postdata, headers,
- np ? np(url) : std::string());
+ namedCacheFile ? namingPolicy()(url) : "");
}
return std::auto_ptr<IOChannel>();
@@ -141,7 +123,7 @@
std::auto_ptr<IOChannel>
StreamProvider::getStream(const URL& url, const std::string& postdata,
- NamingPolicy np)
+ bool namedCacheFile) const
{
std::auto_ptr<IOChannel> stream;
@@ -176,7 +158,7 @@
{
if (URLAccessManager::allow(url)) {
stream = NetworkAdapter::makeStream(url.str(), postdata,
- np ? np(url) : std::string());
+ namedCacheFile ? namingPolicy()(url) : "");
}
// Will return 0 auto_ptr if not allowed.
return stream;
@@ -185,96 +167,5 @@
}
-namespace {
-
-/// Transform a URL into a directory and create it.
-//
-/// @return an empty string if the directory cannot be created, otherwise
-/// the name of the created directory with a trailing slash.
-/// @param url The path to transform. Anything after the last '/' is ignored.
-std::string
-urlToDirectory(const std::string& path)
-{
-
- const RcInitFile& rcfile = RcInitFile::getDefaultInstance();
- const std::string& dir = rcfile.getMediaDir() + "/" + path;
-
- // Create the user-specified directory if possible.
- // An alternative would be to use the 'host' part and create a
- // directory tree.
- if (!mkdirRecursive(dir)) {
- // Error
- return std::string();
- }
-
- return dir;
-
-}
-
-std::string
-overwriteExisting(const URL& url)
-{
- std::string path = url.path().substr(1);
-
- // Replace all slashes with a _ for a flat directory structure.
- boost::replace_all(path, "/", "_");
-
- const std::string& dir = urlToDirectory(url.hostname() + "/");
-
- if (dir.empty()) return std::string();
-
- return dir + path;
-}
-
-std::string
-incrementalRename(const URL& url)
-{
-
- const std::string& path = url.path();
- assert(!path.empty());
- assert(path[0] == '/');
-
- // Find the last dot, but not if it's first in the path (after the
- // initial '/').
- std::string::size_type dot = path.rfind('.');
- if (dot == 1) dot = std::string::npos;
-
- // Take the path from after the initial '/' to the last '.' for
- // manipulation. It doesn't matter if dot is npos.
- std::string pre = path.substr(1, dot - 1);
-
- // Replace all slashes with a _ for a flat directory structure.
- boost::replace_all(pre, "/", "_");
-
- const std::string& suffix = (dot == std::string::npos) ? "" :
- path.substr(dot);
-
- // Add a trailing slash.
- const std::string& dir = urlToDirectory(url.hostname() + "/");
- if (dir.empty()) return std::string();
-
- std::ostringstream s(dir + pre + suffix);
-
- size_t i = 0;
-
- const size_t m = std::numeric_limits<size_t>::max();
-
- struct stat st;
- while (stat(s.str().c_str(), &st) >= 0 && i < m) {
- s.str("");
- s << dir << pre << i << suffix;
- ++i;
- }
-
- // If there are no options left, return an empty string.
- if (i == m) {
- return std::string();
- }
-
- return s.str();
-
-}
-
-} // anonymous namespace
} // namespace gnash
=== modified file 'libcore/StreamProvider.h'
--- a/libcore/StreamProvider.h 2009-01-27 16:40:28 +0000
+++ b/libcore/StreamProvider.h 2009-02-09 10:08:23 +0000
@@ -18,11 +18,12 @@
#ifndef GNASH_STREAMPROVIDER_H
#define GNASH_STREAMPROVIDER_H
+#include "NetworkAdapter.h"
+#include "dsodefs.h" // for DSOEXPORT
+#include "NamingPolicy.h"
+
#include <map>
#include <memory>
-#include "NetworkAdapter.h"
-
-#include "dsodefs.h" // for DSOEXPORT
// Forward declarations
namespace gnash {
@@ -39,21 +40,18 @@
public:
- typedef std::string (*NamingPolicy) (const URL&);
-
- StreamProvider() {}
+ StreamProvider(std::auto_ptr<NamingPolicy> =
+ std::auto_ptr<NamingPolicy>(new NamingPolicy));
virtual ~StreamProvider() {}
- static StreamProvider& getDefaultInstance();
-
/// Returned stream ownership is transferred to caller.
//
/// On error NULL is returned
/// Derive from this for a CachingStreamProvider
///
virtual std::auto_ptr<IOChannel> getStream(const URL& url,
- NamingPolicy np = 0);
+ bool namedCacheFile = false) const;
/// Get a stream from the response of a POST operation
//
@@ -70,20 +68,39 @@
///
///
virtual std::auto_ptr<IOChannel> getStream(const URL& url,
- const std::string& postdata, NamingPolicy np = 0);
+ const std::string& postdata, bool namedCacheFile = false) const;
virtual std::auto_ptr<IOChannel> getStream(const URL& url,
const std::string& postdata,
- const NetworkAdapter::RequestHeaders& headers, NamingPolicy np =
0);
+ const NetworkAdapter::RequestHeaders& headers,
+ bool namedCacheFile = false) const;
+ /// Set the NamingPolicy for cache files
+ //
+ /// This is only used when cache file naming is requested in getStream()
+ /// This StreamProvider owns the NamingPolicy instance.
+ void setNamingPolicy(std::auto_ptr<NamingPolicy> np)
+ {
+ _namingPolicy = np;
+ }
+
/// Return the currently selected policy for converting URL to filename
- virtual NamingPolicy currentNamingPolicy() const;
+ const NamingPolicy& namingPolicy() const
+ {
+ assert(_namingPolicy.get());
+ return *_namingPolicy;
+ }
+
+private:
+
+ /// The current naming policy for cache files.
+ std::auto_ptr<NamingPolicy> _namingPolicy;
};
} // namespace gnash
-#endif // _GNASH_STREAMPROVIDER_H
+#endif
// Local Variables:
=== modified file 'libcore/asobj/NetConnection_as.cpp'
--- a/libcore/asobj/NetConnection_as.cpp 2009-01-27 16:40:28 +0000
+++ b/libcore/asobj/NetConnection_as.cpp 2009-02-09 09:29:52 +0000
@@ -589,8 +589,12 @@
#endif
queued_count = 0;
- _connection.reset(StreamProvider::getDefaultInstance().getStream(
- _url, postdata_str, _headers).release());
+ // TODO: it might be useful for a Remoting Handler to have a
+ // StreamProvider member
+ const StreamProvider& sp =
+ _nc.getVM().getRoot().runInfo().streamProvider();
+
+ _connection.reset(sp.getStream(_url, postdata_str,
_headers).release());
_postdata.resize(6);
#ifdef GNASH_DEBUG_REMOTING
@@ -953,7 +957,7 @@
{
const RunInfo& ri = _vm.getRoot().runInfo();
- StreamProvider& streamProvider = ri.streamProvider();
+ const StreamProvider& streamProvider = ri.streamProvider();
// Construct URL with base URL (assuming not connected to RTMP server..)
// TODO: For RTMP return the named stream from an existing RTMP connection.
@@ -964,10 +968,7 @@
const RcInitFile& rcfile = RcInitFile::getDefaultInstance();
- StreamProvider::NamingPolicy cacheNamer = rcfile.saveStreamingMedia() ?
- streamProvider.currentNamingPolicy() : 0;
-
- return streamProvider.getStream(url, cacheNamer);
+ return streamProvider.getStream(url, rcfile.saveStreamingMedia());
}
=== modified file 'libcore/asobj/Sound_as.cpp'
--- a/libcore/asobj/Sound_as.cpp 2008-12-25 19:02:32 +0000
+++ b/libcore/asobj/Sound_as.cpp 2009-02-09 09:29:52 +0000
@@ -211,7 +211,7 @@
const movie_root& mr = _vm.getRoot();
URL url(file, mr.runInfo().baseURL());
- StreamProvider& streamProvider = mr.runInfo().streamProvider();
+ const StreamProvider& streamProvider = mr.runInfo().streamProvider();
std::auto_ptr<IOChannel> inputStream(streamProvider.getStream(url));
if ( ! inputStream.get() )
{
@@ -222,7 +222,7 @@
externalSound = true;
isStreaming = streaming;
- _mediaParser.reset(
_mediaHandler->createMediaParser(inputStream).release() );
+
_mediaParser.reset(_mediaHandler->createMediaParser(inputStream).release());
if ( ! _mediaParser )
{
log_error(_("Unable to create parser for Sound at %s"), url);
@@ -239,7 +239,8 @@
}
else
{
- LOG_ONCE(log_unimpl("Non-streaming Sound.loadSound: will behave as a
streaming one"));
+ LOG_ONCE(log_unimpl("Non-streaming Sound.loadSound: will behave "
+ "as a streaming one"));
// if not streaming, we'll probe on .start()
}
}
=== modified file 'libcore/impl.cpp'
--- a/libcore/impl.cpp 2009-01-27 16:40:28 +0000
+++ b/libcore/impl.cpp 2009-02-09 09:29:52 +0000
@@ -322,16 +322,14 @@
std::auto_ptr<IOChannel> in;
- StreamProvider& streamProvider = runInfo.streamProvider();
+ const StreamProvider& streamProvider = runInfo.streamProvider();
const RcInitFile& rcfile = RcInitFile::getDefaultInstance();
- StreamProvider::NamingPolicy cacheNamer = rcfile.saveLoadedMedia() ?
- streamProvider.currentNamingPolicy() : 0;
-
- if ( postdata ) in = streamProvider.getStream(url, *postdata,
- cacheNamer);
- else in = streamProvider.getStream(url, cacheNamer);
+ if (postdata) {
+ in = streamProvider.getStream(url, *postdata, rcfile.saveLoadedMedia());
+ }
+ else in = streamProvider.getStream(url, rcfile.saveLoadedMedia());
if ( ! in.get() )
{
=== modified file 'testsuite/MovieTester.cpp'
--- a/testsuite/MovieTester.cpp 2008-11-24 13:05:00 +0000
+++ b/testsuite/MovieTester.cpp 2009-02-09 09:29:52 +0000
@@ -81,7 +81,10 @@
initTestingSoundHandlers();
_runInfo.reset(new RunInfo(url));
- _runInfo->setSoundHandler(_sound_handler.get());
+ _runInfo->setSoundHandler(_sound_handler);
+
+ _runInfo->setStreamProvider(boost::shared_ptr<StreamProvider>(
+ new StreamProvider));
if ( url == "-" )
{
=== modified file 'testsuite/MovieTester.h'
--- a/testsuite/MovieTester.h 2008-10-28 15:32:20 +0000
+++ b/testsuite/MovieTester.h 2009-02-09 09:29:52 +0000
@@ -319,7 +319,7 @@
gnash::movie_instance* _movie;
- std::auto_ptr<sound::sound_handler> _sound_handler;
+ boost::shared_ptr<sound::sound_handler> _sound_handler;
std::auto_ptr<RunInfo> _runInfo;
/// Current pointer position - X ordinate
=== modified file 'utilities/processor.cpp'
--- a/utilities/processor.cpp 2008-10-29 07:44:11 +0000
+++ b/utilities/processor.cpp 2009-02-09 09:29:52 +0000
@@ -56,6 +56,7 @@
#include "smart_ptr.h"
#include "IOChannel.h" // for proper dtor call
#include "GnashSleep.h" // for usleep comptibility.
+#include "StreamProvider.h"
extern "C"{
#ifdef HAVE_GETOPT_H
@@ -352,9 +353,11 @@
#endif
gnash::media::MediaHandler::set(handler);
- std::auto_ptr<sound::sound_handler> soundHandler(
+ boost::shared_ptr<sound::sound_handler> soundHandler(
new sound::NullSoundHandler());
+ boost::shared_ptr<StreamProvider> sp(new StreamProvider);
+
std::vector<movie_data> data;
// Play through all the movies.
@@ -363,7 +366,8 @@
{
RunInfo runInfo(*i);
- runInfo.setSoundHandler(soundHandler.get());
+ runInfo.setSoundHandler(soundHandler);
+ runInfo.setStreamProvider(sp);
boost::intrusive_ptr<gnash::movie_definition> m =
play_movie(*i, runInfo);
- [Gnash-commit] /srv/bzr/gnash/trunk r10566: Rework NamingPolicy to use base URL for ease of finding saved media.,
Benjamin Wolsey <=