summaryrefslogtreecommitdiff
path: root/i/simulotron/src/hub/hub.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/simulotron/src/hub/hub.cc')
-rw-r--r--i/simulotron/src/hub/hub.cc44
1 files changed, 29 insertions, 15 deletions
diff --git a/i/simulotron/src/hub/hub.cc b/i/simulotron/src/hub/hub.cc
index 13d3e23..bfdfc91 100644
--- a/i/simulotron/src/hub/hub.cc
+++ b/i/simulotron/src/hub/hub.cc
@@ -28,10 +28,17 @@
#include <iostream>
-Hub::Hub (std::string & address, int port)
+Hub::Hub (const std::string & address, int port)
:timeh_(0), socket_(address, port), isRunning(false)
{
init();
+ socket_.listen(32);
+}
+
+Hub::~Hub(void)
+{
+ for (std::list<ComH *>::iterator it = modules_.begin(); it != modules_.end(); it++)
+ delete *it;
}
void
@@ -45,7 +52,9 @@ void
Hub::init(void)
{
// Créer la liste des modules attendus
- //dfqsdf
+ ///\todo faire l'init
+ modAwaited_.push_back(std::string("module1"));
+ modAwaited_.push_back(std::string("module2"));
}
@@ -56,14 +65,15 @@ Hub::waitConnection(void)
while (!modAwaited_.empty())
{
// On crée le système de com avec le module
- modules_.push_back(ComH(socket_));
+ modules_.push_back(new ComH(socket_));
// On verifie que le module est attendu
- std::list<std::string>::iterator it = find(modAwaited_.begin(), modAwaited_.end(), modules_.back().getModuleName());
+ 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;
+ std::cerr << "Un module inattendu a tenté de se connecter au Hub, nom du module: " << modules_.back()->getModuleName() << std::endl;
// On vire le malotru
+ delete modules_.back();
modules_.pop_back();
continue;
}
@@ -87,19 +97,19 @@ Hub::startLoop(void)
void
Hub::processModules(void)
{
- for(std::list<ComH>::iterator it = modules_.begin(); it != modules_.end(); it++)
+ for(std::list<ComH *>::iterator it = modules_.begin(); it != modules_.end(); it++)
{
processModule(it);
}
}
void
-Hub::processModule(const std::list<ComH>::iterator & it)
+Hub::processModule(const std::list<ComH *>::iterator & it)
{
std::string source, dest;
int msgId;
GSMessage gsm;
- while (it->receiveMsg(gsm, source, dest, msgId))
+ while ((*it)->receiveMsg(gsm, source, dest, msgId, false))
laPoste(gsm, source, dest, msgId);
}
@@ -108,17 +118,22 @@ Hub::processWaits(void)
{
int timeToSet = 0;
long long int tmp;
- for(std::list<ComH>::iterator it = modules_.begin(); it != modules_.end(); it++)
+ for(std::list<ComH *>::iterator it = modules_.begin(); it != modules_.end(); it++)
{
- if(!it->isWaiting())
+ if(!(*it)->isWaiting())
return;
- tmp = it->getDLWait();
+ tmp = (*it)->getDLWait();
if(tmp != -1 && tmp < timeToSet)
timeToSet = tmp;
}
}
void
+Hub::processStoppingRules (void)
+{
+}
+
+void
Hub::laPoste (const GSMessage & gsm, const std::string & source, const std::string & dest, int msgId)
{
//Si c'est un message particulier
@@ -129,11 +144,10 @@ Hub::laPoste (const GSMessage & gsm, const std::string & source, const std::stri
else
{
///\todo pas optimisé
- for(std::list<ComH>::iterator it = modules_.begin(); it != modules_.end(); it++)
+ for(std::list<ComH *>::iterator it = modules_.begin(); it != modules_.end(); it++)
{
- if(dest == it->getModuleName())
- it->send(gsm, source, dest, msgId);
+ if(dest == (*it)->getModuleName())
+ (*it)->send(gsm, source, dest);
}
}
}
-