From 56cc59cf44ec64440ba4d1c0d005196195c758e6 Mon Sep 17 00:00:00 2001 From: hugues Date: Sat, 25 Mar 2006 15:07:51 +0000 Subject: Nettoyage du repository glagen git-svn-id: file:///usr/local/opt/svn/repos/glagen@12 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c --- algo_distribue/network/data/Data.cc | 1 + algo_distribue/network/data/Data.hh | 78 +++++++++++++++++++++++++++++ algo_distribue/network/data/Data_exemple.cc | 1 + algo_distribue/network/data/Data_exemple.hh | 66 ++++++++++++++++++++++++ algo_distribue/network/data/Data_string.cc | 1 + algo_distribue/network/data/Data_string.hh | 60 ++++++++++++++++++++++ 6 files changed, 207 insertions(+) create mode 100644 algo_distribue/network/data/Data.cc create mode 100644 algo_distribue/network/data/Data.hh create mode 100644 algo_distribue/network/data/Data_exemple.cc create mode 100644 algo_distribue/network/data/Data_exemple.hh create mode 100644 algo_distribue/network/data/Data_string.cc create mode 100644 algo_distribue/network/data/Data_string.hh (limited to 'algo_distribue/network/data') diff --git a/algo_distribue/network/data/Data.cc b/algo_distribue/network/data/Data.cc new file mode 100644 index 0000000..d3bbe6a --- /dev/null +++ b/algo_distribue/network/data/Data.cc @@ -0,0 +1 @@ +#include "Data.hh" diff --git a/algo_distribue/network/data/Data.hh b/algo_distribue/network/data/Data.hh new file mode 100644 index 0000000..3b630ff --- /dev/null +++ b/algo_distribue/network/data/Data.hh @@ -0,0 +1,78 @@ +// Classe Data + +// Dans le TYPEDATA, il faut l'implementation de toString (retourne un string) +// et de type (retourne unsigned short int) + +// Type 0: char +// Type 1: unsigned char +// Type 2: int +// Type 3: unsigned int +// Type 4: short int +// Type 5: unsigned short int +// Type 6: long int +// Type 7: unsigned long int +// Type 8: float +// Type 9: double +// Type 10: long double + +#ifndef DATA_HH_ +# define DATA_HH_ + +#include +#include +#include + +#include + +template class Data +{ +public: + Data() : _data(new std::list) {}; + + Data(std::list* data) : _data(data) {}; + + void error() + { + perror(""); + exit(errno); + } + + void add_data(const TYPEDATA& data) { _data->push_back(data); }; + + void send(const int& fd) const + { + std::list::iterator data = _data->begin(); + unsigned int size = _data->size(); + std::cout << "Taille a ecrire:" << size << std::endl; + write(fd, &size, sizeof(unsigned int)); + for (; data != _data->end(); ++data) + data->write_data(fd); + } + + void receive(const int& fd) + { + unsigned int size = 0; + do + { + errno = 0; + read(fd, &size, sizeof(unsigned int)); + } + while(errno == 4); + if (errno) + this->error(); + std::cout << "Taille lu: " << size << std::endl; + TYPEDATA data; + for (unsigned int i = 0; i < size; ++i) + { + data.read_data(fd); + _data->push_back(data); + } + } + + std::list* get_data() { return (_data); } + +private: + std::list* _data; +}; + +#endif // DATA_HH_ diff --git a/algo_distribue/network/data/Data_exemple.cc b/algo_distribue/network/data/Data_exemple.cc new file mode 100644 index 0000000..9578493 --- /dev/null +++ b/algo_distribue/network/data/Data_exemple.cc @@ -0,0 +1 @@ +#include "Data_exemple.hh" diff --git a/algo_distribue/network/data/Data_exemple.hh b/algo_distribue/network/data/Data_exemple.hh new file mode 100644 index 0000000..ca1291b --- /dev/null +++ b/algo_distribue/network/data/Data_exemple.hh @@ -0,0 +1,66 @@ +// Classe Data_exemple + +// Un exemple sur un point de coordonnees 3D + +#ifndef DATA_EXEMPLE_HH_ +# define DATA_EXEMPLE_HH_ + +#include +#include // Pour write/read + +#include + +class Data_exemple +{ +public: + Data_exemple() : _x(0), _y(0), _z(0) {}; + Data_exemple(int x, int y, int z) : _x(x), _y(y), _z(z) {}; + + void write_data(const int& fd) const + { + std::cout << "Donnees envoyes au serveur" << std::endl; + std::cout << _x << std::endl; + std::cout << _y << std::endl; + std::cout << _z << std::endl; + write(fd, &_x, sizeof(int)); + write(fd, &_y, sizeof(int)); + write(fd, &_z, sizeof(int)); + } + + void read_data(const int& fd) + { + do + { + errno = 0; + read(fd, &_x, sizeof(int)); + } + while (errno == 4); + + do + { + errno = 0; + read(fd, &_y, sizeof(int)); + } + while (errno == 4); + + do + { + errno = 0; + read(fd, &_z, sizeof(int)); + } + while (errno == 4); + + std::cout << "Reception message sur le file descriptor :" << fd + << std::endl; + std::cout << _x << std::endl; + std::cout << _y << std::endl; + std::cout << _z << std::endl; + } + +private: + int _x; + int _y; + int _z; +}; + +#endif // DATA_EXEMPLE diff --git a/algo_distribue/network/data/Data_string.cc b/algo_distribue/network/data/Data_string.cc new file mode 100644 index 0000000..9578493 --- /dev/null +++ b/algo_distribue/network/data/Data_string.cc @@ -0,0 +1 @@ +#include "Data_exemple.hh" diff --git a/algo_distribue/network/data/Data_string.hh b/algo_distribue/network/data/Data_string.hh new file mode 100644 index 0000000..a395725 --- /dev/null +++ b/algo_distribue/network/data/Data_string.hh @@ -0,0 +1,60 @@ +#ifndef DATA_STRING_HH_ +# define DATA_STRING_HH_ + +#include +#include +#include // Pour write/read + +#include + +class Data_string +{ +public: + Data_string() : _str("") {}; + Data_string(const string& str) : _str(str) {}; + + void write_data(const int& fd) const + { + + std::cout << "Donnees envoyes" << std::endl << _str << std::endl; + unsigned int size = _str.size(); + write(fd, &size, sizeof(unsigned int)); + for (unsigned int i = 0; i < size; ++i) + { + char car = _str[i]; + write(fd, &car, sizeof(char)); + } + } + + void read_data(const int& fd) + { + unsigned int size = 0; + do + { + errno = 0; + read(fd, &size, sizeof(size)); + } + while (errno == 4); + + _str = ""; + for (unsigned int i = 0; i < size; ++i) + { + char car; + do + { + errno = 0; + read(fd, &car, sizeof(char)); + } + while (errno == 4); + _str += car; + } + + std::cout << "Reception message sur le file descriptor :" << fd + << std::endl << _str << std::endl; + } + +private: + string _str; +}; + +#endif // DATA_STRING -- cgit v1.2.3