Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-02 11:09:04 +0000
committerStijn Buys <ingar@osirion.org>2008-02-02 11:09:04 +0000
commit365b0c6330ea607706b708d92da7a46b1ed1fb15 (patch)
tree67e8136d48e8e7f0c5bdc17b4a2c284dcf202641 /src
parent6c8446cddb37df732fc9e5fc21f98e31968ce634 (diff)
introduced libsys
implemented signal handling
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client/Makefile.am6
-rw-r--r--src/client/input.cc4
-rw-r--r--src/common/common.h2
-rw-r--r--src/core/Makefile.am2
-rw-r--r--src/core/applicationinterface.cc30
-rw-r--r--src/filesystem/Makefile.am3
-rw-r--r--src/server/Makefile.am6
-rw-r--r--src/sys/Makefile.am6
-rw-r--r--src/sys/sys.cc42
-rw-r--r--src/sys/sys.h19
11 files changed, 108 insertions, 14 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ab95099..ad350fc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
# set the include path found by configure
AM_CPPFLAGS = $(DEBUG_CFLAGS) $(WARN_CFLAGS) $(all_includes)
-SUBDIRS = math common filesystem core game server gl client
+SUBDIRS = math common sys filesystem core game server gl client
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index e191f5f..9807963 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -3,10 +3,8 @@ METASOURCES = AUTO
bin_PROGRAMS = osirion
osirion_LDADD = $(top_builddir)/src/math/libmath.la \
- $(top_builddir)/src/common/libcommon.la \
- $(top_builddir)/src/filesystem/libfilesystem.la \
- $(top_builddir)/src/core/libcore.la \
- $(top_builddir)/src/game/libgame.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
diff --git a/src/client/input.cc b/src/client/input.cc
index 5f38d35..3e37a19 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -46,7 +46,7 @@ void Input::handle_keypressed(SDL_keysym* keysym)
{
switch( keysym->sym ) {
case SDLK_ESCAPE:
- client::application.shutdown();
+ application.shutdown();
break;
case SDLK_LEFT:
camera.rotate_left();
@@ -91,7 +91,7 @@ void Input::process()
handle_keyreleased( &event.key.keysym );
break;
case SDL_QUIT:
- client::application.shutdown();
+ application.shutdown();
break;
}
diff --git a/src/common/common.h b/src/common/common.h
index 61aa47c..2fdec9d 100644
--- a/src/common/common.h
+++ b/src/common/common.h
@@ -10,6 +10,8 @@
#include "config.h"
/// common functions and components that can be use by any subsytem
+/** libcommon has no dependencies
+ */
namespace common {}
#include "common/consoleinterface.h"
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index b062f9e..8046b79 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -4,7 +4,7 @@ INCLUDES = -I$(top_srcdir)/src
libcore_la_SOURCES = applicationinterface.cc gameinterface.cc
libcore_la_LDFLAGS = -avoid-version
libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \
- $(top_builddir)/src/common/libcommon.la \
+ $(top_builddir)/src/common/libcommon.la $(top_builddir)/src/sys/libsys.la \
$(top_builddir)/src/filesystem/libfilesystem.la
noinst_LTLIBRARIES = libcore.la
diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc
index 9ef5c16..ba22d8c 100644
--- a/src/core/applicationinterface.cc
+++ b/src/core/applicationinterface.cc
@@ -6,14 +6,37 @@
#include "core/core.h"
#include "filesystem/filesystem.h"
+#include "sys/sys.h"
#include "common/common.h"
#include <iostream>
#include <stdlib.h>
+#include <errno.h>
+#include <signal.h>
+
namespace core {
+extern "C" void signal_handler(int signum)
+{
+ switch(signum){
+ case SIGHUP:
+ case SIGINT:
+ case SIGQUIT:
+ case SIGTERM:
+ con_warn << "received signal " << signum << ", shutting down..." << std::endl;
+ if (ApplicationInterface::instance());
+ ApplicationInterface::instance()->shutdown();
+ exit(1);
+ break;
+ default:
+ con_warn << "received signal " << signum << ", terminated..." << std::endl;
+ exit(1);
+ break;
+ }
+}
+
ApplicationInterface *ApplicationInterface::applicationinterface_instance = 0;
ApplicationInterface::ApplicationInterface() {
@@ -22,6 +45,11 @@ ApplicationInterface::ApplicationInterface() {
exit(2);
}
applicationinterface_instance = this;
+
+ sys::signal(SIGHUP, signal_handler);
+ sys::signal(SIGINT, signal_handler);
+ sys::signal(SIGQUIT, signal_handler);
+ sys::signal(SIGTERM, signal_handler);
}
ApplicationInterface::~ApplicationInterface()
@@ -29,7 +57,7 @@ ApplicationInterface::~ApplicationInterface()
applicationinterface_instance = 0;
}
-ApplicationInterface *ApplicationInterface::instance()
+ApplicationInterface *ApplicationInterface::instance()
{
return applicationinterface_instance;
}
diff --git a/src/filesystem/Makefile.am b/src/filesystem/Makefile.am
index c072b02..2eb094f 100644
--- a/src/filesystem/Makefile.am
+++ b/src/filesystem/Makefile.am
@@ -2,7 +2,8 @@ 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/common/libcommon.la
+libfilesystem_la_LIBADD = $(top_builddir)/src/sys/libsys.la \
+ $(top_builddir)/src/common/libcommon.la
noinst_LTLIBRARIES = libfilesystem.la
noinst_HEADERS = file.h filesystem.h inifile.h path.h
diff --git a/src/server/Makefile.am b/src/server/Makefile.am
index c8695ca..729fabf 100644
--- a/src/server/Makefile.am
+++ b/src/server/Makefile.am
@@ -2,10 +2,8 @@ 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/filesystem/libfilesystem.la \
- $(top_builddir)/src/core/libcore.la \
- $(top_builddir)/src/game/libgame.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
noinst_HEADERS = application.h console.h server.h timer.h
INCLUDES = -I$(top_srcdir)/src
diff --git a/src/sys/Makefile.am b/src/sys/Makefile.am
new file mode 100644
index 0000000..44f69c4
--- /dev/null
+++ b/src/sys/Makefile.am
@@ -0,0 +1,6 @@
+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
diff --git a/src/sys/sys.cc b/src/sys/sys.cc
new file mode 100644
index 0000000..97da23e
--- /dev/null
+++ b/src/sys/sys.cc
@@ -0,0 +1,42 @@
+/*
+ sys/sys.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+// project headers
+#include "sys/sys.h"
+
+// system headers
+#include <signal.h>
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+
+namespace sys {
+
+bool mkdir(const char *path)
+{
+#ifdef _WIN32
+ ::mkdir(path);
+ // FIXME check return value
+ return true;
+#else
+ return (::mkdir(path, 0777) == 0);
+#endif
+}
+
+void signal(int signum, signalfunc handler)
+{
+#ifndef _WIN32
+ struct sigaction sa;
+
+ sa.sa_handler = handler;
+ sa.sa_flags = 0;
+
+ sigaction(signum, &sa, 0);
+#endif
+}
+
+}
diff --git a/src/sys/sys.h b/src/sys/sys.h
new file mode 100644
index 0000000..0d05b67
--- /dev/null
+++ b/src/sys/sys.h
@@ -0,0 +1,19 @@
+/*
+ sys/sys.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_H__
+#define __INCLUDED_SYS_H__
+
+/// contains operating system dependent functions
+namespace sys {
+ typedef void (* signalfunc)(int signum);
+
+ bool mkdir(const char *path);
+ void signal(int signum, signalfunc handler);
+}
+
+#endif // __INCLUDED_SYS_H__
+