From c6dd17a1435db36eeaff24e40a7cc212ee7214a0 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 2 Aug 2013 10:27:19 +0200 Subject: Using SimpleContext in SimpleMustache's setTemplate, as it reads from a Handle using readU8. We'll switch readU8 to use a Future. --- src/HttpServer.cc | 21 +++++++++++++-------- src/SimpleMustache.cc | 1 + tests/test-Http.cc | 17 ++++++++++++----- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 357bb26..2bc0710 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -83,16 +83,23 @@ class HttpWorker : public Task { Balau::SimpleMustache Balau::HttpWorker::m_errorTemplate; -class SetDefaultTemplate : public Balau::AtStart { - public: - SetDefaultTemplate() : AtStart(0) { } - virtual void doStart(); +namespace { + +class SetDefaultTemplateTask : public Balau::Task { static const Balau::String m_defaultErrorTemplate; + virtual const char * getName() const { return "SetDefaultTemplateTask"; } + virtual void Do() { Balau::HttpWorker::buildErrorTemplate(m_defaultErrorTemplate); } +}; + +class SetDefaultTemplate : public Balau::AtStartAsTask { + public: + SetDefaultTemplate() : AtStartAsTask(0) { } + virtual Balau::Task * createStartTask() { return new SetDefaultTemplateTask(); } }; static SetDefaultTemplate setDefaultTemplate; -const Balau::String SetDefaultTemplate::m_defaultErrorTemplate( +const Balau::String SetDefaultTemplateTask::m_defaultErrorTemplate( "\n" "\n" @@ -116,9 +123,7 @@ const Balau::String SetDefaultTemplate::m_defaultErrorTemplate( "\n" ); -void SetDefaultTemplate::doStart() { - Balau::HttpWorker::buildErrorTemplate(m_defaultErrorTemplate); -} +}; Balau::HttpWorker::HttpWorker(IO io, void * _server) : m_socket(new WriteOnly(io)), m_strm(new BStream(io)) { m_server = (HttpServer *) _server; diff --git a/src/SimpleMustache.cc b/src/SimpleMustache.cc index d2db99f..6f7acdc 100644 --- a/src/SimpleMustache.cc +++ b/src/SimpleMustache.cc @@ -116,6 +116,7 @@ void Balau::SimpleMustache::Context::empty(bool skipFirst) { static const Balau::Regex changing("^(.*) +(.*)$"); void Balau::SimpleMustache::setTemplate(IO _h) { + Task::SimpleContext simpleContext; empty(); IO h(new BStream(_h)); h->detach(); diff --git a/tests/test-Http.cc b/tests/test-Http.cc index cd183ce..1ea040b 100644 --- a/tests/test-Http.cc +++ b/tests/test-Http.cc @@ -25,13 +25,20 @@ const char htmlTemplateStr[] = "\n" ; -class TestHtmlTemplate : public AtStart { - public: - TestHtmlTemplate() : AtStart(10), htmlTemplate(m_template) { } - virtual void doStart() { m_template.setTemplate(htmlTemplateStr); } +class TestHtmlTemplateTask : public Task { + virtual void Do() { m_template.setTemplate(htmlTemplateStr); } + virtual const char * getName() const { return "TestHtmlTemplateTask"; } + SimpleMustache & m_template; +public: + TestHtmlTemplateTask(SimpleMustache & htmlTemplate) : m_template(htmlTemplate) { } +}; +class TestHtmlTemplate : public AtStartAsTask { + public: + TestHtmlTemplate() : AtStartAsTask(10), htmlTemplate(m_template) { } + virtual Task * createStartTask() { return new TestHtmlTemplateTask(m_template); } const SimpleMustache & htmlTemplate; - private: + public: SimpleMustache m_template; }; -- cgit v1.2.3