-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyuni-client.cpp
101 lines (81 loc) · 3.48 KB
/
pyuni-client.cpp
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
92
93
94
95
96
97
98
99
100
/**********************************************************************
File name: pyuni-client.cpp
This file is part of: Pythonic Universe
LICENSE
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations under
the License.
Alternatively, the contents of this file may be used under the terms of
the GNU General Public license (the "GPL License"), in which case the
provisions of GPL License are applicable instead of those above.
FEEDBACK & QUESTIONS
For feedback and questions about pyuni please e-mail one of the authors
named in the AUTHORS file.
**********************************************************************/
#include <iostream>
#include <fstream>
#include <cassert>
#include <boost/python.hpp>
#include "CEngine/IO/Log.hpp"
#include "CEngine/IO/FileStream.hpp"
#include "CEngine/IO/StdIOStream.hpp"
#include "CEngine/WindowInterface/Display.hpp"
#include "CEngine/WindowInterface/Window.hpp"
#include "CEngine/WindowInterface/X11/X11Display.hpp"
#include "CEngine/PythonInterface/Package.hpp"
#include "CEngine/PythonInterface/CairoHelpers.hpp"
PyEngine::Display *disp = 0;
int main(int argc, char** argv) {
PyEngine::StreamHandle xmlFile(new PyEngine::FileStream("log.xml", PyEngine::OM_WRITE, PyEngine::WM_OVERWRITE));
PyEngine::log->addSink(PyEngine::LogStdOutSink(PyEngine::All));
PyEngine::log->logf(PyEngine::Debug, "Set up stdout sink");
PyEngine::log->addSink(PyEngine::LogSinkHandle(new PyEngine::LogXMLSink(PyEngine::All & (~PyEngine::Debug), xmlFile, "log.xsl")));
PyEngine::log->logf(PyEngine::Debug, "Set up xml sink");
PyEngine::log->logf(PyEngine::Information, "Log system started up successfully.");
try
{
PyEngine::addCUniToInittab();
Py_Initialize();
PySys_SetArgv(argc, argv);
// this must happen after python was initialized. We're loading
// a module here ;)
PyEngine::setupCairoHelpers();
boost::python::object cuni_window_namespace = boost::python::import("_cuni_window").attr("__dict__");
boost::python::object cuni_log_namespace = boost::python::import("_cuni_log").attr("__dict__");
boost::python::object main_namespace = boost::python::import("__main__").attr("__dict__");
// FIXME: Is this possible without explizit reference to the
// platform?
// Boost needs the explicit type for casting, but it would be
// nice to force it somehow to do the right thing.
PyEngine::X11Display *x11 = new PyEngine::X11Display();
disp = x11;
cuni_window_namespace["display"] = x11;
cuni_log_namespace["server"] = PyEngine::logHandle;
std::string str;
{
std::stringstream s;
std::ifstream main("py-universe.py");
s << main.rdbuf();
main.close();
str = std::string(s.str());
}
exec(str.c_str(), main_namespace);
delete PyEngine::log;
}
catch (boost::python::error_already_set const&)
{
delete PyEngine::log;
PyErr_Print();
return 1;
}
return 0;
}
// Local Variables:
// c-file-style: "k&r"
// c-basic-offset: 4
// End: