@@ -66,13 +66,13 @@ errorCode Broker::addDataConnector(MetaDataConnector *dataConnector)
6666 return 0 ;
6767}
6868
69- errorCode Broker::addImageConnector (ImageConnector *imageConnector)
69+ errorCode Broker::addImageConnector (ImageConnector *imageConnector, int id )
7070{
7171 imageConnector->setBroker (this );
7272 ImageConnectorContainer d;
7373 d.connector = imageConnector;
7474 d.thread = 0 ;
75- imageConnectorList. push_back (d) ;
75+ imageConnectorList[id] = d ;
7676 if (imageConnector->showClient )
7777 {
7878 json_t * element = json_object ();
@@ -294,8 +294,8 @@ errorCode Broker::run()
294294 }
295295 for (auto it = imageConnectorList.begin (); it != imageConnectorList.end (); it++)
296296 {
297- printf (" Launching %s\n " ,(*it).connector ->getName ().c_str ());
298- pthread_create (&((*it).thread ),NULL ,Runable::run_runable,(*it).connector );
297+ printf (" Launching %s\n " ,(*it).second . connector ->getName ().c_str ());
298+ pthread_create (&((*it).second . thread ),NULL ,Runable::run_runable,(*it). second .connector );
299299 }
300300 while (force_exit == 0 )
301301 {
@@ -349,7 +349,7 @@ errorCode Broker::run()
349349 container->image ->suicide ();
350350 else
351351 for (auto ic=imageConnectorList.begin ();ic!=imageConnectorList.end ();ic++)
352- (*ic).connector ->masterSendMessage (container);
352+ (*ic).second . connector ->masterSendMessage (container);
353353 }
354354 else
355355 {
@@ -412,7 +412,7 @@ errorCode Broker::run()
412412 dc = dc->next ;
413413 }
414414 for (auto it = imageConnectorList.begin (); it != imageConnectorList.end (); it++)
415- (*it).connector ->masterSendMessage (new ImageBufferContainer (GROUP_ADDED,NULL ,group,1 ));
415+ (*it).second . connector ->masterSendMessage (new ImageBufferContainer (GROUP_ADDED,NULL ,group,1 ));
416416 }
417417 }
418418 else
@@ -434,7 +434,7 @@ errorCode Broker::run()
434434 dc = dc->next ;
435435 }
436436 for (auto it = imageConnectorList.begin (); it != imageConnectorList.end (); it++)
437- (*it).connector ->masterSendMessage (new ImageBufferContainer (GROUP_FINISHED,NULL ,group,1 ));
437+ (*it).second . connector ->masterSendMessage (new ImageBufferContainer (GROUP_FINISHED,NULL ,group,1 ));
438438 // Now let's remove the whole group
439439 group->master ->group = NULL ;
440440 printf (" Removed group %i\n " ,group->id );
@@ -497,11 +497,12 @@ errorCode Broker::run()
497497 {
498498 int id = json_integer_value ( json_object_get (message->json_root , " observe id" ) );
499499 int stream = json_integer_value ( json_object_get (message->json_root , " stream" ) );
500+ // printf("%d\n", stream);
500501 bool dropable = json_boolean_value ( json_object_get (message->json_root , " dropable" ) );
501- if ( stream < 0 )
502- stream = 0 ;
503- if ( stream >= int (imageConnectorList.size ()) )
504- stream = imageConnectorList.size ()-1 ;
502+ // if ( stream < 0 )
503+ // stream = 0;
504+ // if ( stream >= int(imageConnectorList.size()) )
505+ // stream = imageConnectorList.size()-1;
505506 const char * url = json_string_value ( json_object_get (message->json_root , " url" ) );
506507 void * ref = (void *)dc->t ;
507508 dc->t ->observe ( id, stream, dropable );
@@ -518,6 +519,7 @@ errorCode Broker::run()
518519 }
519520 if (group)
520521 {
522+ // printf("%d\n", stream);
521523 json_t *js, *root = json_object ();
522524 if (json_array_size ( js = json_object_get ( group->initData , " projection" ) ) == 16 )
523525 json_object_set ( root, " projection" , js );
@@ -529,7 +531,8 @@ errorCode Broker::run()
529531 json_object_set ( root, " distance" , js );
530532 json_object_set_new ( root, " type" , json_string ( " update" ) );
531533 dc->t ->masterSendMessage (new MessageContainer (UPDATE,root));
532- imageConnectorList[ stream ].connector ->masterSendMessage (new ImageBufferContainer (GROUP_OBSERVED,NULL ,group,1 ,url,ref));
534+ if (imageConnectorList.find (stream) != imageConnectorList.end ())
535+ imageConnectorList[ stream ].connector ->masterSendMessage (new ImageBufferContainer (GROUP_OBSERVED,NULL ,group,1 ,url,ref));
533536 // Send request for (transfer) functions and most recent frame
534537 char buffer[] =
535538 " {\" type\" : \" feedback\" , \" request\" : \" transfer\" } "
@@ -560,7 +563,8 @@ errorCode Broker::run()
560563 }
561564 it = it->next ;
562565 }
563- if (group)
566+ // TODO: Check for define, not necessary if not activated
567+ if (group && imageConnectorList.find (stream) != imageConnectorList.end ())
564568 imageConnectorList[ stream ].connector ->masterSendMessage (new ImageBufferContainer (GROUP_OBSERVED_STOPPED,NULL ,group,1 ,url,ref));
565569 }
566570 if (message->type == CLOSED)
@@ -584,23 +588,22 @@ errorCode Broker::run()
584588 }
585589 dc = next;
586590 }
587-
588591 // /////////////////////////////////////
589592 // Iterate over all image connectors //
590593 // /////////////////////////////////////
591594 for (auto it = imageConnectorList.begin (); it != imageConnectorList.end (); it++)
592595 {
593- while (ImageBufferContainer* message = (*it).connector ->masterGetMessage ())
596+ while (ImageBufferContainer* message = (*it).second . connector ->masterGetMessage ())
594597 {
595598 if (message->type == REGISTER_STREAM)
596599 {
597600 pthread_mutex_lock (&message->group ->streams_mutex );
598- message->group ->streams [(*it).connector ->getName ()].insert ( std::pair< void *,std::string >( message->reference , std::string ((char *)message->image ->buffer ) ));
601+ message->group ->streams [(*it).second . connector ->getName ()].insert ( std::pair< void *,std::string >( message->reference , std::string ((char *)message->image ->buffer ) ));
599602 pthread_mutex_unlock (&message->group ->streams_mutex );
600603 json_t * root = json_object ();
601604 json_object_set_new ( root, " type" , json_string (" register video" ) );
602605 json_object_set_new ( root, " name" , json_string ( message->group ->getName ().c_str () ) );
603- json_object_set_new ( root, " connector" , json_string ( (*it).connector ->getName ().c_str () ) );
606+ json_object_set_new ( root, " connector" , json_string ( (*it).second . connector ->getName ().c_str () ) );
604607 json_object_set_new ( root, " reference" , json_integer ( (long )message->reference ) );
605608 ThreadList<MetaDataClient*>::ThreadListContainer_ptr dc = dataClientList.getFront ();
606609 while (dc)
@@ -651,8 +654,8 @@ errorCode Broker::run()
651654 }
652655 for (auto it = imageConnectorList.begin (); it != imageConnectorList.end (); it++)
653656 {
654- printf (" Asking %s to exit\n " ,(*it).connector ->getName ().c_str ());
655- (*it).connector ->masterSendMessage (new ImageBufferContainer (IMG_FORCE_EXIT,NULL ,NULL ,1 ));
657+ printf (" Asking %s to exit\n " ,(*it).second . connector ->getName ().c_str ());
658+ (*it).second . connector ->masterSendMessage (new ImageBufferContainer (IMG_FORCE_EXIT,NULL ,NULL ,1 ));
656659 }
657660 for (auto it = dataConnectorList.begin (); it != dataConnectorList.end (); it++)
658661 {
@@ -661,8 +664,8 @@ errorCode Broker::run()
661664 }
662665 for (auto it = imageConnectorList.begin (); it != imageConnectorList.end (); it++)
663666 {
664- pthread_join ((*it).thread ,NULL );
665- printf (" %s finished\n " ,(*it).connector ->getName ().c_str ());
667+ pthread_join ((*it).second . thread ,NULL );
668+ printf (" %s finished\n " ,(*it).second . connector ->getName ().c_str ());
666669 }
667670 signal (SIGINT, SIG_DFL);
668671 return 0 ;
0 commit comments