summaryrefslogtreecommitdiff
path: root/src/Main.cc
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-12-04 01:19:09 -0800
committerPixel <pixel@nobis-crew.org>2011-12-04 01:20:10 -0800
commitd440c3f50a918a932293ad98bcec96eaa4683222 (patch)
tree33e8e42a8e4506ae9da70cdb44dd133bde7f7219 /src/Main.cc
parente5577eb7a643ce7885e5d14660a6d24254161622 (diff)
Reworked some things in the architecture, mainly exceptions and asserts.
-) Removed Assert() -) Added AAssert(), IAssert(), RAssert(), TAssert() and Failure() -) Reworked all asserts in the code, and added meaningful messages to them. -) Changed the way the startup code is generated; BALAU_STARTUP is no longer necessary.
Diffstat (limited to 'src/Main.cc')
-rw-r--r--src/Main.cc85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/Main.cc b/src/Main.cc
index eb5e589..d42a1a5 100644
--- a/src/Main.cc
+++ b/src/Main.cc
@@ -1,4 +1,7 @@
#include "Main.h"
+#include "TaskMan.h"
+#include "Printer.h"
+#include "AtStartExit.h"
Balau::AtStart * Balau::AtStart::s_head = 0;
Balau::AtExit * Balau::AtExit::s_head = 0;
@@ -6,6 +9,7 @@ Balau::AtExit * Balau::AtExit::s_head = 0;
Balau::AtStart::AtStart(int priority) : m_priority(priority) {
if (priority < 0)
return;
+ AAssert(!Main::hasMain(), "An AtStart can't be created dynamically");
AtStart ** ptr = &s_head;
@@ -20,6 +24,7 @@ Balau::AtStart::AtStart(int priority) : m_priority(priority) {
Balau::AtExit::AtExit(int priority) : m_priority(priority) {
if (priority < 0)
return;
+ AAssert(!Main::hasMain(), "An AtExit can't be created dynamically");
AtExit ** ptr = &s_head;
@@ -32,3 +37,83 @@ Balau::AtExit::AtExit(int priority) : m_priority(priority) {
}
Balau::Main * Balau::Main::s_application = NULL;
+
+Balau::MainTask::~MainTask() {
+ if (m_stopTaskManOnExit)
+ TaskMan::stop(0);
+}
+
+const char * Balau::MainTask::getName() {
+ return "Main Task";
+}
+
+int Balau::Main::bootstrap(int _argc, char ** _argv) {
+ int r = 0;
+ m_status = STARTING;
+
+ argc = _argc;
+ argv = _argv;
+ enve = NULL;
+
+ for (AtStart * ptr = AtStart::s_head; ptr; ptr = ptr->m_next)
+ ptr->doStart();
+
+ try {
+ m_status = RUNNING;
+ MainTask * mainTask = createTask(new MainTask());
+ r = TaskMan::getDefaultTaskMan()->mainLoop();
+ m_status = STOPPING;
+ }
+ catch (Exit e) {
+ m_status = STOPPING;
+ Printer::log(M_ERROR, "We shouldn't have gotten an Exit exception here... exitting anyway");
+ std::vector<String> trace = e.getTrace();
+ for (std::vector<String>::iterator i = trace.begin(); i != trace.end(); i++)
+ Printer::log(M_ERROR, "%s", i->to_charp());
+ r = e.getCode();
+ }
+ catch (RessourceException e) {
+ m_status = STOPPING;
+ Printer::log(M_ERROR | M_ALERT, "The application got a ressource problem: %s", e.getMsg());
+ const char * details = e.getDetails();
+ if (details)
+ Printer::log(M_ERROR, " %s", details);
+ std::vector<String> trace = e.getTrace();
+ for (std::vector<String>::iterator i = trace.begin(); i != trace.end(); i++)
+ Printer::log(M_DEBUG, "%s", i->to_charp());
+ r = -1;
+ }
+ catch (GeneralException e) {
+ m_status = STOPPING;
+ Printer::log(M_ERROR | M_ALERT, "The application caused an exception: %s", e.getMsg());
+ const char * details = e.getDetails();
+ if (details)
+ Printer::log(M_ERROR, " %s", details);
+ std::vector<String> trace = e.getTrace();
+ for (std::vector<String>::iterator i = trace.begin(); i != trace.end(); i++)
+ Printer::log(M_DEBUG, "%s", i->to_charp());
+ r = -1;
+ }
+ catch (...) {
+ m_status = STOPPING;
+ Printer::log(M_ERROR | M_ALERT, "The application caused an unknown exception");
+ r = -1;
+ }
+ m_status = STOPPING;
+
+ for (AtExit * ptr = AtExit::s_head; ptr; ptr = ptr->m_next)
+ ptr->doExit();
+
+ m_status = STOPPED;
+ return r;
+}
+
+extern "C" {
+
+int main(int argc, char ** argv) {
+ setlocale(LC_ALL, "");
+ Balau::Main mainClass;
+ return mainClass.bootstrap(argc, argv);
+}
+
+};