From 001f91e6ddce33aec769348adc55f0c0b0c09534 Mon Sep 17 00:00:00 2001 From: haller Date: Mon, 19 Dec 2005 21:56:10 +0000 Subject: * changement sans interet dans comc * Codage de aiguillage en cours * Ajout de fonctionnalité de traitement à GSMessage * Remaniement des constructeur de GSTransmitter * nettoyage et modification du test des gs --- i/simulotron/src/aiguillage/aiguillage.hh | 6 +++++ i/simulotron/src/comc/comc.hh | 20 +++++++++------- i/simulotron/src/gs/gs_message.cc | 9 +++++++- i/simulotron/src/gs/gs_message.hh | 6 +++-- i/simulotron/src/gs/gs_transmitter.cc | 9 ++++++-- i/simulotron/src/gs/gs_transmitter.hh | 11 +++++---- i/simulotron/src/gs/test_gs.cc | 38 +++++++++++-------------------- 7 files changed, 57 insertions(+), 42 deletions(-) (limited to 'i/simulotron') diff --git a/i/simulotron/src/aiguillage/aiguillage.hh b/i/simulotron/src/aiguillage/aiguillage.hh index 3c68e66..a549eae 100644 --- a/i/simulotron/src/aiguillage/aiguillage.hh +++ b/i/simulotron/src/aiguillage/aiguillage.hh @@ -27,8 +27,11 @@ class Aiguillage { + private: + static const int MAX_SIZE_NAME = 8; private: GSTransmitter gqt_; + std::string name_; public: /// Constructeur Aiguillage(void); @@ -36,5 +39,8 @@ class Aiguillage void send(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); + private: + /// Set le nom de transmition + void setName(std::string & name); }; #endif //AIGUILLAGE_HH diff --git a/i/simulotron/src/comc/comc.hh b/i/simulotron/src/comc/comc.hh index f77aadb..9d2477e 100644 --- a/i/simulotron/src/comc/comc.hh +++ b/i/simulotron/src/comc/comc.hh @@ -28,13 +28,17 @@ template class ComC : public C { - /// Constructeur - ComC(const Address & adr, const std::string & name); - /// 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 - void receive(void); + private: + GSTransmitter gst_; + public: + /// Constructeur + ComC(const std::string & address, int port, const std::string & name); + /// 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 818c433..34a4368 100644 --- a/i/simulotron/src/gs/gs_message.cc +++ b/i/simulotron/src/gs/gs_message.cc @@ -56,12 +56,19 @@ GSMessage::readGS(void * data, size_t size) } void -GSMessage::writeGS (const void * data, size_t size) +GSMessage::appendGS (const void * data, size_t size) { gs_.append(static_cast (data), size); setIteratorBegin(); } +void +GSMessage::insertFrontGS(const void * data, size_t size) +{ + gs_.insert(0, static_cast (data), size); + setIteratorBegin(); +} + void GSMessage::setIteratorBegin(void) { diff --git a/i/simulotron/src/gs/gs_message.hh b/i/simulotron/src/gs/gs_message.hh index b96491c..2f01949 100644 --- a/i/simulotron/src/gs/gs_message.hh +++ b/i/simulotron/src/gs/gs_message.hh @@ -44,8 +44,10 @@ class GSMessage const std::string & getGS (void) const; /// Récupération de données de la gs void readGS (void * data, size_t size); - /// Ecriture de la gs - void writeGS (const void * data, size_t size); + /// Ecriture à la fin de la gs + void appendGS (const void * data, size_t size); + /// Ecriture au début de la gs + void insertFrontGS (const void * data, size_t); /// Remise à zéro de l'itérateur de lecture void setIteratorBegin(void); /// Efface la GS diff --git a/i/simulotron/src/gs/gs_transmitter.cc b/i/simulotron/src/gs/gs_transmitter.cc index e593cdb..9f53963 100644 --- a/i/simulotron/src/gs/gs_transmitter.cc +++ b/i/simulotron/src/gs/gs_transmitter.cc @@ -30,11 +30,16 @@ #include #include -GSTransmitter::GSTransmitter(SocketClient & socket) +GSTransmitter::GSTransmitter(SocketServer & socket) :socket_(socket) { } +GSTransmitter::GSTransmitter(const std::string & address, int port) +{ + socket_.connect(address, port); +} + /// Renvoie 0 quand un message est récupéré, -1 sinon int GSTransmitter::getGS(GSMessage & gsm) @@ -63,7 +68,7 @@ GSTransmitter::getGS(GSMessage & gsm) | static_cast (strBrut_[3]); if(size > strBrut_.size() - 4) return -1; - gsm.writeGS (strBrut_.substr(4, size).data(), size); + gsm.appendGS (strBrut_.substr(4, size).data(), size); strBrut_.erase (0, size + 4); return 0; } diff --git a/i/simulotron/src/gs/gs_transmitter.hh b/i/simulotron/src/gs/gs_transmitter.hh index 10ec27a..86c0620 100644 --- a/i/simulotron/src/gs/gs_transmitter.hh +++ b/i/simulotron/src/gs/gs_transmitter.hh @@ -25,21 +25,24 @@ * * }}} */ +#include "socket/socket_client.hh" #include -class SocketClient; +class SocketServer; class GSMessage; class GSTransmitter { private: /// Socket de transmission - SocketClient & socket_; + SocketClient socket_; /// String brute récupéré std::string strBrut_; public: - /// Constructeur - GSTransmitter(SocketClient & socket); + /// Constructeur prenant un socket (cas d'un serveur) + GSTransmitter(SocketServer & socket); + /// Constructeur prenant une adresse (cas d'un client) + GSTransmitter(const std::string & address, int port); /// Récupère une grosse string int getGS(GSMessage & gsm); /// envoie une grosse string diff --git a/i/simulotron/src/gs/test_gs.cc b/i/simulotron/src/gs/test_gs.cc index 108c000..7416949 100644 --- a/i/simulotron/src/gs/test_gs.cc +++ b/i/simulotron/src/gs/test_gs.cc @@ -23,20 +23,14 @@ * * }}} */ -#include "socket/address.hh" #include "socket/socket_server.hh" -#include "socket/socket_client.hh" #include "gs/gs_transmitter.hh" #include "gs/gs_message.hh" -#include "utils/errno_exception.hh" +#include #include -#include #include -// Adress useful -Address adr; -Address adr2; //Chaine et char de test const std::string strDepart = "J'aime la prog système."; std::string strDest; @@ -62,7 +56,7 @@ int main(void) //retour des test int resultClient, resultServer; // Création de la socket serveur; - SocketServer sockServ(Address(4242)); + SocketServer sockServ(std::string(),4242); // Mise en écoute du socket serveur sockServ.listen(12); // On crée le fork du client @@ -90,10 +84,8 @@ int main(void) int testGSServer(SocketServer & sockServ) { - // Acceptation d'une connection - SocketClient sockFork(sockServ); // Création du transmitter - GSTransmitter gst(sockFork); + GSTransmitter gst(sockServ); // Reception des messages // une string GSMessage gsm; @@ -205,29 +197,25 @@ void testGSClient(int pauseMode) sleep (10); try { - // Création de la socket client - SocketClient sockClient; - // Demande de connection - sockClient.connect(Address(std::string("localhost"), 4242)); // Création du transmitter - GSTransmitter gst(sockClient); + GSTransmitter gst(std::string("127.0.0.1"), 4242); GSMessage g1,g2,g3,g4,g5,g6,g7; - g1.writeGS(strDepart.data(), strDepart.size()); + g1.appendGS(strDepart.data(), strDepart.size()); gst.putGS(g1); - g2.writeGS(&a, sizeof(char)); + g2.appendGS(&a, sizeof(char)); gst.putGS(g2); - g3.writeGS(&s1, sizeof(short)); + g3.appendGS(&s1, sizeof(short)); gst.putGS(g3); - g4.writeGS(&i1, sizeof(int)); + g4.appendGS(&i1, sizeof(int)); gst.putGS(g4); - g5.writeGS(&i3, sizeof(int)); + g5.appendGS(&i3, sizeof(int)); gst.putGS(g5); - g6.writeGS(&l1, sizeof(long)); + g6.appendGS(&l1, sizeof(long)); gst.putGS(g6); - g7.writeGS(&s1, sizeof(short)); - g7.writeGS(&l1, sizeof(long)); - g7.writeGS(&i3, sizeof(int)); + g7.appendGS(&l1, sizeof(long)); + g7.insertFrontGS(&s1, sizeof(short)); + g7.appendGS(&i3, sizeof(int)); gst.putGS(g7); } catch(std::exception & chier) -- cgit v1.2.3