Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/Makefile.am4
-rw-r--r--src/sys/consoleinterface.cc35
-rw-r--r--src/sys/consoleinterface.h59
-rw-r--r--src/sys/sys.cc19
-rw-r--r--src/sys/sys.h10
5 files changed, 119 insertions, 8 deletions
diff --git a/src/sys/Makefile.am b/src/sys/Makefile.am
index 44f69c4..be1c636 100644
--- a/src/sys/Makefile.am
+++ b/src/sys/Makefile.am
@@ -2,5 +2,5 @@ INCLUDES = -I$(top_srcdir)/src
METASOURCES = AUTO
libsys_la_LDFLAGS = -avoid-version -no-undefined
noinst_LTLIBRARIES = libsys.la
-libsys_la_SOURCES = sys.cc
-noinst_HEADERS = sys.h
+libsys_la_SOURCES = consoleinterface.cc sys.cc
+noinst_HEADERS = consoleinterface.h sys.h
diff --git a/src/sys/consoleinterface.cc b/src/sys/consoleinterface.cc
new file mode 100644
index 0000000..45df367
--- /dev/null
+++ b/src/sys/consoleinterface.cc
@@ -0,0 +1,35 @@
+/*
+ sys/consoleinterface.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "sys/consoleinterface.h"
+
+#include <iostream>
+
+#include <stdlib.h>
+
+namespace sys {
+
+ConsoleInterface *ConsoleInterface::consoleinterface_instance = 0;
+
+ConsoleInterface::ConsoleInterface() {
+ if (consoleinterface_instance) {
+ std::cerr << "multiple singleton instances: sys::ConsoleInterface" << std::endl;
+ sys::quit(2);
+ }
+ consoleinterface_instance = this;
+}
+
+ConsoleInterface::~ConsoleInterface()
+{
+ consoleinterface_instance = 0;
+}
+
+ConsoleInterface *ConsoleInterface::instance()
+{
+ return consoleinterface_instance;
+}
+
+} // namespace sys
diff --git a/src/sys/consoleinterface.h b/src/sys/consoleinterface.h
new file mode 100644
index 0000000..e0228ae
--- /dev/null
+++ b/src/sys/consoleinterface.h
@@ -0,0 +1,59 @@
+/*
+ sys/consoleinterface.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2.
+*/
+
+#ifndef __INCLUDED_SYS_CONSOLEINTERFACE_H__
+#define __INCLUDED_SYS_CONSOLEINTERFACE_H__
+
+// project headers
+#include "sys/sys.h"
+
+// C++ headers
+#include <iostream>
+
+/// global define to send a message to the system console
+#define con_print sys::ConsoleInterface::instance()->messagestream()
+/// global define to send a warning message to the system console
+#define con_warn sys::ConsoleInterface::instance()->warningstream()
+
+#ifdef HAVE_DEBUG_MESSAGES
+/// global define to send a debug message to the system console
+#define con_debug sys::ConsoleInterface::instance()->debugstream()
+#else
+#define con_debug if (0) *(std::ostream*)(0)
+#endif
+
+namespace sys {
+
+/// interface for the client and server Console classes
+class ConsoleInterface {
+public:
+ /// default constructor
+ ConsoleInterface();
+
+ /// default destructor
+ virtual ~ConsoleInterface();
+
+ /// stream to send normal messages too
+ virtual std::ostream & messagestream() = 0;
+
+ /// stream to send warning messages too
+ virtual std::ostream & warningstream() = 0;
+
+ /// stream to send debug messages too
+ virtual std::ostream & debugstream() = 0;
+
+ /// a pointer to the current console instance
+ static ConsoleInterface *instance();
+
+private:
+ /// console singleton
+ static ConsoleInterface *consoleinterface_instance;
+};
+
+} // namespace sys
+
+#endif // __INCLUDED_SYS_CONSOLEINTERFACE_H__
+
diff --git a/src/sys/sys.cc b/src/sys/sys.cc
index 97da23e..dc342bd 100644
--- a/src/sys/sys.cc
+++ b/src/sys/sys.cc
@@ -8,15 +8,20 @@
#include "sys/sys.h"
// system headers
-#include <signal.h>
+#ifdef _WIN32
+
+#include <dlfcn.h>
+
+#else
+#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
+#endif
+#include <stdlib.h>
-namespace sys {
-
-bool mkdir(const char *path)
+bool sys::mkdir(const char *path)
{
#ifdef _WIN32
::mkdir(path);
@@ -27,7 +32,7 @@ bool mkdir(const char *path)
#endif
}
-void signal(int signum, signalfunc handler)
+void sys::signal(int signum, signalfunc handler)
{
#ifndef _WIN32
struct sigaction sa;
@@ -35,8 +40,10 @@ void signal(int signum, signalfunc handler)
sa.sa_handler = handler;
sa.sa_flags = 0;
- sigaction(signum, &sa, 0);
+ ::sigaction(signum, &sa, 0);
#endif
}
+void sys::quit(int status) {
+ exit(status);
}
diff --git a/src/sys/sys.h b/src/sys/sys.h
index 0d05b67..86642e5 100644
--- a/src/sys/sys.h
+++ b/src/sys/sys.h
@@ -7,13 +7,23 @@
#ifndef __INCLUDED_SYS_H__
#define __INCLUDED_SYS_H__
+#include "config.h"
+
/// contains operating system dependent functions
namespace sys {
typedef void (* signalfunc)(int signum);
+ /// create a directory
bool mkdir(const char *path);
+ /// intercept OS signals
void signal(int signum, signalfunc handler);
+ /// quit
+ /** @param status return value
+ */
+ void quit(int status);
}
+#include "sys/consoleinterface.h"
+
#endif // __INCLUDED_SYS_H__