[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi .cvsignore myconf test/include/.cvsignore... [CERTI-SH
From: |
certi-cvs |
Subject: |
[certi-cvs] certi .cvsignore myconf test/include/.cvsignore... [CERTI-SHM] |
Date: |
Wed, 08 Jul 2009 14:48:03 +0000 |
CVSROOT: /sources/certi
Module name: certi
Branch: CERTI-SHM
Changes by: Eric NOULARD <erk> 09/07/08 14:48:03
Modified files:
. : .cvsignore myconf
Added files:
test/include : .cvsignore
test/Billard : .cvsignore billard.cc_v1
RTIG : .cvsignore
test : .cvsignore
test/libgraphc : .cvsignore
RTIA : Communications.cc_v1 Communications.cc_V2
Communications.cc.ok .cvsignore
libRTI : .cvsignore
Log message:
store CERTI SHM (HP CERTI modification)
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/test/include/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/test/Billard/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.2.6.2
http://cvs.savannah.gnu.org/viewcvs/certi/test/Billard/billard.cc_v1?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.2.6.2
http://cvs.savannah.gnu.org/viewcvs/certi/test/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.2.6.2
http://cvs.savannah.gnu.org/viewcvs/certi/test/libgraphc/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.2.6.2
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.cc_v1?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.cc_V2?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.cc.ok?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.2.6.2
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.2.6.2
http://cvs.savannah.gnu.org/viewcvs/certi/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&r1=1.6.2.2&r2=1.6.2.3
http://cvs.savannah.gnu.org/viewcvs/certi/myconf?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.2&r2=3.2.2.1
Patches:
Index: .cvsignore
===================================================================
RCS file: /sources/certi/certi/.cvsignore,v
retrieving revision 1.6.2.2
retrieving revision 1.6.2.3
diff -u -b -r1.6.2.2 -r1.6.2.3
--- .cvsignore 8 Jul 2009 14:40:19 -0000 1.6.2.2
+++ .cvsignore 8 Jul 2009 14:48:03 -0000 1.6.2.3
@@ -1,2 +1,19 @@
Makefile.in
+Makefile
build
+.cproject
+.project
+config.h
+configure
+config.status
+aclocal.m4
+config.sub
+install-sh
+config.h.in
+config.guess
+depcomp
+libtool
+missing
+mkinstalldirs
+ltmain.sh
+stamp-h1
Index: myconf
===================================================================
RCS file: /sources/certi/certi/Attic/myconf,v
retrieving revision 3.2
retrieving revision 3.2.2.1
diff -u -b -r3.2 -r3.2.2.1
--- myconf 14 Jan 2003 14:40:01 -0000 3.2
+++ myconf 8 Jul 2009 14:48:03 -0000 3.2.2.1
@@ -1,6 +1,6 @@
#! /bin/sh
# CERTI myconf
-# $Id: myconf,v 3.2 2003/01/14 14:40:01 breholee Exp $
+# $Id: myconf,v 3.2.2.1 2009/07/08 14:48:03 erk Exp $
case $1 in
sun)
@@ -8,7 +8,6 @@
CC=cc ;
CXX=CC ;
AR=CC ;
- CXXFLAGS="-g" ;
AR_FLAGS=$CXXFLAGS" -xar -o" ;
export CC CXX AR CXXFLAGS LDFLAGS AR_FLAGS
;;
@@ -41,6 +40,7 @@
;;
esac
-./configure --prefix=$HOME/CERTI $2 $3 $4 $5
-# $Id: myconf,v 3.2 2003/01/14 14:40:01 breholee Exp $
+./configure --prefix=/mnt/disk2/LOCAL/ADELE/BETOULE/CERTI $2 $3 $4 $5
+
+# $Id: myconf,v 3.2.2.1 2009/07/08 14:48:03 erk Exp $
Index: test/include/.cvsignore
===================================================================
RCS file: test/include/.cvsignore
diff -N test/include/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/include/.cvsignore 8 Jul 2009 14:48:02 -0000 1.1.2.1
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
Index: test/Billard/.cvsignore
===================================================================
RCS file: test/Billard/.cvsignore
diff -N test/Billard/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/Billard/.cvsignore 8 Jul 2009 14:48:02 -0000 1.2.6.2
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
Index: test/Billard/billard.cc_v1
===================================================================
RCS file: test/Billard/billard.cc_v1
diff -N test/Billard/billard.cc_v1
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/Billard/billard.cc_v1 8 Jul 2009 14:48:02 -0000 1.1.2.1
@@ -0,0 +1,682 @@
+// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002, 2003 ONERA
+//
+// This file is part of CERTI
+//
+// CERTI is free software ; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation ; either version 2 of the License, or
+// (at your option) any later version.
+//
+// CERTI is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// $Id: billard.cc_v1,v 1.1.2.1 2009/07/08 14:48:02 erk Exp $
+// ----------------------------------------------------------------------------
+
+// Project
+#include <config.h>
+#include "bille.hh"
+#include "my_fed.hh"
+#include "constants.hh"
+#include "cmdline.h"
+
+// Libraries
+#include "RTI.hh"
+#include "PrettyDebug.hh"
+#ifdef TEST_USES_GRAPHICS
+#include "graph_c.hh"
+#endif
+
+// Standard libraries
+#include <cstdio>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <math.h>
+#include <iostream>
+#include <signal.h>
+#include <exception>
+
+using namespace std ;
+
+// Definition des constantes
+
+#define HEURE_DEB 10.0
+#define TEMPS_SIMU_F 60 // Duree de la simulation en secondes
+#define TEMPS_SIMU_C 60 // Duree de la simulation en secondes
+// j'ai différencié le temps suivant si on est ou pas créateur: utilisé
+// seulement pour faire des test
+
+const RTIfedTime TIME_STEP(1.0); // lookahead
+
+#define XMAX 500 /* dimensions fenetre graphique */
+#define YMAX 100
+#define XFEN 50 /* position de cette fenetre */
+#define YFEN 70
+#define TMAX 30
+
+// ------------------
+// -- Declarations --
+// ------------------
+
+// Declaration des fonctions externes
+extern void InitGraphe(int X, int Y, unsigned WIDHT, unsigned HEIGHT);
+
+// Declaration des objets et variables globaux
+
+RTI::RTIambassador *rtiamb ;
+Fed *fedamb ;
+
+static pdCDebug D("BILLARD", "(main) - ");
+
+bool exit_billard ;
+int nbtick=0 ;
+unsigned int t, s ;
+char c ;
+
+int YOFFSET ;
+int XOFFSET ;
+
+int autostart = 0 ;
+int delay = 0 ;
+int timer = 0 ;
+
+bool verbose ;
+
+// ----------------------------------------
+// -- Declaration des fonctions internes --
+// ----------------------------------------
+extern "C" void sortir(int SignalNumber);
+void ExceptionHandler(void);
+void InitialisationGraphique(FederateHandle myFederateID);
+void SetTimeRegulation(RTI::RTIambassador *rtiamb,
+ bool creator,
+ FedTime& localTime);
+void synchronize(RTI::RTIambassador *rtiamb,
+ Fed *fedamb,
+ bool creator);
+
+// ----------------------------------------------------------------------------
+//! Test program entry point.
+int
+main(int argc, char **argv)
+{
+ int i = 0 ; // Variable de boucle
+ RTIfedTime localTime(0.0); // Temps local du federe
+ RTIfedTime* time_aux ;
+ FederateHandle id = 0 ;
+ bool creator = false ;
+ char *FederationName ;
+ char *FederateName ;
+ char *DotFedFile ;
+
+ printf("CERTI-Billard " VERSION " - Copyright (C) 2002, 2003 ONERA\n");
+ printf("This is free software ; see the source for copying conditions. "
+ "There is NO\nwarranty ; not even for MERCHANTABILITY or FITNESS"
+ " FOR A PARTICULAR PURPOSE.\n\n");
+
+ gengetopt_args_info args_info ;
+ if (cmdline_parser(argc, argv, &args_info) != 0)
+ exit(EXIT_FAILURE);
+
+ verbose = args_info.verbose_flag ;
+
+ rtiamb = new RTI::RTIambassador();
+ fedamb = new Fed(rtiamb);
+
+ // Handlers
+ std::signal(SIGINT, sortir);
+ std::signal(SIGALRM, sortir);
+
+ set_terminate(ExceptionHandler);
+ set_unexpected(ExceptionHandler);
+
+ // Nom de la fédération
+ FederationName = args_info.federation_arg ;
+ DotFedFile = new char[strlen(FederationName)+5] ;
+ strcpy(DotFedFile, FederationName);
+#ifdef HAVE_XML // if compiled with XML, use the .xml description
+ strcat(DotFedFile, ".xml");
+#else
+ strcat(DotFedFile, ".fed");
+#endif
+ printf("Using %s file\n", DotFedFile);
+
+ FederateName = args_info.name_arg ;
+
+ // Timer
+ if (args_info.timer_given)
+ timer = args_info.timer_arg ;
+
+ // Delay
+ if(args_info.delay_given)
+ delay = args_info.delay_arg ;
+
+ // Autostart
+ if(args_info.auto_given)
+ autostart = args_info.auto_arg ;
+
+ // Log
+ if (args_info.logfile_given)
+ fedamb->enableLog(args_info.logfile_arg);
+
+ // Verifier que la federation existe
+ printf("avant createFederationExecution\n");
+ try {
+ rtiamb->createFederationExecution(FederationName,
+ DotFedFile);
+ D.Out(pdInit, "Federation execution created.");
+ creator = true ;
+ }
+ catch (FederationExecutionAlreadyExists& e) {
+ D.Out(pdInit, "Federation execution already created.");
+ }
+ printf("apres createFederationExecution\n");
+
+ // Participer a la federation
+ D.Out(pdInit, "Federate %s attempting to join the %s federation.",
+ FederateName, FederationName);
+
+ bool joined = false ;
+ // int numTries = 0 ;
+
+ while (!joined) {
+ try {
+ id=rtiamb->joinFederationExecution(FederateName,
+ FederationName,
+ fedamb);
+ joined = true ;
+ D.Out(pdInit, "Federate %s joined the %s : I'm #%d .",
+ FederateName, FederationName, id);
+ break ;
+ }
+ catch (FederateAlreadyExecutionMember& e) {
+ D.Out(pdExcept,
+ "Federate %s already exists in the Federation Execution.",
+ FederateName);
+ throw ;
+ }
+ catch (FederationExecutionDoesNotExist& e) {
+ D.Out(pdExcept, "Federate %s : FederationExecutionDoesNotExist.",
+ FederateName);
+ // sleep(1);
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept,
+ "Federate %s :Join Federation Execution failed : %d .",
+ FederateName, &e);
+ throw ;
+ }
+ }
+
+ if (args_info.yoffset_given)
+ YOFFSET = args_info.yoffset_arg ;
+ else
+ YOFFSET = YMAX*(id-1)+25*id ;
+
+ if (args_info.xoffset_given)
+ XOFFSET = args_info.xoffset_arg ;
+ else
+ XOFFSET = 0 ;
+
+ // Creator put federation in pause.
+ if (creator) {
+ D.Out(pdInit, "Pause requested");
+ try {
+ rtiamb->registerFederationSynchronizationPoint("Init",
+ "Waiting all players.");
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept, "Federate #%s : Register Federation "
+ "Synchronization Point failed : %d .", argv[1], &e);
+ }
+ }
+
+ // Publication et abonnement
+ D.Out(pdInit, "Federate #%s publishinng and subscribing objects.",
argv[1]);
+ fedamb->PublishAndsubscribe();
+
+ // Waiting for callbacks
+ rtiamb->tick(1.0, 2.0);
+ nbtick++ ;
+
+ // --------------------
+ // -- Initialization --
+ // --------------------
+#ifdef TEST_USES_GRAPHICS
+ // Ouvrir fenetre graphique
+ InitialisationGraphique(id);
+#endif
+
+ // Mettre en route la regulation, se declarer contraint etc.
+ if (args_info.coordinated_flag) {
+ SetTimeRegulation(rtiamb, creator, localTime);
+
+ // Waiting for callbacks
+ try {
+ rtiamb->tick(1.0, 2.0);
+ nbtick++ ;
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept, "Exception ticking the RTI : %d", &e);
+ }
+ }
+
+ // Initial synchronization.
+ synchronize(rtiamb, fedamb, creator);
+ D.Out(pdInit, "Initial synchronization done.");
+
+ // Creer ma boule
+ if (args_info.initx_given && args_info.inity_given) {
+ fedamb->Local.init(args_info.initx_arg, args_info.inity_arg);
+ }
+ else
+ fedamb->Local.init(id);
+ D.Out(pdTrace, "creation de la boule réussie.");
+
+ // Declarer la boule aux autres federes
+ fedamb->RegisterObjects(FederateName);
+ cout << "Created Object " << fedamb->Local.ID << endl ;
+ D.Out(pdInit, "Local Object registered under ID %d", fedamb->Local.ID);
+
+ // Delay ?
+ if (delay != 0) {
+ while (delay >= 0) {
+ sleep(1);
+ printf("\rDelay : %5d", delay);
+ fflush(stdout);
+ delay-- ;
+ }
+ printf("\n");
+ }
+
+ rtiamb->queryFederateTime(localTime);
+
+ // ------------------------------
+ // -- Boucle de la simulation --
+ // ------------------------------
+ D.Out(pdTrace, "Start simulation loop.");
+ D.Out(pdTrace, "Local object ID %d.", fedamb->Local.ID);
+
+ exit_billard = false ;
+ int cpt_boucle_simu = 0;
+ while (!exit_billard) {
+ // Advance Time
+ // localTime = rtiamb->requestFederateTime();
+ fedamb->granted = false ;
+ rtiamb->queryFederateTime(localTime);
+
+ try {
+ time_aux=new RTIfedTime(localTime.getTime()+TIME_STEP.getTime());
+
+ D.Out(pdDebug, "time_aux : %.2f - localtime : %.2f - "
+ "timestep : %.2f", time_aux->getTime(),
+ ((RTIfedTime&)localTime).getTime(),
+ ((RTIfedTime&)TIME_STEP).getTime());
+ rtiamb->timeAdvanceRequest(*time_aux);
+ if (verbose)
+ cout << "-> TAR " << time_aux->getTime() << endl ;
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept, "******* Exception sur timeAdvanceRequest.");
+ }
+ delete time_aux ;
+
+ while (!fedamb->granted) {
+ try {
+ rtiamb->tick();
+ nbtick++ ;
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept, "******** Exception ticking the RTI : %d.",
&e);
+ }
+ }
+ try {
+ rtiamb->queryFederateTime(localTime);
+ if (verbose)
+ cout << "<= TAG " << localTime.getTime() << endl ;
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept,
+ "**** Exception asking for federate local time : ", &e);
+ }
+
+ D.Out(pdTrace, "Time advanced, local time is now %.2f.",
+ localTime.getTime());
+
+ // Teste la collision avec d'autres billes
+ D.Out(pdTrace, "objet: %d, ID: %d.", fedamb->RemoteCount,
+ fedamb->Remote[i].ID);
+
+ for (i = 0 ; i < fedamb->RemoteCount ; i++) {
+ if ((fedamb->Remote[i].ID != 0) &&
+ (fedamb->Local.Collision(&fedamb->Remote[i]))) {
+ CBoule *Local = & (fedamb->Local);
+ CBille *Remote = & (fedamb->Remote[i]);
+
+ D.Out(pdTrace, "Collision between %d and %d.", Local->ID,
+ Remote->ID);
+#ifndef TEST_USES_GRAPHICS
+ // Meme message si on est en mode non graphique
+ //printf("\nCollision de %d et %d\n", Local->ID, Remote->ID);
+#endif
+ time_aux = new RTIfedTime(localTime.getTime() +
+ TIME_STEP.getTime());
+
+ D.Out(pdDebug,
+ "time_aux : %.2f - localtime : %.2f - timestep : %.2f",
+ time_aux->getTime(),
+ ((RTIfedTime&)localTime).getTime(),
+ ((RTIfedTime&)TIME_STEP).getTime());
+
+ fedamb->sendInteraction(*time_aux, Remote->ID);
+ delete time_aux ;
+ // On prend la vitesse de l'autre sauf dans le cas ou
+ // on avait deja la meme. Dans ce cas, on inverse la notre.
+ if ((Local->dx == Remote->dx) && (Local->dy == Remote->dy)) {
+ Local->dx = -(Local->dx);
+ Local->dy = -(Local->dy);
+ }
+ else
+ Local->Direction(Remote->dx, Remote->dy);
+
+ }
+ D.Out(pdTrace, "no collision.");
+
+ }
+
+ // Teste la collision avec le bord
+ fedamb->Local.CollisionBords(XMAX, YMAX);
+ D.Out(pdTrace, "Border collisions...");
+
+ // Mise a jour graphique
+ fedamb->Local.Effacer();
+ D.Out(pdTrace, "Clear ball.");
+
+ fedamb->Local.Deplacer();
+ fedamb->Local.Afficher();
+ D.Out(pdTrace, "Redisplay ball.");
+
+ // Envoie d'une mise a jour des attributs
+ time_aux=new RTIfedTime(localTime.getTime()+TIME_STEP.getTime());
+ D.Out(pdDebug, "time_aux : %.2f - localtime : %.2f - timestep : %.2f",
+ time_aux->getTime(),
+ ((RTIfedTime&)localTime).getTime(),
+ ((RTIfedTime&)TIME_STEP).getTime());
+
+ fedamb->SendUpdate(*time_aux);
+ delete time_aux ;
+ D.Out(pdTrace, "fin tour de boucle.");
+ cpt_boucle_simu++;
+ } // fin de la boucle de simulation.
+
+ // -----------------
+ // -- Terminaison --
+ // -----------------
+ D.Out(pdTrace, "End of simulation loop.");
+ D.Out(pdTerm, "Resultat de la simulation : %d iterations \n",
cpt_boucle_simu);
+
+ fedamb->DeleteObjects(localTime);
+ D.Out(pdTerm, "Local objects deleted.");
+
+ if (strcmp(argv[2], "on") == 0) {
+ rtiamb->disableTimeConstrained();
+ D.Out(pdTerm, "Not constrained anymore.");
+
+ rtiamb->disableTimeRegulation();
+ D.Out(pdTerm, "Not regulating anymore");
+ }
+
+ try {
+ rtiamb->
+ resignFederationExecution(DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES);
+ D.Out(pdTerm, "Just resigned from federation");
+ }
+ catch (Exception &e) {
+ D.Out(pdExcept,
+ "** Exception during resignFederationExecution by federate");
+ }
+ // Detruire la federation
+
+ if (creator) {
+ for (;;) {
+ rtiamb->tick(1.0, 2.0);
+ nbtick++ ;
+
+ try {
+ D.Out(pdTerm, "Asking from federation destruction...");
+ rtiamb->destroyFederationExecution(FederationName);
+
+ D.Out(pdTerm, "Federation destruction granted.");
+ break ;
+ }
+ catch (FederatesCurrentlyJoined) {
+ sleep(5);
+ }
+ }
+ }
+ D.Out(pdTerm, "Destroying RTIAmbassador and FedAmbassador.");
+ delete fedamb ;
+ delete rtiamb ;
+
+ D.Out(pdTerm, "Federation terminated.");
+}
+
+// ----------------------------------------------------------------------------
+//! sortir.
+void
+sortir(int SignalNumber)
+{
+ if (SignalNumber == SIGALRM) {
+ D.Out(pdTerm, "Alarm signal received, exiting...");
+ exit_billard = true ;
+ }
+ else {
+ D.Out(pdTerm, "Emergency stop, destroying Ambassadors.");
+ if (fedamb != 0) delete fedamb ;
+ if (rtiamb != 0) delete rtiamb ;
+ D.Out(pdTerm, "Federate terminated.");
+ exit(EXIT_FAILURE);
+ }
+}
+
+// ----------------------------------------------------------------------------
+//! ExceptionHandler.
+void
+ExceptionHandler(void)
+{
+ D.Out(pdExcept, "****Exception thrown on the 'test_heritage' Federate.");
+ exit(-1);
+}
+
+// ----------------------------------------------------------------------------
+//! InitialisationGraphique.
+void
+InitialisationGraphique(FederateHandle id)
+{
+ int x = XFEN + XOFFSET ;
+ int y = YFEN + YOFFSET ;
+ unsigned int width = XMAX ;
+ unsigned int height = YMAX ;
+
+#ifdef TEST_USES_GRAPHICS
+ InitGraphe(x, y, width, height);
+ D.Out(pdInit, "InitGraphe(%d, %d, %d, %d)", x, y, width, height);
+#endif
+}
+
+// ----------------------------------------------------------------------------
+//! SetTimeRegulation.
+void
+SetTimeRegulation(RTI::RTIambassador *rtiamb,
+ bool /*creator*/,
+ FedTime& localTime)
+{
+ // S'enregistrer comme regulateur.
+ while (1) {
+ rtiamb->queryFederateTime(localTime);
+
+ try {
+ rtiamb->enableTimeRegulation(localTime, TIME_STEP);
+ break ;
+ }
+ catch (FederationTimeAlreadyPassed) {
+ // Si Je ne suis pas le premier, je vais les rattraper.
+ rtiamb->queryFederateTime(localTime);
+ fedamb->granted = false ;
+ RTIfedTime requestTime(((RTIfedTime&)localTime).getTime());
+ // D.Out(pdInit, "localtime %.2f, requestTime %.2f",
+ // ((RTIfedTime&)localTime).getTime(),
+ // ((RTIfedTime&)requestTime).getTime());
+ requestTime += TIME_STEP ;
+ // D.Out(pdInit, "localtime %.2f, requestTime %.2f",
+ // ((RTIfedTime&)localTime).getTime(),
+ // ((RTIfedTime&)requestTime).getTime());
+ rtiamb->timeAdvanceRequest(requestTime);
+
+ while (!fedamb->granted) {
+ try {
+ rtiamb->tick(1.0, 2.0);
+ }
+ catch (RTIinternalError) {
+ printf("RTIinternalError Raised in tick.\n");
+ exit(-1);
+ }
+ }
+ }
+ catch (RTIinternalError) {
+ printf("RTIinternalError Raised in setTimeRegulating.\n");
+ exit(-1);
+ }
+ }
+
+ D.Out(pdInit, "Time Regulating on.");
+
+ // Se declarer contraint.
+ rtiamb->enableTimeConstrained();
+ D.Out(pdInit, "Time Constrained true.");
+ rtiamb->modifyLookahead(TIME_STEP);
+}
+
+// ----------------------------------------------------------------------------
+//! Return the remaining time when the alarm is stopped.
+void
+synchronize(RTI::RTIambassador *rtiamb, Fed *fedamb, bool creator)
+{
+ if (creator) {
+ // Wait a signal from user and stop the pause synchronization.
+
+ if (autostart == 0) {
+ cout << "Press ENTER to start execution..." << endl ;
+ getchar();
+ }
+ else {
+ while (autostart >= 0) {
+ sleep(1);
+ printf("\rAutostart : %5d", autostart);
+ fflush(stdout);
+ autostart-- ;
+ }
+ printf("\n");
+ }
+
+ D.Out(pdInit, "Creator can resume execution...");
+ while (!fedamb->paused)
+ try {
+ D.Out(pdInit, "not paused");
+ rtiamb->tick(1.0, 2.0);
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept, "******** Exception ticking the RTI : %d ",
&e);
+ }
+ D.Out(pdDebug, "paused");
+
+ try {
+ rtiamb->synchronizationPointAchieved("Init");
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept, "**** Exception achieving a synchronization "
+ "point by creator : %d", &e);
+ }
+
+ while(fedamb->paused)
+ try {
+ rtiamb->tick(1.0, 2.0) ;
+ }
+ catch(Exception& e) {
+ D.Out(pdExcept, "**** Exception ticking the RTI : %d.",&e);
+ }
+ }
+ else {
+ if (autostart != 0) {
+ printf("Ignoring autostart (federate is not creator)\n");
+ }
+ printf("Synchronization...\n");
+
+ if (!fedamb->paused) {
+ D.Out(pdInit,
+ "Federate not paused: too early");
+ while (!fedamb->paused) {
+ try {
+ rtiamb->tick(1.0, 2.0);
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept,
+ "******** Exception ticking the RTI : %d.", &e);
+ }
+ }
+ }
+ D.Out(pdInit, "Federate paused");
+
+ try {
+ // Federate ends its synchronization.
+ rtiamb->synchronizationPointAchieved("Init");
+ D.Out(pdInit, "Pause achieved.");
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept,
+ "**** Exception achieving a synchronization point : %d",
+ &e);
+ }
+
+ D.Out(pdInit,
+ "Federate waiting end of pause...");
+ while (fedamb->paused) {
+ try {
+ rtiamb->tick(1.0, 2.0);
+ }
+ catch (Exception& e) {
+ D.Out(pdExcept, "******** Exception ticking the RTI : %d.",
&e);
+ }
+ }
+ D.Out(pdInit, "End of pause");
+ }
+
+ D.Out(pdInit, "Federation is synchronized.");
+
+ // Demarre le compte-a-rebours de la simulation.
+ struct sigaction a ;
+
+ a.sa_handler = sortir ;
+ sigemptyset(&a.sa_mask);
+ sigaction(SIGALRM, &a, NULL);
+ // sigset(SIGALRM, sortir);
+
+ if (timer != 0) {
+ printf("Timer : %5d\n", timer);
+ alarm(timer);
+ }
+}
+
+// EOF $Id: billard.cc_v1,v 1.1.2.1 2009/07/08 14:48:02 erk Exp $
Index: RTIG/.cvsignore
===================================================================
RCS file: RTIG/.cvsignore
diff -N RTIG/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RTIG/.cvsignore 8 Jul 2009 14:48:03 -0000 1.2.6.2
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
Index: test/.cvsignore
===================================================================
RCS file: test/.cvsignore
diff -N test/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/.cvsignore 8 Jul 2009 14:48:03 -0000 1.2.6.2
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
Index: test/libgraphc/.cvsignore
===================================================================
RCS file: test/libgraphc/.cvsignore
diff -N test/libgraphc/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/libgraphc/.cvsignore 8 Jul 2009 14:48:03 -0000 1.2.6.2
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
Index: RTIA/Communications.cc_v1
===================================================================
RCS file: RTIA/Communications.cc_v1
diff -N RTIA/Communications.cc_v1
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RTIA/Communications.cc_v1 8 Jul 2009 14:48:03 -0000 1.1.2.1
@@ -0,0 +1,330 @@
+// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002, 2003 ONERA
+//
+// This file is part of CERTI
+//
+// CERTI is free software ; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation ; either version 2 of the License, or
+// (at your option) any later version.
+//
+// CERTI is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// $Id: Communications.cc_v1,v 1.1.2.1 2009/07/08 14:48:03 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include "Communications.hh"
+
+namespace certi {
+namespace rtia {
+
+static pdCDebug D("RTIA_COMM", "(RTIA Comm) ");
+
+// ----------------------------------------------------------------------------
+/*! Wait a message coming from RTIG. Parameters are :
+ 1- Returned message,
+ 2- Message type expected,
+ 3- Federate which sent the message, 0 if indifferent.
+*/
+void Communications::waitMessage(NetworkMessage *msg,
+ TypeNetworkMessage type_msg,
+ FederateHandle numeroFedere)
+{
+ NetworkMessage *tampon ;
+
+ assert(type_msg > 0 && type_msg < 100);
+
+ D.Out(pdProtocol, "Waiting for Message of Type %d.", type_msg);
+
+ // Does a new message has arrived ?
+ if (searchMessage(type_msg, numeroFedere, msg) == RTI_TRUE)
+ return ;
+
+ // Otherwise, wait for a message with same type than expected and with
+ // same federate number.
+ tampon = new NetworkMessage ;
+ //tampon->read((SecureTCPSocket *)this);
+ tampon->read((SocketSHM *)this);
+
+ D.Out(pdProtocol, "TCP Message of Type %d has arrived.", type_msg);
+
+ while ((tampon->type != type_msg) ||
+ ((numeroFedere != 0) && (tampon->federate != numeroFedere))) {
+ waitingList.push_back(tampon);
+ tampon = new NetworkMessage ;
+ tampon->read((SocketSHM *)this);
+ //tampon->read((SecureTCPSocket *) this);
+
+ D.Out(pdProtocol, "Message of Type %d has arrived.", type_msg);
+ }
+
+ // BUG: Should use copy operator.
+ memcpy((void *) msg, (void *) tampon, sizeof(NetworkMessage));
+ delete tampon ;
+
+ assert(msg != NULL);
+ assert(msg->type == type_msg);
+}
+
+// ----------------------------------------------------------------------------
+//! Communications.
+Communications::Communications(void)
+ : SocketUN(), SecureTCPSocket(), SocketUDP(), SocketSHM()
+{
+ char nom_serveur_RTIG[200] ;
+
+ // Federate/RTIA link creation.
+ acceptUN();
+
+ // RTIG TCP link creation.
+ char *certihost = getenv("CERTI_HOST");
+
+ ifstream* file = NULL ;
+ if (certihost==NULL) {
+ file = new ifstream("RTIA.dat", ios::in);
+ if (!file->is_open()) {
+ cout << "RTIA ERROR: Unable to find RTIG host." << endl ;
+ cout << "No RTIA.dat file found, no CERTI_HOST variable set" <<
endl ;
+ exit(-1);
+ }
+
+ file->get(nom_serveur_RTIG, 200);
+ file->close();
+ delete file ;
+ certihost = nom_serveur_RTIG ;
+ }
+
+ const char *tcp_port = getenv("CERTI_TCP_PORT");
+ const char *udp_port = getenv("CERTI_UDP_PORT");
+ if (tcp_port==NULL) tcp_port = PORT_TCP_RTIG ;
+ if (udp_port==NULL) udp_port = PORT_UDP_RTIG ;
+
+ //createTCPClient(atoi(tcp_port), certihost);
+ createSHMClient(atoi(tcp_port), certihost);
+ createUDPClient(atoi(udp_port), certihost);
+}
+
+// ----------------------------------------------------------------------------
+//! ~Communications.
+Communications::~Communications(void)
+{
+ // Advertise RTIG that TCP link is being closed.
+
+ NetworkMessage msg ;
+ msg.type = m_CLOSE_CONNEXION ;
+ msg.write((SocketSHM *) this);
+
+ SecureTCPSocket::close();
+}
+
+// ----------------------------------------------------------------------------
+//! Request a service to federate.
+void
+Communications::requestFederateService(Message *req, Message *rep)
+{
+ assert(req != NULL);
+ D.Out(pdRequest, "Sending Request to Federate, Type %d.", req->type);
+ sendUN(req);
+ receiveUN(rep);
+ D.Out(pdAnswer, "Received Answer from Federate.");
+ assert(req->type == rep->type);
+}
+
+// ----------------------------------------------------------------------------
+unsigned long
+Communications::getAddress(void)
+{
+ return((SocketUDP *) this)->getAddr();
+}
+
+// ----------------------------------------------------------------------------
+unsigned int
+Communications::getPort(void)
+{
+ return((SocketUDP *) this)->getPort();
+}
+
+// ----------------------------------------------------------------------------
+//! read message.
+/*! Reads a message either from the network or from the federate
+ Returns the actual source in the 1st parameter (RTIG=>1 federate=>2)
+*/
+void
+Communications::readMessage(int &n, NetworkMessage *msg_reseau, Message *msg)
+{
+ // initialize fdset for use with select.
+ D.Out(pdTrace,"Initialise fd_set");
+ fd_set fdset ;
+ FD_ZERO(&fdset);
+ FD_SET(_socket_un, &fdset);
+ FD_SET(SecureTCPSocket::returnSocket(), &fdset);
+ FD_SET(SocketUDP::returnSocket(), &fdset);
+
+#ifdef FEDERATION_USES_MULTICAST
+ // if multicast link is initialized (during join federation).
+ if (_est_init_mc)
+ FD_SET(_socket_mc, &fdset);
+#endif
+
+ if (!waitingList.empty()) {
+ // One message is in waiting buffer.
+ NetworkMessage *msg2 ;
+ msg2 = waitingList.front();
+ waitingList.pop_front();
+ memcpy(msg_reseau, msg2, TAILLE_MSG_RESEAU);
+ delete msg2 ;
+ n = 1 ;
+ }
+ else if (SecureTCPSocket::isDataReady() == RTI_TRUE) {
+ // Datas are in TCP waiting buffer.
+ // Read a message from RTIG TCP link.
+ msg_reseau->read((SecureTCPSocket *) this);
+ n = 1 ;
+ }
+ else if (SocketUDP::isDataReady() == RTI_TRUE) {
+ // Datas are in UDP waiting buffer.
+ // Read a message from RTIG UDP link.
+ msg_reseau->read((SocketUDP *) this);
+ n = 1 ;
+ }
+ else if (SocketUN::isDataReady() == RTI_TRUE) {
+ // Datas are in UNIX waiting buffer.
+ // Read a message from federate UNIX link.
+ msg->read((SocketUN *) this);
+ n = 2 ;
+ }
+ else if (SocketSHM::isDataReady() == RTI_TRUE){
+ msg_reseau->read((SocketSHM *) this);
+ n = 1 ;
+ }
+ else {
+ // waitingList is empty and no data in TCP buffer.
+ // Wait a message (coming from federate or network).
+ int result = 0;
+ struct timeval delai;
+ delai.tv_sec = 0;
+ delai.tv_usec = 0;
+ D.Out(pdTrace,"Attente message");
+ while(result ==0){
+ if(!FD_ISSET(SecureTCPSocket::returnSocket(),
&fdset)){D.Out(pdTrace,"Erreur socketTCP non selecte ");
+ }
+ if(!FD_ISSET(SocketUDP::returnSocket(),
&fdset)){D.Out(pdTrace,"Erreur socketUDP non selecte");
+ FD_SET(SocketUDP::returnSocket(), &fdset);}
+ if(!FD_ISSET(_socket_un, &fdset)){D.Out(pdTrace,"Erreur socketUN non
selecte");
+ FD_SET(_socket_un, &fdset);}
+
+ if ((result=select(ulimit(4, 0), &fdset, NULL, NULL, &delai)) < 0) {
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else
+ throw NetworkError();
+ }
+
+
+ if (SocketSHM::isDataReady() == RTI_TRUE){
+ result = 1;
+ }
+ }
+ D.Out(pdTrace,"Message recu");
+ // At least one message has been received, read this message.
+
+#ifdef FEDERATION_USES_MULTICAST
+ // Priorite aux messages venant du multicast(pour essayer d'eviter
+ // un depassement de la file et donc la perte de messages)
+
+ if (_est_init_mc && FD_ISSET(_socket_mc, &fdset)) {
+ // Read a message coming from the multicast link.
+ receiveMC(msg_reseau);
+ n = 1 ;
+ }
+#endif
+
+ if (FD_ISSET(SecureTCPSocket::returnSocket(), &fdset)) {
+ // Read a message coming from the TCP link with RTIG.
+ msg_reseau->read((SecureTCPSocket *) this);
+ n = 1 ;
+ }
+ else if (FD_ISSET(SocketUDP::returnSocket(), &fdset)) {
+ // Read a message coming from the UDP link with RTIG.
+ msg_reseau->read((SocketUDP *) this);
+ n = 1 ;
+ }
+ else if (FD_ISSET(_socket_un, &fdset)){
+ // Read a message coming from the federate.
+ receiveUN(msg);
+ n = 2 ;
+ }
+ else{
+ msg_reseau->read((SocketSHM *) this);
+ n = 1 ;
+ }
+ }
+}
+
+// ----------------------------------------------------------------------------
+/*! Returns RTI_TRUE if a 'type_msg' message coming from federate
+ 'numeroFedere' (or any other federate if numeroFedere == 0) was in
+ the queue and was copied in 'msg'. If no such message is found,
+ returns RTI_FALSE.
+*/
+Boolean
+Communications::searchMessage(TypeNetworkMessage type_msg,
+ FederateHandle numeroFedere,
+ NetworkMessage *msg)
+{
+ list<NetworkMessage *>::iterator i ;
+ for (i = waitingList.begin(); i != waitingList.end(); i++) {
+
+ D.Out(pdProtocol, "Rechercher message de type %d .", type_msg);
+
+ if ((*i)->type == type_msg) {
+ // if numeroFedere != 0, verify that federateNumbers are similar
+ if (((*i)->federate == numeroFedere) || (numeroFedere == 0)) {
+ memcpy(msg, (*i), TAILLE_MSG_RESEAU);
+ waitingList.erase(i);
+ delete (*i);
+ D.Out(pdProtocol,
+ "Message of Type %d was already here.",
+ type_msg);
+ return RTI_TRUE ;
+ }
+ }
+ }
+ return RTI_FALSE ;
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::sendMessage(NetworkMessage *Msg)
+{
+ Msg->write((SocketSHM *) this);
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::sendUN(Message *Msg)
+{
+ D.Out(pdProtocol, "Send Message Unix");
+ Msg->write((SocketUN *) this);
+ D.Out(pdProtocol, "Send Message Unix, done");
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::receiveUN(Message *Msg)
+{
+ Msg->read((SocketUN *) this);
+}
+
+}} // namespace certi/rtia
+
+// $Id: Communications.cc_v1,v 1.1.2.1 2009/07/08 14:48:03 erk Exp $
Index: RTIA/Communications.cc_V2
===================================================================
RCS file: RTIA/Communications.cc_V2
diff -N RTIA/Communications.cc_V2
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RTIA/Communications.cc_V2 8 Jul 2009 14:48:03 -0000 1.1.2.1
@@ -0,0 +1,336 @@
+// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002, 2003 ONERA
+//
+// This file is part of CERTI
+//
+// CERTI is free software ; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation ; either version 2 of the License, or
+// (at your option) any later version.
+//
+// CERTI is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// $Id: Communications.cc_V2,v 1.1.2.1 2009/07/08 14:48:03 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include "Communications.hh"
+
+namespace certi {
+namespace rtia {
+
+static pdCDebug D("RTIA_COMM", "(RTIA Comm) ");
+
+// ----------------------------------------------------------------------------
+/*! Wait a message coming from RTIG. Parameters are :
+ 1- Returned message,
+ 2- Message type expected,
+ 3- Federate which sent the message, 0 if indifferent.
+*/
+void Communications::waitMessage(NetworkMessage *msg,
+ TypeNetworkMessage type_msg,
+ FederateHandle numeroFedere)
+{
+ NetworkMessage *tampon ;
+
+ assert(type_msg > 0 && type_msg < 100);
+
+ D.Out(pdProtocol, "Waiting for Message of Type %d.", type_msg);
+
+ // Does a new message has arrived ?
+ if (searchMessage(type_msg, numeroFedere, msg) == RTI_TRUE)
+ return ;
+
+ // Otherwise, wait for a message with same type than expected and with
+ // same federate number.
+ tampon = new NetworkMessage ;
+ //tampon->read((SecureTCPSocket *)this);
+ tampon->read((SocketSHM *)this);
+
+ D.Out(pdProtocol, "TCP Message of Type %d has arrived.", type_msg);
+
+ while ((tampon->type != type_msg) ||
+ ((numeroFedere != 0) && (tampon->federate != numeroFedere))) {
+ waitingList.push_back(tampon);
+ tampon = new NetworkMessage ;
+ tampon->read((SocketSHM *)this);
+ //tampon->read((SecureTCPSocket *) this);
+
+ D.Out(pdProtocol, "Message of Type %d has arrived.", type_msg);
+ }
+
+ // BUG: Should use copy operator.
+ memcpy((void *) msg, (void *) tampon, sizeof(NetworkMessage));
+ delete tampon ;
+
+ assert(msg != NULL);
+ assert(msg->type == type_msg);
+}
+
+// ----------------------------------------------------------------------------
+//! Communications.
+Communications::Communications(void)
+ : SocketUN(), SecureTCPSocket(), SocketUDP(), SocketSHM()
+{
+ char nom_serveur_RTIG[200] ;
+
+ // Federate/RTIA link creation.
+ acceptUN();
+
+ // RTIG TCP link creation.
+ char *certihost = getenv("CERTI_HOST");
+
+ ifstream* file = NULL ;
+ if (certihost==NULL) {
+ file = new ifstream("RTIA.dat", ios::in);
+ if (!file->is_open()) {
+ cout << "RTIA ERROR: Unable to find RTIG host." << endl ;
+ cout << "No RTIA.dat file found, no CERTI_HOST variable set" <<
endl ;
+ exit(-1);
+ }
+
+ file->get(nom_serveur_RTIG, 200);
+ file->close();
+ delete file ;
+ certihost = nom_serveur_RTIG ;
+ }
+
+ const char *tcp_port = getenv("CERTI_TCP_PORT");
+ const char *udp_port = getenv("CERTI_UDP_PORT");
+ if (tcp_port==NULL) tcp_port = PORT_TCP_RTIG ;
+ if (udp_port==NULL) udp_port = PORT_UDP_RTIG ;
+
+ //createTCPClient(atoi(tcp_port), certihost);
+ createSHMClient(atoi(tcp_port), certihost);
+ createUDPClient(atoi(udp_port), certihost);
+}
+
+// ----------------------------------------------------------------------------
+//! ~Communications.
+Communications::~Communications(void)
+{
+ // Advertise RTIG that TCP link is being closed.
+
+ NetworkMessage msg ;
+ msg.type = m_CLOSE_CONNEXION ;
+ msg.write((SocketSHM *) this);
+
+ SecureTCPSocket::close();
+}
+
+// ----------------------------------------------------------------------------
+//! Request a service to federate.
+void
+Communications::requestFederateService(Message *req, Message *rep)
+{
+ assert(req != NULL);
+ D.Out(pdRequest, "Sending Request to Federate, Type %d.", req->type);
+ sendUN(req);
+ receiveUN(rep);
+ D.Out(pdAnswer, "Received Answer from Federate.");
+ assert(req->type == rep->type);
+}
+
+// ----------------------------------------------------------------------------
+unsigned long
+Communications::getAddress(void)
+{
+ return((SocketUDP *) this)->getAddr();
+}
+
+// ----------------------------------------------------------------------------
+unsigned int
+Communications::getPort(void)
+{
+ return((SocketUDP *) this)->getPort();
+}
+
+// ----------------------------------------------------------------------------
+//! read message.
+/*! Reads a message either from the network or from the federate
+ Returns the actual source in the 1st parameter (RTIG=>1 federate=>2)
+*/
+void
+Communications::readMessage(int &n, NetworkMessage *msg_reseau, Message *msg)
+{
+ // initialize fdset for use with select.
+ D.Out(pdTrace,"Initialise fd_set");
+ fd_set fdset ;
+ FD_ZERO(&fdset);
+ FD_SET(_socket_un, &fdset);
+ FD_SET(SecureTCPSocket::returnSocket(), &fdset);
+ FD_SET(SocketUDP::returnSocket(), &fdset);
+
+#ifdef FEDERATION_USES_MULTICAST
+ // if multicast link is initialized (during join federation).
+ if (_est_init_mc)
+ FD_SET(_socket_mc, &fdset);
+#endif
+
+ if (!waitingList.empty()) {
+ // One message is in waiting buffer.
+ NetworkMessage *msg2 ;
+ msg2 = waitingList.front();
+ waitingList.pop_front();
+ memcpy(msg_reseau, msg2, TAILLE_MSG_RESEAU);
+ delete msg2 ;
+ n = 1 ;
+ }
+ /* else if (SecureTCPSocket::isDataReady() == RTI_TRUE) {
+ // Datas are in TCP waiting buffer.
+ // Read a message from RTIG TCP link.
+ msg_reseau->read((SecureTCPSocket *) this);
+ n = 1 ;
+ }
+ else if (SocketUDP::isDataReady() == RTI_TRUE) {
+ // Datas are in UDP waiting buffer.
+ // Read a message from RTIG UDP link.
+ msg_reseau->read((SocketUDP *) this);
+ n = 1 ;
+ } */
+ else if (SocketUN::isDataReady() == RTI_TRUE) {
+ // Datas are in UNIX waiting buffer.
+ // Read a message from federate UNIX link.
+ msg->read((SocketUN *) this);
+ n = 2 ;
+ }
+ else if (SocketSHM::isDataReady() == RTI_TRUE){
+ msg_reseau->read((SocketSHM *) this);
+ n = 1 ;
+ }
+ else {
+ // waitingList is empty and no data in TCP buffer.
+ // Wait a message (coming from federate or network).
+ int result = 0;
+ struct timeval delai;
+ delai.tv_sec = 0;
+ delai.tv_usec = 0;
+ D.Out(pdTrace,"Attente message");
+ while(result ==0){
+ // if(!FD_ISSET(SecureTCPSocket::returnSocket(),
&fdset)){D.Out(pdTrace,"Erreur socketTCP non selecte "); }
+ // if(!FD_ISSET(SocketUDP::returnSocket(),
&fdset)){D.Out(pdTrace,"Erreur socketUDP non selecte");
+ // FD_SET(SocketUDP::returnSocket(), &fdset);}
+ if(!FD_ISSET(_socket_un, &fdset)){
+ D.Out(pdTrace,"Erreur socketUN non selecte");
+ FD_SET(_socket_un, &fdset);
+ }
+
+ if ((result=select(ulimit(4, 0), &fdset, NULL, NULL, &delai)) < 0)
{
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else
+ throw NetworkError();
+ }
+
+
+ if (SocketSHM::isDataReady() == RTI_TRUE){
+ result = 1;
+ }
+
+ if ( result == 0 ) sched_yield ( ) ;
+ // sched_yield ( ) ;
+
+ } // end while
+
+ D.Out(pdTrace,"Message recu");
+ // At least one message has been received, read this message.
+
+#ifdef FEDERATION_USES_MULTICAST
+ // Priorite aux messages venant du multicast(pour essayer d'eviter
+ // un depassement de la file et donc la perte de messages)
+
+ if (_est_init_mc && FD_ISSET(_socket_mc, &fdset)) {
+ // Read a message coming from the multicast link.
+ receiveMC(msg_reseau);
+ n = 1 ;
+ }
+#endif
+
+ if (FD_ISSET(SecureTCPSocket::returnSocket(), &fdset)) {
+ // Read a message coming from the TCP link with RTIG.
+ msg_reseau->read((SecureTCPSocket *) this);
+ n = 1 ;
+ }
+ else if (FD_ISSET(SocketUDP::returnSocket(), &fdset)) {
+ // Read a message coming from the UDP link with RTIG.
+ msg_reseau->read((SocketUDP *) this);
+ n = 1 ;
+ }
+ else if (FD_ISSET(_socket_un, &fdset)){
+ // Read a message coming from the federate.
+ receiveUN(msg);
+ n = 2 ;
+ }
+ else {
+ msg_reseau->read((SocketSHM *) this);
+ n = 1 ;
+ }
+ }
+}
+
+// ----------------------------------------------------------------------------
+/*! Returns RTI_TRUE if a 'type_msg' message coming from federate
+ 'numeroFedere' (or any other federate if numeroFedere == 0) was in
+ the queue and was copied in 'msg'. If no such message is found,
+ returns RTI_FALSE.
+*/
+Boolean
+Communications::searchMessage(TypeNetworkMessage type_msg,
+ FederateHandle numeroFedere,
+ NetworkMessage *msg)
+{
+ list<NetworkMessage *>::iterator i ;
+ for (i = waitingList.begin(); i != waitingList.end(); i++) {
+
+ D.Out(pdProtocol, "Rechercher message de type %d .", type_msg);
+
+ if ((*i)->type == type_msg) {
+ // if numeroFedere != 0, verify that federateNumbers are similar
+ if (((*i)->federate == numeroFedere) || (numeroFedere == 0)) {
+ memcpy(msg, (*i), TAILLE_MSG_RESEAU);
+ waitingList.erase(i);
+ delete (*i);
+ D.Out(pdProtocol,
+ "Message of Type %d was already here.",
+ type_msg);
+ return RTI_TRUE ;
+ }
+ }
+ }
+ return RTI_FALSE ;
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::sendMessage(NetworkMessage *Msg)
+{
+ Msg->write((SocketSHM *) this);
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::sendUN(Message *Msg)
+{
+ D.Out(pdProtocol, "Send Message Unix");
+ Msg->write((SocketUN *) this);
+ D.Out(pdProtocol, "Send Message Unix, done");
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::receiveUN(Message *Msg)
+{
+ Msg->read((SocketUN *) this);
+}
+
+}} // namespace certi/rtia
+
+// $Id: Communications.cc_V2,v 1.1.2.1 2009/07/08 14:48:03 erk Exp $
Index: RTIA/Communications.cc.ok
===================================================================
RCS file: RTIA/Communications.cc.ok
diff -N RTIA/Communications.cc.ok
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RTIA/Communications.cc.ok 8 Jul 2009 14:48:03 -0000 1.1.2.1
@@ -0,0 +1,331 @@
+// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002, 2003 ONERA
+//
+// This file is part of CERTI
+//
+// CERTI is free software ; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation ; either version 2 of the License, or
+// (at your option) any later version.
+//
+// CERTI is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// $Id: Communications.cc.ok,v 1.1.2.1 2009/07/08 14:48:03 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include "Communications.hh"
+
+namespace certi {
+namespace rtia {
+
+static pdCDebug D("RTIA_COMM", "(RTIA Comm) ");
+
+// ----------------------------------------------------------------------------
+/*! Wait a message coming from RTIG. Parameters are :
+ 1- Returned message,
+ 2- Message type expected,
+ 3- Federate which sent the message, 0 if indifferent.
+*/
+void Communications::waitMessage(NetworkMessage *msg,
+ TypeNetworkMessage type_msg,
+ FederateHandle numeroFedere)
+{
+ NetworkMessage *tampon ;
+
+ assert(type_msg > 0 && type_msg < 100);
+
+ D.Out(pdProtocol, "Waiting for Message of Type %d.", type_msg);
+
+ // Does a new message has arrived ?
+ if (searchMessage(type_msg, numeroFedere, msg) == RTI_TRUE)
+ return ;
+
+ // Otherwise, wait for a message with same type than expected and with
+ // same federate number.
+ tampon = new NetworkMessage ;
+ //tampon->read((SecureTCPSocket *)this);
+ tampon->read((SocketSHM *)this);
+
+ D.Out(pdProtocol, "TCP Message of Type %d has arrived.", type_msg);
+
+ while ((tampon->type != type_msg) ||
+ ((numeroFedere != 0) && (tampon->federate != numeroFedere))) {
+ waitingList.push_back(tampon);
+ tampon = new NetworkMessage ;
+ tampon->read((SocketSHM *)this);
+ //tampon->read((SecureTCPSocket *) this);
+
+ D.Out(pdProtocol, "Message of Type %d has arrived.", type_msg);
+ }
+
+ // BUG: Should use copy operator.
+ memcpy((void *) msg, (void *) tampon, sizeof(NetworkMessage));
+ delete tampon ;
+
+ assert(msg != NULL);
+ assert(msg->type == type_msg);
+}
+
+// ----------------------------------------------------------------------------
+//! Communications.
+Communications::Communications(void)
+ : SocketUN(), SecureTCPSocket(), SocketUDP(), SocketSHM()
+{
+ char nom_serveur_RTIG[200] ;
+
+ // Federate/RTIA link creation.
+ acceptUN();
+
+ // RTIG TCP link creation.
+ char *certihost = getenv("CERTI_HOST");
+
+ ifstream* file = NULL ;
+ if (certihost==NULL) {
+ file = new ifstream("RTIA.dat", ios::in);
+ if (!file->is_open()) {
+ cout << "RTIA ERROR: Unable to find RTIG host." << endl ;
+ cout << "No RTIA.dat file found, no CERTI_HOST variable set" <<
endl ;
+ exit(-1);
+ }
+
+ file->get(nom_serveur_RTIG, 200);
+ file->close();
+ delete file ;
+ certihost = nom_serveur_RTIG ;
+ }
+
+ const char *tcp_port = getenv("CERTI_TCP_PORT");
+ const char *udp_port = getenv("CERTI_UDP_PORT");
+ if (tcp_port==NULL) tcp_port = PORT_TCP_RTIG ;
+ if (udp_port==NULL) udp_port = PORT_UDP_RTIG ;
+
+ //createTCPClient(atoi(tcp_port), certihost);
+ createSHMClient(atoi(tcp_port), certihost);
+ createUDPClient(atoi(udp_port), certihost);
+}
+
+// ----------------------------------------------------------------------------
+//! ~Communications.
+Communications::~Communications(void)
+{
+ // Advertise RTIG that TCP link is being closed.
+
+ NetworkMessage msg ;
+ msg.type = m_CLOSE_CONNEXION ;
+ msg.write((SocketSHM *) this);
+
+ SecureTCPSocket::close();
+}
+
+// ----------------------------------------------------------------------------
+//! Request a service to federate.
+void
+Communications::requestFederateService(Message *req, Message *rep)
+{
+ assert(req != NULL);
+ D.Out(pdRequest, "Sending Request to Federate, Type %d.", req->type);
+ sendUN(req);
+ receiveUN(rep);
+ D.Out(pdAnswer, "Received Answer from Federate.");
+ assert(req->type == rep->type);
+}
+
+// ----------------------------------------------------------------------------
+unsigned long
+Communications::getAddress(void)
+{
+ return((SocketUDP *) this)->getAddr();
+}
+
+// ----------------------------------------------------------------------------
+unsigned int
+Communications::getPort(void)
+{
+ return((SocketUDP *) this)->getPort();
+}
+
+// ----------------------------------------------------------------------------
+//! read message.
+/*! Reads a message either from the network or from the federate
+ Returns the actual source in the 1st parameter (RTIG=>1 federate=>2)
+*/
+void
+Communications::readMessage(int &n, NetworkMessage *msg_reseau, Message *msg)
+{
+ // initialize fdset for use with select.
+ D.Out(pdTrace,"Initialise fd_set");
+ fd_set fdset ;
+ FD_ZERO(&fdset);
+ FD_SET(_socket_un, &fdset);
+ FD_SET(SecureTCPSocket::returnSocket(), &fdset);
+ FD_SET(SocketUDP::returnSocket(), &fdset);
+
+#ifdef FEDERATION_USES_MULTICAST
+ // if multicast link is initialized (during join federation).
+ if (_est_init_mc)
+ FD_SET(_socket_mc, &fdset);
+#endif
+
+ if (!waitingList.empty()) {
+ // One message is in waiting buffer.
+ NetworkMessage *msg2 ;
+ msg2 = waitingList.front();
+ waitingList.pop_front();
+ memcpy(msg_reseau, msg2, TAILLE_MSG_RESEAU);
+ delete msg2 ;
+ n = 1 ;
+ }
+ else if (SecureTCPSocket::isDataReady() == RTI_TRUE) {
+ // Datas are in TCP waiting buffer.
+ // Read a message from RTIG TCP link.
+ msg_reseau->read((SecureTCPSocket *) this);
+ n = 1 ;
+ }
+ else if (SocketUDP::isDataReady() == RTI_TRUE) {
+ // Datas are in UDP waiting buffer.
+ // Read a message from RTIG UDP link.
+ msg_reseau->read((SocketUDP *) this);
+ n = 1 ;
+ }
+ else if (SocketUN::isDataReady() == RTI_TRUE) {
+ // Datas are in UNIX waiting buffer.
+ // Read a message from federate UNIX link.
+ msg->read((SocketUN *) this);
+ n = 2 ;
+ }
+ else if (SocketSHM::isDataReady() == RTI_TRUE){
+ msg_reseau->read((SocketSHM *) this);
+ n = 1 ;
+ }
+ else {
+ // waitingList is empty and no data in TCP buffer.
+ // Wait a message (coming from federate or network).
+ int result = 0;
+ struct timeval delai;
+ delai.tv_sec = 0;
+ delai.tv_usec = 0;
+ D.Out(pdTrace,"Attente message");
+ while(result ==0){
+ if(!FD_ISSET(SecureTCPSocket::returnSocket(),
&fdset)){D.Out(pdTrace,"Erreur socketTCP non selecte ");
+ }
+ if(!FD_ISSET(SocketUDP::returnSocket(),
&fdset)){D.Out(pdTrace,"Erreur socketUDP non selecte");
+ FD_SET(SocketUDP::returnSocket(), &fdset);}
+ if(!FD_ISSET(_socket_un, &fdset)){D.Out(pdTrace,"Erreur socketUN non
selecte");
+ FD_SET(_socket_un, &fdset);}
+
+ if ((result=select(ulimit(4, 0), &fdset, NULL, NULL, &delai)) < 0) {
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else
+ throw NetworkError();
+ }
+
+
+ if (SocketSHM::isDataReady() == RTI_TRUE){
+ result = 1;
+ }
+ if (result == 0) sched_yield();
+ }
+ D.Out(pdTrace,"Message recu");
+ // At least one message has been received, read this message.
+
+#ifdef FEDERATION_USES_MULTICAST
+ // Priorite aux messages venant du multicast(pour essayer d'eviter
+ // un depassement de la file et donc la perte de messages)
+
+ if (_est_init_mc && FD_ISSET(_socket_mc, &fdset)) {
+ // Read a message coming from the multicast link.
+ receiveMC(msg_reseau);
+ n = 1 ;
+ }
+#endif
+
+ if (FD_ISSET(SecureTCPSocket::returnSocket(), &fdset)) {
+ // Read a message coming from the TCP link with RTIG.
+ msg_reseau->read((SecureTCPSocket *) this);
+ n = 1 ;
+ }
+ else if (FD_ISSET(SocketUDP::returnSocket(), &fdset)) {
+ // Read a message coming from the UDP link with RTIG.
+ msg_reseau->read((SocketUDP *) this);
+ n = 1 ;
+ }
+ else if (FD_ISSET(_socket_un, &fdset)){
+ // Read a message coming from the federate.
+ receiveUN(msg);
+ n = 2 ;
+ }
+ else{
+ msg_reseau->read((SocketSHM *) this);
+ n = 1 ;
+ }
+ }
+}
+
+// ----------------------------------------------------------------------------
+/*! Returns RTI_TRUE if a 'type_msg' message coming from federate
+ 'numeroFedere' (or any other federate if numeroFedere == 0) was in
+ the queue and was copied in 'msg'. If no such message is found,
+ returns RTI_FALSE.
+*/
+Boolean
+Communications::searchMessage(TypeNetworkMessage type_msg,
+ FederateHandle numeroFedere,
+ NetworkMessage *msg)
+{
+ list<NetworkMessage *>::iterator i ;
+ for (i = waitingList.begin(); i != waitingList.end(); i++) {
+
+ D.Out(pdProtocol, "Rechercher message de type %d .", type_msg);
+
+ if ((*i)->type == type_msg) {
+ // if numeroFedere != 0, verify that federateNumbers are similar
+ if (((*i)->federate == numeroFedere) || (numeroFedere == 0)) {
+ memcpy(msg, (*i), TAILLE_MSG_RESEAU);
+ waitingList.erase(i);
+ delete (*i);
+ D.Out(pdProtocol,
+ "Message of Type %d was already here.",
+ type_msg);
+ return RTI_TRUE ;
+ }
+ }
+ }
+ return RTI_FALSE ;
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::sendMessage(NetworkMessage *Msg)
+{
+ Msg->write((SocketSHM *) this);
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::sendUN(Message *Msg)
+{
+ D.Out(pdProtocol, "Send Message Unix");
+ Msg->write((SocketUN *) this);
+ D.Out(pdProtocol, "Send Message Unix, done");
+}
+
+// ----------------------------------------------------------------------------
+void
+Communications::receiveUN(Message *Msg)
+{
+ Msg->read((SocketUN *) this);
+}
+
+}} // namespace certi/rtia
+
+// $Id: Communications.cc.ok,v 1.1.2.1 2009/07/08 14:48:03 erk Exp $
Index: RTIA/.cvsignore
===================================================================
RCS file: RTIA/.cvsignore
diff -N RTIA/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RTIA/.cvsignore 8 Jul 2009 14:48:03 -0000 1.2.6.2
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
Index: libRTI/.cvsignore
===================================================================
RCS file: libRTI/.cvsignore
diff -N libRTI/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libRTI/.cvsignore 8 Jul 2009 14:48:03 -0000 1.2.6.2
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi .cvsignore myconf test/include/.cvsignore... [CERTI-SHM],
certi-cvs <=