From 614da7f1a522dc1f234269d3f6422542758ac928 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:38 +0000 Subject: Utilisateur : Fcolin Date : 16/06/00 Heure : 10:14 Créé (vss 1) --- Ivy/IvyWatcher.cxx | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Ivy/IvyWatcher.cxx (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx new file mode 100644 index 0000000..c963968 --- /dev/null +++ b/Ivy/IvyWatcher.cxx @@ -0,0 +1,114 @@ +// IvyWatcher.cpp : implementation file +// + +#include "stdafx.h" + +#include "IvyWatcher.h" +#include "IvyApplication.h" + +///////////////////////////////////////////////////////////////////////////// +// IvyWatcher + + +#define VERSION 3 + +IvyWatcher::IvyWatcher(Ivy * bus) +{ + this->bus = bus; +} +IvyWatcher::~IvyWatcher() +{ +} + + + +///////////////////////////////////////////////////////////////////////////// +// IvyWatcher member functions + +void IvyWatcher::OnReceive(int nErrorCode) +{ + int err; + int version; + char buffer[256]; + string remotehost; + UINT remoteport; + UINT serviceport; + + + err = ReceiveFrom( buffer, sizeof(buffer), remotehost, remoteport ); + if ( err == SOCKET_ERROR ) + { + TRACE("Receive Broadcast error %d\n",GetLastError()); + return; + } + buffer[err] ='\0'; + err = sscanf(buffer,"%d %u",&version, &serviceport); + if ( err != 2 ) + { + /* ignore the message */ + TRACE(" Bad Supervision message expected 'version port'\n"); + return; + } + if ( version != VERSION ) + { + /* ignore the message */ + TRACE(" Bad Ivy verion number expected %d receive %d from %s:%d\n", VERSION,version, remotehost, remoteport); + return; + } + /* check if we receive our own message should test also the host */ + if ( serviceport == bus->GetApplicationPort() /*&& remotehost == "localhost"*/) return; + TRACE(" Broadcast de %s:%u port %u\n", remotehost.c_str(), remoteport, serviceport ); + + /* connect to the service and send the regexp */ + IvyApplication *newapp = new IvyApplication(bus); + // exception to catch + newapp->Create(remotehost.c_str(), serviceport); + // delete newapp; + // return; + + bus->AddApplication( newapp ); + TRACE(" Connecting to %s:%u\n", remotehost.c_str(), serviceport ); + +} + +void IvyWatcher::start(const char *domainlist) +{ + BOOL reuse = TRUE; + string domain; + UINT port; + // determine domain to use + domain = bus->GetDomain( domainlist ); + + // first find our UDP port + int sep_index = domain.rfind( ':' ); + if ( sep_index != -1 ) + { + port = atoi ( domain.substr( sep_index +1 ).c_str() ); + // supress port number from end of domain list + domain.erase( sep_index, domain.length() - sep_index ); + } + // create UDP receiver + // catch exception !!! + Socket(SOCK_DGRAM); + SetSockOpt( SO_REUSEADDR, &reuse, sizeof(BOOL) ); + Bind(port); + + string addr; + char hello[1024]; + int len = sprintf( hello, "%d %u\n", VERSION, bus->GetApplicationPort() ); + + // send broadcast to domain list + while ( !domain.empty() ) + { + // find addr up to separator + int index = domain.find_first_of( ", \t" ); + addr = domain.substr( 0, index ); + domain.erase( 0, addr.length() +1 ); + TRACE("Ivy Broadcasting on %s:%d\n", addr.c_str(), port ); + SendTo( hello, len, port, addr.c_str() ); + } +} +void IvyWatcher::stop() +{ + Close(); +} -- cgit v1.1 From 95b2373c6e00b8a57e88008c934634bd8e2e17bd Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:40 +0000 Subject: Utilisateur : Fcolin Date : 29/06/00 Heure : 15:59 Archivé dans $/Ivy Commentaire: Version multicast (vss 2) --- Ivy/IvyWatcher.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index c963968..099e670 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -105,6 +105,7 @@ void IvyWatcher::start(const char *domainlist) addr = domain.substr( 0, index ); domain.erase( 0, addr.length() +1 ); TRACE("Ivy Broadcasting on %s:%d\n", addr.c_str(), port ); + AddMember( addr.c_str() ); SendTo( hello, len, port, addr.c_str() ); } } -- cgit v1.1 From 0c05305dc38012e87d470b972cf88aef26f71425 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:42 +0000 Subject: Utilisateur : Fcolin Date : 23/01/01 Heure : 13:12 Archivé dans $/Ivy Commentaire: remove 'using name space std;' (vss 3) --- Ivy/IvyWatcher.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index 099e670..a363bdc 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -30,7 +30,7 @@ void IvyWatcher::OnReceive(int nErrorCode) int err; int version; char buffer[256]; - string remotehost; + String remotehost; UINT remoteport; UINT serviceport; @@ -74,7 +74,7 @@ void IvyWatcher::OnReceive(int nErrorCode) void IvyWatcher::start(const char *domainlist) { BOOL reuse = TRUE; - string domain; + String domain; UINT port; // determine domain to use domain = bus->GetDomain( domainlist ); @@ -93,7 +93,7 @@ void IvyWatcher::start(const char *domainlist) SetSockOpt( SO_REUSEADDR, &reuse, sizeof(BOOL) ); Bind(port); - string addr; + String addr; char hello[1024]; int len = sprintf( hello, "%d %u\n", VERSION, bus->GetApplicationPort() ); -- cgit v1.1 From a30fc57b42e9b6846aab57d41f34291da563bdaa Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:44 +0000 Subject: Utilisateur : Fcolin Date : 31/01/01 Heure : 11:18 Archivé dans $/Ivy (vss 4) --- Ivy/IvyWatcher.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index a363bdc..099e670 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -30,7 +30,7 @@ void IvyWatcher::OnReceive(int nErrorCode) int err; int version; char buffer[256]; - String remotehost; + string remotehost; UINT remoteport; UINT serviceport; @@ -74,7 +74,7 @@ void IvyWatcher::OnReceive(int nErrorCode) void IvyWatcher::start(const char *domainlist) { BOOL reuse = TRUE; - String domain; + string domain; UINT port; // determine domain to use domain = bus->GetDomain( domainlist ); @@ -93,7 +93,7 @@ void IvyWatcher::start(const char *domainlist) SetSockOpt( SO_REUSEADDR, &reuse, sizeof(BOOL) ); Bind(port); - String addr; + string addr; char hello[1024]; int len = sprintf( hello, "%d %u\n", VERSION, bus->GetApplicationPort() ); -- cgit v1.1 From db65e6f46e6394f813148f179a08573752f5c220 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:46 +0000 Subject: Utilisateur : Fcolin Date : 2/02/01 Heure : 18:30 Archivé dans $/Ivy Commentaire: win CE compile not finished (vss 5) --- Ivy/IvyWatcher.cxx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index 099e670..8bd46bf 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -3,6 +3,11 @@ #include "stdafx.h" +#ifdef _DEBUG +#define DEBUG_NEW new(__FILE__, __LINE__) +#define new DEBUG_NEW +#endif + #include "IvyWatcher.h" #include "IvyApplication.h" -- cgit v1.1 From 0944a08b5666a732ce74d888b34d8b3f3cca4535 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:48 +0000 Subject: Utilisateur : Fcolin Date : 23/05/01 Heure : 10:25 Archivé dans $/Ivy (vss 6) --- Ivy/IvyWatcher.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index 8bd46bf..57f054c 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -43,7 +43,7 @@ void IvyWatcher::OnReceive(int nErrorCode) err = ReceiveFrom( buffer, sizeof(buffer), remotehost, remoteport ); if ( err == SOCKET_ERROR ) { - TRACE("Receive Broadcast error %d\n",GetLastError()); + TRACE("Receive Broadcast error %d\n",this->GetLastError()); return; } buffer[err] ='\0'; -- cgit v1.1 From d0988d727ee447c4a268644b36c93ba572205f82 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:50 +0000 Subject: Utilisateur : Fcolin Date : 17/07/01 Heure : 18:25 Archivé dans $/Ivy (vss 7) --- Ivy/IvyWatcher.cxx | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index 57f054c..4101d11 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -3,10 +3,6 @@ #include "stdafx.h" -#ifdef _DEBUG -#define DEBUG_NEW new(__FILE__, __LINE__) -#define new DEBUG_NEW -#endif #include "IvyWatcher.h" #include "IvyApplication.h" -- cgit v1.1 From 013d410ea25c166272b79a452155be6190c4862c Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:52 +0000 Subject: Utilisateur : Fcolin Date : 17/09/01 Heure : 15:46 Archivé dans $/Ivy Commentaire: manque start listener pour UDP socket (vss 8) --- Ivy/IvyWatcher.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index 4101d11..d20bfa3 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -93,6 +93,7 @@ void IvyWatcher::start(const char *domainlist) Socket(SOCK_DGRAM); SetSockOpt( SO_REUSEADDR, &reuse, sizeof(BOOL) ); Bind(port); + StartListener(); string addr; char hello[1024]; -- cgit v1.1 From 84c5a1c5084da8841b3de03cd07db6ceb7cbbdf8 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:54 +0000 Subject: Utilisateur : Fcolin Date : 19/06/02 Heure : 15:14 Archivé dans $/Ivy (vss 9) --- Ivy/IvyWatcher.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index d20bfa3..8df0ac4 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -76,7 +76,7 @@ void IvyWatcher::start(const char *domainlist) { BOOL reuse = TRUE; string domain; - UINT port; + UINT port=0; // determine domain to use domain = bus->GetDomain( domainlist ); -- cgit v1.1 From efde241a613f12c035898c99eb7595a97f8fe06d Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:56 +0000 Subject: Utilisateur : Fcolin Date : 1/06/05 Heure : 16:45 Archivé dans $/Bus/Ivy Commentaire: (vss 10) --- Ivy/IvyWatcher.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index 8df0ac4..af19fe5 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -1,7 +1,7 @@ // IvyWatcher.cpp : implementation file // -#include "stdafx.h" +#include "IvyStdAfx.h" #include "IvyWatcher.h" @@ -97,7 +97,7 @@ void IvyWatcher::start(const char *domainlist) string addr; char hello[1024]; - int len = sprintf( hello, "%d %u\n", VERSION, bus->GetApplicationPort() ); + int len = _snprintf( hello, sizeof(hello), "%d %u\n", VERSION, bus->GetApplicationPort() ); // send broadcast to domain list while ( !domain.empty() ) -- cgit v1.1 From c7b04986097c2c4fa6e0d9ad00bdaf5dff9cdeec Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:03:58 +0000 Subject: Utilisateur : Fcolin Date : 2/06/05 Heure : 18:42 Archivé dans $/Bus/Ivy Commentaire: Suppression de la STL et ajout d'un namespace pour les datatypes internes Ivy (vss 11) --- Ivy/IvyWatcher.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index af19fe5..424c8ac 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -31,7 +31,7 @@ void IvyWatcher::OnReceive(int nErrorCode) int err; int version; char buffer[256]; - string remotehost; + ivy::string remotehost; UINT remoteport; UINT serviceport; @@ -53,7 +53,7 @@ void IvyWatcher::OnReceive(int nErrorCode) if ( version != VERSION ) { /* ignore the message */ - TRACE(" Bad Ivy verion number expected %d receive %d from %s:%d\n", VERSION,version, remotehost, remoteport); + TRACE(" Bad Ivy verion number expected %d receive %d from %s:%d\n", VERSION,version, remotehost.c_str(), remoteport); return; } /* check if we receive our own message should test also the host */ @@ -75,7 +75,7 @@ void IvyWatcher::OnReceive(int nErrorCode) void IvyWatcher::start(const char *domainlist) { BOOL reuse = TRUE; - string domain; + ivy::string domain; UINT port=0; // determine domain to use domain = bus->GetDomain( domainlist ); @@ -95,7 +95,7 @@ void IvyWatcher::start(const char *domainlist) Bind(port); StartListener(); - string addr; + ivy::string addr; char hello[1024]; int len = _snprintf( hello, sizeof(hello), "%d %u\n", VERSION, bus->GetApplicationPort() ); -- cgit v1.1 From f67017bf198b8d5cce6cbe7823a20e052e12b3d6 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:04:00 +0000 Subject: Utilisateur : Fcolin Date : 23/09/05 Heure : 15:27 Archivé dans $/Bus/Ivy Commentaire: (vss 12) --- Ivy/IvyWatcher.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index 424c8ac..4faca90 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -28,7 +28,7 @@ IvyWatcher::~IvyWatcher() void IvyWatcher::OnReceive(int nErrorCode) { - int err; + size_t err; int version; char buffer[256]; ivy::string remotehost; @@ -81,7 +81,7 @@ void IvyWatcher::start(const char *domainlist) domain = bus->GetDomain( domainlist ); // first find our UDP port - int sep_index = domain.rfind( ':' ); + size_t sep_index = domain.rfind( ':' ); if ( sep_index != -1 ) { port = atoi ( domain.substr( sep_index +1 ).c_str() ); @@ -103,7 +103,7 @@ void IvyWatcher::start(const char *domainlist) while ( !domain.empty() ) { // find addr up to separator - int index = domain.find_first_of( ", \t" ); + size_t index = domain.find_first_of( ", \t" ); addr = domain.substr( 0, index ); domain.erase( 0, addr.length() +1 ); TRACE("Ivy Broadcasting on %s:%d\n", addr.c_str(), port ); -- cgit v1.1 From f7cffc1477ac2dffa98bca7f9cd5b589ef62f00d Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:04:02 +0000 Subject: Utilisateur : Fcolin Date : 16/11/05 Heure : 9:54 Archivé dans $/Bus/Ivy Commentaire: 64 bits ports (vss 13) --- Ivy/IvyWatcher.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index 4faca90..d9f8cf8 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -43,7 +43,7 @@ void IvyWatcher::OnReceive(int nErrorCode) return; } buffer[err] ='\0'; - err = sscanf(buffer,"%d %u",&version, &serviceport); + err = sscanf_s(buffer,"%d %u",&version, &serviceport); if ( err != 2 ) { /* ignore the message */ @@ -97,7 +97,7 @@ void IvyWatcher::start(const char *domainlist) ivy::string addr; char hello[1024]; - int len = _snprintf( hello, sizeof(hello), "%d %u\n", VERSION, bus->GetApplicationPort() ); + int len = _snprintf_s( hello, sizeof(hello), sizeof(hello)-1, "%d %u\n", VERSION, bus->GetApplicationPort() ); // send broadcast to domain list while ( !domain.empty() ) -- cgit v1.1 From 2ee1ed697edc42aae7962877a5649e2c280741b8 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:04:04 +0000 Subject: Utilisateur : Fcolin Date : 19/04/06 Heure : 15:07 Archivé dans $/Bus/Ivy Commentaire: (vss 14) --- Ivy/IvyWatcher.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index d9f8cf8..e2a2783 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -42,7 +42,7 @@ void IvyWatcher::OnReceive(int nErrorCode) TRACE("Receive Broadcast error %d\n",this->GetLastError()); return; } - buffer[err] ='\0'; + if ( err < 255 ) buffer[err] ='\0'; err = sscanf_s(buffer,"%d %u",&version, &serviceport); if ( err != 2 ) { -- cgit v1.1 From a590fa8d95a798b1a4f750ed9b5b85e9e642e701 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:04:06 +0000 Subject: Utilisateur : Fcolin Date : 23/05/06 Heure : 18:18 Archivé dans $/Bus/Ivy Commentaire: Modification protocol UDP (vss 15) --- Ivy/IvyWatcher.cxx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'Ivy/IvyWatcher.cxx') diff --git a/Ivy/IvyWatcher.cxx b/Ivy/IvyWatcher.cxx index e2a2783..4cbf604 100644 --- a/Ivy/IvyWatcher.cxx +++ b/Ivy/IvyWatcher.cxx @@ -30,12 +30,16 @@ void IvyWatcher::OnReceive(int nErrorCode) { size_t err; int version; - char buffer[256]; + char buffer[2048]; ivy::string remotehost; UINT remoteport; UINT serviceport; + char appid[2048]; + char appname[2048]; - + memset( appid, 0, sizeof( appid ) ); + memset( appname, 0, sizeof( appname ) ); + err = ReceiveFrom( buffer, sizeof(buffer), remotehost, remoteport ); if ( err == SOCKET_ERROR ) { @@ -43,8 +47,8 @@ void IvyWatcher::OnReceive(int nErrorCode) return; } if ( err < 255 ) buffer[err] ='\0'; - err = sscanf_s(buffer,"%d %u",&version, &serviceport); - if ( err != 2 ) + err = sscanf_s(buffer,"%d %u %s %[^\n]",&version, &serviceport,appid, sizeof(appid), appname,sizeof(appname)); + if ( err < 2 ) { /* ignore the message */ TRACE(" Bad Supervision message expected 'version port'\n"); @@ -56,6 +60,9 @@ void IvyWatcher::OnReceive(int nErrorCode) TRACE(" Bad Ivy verion number expected %d receive %d from %s:%d\n", VERSION,version, remotehost.c_str(), remoteport); return; } + /* check if we received our own message. SHOULD ALSO TEST THE HOST */ + if ( strcmp( appid , bus->ApplicationID.c_str()) ==0 ) return; + /* check if we receive our own message should test also the host */ if ( serviceport == bus->GetApplicationPort() /*&& remotehost == "localhost"*/) return; TRACE(" Broadcast de %s:%u port %u\n", remotehost.c_str(), remoteport, serviceport ); @@ -63,7 +70,7 @@ void IvyWatcher::OnReceive(int nErrorCode) /* connect to the service and send the regexp */ IvyApplication *newapp = new IvyApplication(bus); // exception to catch - newapp->Create(remotehost.c_str(), serviceport); + newapp->Create(remotehost.c_str(), serviceport, appname ); // delete newapp; // return; @@ -96,8 +103,8 @@ void IvyWatcher::start(const char *domainlist) StartListener(); ivy::string addr; - char hello[1024]; - int len = _snprintf_s( hello, sizeof(hello), sizeof(hello)-1, "%d %u\n", VERSION, bus->GetApplicationPort() ); + char hello[2048]; + int len = _snprintf_s( hello, sizeof(hello), sizeof(hello)-1, "%d %u %s %s\n", VERSION, bus->GetApplicationPort(), bus->ApplicationID.c_str(), bus->ApplicationName.c_str() ); // send broadcast to domain list while ( !domain.empty() ) -- cgit v1.1