summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-03-08 12:57:36 +0000
committerrandomdan <randomdan@localhost>2011-03-08 12:57:36 +0000
commite1ffe0d64996af3110ea5b6c8b677682381d2ba9 (patch)
treea153976de624b099694618f0286a285613e14085
parentFix inheritance of If (diff)
downloadproject2-e1ffe0d64996af3110ea5b6c8b677682381d2ba9.tar.bz2
project2-e1ffe0d64996af3110ea5b6c8b677682381d2ba9.tar.xz
project2-e1ffe0d64996af3110ea5b6c8b677682381d2ba9.zip
Split appData and envData
Add appData to all presenters, add envData to the final cgi stage if it is a presenter Add timing info to appData
-rw-r--r--project2/appEngine.h1
-rw-r--r--project2/cgi/cgiAppEngine.cpp26
-rw-r--r--project2/cgi/cgiAppEngine.h3
-rw-r--r--project2/console/consoleAppEngine.cpp10
-rw-r--r--project2/console/consoleAppEngine.h1
-rw-r--r--project2/presenter.cpp4
6 files changed, 38 insertions, 7 deletions
diff --git a/project2/appEngine.h b/project2/appEngine.h
index 2921b2d..a9df07e 100644
--- a/project2/appEngine.h
+++ b/project2/appEngine.h
@@ -15,6 +15,7 @@ class ApplicationEngine : public Configuration {
virtual const Environment * env() const = 0;
virtual SessionPtr session() const = 0;
virtual void addAppData(const Presenter * p) const = 0;
+ virtual void addEnvData(const Presenter * p) const = 0;
static ApplicationEngine * getCurrent() { return currentEngine; }
private:
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index d8c667a..e8c23e5 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -10,6 +10,7 @@
#include <boost/foreach.hpp>
#include "../sessionXml.h"
#include <cxxabi.h>
+#include <boost/date_time/microsec_time_clock.hpp>
const std::string SESSIONID = "sessionID";
typedef UUID SIDKey;
@@ -108,6 +109,7 @@ CgiApplicationEngine::write(std::ostream & IO) const
void
CgiApplicationEngine::process() const
{
+ startTime = boost::date_time::microsec_clock<boost::posix_time::ptime>::universal_time();
try {
for (StagePtr nextStage; (nextStage = currentStage->run()); ) {
currentStage = nextStage;
@@ -119,6 +121,11 @@ CgiApplicationEngine::process() const
catch (const std::exception & ex) {
currentStage = new ErrorStage(_env, ex);
}
+ endTime = boost::date_time::microsec_clock<boost::posix_time::ptime>::universal_time();
+ const Presenter * p = boost::dynamic_pointer_cast<const Presenter>(currentStage).get();
+ if (p) {
+ addAppData(p);
+ }
}
CgiApplicationEngine::Stage::Stage()
@@ -165,8 +172,12 @@ CgiApplicationEngine::PresentStage::getDataDocument() const
}
void
-CgiApplicationEngine::addAppData(const Presenter * p) const
+CgiApplicationEngine::addEnvData(const Presenter * p) const
{
+ // These were for debug... but why not pass them on?
+ p->addField("servername", "project2", env()->getServerName());
+ p->addField("scriptname", "project2", env()->getScriptName());
+
// URL elements
p->pushSub("uriElems", "project2");
BOOST_FOREACH(std::string s, _env->elems) {
@@ -183,7 +194,11 @@ CgiApplicationEngine::addAppData(const Presenter * p) const
p->popSub();
}
p->popSub();
+}
+void
+CgiApplicationEngine::addAppData(const Presenter * p) const
+{
// Sessions variables
if (!sessionID.is_nil()) {
p->pushSub("session", "project2");
@@ -197,6 +212,15 @@ CgiApplicationEngine::addAppData(const Presenter * p) const
}
p->popSub();
}
+
+ // Timing info
+ p->pushSub("timing", "project2");
+ p->addAttr("start", startTime);
+ if (!endTime.is_not_a_date_time()) {
+ p->addAttr("end", endTime);
+ p->addAttr("duration", (endTime - startTime).total_milliseconds());
+ }
+ p->popSub();
}
CgiApplicationEngine::RequestStage::RequestStage(const std::string & id)
diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h
index 65142b6..cfab7c4 100644
--- a/project2/cgi/cgiAppEngine.h
+++ b/project2/cgi/cgiAppEngine.h
@@ -33,9 +33,12 @@ class CgiApplicationEngine : public ApplicationEngine {
SessionPtr session() const;
virtual Glib::ustring resolveCurrentConfig() const;
void addAppData(const Presenter * p) const;
+ void addEnvData(const Presenter * p) const;
const CgiEnvironment * _env;
private:
+ mutable boost::posix_time::ptime startTime;
+ mutable boost::posix_time::ptime endTime;
typedef std::pair<Glib::ustring, Glib::ustring> DomainPlatform;
typedef std::list<DomainPlatform> DomainPlatforms;
mutable DomainPlatforms domplat;
diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp
index d5e2bf6..a45f704 100644
--- a/project2/console/consoleAppEngine.cpp
+++ b/project2/console/consoleAppEngine.cpp
@@ -85,9 +85,8 @@ ConsoleApplicationEngine::process() const
}
}
RequestHost::run();
- BOOST_FOREACH(const Views::value_type & v, views) {
- v->execute(this);
- }
+ Presenter::execute();
+ addAppData(this);
}
const Environment *
@@ -103,6 +102,11 @@ ConsoleApplicationEngine::session() const
}
void
+ConsoleApplicationEngine::addEnvData(const Presenter *) const
+{
+}
+
+void
ConsoleApplicationEngine::addAppData(const Presenter *) const
{
}
diff --git a/project2/console/consoleAppEngine.h b/project2/console/consoleAppEngine.h
index 1e4f1c3..b7b4f1d 100644
--- a/project2/console/consoleAppEngine.h
+++ b/project2/console/consoleAppEngine.h
@@ -25,6 +25,7 @@ class ConsoleApplicationEngine : public ApplicationEngine, public Presenter, Req
SessionPtr session() const;
virtual Glib::ustring resolveCurrentConfig() const;
virtual void addAppData(const Presenter * p) const;
+ virtual void addEnvData(const Presenter * p) const;
protected:
const ConsoleEnvironment * _env;
diff --git a/project2/presenter.cpp b/project2/presenter.cpp
index 11f2996..73a6cfa 100644
--- a/project2/presenter.cpp
+++ b/project2/presenter.cpp
@@ -19,9 +19,7 @@ Presenter::execute() const
}
// These were for debug... but why not pass them on?
ApplicationEngine * appEngine = ApplicationEngine::getCurrent();
- addField("servername", "project2", appEngine->env()->getServerName());
- addField("scriptname", "project2", appEngine->env()->getScriptName());
- appEngine->addAppData(this);
+ appEngine->addEnvData(this);
}
void