summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-08-07 17:52:17 +0000
committerrandomdan <randomdan@localhost>2010-08-07 17:52:17 +0000
commit3c0d59a816b8cd360cecbb769286c99ad2ee991f (patch)
treed34ba5a6bcfb0341c4dc365d2508bb9aa54c2486
parentMove CGI code into its own folder (diff)
downloadproject2-3c0d59a816b8cd360cecbb769286c99ad2ee991f.tar.bz2
project2-3c0d59a816b8cd360cecbb769286c99ad2ee991f.tar.xz
project2-3c0d59a816b8cd360cecbb769286c99ad2ee991f.zip
Adds an largely untested console appengine
-rw-r--r--project2/Doxyfile42
-rw-r--r--project2/Jamfile.jam15
-rw-r--r--project2/appEngine.cpp2
-rw-r--r--project2/appEngine.h2
-rw-r--r--project2/cgi/cgiAppEngine.cpp2
-rw-r--r--project2/console/consoleAppEngine.cpp85
-rw-r--r--project2/console/consoleAppEngine.h42
-rw-r--r--project2/console/consoleEnvironment.cpp48
-rw-r--r--project2/console/consoleEnvironment.h24
-rw-r--r--project2/console/p2consoleMain.cpp22
10 files changed, 245 insertions, 39 deletions
diff --git a/project2/Doxyfile b/project2/Doxyfile
index d59538c..e5f9500 100644
--- a/project2/Doxyfile
+++ b/project2/Doxyfile
@@ -196,7 +196,7 @@ ALIASES =
# For instance, some of the names that are used will be different. The list
# of all members will be omitted, etc.
-OPTIMIZE_OUTPUT_FOR_C = NO
+OPTIMIZE_OUTPUT_FOR_C = YES
# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
# sources only. Doxygen will then generate output that is more tailored for
@@ -236,7 +236,7 @@ EXTENSION_MAPPING =
# func(std::string) {}). This also make the inheritance and collaboration
# diagrams that involve STL classes more complete and accurate.
-BUILTIN_STL_SUPPORT = NO
+BUILTIN_STL_SUPPORT = YES
# If you use Microsoft's C++/CLI language, you should set this option to YES to
# enable parsing support.
@@ -256,7 +256,7 @@ SIP_SUPPORT = NO
# setting a simple type. If this is not the case, or you want to show the
# methods anyway, you should set this option to NO.
-IDL_PROPERTY_SUPPORT = YES
+IDL_PROPERTY_SUPPORT = NO
# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
# tag is set to YES, then doxygen will reuse the documentation of the first
@@ -281,7 +281,7 @@ SUBGROUPING = YES
# be useful for C code in case the coding convention dictates that all compound
# types are typedef'ed and only the typedef is referenced, never the tag name.
-TYPEDEF_HIDES_STRUCT = NO
+TYPEDEF_HIDES_STRUCT = Yes
# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
# determine which symbols to keep in memory and which to flush to disk.
@@ -607,43 +607,13 @@ INPUT_ENCODING = UTF-8
# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
-FILE_PATTERNS = *.c \
- *.cc \
- *.cxx \
- *.cpp \
- *.c++ \
- *.d \
- *.java \
- *.ii \
- *.ixx \
- *.ipp \
- *.i++ \
- *.inl \
- *.h \
- *.hh \
- *.hxx \
- *.hpp \
- *.h++ \
- *.idl \
- *.odl \
- *.cs \
- *.php \
- *.php3 \
- *.inc \
- *.m \
- *.mm \
- *.dox \
- *.py \
- *.f90 \
- *.f \
- *.vhd \
- *.vhdl
+FILE_PATTERNS = *.cpp *.h
# The RECURSIVE tag can be used to turn specify whether or not subdirectories
# should be searched for input files as well. Possible values are YES and NO.
# If left blank NO is used.
-RECURSIVE = NO
+RECURSIVE = YES
# The EXCLUDE tag can be used to specify files and/or directories that should
# excluded from the INPUT source files. This way you can easily exclude a
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam
index a57b961..e5633a9 100644
--- a/project2/Jamfile.jam
+++ b/project2/Jamfile.jam
@@ -11,6 +11,7 @@ lib fcgi : : <name>fcgi ;
lib fcgi++ : : <name>fcgi++ ;
lib odbc : : <name>odbc ;
lib boost_regex : : <name>boost_regex ;
+lib boost_filesystem : : <name>boost_filesystem ;
lib cgicc : : <name>cgicc ;
lib esmtp : : <name>esmtp ;
@@ -29,3 +30,17 @@ exe p2web :
<library>cgicc
<library>fcgi++
<library>fcgi ;
+
+exe p2console :
+ libxmlpp
+ libxslt
+ [ glob *.cpp ]
+ [ glob console/*.cpp ]
+ ../libmisc
+ ../libodbcpp :
+ <include>../libmisc/
+ <include>../libodbcpp/
+ <library>boost_regex
+ <library>boost_filesystem
+ <library>odbc
+ <library>esmtp ;
diff --git a/project2/appEngine.cpp b/project2/appEngine.cpp
index be49c10..3961ffe 100644
--- a/project2/appEngine.cpp
+++ b/project2/appEngine.cpp
@@ -3,7 +3,7 @@
ApplicationEngine * ApplicationEngine::currentEngine = NULL;
-ApplicationEngine::ApplicationEngine(const Environment *)
+ApplicationEngine::ApplicationEngine()
{
if (currentEngine) {
throw std::runtime_error("One application at a time, please");
diff --git a/project2/appEngine.h b/project2/appEngine.h
index ab8b588..223a928 100644
--- a/project2/appEngine.h
+++ b/project2/appEngine.h
@@ -13,7 +13,7 @@ class ApplicationEngine {
class DataSourceNotFound : public std::exception { };
class DataSourceNotCompatible : public std::exception { };
- ApplicationEngine(const Environment *);
+ ApplicationEngine();
virtual ~ApplicationEngine() = 0;
virtual void process() const = 0;
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index 5348246..98cb397 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -19,7 +19,7 @@ typedef std::string SValue;
SessionContainer * sessionsContainer = new SessionContainerShm();
CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e) :
- ApplicationEngine(e),
+ ApplicationEngine(),
_env(e),
header(NULL),
sessionID(boost::uuids::nil_generator()())
diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp
new file mode 100644
index 0000000..5955538
--- /dev/null
+++ b/project2/console/consoleAppEngine.cpp
@@ -0,0 +1,85 @@
+#include "consoleAppEngine.h"
+#include "consoleEnvironment.h"
+#include "../iterate.h"
+#include <stdexcept>
+#include <libxml/xinclude.h>
+
+ConsoleApplicationEngine::ConsoleApplicationEngine(const ConsoleEnvironment * env, const boost::filesystem::path & f) :
+ ApplicationEngine()
+{
+ xmlpp::DomParser request(f.string());
+ while (xmlXIncludeProcessFlags(request.get_document()->cobj(), XML_PARSE_NOXINCNODE) > 0);
+ xmlpp::Element * requestRoot = request.get_document()->get_root_node();
+
+ Loaders loaders;
+ _DataSource::AddLoaders(loaders, this->datasources);
+ _ParamChecker::AddLoaders(loaders, parameterChecks);
+ _Task::AddLoaders(loaders, tasks);
+ _Iterate::AddLoaders(loaders, tasks);
+ _LoaderBase::collectAll(loaders, "project2", requestRoot, true, true);
+}
+
+ConsoleApplicationEngine::~ConsoleApplicationEngine()
+{
+}
+
+void
+ConsoleApplicationEngine::process() const
+{
+ BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) {
+ if (!pc.second->performCheck(this)) {
+ throw std::runtime_error("Check failed");
+ }
+ }
+ try {
+ BOOST_FOREACH(NoOutputExecutes::value_type t, tasks) {
+ t.second->execute();
+ }
+ // Commit data source transactions (without invoking a connection)
+ BOOST_FOREACH(DataSources::value_type ds, this->datasources) {
+ ds.second->commit();
+ }
+ }
+ catch (...) {
+ // Do something about the error
+ BOOST_FOREACH(DataSources::value_type ds, this->datasources) {
+ ds.second->rollback();
+ }
+ throw;
+ }
+}
+
+const Environment *
+ConsoleApplicationEngine::env() const
+{
+ return _env;
+}
+
+SessionPtr
+ConsoleApplicationEngine::session() const
+{
+ return SessionPtr();
+}
+
+PresenterPtr
+ConsoleApplicationEngine::getPresenter(const std::string & group, const std::string & id) const
+{
+ return PresenterPtr(new ConsolePresenter(this, group, id));
+}
+
+ConsoleApplicationEngine::ConsolePresenter::ConsolePresenter(const ConsoleApplicationEngine *,
+ const std::string & group, const std::string & id) :
+ Presenter(group, id)
+{
+}
+
+ConsoleApplicationEngine::ConsolePresenter::~ConsolePresenter()
+{
+}
+
+Presenter::XmlDocumentPtr
+ConsoleApplicationEngine::ConsolePresenter::getDataDocument() const
+{
+ return Presenter::getDataDocument();
+}
+
diff --git a/project2/console/consoleAppEngine.h b/project2/console/consoleAppEngine.h
new file mode 100644
index 0000000..7ff1059
--- /dev/null
+++ b/project2/console/consoleAppEngine.h
@@ -0,0 +1,42 @@
+#ifndef CGIAPPENGINE_H
+#define CGIAPPENGINE_H
+
+#include "../appEngine.h"
+#include "../task.h"
+#include "../paramChecker.h"
+#include "../presenter.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/uuid/uuid.hpp>
+#include <boost/filesystem/path.hpp>
+#include <libxml++/document.h>
+#include <libxml++/parsers/domparser.h>
+
+class ConsoleEnvironment;
+class Session;
+
+class ConsoleApplicationEngine : public ApplicationEngine {
+ public:
+ ConsoleApplicationEngine(const ConsoleEnvironment *, const boost::filesystem::path &);
+ virtual ~ConsoleApplicationEngine();
+
+ void process() const;
+ const Environment * env() const;
+ SessionPtr session() const;
+ PresenterPtr getPresenter(const std::string & group, const std::string & id) const;
+ protected:
+ const ConsoleEnvironment * _env;
+ private:
+ class ConsolePresenter : public Presenter {
+ public:
+ ConsolePresenter(const ConsoleApplicationEngine *, const std::string & id);
+ ConsolePresenter(const ConsoleApplicationEngine *, const std::string & group, const std::string & id);
+ virtual ~ConsolePresenter();
+ protected:
+ XmlDocumentPtr getDataDocument() const;
+ };
+ OrderedParamCheckers parameterChecks;
+ NoOutputExecutes tasks;
+};
+
+#endif
+
diff --git a/project2/console/consoleEnvironment.cpp b/project2/console/consoleEnvironment.cpp
new file mode 100644
index 0000000..314f465
--- /dev/null
+++ b/project2/console/consoleEnvironment.cpp
@@ -0,0 +1,48 @@
+#include "consoleEnvironment.h"
+#include <sys/utsname.h>
+#include <syslog.h>
+#include <errno.h>
+#include <string.h>
+
+ConsoleEnvironment::ConsoleEnvironment(int argc, char ** argv) :
+ scriptname(argv[0]),
+ todolist(argv + 1, argv + argc)
+{
+}
+
+ConsoleEnvironment::~ConsoleEnvironment()
+{
+}
+
+Glib::ustring
+ConsoleEnvironment::getParamUri(unsigned int idx) const
+{
+ throw std::runtime_error("Not implemented");
+}
+
+Glib::ustring
+ConsoleEnvironment::getParamQuery(const std::string & idx) const
+{
+ throw std::runtime_error("Not implemented");
+}
+
+std::string
+ConsoleEnvironment::getServerName() const
+{
+ struct utsname name;
+ if (uname(&name)) {
+ syslog(LOG_WARNING, "%s: Unable to determine local host name (%d:%s)",
+ __FUNCTION__, errno, strerror(errno));
+ return "unknown";
+ }
+ else {
+ return name.nodename;
+ }
+}
+
+std::string
+ConsoleEnvironment::getScriptName() const
+{
+ return scriptname;
+}
+
diff --git a/project2/console/consoleEnvironment.h b/project2/console/consoleEnvironment.h
new file mode 100644
index 0000000..faa6431
--- /dev/null
+++ b/project2/console/consoleEnvironment.h
@@ -0,0 +1,24 @@
+#ifndef ENVPROC_H
+#define ENVPROC_H
+
+#include <string>
+#include <list>
+#include <boost/filesystem/path.hpp>
+#include "../environment.h"
+
+class ConsoleEnvironment : public Environment {
+ public:
+ ConsoleEnvironment(int argc, char ** argv);
+ virtual ~ConsoleEnvironment();
+
+ Glib::ustring getParamUri(unsigned int idx) const;
+ Glib::ustring getParamQuery(const std::string & idx) const;
+ std::string getServerName() const;
+ std::string getScriptName() const;
+
+ const std::string scriptname;
+ typedef std::list<boost::filesystem::path> ToDoList;
+ ToDoList todolist;
+};
+
+#endif
diff --git a/project2/console/p2consoleMain.cpp b/project2/console/p2consoleMain.cpp
new file mode 100644
index 0000000..a8d1ffc
--- /dev/null
+++ b/project2/console/p2consoleMain.cpp
@@ -0,0 +1,22 @@
+#include <libxml/tree.h>
+#include "consoleEnvironment.h"
+#include "consoleAppEngine.h"
+#include <iostream>
+
+int main(int argc, char ** argv)
+{
+ ConsoleEnvironment env(argc, argv);
+ BOOST_FOREACH(const boost::filesystem::path & file, env.todolist) {
+ try {
+ ConsoleApplicationEngine app(&env, file);
+ app.process();
+ }
+ catch (const std::exception & e) {
+ std::cerr << "Kaboom!" << std::endl << std::endl << e.what() << std::endl;
+ }
+ catch (...) {
+ std::cerr << "Kaboom!" << std::endl << std::endl << "Unknown exception." << std::endl;
+ }
+ }
+}
+