From 08665d1190b5512046797e34041575aeaccc1ec7 Mon Sep 17 00:00:00 2001 From: haller Date: Mon, 19 Dec 2005 23:21:42 +0000 Subject: * Creation du fichier comc.c * Codage de Aiguillage en progression... * Creation d'un test_aiguillage pipo (pour l'instant) * Ajout de fonctionnalité à GSMessage * Ajout de Aiguillage pour la compilation dans le Makefile.am --- i/simulotron/src/Makefile.am | 4 +- i/simulotron/src/aiguillage/aiguillage.cc | 74 ++++++++++++++++++++++++++ i/simulotron/src/aiguillage/aiguillage.hh | 14 ++--- i/simulotron/src/aiguillage/test_aiguillage.cc | 4 ++ i/simulotron/src/comc/comc.cc | 39 ++++++++++++++ i/simulotron/src/gs/gs_message.cc | 14 +++++ i/simulotron/src/gs/gs_message.hh | 4 ++ 7 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 i/simulotron/src/aiguillage/aiguillage.cc create mode 100644 i/simulotron/src/aiguillage/test_aiguillage.cc create mode 100644 i/simulotron/src/comc/comc.cc (limited to 'i/simulotron') diff --git a/i/simulotron/src/Makefile.am b/i/simulotron/src/Makefile.am index ce848fe..ddf2d78 100644 --- a/i/simulotron/src/Makefile.am +++ b/i/simulotron/src/Makefile.am @@ -3,12 +3,14 @@ check_PROGRAMS = include socket/Makefile.incl.am include utils/Makefile.incl.am include gs/Makefile.incl.am +include aiguillage/Makefile.incl.am bin_PROGRAMS = simulotron simulotron_SOURCES = main.cc \ $(socket_S) \ $(gs_message_S) \ - $(gs_transmitter_S) + $(gs_transmitter_S) \ + $(aiguillage_S) AM_CXXFLAGS = -g -Wall -W -fmessage-length=0 simulotron_LDADD = diff --git a/i/simulotron/src/aiguillage/aiguillage.cc b/i/simulotron/src/aiguillage/aiguillage.cc new file mode 100644 index 0000000..95bbad1 --- /dev/null +++ b/i/simulotron/src/aiguillage/aiguillage.cc @@ -0,0 +1,74 @@ +/* aiguillage.cc - Classe rajoutant les info de la source et de la dest d'un packet */ +/* 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. + * + * }}} */ + +#include "aiguillage/aiguillage.hh" +#include "gs/gs_message.hh" + +#include + +/// Constructeur +Aiguillage::Aiguillage(const std::string & address, int port, const std::string & name) + :gst_(address, port) +{ + setName(name); +} + +/// Envoie un paquet en rajoutant les infos de sources et de provenance +void +Aiguillage::send(const GSMessage & gsm, const std::string & source, + const std::string & dest) +{ + ///\todo Voir pour optimiser ca + GSMessage g = gsm; + g.insertFrontGS(dest.data(), MAX_SIZE_NAME); + // Si source est vide, mettre name_ + if(source.empty()) + g.insertFrontGS(name_.data(), MAX_SIZE_NAME); + else + g.insertFrontGS(source.data(), MAX_SIZE_NAME); + gst_.putGS(g); +} + +/// Reçoie un paquet du réseau et supprime les infos src et dest du GSM +int +Aiguillage::receive(GSMessage & gsm, std::string & source, std::string & dest) +{ + if(gst_.getGS(gsm) != 0) + return -1; + gsm.getString(source, 8); + gsm.getString(dest, 8); + gsm.delBeforeIt(); + return 0; +} + +void +Aiguillage::setName(const std::string & name) +{ + if(name.size() > MAX_SIZE_NAME) + throw std::runtime_error("Le nom est trop long!!"); + name_ = name; + name_.append(MAX_SIZE_NAME - name.size(), '\0'); +} + diff --git a/i/simulotron/src/aiguillage/aiguillage.hh b/i/simulotron/src/aiguillage/aiguillage.hh index a549eae..3ec2bae 100644 --- a/i/simulotron/src/aiguillage/aiguillage.hh +++ b/i/simulotron/src/aiguillage/aiguillage.hh @@ -25,22 +25,24 @@ * * }}} */ +#include "gs/gs_transmitter.hh" + class Aiguillage { private: - static const int MAX_SIZE_NAME = 8; + static const unsigned int MAX_SIZE_NAME = 8; private: - GSTransmitter gqt_; + GSTransmitter gst_; std::string name_; public: /// Constructeur - Aiguillage(void); + Aiguillage(const std::string & address, int port, const std::string & name); /// Envoie un paquet en rajoutant les infos de sources et de provenance - void send(GSMessage & gsm, const std::string & source, const std::string & dest); + void send(const GSMessage & gsm, const std::string & source, const std::string & dest); /// Reçoie un paquet du réseau et supprime les infos src et dest du GSM - int receive(GSMessage & gsm, std::string & source, const std::string & dest); + int receive(GSMessage & gsm, std::string & source, std::string & dest); private: /// Set le nom de transmition - void setName(std::string & name); + void setName(const std::string & name); }; #endif //AIGUILLAGE_HH diff --git a/i/simulotron/src/aiguillage/test_aiguillage.cc b/i/simulotron/src/aiguillage/test_aiguillage.cc new file mode 100644 index 0000000..82be6e4 --- /dev/null +++ b/i/simulotron/src/aiguillage/test_aiguillage.cc @@ -0,0 +1,4 @@ +int main (void) +{ + return 0; +} diff --git a/i/simulotron/src/comc/comc.cc b/i/simulotron/src/comc/comc.cc new file mode 100644 index 0000000..4781c33 --- /dev/null +++ b/i/simulotron/src/comc/comc.cc @@ -0,0 +1,39 @@ +/* comc.cc - Classe la plus haute dans la transmission par socket */ +/* 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. + * + * }}} */ + +/// Constructeur +template +ComC::ComC(const std::string & address, int port, const std::string & name) + :C(),gst_(address, port) +{ +} +/// Envoie un truc dans le réseau +template +void send(const T & message, const std::string & destname); +/// Recoie quelque chose et appelle une fonction callback +template +void receive(void); + +#endif //COMC_HH diff --git a/i/simulotron/src/gs/gs_message.cc b/i/simulotron/src/gs/gs_message.cc index 34a4368..c0e099a 100644 --- a/i/simulotron/src/gs/gs_message.cc +++ b/i/simulotron/src/gs/gs_message.cc @@ -55,6 +55,13 @@ GSMessage::readGS(void * data, size_t size) igs_ += size; } +void +GSMessage::getString(std::string & str, size_t size) +{ + str.assign(igs_, igs_ + size); + igs_ += size; +} + void GSMessage::appendGS (const void * data, size_t size) { @@ -81,3 +88,10 @@ GSMessage::clear(void) gs_.clear(); setIteratorBegin(); } + +void +GSMessage::delBeforeIt(void) +{ + gs_.erase(gs_.begin(), igs_ - 1); + setIteratorBegin(); +} diff --git a/i/simulotron/src/gs/gs_message.hh b/i/simulotron/src/gs/gs_message.hh index 2f01949..45ed43d 100644 --- a/i/simulotron/src/gs/gs_message.hh +++ b/i/simulotron/src/gs/gs_message.hh @@ -44,6 +44,8 @@ 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 + void getString (std::string & str, size_t size); /// Ecriture à la fin de la gs void appendGS (const void * data, size_t size); /// Ecriture au début de la gs @@ -52,6 +54,8 @@ class GSMessage void setIteratorBegin(void); /// Efface la GS void clear(void); + /// Efface tout ce qu'il y a avant l'iterateur + void delBeforeIt(void); }; #endif //gs_message_hh -- cgit v1.2.3