summaryrefslogtreecommitdiff
path: root/i/simulotron/src
diff options
context:
space:
mode:
authorhaller2006-01-11 15:22:48 +0000
committerhaller2006-01-11 15:22:48 +0000
commit3cc65a4aa5299558dab3308bcba82f0480855a35 (patch)
tree38576b576f6a86524c699e0eb725c24448c1d07b /i/simulotron/src
parent9913620eca0dbc3995125b4e97089eb855107560 (diff)
* Simulotron
- mise en place de la doc - Ajout d'un Doxyfile - Le Makefile de doc passe en manuel - Le Makefile de doc génère le doxy et les aft - ComC - Premier jet de ComC qui fonctionne - Suppression du send.tcc - Suppression des fichier necessaire au test de la version précédente - Mise en place du test de ComC - Ajout des fichiers de structures des messages - Integration à A/A - gs_message - Ajout d'une fct get_string pour récupérer les str de taille variable - Modification du test_gs - hub - Codage en cours...
Diffstat (limited to 'i/simulotron/src')
-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
13 files changed, 414 insertions, 131 deletions
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