This commit is contained in:
glenux 2006-02-05 18:24:11 +00:00
parent 36b156e5de
commit 38ae9f71b3
6 changed files with 74 additions and 34 deletions

View file

@ -8,6 +8,7 @@ using namespace std;
Config::Config(int argc, char **argv) { Config::Config(int argc, char **argv) {
_port = -1; _port = -1;
_index = -1;
_mode = Protocol::TYPE_UNKNOWN; _mode = Protocol::TYPE_UNKNOWN;
int groupPort; int groupPort;
@ -22,13 +23,14 @@ Config::Config(int argc, char **argv) {
{"group", required_argument, 0, 'g'}, {"group", required_argument, 0, 'g'},
{"port", required_argument, 0, 'p'}, {"port", required_argument, 0, 'p'},
{"index", required_argument, 0, 'i'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
int option_index = 0; int option_index = 0;
int c = getopt_long(argc, argv, "TACg:p:", int c = getopt_long(argc, argv, "TACg:p:i:",
long_options, &option_index); long_options, &option_index);
/* detect the end of options */ /* detect the end of options */
@ -55,6 +57,15 @@ Config::Config(int argc, char **argv) {
_mode = Protocol::TYPE_TEST; _mode = Protocol::TYPE_TEST;
break; break;
} }
case 'i':
{
stringstream s;
printf("Index -> %s\n",optarg);
s << string(optarg);
s >> _index;
}
break;
case 'p': case 'p':
{ {
stringstream s; stringstream s;
@ -111,6 +122,11 @@ bool Config::isValid() {
} }
valid++; valid++;
if (_index > 0) {
score++;
}
valid++;
return (valid == score); return (valid == score);
} }
@ -122,6 +138,10 @@ Protocol::Type Config::getMode(){
return _mode; return _mode;
} }
short Config::getIndex(){
return _index;
}
int Config::getPort(){ int Config::getPort(){
return _port; return _port;
} }

View file

@ -14,6 +14,7 @@ class Config {
std::list<HostId> _group_hosts; std::list<HostId> _group_hosts;
int _port; int _port;
Protocol::Type _mode; Protocol::Type _mode;
short _index;
protected: protected:
@ -25,6 +26,7 @@ class Config {
bool isValid(); bool isValid();
std::list<HostId> getGroupHosts(); std::list<HostId> getGroupHosts();
int getPort(); int getPort();
short getIndex();
Protocol::Type getMode(); Protocol::Type getMode();
}; };
#endif // _GYR_CONFIG_H #endif // _GYR_CONFIG_H

View file

@ -26,11 +26,11 @@ int main(int argc, char ** argv){
if (config.isValid()){ if (config.isValid()){
Glib::thread_init(); Glib::thread_init();
Group grp(config.getGroupHosts()); Group grp(config.getGroupHosts(), config.getIndex());
Clock * clk; Clock * clk;
//FIXME non-dynamic port ! //FIXME non-dynamic port !
int portHigh = 2310; int portHigh = 2710;
switch(config.getMode()){ switch(config.getMode()){
case Protocol::TYPE_TEST: case Protocol::TYPE_TEST:

View file

@ -5,9 +5,10 @@
#define DEBUG 0 #define DEBUG 0
Group::Group(std::list<HostId> group){ Group::Group(std::list<HostId> group, short index){
_hosts = group; _hosts = group;
_socket_desc = socket(AF_INET, SOCK_DGRAM, 0); _socket_desc = socket(AF_INET, SOCK_DGRAM, 0);
_index = index;
/* et l'autre variante : AF_UNIX */ /* et l'autre variante : AF_UNIX */
if (_socket_desc < 0){ if (_socket_desc < 0){
@ -79,8 +80,11 @@ void Group::broadcast(Message & msg){
printf("Group::broadcast -- exit\n"); printf("Group::broadcast -- exit\n");
} }
short Group::getIndex(){
return _index;
}
void Group::sendto(Message &msg, int index){ void Group::sendto(Message &msg, short index){
sockaddr_in * addr = _addrs[index]; sockaddr_in * addr = _addrs[index];
if (DEBUG) if (DEBUG)

View file

@ -27,13 +27,16 @@ class Group {
std::list<HostId> _hosts; std::list<HostId> _hosts;
std::vector<sockaddr_in *> _addrs; std::vector<sockaddr_in *> _addrs;
int _socket_desc; int _socket_desc;
short _index;
protected: protected:
public: public:
Group(std::list<HostId> group); Group(std::list<HostId> group, short myindex);
void sendto(Message &msg, int index); void sendto(Message &msg, short index);
void broadcast(Message &msg); void broadcast(Message &msg);
short getIndex();
}; };
#endif #endif

View file

@ -110,9 +110,19 @@ void LowReceiver::manage_abcast(Message * mesg) {
std::list<MessageCellAb *>::iterator iter; std::list<MessageCellAb *>::iterator iter;
printf("LowReceiver::manage_abcast -- init\n"); printf("LowReceiver::manage_abcast -- init\n");
// FIXME: on suppose ne pas etre l'emetteur
// identifiant = horloge + id_site_emeteur // identifiant = horloge + id_site_emeteur
bool firstSeenMessage = true; bool firstSeenMessage = true;
bool iAmTheEmitter = false;
if (mesg->getStamp().getIndex() == _group.getIndex()){
iAmTheEmitter = true;
}
if (iAmTheEmitter){
printf("LowReceiver::manage_abcast - Received my own message \n");
//FIXME: faire la gestion du abcast/send ici, c'est plus simple que
//de partager une variable+mutex avec le sender
} else {
for (iter = fifo.begin(); iter != fifo.end(); iter++){ for (iter = fifo.begin(); iter != fifo.end(); iter++){
MessageCellAb * cur = *iter; MessageCellAb * cur = *iter;
if (cur->message == mesg) { if (cur->message == mesg) {
@ -133,11 +143,12 @@ void LowReceiver::manage_abcast(Message * mesg) {
} else { } else {
// sinon // sinon
// - l'estampille du message est mise a jour // - l'estampille du message est mise a jour
TimeStamp * stamp = new TimeStamp (Protocol::TYPE_ABCAST, cell->message->getData(), cell->message->getDataSize()); TimeStamp * stamp = new TimeStamp (Protocol::TYPE_ABCAST, mesg->getData(), mesg->getDataSize());
// - le message est marqué comme final // - le message est marqué comme final
// - on défile les estampille finale la // - on défile les estampille finale la
} }
}
} }
void LowReceiver::manage_cbcast(Message * mesg) { void LowReceiver::manage_cbcast(Message * mesg) {