From a54540515e0745d24e546dde26231d2f0f5bb8ad Mon Sep 17 00:00:00 2001 From: randomdan Date: Sat, 15 Mar 2014 13:18:17 +0000 Subject: Add a stream presenter, allows output of any source stream Propergate stream exceptions back to presenters Expose the ICE communicator from iceDataSource --- project2/cgi/cgiAppEngine.cpp | 1 + project2/ice/iceDataSource.h | 1 + project2/streams/streamPresenter.cpp | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 project2/streams/streamPresenter.cpp diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 872f896..234cbeb 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -125,6 +125,7 @@ finalTransformSource(TransformSourcePtr ts) void CgiApplicationEngine::process(std::ostream & IO, CgiRequestContext * crc) const { + IO.exceptions(std::ifstream::failbit | std::ifstream::badbit); bool sessionEmpty = crc->getSession()->Empty(); crc->startTime = boost::date_time::microsec_clock::universal_time(); bool triedNotFound = false; diff --git a/project2/ice/iceDataSource.h b/project2/ice/iceDataSource.h index b145fe5..47af13b 100644 --- a/project2/ice/iceDataSource.h +++ b/project2/ice/iceDataSource.h @@ -31,6 +31,7 @@ class IceDataSource : public DataSource { return Interface::checkedCast(existingProxy->second); } + const Ice::CommunicatorPtr GetCommunicator() const { return ic; } static void FinaliseLoad(); private: diff --git a/project2/streams/streamPresenter.cpp b/project2/streams/streamPresenter.cpp new file mode 100644 index 0000000..3dde21c --- /dev/null +++ b/project2/streams/streamPresenter.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +class StreamPresenter : public Presenter, public WritableContent, public SourceOf { + public: + StreamPresenter(ScriptNodePtr e, ObjectSource os, ExecContext * ) : + Presenter(os), + contentType(e, "contenttype", "application/octet-stream") + { + e->script->loader.addLoadTarget(e, Storer::into(&stream)); + } + + WritableContent::Class getContentClass() const + { + return ClassData; + } + + Glib::ustring getContentType() const + { + return contentType(NULL); + } + + static size_t write(std::ostream * os, const char * data, size_t len) + { + os->write(data, len); + return len; + } + + void writeTo(std::ostream & os, const std::string&, ExecContext * ec) const + { + if (stream) { + stream->runStream(boost::bind(&StreamPresenter::write, &os, _1, _2), ec); + } + } + + void addNewArray(const Glib::ustring&, bool) const + { + } + + void finishArray(bool) const + { + } + + void init(ExecContext*) + { + } + + void pushSub(const Glib::ustring&, const Glib::ustring&) const + { + } + + void addText(const VariableType&) const + { + } + + void popSub() const + { + } + + operator const WritableContent * () const + { + return this; + } + + private: + Variable contentType; + StreamPtr stream; +}; + +DECLARE_GENERIC_LOADER("stream", PresenterLoader, StreamPresenter) -- cgit v1.2.3