summaryrefslogtreecommitdiff
path: root/i/simulotron/src/comc/comc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/simulotron/src/comc/comc.cc')
-rw-r--r--i/simulotron/src/comc/comc.cc29
1 files changed, 23 insertions, 6 deletions
diff --git a/i/simulotron/src/comc/comc.cc b/i/simulotron/src/comc/comc.cc
index cbfb474..6ac3f69 100644
--- a/i/simulotron/src/comc/comc.cc
+++ b/i/simulotron/src/comc/comc.cc
@@ -30,7 +30,7 @@
/// Constructeur client
ComC::ComC(const std::string & address, int port, const std::string & name)
- :aiguillage_(address, port, name)
+ :aiguillage_(address, port, name), moduleName_(name)
{
}
@@ -40,6 +40,23 @@ ComC::ComC(SocketServer & socket, const std::string & name)
{
}
+/// Initialise la communication avec le hub
+void
+ComC::initHub(void)
+{
+ // Envoie du premier message
+ msg1 ms;
+ ms.moduleName = moduleName_;
+ send(ms,std::string("hub"));
+ // Attente de la reponse du hub
+ GSMessage gsm;
+ std::string source, dest;
+ int msgId;
+ receiveGS(gsm, source, dest, msgId, true);
+ if (msgId != 2) /// \todo c'est moche
+ throw simulotron_exception("ComC:", "Rejet du hub!!");
+}
+
void
ComC::send(const msgX & message, const std::string & destname)
{
@@ -49,13 +66,13 @@ ComC::send(const msgX & message, const std::string & destname)
}
/// Récupération de la GS
-int
-ComC::receiveGS(GSMessage & gsm, std::string & source, std::string & dest, int & msgId)
+bool
+ComC::receiveGS(GSMessage & gsm, std::string & source, std::string & dest, int & msgId, bool bloquant)
{
- if(aiguillage_.receive(gsm, source, dest) != 0)
- return 1;
+ if(!aiguillage_.receive(gsm, source, dest, bloquant))
+ return false;
gsm.readGS(&msgId, sizeof(int));
gsm.setIteratorBegin();
- return 0;
+ return true;
}