summaryrefslogtreecommitdiff
path: root/project2/console/consoleAppEngine.cpp
blob: 83ab311fc68a0511afb7d7135c4582df75d01f31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <pch.hpp>
#include <glibmm/exception.h>
#include <cxxabi.h>
#include "consoleAppEngine.h"
#include "consoleEnvironment.h"
#include "safeMapFind.h"
#include "iterate.h"
#include "xmlObjectLoader.h"
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include <iostream>

SimpleMessageException(UnknownPlatformAlias);

ConsoleApplicationEngine::ConsoleApplicationEngine(const ConsoleEnvironment * env, const boost::filesystem::path & f) :
	XmlScriptParser(f, false),
	SourceObject(get_document()->get_root_node()),
	CheckHost(f),
	ApplicationEngine("console/environment"),
	TaskHost(f),
	ViewHost(f),
	_env(env),
	runtime(new Session(UUID::generate_random()))
{
}

ConsoleApplicationEngine::~ConsoleApplicationEngine()
{
}

void
onCheckFailureHelper(boost::intrusive_ptr<const ParamChecker> pc)
{
	throw std::runtime_error(pc->message());
}

void
ConsoleApplicationEngine::process() const
{
	try {
		runChecks();
		execute();
		executeViews(boost::bind(&PresenterLoader::createFrom, LoaderBase::getLoader<PresenterLoader, NotSupported>("console"), _1));
		addAppData(presenter.get());
	}
	catch (const std::exception & e) {
		char * buf = __cxxabiv1::__cxa_demangle(typeid(e).name(), NULL, NULL, NULL);
		Logger()->messagef(LOG_ERR, "%s: Script errored: %s: %s", __FUNCTION__, buf, e.what());
		free(buf);
	}
	catch (const Glib::Exception & e) {
		char * buf = __cxxabiv1::__cxa_demangle(typeid(e).name(), NULL, NULL, NULL);
		Logger()->messagef(LOG_ERR, "%s: Script errored: %s: %s", __FUNCTION__, buf, e.what().c_str());
		free(buf);
	}
}

const Environment *
ConsoleApplicationEngine::env() const
{
	return _env;
}

SessionPtr
ConsoleApplicationEngine::session() const
{
	return runtime;
}

void
ConsoleApplicationEngine::addEnvData(const MultiRowSetPresenter *) const
{
}

void
ConsoleApplicationEngine::addAppData(const MultiRowSetPresenter *) const
{
}

Glib::ustring
ConsoleApplicationEngine::resolveCurrentConfig() const
{
	return safeMapLookup<UnknownPlatformAlias>(conplat, _env->getPlatform());
}

void
ConsoleApplicationEngine::loadEngineSection(const xmlpp::Element * e) const
{
	conplat.insert(ConsolePlatforms::value_type(e->get_attribute_value("setting"), e->get_attribute_value("platform")));
}