summaryrefslogtreecommitdiff
path: root/Ivy/Ivy.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Ivy/Ivy.cxx')
-rw-r--r--Ivy/Ivy.cxx43
1 files changed, 30 insertions, 13 deletions
diff --git a/Ivy/Ivy.cxx b/Ivy/Ivy.cxx
index fa1021d..fe05e7d 100644
--- a/Ivy/Ivy.cxx
+++ b/Ivy/Ivy.cxx
@@ -86,7 +86,7 @@ const char *Ivy::GenApplicationUniqueIdentifier()
unsigned long curtime;
curtime = GetTickCount();
srand( curtime );
- sprintf(appid,"%d:%lu:%d",rand(),curtime,applicationPort);
+ sprintf_s(appid,sizeof(appid),"%d:%lu:%d",rand(),curtime,applicationPort);
return appid;
}
@@ -133,20 +133,30 @@ const char * Ivy::GetDomain(const char *domainlist)
void Ivy::start(const char *domain)
{
+ if ( watcher->IsRunning() )
+ {
+ Ivy::stop();
+ }
watcher->start(domain);
}
void Ivy::stop()
{
watcher->stop();
+ EnterCriticalSection( &m_application_cs );
IvyApplicationList::iterator iter;
- for ( iter = applications.begin() ; iter != applications.end() ; ++iter )
+ IvyApplicationList copy_applications;
+ copy_applications = applications;
+ applications.clear();
+ LeaveCriticalSection( &m_application_cs );
+
+ for ( iter = copy_applications.begin() ; iter != copy_applications.end() ; ++iter )
{
IvyApplication *app = *iter;
app->Close();
delete app;
}
- applications.clear();
+
}
int Ivy::BindMsg(const char *regexp, IvyMessageCallback *cb)
{
@@ -260,13 +270,14 @@ void Ivy::AddApplication(IvyApplication *app)
}
void Ivy::RemoveApplication(IvyApplication * app)
{
- /// OLD NOT called because of deallocation PB
+ /// OLD NOT called because of deallocation PB
+ // when self application close !!
// the real remove is done at arrival of a new Application
// or at the bus Stop
TRACE( "Ivy::RemoveApplication %lu\n", app );
+ ASSERT( true );
if ( app )
{
-
EnterCriticalSection( &m_application_cs );
applications.remove( app );
LeaveCriticalSection( &m_application_cs );
@@ -408,24 +419,30 @@ void Ivy::SetFilter(int argc, const char **argv )
IvyApplication * Ivy::CheckConnected(IvyApplication * app)
{
+ IvyApplication *application = 0;
if (app->remoteService == 0) /* old application dont check */
- return 0;
+ return application;
/* check to see if app already connected */
+ EnterCriticalSection( &m_application_cs );
IvyApplicationList::iterator iter;
for ( iter = applications.begin() ; iter != applications.end() ; ++iter )
{
- IvyApplication *application = *iter;
- if ( application != app && application->SameApplication(app))
- return application;
+ IvyApplication *other = *iter;
+ if ( other != app && other->SameApplication(app))
+ {
+ application = other;
+ break;
+ }
}
- return 0;
+ LeaveCriticalSection( &m_application_cs );
+ return application;
}
void Ivy::SubstituteInterval (const char *src, char *dst, size_t dst_len)
{
// pas de traitement couteux s'il n'y a rien à interpoler
if (strstr (src, "(?I") == NULL) {
- strcpy (dst,src);
+ strcpy_s (dst,dst_len,src);
return;
} else {
char *curPos;
@@ -443,7 +460,7 @@ void Ivy::SubstituteInterval (const char *src, char *dst, size_t dst_len)
dstPos += lenCp;
// extraction des paramètres de l'intervalle
- sscanf (itvPos, "(?I%d#%d%c", &min, &max, &withDecimal);
+ sscanf_s (itvPos, "(?I%d#%d%c", &min, &max, &withDecimal);
// printf ("DBG> substituteInterval min=%d max=%d withDecimal=%d\n",
// min, max, (withDecimal != 'i'));
@@ -456,7 +473,7 @@ void Ivy::SubstituteInterval (const char *src, char *dst, size_t dst_len)
curPos = strstr (curPos, ")");
curPos++;
}
- strncat (dstPos, curPos, dst_len-(dstPos-dst));
+ strncat_s (dstPos,dst_len-( dst-dstPos), curPos, dst_len-(dstPos-dst));
}
}