summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i/simulotron/configure.ac1
-rw-r--r--i/simulotron/doc/Doxyfile269
-rw-r--r--i/simulotron/doc/Makefile15
-rw-r--r--i/simulotron/doc/Makefile.am0
-rw-r--r--i/simulotron/src/Makefile.am4
-rw-r--r--i/simulotron/src/comc/Makefile.incl.am12
-rw-r--r--i/simulotron/src/comc/comc.cc (renamed from i/simulotron/src/comc/comc.tcc)39
-rw-r--r--i/simulotron/src/comc/comc.hh20
-rw-r--r--i/simulotron/src/comc/send.tcc40
-rw-r--r--i/simulotron/src/comc/struct_message.hh79
-rw-r--r--i/simulotron/src/comc/test_comc.cc107
-rw-r--r--i/simulotron/src/comc/test_comc_struct.hh37
-rw-r--r--i/simulotron/src/gs/gs_message.cc9
-rw-r--r--i/simulotron/src/gs/gs_message.hh4
-rw-r--r--i/simulotron/src/gs/test_gs.cc16
-rw-r--r--i/simulotron/src/hub/hub.cc139
-rw-r--r--i/simulotron/src/hub/hub.hh39
17 files changed, 698 insertions, 132 deletions
diff --git a/i/simulotron/configure.ac b/i/simulotron/configure.ac
index 448cfa5..5fdfd07 100644
--- a/i/simulotron/configure.ac
+++ b/i/simulotron/configure.ac
@@ -29,6 +29,5 @@ AC_CHECK_FUNCS([gethostbyaddr gethostbyname inet_ntoa socket strerror])
AC_CONFIG_FILES([Makefile
- doc/Makefile
src/Makefile])
AC_OUTPUT
diff --git a/i/simulotron/doc/Doxyfile b/i/simulotron/doc/Doxyfile
new file mode 100644
index 0000000..581c418
--- /dev/null
+++ b/i/simulotron/doc/Doxyfile
@@ -0,0 +1,269 @@
+# Doxyfile 1.4.2
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME = "Simulotron"
+PROJECT_NUMBER = 2006.0.01
+OUTPUT_DIRECTORY = .
+CREATE_SUBDIRS = NO
+OUTPUT_LANGUAGE = French
+USE_WINDOWS_ENCODING = NO
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH = .
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = YES
+MULTILINE_CPP_IS_BRIEF = NO
+DETAILS_AT_TOP = NO
+INHERIT_DOCS = YES
+DISTRIBUTE_GROUP_DOC = NO
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 8
+ALIASES =
+OPTIMIZE_OUTPUT_FOR_C = NO
+OPTIMIZE_OUTPUT_JAVA = NO
+SUBGROUPING = YES
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = YES
+EXTRACT_STATIC = YES
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = YES
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_BY_SCOPE_NAME = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_DIRECTORIES = YES
+FILE_VERSION_FILTER =
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = ../src/
+FILE_PATTERNS = *.c \
+ *.cc \
+ *.cxx \
+ *.cpp \
+ *.c++ \
+ *.d \
+ *.java \
+ *.ii \
+ *.ixx \
+ *.ipp \
+ *.i++ \
+ *.inl \
+ *.h \
+ *.hh \
+ *.hxx \
+ *.hpp \
+ *.h++ \
+ *.idl \
+ *.odl \
+ *.cs \
+ *.php \
+ *.php3 \
+ *.inc \
+ *.m \
+ *.mm \
+ *.dox \
+ *.C \
+ *.CC \
+ *.C++ \
+ *.II \
+ *.I++ \
+ *.H \
+ *.HH \
+ *.H++ \
+ *.CS \
+ *.PHP \
+ *.PHP3 \
+ *.M \
+ *.MM
+RECURSIVE = YES
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS = *
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = YES
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION = YES
+VERBATIM_HEADERS = YES
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = NO
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_ALIGN_MEMBERS = YES
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+BINARY_TOC = NO
+TOC_EXPAND = NO
+DISABLE_INDEX = NO
+ENUM_VALUES_PER_LINE = 4
+GENERATE_TREEVIEW = YES
+TREEVIEW_WIDTH = 250
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4wide
+EXTRA_PACKAGES =
+LATEX_HEADER =
+PDF_HYPERLINKS = NO
+USE_PDFLATEX = NO
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = YES
+HIDE_UNDOC_RELATIONS = NO
+HAVE_DOT = YES
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = YES
+TEMPLATE_RELATIONS = YES
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = YES
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+DOT_PATH =
+DOTFILE_DIRS =
+MAX_DOT_GRAPH_WIDTH = 1024
+MAX_DOT_GRAPH_HEIGHT = 1024
+MAX_DOT_GRAPH_DEPTH = 1000
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+SEARCHENGINE = NO
diff --git a/i/simulotron/doc/Makefile b/i/simulotron/doc/Makefile
new file mode 100644
index 0000000..fcb45ca
--- /dev/null
+++ b/i/simulotron/doc/Makefile
@@ -0,0 +1,15 @@
+
+all: doc
+
+
+doc: doc-doxygen doc-aft
+
+
+doc-doxygen:
+ doxygen Doxyfile
+
+doc-aft:
+ for i in *.txt; do aft $$i; done;
+
+clean:
+ rm -rfv *.html *-TOC html
diff --git a/i/simulotron/doc/Makefile.am b/i/simulotron/doc/Makefile.am
deleted file mode 100644
index e69de29..0000000
--- a/i/simulotron/doc/Makefile.am
+++ /dev/null
diff --git a/i/simulotron/src/Makefile.am b/i/simulotron/src/Makefile.am
index be13d3b..ae36f30 100644
--- a/i/simulotron/src/Makefile.am
+++ b/i/simulotron/src/Makefile.am
@@ -5,6 +5,7 @@ include utils/Makefile.incl.am
include gs/Makefile.incl.am
include aiguillage/Makefile.incl.am
include comc/Makefile.incl.am
+include hub/Makefile.incl.am
bin_PROGRAMS = simulotron
simulotron_SOURCES = main.cc \
@@ -12,7 +13,8 @@ simulotron_SOURCES = main.cc \
$(gs_message_S) \
$(gs_transmitter_S) \
$(aiguillage_S) \
- $(comc_S)
+ $(comc_S) \
+ $(hub_S)
AM_CXXFLAGS = -g -Wall -W -fmessage-length=0
simulotron_LDADD =
diff --git a/i/simulotron/src/comc/Makefile.incl.am b/i/simulotron/src/comc/Makefile.incl.am
index 93bf1ee..d1ca797 100644
--- a/i/simulotron/src/comc/Makefile.incl.am
+++ b/i/simulotron/src/comc/Makefile.incl.am
@@ -1,9 +1,9 @@
-comc_S = comc/comc.tcc comc/comc.hh
+comc_S = comc/comc.cc comc/comc.hh comc/struct_message.hh
check_PROGRAMS += test_comc
test_comc_SOURCES = comc/test_comc.cc \
- $(comc_S) \
- $(socket_S) \
- $(aiguillage_S) \
- $(gs_message_S) \
- $(gs_transmitter_S)
+ $(comc_S) \
+ $(gs_message_S) \
+ $(gs_transmitter_S) \
+ $(socket_S) \
+ $(aiguillage_S)
diff --git a/i/simulotron/src/comc/comc.tcc b/i/simulotron/src/comc/comc.cc
index 6e7bef7..cbfb474 100644
--- a/i/simulotron/src/comc/comc.tcc
+++ b/i/simulotron/src/comc/comc.cc
@@ -23,36 +23,39 @@
*
* }}} */
+#include "gs/gs_message.hh"
#include "comc/comc.hh"
#include <stdexcept>
-/// Constructeur général
-template <class C>
-ComC<C>::ComC(const std::string & address, int port, const std::string & name)
- :C(),aiguillage_(address, port, name)
+/// Constructeur client
+ComC::ComC(const std::string & address, int port, const std::string & name)
+ :aiguillage_(address, port, name)
{
}
-/// Fonction send générale qui DOIT planter
-template <class C> template <class T>
-void
-ComC<C>::send(const T & message, const std::string & destname)
+/// Constructeur serveur
+ComC::ComC(SocketServer & socket, const std::string & name)
+ :aiguillage_(socket, name)
{
- throw std::runtime_error("ComC: Utilisation de send avec une struct indéfini!!");
}
-/// Recoie quelque chose et appelle une fonction callback
-template <class C>
void
-ComC<C>::receive(void)
+ComC::send(const msgX & message, const std::string & destname)
{
- throw std::runtime_error("ComC: Utilisation de receive avec une class indefini!!!");
+ GSMessage gsm;
+ message.msgToGs(gsm);
+ aiguillage_.send(gsm, std::string(), destname);
}
-class TuSersARien{};
+/// Récupération de la GS
+int
+ComC::receiveGS(GSMessage & gsm, std::string & source, std::string & dest, int & msgId)
+{
+ if(aiguillage_.receive(gsm, source, dest) != 0)
+ return 1;
+ gsm.readGS(&msgId, sizeof(int));
+ gsm.setIteratorBegin();
+ return 0;
+}
-template<>
-void
-ComC<TuSersARien>::receive(void)
-{}
diff --git a/i/simulotron/src/comc/comc.hh b/i/simulotron/src/comc/comc.hh
index 3edd2c1..a7e0076 100644
--- a/i/simulotron/src/comc/comc.hh
+++ b/i/simulotron/src/comc/comc.hh
@@ -26,27 +26,23 @@
* }}} */
#include "aiguillage/aiguillage.hh"
+#include "comc/struct_message.hh"
-template <class C>
-class ComC : public C
+class ComC
{
private:
Aiguillage aiguillage_;
public:
- /// Constructeur
+ /// Constructeur client
ComC(const std::string & address, int port, const std::string & name);
+ /// Constructeur serveur
+ ComC(SocketServer & socket, const std::string & name);
/// Initialise la communication avec le hub
void InitHub(void);
/// Envoie un truc dans le réseau
- template <class T>
- void send(const T & message, const std::string & destname);
- // Recoie quelque chose et appelle une fonction callback
- // void receive(void);
+ void send(const msgX & message, const std::string & destname);
+ /// Récupération de la GS
+ int receiveGS(GSMessage & gsm, std::string & source, std::string & dest, int & msgId);
};
-/// Contient les fonction de base de la classe
-#include "comc/comc.tcc"
-/// Contient les fonctions send spécialisé.
-#include "comc/send.tcc"
-
#endif //COMC_HH
diff --git a/i/simulotron/src/comc/send.tcc b/i/simulotron/src/comc/send.tcc
deleted file mode 100644
index 6c5554a..0000000
--- a/i/simulotron/src/comc/send.tcc
+++ /dev/null
@@ -1,40 +0,0 @@
-/* send.tcc - Contient toute les fcts send pour les structures gs */
-/* Simulotron - Programme de simulation de robot {{{
- *
- * Copyright (C) 2005 Nicolas Haller
- *
- * Robot APB Team/Efrei 2006.
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
- *
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * }}} */
-
-// Structure 0 - Structure de test
-// int, double, string(8),short, string, long
-template <class C> template <>
-void
-ComC<C>::send(const msg0 & message, const std::string & destname)
-{
- GSMessage gsm;
- gsm appendGS(&i, sizeof(int));
- gsm appendGS(&j, sizeof(double));
- gsm appendGS(&dfsdf, sizeof(int));
- gsm appendGS(&i, sizeof(int));
- gsm appendGS(&i, sizeof(int));
- gsm appendGS(&i, sizeof(int));
-}
-
diff --git a/i/simulotron/src/comc/struct_message.hh b/i/simulotron/src/comc/struct_message.hh
new file mode 100644
index 0000000..598ac40
--- /dev/null
+++ b/i/simulotron/src/comc/struct_message.hh
@@ -0,0 +1,79 @@
+#ifndef STRUCT_MESSAGE_HH
+#define STRUCT_MESSAGE_HH
+/* struct_message.hh - Fichier contenant les structures des messages réseau */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2006 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#include "gs/gs_message.hh"
+
+#include <string>
+#include <stdexcept>
+
+/// Message mère de toute les structures de données réseau
+struct msgX
+{
+ virtual ~msgX(void) {}
+ virtual void msgToGs(GSMessage & gsm) const = 0;
+ virtual void gsToMsg(GSMessage & gsm) = 0;
+};
+
+struct msg0 : public msgX
+{
+ int i;
+ double d;
+ std::string strh; //8 char
+ short s;
+ std::string str;
+ long l;
+
+ virtual void msgToGs(GSMessage & gsm) const
+ {
+ int msgId = 0;
+ gsm.clear();
+ gsm.appendGS(&msgId, sizeof(int));
+ gsm.appendGS(&i, sizeof(int));
+ gsm.appendGS(&d, sizeof(double));
+ gsm.appendGS(strh.data(), 8);
+ gsm.appendGS(&s, sizeof(short));
+ gsm.appendGS(str.c_str(), str.size() + 1);
+ gsm.appendGS(&l, sizeof(long));
+ }
+
+ virtual void gsToMsg(GSMessage & gsm)
+ {
+ int msgId = 0;
+ int tmp;
+ gsm.readGS(&tmp, sizeof(int));
+ if(tmp != msgId)
+ throw std::runtime_error("la gs ne correspond pas à la structure");
+ gsm.readGS(&i, sizeof(int));
+ gsm.readGS(&d, sizeof(double));
+ gsm.getString(strh, 8);
+ gsm.readGS(&s, sizeof(short));
+ gsm.getString(str);
+ gsm.readGS(&l, sizeof(long));
+ }
+};
+
+#endif //STRUCT_MESSAGE_HH
diff --git a/i/simulotron/src/comc/test_comc.cc b/i/simulotron/src/comc/test_comc.cc
index 1fe2aa7..7182df1 100644
--- a/i/simulotron/src/comc/test_comc.cc
+++ b/i/simulotron/src/comc/test_comc.cc
@@ -1,7 +1,7 @@
-/* test_comc.cc - Programme de test pour comc */
+/* test_comc.cc - Programme de test du comc. */
/* Simulotron - Programme de simulation de robot {{{
*
- * Copyright (C) 2005 Nicolas Haller
+ * Copyright (C) 2006 Nicolas Haller
*
* Robot APB Team/Efrei 2005.
* Web: http://assos.efrei.fr/robot/
@@ -23,24 +23,111 @@
*
* }}} */
+#include "comc/struct_message.hh"
#include "comc/comc.hh"
+#include "socket/socket_server.hh"
+#include <sys/wait.h>
#include <iostream>
+// message de test
+msg0 ms;
-int
-main (void)
+int testGSServer(SocketServer & sockServ);
+void testGSClient(int pauseMode);
+
+int main(void)
{
- try
+ //pauseMode pour debbuger le fork
+ int pauseMode = 0;
+ int pid;
+ //retour des test
+ int resultClient, resultServer;
+ //Initialisation des valeurs de la struct de test
+ ms.i = 42;
+ ms.d = 23.23;
+ ms.strh = "chier!!!";
+ ms.s = 4;
+ ms.str = "Ho!! Une structure de test, comme c'est amusant!!";
+ ms.l = 3432;
+ // Création de la socket serveur;
+ SocketServer sockServ(std::string(),4242);
+ // Mise en écoute du socket serveur
+ sockServ.listen(12);
+ // On crée le fork du client
+ pid = fork();
+ if (pid == 0) // processus fils
+ testGSClient(pauseMode);
+ else //processus père
+ resultServer = testGSServer(sockServ);
+
+ // On analyse les résultats
+ wait(&resultClient);
+ if (!(WIFEXITED(resultClient) && WEXITSTATUS(resultClient) == 0))
{
- ComC<TuSersARien> ccTSAR("127.0.0.1", 4080, "chier");
- ccTSAR.receive();
+ std::cerr << "ECHEC: Problème coté client" << std::endl;
+ exit (-1);
}
- catch (std::runtime_error & chier)
+ if (resultServer != 0)
{
- std::cout << chier.what() << std::endl;
- exit(1);
+ std::cerr << "ECHEC: Problème coté serveur" << std::endl;
+ exit (-1);
}
return 0;
}
+
+int testGSServer(SocketServer & sockServ)
+{
+ try
+ {
+ std::string source, dest;
+ GSMessage gsm;
+ msg0 mscom;
+ int msgId;
+ // Création de la comc
+ ComC comc(sockServ,"serveur");
+ while(comc.receiveGS(gsm,source,dest, msgId)){}
+ mscom.gsToMsg(gsm);
+ if(!(ms.i == mscom.i &&
+ ms.d == mscom.d &&
+ ms.strh == mscom.strh &&
+ ms.s == mscom.s &&
+ ms.str == mscom.str &&
+ ms.l == mscom.l))
+ {
+ std::cout << "CHIER!! Le message recu n'est pas identique !!" << std::endl;
+ std::cout << "m d'origine: " << ms.i << "\nm d'arrivée: " << mscom.i << "result: " << (ms.i == mscom.i) << std::endl;
+ std::cout << "m d'origine: " << ms.d << "\nm d'arrivée: " << mscom.d << "result: " << (ms.d == mscom.d) << std::endl;
+ std::cout << "m d'origine: " << ms.strh << "\nm d'arrivée: " << mscom.strh << "result: " << (ms.strh == mscom.strh) << std::endl;
+ std::cout << "m d'origine: " << ms.s << "\nm d'arrivée: " << mscom.s << "result: " << (ms.s == mscom.s) << std::endl;
+ std::cout << "m d'origine: " << ms.str << "\nm d'arrivée: " << mscom.str << "result: " << (ms.str == mscom.str) << std::endl;
+ std::cout << "m d'origine: " << ms.l << "\nm d'arrivée: " << mscom.l << "result: " << (ms.l == mscom.l) << std::endl;
+ return 1;
+ }
+ }
+ catch (std::exception & c)
+ {
+ std::cout << "Oops, exeption dans le serveur" << std::endl;
+ }
+ return 0;
+}
+
+void testGSClient(int pauseMode)
+{
+ while(pauseMode)
+ sleep (10);
+ try
+ {
+ // Création du comc
+ ComC comc(std::string("127.0.0.1"), 4242, "client");
+ comc.send(ms, std::string("serveur"));
+ }
+ catch(std::exception & chier)
+ {
+ std::cout << "CHIER !! Une exception a été lancé coté client!!" << std::endl;
+ std::cout << chier.what() << std::endl;
+ exit (1);
+ }
+ exit (0);
+}
diff --git a/i/simulotron/src/comc/test_comc_struct.hh b/i/simulotron/src/comc/test_comc_struct.hh
deleted file mode 100644
index fa1fc63..0000000
--- a/i/simulotron/src/comc/test_comc_struct.hh
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef TCS_HH
-#define TCS_HH
-/* test_comc_struct.hh - message de test 0 */
-/* Simulotron - Programme de simulation de robot {{{
- *
- * Copyright (C) 2006 Nicolas Haller
- *
- * Robot APB Team/Efrei 2006.
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
- *
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * }}} */
-
-struct msg0
-{
- int i;
- double j;
- std::string str1; // Limité à 8 octets
- short s;
- std::string str2; // string infini
- long l;
-}
-#endif //TCS_HH
diff --git a/i/simulotron/src/gs/gs_message.cc b/i/simulotron/src/gs/gs_message.cc
index 541c14c..0ab8bb8 100644
--- a/i/simulotron/src/gs/gs_message.cc
+++ b/i/simulotron/src/gs/gs_message.cc
@@ -56,12 +56,21 @@ GSMessage::readGS(void * data, size_t size)
}
void
+GSMessage::getString(std::string & str)
+{
+ std::string tmp (igs_, gs_.end());
+ str.assign(tmp.c_str());
+ igs_ += str.size() + 1;
+}
+
+void
GSMessage::getString(std::string & str, size_t size)
{
str.assign(igs_, igs_ + size);
igs_ += size;
}
+///\todo Est-ce vraiment bien ca? et pourquoi une fct templaté?
void
GSMessage::appendGS (const void * data, size_t size)
{
diff --git a/i/simulotron/src/gs/gs_message.hh b/i/simulotron/src/gs/gs_message.hh
index 45ed43d..cfb0b41 100644
--- a/i/simulotron/src/gs/gs_message.hh
+++ b/i/simulotron/src/gs/gs_message.hh
@@ -44,7 +44,9 @@ class GSMessage
const std::string & getGS (void) const;
/// Récupération de données de la gs
void readGS (void * data, size_t size);
- /// Récupère des données sous forme d'une string
+ /// Récupère des données sous la forme d'une string terminé par un \0
+ void getString (std::string & str);
+ /// Récupère des données sous forme d'une string de taille fixe
void getString (std::string & str, size_t size);
/// Ecriture à la fin de la gs
void appendGS (const void * data, size_t size);
diff --git a/i/simulotron/src/gs/test_gs.cc b/i/simulotron/src/gs/test_gs.cc
index 7416949..acf47f9 100644
--- a/i/simulotron/src/gs/test_gs.cc
+++ b/i/simulotron/src/gs/test_gs.cc
@@ -90,7 +90,8 @@ int testGSServer(SocketServer & sockServ)
// une string
GSMessage gsm;
while (gst.getGS(gsm) != 0);
- if (strDepart != gsm.getGS())
+ gsm.getString(strDest);
+ if (strDepart != strDest)
{
std::cout << "CHIER String altéré\n"
<< "Message d'origine: " << strDepart << "\n"
@@ -163,6 +164,7 @@ int testGSServer(SocketServer & sockServ)
while (gst.getGS(gsm) != 0);
gsm.readGS(&s2,sizeof(short));
gsm.readGS(&l2,sizeof(long));
+ gsm.getString(strDest);
gsm.readGS(&i4,sizeof(int));
if ( s1 != s2)
{
@@ -180,6 +182,15 @@ int testGSServer(SocketServer & sockServ)
<< std::endl;
return 1;
}
+ if ( strDepart != strDest)
+ {
+ std::cout << "CHIER String altéré\n"
+ << "Message d'origine: " << strDepart << "\n"
+ << "Message d'arrivé: " << gsm.getGS()
+ << std::endl;
+ return 1;
+ }
+
if ( i3 != i4)
{
std::cout << "CHIER int negatif altéré\n"
@@ -200,7 +211,7 @@ void testGSClient(int pauseMode)
// Création du transmitter
GSTransmitter gst(std::string("127.0.0.1"), 4242);
GSMessage g1,g2,g3,g4,g5,g6,g7;
- g1.appendGS(strDepart.data(), strDepart.size());
+ g1.appendGS(strDepart.c_str(), strDepart.size() + 1);
gst.putGS(g1);
g2.appendGS(&a, sizeof(char));
gst.putGS(g2);
@@ -215,6 +226,7 @@ void testGSClient(int pauseMode)
g7.appendGS(&l1, sizeof(long));
g7.insertFrontGS(&s1, sizeof(short));
+ g7.appendGS(strDepart.c_str(), strDepart.size() + 1);
g7.appendGS(&i3, sizeof(int));
gst.putGS(g7);
}
diff --git a/i/simulotron/src/hub/hub.cc b/i/simulotron/src/hub/hub.cc
new file mode 100644
index 0000000..13d3e23
--- /dev/null
+++ b/i/simulotron/src/hub/hub.cc
@@ -0,0 +1,139 @@
+/* hub.cc - Class hub du simulotron */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2006 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#include "hub/hub.hh"
+#include "gs/gs_message.hh"
+
+#include <iostream>
+
+Hub::Hub (std::string & address, int port)
+ :timeh_(0), socket_(address, port), isRunning(false)
+{
+ init();
+}
+
+void
+Hub::start(void)
+{
+ waitConnection();
+ startLoop();
+}
+
+void
+Hub::init(void)
+{
+ // Créer la liste des modules attendus
+ //dfqsdf
+
+}
+
+void
+Hub::waitConnection(void)
+{
+ //Tant que l'on attend des modules...
+ while (!modAwaited_.empty())
+ {
+ // On crée le système de com avec le module
+ modules_.push_back(ComH(socket_));
+ // On verifie que le module est attendu
+ std::list<std::string>::iterator it = find(modAwaited_.begin(), modAwaited_.end(), modules_.back().getModuleName());
+ if(it == modAwaited_.end())
+ {
+ // Ouille, on reporte l'incident
+ std::cerr << "Un module inattendu a tenté de se connecter au Hub, nom du module: " << modules_.back().getModuleName() << std::endl;
+ // On vire le malotru
+ modules_.pop_back();
+ continue;
+ }
+ // On vire le modules de la liste des attendu
+ modAwaited_.erase(it);
+ }
+}
+
+void
+Hub::startLoop(void)
+{
+ isRunning = true;
+ while(isRunning)
+ {
+ processModules();
+ processWaits();
+ processStoppingRules();
+ }
+}
+
+void
+Hub::processModules(void)
+{
+ for(std::list<ComH>::iterator it = modules_.begin(); it != modules_.end(); it++)
+ {
+ processModule(it);
+ }
+}
+
+void
+Hub::processModule(const std::list<ComH>::iterator & it)
+{
+ std::string source, dest;
+ int msgId;
+ GSMessage gsm;
+ while (it->receiveMsg(gsm, source, dest, msgId))
+ laPoste(gsm, source, dest, msgId);
+}
+
+void
+Hub::processWaits(void)
+{
+ int timeToSet = 0;
+ long long int tmp;
+ for(std::list<ComH>::iterator it = modules_.begin(); it != modules_.end(); it++)
+ {
+ if(!it->isWaiting())
+ return;
+ tmp = it->getDLWait();
+ if(tmp != -1 && tmp < timeToSet)
+ timeToSet = tmp;
+ }
+}
+
+void
+Hub::laPoste (const GSMessage & gsm, const std::string & source, const std::string & dest, int msgId)
+{
+ //Si c'est un message particulier
+ if(msgId == 0)
+ {
+ }
+ // Si c'est un message banal
+ else
+ {
+ ///\todo pas optimisé
+ for(std::list<ComH>::iterator it = modules_.begin(); it != modules_.end(); it++)
+ {
+ if(dest == it->getModuleName())
+ it->send(gsm, source, dest, msgId);
+ }
+ }
+}
+
diff --git a/i/simulotron/src/hub/hub.hh b/i/simulotron/src/hub/hub.hh
index 40ddc62..e91f8d0 100644
--- a/i/simulotron/src/hub/hub.hh
+++ b/i/simulotron/src/hub/hub.hh
@@ -25,17 +25,48 @@
*
* }}} */
+#include "hub/comh.hh"
+#include "socket/socket_server.hh"
+
+#include <list>
+
+class GSMessage;
+
class Hub
{
private:
- TimeH timeh_;
- Orders ordres_;
+ /// Horloge de simulation
+ long long int timeh_;
+ /// Listes des modules conectées au hub
+ std::list<ComH> modules_;
+ /// Socket serveur pour la connection
SocketServer socket_;
+ /// Liste des modules attendu
+ std::list<std::string> modAwaited_;
+ /// Drapeau pour sortir de la boucle
+ bool isRunning;
public:
/// Constructeur
- Hub(void);
+ Hub(std::string & address, int port);
+ /// Lancement du hub
+ void start(void);
+ private:
/// Initialisation
- Init(void);
+ void init(void);
+ /// Attend et initialise la communication avec les modules
+ void waitConnection(void);
+ /// Demarre le travail de hub du hub
+ void startLoop(void);
+ /// Traite les messages des modules
+ void processModules(void);
+ /// Traite les message d'un modules
+ void processModule(const std::list<ComH>::iterator & it);
+ /// Traite les wait des modules et fait avancer l'horloge si besoin
+ void processWaits(void);
+ /// Traite les règles d'arret du Hub
+ void processStoppingRules(void);
+ /// Se charge de faire se qu'il faut avec les messages
+ void laPoste (const GSMessage & gsm, const std::string & source, const std::string & dest, int msgId);
};
#endif //HUB_HH