summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--aclocal.m42
-rwxr-xr-xconfigure3
-rw-r--r--configure.ac1
-rw-r--r--src/Core/ConnectionManager.cpp115
-rw-r--r--src/Core/ConnectionManager.h67
-rw-r--r--src/Core/Makefile.am5
-rw-r--r--src/Core/Makefile.in442
-rw-r--r--src/Makefile.am4
-rw-r--r--src/Makefile.in6
-rw-r--r--src/Net/Connection.cpp6
-rw-r--r--src/Net/Connection.h5
-rw-r--r--src/Net/Listener.cpp19
-rw-r--r--src/Net/Listener.h4
-rw-r--r--src/mad-core.cpp40
14 files changed, 678 insertions, 41 deletions
diff --git a/aclocal.m4 b/aclocal.m4
index b1826ac..cc442ca 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -21,7 +21,7 @@ To do so, use the procedure documented by the package, typically `autoreconf'.])
# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
-# serial 52 Debian 1.5.26-1ubuntu1 AC_PROG_LIBTOOL
+# serial 52 Debian 1.5.26-4 AC_PROG_LIBTOOL
# AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
diff --git a/configure b/configure
index d4929b0..912fc30 100755
--- a/configure
+++ b/configure
@@ -20647,7 +20647,7 @@ fi
# Checks for library functions.
-ac_config_files="$ac_config_files Makefile src/Makefile src/Net/Makefile"
+ac_config_files="$ac_config_files Makefile src/Makefile src/Core/Makefile src/Net/Makefile"
cat >confcache <<\_ACEOF
@@ -21245,6 +21245,7 @@ do
"depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
+ "src/Core/Makefile") CONFIG_FILES="$CONFIG_FILES src/Core/Makefile" ;;
"src/Net/Makefile") CONFIG_FILES="$CONFIG_FILES src/Net/Makefile" ;;
*) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
diff --git a/configure.ac b/configure.ac
index bcd30f2..f859434 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,7 @@ AC_C_CONST
AC_CONFIG_FILES([
Makefile
src/Makefile
+ src/Core/Makefile
src/Net/Makefile
])
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
new file mode 100644
index 0000000..3b99875
--- /dev/null
+++ b/src/Core/ConnectionManager.cpp
@@ -0,0 +1,115 @@
+/*
+ * ConnectionManager.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ConnectionManager.h"
+#include <Net/ServerConnection.h>
+#include <Net/Packet.h>
+#include <Net/Listener.h>
+#include <unistd.h>
+
+#include <iostream>
+
+namespace Mad {
+namespace Core {
+
+void ConnectionManager::refreshPollfds() {
+
+}
+
+void ConnectionManager::daemonReceiveHandler(const Net::Connection*, const Net::Packet &packet) const {
+ std::cout << "Received daemon packet:" << std::endl;
+ std::cout << " Type: " << packet.getType() << std::endl;
+ std::cout << " Request ID: 0x" << std::hex << std::uppercase << packet.getRequestId() << std::dec << std::endl;
+ std::cout << " Length: " << packet.getLength() << std::endl;
+}
+
+void ConnectionManager::clientReceiveHandler(const Net::Connection*, const Net::Packet &packet) const {
+ std::cout << "Received client packet:" << std::endl;
+ std::cout << " Type: " << packet.getType() << std::endl;
+ std::cout << " Request ID: 0x" << std::hex << std::uppercase << packet.getRequestId() << std::dec << std::endl;
+ std::cout << " Length: " << packet.getLength() << std::endl;
+}
+
+ConnectionManager::ConnectionManager() {
+ try {
+ // TODO: Get listener addresses from config
+ listeners.push_back(new Net::Listener(Net::IPAddress("0.0.0.0", 6666)));
+ }
+ catch(Net::Exception &e) {
+ // TODO: Log error
+ }
+}
+
+ConnectionManager::~ConnectionManager() {
+ for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end(); ++con)
+ delete *con;
+
+ for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con)
+ delete *con;
+}
+
+void ConnectionManager::wait(int timeout) {
+ // TODO: wait()
+
+ usleep(timeout);
+}
+
+void ConnectionManager::run() {
+ // TODO: Logging
+
+ for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end();) {
+ if((*con)->isConnected()) {
+ (*con)->sendReceive();
+ ++con;
+ }
+ else {
+ delete *con;
+ daemonConnections.erase(con++);
+ }
+ }
+
+ for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end();) {
+ if((*con)->isConnected()) {
+ (*con)->sendReceive();
+ ++con;
+ }
+ else {
+ delete *con;
+ clientConnections.erase(con++);
+ }
+ }
+
+ for(std::list<Net::Listener*>::iterator listener = listeners.begin(); listener != listeners.end(); ++listener) {
+ Net::ServerConnection *con;
+
+ while((con = (*listener)->getConnection()) != 0) {
+ if(con->isDaemonConnection()) {
+ daemonConnections.push_back(con);
+ con->signalReceive().connect(sigc::mem_fun(this, &ConnectionManager::daemonReceiveHandler));
+ }
+ else {
+ clientConnections.push_back(con);
+ con->signalReceive().connect(sigc::mem_fun(this, &ConnectionManager::clientReceiveHandler));
+ }
+ }
+ }
+}
+
+}
+}
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
new file mode 100644
index 0000000..49c9398
--- /dev/null
+++ b/src/Core/ConnectionManager.h
@@ -0,0 +1,67 @@
+/*
+ * ConnectionManager.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_CONNECTIONMANAGER_H_
+#define MAD_CORE_CONNECTIONMANAGER_H_
+
+#include <list>
+#include <vector>
+#include <poll.h>
+
+namespace Mad {
+
+namespace Net {
+class Listener;
+class Connection;
+class ServerConnection;
+class Packet;
+}
+
+namespace Core {
+
+class ConnectionManager {
+ private:
+ // Prevent shallow copy
+ ConnectionManager(const ConnectionManager &o);
+ ConnectionManager& operator=(const ConnectionManager &o);
+
+ std::list<Net::Listener*> listeners;
+
+ std::list<Net::ServerConnection*> daemonConnections;
+ std::list<Net::ServerConnection*> clientConnections;
+
+ std::vector<struct pollfd> pollfds;
+
+ void refreshPollfds();
+
+ void daemonReceiveHandler(const Net::Connection*, const Net::Packet &packet) const;
+ void clientReceiveHandler(const Net::Connection*, const Net::Packet &packet) const;
+
+ public:
+ ConnectionManager();
+ virtual ~ConnectionManager();
+
+ void wait(int timeout);
+ void run();
+};
+
+}
+}
+
+#endif /*MAD_CORE_CONNECTIONMANAGER_H_*/
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
new file mode 100644
index 0000000..b2a2874
--- /dev/null
+++ b/src/Core/Makefile.am
@@ -0,0 +1,5 @@
+noinst_LTLIBRARIES = libcore.la
+
+libcore_la_SOURCES = ConnectionManager.cpp
+
+noinst_HEADERS = ConnectionManager.h
diff --git a/src/Core/Makefile.in b/src/Core/Makefile.in
new file mode 100644
index 0000000..af39f87
--- /dev/null
+++ b/src/Core/Makefile.in
@@ -0,0 +1,442 @@
+# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = src/Core
+DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
+ $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/src/config.h
+CONFIG_CLEAN_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+libcore_la_LIBADD =
+am_libcore_la_OBJECTS = ConnectionManager.lo
+libcore_la_OBJECTS = $(am_libcore_la_OBJECTS)
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(libcore_la_SOURCES)
+DIST_SOURCES = $(libcore_la_SOURCES)
+HEADERS = $(noinst_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+GREP = @GREP@
+GnuTLS_CFLAGS = @GnuTLS_CFLAGS@
+GnuTLS_LIBS = @GnuTLS_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NMEDIT = @NMEDIT@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sigc_CFLAGS = @sigc_CFLAGS@
+sigc_LIBS = @sigc_LIBS@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+noinst_LTLIBRARIES = libcore.la
+libcore_la_SOURCES = ConnectionManager.cpp
+noinst_HEADERS = ConnectionManager.h
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cpp .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Core/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu src/Core/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+clean-noinstLTLIBRARIES:
+ -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+ @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+libcore.la: $(libcore_la_OBJECTS) $(libcore_la_DEPENDENCIES)
+ $(CXXLINK) $(libcore_la_OBJECTS) $(libcore_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConnectionManager.Plo@am__quote@
+
+.cpp.o:
+@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
+
+.cpp.obj:
+@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cpp.lo:
+@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES) $(HEADERS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-info: install-info-am
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-noinstLTLIBRARIES ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+ pdf pdf-am ps ps-am tags uninstall uninstall-am
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/Makefile.am b/src/Makefile.am
index 1694a4a..a62aeb9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = Net
+SUBDIRS = Core Net
bin_PROGRAMS = mad madc mad-core
@@ -9,4 +9,4 @@ madc_SOURCES = madc.cpp
madc_LDADD = Net/libnet.la
mad_core_SOURCES = mad-core.cpp
-mad_core_LDADD = Net/libnet.la
+mad_core_LDADD = Core/libcore.la Net/libnet.la
diff --git a/src/Makefile.in b/src/Makefile.in
index 362222e..0e5f05b 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -51,7 +51,7 @@ mad_OBJECTS = $(am_mad_OBJECTS)
mad_DEPENDENCIES = Net/libnet.la
am_mad_core_OBJECTS = mad-core.$(OBJEXT)
mad_core_OBJECTS = $(am_mad_core_OBJECTS)
-mad_core_DEPENDENCIES = Net/libnet.la
+mad_core_DEPENDENCIES = Core/libcore.la Net/libnet.la
am_madc_OBJECTS = madc.$(OBJEXT)
madc_OBJECTS = $(am_madc_OBJECTS)
madc_DEPENDENCIES = Net/libnet.la
@@ -196,13 +196,13 @@ sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-SUBDIRS = Net
+SUBDIRS = Core Net
mad_SOURCES = mad.cpp
mad_LDADD = Net/libnet.la
madc_SOURCES = madc.cpp
madc_LDADD = Net/libnet.la
mad_core_SOURCES = mad-core.cpp
-mad_core_LDADD = Net/libnet.la
+mad_core_LDADD = Core/libcore.la Net/libnet.la
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp
index e7be313..4e3fee4 100644
--- a/src/Net/Connection.cpp
+++ b/src/Net/Connection.cpp
@@ -168,5 +168,11 @@ void Connection::disconnect() {
state = DISCONNECTED;
}
+struct pollfd Connection::getPollfd() const {
+ struct pollfd fd = {sock, (receiveComplete() ? 0 : POLLIN) | (sendQueueEmpty() ? 0 : POLLOUT), 0};
+
+ return fd;
+}
+
}
}
diff --git a/src/Net/Connection.h b/src/Net/Connection.h
index 0ef3ebf..0880036 100644
--- a/src/Net/Connection.h
+++ b/src/Net/Connection.h
@@ -23,6 +23,7 @@
#include <queue>
#include <gnutls/gnutls.h>
#include <sigc++/signal.h>
+#include <poll.h>
#include "Packet.h"
namespace Mad {
@@ -125,6 +126,8 @@ class Connection {
void disconnect();
+ struct pollfd getPollfd() const;
+
bool send(const Packet &packet) {
if(!isConnected() || isConnecting())
return false;
@@ -142,7 +145,7 @@ class Connection {
doSend();
}
- bool sendQueueEmpty() {return transS.empty();}
+ bool sendQueueEmpty() const {return transS.empty();}
sigc::signal<void,const Connection*,const Packet&> signalReceive() const {return signal;}
diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp
index 3fb2415..8386389 100644
--- a/src/Net/Listener.cpp
+++ b/src/Net/Listener.cpp
@@ -67,13 +67,32 @@ Listener::Listener(const IPAddress &address0) throw(ConnectionException)
}
Listener::~Listener() {
+ for(std::list<ServerConnection*>::iterator con = connections.begin(); con != connections.end(); ++con) {
+ (*con)->disconnect();
+ delete *con;
+ }
+
shutdown(sock, SHUT_RDWR);
close(sock);
gnutls_dh_params_deinit(dh_params);
}
+std::vector<struct pollfd> Listener::getPollfds() const {
+ std::vector<struct pollfd> pollfds;
+
+ struct pollfd fd = {sock, POLLIN, 0};
+ pollfds.push_back(fd);
+
+ for(std::list<ServerConnection*>::const_iterator con = connections.begin(); con != connections.end(); ++con)
+ pollfds.push_back((*con)->getPollfd());
+
+ return pollfds;
+}
+
ServerConnection* Listener::getConnection() {
+ // TODO: Logging
+
int sd;
struct sockaddr_in sa;
socklen_t addrlen = sizeof(sa);
diff --git a/src/Net/Listener.h b/src/Net/Listener.h
index 5c59a6e..9952268 100644
--- a/src/Net/Listener.h
+++ b/src/Net/Listener.h
@@ -23,7 +23,9 @@
#include "IPAddress.h"
#include "ConnectionException.h"
#include <gnutls/gnutls.h>
+#include <poll.h>
#include <list>
+#include <vector>
namespace Mad {
namespace Net {
@@ -47,6 +49,8 @@ class Listener {
Listener(const IPAddress &address0) throw(ConnectionException);
virtual ~Listener();
+ std::vector<struct pollfd> getPollfds() const;
+
ServerConnection* getConnection();
};
diff --git a/src/mad-core.cpp b/src/mad-core.cpp
index 3ef7a80..ea0eded 100644
--- a/src/mad-core.cpp
+++ b/src/mad-core.cpp
@@ -17,44 +17,18 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "Net/Listener.h"
-#include "Net/ServerConnection.h"
-#include "Net/IPAddress.h"
-#include <iostream>
+#include "Net/Connection.h"
+#include "Core/ConnectionManager.h"
-bool running = true;
-
-void receiveHandler(const Mad::Net::Connection*, const Mad::Net::Packet &packet) {
- std::cout << "Received packet:" << std::endl;
- std::cout << " Type: " << packet.getType() << std::endl;
- std::cout << " Request ID: 0x" << std::hex << std::uppercase << packet.getRequestId() << std::dec << std::endl;
- std::cout << " Length: " << packet.getLength() << std::endl;
-
- running = false;
-}
-
int main() {
Mad::Net::Connection::init();
- try {
- Mad::Net::Listener listener(Mad::Net::IPAddress("0.0.0.0", 6666));
-
- Mad::Net::ServerConnection *connection = 0;
-
- while((connection = listener.getConnection()) == 0)
- usleep(100000);
-
- connection->signalReceive().connect(sigc::ptr_fun(receiveHandler));
-
- while(running)
- connection->sendReceive();
-
- connection->disconnect();
- delete connection;
- }
- catch(Mad::Net::Exception &e) {
- std::cerr << "Connection error: " << e.what() << std::endl;
+ Mad::Core::ConnectionManager connectionManager;
+
+ while(true) {
+ connectionManager.run();
+ connectionManager.wait(100000);
}
Mad::Net::Connection::deinit();