From cdc5a69a108654ff378839e8cf93669de31ff9c5 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 2 Feb 2008 13:23:00 +0000 Subject: removed libcommon modularized client and server --- INSTALL | 15 +++++----- README | 15 ++++++---- configure.in | 6 ++-- osirion.kdevelop | 22 +++++++-------- osirion.kdevelop.pcs | Bin 217050 -> 235690 bytes osirion.kdevses | 31 ++++++++++++++++---- src/Makefile.am | 13 ++++++++- src/client/Makefile.am | 22 ++++++--------- src/client/console.h | 4 +-- src/client/main.cc | 14 ---------- src/client/video.cc | 2 +- src/client/view.cc | 4 +-- src/core/Makefile.am | 5 ++-- src/core/applicationinterface.cc | 28 ++++++++++++------- src/core/applicationinterface.h | 3 ++ src/filesystem/Makefile.am | 3 +- src/filesystem/file.cc | 2 +- src/filesystem/filesystem.cc | 2 +- src/filesystem/path.cc | 18 +++--------- src/game/Makefile.am | 6 +--- src/game/game.cc | 2 +- src/game/game.h | 2 +- src/gl/Makefile.am | 1 + src/gl/gllib.cc | 2 +- src/server/Makefile.am | 13 ++++----- src/server/application.cc | 14 +++++++++- src/server/application.h | 3 ++ src/server/console.h | 4 +-- src/server/main.cc | 14 ---------- src/server/server.cc | 2 +- src/server/server.h | 2 +- src/sys/Makefile.am | 4 +-- src/sys/consoleinterface.cc | 35 +++++++++++++++++++++++ src/sys/consoleinterface.h | 59 +++++++++++++++++++++++++++++++++++++++ src/sys/sys.cc | 19 +++++++++---- src/sys/sys.h | 10 +++++++ 36 files changed, 263 insertions(+), 138 deletions(-) delete mode 100644 src/client/main.cc delete mode 100644 src/server/main.cc create mode 100644 src/sys/consoleinterface.cc create mode 100644 src/sys/consoleinterface.h diff --git a/INSTALL b/INSTALL index 25bbf54..1ee3364 100644 --- a/INSTALL +++ b/INSTALL @@ -11,16 +11,17 @@ I have succesfully compiled it on the following platforms: Compile the source by executing the following commands: -autoreconf -fi -./configure -make + autoreconf -fi + ./configure + make -To run the program execute: +To run the client program, execute: -src/client/osirion + src/osirion -To run the dedicated server: -src/server/osiriond +To run the dedicated server, execute: + + src/osiriond The game data files should be located in the subdirectory data/base of the main distribution. diff --git a/README b/README index 6f75ff3..0b6a919 100644 --- a/README +++ b/README @@ -17,18 +17,23 @@ Organization of the distribution src/ C++ source code - client\ osirion client - common\ General utility classes - game\ Game engine, used by client and server - gl\ OpenGL library, used by client + math\ mathematical classes + sys\ low-level system functions + filesystem\ virtual filesystem + core\ game-independent core classes + game\ game-specific functions server\ osiriond dedicated server + gl\ OpenGL wrapper library + client\ osirion client data/ Data files base\ main data files License + The program is distributed under the terms and conditions of the GNU General Public License version 2. + Copyright 2007-2008 + Ingar -Ingar diff --git a/configure.in b/configure.in index c7b243a..e4854e4 100644 --- a/configure.in +++ b/configure.in @@ -136,9 +136,9 @@ AC_SUBST(LIBSDL_RPATH) CXXFLAGS="-pipe $DEBUG_CFLAGS $WARN_CFLAGS $CXXFLAGS" AC_SUBST(CXXFLAGS) -AC_OUTPUT(Makefile src/Makefile src/client/Makefile src/common/Makefile \ - src/core/Makefile src/filesystem/Makefile src/game/Makefile src/gl/Makefile src/math/Makefile \ - src/server/Makefile src/sys/Makefile) +AC_OUTPUT(Makefile src/Makefile src/client/Makefile src/core/Makefile \ + src/filesystem/Makefile src/game/Makefile src/gl/Makefile src/math/Makefile src/server/Makefile \ + src/sys/Makefile) AC_MSG_RESULT([ The Osirion Project $VERSION diff --git a/osirion.kdevelop b/osirion.kdevelop index 35ce71d..7032509 100644 --- a/osirion.kdevelop +++ b/osirion.kdevelop @@ -16,12 +16,12 @@ ./ false The OSiRiON Project is an SDL+OpenGL space game. - + kdevsubversion - src/server/osiriond + src/sys/libsys.la debug @@ -37,8 +37,8 @@ - /home/ingar/projects/osirion/debug/./src/game - /home/ingar/projects/osirion/debug/./src/client + /home/ingar/projects/osirion/osirion-work/debug/src/ + /home/ingar/projects/osirion/osirion-work/debug/src/ @@ -81,7 +81,7 @@ false 2 false - + 0 @@ -196,7 +196,7 @@ - + set m_,_ theValue @@ -228,11 +228,11 @@ - - - - - + + + + + true false false diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs index 5a814c9..67d2f75 100644 Binary files a/osirion.kdevelop.pcs and b/osirion.kdevelop.pcs differ diff --git a/osirion.kdevses b/osirion.kdevses index 5fce955..753d24f 100644 --- a/osirion.kdevses +++ b/osirion.kdevses @@ -1,13 +1,34 @@ - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index ad350fc..cd06cd7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,17 @@ # set the include path found by configure AM_CPPFLAGS = $(DEBUG_CFLAGS) $(WARN_CFLAGS) $(all_includes) +INCLUDES = -I$(top_srcdir)/src +SUBDIRS = math sys filesystem core game server gl client -SUBDIRS = math common sys filesystem core game server gl client +noinst_HEADERS = config.h +bin_PROGRAMS = osiriond osirion +# dedicated server +osiriond_SOURCES = osiriond.cc +osiriond_LDADD = $(top_builddir)/src/server/libserver.la +# client +osirion_SOURCES = osirion.cc +osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) +osirion_LDADD = $(top_builddir)/src/client/libclient.la +osirion_LDFLAGS = $(LIBSDL_LIBS) $(GL_LIBS) diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 9807963..f1a3f9d 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -1,17 +1,13 @@ - METASOURCES = AUTO -bin_PROGRAMS = osirion - -osirion_LDADD = $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/common/libcommon.la $(top_builddir)/src/sys/libsys.la \ - $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la \ - $(top_builddir)/src/gl/libgl.la -osirion_SOURCES = application.cc camera.cc client.cc console.cc hud.cc input.cc main.cc \ - shipdrawer.cc stardrawer.cc video.cc view.cc - INCLUDES = -I$(top_srcdir)/src -osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) -osirion_LDFLAGS = $(LIBSDL_LIBS) $(GL_LIBS) +libclient_la_SOURCES = application.cc camera.cc client.cc console.cc hud.cc input.cc \ + shipdrawer.cc stardrawer.cc video.cc view.cc +libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) +libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) +noinst_LTLIBRARIES = libclient.la noinst_HEADERS = application.h camera.h client.h console.h input.h shipdrawer.h stardrawer.h \ - video.h view.h + video.h view.h +libclient_la_LIBADD = $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la \ + $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la $(top_builddir)/src/gl/libgl.la diff --git a/src/client/console.h b/src/client/console.h index 8e8ab02..1a36d00 100644 --- a/src/client/console.h +++ b/src/client/console.h @@ -7,12 +7,12 @@ #ifndef __INCLUDED_CLIENT_CONSOLE_H__ #define __INCLUDED_CLIENT_CONSOLE_H__ -#include "common/consoleinterface.h" +#include "sys/consoleinterface.h" namespace client { /// client console implementation -class Console : public common::ConsoleInterface { +class Console : public sys::ConsoleInterface { public: /// stream to send normal messages too virtual std::ostream & messagestream(); diff --git a/src/client/main.cc b/src/client/main.cc deleted file mode 100644 index 6955042..0000000 --- a/src/client/main.cc +++ /dev/null @@ -1,14 +0,0 @@ -/* client/main.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#include "client/client.h" - -int main( int argc, char *argv[] ) -{ - client::application.init(); - client::application.run(); - client::application.shutdown(); -} - diff --git a/src/client/video.cc b/src/client/video.cc index 9a542f3..ca0401f 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -6,7 +6,7 @@ #include "client/client.h" #include "gl/gllib.h" -#include "common/common.h" +#include "sys/sys.h" #include diff --git a/src/client/view.cc b/src/client/view.cc index 63a6942..30dd6d6 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -9,7 +9,7 @@ #include "client/stardrawer.h" #include "game/game.h" #include "gl/gllib.h" -#include "common/common.h" +#include "sys/sys.h" #include "math/mathlib.h" #include @@ -17,8 +17,6 @@ namespace client { -using namespace common; - ShipDrawer *shipdrawer = 0; StarDrawer *stardrawer = 0; diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 8046b79..a70652e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -2,10 +2,9 @@ METASOURCES = AUTO INCLUDES = -I$(top_srcdir)/src libcore_la_SOURCES = applicationinterface.cc gameinterface.cc -libcore_la_LDFLAGS = -avoid-version +libcore_la_LDFLAGS = -avoid-version -no-undefined libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/common/libcommon.la $(top_builddir)/src/sys/libsys.la \ - $(top_builddir)/src/filesystem/libfilesystem.la + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la noinst_LTLIBRARIES = libcore.la noinst_HEADERS = applicationinterface.h core.h gameinterface.h diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc index ba22d8c..209a4f5 100644 --- a/src/core/applicationinterface.cc +++ b/src/core/applicationinterface.cc @@ -7,17 +7,14 @@ #include "core/core.h" #include "filesystem/filesystem.h" #include "sys/sys.h" -#include "common/common.h" #include - -#include - #include #include namespace core { +// --------------- signal_handler ----------------------------------- extern "C" void signal_handler(int signum) { switch(signum){ @@ -25,24 +22,30 @@ extern "C" void signal_handler(int signum) case SIGINT: case SIGQUIT: case SIGTERM: - con_warn << "received signal " << signum << ", shutting down..." << std::endl; - if (ApplicationInterface::instance()); + if (ApplicationInterface::instance()) { + con_warn << "received signal " << signum << ", shutting down..." << std::endl; ApplicationInterface::instance()->shutdown(); - exit(1); + ApplicationInterface::instance()->quit(0); + } else { + std::cerr << "received signal " << signum << ", no application found, terminated..." << std::endl; + sys::quit(1); + } break; default: - con_warn << "received signal " << signum << ", terminated..." << std::endl; - exit(1); + std::cerr << "received signal " << signum << ", terminated..." << std::endl; + sys::quit(1); break; } } +// --------------- ApplicationInterface ----------------------------- + ApplicationInterface *ApplicationInterface::applicationinterface_instance = 0; ApplicationInterface::ApplicationInterface() { if (applicationinterface_instance) { std::cerr << "multiple singleton instances: core::ApplicationInterface" << std::endl; - exit(2); + sys::quit(2); } applicationinterface_instance = this; @@ -87,6 +90,11 @@ void ApplicationInterface::shutdown() filesystem::shutdown(); } +void ApplicationInterface::quit(int status) +{ + sys::quit(status); +} + void ApplicationInterface::frame(float seconds) { if (game()) diff --git a/src/core/applicationinterface.h b/src/core/applicationinterface.h index 19eaee6..6093427 100644 --- a/src/core/applicationinterface.h +++ b/src/core/applicationinterface.h @@ -24,6 +24,9 @@ public: /// shutdown the application virtual void shutdown(); + /// quit the application + virtual void quit(int status); + /// run a core frame virtual void frame(float seconds); diff --git a/src/filesystem/Makefile.am b/src/filesystem/Makefile.am index 2eb094f..a490cd3 100644 --- a/src/filesystem/Makefile.am +++ b/src/filesystem/Makefile.am @@ -2,8 +2,7 @@ METASOURCES = AUTO libfilesystem_la_SOURCES = file.cc filesystem.cc inifile.cc path.cc libfilesystem_la_LDFLAGS = -avoid-version -no-undefined -libfilesystem_la_LIBADD = $(top_builddir)/src/sys/libsys.la \ - $(top_builddir)/src/common/libcommon.la +libfilesystem_la_LIBADD = $(top_builddir)/src/sys/libsys.la noinst_LTLIBRARIES = libfilesystem.la noinst_HEADERS = file.h filesystem.h inifile.h path.h diff --git a/src/filesystem/file.cc b/src/filesystem/file.cc index 4e68bbd..cd6ae1b 100644 --- a/src/filesystem/file.cc +++ b/src/filesystem/file.cc @@ -5,7 +5,7 @@ */ // project headers -#include "common/common.h" +#include "sys/sys.h" #include "filesystem/filesystem.h" namespace filesystem { diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc index 5ae4da7..b720198 100644 --- a/src/filesystem/filesystem.cc +++ b/src/filesystem/filesystem.cc @@ -6,7 +6,7 @@ // project headers #include "filesystem/filesystem.h" -#include "common/common.h" +#include "sys/sys.h" std::string filesystem::datadir = ""; std::string filesystem::homedir = ""; diff --git a/src/filesystem/path.cc b/src/filesystem/path.cc index ac780c4..c090791 100644 --- a/src/filesystem/path.cc +++ b/src/filesystem/path.cc @@ -6,13 +6,7 @@ // project headers #include "filesystem/path.h" -#include "common/common.h" - -#ifdef _WIN32 -#include -#else -#include -#endif +#include "sys/sys.h" namespace filesystem { @@ -21,14 +15,10 @@ void Path::create(std::string path) { if (tmp[tmp.size()-1] == '/') tmp = tmp.substr(0, tmp.size() - 1); -#ifdef _WIN32 - mkdir(tmp.c_str()); -#else - if (!mkdir(tmp.c_str(), 0777)) - con_warn << "Could not create directory " << tmp << std::endl; + if (!sys::mkdir(tmp.c_str())) + con_warn << "could not create directory " << tmp << std::endl; else - con_debug << "Path created " << tmp << std::endl; -#endif + con_debug << "directory created " << tmp << std::endl; } bool Path::exists(std::string path) { diff --git a/src/game/Makefile.am b/src/game/Makefile.am index 1ed5015..f86c814 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -1,11 +1,7 @@ INCLUDES = -I$(top_srcdir)/src METASOURCES = AUTO -libgame_la_LDFLAGS = -avoid-version --no-undefined -libgame_la_LIBADD = $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/common/libcommon.la \ - $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/core/libcore.la +libgame_la_LDFLAGS = -avoid-version libgame_la_SOURCES = game.cc sector.cc ship.cc shipspecs.cc star.cc noinst_LTLIBRARIES = libgame.la diff --git a/src/game/game.cc b/src/game/game.cc index b2b0822..7f2ad17 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -10,7 +10,7 @@ #include "game/ship.h" #include "game/star.h" #include "filesystem/filesystem.h" -#include "common/common.h" +#include "sys/sys.h" // C++ headers #include diff --git a/src/game/game.h b/src/game/game.h index 5a0afc7..6f77bcf 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -11,7 +11,7 @@ #include "game/ship.h" #include "game/star.h" #include "core/core.h" -#include "common/common.h" +#include "sys/sys.h" /// the game-specific engine /** The main game functions. The console should be initialized before calling these. diff --git a/src/gl/Makefile.am b/src/gl/Makefile.am index 7c1445e..7ddb67b 100644 --- a/src/gl/Makefile.am +++ b/src/gl/Makefile.am @@ -8,3 +8,4 @@ libgl_la_CXXFLAGS = @GL_CFLAGS@ noinst_LTLIBRARIES = libgl.la noinst_HEADERS = box.h gllib.h sphere.h +libgl_la_LIBADD = $(top_builddir)/src/math/libmath.la diff --git a/src/gl/gllib.cc b/src/gl/gllib.cc index e57ab5d..3d3e26c 100644 --- a/src/gl/gllib.cc +++ b/src/gl/gllib.cc @@ -6,7 +6,7 @@ // project includes #include "gl/gllib.h" -#include "common/common.h" +#include "sys/sys.h" // system includes #include "GL/gl.h" diff --git a/src/server/Makefile.am b/src/server/Makefile.am index 729fabf..6875dbf 100644 --- a/src/server/Makefile.am +++ b/src/server/Makefile.am @@ -1,10 +1,9 @@ METASOURCES = AUTO -bin_PROGRAMS = osiriond -osiriond_SOURCES = application.cc console.cc main.cc server.cc timer.cc -osiriond_LDADD = $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/common/libcommon.la $(top_builddir)/src/sys/libsys.la \ - $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la +libserver_la_SOURCES = application.cc console.cc server.cc timer.cc noinst_HEADERS = application.h console.h server.h timer.h - +noinst_LTLIBRARIES = libserver.la INCLUDES = -I$(top_srcdir)/src - +libserver_la_LDFLAGS = -avoid-version -no-undefined +libserver_la_LIBADD = $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la \ + $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la diff --git a/src/server/application.cc b/src/server/application.cc index b6cd91f..0d3fe4b 100644 --- a/src/server/application.cc +++ b/src/server/application.cc @@ -14,6 +14,10 @@ namespace server { void Application::init() { + // FIXME core should be able to load game.so + // force initialization of the game object + server::game = new game::Game(); + // initialize core core::ApplicationInterface::init(); @@ -44,7 +48,15 @@ void Application::shutdown() core::ApplicationInterface::shutdown(); - exit(0); + quit(0); +} + +void Application::quit(int status) +{ + // FIXME core should be able to unload game.so + delete server::game; + + core::ApplicationInterface::quit(status); } } diff --git a/src/server/application.h b/src/server/application.h index c12a608..b081726 100644 --- a/src/server/application.h +++ b/src/server/application.h @@ -22,6 +22,9 @@ public: /// shutdown the server Application virtual void shutdown(); + + /// quit the server Application + virtual void quit(int status); }; } diff --git a/src/server/console.h b/src/server/console.h index 188d2b6..34166be 100644 --- a/src/server/console.h +++ b/src/server/console.h @@ -7,12 +7,12 @@ #ifndef __INCLUDED_SERVER_CONSOLE_H__ #define __INCLUDED_SERVER_CONSOLE_H__ -#include "common/consoleinterface.h" +#include "sys/consoleinterface.h" namespace server { /// server console implementation -class Console : public common::ConsoleInterface { +class Console : public sys::ConsoleInterface { public: /// stream to send normal messages too virtual std::ostream & messagestream(); diff --git a/src/server/main.cc b/src/server/main.cc deleted file mode 100644 index 052c68d..0000000 --- a/src/server/main.cc +++ /dev/null @@ -1,14 +0,0 @@ -/* - server/main.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#include "server/server.h" - -int main( int argc, char *argv[] ) -{ - server::application.init(); - server::application.run(); - server::application.shutdown(); -} diff --git a/src/server/server.cc b/src/server/server.cc index ad8960e..fc37aa6 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -14,7 +14,7 @@ namespace server { Application application; Console console; -game::Game Game; +game::Game *game; } diff --git a/src/server/server.h b/src/server/server.h index 14d1d4b..7871c5f 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -21,7 +21,7 @@ extern Application application; extern Console console; /// global Game instance -extern game::Game game; +extern game::Game *game; } // namespace server 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 + +#include + +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 + +/// 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 +#ifdef _WIN32 + +#include + +#else +#include #include #include +#endif +#include -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__ -- cgit v1.2.3