[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi RTIG/Federation.cc RTIG/FederationsList.c... [CERTI-SH
From: |
certi-cvs |
Subject: |
[certi-cvs] certi RTIG/Federation.cc RTIG/FederationsList.c... [CERTI-SHM] |
Date: |
Thu, 28 May 2009 20:58:26 +0000 |
CVSROOT: /sources/certi
Module name: certi
Branch: CERTI-SHM
Changes by: Eric NOULARD <erk> 09/05/28 20:58:26
Modified files:
RTIG : Federation.cc FederationsList.cc
RTIG_processing.cc RTIG.cc RTIG.hh
libCERTI : NetworkMessage.cc SocketTCP.cc Interaction.cc
NetworkMessage.hh NetworkMessage_RW.cc
FedParser_Build.cc XmlParser.hh XmlParser.cc
SocketServer.hh MessageBody.hh MessageBody.cc
Socket.hh GAV.cc Message_RW.cc FedParser.hh
SocketServer.cc Makefile.am
RTIA : RTIA.cc Communications.cc Communications.hh
test/Billard : billard.cc
libpdebug : DebugOStream.hh PrettyDebug.cc
include : local_config.hh
libRTI : RTIambassador.cc
Added files:
libCERTI : CCom.hh SocketSHM.hh SocketSHM.cc_v1 CCom.cc
SocketSHM.cc
RTIA : Communications.cc_v1 Communications.cc_V2
Communications.cc.ok
test/Billard : billard.cc_v1
Log message:
Check-on presumed last (and working) CERTI-SHM version
taken from ftp://ftp.cert.fr/pub/siron/certi-SHM-3.0.tar.gz
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/Federation.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.12&r2=3.12.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/FederationsList.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.9&r2=3.9.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG_processing.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.7&r2=3.7.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.7&r2=3.7.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.7&r2=3.7.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/NetworkMessage.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.4&r2=3.4.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketTCP.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.5&r2=3.5.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Interaction.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.10&r2=3.10.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/NetworkMessage.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.4&r2=3.4.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/NetworkMessage_RW.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.4&r2=3.4.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/FedParser_Build.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.6&r2=3.6.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/XmlParser.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.6&r2=3.6.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/XmlParser.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.8&r2=3.8.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketServer.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.4&r2=3.4.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/MessageBody.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.4&r2=3.4.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/MessageBody.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.3&r2=3.3.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Socket.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.3&r2=3.3.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/GAV.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.5&r2=3.5.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Message_RW.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.7&r2=3.7.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/FedParser.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.7&r2=3.7.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketServer.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.5&r2=3.5.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Makefile.am?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.8&r2=3.8.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/CCom.hh?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHM.hh?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHM.cc_v1?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/CCom.cc?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHM.cc?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/RTIA.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.6&r2=3.6.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.7&r2=3.7.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.5&r2=3.5.2.1
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/test/Billard/billard.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.13&r2=3.13.2.1
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/libpdebug/DebugOStream.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.0&r2=3.0.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libpdebug/PrettyDebug.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.3&r2=3.3.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/include/local_config.hh?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.2&r2=3.2.6.1
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/RTIambassador.cc?cvsroot=certi&only_with_tag=CERTI-SHM&r1=3.18&r2=3.18.2.1
Patches:
Index: RTIG/Federation.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/Federation.cc,v
retrieving revision 3.12
retrieving revision 3.12.2.1
diff -u -b -r3.12 -r3.12.2.1
--- RTIG/Federation.cc 21 Mar 2003 15:06:46 -0000 3.12
+++ RTIG/Federation.cc 28 May 2009 20:58:20 -0000 3.12.2.1
@@ -19,7 +19,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: Federation.cc,v 3.12 2003/03/21 15:06:46 breholee Exp $
+// $Id: Federation.cc,v 3.12.2.1 2009/05/28 20:58:20 erk Exp $
// ----------------------------------------------------------------------------
#include "Federation.hh"
@@ -478,12 +478,14 @@
RestoreInProgress,
RTIinternalError)
{
+ D.Out(pdTerm, "check federate");
this->check(federate); // It may throw FederateNotExecutionMember.
-
+ D.Out(pdTerm, "check federate done");
if ((label == NULL) || (strlen(label) > MAX_USER_TAG_LENGTH))
throw RTIinternalError("Bad pause label(null or too long).");
// Verify label does not already exists
+ D.Out(pdTerm, "verify map");
std::map<const char *, const char *>::const_iterator i ;
i = synchronizationLabels.begin();
for (; i != synchronizationLabels.end(); i++) {
@@ -491,14 +493,16 @@
throw FederationAlreadyPaused(); // Label already pending.
}
}
-
+D.Out(pdTerm, "synchronizationLabels insert");
// If not already in pending labels, insert to list.
synchronizationLabels.insert(pair<const char *, const char
*>(strdup(label),
strdup(tag)));
-
+D.Out(pdTerm, "add label");
// Add label to each federate (may throw RTIinternalError).
list<Federate *>::iterator j ;
for (j = begin(); j != end(); j++) {
+ if((*j)==NULL)D.Out(pdTerm, "pointeur null");
+ else D.Out(pdTerm, "pointeur non null");
(*j)->addSynchronizationLabel(label);
}
@@ -746,6 +750,15 @@
Federation::remove(FederateHandle federate_handle)
throw (FederateOwnsAttributes, FederateNotExecutionMember)
{
+ // Supprime les references au federe pour les classes d'objets
+ D.Out(pdInit, "Federate %d removed from the Root Object tree...",
federate_handle);
+ root->ObjectClasses->killFederate(federate_handle);
+
+ // Supprime les references au federe pour les classes d'interactions.
+ D.Out(pdInit, "Federate %d removed from the Root Inteaction tree...",
+ federate_handle);
+ root->Interactions->killFederate(federate_handle);
+
for (list<Federate *>::iterator i = begin(); i != end(); i++) {
if ((*i)->getHandle() == federate_handle) {
// BUG: RemoveFederate: Should see if Federate owns attributes
@@ -1259,5 +1272,5 @@
}} // namespace certi/rtig
-// $Id: Federation.cc,v 3.12 2003/03/21 15:06:46 breholee Exp $
+// $Id: Federation.cc,v 3.12.2.1 2009/05/28 20:58:20 erk Exp $
Index: RTIG/FederationsList.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/FederationsList.cc,v
retrieving revision 3.9
retrieving revision 3.9.2.1
diff -u -b -r3.9 -r3.9.2.1
--- RTIG/FederationsList.cc 21 Mar 2003 15:06:46 -0000 3.9
+++ RTIG/FederationsList.cc 28 May 2009 20:58:20 -0000 3.9.2.1
@@ -19,7 +19,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: FederationsList.cc,v 3.9 2003/03/21 15:06:46 breholee Exp $
+// $Id: FederationsList.cc,v 3.9.2.1 2009/05/28 20:58:20 erk Exp $
// ----------------------------------------------------------------------------
#include "FederationsList.hh"
@@ -117,11 +117,12 @@
throw (FederationExecutionDoesNotExist, RTIinternalError)
{
federation = NULL ;
-
+D.Out(pdTrace, "searchFederation");
// It may raise RTIinternalError
checkHandle(handle);
list<Federation *>::const_iterator i = begin();
+ D.Out(pdTrace, "begin search");
for (int j = 1 ; i != end(); i++, j++) {
if ((*i)->getHandle() == handle) {
federation = (*i);
@@ -351,6 +352,7 @@
FederationsList::checkHandle(FederationHandle handle)
throw (RTIinternalError)
{
+D.Out(pdTrace, "checkHandle");
if (handle <= 0) {
D.Out(pdExcept, "Illegal Handle %d.", handle);
throw RTIinternalError("Negative or null FederationHandle.");
@@ -469,10 +471,12 @@
searchFederation(handle, federation);
// It may throw a bunch of exceptions.
- if (state)
- federation->registerSynchronization(federate, label, tag);
- else
- federation->unregisterSynchronization(federate, label);
+ if (state){
+ D.Out(pdTrace, "call registerSynchronization");
+ federation->registerSynchronization(federate, label, tag);}
+ else{
+ D.Out(pdTrace, "call unregisterSynchronization");
+ federation->unregisterSynchronization(federate, label);}
}
// ---------------------------------------------------------------------------
@@ -1003,5 +1007,5 @@
}}
-// EOF $Id: FederationsList.cc,v 3.9 2003/03/21 15:06:46 breholee Exp $
+// EOF $Id: FederationsList.cc,v 3.9.2.1 2009/05/28 20:58:20 erk Exp $
Index: RTIG/RTIG_processing.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG_processing.cc,v
retrieving revision 3.7
retrieving revision 3.7.2.1
diff -u -b -r3.7 -r3.7.2.1
--- RTIG/RTIG_processing.cc 21 Mar 2003 15:06:46 -0000 3.7
+++ RTIG/RTIG_processing.cc 28 May 2009 20:58:20 -0000 3.7.2.1
@@ -19,7 +19,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: RTIG_processing.cc,v 3.7 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIG_processing.cc,v 3.7.2.1 2009/05/28 20:58:20 erk Exp $
// ----------------------------------------------------------------------------
#include "RTIG.hh"
@@ -251,13 +251,16 @@
void
RTIG::processRegisterSynchronization(Socket *link, NetworkMessage *req)
{
+ D.Out(pdTrace,"Call addToLinef");
auditServer->addToLinef("Label \"%s\" registered. Tag is \"%s\"",
req->label, req->tag);
+ D.Out(pdTrace,"Call manageSynchronization");
federations->manageSynchronization(req->federation,
req->federate,
true,
req->label,
req->tag);
+ D.Out(pdTrace,"End
of manageSynchronization");
D.Out(pdTerm, "Federation %u is now synchronizing.", req->federation);
// send synchronizationPointRegistrationSucceeded() to federate.
@@ -286,6 +289,7 @@
false,
req->label,
"");
+
D.Out(pdTerm, "Federate %u has synchronized.", req->federate);
}
@@ -824,4 +828,4 @@
}} // namespace certi/rtig
-// $Id: RTIG_processing.cc,v 3.7 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIG_processing.cc,v 3.7.2.1 2009/05/28 20:58:20 erk Exp $
Index: RTIG/RTIG.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG.cc,v
retrieving revision 3.7
retrieving revision 3.7.2.1
diff -u -b -r3.7 -r3.7.2.1
--- RTIG/RTIG.cc 21 Mar 2003 15:06:46 -0000 3.7
+++ RTIG/RTIG.cc 28 May 2009 20:58:21 -0000 3.7.2.1
@@ -19,7 +19,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: RTIG.cc,v 3.7 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIG.cc,v 3.7.2.1 2009/05/28 20:58:21 erk Exp $
// ----------------------------------------------------------------------------
#include "RTIG.hh"
@@ -85,7 +85,8 @@
RTIG::chooseProcessingMethod(Socket *link, NetworkMessage *msg)
{
- // This may throw a security error.
+ // This may throw a security error
+ D.Out(pdTrace,"link->returnSocket() : %d",link->returnSocket());
socketServer->checkMessage(link->returnSocket(), msg);
switch(msg->type) {
@@ -116,20 +117,20 @@
break ;
case m_CREATE_FEDERATION_EXECUTION:
- D.Out(pdTrace, "Create federation \"%s\".", msg->federation);
+ D.Out(pdTrace, "Create federation \"%s\".", msg->federationName);
auditServer->setLevel(9);
processCreateFederation(link, msg);
break ;
case m_DESTROY_FEDERATION_EXECUTION:
- D.Out(pdTrace, "Destroy federation \"%s\".", msg->federation);
+ D.Out(pdTrace, "Destroy federation \"%s\".", msg->federationName);
auditServer->setLevel(9);
processDestroyFederation(link, msg);
break ;
case m_JOIN_FEDERATION_EXECUTION:
D.Out(pdTrace, "federate \"%s\" joins federation \"%s\".",
- msg->federate, msg->federation);
+ msg->federateName, msg->federationName);
auditServer->setLevel(9);
processJoinFederation(link, msg);
break ;
@@ -145,8 +146,11 @@
D.Out(pdTrace,
"Federation %u: registerFedSyncPoint from federate %u.",
msg->federation, msg->federate);
+ D.Out(pdTrace,"Call set Level");
auditServer->setLevel(8);
+ D.Out(pdTrace,"Call processRegisterSynchronization");
processRegisterSynchronization(link, msg);
+
break ;
case m_SYNCHRONIZATION_POINT_ACHIEVED:
@@ -311,7 +315,7 @@
{
int result ;
fd_set fd ;
- Socket *link ;
+ SocketTuple *link ;
// create TCP and UDP connections for the RTIG server
udpSocketServer.createUDPServer(udpPort);
@@ -322,41 +326,40 @@
terminate = false ;
- while (!terminate) {
- // Initialize fd_set structure with all opened sockets.
FD_ZERO(&fd);
FD_SET(tcpSocketServer.returnSocket(), &fd);
- socketServer->addToFDSet(&fd);
+ ::select(ulimit(4, 0), &fd, NULL, NULL,NULL);
+
+ while (!terminate) {
- // Wait for an incoming message.
- result = 0 ;
- result = select(ulimit(4, 0), &fd, NULL, NULL, NULL);
- if ((result == -1)&& (errno == EINTR)) break ;
- // Is it a message from an already opened connection?
- link = socketServer->getActiveSocket(&fd);
+ D.Out(pdTrace, "Waiting for request");
+ link = socketServer->select(&fd, &terminate);
+ if (terminate)
+ break;
if (link != NULL) {
- D.Out(pdCom, "Incoming message on socket %ld.",
link->returnSocket());
+ D.Out(pdCom, "Incoming message on socket %ld.",
link->QuickLink->returnSocket());
try {
do {
- link = processIncomingMessage((SecureTCPSocket *)link);
- if (link == NULL)break ;
- } while (link->isDataReady()== RTI_TRUE);
+ link->QuickLink =
(SocketSHM*)processIncomingMessage(link->QuickLink);
+ if (link ->QuickLink== NULL)break ;
+ D.Out(pdTrace, "Request processed");
+ } while (link->QuickLink->isDataReady()== RTI_TRUE);
}
catch (NetworkError &e) {
if (e._reason != NULL)
D.Out(pdExcept, "Catching Network Error, reason : %s",
e._reason);
else
D.Out(pdExcept, "Catching Network Error, no reason
string.");
- cout << "RTIG dropping client connection " <<
link->returnSocket()
+ cout << "RTIG dropping client connection " <<
link->QuickLink->returnSocket()
<< '.' << endl ;
- closeConnection((SecureTCPSocket *)link, true);
+ closeConnection((SocketSHM *)link->QuickLink, true);
link = NULL ;
}
}
// Or on the server socket ?
- if (FD_ISSET(tcpSocketServer.returnSocket(), &fd)) {
+ else{
D.Out(pdCom, "Demande de connexion.");
openConnection();
}
@@ -864,4 +867,4 @@
}} // namespace certi/rtig
-// $Id: RTIG.cc,v 3.7 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIG.cc,v 3.7.2.1 2009/05/28 20:58:21 erk Exp $
Index: RTIG/RTIG.hh
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG.hh,v
retrieving revision 3.7
retrieving revision 3.7.2.1
diff -u -b -r3.7 -r3.7.2.1
--- RTIG/RTIG.hh 21 Mar 2003 15:06:46 -0000 3.7
+++ RTIG/RTIG.hh 28 May 2009 20:58:21 -0000 3.7.2.1
@@ -19,7 +19,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: RTIG.hh,v 3.7 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIG.hh,v 3.7.2.1 2009/05/28 20:58:21 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_RTIG_HH
@@ -30,6 +30,7 @@
#include "RTItypes.hh"
#include "NetworkMessage.hh"
#include "SecureTCPSocket.hh"
+#include "SocketSHM.hh"
#include "SocketMC.hh"
#include "SocketServer.hh"
#include "FederationsList.hh"
@@ -125,4 +126,4 @@
#endif // _CERTI_RTIG_HH
// ----------------------------------------------------------------------------
-// $Id: RTIG.hh,v 3.7 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIG.hh,v 3.7.2.1 2009/05/28 20:58:21 erk Exp $
Index: libCERTI/NetworkMessage.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/NetworkMessage.cc,v
retrieving revision 3.4
retrieving revision 3.4.2.1
diff -u -b -r3.4 -r3.4.2.1
--- libCERTI/NetworkMessage.cc 19 Feb 2003 18:07:30 -0000 3.4
+++ libCERTI/NetworkMessage.cc 28 May 2009 20:58:21 -0000 3.4.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: NetworkMessage.cc,v 3.4 2003/02/19 18:07:30 breholee Exp $
+// $Id: NetworkMessage.cc,v 3.4.2.1 2009/05/28 20:58:21 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
@@ -29,6 +29,8 @@
namespace certi {
+static pdCDebug D("NETWORK_MESSAGE", "(NetworkMes) - ");
+
// -------------
// -- Affiche --
// -------------
@@ -36,15 +38,15 @@
void
NetworkMessage::display(const char *s)
{
- printf(" --- MESSAGE RESEAU --- %s ---\n", s);
- printf(" type = %d\n", type);
- printf(" number = %ld-%d\n", federate, number);
- printf(" date = %f\n", date);
- printf(" exception = %d\n", exception);
- printf(" ObjectHandle = %ld\n", objectClass);
- printf(" interactionClass= %ld\n", interactionClass);
- printf(" object = %ld\n", object);
- printf(" handleArraySize = %d\n", handleArraySize);
+ D.Out(pdTrace, "--- MESSAGE RESEAU --- %s ---", s);
+ D.Out(pdTrace, " type = %d", type);
+ D.Out(pdTrace, " number = %ld-%d", federate, number);
+ D.Out(pdTrace, " date = %f", date);
+ D.Out(pdTrace, " exception = %d", exception);
+ D.Out(pdTrace, " ObjectHandle = %ld", objectClass);
+ D.Out(pdTrace, " interactionClass= %ld", interactionClass);
+ D.Out(pdTrace, " object = %ld", object);
+ D.Out(pdTrace, " handleArraySize = %d", handleArraySize);
}
// --------------------
@@ -227,4 +229,4 @@
}
-// $Id: NetworkMessage.cc,v 3.4 2003/02/19 18:07:30 breholee Exp $
+// $Id: NetworkMessage.cc,v 3.4.2.1 2009/05/28 20:58:21 erk Exp $
Index: libCERTI/SocketTCP.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketTCP.cc,v
retrieving revision 3.5
retrieving revision 3.5.2.1
diff -u -b -r3.5 -r3.5.2.1
--- libCERTI/SocketTCP.cc 19 Feb 2003 18:07:30 -0000 3.5
+++ libCERTI/SocketTCP.cc 28 May 2009 20:58:21 -0000 3.5.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: SocketTCP.cc,v 3.5 2003/02/19 18:07:30 breholee Exp $
+// $Id: SocketTCP.cc,v 3.5.2.1 2009/05/28 20:58:21 erk Exp $
// ----------------------------------------------------------------------------
#include "SocketTCP.hh"
@@ -486,4 +486,4 @@
}
-// $Id: SocketTCP.cc,v 3.5 2003/02/19 18:07:30 breholee Exp $
+// $Id: SocketTCP.cc,v 3.5.2.1 2009/05/28 20:58:21 erk Exp $
Index: libCERTI/Interaction.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Interaction.cc,v
retrieving revision 3.10
retrieving revision 3.10.2.1
diff -u -b -r3.10 -r3.10.2.1
--- libCERTI/Interaction.cc 19 Feb 2003 18:07:29 -0000 3.10
+++ libCERTI/Interaction.cc 28 May 2009 20:58:22 -0000 3.10.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: Interaction.cc,v 3.10 2003/02/19 18:07:29 breholee Exp $
+// $Id: Interaction.cc,v 3.10.2.1 2009/05/28 20:58:22 erk Exp $
// ----------------------------------------------------------------------------
#include "Interaction.hh"
@@ -491,7 +491,7 @@
ParameterHandle *parameter_list,
ParameterValue *value_list,
UShort list_size,
- FederationTime,
+ FederationTime theTime,
const char *the_tag)
throw (FederateNotPublishing,
InteractionClassNotDefined,
@@ -511,6 +511,7 @@
answer->federation = server->federation();
answer->federate = federate_handle ;
answer->interactionClass = handle ; // Interaction Class Handle
+ answer->date = theTime ;
strcpy(answer->label, the_tag);
@@ -636,4 +637,4 @@
} // namespace certi
-// $Id: Interaction.cc,v 3.10 2003/02/19 18:07:29 breholee Exp $
+// $Id: Interaction.cc,v 3.10.2.1 2009/05/28 20:58:22 erk Exp $
Index: libCERTI/NetworkMessage.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/NetworkMessage.hh,v
retrieving revision 3.4
retrieving revision 3.4.2.1
diff -u -b -r3.4 -r3.4.2.1
--- libCERTI/NetworkMessage.hh 21 Mar 2003 15:06:46 -0000 3.4
+++ libCERTI/NetworkMessage.hh 28 May 2009 20:58:22 -0000 3.4.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: NetworkMessage.hh,v 3.4 2003/03/21 15:06:46 breholee Exp $
+// $Id: NetworkMessage.hh,v 3.4.2.1 2009/05/28 20:58:22 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_NETWORK_MESSAGE
@@ -28,6 +28,8 @@
#include <cstdio>
#include <cstring>
+#include <sched.h>
+#include <unistd.h>
#include "baseTypes.hh"
#include "RTItypes.hh"
#include "Exception.hh"
@@ -43,6 +45,17 @@
#define PORT_TCP_RTIG "60400"
#define PORT_UDP_RTIG "60500"
+// Taille de la chaine de caractères du message
+#define TAILLE_MESSAGE 256
+
+// Constantes full and empty
+
+#define FULL '1'
+#define EMPTY '0'
+
+// Nombre max de clients
+#define MAX_CLIENTS 100
+
#define MAX_EXCEPTION_REASON_LENGTH 100
namespace certi {
@@ -155,6 +168,26 @@
HeaderUnion VP ; // Variable Part
} HeaderStruct ;
+ // Shared Memory de communication entre client et serveur
+
+typedef struct {
+ char qui ; // char de synchronisation
+ HeaderStruct Header ;
+ MessageBody Body ;
+} SharedMemory ;
+
+typedef struct {
+ SharedMemory S_C ; // Zone serveur vers client
+ SharedMemory C_S ; // Zone client vers serveur
+} SHM ;
+
+ // Segment Mémoire pour la communication des id's de mémoires partagées
+
+typedef struct {
+ long num_client_propose ; // numéro de client = nom du fédéré
+ char num_client_reel [TAILLE_MESSAGE] ; // numéro de client réel retourné
par le serveur et indicateur de requête (join ou resign) de la part du client
+} MessageFile ;
+
class NetworkMessage
{
public :
@@ -190,6 +223,17 @@
// -- Network Public Methods --(cf. NetworkMessage_RW.cc)
// ----------------------------
+ // Read and Write NetworkMessage Objects to and from Shared Memory.
+
+ int write(SharedMemory *Shm, int wait)
+ throw (NetworkError,
+ NetworkSignal);
+
+ int read(SharedMemory *Shm, int wait)
+ throw (NetworkError,
+ NetworkSignal);
+
+
// Read and Write NetworkMessage Objects to and from Socket objects.
void write(Socket *Socket)
@@ -200,6 +244,15 @@
throw (NetworkError,
NetworkSignal);
+ // Selects the first C_S shared memory available for reading
+
+ int select_SHM_C_S_full(SHM **Shm,int *id_shm) ;
+
+ // Selects the first S_C shared memory available for writing
+
+ int select_SHM_S_C_empty(SHM **Shm,int *id_shm) ;
+
+
// ------------------------------
// -- Attribute Access Methods --
// ------------------------------
@@ -284,20 +337,24 @@
// Read a Message Body from a Socket. Should be called after ReadHeader.
void readBody(Socket *Socket);
+ void readBody(SharedMemory *shm);
// Read a Header from a socket, and process it to read its content.
// Return RTI_TRUE if the ReadBody Method has to be called.
Boolean readHeader(Socket *Socket);
+ Boolean readHeader(SharedMemory *shm);
// The message is written onto the socket by WriteHeader if no body
// is required, or by WriteBody is a body has been required by WriteHeader.
// Prepare and write a Body to a socket. Should be called after
// WriteHeader.
+ void writeBody(SharedMemory *Shm);
void writeBody(Socket *Socket);
// Prepare and Write a Header to a Socket, and return RTI_TRUE
// if the WriteBody method has to be called.
+ Boolean writeHeader(SharedMemory *Shm);
Boolean writeHeader(Socket *Socket);
// -- Others Private Read Methods --
@@ -315,4 +372,4 @@
#endif // _CERTI_NETWORK_MESSAGE
-// $Id: NetworkMessage.hh,v 3.4 2003/03/21 15:06:46 breholee Exp $
+// $Id: NetworkMessage.hh,v 3.4.2.1 2009/05/28 20:58:22 erk Exp $
Index: libCERTI/NetworkMessage_RW.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/NetworkMessage_RW.cc,v
retrieving revision 3.4
retrieving revision 3.4.2.1
diff -u -b -r3.4 -r3.4.2.1
--- libCERTI/NetworkMessage_RW.cc 21 Mar 2003 15:06:46 -0000 3.4
+++ libCERTI/NetworkMessage_RW.cc 28 May 2009 20:58:22 -0000 3.4.2.1
@@ -20,13 +20,14 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: NetworkMessage_RW.cc,v 3.4 2003/03/21 15:06:46 breholee Exp $
+// $Id: NetworkMessage_RW.cc,v 3.4.2.1 2009/05/28 20:58:22 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
#include "NetworkMessage.hh"
+#define USE_SHM
namespace certi {
static pdCDebug D("MESSAGER", "(messageR) - ");
@@ -35,15 +36,31 @@
#define USE_HEADER_AND_BODY
-// ----------
-// -- Read --
-// ----------
+// ----------------
+// -- Read Socket--
+// ----------------
void
NetworkMessage::read(Socket *socket)
throw (NetworkError,
NetworkSignal)
{
+#ifdef USE_SHM
+ Boolean Result;
+ SharedMemory shm;
+ D.Out(pdDebug, "Lecture sur le soket shm");
+ socket->receive(&shm,0);
+ D.Out(pdDebug, "Lecture achevee : traitement du Header");
+ Result = readHeader(&shm);
+
+ // 2- if ReadHeader returned RTI_TRUE, Read Body.
+
+ if (Result == RTI_TRUE)
+ {
+ D.Out(pdDebug, "Traitement du body");
+ readBody(&shm);
+ }
+#else
#ifdef USE_HEADER_AND_BODY
Boolean Result ;
@@ -59,12 +76,87 @@
Socket->receive(this, sizeof(NetworkMessage));
#endif
+#endif
+}
+
+// ------------------------
+// -- Read Shared Memory --
+// ------------------------
+
+int
+NetworkMessage::read(SharedMemory *shm, int wait)
+ throw (NetworkError,
+ NetworkSignal)
+
+// ----------------------------------------------------
+// if (wait)
+// wait until a message in shm is available
+// return 1 ;
+// else
+// if (a message in shm is available)
+// read the message ;
+// return 1 ;
+// else
+// return 0 ;
+// ----------------------------------------------------
+
+{
+#ifdef USE_HEADER_AND_BODY
+
+ Boolean Result ;
+
+
+ if (shm->qui == EMPTY)
+ if(wait)
+ D.Out(pdProtocol, "READ_INIT : Bloqué en lecture. Attente...");
+ else
+ {
+ D.Out(pdProtocol, "READ_INIT : Segment mémoire vide ...");
+ return 0 ;
+ }
+ else
+ D.Out(pdProtocol, "READ_INIT : Lecture autorisée ...");
+
+ // Synchronize
+
+ while (shm->qui == EMPTY)
+ {
+ if (sched_yield ())
+ {
+ D.Out(pdError, "READ_INIT : readMessage : sched_yield problem");
+ exit (-1) ;
+ }
+ }
+
+ D.Out(pdProtocol, "READ_DEBLOQUE : Je lis le header");
+
+ // 1- Read Header
+
+ Result = readHeader(shm);
+
+ // 2- if ReadHeader returned RTI_TRUE, Read Body.
+
+ if (Result == RTI_TRUE)
+ {
+ D.Out(pdDebug, "READ_DEBLOQUE : Je lis le body");
+ readBody(shm);
+ }
+
+ shm -> qui = EMPTY ;
+
+ D.Out(pdDebug, "READ_FIN");
+
+ return 1 ;
+
+#else
+
+#endif
}
-// --------------
-// -- ReadBody --
-// --------------
+// --------------------
+// -- ReadBody Socket--
+// --------------------
void
NetworkMessage::readBody(Socket *socket)
@@ -105,54 +197,782 @@
Body.readBlock((char *) handleArray,
handleArraySize * sizeof(AttributeHandle));
for (i = 0 ; i < handleArraySize ; i ++) {
- Body.readString(ValueArray[i], MAX_BYTES_PER_VALUE);
+ Body.readString(ValueArray[i], MAX_BYTES_PER_VALUE);
+ }
+ break ;
+
+ case m_CREATE_FEDERATION_EXECUTION:
+ case m_DESTROY_FEDERATION_EXECUTION:
+ readFederationName(&Body);
+ break ;
+
+ case m_REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
+ case m_ANNOUNCE_SYNCHRONIZATION_POINT:
+ readLabel(&Body);
+ readTag(&Body);
+ break ;
+
+ case m_SYNCHRONIZATION_POINT_ACHIEVED:
+ case m_SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED:
+ case m_FEDERATION_SYNCHRONIZED:
+ readLabel(&Body);
+ break ;
+
+ case m_DELETE_OBJECT:
+ case m_REMOVE_OBJECT:
+ object = Body.readLongInt();
+ readLabel(&Body);
+ break ;
+
+ // -- No Variable Part --
+
+ case m_IS_ATTRIBUTE_OWNED_BY_FEDERATE:
+ case m_INFORM_ATTRIBUTE_OWNERSHIP:
+ case m_ATTRIBUTE_IS_NOT_OWNED:
+ case m_QUERY_ATTRIBUTE_OWNERSHIP:
+ object = Body.readLongInt();
+ handleArray[0] = Body.readShortInt();
+ readLabel(&Body);
+ break ;
+
+
+ case m_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION:
+ case m_REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE:
+ object = Body.readLongInt();
+ handleArraySize = Body.readShortInt();
+ for (i = 0 ; i < handleArraySize ; i ++)
+ handleArray[i] = Body.readShortInt();
+ readLabel(&Body);
+ break ;
+
+
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION:
+ case m_ATTRIBUTE_OWNERSHIP_UNAVAILABLE:
+ case m_UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION:
+ case m_CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
+ case m_CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
+ case m_CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION:
+ object = Body.readLongInt();
+ handleArraySize = Body.readShortInt();
+ for (i = 0 ; i < handleArraySize ; i ++)
+ handleArray[i] = Body.readShortInt();
+ break ;
+
+
+
+ // -- Join Variable Part --
+
+ case m_JOIN_FEDERATION_EXECUTION:
+ readFederationName(&Body);
+ readFederateName(&Body);
+ break ;
+
+ // -- O_I Variable Part(Body not empty) --
+
+ case m_PUBLISH_OBJECT_CLASS:
+ case m_SUBSCRIBE_OBJECT_CLASS:
+ for (i = 0 ; i < handleArraySize ; i ++)
+ handleArray[i] = Body.readShortInt();
+ break ;
+
+ case m_REGISTER_OBJECT:
+ case m_DISCOVER_OBJECT:
+ object = Body.readLongInt();
+ readLabel(&Body);
+ break ;
+
+
+ // -- Default Handler --
+
+ default:
+ D.Out(pdExcept, "Unknown type %d in ReadBody.", Header.type);
+ throw RTIinternalError("Unknown/Unimplemented type for Body.");
+ }
+
+}
+
+
+// ----------------------
+// -- ReadHeader Socket--
+// ----------------------
+
+Boolean
+NetworkMessage::readHeader(Socket *socket)
+{
+ // 1- Read Header from Socket
+ socket->receive((void *) &Header, sizeof(HeaderStruct));
+
+ // 2- Parse Header(Static Part)
+ type = Header.type ;
+ exception = Header.exception ;
+ federate = Header.federate ;
+ federation = Header.federation ;
+
+ // 2- Parse Header according to its type(Variable Part)
+ // NULL, UAV and SendInteraction are the most common ones.
+
+ if (type == m_MESSAGE_NULL)
+ date = Header.VP.time.date ;
+
+ else if ((type == m_UPDATE_ATTRIBUTE_VALUES)
+ || (type == m_REFLECT_ATTRIBUTE_VALUES)) {
+ objectClass = Header.VP.O_I.handle ;
+ handleArraySize = Header.VP.O_I.size ;
+ date = Header.VP.O_I.date ;
+ }
+
+ else
+ switch(Header.type) {
+
+ case m_SEND_INTERACTION:
+ case m_RECEIVE_INTERACTION:
+ interactionClass = Header.VP.O_I.handle ;
+ handleArraySize = Header.VP.O_I.size ;
+ date = Header.VP.O_I.date ;
+ break ;
+
+ // -- No Variable Part --
+
+ case m_CREATE_FEDERATION_EXECUTION:
+ case m_DESTROY_FEDERATION_EXECUTION:
+ case m_REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
+ case m_SYNCHRONIZATION_POINT_ACHIEVED:
+ case m_SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED:
+ case m_FEDERATION_SYNCHRONIZED:
+ case m_ANNOUNCE_SYNCHRONIZATION_POINT:
+ case m_DELETE_OBJECT:
+ case m_REMOVE_OBJECT:
+ case m_CLOSE_CONNEXION:
+ case m_RESIGN_FEDERATION_EXECUTION:
+ case m_IS_ATTRIBUTE_OWNED_BY_FEDERATE:
+ case m_INFORM_ATTRIBUTE_OWNERSHIP:
+ case m_ATTRIBUTE_IS_NOT_OWNED:
+ case m_QUERY_ATTRIBUTE_OWNERSHIP:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION:
+ case m_ATTRIBUTE_OWNERSHIP_UNAVAILABLE:
+ case m_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION:
+ case m_UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION:
+ case m_REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE:
+ case m_ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION:
+ case m_CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
+ case m_CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
+ case m_CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION:
+ break ;
+
+ // -- time Variable Part(No Body)[Continued]--
+
+ case m_SET_TIME_REGULATING:
+ date = Header.VP.time.date ;
+ regulator = Header.VP.time.R_or_C ;
+ break ;
+
+ case m_SET_TIME_CONSTRAINED:
+ date = Header.VP.time.date ;
+ constrained = Header.VP.time.R_or_C ;
+ break ;
+
+ // -- ReqID Variable Part(No Body) --
+
+ case m_REQUEST_ID:
+ idCount = Header.VP.ReqID.count ;
+ firstId = Header.VP.ReqID.first ;
+ lastId = Header.VP.ReqID.last ;
+ break ;
+ // -- T_O Variable Part --
+
+ case m_CHANGE_ATTRIBUTE_TRANSPORT_TYPE:
+ case m_CHANGE_ATTRIBUTE_ORDER_TYPE:
+ case m_CHANGE_INTERACTION_TRANSPORT_TYPE:
+ case m_CHANGE_INTERACTION_ORDER_TYPE:
+ throw RTIinternalError("Read Message not implemented for T/O.");
+ break ;
+
+ // -- Join Variable Part(No Body) --
+
+ case m_JOIN_FEDERATION_EXECUTION:
+ numberOfRegulators = Header.VP.Join.NbReg ;
+ multicastAddress = Header.VP.Join.AdrMC ;
+ bestEffortAddress = Header.VP.Join.Addr ;
+ bestEffortPeer = Header.VP.Join.peer ;
+ break ;
+
+ // -- O_I Variable Part(No Body) --
+
+ case m_UNPUBLISH_OBJECT_CLASS:
+ case m_UNSUBSCRIBE_OBJECT_CLASS:
+ objectClass = Header.VP.O_I.handle ;
+ break ;
+
+ case m_PUBLISH_INTERACTION_CLASS:
+ case m_UNPUBLISH_INTERACTION_CLASS:
+ case m_SUBSCRIBE_INTERACTION_CLASS:
+ case m_UNSUBSCRIBE_INTERACTION_CLASS:
+ case m_TURN_INTERACTIONS_ON:
+ case m_TURN_INTERACTIONS_OFF:
+ interactionClass = Header.VP.O_I.handle ;
+ break ;
+
+ // -- O_I Variable Part(Body not empty) --
+
+ case m_PUBLISH_OBJECT_CLASS:
+ case m_SUBSCRIBE_OBJECT_CLASS:
+ objectClass = Header.VP.O_I.handle ;
+ handleArraySize = Header.VP.O_I.size ;
+ break ;
+
+ case m_REGISTER_OBJECT:
+ case m_DISCOVER_OBJECT:
+ objectClass = Header.VP.O_I.handle ;
+ break ;
+
+ // -- Default Handler --
+
+ default:
+ D.Out(pdExcept, "Unknown type %d in ReadHeader.", Header.type);
+ throw RTIinternalError("Received unknown Header type.");
+ }
+
+ // 4- If Header.bodySize is not 0, return RTI_TRUE, else RTI_FALSE
+
+ if (Header.bodySize == 0)
+ return RTI_FALSE ;
+ else
+ return RTI_TRUE ;
+}
+
+
+// ----------------------------
+// -- ReadBody Shared Memory --
+// ----------------------------
+
+void
+NetworkMessage::readBody(SharedMemory *shm)
+{
+ MessageBody Body ;
+ unsigned short i ;
+
+ Body.writeBlock(shm->Body.getBuffer(), shm->Body.getLength()) ;
+
+ if (shm->Header.bodySize == 0)
+ throw RTIinternalError("ReadBody should not have been called.");
+
+ // 3. Read informations from Message Body according to message type.
+
+ if ((shm->Header.type == m_UPDATE_ATTRIBUTE_VALUES)
+ || (shm->Header.type == m_REFLECT_ATTRIBUTE_VALUES)) {
+
+ object = Body.readLongInt();
+ readLabel(&Body);
+ Body.readBlock((char *) handleArray,
+ handleArraySize * sizeof(AttributeHandle));
+ for (i = 0 ; i < handleArraySize ; i ++) {
+ Body.readString(ValueArray[i], MAX_BYTES_PER_VALUE);
+ }
+ }
+
+ else
+
+ switch(shm->Header.type) {
+
+ // -- O_I Variable Part With Date(Body Not Empty) --
+ // Those types are put in front line because they are the most
used.
+ case m_SEND_INTERACTION:
+ case m_RECEIVE_INTERACTION:
+ readLabel(&Body);
+ Body.readBlock((char *) handleArray,
+ handleArraySize * sizeof(AttributeHandle));
+ for (i = 0 ; i < handleArraySize ; i ++) {
+ Body.readString(ValueArray[i], MAX_BYTES_PER_VALUE);
+ }
+ break ;
+
+ case m_CREATE_FEDERATION_EXECUTION:
+ case m_DESTROY_FEDERATION_EXECUTION:
+ readFederationName(&Body);
+ break ;
+
+ case m_REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
+ case m_ANNOUNCE_SYNCHRONIZATION_POINT:
+ readLabel(&Body);
+ readTag(&Body);
+ break ;
+
+ case m_SYNCHRONIZATION_POINT_ACHIEVED:
+ case m_SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED:
+ case m_FEDERATION_SYNCHRONIZED:
+ readLabel(&Body);
+ break ;
+
+ case m_DELETE_OBJECT:
+ case m_REMOVE_OBJECT:
+ object = Body.readLongInt();
+ readLabel(&Body);
+ break ;
+
+ // -- No Variable Part --
+
+ case m_IS_ATTRIBUTE_OWNED_BY_FEDERATE:
+ case m_INFORM_ATTRIBUTE_OWNERSHIP:
+ case m_ATTRIBUTE_IS_NOT_OWNED:
+ case m_QUERY_ATTRIBUTE_OWNERSHIP:
+ object = Body.readLongInt();
+ handleArray[0] = Body.readShortInt();
+ readLabel(&Body);
+ break ;
+
+
+ case m_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION:
+ case m_REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE:
+ object = Body.readLongInt();
+ handleArraySize = Body.readShortInt();
+ for (i = 0 ; i < handleArraySize ; i ++)
+ handleArray[i] = Body.readShortInt();
+ readLabel(&Body);
+ break ;
+
+
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION:
+ case m_ATTRIBUTE_OWNERSHIP_UNAVAILABLE:
+ case m_UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION:
+ case m_CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
+ case m_CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
+ case m_CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION:
+ object = Body.readLongInt();
+ handleArraySize = Body.readShortInt();
+ for (i = 0 ; i < handleArraySize ; i ++)
+ handleArray[i] = Body.readShortInt();
+ break ;
+
+
+
+ // -- Join Variable Part --
+
+ case m_JOIN_FEDERATION_EXECUTION:
+ readFederationName(&Body);
+ readFederateName(&Body);
+ break ;
+
+ // -- O_I Variable Part(Body not empty) --
+
+ case m_PUBLISH_OBJECT_CLASS:
+ case m_SUBSCRIBE_OBJECT_CLASS:
+ for (i = 0 ; i < handleArraySize ; i ++)
+ handleArray[i] = Body.readShortInt();
+ break ;
+
+ case m_REGISTER_OBJECT:
+ case m_DISCOVER_OBJECT:
+ object = Body.readLongInt();
+ readLabel(&Body);
+ break ;
+
+
+ // -- Default Handler --
+
+ default:
+ D.Out(pdExcept, "Unknown type %d in ReadBody.", shm->Header.type);
+ throw RTIinternalError("Unknown/Unimplemented type for Body.");
+ }
+
+}
+
+
+// -----------------------------
+// -- ReadHeader Shared Memory--
+// -----------------------------
+
+Boolean
+NetworkMessage::readHeader(SharedMemory *shm)
+{
+
+ // 2- Parse Header(Static Part)
+ type = shm->Header.type ;
+ exception = shm->Header.exception ;
+ federate = shm->Header.federate ;
+ federation = shm->Header.federation ;
+
+ // 2- Parse Header according to its type(Variable Part)
+ // NULL, UAV and SendInteraction are the most common ones.
+
+ if (type == m_MESSAGE_NULL)
+ date = shm->Header.VP.time.date ;
+
+ else if ((type == m_UPDATE_ATTRIBUTE_VALUES)
+ || (type == m_REFLECT_ATTRIBUTE_VALUES)) {
+ objectClass = shm->Header.VP.O_I.handle ;
+ handleArraySize = shm->Header.VP.O_I.size ;
+ date = shm->Header.VP.O_I.date ;
+ }
+
+ else
+ switch(shm->Header.type) {
+
+ case m_SEND_INTERACTION:
+ case m_RECEIVE_INTERACTION:
+ interactionClass = shm->Header.VP.O_I.handle ;
+ handleArraySize = shm->Header.VP.O_I.size ;
+ date = shm->Header.VP.O_I.date ;
+ break ;
+
+ // -- No Variable Part --
+
+ case m_CREATE_FEDERATION_EXECUTION:
+ case m_DESTROY_FEDERATION_EXECUTION:
+ case m_REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
+ case m_SYNCHRONIZATION_POINT_ACHIEVED:
+ case m_SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED:
+ case m_FEDERATION_SYNCHRONIZED:
+ case m_ANNOUNCE_SYNCHRONIZATION_POINT:
+ case m_DELETE_OBJECT:
+ case m_REMOVE_OBJECT:
+ case m_CLOSE_CONNEXION:
+ case m_RESIGN_FEDERATION_EXECUTION:
+ case m_IS_ATTRIBUTE_OWNED_BY_FEDERATE:
+ case m_INFORM_ATTRIBUTE_OWNERSHIP:
+ case m_ATTRIBUTE_IS_NOT_OWNED:
+ case m_QUERY_ATTRIBUTE_OWNERSHIP:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION:
+ case m_ATTRIBUTE_OWNERSHIP_UNAVAILABLE:
+ case m_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION:
+ case m_UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_ATTRIBUTE_OWNERSHIP_ACQUISITION:
+ case m_REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE:
+ case m_ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION:
+ case m_CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case m_ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
+ case m_CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
+ case m_CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION:
+ break ;
+
+ // -- time Variable Part(No Body)[Continued]--
+
+ case m_SET_TIME_REGULATING:
+ date = shm->Header.VP.time.date ;
+ regulator = shm->Header.VP.time.R_or_C ;
+ break ;
+
+ case m_SET_TIME_CONSTRAINED:
+ date = shm->Header.VP.time.date ;
+ constrained = shm->Header.VP.time.R_or_C ;
+ break ;
+
+ // -- ReqID Variable Part(No Body) --
+
+ case m_REQUEST_ID:
+ idCount = shm->Header.VP.ReqID.count ;
+ firstId = shm->Header.VP.ReqID.first ;
+ lastId = shm->Header.VP.ReqID.last ;
+ break ;
+ // -- T_O Variable Part --
+
+ case m_CHANGE_ATTRIBUTE_TRANSPORT_TYPE:
+ case m_CHANGE_ATTRIBUTE_ORDER_TYPE:
+ case m_CHANGE_INTERACTION_TRANSPORT_TYPE:
+ case m_CHANGE_INTERACTION_ORDER_TYPE:
+ throw RTIinternalError("Read Message not implemented for T/O.");
+ break ;
+
+ // -- Join Variable Part(No Body) --
+
+ case m_JOIN_FEDERATION_EXECUTION:
+ numberOfRegulators = shm->Header.VP.Join.NbReg ;
+ multicastAddress = shm->Header.VP.Join.AdrMC ;
+ bestEffortAddress = shm->Header.VP.Join.Addr ;
+ bestEffortPeer = shm->Header.VP.Join.peer ;
+ break ;
+
+ // -- O_I Variable Part(No Body) --
+
+ case m_UNPUBLISH_OBJECT_CLASS:
+ case m_UNSUBSCRIBE_OBJECT_CLASS:
+ objectClass = shm->Header.VP.O_I.handle ;
+ break ;
+
+ case m_PUBLISH_INTERACTION_CLASS:
+ case m_UNPUBLISH_INTERACTION_CLASS:
+ case m_SUBSCRIBE_INTERACTION_CLASS:
+ case m_UNSUBSCRIBE_INTERACTION_CLASS:
+ case m_TURN_INTERACTIONS_ON:
+ case m_TURN_INTERACTIONS_OFF:
+ interactionClass = shm->Header.VP.O_I.handle ;
+ break ;
+
+ // -- O_I Variable Part(Body not empty) --
+
+ case m_PUBLISH_OBJECT_CLASS:
+ case m_SUBSCRIBE_OBJECT_CLASS:
+ objectClass = shm->Header.VP.O_I.handle ;
+ handleArraySize = shm->Header.VP.O_I.size ;
+ break ;
+
+ case m_REGISTER_OBJECT:
+ case m_DISCOVER_OBJECT:
+ objectClass = shm->Header.VP.O_I.handle ;
+ break ;
+
+ // -- Default Handler --
+
+ default:
+ D.Out(pdExcept, "Unknown type %d in ReadHeader.",
shm->Header.type);
+ throw RTIinternalError("Received unknown Header type.");
+ }
+
+ // 4- If Header.bodySize is not 0, return RTI_TRUE, else RTI_FALSE
+
+ if (shm->Header.bodySize == 0)
+ return RTI_FALSE ;
+ else
+ return RTI_TRUE ;
+}
+
+
+// ---------------
+// -- ReadLabel --
+// ---------------
+
+void
+NetworkMessage::readLabel(MessageBody *Body)
+{
+ Body->readString(label, MAX_USER_TAG_LENGTH);
+}
+
+// ---------------------------------------------------------------------------
+//! Read the tag contained into the message.
+void NetworkMessage::readTag(MessageBody *Body)
+{
+ Body->readString(tag, MAX_USER_TAG_LENGTH);
+}
+
+// ---------------------------------------------------------------------------
+//! Read the federation name.
+void
+NetworkMessage::readFederationName(MessageBody *Body)
+{
+ Body->readString(federationName, MAX_FEDERATION_NAME_LENGTH);
+}
+
+
+// -------------------
+// -- ReadNomFedere --
+// -------------------
+
+void
+NetworkMessage::readFederateName(MessageBody *Body)
+{
+ Body->readString(federateName, MAX_FEDERATE_NAME_LENGTH);
+}
+
+
+// -----------------------
+// -- Write SharedMemory--
+// -----------------------
+
+int
+NetworkMessage::write(SharedMemory *shm, int wait)
+ throw (NetworkError,
+ NetworkSignal)
+{
+
+// ----------------------------------------------------
+// if (wait)
+// wait until the shm is empty
+// return 1 ;
+// else
+// if (the shm is empty)
+// write message ;
+// return 1 ;
+// else
+// return 0 ;
+// ----------------------------------------------------
+
+#ifdef USE_HEADER_AND_BODY
+ Boolean Result ;
+
+
+ // Synchronize
+
+ if ( shm->qui == FULL)
+ {
+ if(wait)
+ D.Out(pdProtocol, "WRITE_INIT : Bloqué en écriture avec mémoire
pleine. Attente...");
+ else
+ {
+ D.Out(pdProtocol, "WRITE_INIT : Segment mémoire plein.");
+ return 0 ;
+ }
+ }
+ else
+ D.Out(pdProtocol, "WRITE_INIT : Ecriture autorisée");
+
+ while ( shm->qui == FULL )
+ {
+ if (sched_yield ())
+ {
+ D.Out(pdError, "writeMessage : sched_yield problem");
+ exit (-1) ;
+ }
+ }
+
+ D.Out(pdProtocol, "WRITE_DEBLOQUE : J'écris le header");
+
+ // 1- Call WriteHeader
+
+ Result = writeHeader(shm);
+
+ // 2- If WriteHeader returned RTI_TRUE, call WriteBody.
+ if (Result == RTI_TRUE)
+ {
+ D.Out(pdDebug, "WRITE_DEBLOQUE : J'écris le body");
+ writeBody(shm);
+ }
+ D.Out(pdDebug, "WRITE_INIT : Body.length = %hd\n", shm->Body.getLength());
+ shm->qui= FULL ;
+
+ D.Out(pdDebug, "WRITE_FIN");
+
+ return 1 ;
+
+#else
+
+#endif
+
+}
+
+// -----------------
+// -- Write Socket--
+// -----------------
+
+void
+NetworkMessage::write(Socket *socket)
+ throw (NetworkError,
+ NetworkSignal)
+{
+Boolean Result ;
+#ifdef USE_SHM
+ SharedMemory shm;
+ D.Out(pdDebug, "Ecriture du Header");
+ Result = writeHeader(&shm);
+ // 2- If WriteHeader returned RTI_TRUE, call WriteBody.
+ if (Result == RTI_TRUE)
+ {
+ D.Out(pdDebug, "Ecriture du body");
+ writeBody(&shm);
+ }
+ D.Out(pdDebug, "Ecriture sur le socket shm");
+ socket->send(&shm,0);
+#else
+#ifdef USE_HEADER_AND_BODY
+
+ // 1- Call WriteHeader
+ Result = writeHeader(socket);
+
+ // 2- If WriteHeader returned RTI_TRUE, call WriteBody.
+ if (Result == RTI_TRUE)
+ writeBody(socket);
+
+#else
+ socket->send(this, sizeof(NetworkMessage));
+ //socket->send((NetworkMessage)this, sizeof(NetworkMessage));
+#endif
+#endif
+}
+
+
+// ----------------------------
+// -- WriteBody Shared Memory--
+// ----------------------------
+
+void
+NetworkMessage::writeBody(SharedMemory *shm)
+{
+ MessageBody Body ;
+ unsigned short i ;
+
+ // 1- Prepare Body Structure according to Message type
+ if ((shm->Header.type == m_UPDATE_ATTRIBUTE_VALUES)
+ || (shm->Header.type == m_REFLECT_ATTRIBUTE_VALUES)) {
+ Body.writeLongInt(object);
+ Body.writeString(label);
+ Body.writeBlock((char *) handleArray,
+ handleArraySize * sizeof(AttributeHandle));
+ for (i = 0 ; i < handleArraySize ; i ++) {
+ Body.writeString(ValueArray[i]);
+ }
+ }
+ else
+ switch(shm->Header.type) {
+
+ // -- O_I Variable Part With date(Body Not Empty) --
+
+ case m_SEND_INTERACTION:
+ case m_RECEIVE_INTERACTION:
+ Body.writeString(label);
+ Body.writeBlock((char *) handleArray,
+ handleArraySize * sizeof(AttributeHandle));
+ for (i = 0 ; i < handleArraySize ; i ++) {
+ Body.writeString(ValueArray[i]);
}
break ;
+ // -- No Variable Part --
+
case m_CREATE_FEDERATION_EXECUTION:
case m_DESTROY_FEDERATION_EXECUTION:
- readFederationName(&Body);
+ Body.writeString(federationName);
break ;
case m_REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
case m_ANNOUNCE_SYNCHRONIZATION_POINT:
- readLabel(&Body);
- readTag(&Body);
+ Body.writeString(label);
+ Body.writeString(tag);
break ;
case m_SYNCHRONIZATION_POINT_ACHIEVED:
case m_SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED:
case m_FEDERATION_SYNCHRONIZED:
- readLabel(&Body);
+ Body.writeString(label);
break ;
case m_DELETE_OBJECT:
case m_REMOVE_OBJECT:
- object = Body.readLongInt();
- readLabel(&Body);
+ Body.writeLongInt(object);
+ Body.writeString(label);
break ;
- // -- No Variable Part --
-
case m_IS_ATTRIBUTE_OWNED_BY_FEDERATE:
case m_INFORM_ATTRIBUTE_OWNERSHIP:
case m_ATTRIBUTE_IS_NOT_OWNED:
case m_QUERY_ATTRIBUTE_OWNERSHIP:
- object = Body.readLongInt();
- handleArray[0] = Body.readShortInt();
- readLabel(&Body);
+ Body.writeLongInt(object);
+ Body.writeShortInt(handleArray[0]);
+ Body.writeString(label);
break ;
-
case m_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
case m_REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION:
case m_ATTRIBUTE_OWNERSHIP_ACQUISITION:
case m_REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE:
- object = Body.readLongInt();
- handleArraySize = Body.readShortInt();
+ Body.writeLongInt(object);
+ Body.writeShortInt(handleArraySize);
for (i = 0 ; i < handleArraySize ; i ++)
- handleArray[i] = Body.readShortInt();
- readLabel(&Body);
+ Body.writeShortInt(handleArray[i]);
+ Body.writeString(label);
break ;
@@ -165,19 +985,17 @@
case m_ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
case m_CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
case m_CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION:
- object = Body.readLongInt();
- handleArraySize = Body.readShortInt();
+ Body.writeLongInt(object);
+ Body.writeShortInt(handleArraySize);
for (i = 0 ; i < handleArraySize ; i ++)
- handleArray[i] = Body.readShortInt();
+ Body.writeShortInt(handleArray[i]);
break ;
-
-
// -- Join Variable Part --
case m_JOIN_FEDERATION_EXECUTION:
- readFederationName(&Body);
- readFederateName(&Body);
+ Body.writeString(federationName);
+ Body.writeString(federateName);
break ;
// -- O_I Variable Part(Body not empty) --
@@ -185,85 +1003,98 @@
case m_PUBLISH_OBJECT_CLASS:
case m_SUBSCRIBE_OBJECT_CLASS:
for (i = 0 ; i < handleArraySize ; i ++)
- handleArray[i] = Body.readShortInt();
+ Body.writeShortInt(handleArray[i]);
break ;
case m_REGISTER_OBJECT:
case m_DISCOVER_OBJECT:
- object = Body.readLongInt();
- readLabel(&Body);
+ Body.writeLongInt(object);
+ Body.writeString(label);
break ;
-
// -- Default Handler --
default:
- D.Out(pdExcept, "Unknown type %d in ReadBody.", Header.type);
- throw RTIinternalError("Unknown/Unimplemented type for Body.");
+ D.Out(pdExcept, "Unknown type %d in WriteBody.", shm->Header.type);
+ throw RTIinternalError("Unknown/Unimplemented type for
shm->Header.");
+
}
+ // 2- Set Header.bodySize
+
+ // Body Size does not include the copy of the Header!
+ shm->Header.bodySize = Body.getLength() ;
+
+ std::memcpy(&(shm->Body), &Body, sizeof(Body)) ;
+
}
-// ----------------
-// -- ReadHeader --
-// ----------------
+// ------------------------------
+// -- WriteHeader Shared Memory--
+// ------------------------------
Boolean
-NetworkMessage::readHeader(Socket *socket)
+NetworkMessage::writeHeader(SharedMemory *shm)
{
- // 1- Read Header from Socket
- socket->receive((void *) &Header, sizeof(HeaderStruct));
- // 2- Parse Header(Static Part)
- type = Header.type ;
- exception = Header.exception ;
- federate = Header.federate ;
- federation = Header.federation ;
+ // 2- Fill Header(Static Part)
+ shm->Header.type = type ;
+ shm->Header.exception = exception ;
+ shm->Header.federate = federate ;
+ shm->Header.federation = federation ;
- // 2- Parse Header according to its type(Variable Part)
- // NULL, UAV and SendInteraction are the most common ones.
+ // 3- Fill Header(Variable Part)[Sorted by Variable part type]
- if (type == m_MESSAGE_NULL)
- date = Header.VP.time.date ;
+ // Note: Header.bodySize is not set to the actual Body size, but
+ // to zero to indicate there is no Body, or 1 if a Body is needed.
+ if (type == m_MESSAGE_NULL) {
+ shm->Header.bodySize = 0 ;
+ shm->Header.VP.time.date = date ;
+ }
else if ((type == m_UPDATE_ATTRIBUTE_VALUES)
|| (type == m_REFLECT_ATTRIBUTE_VALUES)) {
- objectClass = Header.VP.O_I.handle ;
- handleArraySize = Header.VP.O_I.size ;
- date = Header.VP.O_I.date ;
+ // Body contains ObjectHandle, handleArray, ValueArray, label
+ shm->Header.bodySize = 1 ;
+ shm->Header.VP.O_I.handle = objectClass ;
+ shm->Header.VP.O_I.size = handleArraySize ;
+ shm->Header.VP.O_I.date = date ;
}
-
else
- switch(Header.type) {
+ switch(type) {
+
case m_SEND_INTERACTION:
case m_RECEIVE_INTERACTION:
- interactionClass = Header.VP.O_I.handle ;
- handleArraySize = Header.VP.O_I.size ;
- date = Header.VP.O_I.date ;
+ // Body contains handleArray, ValueArray, label.
+ shm->Header.bodySize = 1 ;
+ shm->Header.VP.O_I.handle = interactionClass ;
+ shm->Header.VP.O_I.size = handleArraySize ;
+ shm->Header.VP.O_I.date = date ;
break ;
- // -- No Variable Part --
+ // -- No Variable Part, No Body --
- case m_CREATE_FEDERATION_EXECUTION:
- case m_DESTROY_FEDERATION_EXECUTION:
- case m_REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
- case m_SYNCHRONIZATION_POINT_ACHIEVED:
- case m_SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED:
- case m_FEDERATION_SYNCHRONIZED:
- case m_ANNOUNCE_SYNCHRONIZATION_POINT:
- case m_DELETE_OBJECT:
- case m_REMOVE_OBJECT:
case m_CLOSE_CONNEXION:
case m_RESIGN_FEDERATION_EXECUTION:
- case m_IS_ATTRIBUTE_OWNED_BY_FEDERATE:
+ shm->Header.bodySize = 0 ;
+ break ;
+
+ // -- No Variable Part, Body not empty --
+
+ case m_CREATE_FEDERATION_EXECUTION:
+ case m_DESTROY_FEDERATION_EXECUTION:
+ // Body Contains federationName.
case m_INFORM_ATTRIBUTE_OWNERSHIP:
case m_ATTRIBUTE_IS_NOT_OWNED:
+ case m_IS_ATTRIBUTE_OWNED_BY_FEDERATE:
case m_QUERY_ATTRIBUTE_OWNERSHIP:
+ // Body Contains ObjectHandle and label
case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE:
case m_ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION:
case m_ATTRIBUTE_OWNERSHIP_UNAVAILABLE:
+ // Body Contains ObjectHandle and handleArray
case m_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
case m_REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION:
case m_UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
@@ -274,50 +1105,74 @@
case m_ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
case m_CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
case m_CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION:
+ shm->Header.bodySize = 1 ;
break ;
- // -- time Variable Part(No Body)[Continued]--
+ case m_REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
+ case m_SYNCHRONIZATION_POINT_ACHIEVED:
+ case m_SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED:
+ case m_FEDERATION_SYNCHRONIZED:
+ case m_ANNOUNCE_SYNCHRONIZATION_POINT:
+ // Body Contains Label(should be non-empty)
+ // BUG: S'il fait moins de 16 octet, il passe dans le header.
+ shm->Header.bodySize = 1 ;
+ break ;
+
+ case m_DELETE_OBJECT:
+ case m_REMOVE_OBJECT:
+ // Body Contains ObjectHandle, and label
+ shm->Header.bodySize = 1 ;
+ break ;
+
+ // -- time Variable Part(No Body)[Continued] --
case m_SET_TIME_REGULATING:
- date = Header.VP.time.date ;
- regulator = Header.VP.time.R_or_C ;
+ shm->Header.bodySize = 0 ;
+ shm->Header.VP.time.date = date ;
+ shm->Header.VP.time.R_or_C = regulator ;
break ;
case m_SET_TIME_CONSTRAINED:
- date = Header.VP.time.date ;
- constrained = Header.VP.time.R_or_C ;
+ shm->Header.bodySize = 0 ;
+ shm->Header.VP.time.date = date ;
+ shm->Header.VP.time.R_or_C = constrained ;
break ;
// -- ReqID Variable Part(No Body) --
case m_REQUEST_ID:
- idCount = Header.VP.ReqID.count ;
- firstId = Header.VP.ReqID.first ;
- lastId = Header.VP.ReqID.last ;
+ shm->Header.bodySize = 0 ;
+ shm->Header.VP.ReqID.count = idCount ;
+ shm->Header.VP.ReqID.first = firstId ;
+ shm->Header.VP.ReqID.last = lastId ;
break ;
+
// -- T_O Variable Part --
case m_CHANGE_ATTRIBUTE_TRANSPORT_TYPE:
case m_CHANGE_ATTRIBUTE_ORDER_TYPE:
case m_CHANGE_INTERACTION_TRANSPORT_TYPE:
case m_CHANGE_INTERACTION_ORDER_TYPE:
- throw RTIinternalError("Read Message not implemented for T/O.");
+ throw RTIinternalError("Write Message not implemented for T/O.");
break ;
- // -- Join Variable Part(No Body) --
+ // -- Join Variable Part --
case m_JOIN_FEDERATION_EXECUTION:
- numberOfRegulators = Header.VP.Join.NbReg ;
- multicastAddress = Header.VP.Join.AdrMC ;
- bestEffortAddress = Header.VP.Join.Addr ;
- bestEffortPeer = Header.VP.Join.peer ;
+ // Body contains federationName and federateName
+ shm->Header.bodySize = 1 ;
+ shm->Header.VP.Join.NbReg = numberOfRegulators ;
+ shm->Header.VP.Join.AdrMC = multicastAddress ;
+ shm->Header.VP.Join.Addr = bestEffortAddress ;
+ shm->Header.VP.Join.peer = bestEffortPeer ;
break ;
// -- O_I Variable Part(No Body) --
case m_UNPUBLISH_OBJECT_CLASS:
case m_UNSUBSCRIBE_OBJECT_CLASS:
- objectClass = Header.VP.O_I.handle ;
+ shm->Header.bodySize = 0 ;
+ shm->Header.VP.O_I.handle = objectClass ;
break ;
case m_PUBLISH_INTERACTION_CLASS:
@@ -326,105 +1181,54 @@
case m_UNSUBSCRIBE_INTERACTION_CLASS:
case m_TURN_INTERACTIONS_ON:
case m_TURN_INTERACTIONS_OFF:
- interactionClass = Header.VP.O_I.handle ;
+ shm->Header.bodySize = 0 ;
+ shm->Header.VP.O_I.handle = interactionClass ;
break ;
// -- O_I Variable Part(Body not empty) --
case m_PUBLISH_OBJECT_CLASS:
case m_SUBSCRIBE_OBJECT_CLASS:
- objectClass = Header.VP.O_I.handle ;
- handleArraySize = Header.VP.O_I.size ;
+ // Body contains handleArray[handleArraySize](if not empty)
+
+ if (handleArraySize > 0)
+ shm->Header.bodySize = 1 ;
+ else
+ shm->Header.bodySize = 0 ;
+
+ shm->Header.VP.O_I.handle = objectClass ;
+ shm->Header.VP.O_I.size = handleArraySize ;
break ;
case m_REGISTER_OBJECT:
case m_DISCOVER_OBJECT:
- objectClass = Header.VP.O_I.handle ;
+ // Body Contains ObjectHandle and label
+ shm->Header.bodySize = 1 ;
+ shm->Header.VP.O_I.handle = objectClass ;
break ;
// -- Default Handler --
default:
- D.Out(pdExcept, "Unknown type %d in ReadHeader.", Header.type);
- throw RTIinternalError("Received unknown Header type.");
+ D.Out(pdExcept, "Unknown type %d in WriteHeader.",
shm->Header.type);
+ throw RTIinternalError("Unknown/Unimplemented type for
shm->Header.");
+
}
- // 4- If Header.bodySize is not 0, return RTI_TRUE, else RTI_FALSE
+ // 4- If Header.bodySize = 0, send message and return RTI_FALSE,
+ // Else send nothing(will be done by WriteBody), and return RTI_TRUE.
- if (Header.bodySize == 0)
+ if (shm->Header.bodySize == 0) {
return RTI_FALSE ;
+ }
else
return RTI_TRUE ;
-}
-
-
-// ---------------
-// -- ReadLabel --
-// ---------------
-
-void
-NetworkMessage::readLabel(MessageBody *Body)
-{
- Body->readString(label, MAX_USER_TAG_LENGTH);
-}
-
-// ---------------------------------------------------------------------------
-//! Read the tag contained into the message.
-void NetworkMessage::readTag(MessageBody *Body)
-{
- Body->readString(tag, MAX_USER_TAG_LENGTH);
-}
-
-// ---------------------------------------------------------------------------
-//! Read the federation name.
-void
-NetworkMessage::readFederationName(MessageBody *Body)
-{
- Body->readString(federationName, MAX_FEDERATION_NAME_LENGTH);
-}
-
-
-// -------------------
-// -- ReadNomFedere --
-// -------------------
-
-void
-NetworkMessage::readFederateName(MessageBody *Body)
-{
- Body->readString(federateName, MAX_FEDERATE_NAME_LENGTH);
-}
-
-
-// -----------
-// -- Write --
-// -----------
-
-void
-NetworkMessage::write(Socket *socket)
- throw (NetworkError,
- NetworkSignal)
-{
-
-#ifdef USE_HEADER_AND_BODY
- Boolean Result ;
- // 1- Call WriteHeader
- Result = writeHeader(socket);
-
- // 2- If WriteHeader returned RTI_TRUE, call WriteBody.
- if (Result == RTI_TRUE)
- writeBody(socket);
-
-#else
- socket->send(this, sizeof(NetworkMessage));
- //socket->send((NetworkMessage)this, sizeof(NetworkMessage));
-#endif
}
-
-// ---------------
-// -- WriteBody --
-// ---------------
+// ---------------------
+// -- WriteBody Socket--
+// ---------------------
void
NetworkMessage::writeBody(Socket *socket)
@@ -445,7 +1249,6 @@
Body.writeString(label);
Body.writeBlock((char *) handleArray,
handleArraySize * sizeof(AttributeHandle));
-
for (i = 0 ; i < handleArraySize ; i ++) {
Body.writeString(ValueArray[i]);
}
@@ -565,14 +1368,14 @@
((HeaderStruct *) Body.getBuffer())->bodySize = Header.bodySize ;
// 3- Write Header to socket, then write Body to socket.
- // socket->send((void *) &Header, sizeof(HeaderStruct));
+
socket->send((void *) Body.getBuffer(), Body.getLength());
}
-// -----------------
-// -- WriteHeader --
-// -----------------
+// -----------------------
+// -- WriteHeader Socket--
+// -----------------------
Boolean
NetworkMessage::writeHeader(Socket *socket)
@@ -769,6 +1572,88 @@
}
+// --------------------------------------------
+// -- select_SHM_C_S_full (ONLY for Server) --
+// --------------------------------------------
+
+int
+NetworkMessage::select_SHM_C_S_full(SHM *shm[], int *id_shm)
+
+{
+
+// --------------------------------------------------------------------
+// shm : array of pointer to shared memory for server
+// id_shm : array of shared memory id's currently attached
+//
+//
+// Selects and returns the first full C_S shared memory (index in shm):
+// Server is then allowed to read
+//
+// Returns -1 otherwise
+// --------------------------------------------------------------------
+
+ int i ;
+
+ for(i=0; i<MAX_CLIENTS; i++)
+ {
+ if(*(id_shm+i) > 0) // Attached shared memory
+ {
+ if((shm[i]->C_S).qui == FULL)
+ {
+ D.Out(pdTrace, "select_SHM_C_S_full : shared memory with id %d is
full", *(id_shm+i));
+ return i ;
+ }
+ }
+ else
+ if(*(id_shm+i) == 0) // No attached shared memory
+ {
+ D.Out(pdTrace, "select_SHM_C_S_full : no full shared memory") ;
+ return -1 ;
+ }
+ }
+}
+
+// --------------------------------------------
+// -- select_SHM_S_C_empty (ONLY for Server) --
+// --------------------------------------------
+
+int
+NetworkMessage::select_SHM_S_C_empty(SHM *shm[], int *id_shm)
+
+{
+
+// --------------------------------------------------------------------
+// shm : array of pointer to shared memory for server
+// id_shm : array of shared memory id's currently attached
+//
+//
+// Selects and returns the first empty S_C shared memory (index in shm):
+// Server is then allowed to write
+//
+// Returns -1 otherwise
+// --------------------------------------------------------------------
+
+ int i ;
+
+ for(i=0; i<MAX_CLIENTS; i++)
+ {
+ if(*(id_shm+i) > 0) // Attached shared memory
+ {
+ if((shm[i]->S_C).qui == EMPTY)
+ {
+ D.Out(pdTrace, "select_SHM_S_C_empty : shared memory with id %d
is empty", *(id_shm+i));
+ return i ;
+ }
+ }
+ else
+ if(*(id_shm+i) == 0) // No attached shared memory
+ {
+ D.Out(pdTrace, "select_SHM_S_C_empty : no empty shared memory") ;
+ return -1 ;
+ }
+ }
+}
+
} // namespace certi
-// $Id: NetworkMessage_RW.cc,v 3.4 2003/03/21 15:06:46 breholee Exp $
+// $Id: NetworkMessage_RW.cc,v 3.4.2.1 2009/05/28 20:58:22 erk Exp $
Index: libCERTI/FedParser_Build.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/FedParser_Build.cc,v
retrieving revision 3.6
retrieving revision 3.6.2.1
diff -u -b -r3.6 -r3.6.2.1
--- libCERTI/FedParser_Build.cc 4 Mar 2003 18:10:25 -0000 3.6
+++ libCERTI/FedParser_Build.cc 28 May 2009 20:58:22 -0000 3.6.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: FedParser_Build.cc,v 3.6 2003/03/04 18:10:25 breholee Exp $
+// $Id: FedParser_Build.cc,v 3.6.2.1 2009/05/28 20:58:22 erk Exp $
// ----------------------------------------------------------------------------
// FedParser Class handles .fed files.
@@ -54,9 +54,8 @@
return ;
}
- FEDFile->read(InBuffer, CREAD_MAX_BUF_LENGTH);
+ int LengthRead = fread(InBuffer, 1, CREAD_MAX_BUF_LENGTH, FEDFile);
- int LengthRead = FEDFile->gcount();
if (LengthRead == 0) {
CurrentChar = ZEOF ;
return ;
@@ -103,7 +102,7 @@
FedParser::~FedParser(void)
{
if (FEDFile != NULL)
- FEDFile->close();
+ fclose(FEDFile);
#ifdef CREAD_DISPLAYS_ROOTOBJ
if (ErrorWhileReading == RTI_FALSE)
@@ -207,9 +206,9 @@
FedParser::readFile(const char *FedFile)
throw (CouldNotOpenRID, ErrorReadingRID, SecurityError, RTIinternalError)
{
- FEDFile = new ifstream(FedFile, ios::in);
+ FEDFile = fopen(FedFile, "r");
- if (!FEDFile->is_open())
+ if(FEDFile == NULL)
{
D.Out(pdError, "Unable to open \"%s\".", FedFile);
throw CouldNotOpenRID(FedFile);
@@ -219,13 +218,13 @@
store(readListFirst());
}
catch (MemoryExhausted &e) {
- FEDFile->close();
+ fclose(FEDFile);
ErrorWhileReading = RTI_TRUE ;
D.Out(pdError, "FedParser throwing RTIinternalError.");
throw RTIinternalError(e._serial, e._reason);
}
catch (Exception &e) {
- FEDFile->close();
+ fclose(FEDFile);
ErrorWhileReading = RTI_TRUE ;
D.Out(pdError, "FedParser throwing exception %s.", e._name);
if (e._reason != NULL)
@@ -233,7 +232,7 @@
throw ErrorReadingRID(e._serial, e._reason);
}
- FEDFile->close();
+ fclose(FEDFile);
FEDFile = NULL ;
}
@@ -394,4 +393,4 @@
}}
-// $Id: FedParser_Build.cc,v 3.6 2003/03/04 18:10:25 breholee Exp $
+// $Id: FedParser_Build.cc,v 3.6.2.1 2009/05/28 20:58:22 erk Exp $
Index: libCERTI/XmlParser.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/XmlParser.hh,v
retrieving revision 3.6
retrieving revision 3.6.2.1
diff -u -b -r3.6 -r3.6.2.1
--- libCERTI/XmlParser.hh 21 Mar 2003 12:47:56 -0000 3.6
+++ libCERTI/XmlParser.hh 28 May 2009 20:58:22 -0000 3.6.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: XmlParser.hh,v 3.6 2003/03/21 12:47:56 breholee Exp $
+// $Id: XmlParser.hh,v 3.6.2.1 2009/05/28 20:58:22 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_XML_PARSER_HH
@@ -81,8 +81,10 @@
string filename ;
RootObject* root ;
+#ifdef HAVE_XML
xmlDocPtr doc ;
xmlNodePtr cur ;
+#endif
int freeObjectClassHandle ;
int freeInteractionClassHandle ;
@@ -99,4 +101,4 @@
#endif // _CERTI_XML_PARSER_HH
-// $Id: XmlParser.hh,v 3.6 2003/03/21 12:47:56 breholee Exp $
+// $Id: XmlParser.hh,v 3.6.2.1 2009/05/28 20:58:22 erk Exp $
Index: libCERTI/XmlParser.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/XmlParser.cc,v
retrieving revision 3.8
retrieving revision 3.8.2.1
diff -u -b -r3.8 -r3.8.2.1
--- libCERTI/XmlParser.cc 21 Mar 2003 14:03:36 -0000 3.8
+++ libCERTI/XmlParser.cc 28 May 2009 20:58:22 -0000 3.8.2.1
@@ -20,13 +20,13 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: XmlParser.cc,v 3.8 2003/03/21 14:03:36 breholee Exp $
+// $Id: XmlParser.cc,v 3.8.2.1 2009/05/28 20:58:22 erk Exp $
// ----------------------------------------------------------------------------
-#ifdef HAVE_XML
-
#include "XmlParser.hh"
+#ifdef HAVE_XML
+
namespace certi {
static pdCDebug D("XMLPARSER", "(XmlParser) ");
@@ -281,4 +281,4 @@
#endif // HAVE_XML
-// $Id: XmlParser.cc,v 3.8 2003/03/21 14:03:36 breholee Exp $
+// $Id: XmlParser.cc,v 3.8.2.1 2009/05/28 20:58:22 erk Exp $
Index: libCERTI/SocketServer.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketServer.hh,v
retrieving revision 3.4
retrieving revision 3.4.2.1
diff -u -b -r3.4 -r3.4.2.1
--- libCERTI/SocketServer.hh 19 Feb 2003 18:07:30 -0000 3.4
+++ libCERTI/SocketServer.hh 28 May 2009 20:58:22 -0000 3.4.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: SocketServer.hh,v 3.4 2003/02/19 18:07:30 breholee Exp $
+// $Id: SocketServer.hh,v 3.4.2.1 2009/05/28 20:58:22 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_SOCKET_SERVER_HH
@@ -33,11 +33,15 @@
#include "Socket.hh"
#include "SocketTCP.hh"
#include "SocketUDP.hh"
+#include "SocketSHM.hh"
#include "NetworkMessage.hh"
#include "SecurityLevel.hh"
#include "SecureTCPSocket.hh"
+#include <sys/ioctl.h>
+
+#include "PrettyDebug.hh"
namespace certi {
@@ -51,6 +55,7 @@
SocketTCP *ReliableLink ;
SocketUDP *BestEffortLink ;
+ SocketSHM *QuickLink;
SocketTuple(Socket *theTCPLink);
~SocketTuple();
@@ -115,10 +120,13 @@
FederateHandle the_federate) const
throw (FederateNotExecutionMember);
+ SocketTuple* SocketServer::select(fd_set * fd, bool *terminate);
+
private:
// The Server socket object(used for Accepts)
SocketTCP *ServerSocketTCP ;
SocketUDP *ServerSocketUDP ;
+ fd_set fd ;
// int port ;
// ---------------------
@@ -132,4 +140,4 @@
#endif // _CERTI_SOCKET_SERVER_HH
-// $Id: SocketServer.hh,v 3.4 2003/02/19 18:07:30 breholee Exp $
+// $Id: SocketServer.hh,v 3.4.2.1 2009/05/28 20:58:22 erk Exp $
Index: libCERTI/MessageBody.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/MessageBody.hh,v
retrieving revision 3.4
retrieving revision 3.4.2.1
diff -u -b -r3.4 -r3.4.2.1
--- libCERTI/MessageBody.hh 19 Feb 2003 18:07:30 -0000 3.4
+++ libCERTI/MessageBody.hh 28 May 2009 20:58:23 -0000 3.4.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: MessageBody.hh,v 3.4 2003/02/19 18:07:30 breholee Exp $
+// $Id: MessageBody.hh,v 3.4.2.1 2009/05/28 20:58:23 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_MESSAGE_BODY_HH
@@ -35,7 +35,7 @@
namespace certi {
//! There is no overflow checking, so this value would better be big enough.
-#define BODY_BUFFER_MAX_SIZE 200
+#define BODY_BUFFER_MAX_SIZE 4096
/*! La classe Body est en fait un buffer de caracteres, avec des methodes
permettant d'y ecrire et d'y lire des entiers(courts et longs) et des
@@ -166,4 +166,4 @@
#endif // _CERTI_MESSAGE_BODY_HH
-// $Id: MessageBody.hh,v 3.4 2003/02/19 18:07:30 breholee Exp $
+// $Id: MessageBody.hh,v 3.4.2.1 2009/05/28 20:58:23 erk Exp $
Index: libCERTI/MessageBody.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/MessageBody.cc,v
retrieving revision 3.3
retrieving revision 3.3.2.1
diff -u -b -r3.3 -r3.3.2.1
--- libCERTI/MessageBody.cc 19 Feb 2003 18:07:30 -0000 3.3
+++ libCERTI/MessageBody.cc 28 May 2009 20:58:23 -0000 3.3.2.1
@@ -20,10 +20,12 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: MessageBody.cc,v 3.3 2003/02/19 18:07:30 breholee Exp $
+// $Id: MessageBody.cc,v 3.3.2.1 2009/05/28 20:58:23 erk Exp $
// ----------------------------------------------------------------------------
#include "MessageBody.hh"
+#include <iostream.h>
+
// Comment this out if you don't want to use Integer encoding in stream.
// #define USE_INT_ENCODING
@@ -118,4 +120,4 @@
}
-// $Id: MessageBody.cc,v 3.3 2003/02/19 18:07:30 breholee Exp $
+// $Id: MessageBody.cc,v 3.3.2.1 2009/05/28 20:58:23 erk Exp $
Index: libCERTI/Socket.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Socket.hh,v
retrieving revision 3.3
retrieving revision 3.3.2.1
diff -u -b -r3.3 -r3.3.2.1
--- libCERTI/Socket.hh 19 Feb 2003 18:07:30 -0000 3.3
+++ libCERTI/Socket.hh 28 May 2009 20:58:23 -0000 3.3.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: Socket.hh,v 3.3 2003/02/19 18:07:30 breholee Exp $
+// $Id: Socket.hh,v 3.3.2.1 2009/05/28 20:58:23 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_SOCKET_HH
@@ -35,6 +35,7 @@
#define SOCKET_TYPE_MC 1 // Multicast Socket class ID
#define SOCKET_TYPE_UDP 2
#define SOCKET_TYPE_S_TCP 3 // Secure TCP Socket class ID
+#define SOCKET_TYPE_SHM 4
namespace certi {
// Those Exceptions will be used by all Socket classes.
@@ -77,4 +78,4 @@
#endif // _CERTI_SOCKET_HH
-// $Id: Socket.hh,v 3.3 2003/02/19 18:07:30 breholee Exp $
+// $Id: Socket.hh,v 3.3.2.1 2009/05/28 20:58:23 erk Exp $
Index: libCERTI/GAV.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/GAV.cc,v
retrieving revision 3.5
retrieving revision 3.5.2.1
diff -u -b -r3.5 -r3.5.2.1
--- libCERTI/GAV.cc 19 Feb 2003 18:07:29 -0000 3.5
+++ libCERTI/GAV.cc 28 May 2009 20:58:23 -0000 3.5.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: GAV.cc,v 3.5 2003/02/19 18:07:29 breholee Exp $
+// $Id: GAV.cc,v 3.5.2.1 2009/05/28 20:58:23 erk Exp $
// ----------------------------------------------------------------------------
#include "GAV.hh"
@@ -48,6 +48,7 @@
counter++ ;
i++ ;
}
+ i++ ;
if ((counter%2)==0) size += (counter/2);
else size += 1+((counter-1)/2);
counter = 0 ;
@@ -509,4 +510,4 @@
}
-// $Id: GAV.cc,v 3.5 2003/02/19 18:07:29 breholee Exp $
+// $Id: GAV.cc,v 3.5.2.1 2009/05/28 20:58:23 erk Exp $
Index: libCERTI/Message_RW.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/Message_RW.cc,v
retrieving revision 3.7
retrieving revision 3.7.2.1
diff -u -b -r3.7 -r3.7.2.1
--- libCERTI/Message_RW.cc 21 Mar 2003 15:06:46 -0000 3.7
+++ libCERTI/Message_RW.cc 28 May 2009 20:58:23 -0000 3.7.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: Message_RW.cc,v 3.7 2003/03/21 15:06:46 breholee Exp $
+// $Id: Message_RW.cc,v 3.7.2.1 2009/05/28 20:58:23 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
@@ -122,7 +122,6 @@
case REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION:
case ATTRIBUTE_OWNERSHIP_ACQUISITION:
case REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE:
- case ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION:
object = Body.readLongInt();
handleArraySize = Body.readShortInt();
readHandleArray(&Body);
@@ -133,6 +132,7 @@
case ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION:
case ATTRIBUTE_OWNERSHIP_UNAVAILABLE:
case UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
+ case ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION:
case CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
case ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
case CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
@@ -248,6 +248,7 @@
Boolean
Message::readHeader(SocketUN *socket)
{
+
// 1- Read Header from Socket
socket->receive((void *) &header, sizeof(MessageHeader));
@@ -420,7 +421,6 @@
}
// 4- If Header.bodySize is not 0, return RTI_TRUE, else RTI_FALSE
-
if (header.bodySize == 0)
return RTI_FALSE ;
else
@@ -982,4 +982,4 @@
} // namespace certi
-// $Id: Message_RW.cc,v 3.7 2003/03/21 15:06:46 breholee Exp $
+// $Id: Message_RW.cc,v 3.7.2.1 2009/05/28 20:58:23 erk Exp $
Index: libCERTI/FedParser.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/FedParser.hh,v
retrieving revision 3.7
retrieving revision 3.7.2.1
diff -u -b -r3.7 -r3.7.2.1
--- libCERTI/FedParser.hh 4 Mar 2003 18:10:25 -0000 3.7
+++ libCERTI/FedParser.hh 28 May 2009 20:58:23 -0000 3.7.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: FedParser.hh,v 3.7 2003/03/04 18:10:25 breholee Exp $
+// $Id: FedParser.hh,v 3.7.2.1 2009/05/28 20:58:23 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_FED_PARSER_HH
@@ -32,12 +32,10 @@
#include "PrettyDebug.hh"
// Standard libraries
-#include <fstream>
#include <iostream>
#include <vector>
+#include <stdio.h>
-using std::ifstream ;
-using std::ios ;
using std::cout ;
using std::endl ;
using std::vector ;
@@ -264,7 +262,7 @@
// -- FED File objects and buffer --(used in the read part)
// ---------------------------------
- ifstream *FEDFile ; //!< Pointer to file stream for reading data.
+ FILE *FEDFile ; //!< Pointer to file stream for reading data.
char InBuffer[CREAD_MAX_BUF_LENGTH] ; //!< Buffer used to store
//piece of file.
@@ -280,4 +278,4 @@
#endif // _CERTI_FED_PARSER_HH
-// $Id: FedParser.hh,v 3.7 2003/03/04 18:10:25 breholee Exp $
+// $Id: FedParser.hh,v 3.7.2.1 2009/05/28 20:58:23 erk Exp $
Index: libCERTI/SocketServer.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketServer.cc,v
retrieving revision 3.5
retrieving revision 3.5.2.1
diff -u -b -r3.5 -r3.5.2.1
--- libCERTI/SocketServer.cc 19 Feb 2003 18:07:30 -0000 3.5
+++ libCERTI/SocketServer.cc 28 May 2009 20:58:24 -0000 3.5.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: SocketServer.cc,v 3.5 2003/02/19 18:07:30 breholee Exp $
+// $Id: SocketServer.cc,v 3.5.2.1 2009/05/28 20:58:24 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
@@ -29,6 +29,8 @@
namespace certi {
+static pdCDebug D("RTIG", "(Socket Server)- ");
+
// ----------------------------------------------------------------------------
/*! This method is called when the RTIG wants to initialize its
FD_SET before doing a select. It will add all open socket to the set.
@@ -53,6 +55,7 @@
SocketServer::checkMessage(long socket_number, NetworkMessage *message) const
throw (SecurityError)
{
+D.Out(pdTrace,"CheckMessage : %ld", socket_number);
if ((message->federation == 0) && (message->federate == 0))
return ;
@@ -63,6 +66,7 @@
}
catch (Exception &e) {
// BUG: Should put a line in the Audit.
+ D.Out(pdTrace,"C'est bien ici.");
throw SecurityError("Message has a unknown origin.");
}
@@ -113,11 +117,15 @@
tuple->ReliableLink->close();
tuple->BestEffortLink->close();
+ //A FAIRE : Problablement necessaire de fermer d'abord l'autre cote
+
delete tuple->ReliableLink ;
delete tuple->BestEffortLink ;
+ delete tuple->QuickLink;
tuple->ReliableLink = NULL ;
tuple->BestEffortLink = NULL ;
+ tuple->QuickLink = NULL;
}
}
@@ -156,22 +164,29 @@
throw RTIinternalError("Null socket");
BestEffortLink = new SocketUDP();
+ QuickLink = new SocketSHM();
}
// ----------------------------------------------------------------------------
//! SocketTuple destructor.
SocketTuple::~SocketTuple(void)
{
- if (ReliableLink != NULL) {
- ReliableLink->close();
- delete ReliableLink ;
- ReliableLink = NULL ;
+ if (QuickLink != NULL) {
+ //QuickLink->close();
+ delete QuickLink ;
+ QuickLink = NULL ;
}
if (BestEffortLink != NULL) {
BestEffortLink->close();
delete BestEffortLink ;
BestEffortLink = NULL ;
}
+ if (BestEffortLink != NULL) {
+ BestEffortLink->close();
+ delete BestEffortLink ;
+ BestEffortLink = NULL ;
+ }
+
}
// ----------------------------------------------------------------------------
@@ -186,6 +201,8 @@
if (((*i)->ReliableLink != NULL) &&
(FD_ISSET((*i)->ReliableLink->returnSocket(), select_fdset)))
return (*i)->ReliableLink ;
+ /*if (((*i)->QuickLink != NULL) && ((*i)->QuickLink->isDataReady() ==
RTI_TRUE))
+ return (*i)->QuickLink;*/
}
return NULL ;
@@ -207,17 +224,31 @@
TransportType the_type) const
throw (FederateNotExecutionMember, RTIinternalError)
{
+
+ SocketTuple *tuple;
+ D.Out(pdTrace,"getSocketLink .. : % d, %d", the_federation,the_federate);
// It may throw FederateNotExecutionMember
- SocketTuple *tuple = getWithReferences(the_federation, the_federate);
+ try {
+ tuple = getWithReferences(the_federation, the_federate);
+ }
+ catch (FederateNotExecutionMember &e) {
+ D.Out(pdExcept, "Error while getSocketLink.");
+ throw FederateNotExecutionMember("Reference to a killed Federate.");
+ }
+
+ return tuple->QuickLink;
if (the_type == RELIABLE) {
if (tuple->ReliableLink == 0)
throw RTIinternalError("Reference to a killed Federate.");
+ D.Out(pdTrace,"getWithReference");
return tuple->ReliableLink ;
+
}
else {
if (tuple->BestEffortLink == 0)
throw RTIinternalError("Reference to a killed Federate.");
+ D.Out(pdTrace,"getWithReference");
return tuple->BestEffortLink ;
}
}
@@ -235,7 +266,7 @@
((*i)->Federate == the_federate))
return (*i);
}
-
+ D.Out(pdTrace,"getWithReferences : % d, %d", the_federation,the_federate);
throw FederateNotExecutionMember();
}
@@ -253,8 +284,11 @@
if (((*i)->BestEffortLink != NULL) &&
((*i)->BestEffortLink->returnSocket() == socket_descriptor))
return (*i);
+ if (((*i)->QuickLink != NULL) &&
+ ((*i)->QuickLink->returnSocket() == socket_descriptor))
+ return (*i);
}
-
+ D.Out(pdTrace,"getWithSocket : % ld", socket_descriptor);
throw RTIinternalError("Socket not found.");
}
@@ -272,16 +306,63 @@
if (newLink == NULL)
throw RTIinternalError("Could not allocate new socket.");
- newLink->accept(ServerSocketTCP);
+ //newLink->accept(ServerSocketTCP);
SocketTuple *newTuple = new SocketTuple(newLink);
+ newTuple->QuickLink->accept(ServerSocketTCP);
+
if (newTuple == NULL)
throw RTIinternalError("Could not allocate new tuple.");
push_front(newTuple);
}
+SocketTuple*
+SocketServer::select(fd_set * fd, bool *terminate)
+{
+ SocketTuple* tuple;
+ Socket * link;
+// Initialize fd_set structure with all opened sockets.
+ D.Out(pdTrace,"initialisation de fd_set avec le socket de communication");
+ FD_ZERO(fd);
+ FD_SET(ServerSocketTCP->returnSocket(), fd);
+
+
+ D.Out(pdTrace,"initialisation de fd_set avec les sockets ouverts");
+
+
+ struct timeval delai;
+ delai.tv_sec = 0;
+ delai.tv_usec = 0;
+
+ // Wait for an incoming message.
+
+ int result = 0 ;
+ D.Out(pdTrace,"debut de la scrutation");
+ while(result==0){
+ FD_ZERO(fd);
+ FD_SET(ServerSocketTCP->returnSocket(), fd);
+ result = ::select(ulimit(4, 0), fd, NULL, NULL,&delai);
+ // D.Out(pdTrace,"result = %d",result);
+
+ list<SocketTuple *>::const_iterator i ;
+
+ for (i = begin(); i != end(); i++) {
+ if ((*i)->QuickLink == NULL) continue ;
+ if ((*i)->QuickLink->isDataReady() == RTI_TRUE){
+ D.Out(pdTrace,"requete entrante sur le socket SHM
%d",(*i)->QuickLink->returnSocket());
+ return (*i);
+ }
+ }
+ if (*terminate)
+ return NULL;
+ }
+ D.Out(pdTrace,"requete entrante sur socket TCP");
+ return NULL;
+
+}
+
// ----------------------------------------------------------------------------
/*! Change the FederationHandle and the FederateHandle associated with
"socket". Once the references have been set for a Socket, they can't
@@ -312,4 +393,4 @@
}
-// $Id: SocketServer.cc,v 3.5 2003/02/19 18:07:30 breholee Exp $
+// $Id: SocketServer.cc,v 3.5.2.1 2009/05/28 20:58:24 erk Exp $
Index: libCERTI/Makefile.am
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/Makefile.am,v
retrieving revision 3.8
retrieving revision 3.8.2.1
diff -u -b -r3.8 -r3.8.2.1
--- libCERTI/Makefile.am 4 Mar 2003 17:35:22 -0000 3.8
+++ libCERTI/Makefile.am 28 May 2009 20:58:24 -0000 3.8.2.1
@@ -1,5 +1,5 @@
## CERTI libCERTI Makefile.am
-## $Id: Makefile.am,v 3.8 2003/03/04 17:35:22 breholee Exp $
+## $Id: Makefile.am,v 3.8.2.1 2009/05/28 20:58:24 erk Exp $
## ---------------------------------------------------------------------------
MAINTAINERCLEANFILES = Makefile.in
@@ -21,7 +21,7 @@
Parameter.hh Publisher.hh Range.hh RegionImp.hh RootObject.hh \
RoutingSpace.hh SecureTCPSocket.hh SecurityLevel.hh SecurityServer.hh \
SocketMC.hh SocketServer.hh SocketTCP.hh SocketUDP.hh Subscriber.hh \
-XmlParser.hh
+XmlParser.hh SocketSHM.hh
libCERTI_la_SOURCES = AuditFile.cc AuditLine.cc Exception.cc \
Dimension.cc Extent.cc FederateLevelList.cc FedParser_Build.cc \
@@ -33,7 +33,7 @@
ObjectClassSet.cc Parameter.cc Publisher.cc Range.cc RegionImp.cc \
RootObject.cc RoutingSpace.cc SecureTCPSocket.cc SecurityServer.cc \
SocketMC.cc SocketServer.cc SocketTCP.cc SocketUDP.cc SocketUN.cc \
-Subscriber.cc XmlParser.cc
+Subscriber.cc XmlParser.cc SocketSHM.cc
# libCERTI_la_LDFLAGS = -version-info 0:0:0
# Too unstable to use -version-info, so :
@@ -41,4 +41,4 @@
LDADD = @XML_LIBS@
-## EOF $Id: Makefile.am,v 3.8 2003/03/04 17:35:22 breholee Exp $
+## EOF $Id: Makefile.am,v 3.8.2.1 2009/05/28 20:58:24 erk Exp $
Index: RTIA/RTIA.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/RTIA.cc,v
retrieving revision 3.6
retrieving revision 3.6.2.1
diff -u -b -r3.6 -r3.6.2.1
--- RTIA/RTIA.cc 21 Mar 2003 15:06:46 -0000 3.6
+++ RTIA/RTIA.cc 28 May 2009 20:58:24 -0000 3.6.2.1
@@ -19,7 +19,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: RTIA.cc,v 3.6 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIA.cc,v 3.6.2.1 2009/05/28 20:58:24 erk Exp $
// ----------------------------------------------------------------------------
#include "RTIA.hh"
@@ -200,13 +200,14 @@
Message *msg_un ;
NetworkMessage *msg_tcp_udp ;
int n ;
-
+ D.Out(pdTrace, "RTIA up and Running");
while (!fm->_fin_execution) {
msg_tcp_udp = new NetworkMessage ;
msg_un = new Message ;
try {
+ D.Out(pdProtocol, "try to read a message");
comm->readMessage(n, msg_tcp_udp, msg_un);
}
catch (NetworkSignal) {
@@ -235,4 +236,4 @@
}} // namespace certi/rtia
-// $Id: RTIA.cc,v 3.6 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIA.cc,v 3.6.2.1 2009/05/28 20:58:24 erk Exp $
Index: RTIA/Communications.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/Communications.cc,v
retrieving revision 3.7
retrieving revision 3.7.2.1
diff -u -b -r3.7 -r3.7.2.1
--- RTIA/Communications.cc 19 Feb 2003 15:45:22 -0000 3.7
+++ RTIA/Communications.cc 28 May 2009 20:58:24 -0000 3.7.2.1
@@ -19,7 +19,7 @@
// 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,v 3.7 2003/02/19 15:45:22 breholee Exp $
+// $Id: Communications.cc,v 3.7.2.1 2009/05/28 20:58:24 erk Exp $
// ----------------------------------------------------------------------------
#include "Communications.hh"
@@ -52,7 +52,8 @@
// Otherwise, wait for a message with same type than expected and with
// same federate number.
tampon = new NetworkMessage ;
- tampon->read((SecureTCPSocket *)this);
+ //tampon->read((SecureTCPSocket *)this);
+ tampon->read((SocketSHM *)this);
D.Out(pdProtocol, "TCP Message of Type %d has arrived.", type_msg);
@@ -60,7 +61,8 @@
((numeroFedere != 0) && (tampon->federate != numeroFedere))) {
waitingList.push_back(tampon);
tampon = new NetworkMessage ;
- tampon->read((SecureTCPSocket *) this);
+ tampon->read((SocketSHM *)this);
+ //tampon->read((SecureTCPSocket *) this);
D.Out(pdProtocol, "Message of Type %d has arrived.", type_msg);
}
@@ -76,7 +78,7 @@
// ----------------------------------------------------------------------------
//! Communications.
Communications::Communications(void)
- : SocketUN(), SecureTCPSocket(), SocketUDP()
+ : SocketUN(), SecureTCPSocket(), SocketUDP(), SocketSHM()
{
char nom_serveur_RTIG[200] ;
@@ -106,7 +108,8 @@
if (tcp_port==NULL) tcp_port = PORT_TCP_RTIG ;
if (udp_port==NULL) udp_port = PORT_UDP_RTIG ;
- createTCPClient(atoi(tcp_port), certihost);
+ //createTCPClient(atoi(tcp_port), certihost);
+ createSHMClient(atoi(tcp_port), certihost);
createUDPClient(atoi(udp_port), certihost);
}
@@ -118,7 +121,7 @@
NetworkMessage msg ;
msg.type = m_CLOSE_CONNEXION ;
- msg.write((SecureTCPSocket *) this);
+ msg.write((SocketSHM *) this);
SecureTCPSocket::close();
}
@@ -159,6 +162,7 @@
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);
@@ -180,7 +184,7 @@
delete msg2 ;
n = 1 ;
}
- else if (SecureTCPSocket::isDataReady() == RTI_TRUE) {
+ /* else if (SecureTCPSocket::isDataReady() == RTI_TRUE) {
// Datas are in TCP waiting buffer.
// Read a message from RTIG TCP link.
msg_reseau->read((SecureTCPSocket *) this);
@@ -191,23 +195,52 @@
// 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).
- if (select(ulimit(4, 0), &fdset, NULL, NULL, NULL) < 0) {
+ 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
@@ -231,12 +264,15 @@
msg_reseau->read((SocketUDP *) this);
n = 1 ;
}
- else {
+ else if (FD_ISSET(_socket_un, &fdset)){
// Read a message coming from the federate.
- assert(FD_ISSET(_socket_un, &fdset));
receiveUN(msg);
n = 2 ;
}
+ else {
+ msg_reseau->read((SocketSHM *) this);
+ n = 1 ;
+ }
}
}
@@ -276,14 +312,16 @@
void
Communications::sendMessage(NetworkMessage *Msg)
{
- Msg->write((SecureTCPSocket *) this);
+ 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");
}
// ----------------------------------------------------------------------------
@@ -295,4 +333,4 @@
}} // namespace certi/rtia
-// $Id: Communications.cc,v 3.7 2003/02/19 15:45:22 breholee Exp $
+// $Id: Communications.cc,v 3.7.2.1 2009/05/28 20:58:24 erk Exp $
Index: RTIA/Communications.hh
===================================================================
RCS file: /sources/certi/certi/RTIA/Communications.hh,v
retrieving revision 3.5
retrieving revision 3.5.2.1
diff -u -b -r3.5 -r3.5.2.1
--- RTIA/Communications.hh 19 Feb 2003 15:45:22 -0000 3.5
+++ RTIA/Communications.hh 28 May 2009 20:58:24 -0000 3.5.2.1
@@ -19,7 +19,7 @@
// 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.hh,v 3.5 2003/02/19 15:45:22 breholee Exp $
+// $Id: Communications.hh,v 3.5.2.1 2009/05/28 20:58:24 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_COMMUNICATIONS_HH
@@ -33,6 +33,7 @@
#include "Message.hh"
#include "SocketUN.hh"
#include "SecureTCPSocket.hh"
+#include "SocketSHM.hh"
#include "SocketUDP.hh"
#include "PrettyDebug.hh"
@@ -58,7 +59,8 @@
public SocketMC,
#endif
public SecureTCPSocket,
- public SocketUDP
+ public SocketUDP,
+ public SocketSHM
{
public:
Communications(void);
@@ -88,4 +90,4 @@
#endif // _CERTI_COMMUNICATIONS_HH
-// $Id: Communications.hh,v 3.5 2003/02/19 15:45:22 breholee Exp $
+// $Id: Communications.hh,v 3.5.2.1 2009/05/28 20:58:24 erk Exp $
Index: test/Billard/billard.cc
===================================================================
RCS file: /sources/certi/certi/test/Billard/Attic/billard.cc,v
retrieving revision 3.13
retrieving revision 3.13.2.1
diff -u -b -r3.13 -r3.13.2.1
--- test/Billard/billard.cc 21 Mar 2003 15:06:46 -0000 3.13
+++ test/Billard/billard.cc 28 May 2009 20:58:25 -0000 3.13.2.1
@@ -19,7 +19,7 @@
// 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,v 3.13 2003/03/21 15:06:46 breholee Exp $
+// $Id: billard.cc,v 3.13.2.1 2009/05/28 20:58:25 erk Exp $
// ----------------------------------------------------------------------------
// Project
@@ -47,6 +47,7 @@
#include <iostream>
#include <signal.h>
#include <exception>
+#include <sched.h>
using namespace std ;
@@ -172,6 +173,7 @@
fedamb->enableLog(args_info.logfile_arg);
// Verifier que la federation existe
+ printf("avant createFederationExecution\n");
try {
rtiamb->createFederationExecution(FederationName,
DotFedFile);
@@ -181,6 +183,7 @@
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.",
@@ -308,6 +311,7 @@
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();
@@ -334,6 +338,7 @@
try {
rtiamb->tick();
nbtick++ ;
+ if (!fedamb->granted) sched_yield ( ) ;
}
catch (Exception& e) {
D.Out(pdExcept, "******** Exception ticking the RTI : %d.",
&e);
@@ -366,7 +371,7 @@
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);
+ //printf("\nCollision de %d et %d\n", Local->ID, Remote->ID);
#endif
time_aux = new RTIfedTime(localTime.getTime() +
TIME_STEP.getTime());
@@ -415,18 +420,20 @@
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) {
+ // if (strcmp(argv[2], "on") == 0) {
+ if (args_info.coordinated_flag) {
rtiamb->disableTimeConstrained();
D.Out(pdTerm, "Not constrained anymore.");
@@ -462,6 +469,8 @@
}
}
}
+ D.Out(pdTerm, "Sleeping a bit before ending .... ");
+ sleep ( 5 ) ;
D.Out(pdTerm, "Destroying RTIAmbassador and FedAmbassador.");
delete fedamb ;
delete rtiamb ;
@@ -675,4 +684,4 @@
}
}
-// EOF $Id: billard.cc,v 3.13 2003/03/21 15:06:46 breholee Exp $
+// EOF $Id: billard.cc,v 3.13.2.1 2009/05/28 20:58:25 erk Exp $
Index: libpdebug/DebugOStream.hh
===================================================================
RCS file: /sources/certi/certi/libpdebug/Attic/DebugOStream.hh,v
retrieving revision 3.0
retrieving revision 3.0.2.1
diff -u -b -r3.0 -r3.0.2.1
--- libpdebug/DebugOStream.hh 21 Mar 2003 18:18:26 -0000 3.0
+++ libpdebug/DebugOStream.hh 28 May 2009 20:58:25 -0000 3.0.2.1
@@ -20,14 +20,14 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: DebugOStream.hh,v 3.0 2003/03/21 18:18:26 breholee Exp $
+// $Id: DebugOStream.hh,v 3.0.2.1 2009/05/28 20:58:25 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_DEBUGOSTREAM_HH
#define _CERTI_DEBUGOSTREAM_HH
#include <config.h>
-#include <ostream>
+#include <iostream>
using namespace std;
@@ -262,4 +262,4 @@
#endif // _CERTI_DEBUGOSTREAM_HH
-// $Id: DebugOStream.hh,v 3.0 2003/03/21 18:18:26 breholee Exp $
+// $Id: DebugOStream.hh,v 3.0.2.1 2009/05/28 20:58:25 erk Exp $
Index: libpdebug/PrettyDebug.cc
===================================================================
RCS file: /sources/certi/certi/libpdebug/Attic/PrettyDebug.cc,v
retrieving revision 3.3
retrieving revision 3.3.2.1
diff -u -b -r3.3 -r3.3.2.1
--- libpdebug/PrettyDebug.cc 21 Mar 2003 18:22:12 -0000 3.3
+++ libpdebug/PrettyDebug.cc 28 May 2009 20:58:25 -0000 3.3.2.1
@@ -20,11 +20,13 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: PrettyDebug.cc,v 3.3 2003/03/21 18:22:12 breholee Exp $
+// $Id: PrettyDebug.cc,v 3.3.2.1 2009/05/28 20:58:25 erk Exp $
// ----------------------------------------------------------------------------
#include "PrettyDebug.hh"
+using namespace std;
+
DebugOStream DebugOStream::nullOutputStream(cout);
DebugOStream PrettyDebug::defaultOutputStream(cerr);
@@ -215,4 +217,4 @@
#endif // NO_PRETTYDEBUG
-// $Id: PrettyDebug.cc,v 3.3 2003/03/21 18:22:12 breholee Exp $
+// $Id: PrettyDebug.cc,v 3.3.2.1 2009/05/28 20:58:25 erk Exp $
Index: include/local_config.hh
===================================================================
RCS file: /sources/certi/certi/include/Attic/local_config.hh,v
retrieving revision 3.2
retrieving revision 3.2.6.1
diff -u -b -r3.2 -r3.2.6.1
--- include/local_config.hh 19 Feb 2003 17:20:28 -0000 3.2
+++ include/local_config.hh 28 May 2009 20:58:25 -0000 3.2.6.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: local_config.hh,v 3.2 2003/02/19 17:20:28 breholee Exp $
+// $Id: local_config.hh,v 3.2.6.1 2009/05/28 20:58:25 erk Exp $
// ----------------------------------------------------------------------------
// Types utilises par le RTI : Constantes, exceptions, handles...
@@ -126,7 +126,7 @@
#define MAX_INTERACTION_CLASSES 100
#define MAX_ATTRIBUTES_PER_CLASS 20
#define MAX_PARAMETERS_PER_CLASS 20 // Must be the same as Attributes
-#define MAX_BYTES_PER_VALUE 80
+#define MAX_BYTES_PER_VALUE 4096
#define MAX_BYTES_PER_VALUETYPE 20
#define PRIVILEGE_TO_DELETE_HANDLE 0
#define ROOT_OBJECT_CLASS_HANDLE 0
@@ -146,4 +146,4 @@
#endif // _CERTI_RTI_CONFIG_HH
-// $Id: local_config.hh,v 3.2 2003/02/19 17:20:28 breholee Exp $
+// $Id: local_config.hh,v 3.2.6.1 2009/05/28 20:58:25 erk Exp $
Index: libRTI/RTIambassador.cc
===================================================================
RCS file: /sources/certi/certi/libRTI/RTIambassador.cc,v
retrieving revision 3.18
retrieving revision 3.18.2.1
diff -u -b -r3.18 -r3.18.2.1
--- libRTI/RTIambassador.cc 21 Mar 2003 15:06:46 -0000 3.18
+++ libRTI/RTIambassador.cc 28 May 2009 20:58:25 -0000 3.18.2.1
@@ -20,7 +20,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: RTIambassador.cc,v 3.18 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIambassador.cc,v 3.18.2.1 2009/05/28 20:58:25 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
@@ -198,6 +198,7 @@
i++ ;
}
}
+ end_string[j++] = '\0' ;
}
// ----------------------------------------------------------------------------
@@ -234,6 +235,7 @@
i++ ;
}
}
+ size ++ ;
}
// ===========================================================================
@@ -3627,4 +3629,4 @@
} // namespace certi
-// $Id: RTIambassador.cc,v 3.18 2003/03/21 15:06:46 breholee Exp $
+// $Id: RTIambassador.cc,v 3.18.2.1 2009/05/28 20:58:25 erk Exp $
Index: libCERTI/CCom.hh
===================================================================
RCS file: libCERTI/CCom.hh
diff -N libCERTI/CCom.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/CCom.hh 28 May 2009 20:58:21 -0000 1.1.2.1
@@ -0,0 +1,89 @@
+// **** DEBUT ENTETE *********************************************************
+//
+// Copyright 1997 ONERA
+//
+//
+//_NOM : hla/test/test_msg/CSockServer.hh
+//
+//_VERSION : 1.1
+//
+//_HISTORIQUE :
+// 1.1 Creation par Thomas Hautesserres (address@hidden).
+//
+//_DESCRIPTION : Classe CSockServer, qui simule un serveur recevant des
+// CMessageReseau d'une autre classe CSockClient, a travers une connexion
+// TCP encapsulee dans la classe CSocketTCP (fichier ../util/sockTCP.hh).
+//
+//_CONTEXTE : Test de performance des differentes implementations des
+// CMessageReseau et des CSocket*.
+//
+//_CATEGORIE : Composant de l'implementation de HLA dans le cadre de SAIDA
+//
+//_SYNOPSIS :
+//
+//_ENTREE :
+//
+//_SORTIE :
+//
+//_MODIFIEE :
+//
+//_LOCALE :
+//
+//_DIAGNOSTIC :
+//
+//_BUGS CONNUS : ?
+//
+//_VOIR AUSSI : le fichier README.
+//
+// **** FIN ENTETE ***********************************************************
+
+#ifndef CCOM_HH
+#define CCOM_HH
+
+#include "setup.hh"
+#include "SocketTCP.hh"
+#include "NetworkMessage.hh"
+#include "SocketServer.hh"
+
+using namespace certi ;
+
+class CCom {
+
+public:
+
+ // --------------------------------
+ // -- Constructor and Destructor --
+ // --------------------------------
+
+ // The first parameter is the function called when NULL messages are
+ // received, and the second is called when UAV messages are received.
+ CCom (ProcessFunction *NullProcess = NULL,
+ ProcessFunction *UAVProcess = NULL) ;
+
+ virtual ~CCom () ;
+
+
+ // ------------------
+ // -- Main Methods --
+ // ------------------
+
+ // Return the number Messages received (of all types)
+ virtual long Main (unsigned int Time=0)=0;
+
+ // Should be called whenever a signal is caught (stop the main loop)
+ virtual void SignalHandler (int Sig)=0;
+
+private:
+
+ // ------------------------
+ // -- Private Attributes --
+ // ------------------------
+
+ char EndLoop;
+
+};
+
+ // } // end namespace
+
+#endif // CCOM_HH
+
Index: libCERTI/SocketSHM.hh
===================================================================
RCS file: libCERTI/SocketSHM.hh
diff -N libCERTI/SocketSHM.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHM.hh 28 May 2009 20:58:21 -0000 1.1.2.1
@@ -0,0 +1,197 @@
+// -*- 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-libCERTI
+//
+// CERTI-libCERTI is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// CERTI-libCERTI 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser 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: SocketSHM.hh,v 1.1.2.1 2009/05/28 20:58:21 erk Exp $
+// ----------------------------------------------------------------------------
+
+#ifndef _CERTI_SOCKET_SHM_HH
+#define _CERTI_SOCKET_SHM_HH
+
+#include <config.h>
+
+#include <iostream>
+using std::cout ;
+using std::endl ;
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/time.h>
+#include <signal.h>
+#include <errno.h>
+#include <cstring>
+#include <ulimit.h>
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <netinet/tcp.h>
+
+#include "Socket.hh"
+#include "SocketTCP.hh"
+#include "RTItypes.hh"
+#include "PrettyDebug.hh"
+
+#include "MessageBody.hh"
+#include "NetworkMessage.hh"
+
+// This is the read buffer of TCP sockets. It must be at least as long
+// as the longest data ever received by a socket.
+// If the next line is commented out, no buffer will be used at all.
+#define SOCKSHM_BUFFER_LENGTH 4096
+
+// Taille de la chaine de caractères du message
+#define TAILLE_MESSAGE 256
+
+// Constantes full and empty
+
+#define FULL '1'
+#define EMPTY '0'
+
+// Nombre max de clients
+#define MAX_CLIENTS 100
+
+#define MAX_EXCEPTION_REASON_LENGTH 100
+
+#define SOCKET_TYPE_SHM 4
+
+namespace certi {
+/*
+// Shared Memory de communication entre client et serveur
+
+typedef struct {
+ char qui ; // char de synchronisation
+ HeaderStruct Header ;
+ MessageBody Body ;
+} SharedMemory ;
+
+typedef struct {
+ SharedMemory S_C ; // Zone serveur vers client
+ SharedMemory C_S ; // Zone client vers serveur
+} SHM ;
+*/
+
+/*! IMPORTANT NOTE: This TCP socket implementation uses a Read Buffer to
+ improve global read performances(by reducing Recv system calls). An
+ important drawback of this improvement is that a socket can be marked as
+ empty for the system, but in fact there is data waiting in the read
+ buffer. This is especially a problem for processes using the 'select'
+ system call: the socket won't be marked as ready for reading, because all
+ data has already been read, and is waiting in the internal buffer.
+ Therefore, before returning to a select loop, be sure to call the
+ IsDataReady method to check whether any data is waiting for processing.
+*/
+class SocketSHM : public Socket
+{
+public :
+ // ---------------------------------------------
+ // -- Fonctions heritee de la classe Socket --
+ // ---------------------------------------------
+
+ void send(void *Buffer, unsigned long Size);
+
+ void receive(void *Buffer, unsigned long Size);
+
+ Boolean isDataReady(void) const ;
+
+ int getClass(void) const { return SOCKET_TYPE_SHM ; };
+ int returnSocket(void) const ;
+
+ unsigned long returnAdress(void) const ;
+
+ void close(void);
+
+ // --------------------------
+ // -- SHM Specific Methods --
+ // --------------------------
+
+ SocketSHM(void);
+ ~SocketSHM(void);
+
+ int accept(SocketTCP *serveur);
+
+ void createSHMClient(unsigned int port, char *nom_serveur);
+ /*
+ int accept(SocketTCP *serveur);
+
+ void createTCPClient(unsigned int port, char *nom_serveur);
+ void createTCPClient(unsigned int port, unsigned long addr);
+ void createTCPServer(unsigned int port = 0, unsigned long addr =
INADDR_ANY);
+
+ SocketTCP & operator= (SocketTCP &theSocket);
+ */
+
+private:
+
+ // ------------------------
+ // -- Private Attributes --
+ // ------------------------
+
+ SHM * shm;
+ int shmId; //identifiant du segment
+
+ bool isServer;
+
+
+ /*
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+ Boolean _est_init_tcp ;
+
+ unsigned long long SentBytesCount ;
+ unsigned long long RcvdBytesCount ;
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ // This class can use a buffer to reduce the number of systems calls
+ // when reading a lot of small amouts of data. Each time a Receive
+ // is made, it will try to read SOCKTCP_BUFFER_LENGTH
+
+ char ReadBuffer[SOCKTCP_BUFFER_LENGTH] ;
+ unsigned long RBLength ;
+#endif
+
+ // ---------------------
+ // -- Private Methods --
+ // ---------------------
+
+ unsigned int getPort(void) const ;
+ unsigned long getAddr(void) const ;
+ void setPort(unsigned int port);
+
+ int bind(unsigned int port=0, unsigned long addr=INADDR_ANY);
+ void changeReuseOption();
+ int connect(unsigned int port, unsigned long addr);
+ int listen(unsigned long howMuch=5);
+ int open(void);
+ int timeoutTCP(int, int);
+*/
+};
+}
+
+#endif // _CERTI_SOCKET_SHM_HH
+
+// $Id: SocketSHM.hh,v 1.1.2.1 2009/05/28 20:58:21 erk Exp $
Index: libCERTI/SocketSHM.cc_v1
===================================================================
RCS file: libCERTI/SocketSHM.cc_v1
diff -N libCERTI/SocketSHM.cc_v1
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHM.cc_v1 28 May 2009 20:58:22 -0000 1.1.2.1
@@ -0,0 +1,403 @@
+// -*- 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-libCERTI
+//
+// CERTI-libCERTI is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// CERTI-libCERTI 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser 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: SocketSHM.cc_v1,v 1.1.2.1 2009/05/28 20:58:22 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include "SocketSHM.hh"
+
+namespace certi {
+
+static pdCDebug D("SOCKSHM", "(SocketSHM) - ");
+
+
+// ----------------------------------------------------------------------------
+//! accept.
+int SocketSHM::accept(SocketTCP *serveur)
+{
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+ struct protoent *TCPent ;
+ int optval = 1 ;
+ socklen_t l ;
+
+ assert(serveur != NULL);
+
+ l = sizeof(_sockIn);
+
+ _socket_tcp = ::accept(serveur->returnSocket(), (sockaddr*)&_sockIn, &l);
+ //HPUX: _socket_tcp = accept(serveur->_socket_tcp, (sockaddr*)&_sockIn,
+ //(int*) &l);
+ if (_socket_tcp < 0) {
+ perror("SocketTCP: Accept");
+ exit(-1);
+ }
+
+ // Set the TCP_NODELAY option(Server Side)
+ TCPent = getprotobyname("tcp");
+ if (TCPent == NULL) {
+ cout << "Unable to retrieve TCP protocol number." << endl ;
+ return 0 ;
+ }
+
+ if (setsockopt(_socket_tcp,
+ TCPent->p_proto,
+ TCP_NODELAY,
+ (char *) &optval,
+ sizeof(optval))) {
+ cout << "Error while calling setsockopt." << endl ;
+ return 0 ;
+ }
+ D.Out(pdTrace, "Acceptation d'une connexion cote serveur") ;
+ isServer = true;
+ if ((shmId = shmget (IPC_PRIVATE, sizeof(SHM),IPC_CREAT|0666)) == -1)
+ { perror ("shmget"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Creating shared memory with id = %d", shmId) ;
+
+ /* attachement a une adresse non fixee */
+
+ if ((shm = (SHM *) shmat(shmId, 0 ,0)) == (SHM *) -1)
+ { perror ("shmat"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Shared memory attached") ;
+
+
+ shm -> S_C.qui = EMPTY ; // le segment est libre en écriture
+ shm -> C_S.qui = EMPTY ;
+
+ int ctrl;
+ write(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ read(_socket_tcp,&ctrl,(unsigned) sizeof(int));
+ if(ctrl != shmId) cout<< "erreur de transmission de l'identifiant shm";
+ ::close(_socket_tcp);
+
+ return shmId;
+}
+
+// ----------------------------------------------------------------------------
+//! createSHMClient
+void
+SocketSHM::createSHMClient(unsigned int port, char *nom_serveur){
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+
+
+ D.Out(pdTrace, "Creation socket cote client") ;
+
+ _socket_tcp=socket(AF_INET, SOCK_STREAM, 0);
+
+ D.Out(pdTrace, "Recuperation des infos sur le serveur") ;
+ // recuperer les infos sur le serveur a partir du nom
+ struct hostent *hptr = gethostbyname(nom_serveur);
+ if (hptr == 0) {
+ perror("SocketTCP: gethostbyname");
+ exit(-1);
+ }
+
+ unsigned long addr = 0 ;
+ memcpy((void *) &addr, (void *) hptr->h_addr, hptr->h_length);
+
+
+ int Result ;
+ struct protoent *TCPent ;
+ int optval = 1 ;
+
+ _sockIn.sin_family=AF_INET ;
+ _sockIn.sin_port=htons(port);
+ _sockIn.sin_addr.s_addr=addr ;
+
+ D.Out(pdTrace, "Tentative de connexion") ;
+ Result = ::connect(_socket_tcp, (sockaddr*)&_sockIn, sizeof(_sockIn));
+
+ if (Result < 0)
+ return ;
+
+ // Set the TCP_NODELAY option(Client Side)
+
+ TCPent = getprotobyname("tcp");
+ if (TCPent == NULL) {
+ cout << "Unable to retrieve TCP protocol number." << endl ;
+ return ;
+ }
+
+ if (setsockopt(_socket_tcp,
+ TCPent->p_proto,
+ TCP_NODELAY,
+ (char *) &optval,
+ sizeof(optval))) {
+ cout << "Error while calling setsockopt." << endl ;
+ return ;
+ }
+ D.Out(pdTrace, "Lecture des informations de connexion") ;
+ read(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ write(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ ::close(_socket_tcp);
+
+ D.Out(pdTrace, "Attachement de la memoire") ;
+ isServer = false;
+ //shmId = id_shm;
+ if ((shm = (SHM *) shmat(shmId, 0 ,0)) == (SHM *) -1)
+ { perror ("shmat"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Shared memory attached with id = %d", shmId) ;
+}
+
+
+// ----------------------------------------------------------------------------
+//! Constructor.
+SocketSHM::SocketSHM(void)
+{
+}
+// ----------------------------------------------------------------------------
+//! Destructor.
+SocketSHM::~SocketSHM(void)
+{
+ // Fermeture
+ //if (_est_init_tcp)
+ close();
+/*
+#ifdef RTI_PRINTS_STATISTICS
+ cout << endl ;
+ cout << "TCP Socket(" << _socket_tcp << "): Total Sent Bytes : "
+ << SentBytesCount << '.' << endl ;
+ cout << "TCP Socket(" << _socket_tcp << "): Total Received Bytes : "
+ << RcvdBytesCount << '.' << endl ;
+ cout << endl ;
+#endif
+*/
+}
+
+// ----------------------------------------------------------------------------
+//! send.
+void SocketSHM::send(void *Buffer, unsigned long Size)
+{
+ if(isServer){
+ D.Out(pdTrace, "Ecriture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en ecriture cote serveur") ;
+ while(shm->S_C.qui==FULL)D.Out(pdTrace, "S_C.qui : %c",shm->S_C.qui);
+ D.Out(pdTrace, "Ecriture debloque cote serveur : writing Header") ;
+ shm->S_C.Header = ((SharedMemory *)Buffer)->Header;
+ D.Out(pdTrace, "writing body") ;
+ shm->S_C.Body = ((SharedMemory *)Buffer)->Body;
+ shm->S_C.qui=FULL;
+ D.Out(pdTrace, "S_C.qui positionne a : %c",shm->S_C.qui) ;
+ }
+ else{
+ D.Out(pdTrace, "Ecriture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en Ecriture cote client") ;
+ int result=shm->C_S.qui;
+ while(result==FULL)result=shm->C_S.qui;
+ D.Out(pdTrace, "Ecriture debloque cote client : writing Header") ;
+ shm->C_S.Header = ((SharedMemory *)Buffer)->Header;
+ D.Out(pdTrace, "writing body") ;
+ shm->C_S.Body = ((SharedMemory *)Buffer)->Body;
+ shm->C_S.qui=FULL;
+ D.Out(pdTrace, "C_S.qui positionne a : %c",shm->C_S.qui) ;
+ }
+ /*long nSent = 0 ;
+ long total_sent = 0 ;
+ long expected_size = Size ;
+
+ assert(_est_init_tcp);
+
+ D.Out(pdDebug, "Beginning to send SHM message...");
+
+ while (total_sent < expected_size) {
+ nSent = ::send(_socket_tcp,
+ (char *) Buffer + total_sent,
+ expected_size - total_sent,
+ 0);
+
+ if (nSent < 0) {
+ D.Out(pdExcept, "Error while sending on TCP socket.");
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else {
+ perror("TCP Socket(EmettreTCP) ");
+ throw NetworkError("Error while sending TCP message.");
+ }
+ }
+
+ if (nSent == 0) {
+ D.Out(pdExcept, "No data could be sent, connection closed?.");
+ throw NetworkError("Could not send any data on TCP socket.");
+ }
+
+ total_sent += nSent ;
+ D.Out(pdTrace, "Sent %ld bytes out of %ld.", total_sent,
expected_size);
+ }
+
+ SentBytesCount += total_sent ;*/
+}
+
+// ----------------------------------------------------------------------------
+//! close.
+void SocketSHM::close(void)
+{
+ if(isServer){
+ /* detachement des segments memoire*/
+ if(shmdt(shm)){
+ perror("Echec du shmdt car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detachee cotee serveur") ;
+
+
+ /*Destruction des segments memoire */
+ if(shmctl(shmId, IPC_RMID,0)){
+ perror("Echec de shmctl(IPC_RMID) car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detruite") ;
+ }
+ else{
+ /* detachement des segments memoire*/
+ if(shmdt(shm)){
+ perror("Echec du shmdt car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detachee cotee client") ;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+/*! Return RTI_TRUE if any data as already been read from the system socket
+ and is waiting in the internal buffer, else RTI_FALSE.
+*/
+Boolean
+SocketSHM::isDataReady(void) const
+{
+ if(isServer){
+ if (shm->C_S.qui == FULL) return RTI_TRUE;
+ else return RTI_FALSE;
+ }
+ else{
+ if (shm->S_C.qui == FULL) return RTI_TRUE;
+ else return RTI_FALSE;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+//! receive.
+void SocketSHM::receive(void *Buffer, unsigned long Size)
+{
+ if(isServer){
+ D.Out(pdTrace, "Lecture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en lecture cote serveur") ;
+ while(shm->C_S.qui==EMPTY)D.Out(pdTrace, "C_S.qui : %c",shm->C_S.qui);
+ D.Out(pdTrace, "Lecture debloque cote serveur : reading Header") ;
+ ((SharedMemory *)Buffer)->Header = shm->C_S.Header;
+ D.Out(pdTrace, "reading body") ;
+ ((SharedMemory *)Buffer)->Body = shm->C_S.Body;
+ shm->C_S.qui=EMPTY;
+ D.Out(pdTrace, "C_S.qui positionne a : %c",shm->C_S.qui) ;
+ }
+ else{
+ D.Out(pdTrace, "Lecture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en lecture cote client") ;
+ int result=shm->S_C.qui;
+ while(result==EMPTY)result=shm->S_C.qui;
+ D.Out(pdTrace, "Lecture debloque cote client : reading Header") ;
+ ((SharedMemory *)Buffer)->Header = shm->S_C.Header;
+ D.Out(pdTrace, "reading body") ;
+ ((SharedMemory *)Buffer)->Body = shm->S_C.Body;
+ shm->S_C.qui=EMPTY;
+ D.Out(pdTrace, "S_C.qui positionne a : %c",shm->S_C.qui) ;
+ }
+
+ /*
+ assert(_est_init_tcp);
+
+ long nReceived = 0 ;
+#ifndef SOCKTCP_BUFFER_LENGTH
+ long RBLength = 0 ;
+#endif
+
+ D.Out(pdDebug, "Beginning to receive TCP message...");
+
+ while (RBLength < Size)
+ {
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ nReceived = recv(_socket_tcp,
+ ReadBuffer + RBLength,
+ SOCKTCP_BUFFER_LENGTH - RBLength,
+ 0);
+#else
+ nReceived = recv(_socket_tcp,
+ (char *) Buffer + RBLength,
+ Size - RBLength,
+ 0);
+#endif
+
+ if (nReceived < 0) {
+ D.Out(pdExcept, "Error while receiving on TCP socket.");
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else {
+ perror("TCP Socket(RecevoirTCP) ");
+ throw NetworkError("Error while receiving TCP message.");
+ }
+ }
+
+ if (nReceived == 0) {
+ D.Out(pdExcept, "TCP connection has been closed by peer.");
+ throw NetworkError("Connection closed by client.");
+ }
+
+ RBLength += nReceived ;
+ RcvdBytesCount += nReceived ;
+
+ D.Out(pdTrace, "Received %ld bytes out of %ld.", RBLength, Size);
+ }
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ memcpy(Buffer, (void *) ReadBuffer, Size);
+ memmove((void *) ReadBuffer,
+ (void *)(ReadBuffer + Size),
+ RBLength - Size);
+ RBLength -= Size ;
+#endif
+*/
+}
+
+// ----------------------------------------------------------------------------
+//! Returns the address.
+unsigned long
+SocketSHM::returnAdress(void) const
+{
+ return (unsigned long) shmId;
+}
+
+// ----------------------------------------------------------------------------
+//! Returns the socket.
+int
+SocketSHM::returnSocket(void) const
+{
+ return shmId;
+}
+
+}
+
+// $Id: SocketSHM.cc_v1,v 1.1.2.1 2009/05/28 20:58:22 erk Exp $
Index: libCERTI/CCom.cc
===================================================================
RCS file: libCERTI/CCom.cc
diff -N libCERTI/CCom.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/CCom.cc 28 May 2009 20:58:23 -0000 1.1.2.1
@@ -0,0 +1,50 @@
+// **** DEBUT ENTETE *********************************************************
+//
+// Copyright 2003 ONERA
+//
+//
+//_NOM : hla/test/test_msg/CCom.cc
+//
+//_VERSION : 1.0
+//
+//_HISTORIQUE :
+//
+//
+//_DESCRIPTION : Classe abstraite pour la comunication entre de process
+//
+//
+//_CONTEXTE : Test de performance des differentes implementations des
+// CMessageReseau et des CSocket*.
+//
+//_CATEGORIE :
+//
+//_SYNOPSIS :
+//
+//_ENTREE :
+//
+//_SORTIE :
+//
+//_MODIFIEE :
+//
+//_LOCALE :
+//
+//_DIAGNOSTIC :
+//
+//_BUGS CONNUS : ?
+//
+//_VOIR AUSSI : le fichier README.
+//
+// **** FIN ENTETE ***********************************************************
+
+#include "CCom.hh"
+
+
+CCom::CCom (ProcessFunction *NullProcess ,
+ ProcessFunction *UAVProcess ) {
+
+}
+
+
+CCom::~CCom () {
+
+}
Index: libCERTI/SocketSHM.cc
===================================================================
RCS file: libCERTI/SocketSHM.cc
diff -N libCERTI/SocketSHM.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHM.cc 28 May 2009 20:58:23 -0000 1.1.2.1
@@ -0,0 +1,415 @@
+// -*- 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-libCERTI
+//
+// CERTI-libCERTI is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// CERTI-libCERTI 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser 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: SocketSHM.cc,v 1.1.2.1 2009/05/28 20:58:23 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include "SocketSHM.hh"
+
+namespace certi {
+
+static pdCDebug D("SOCKSHM", "(SocketSHM) - ");
+
+
+// ----------------------------------------------------------------------------
+//! accept.
+int SocketSHM::accept(SocketTCP *serveur)
+{
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+ struct protoent *TCPent ;
+ int optval = 1 ;
+ socklen_t l ;
+
+ assert(serveur != NULL);
+
+ l = sizeof(_sockIn);
+
+ _socket_tcp = ::accept(serveur->returnSocket(), (sockaddr*)&_sockIn, &l);
+ //HPUX: _socket_tcp = accept(serveur->_socket_tcp, (sockaddr*)&_sockIn,
+ //(int*) &l);
+ if (_socket_tcp < 0) {
+ perror("SocketTCP: Accept");
+ exit(-1);
+ }
+
+ // Set the TCP_NODELAY option(Server Side)
+ TCPent = getprotobyname("tcp");
+ if (TCPent == NULL) {
+ cout << "Unable to retrieve TCP protocol number." << endl ;
+ return 0 ;
+ }
+
+ if (setsockopt(_socket_tcp,
+ TCPent->p_proto,
+ TCP_NODELAY,
+ (char *) &optval,
+ sizeof(optval))) {
+ cout << "Error while calling setsockopt." << endl ;
+ return 0 ;
+ }
+ D.Out(pdTrace, "Acceptation d'une connexion cote serveur") ;
+ isServer = true;
+ if ((shmId = shmget (IPC_PRIVATE, sizeof(SHM),IPC_CREAT|0666)) == -1)
+ { perror ("shmget"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Creating shared memory with id = %d", shmId) ;
+
+ /* attachement a une adresse non fixee */
+
+ if ((shm = (SHM *) shmat(shmId, 0 ,0)) == (SHM *) -1)
+ { perror ("shmat"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Shared memory attached") ;
+
+
+ shm -> S_C.qui = EMPTY ; // le segment est libre en écriture
+ shm -> C_S.qui = EMPTY ;
+
+ int ctrl;
+ write(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ read(_socket_tcp,&ctrl,(unsigned) sizeof(int));
+ if(ctrl != shmId) cout<< "erreur de transmission de l'identifiant shm";
+ ::close(_socket_tcp);
+
+ return shmId;
+}
+
+// ----------------------------------------------------------------------------
+//! createSHMClient
+void
+SocketSHM::createSHMClient(unsigned int port, char *nom_serveur){
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+
+
+ D.Out(pdTrace, "Creation socket cote client") ;
+
+ _socket_tcp=socket(AF_INET, SOCK_STREAM, 0);
+
+ D.Out(pdTrace, "Recuperation des infos sur le serveur") ;
+ // recuperer les infos sur le serveur a partir du nom
+ struct hostent *hptr = gethostbyname(nom_serveur);
+ if (hptr == 0) {
+ perror("SocketTCP: gethostbyname");
+ exit(-1);
+ }
+
+ unsigned long addr = 0 ;
+ memcpy((void *) &addr, (void *) hptr->h_addr, hptr->h_length);
+
+
+ int Result ;
+ struct protoent *TCPent ;
+ int optval = 1 ;
+
+ _sockIn.sin_family=AF_INET ;
+ _sockIn.sin_port=htons(port);
+ _sockIn.sin_addr.s_addr=addr ;
+
+ D.Out(pdTrace, "Tentative de connexion") ;
+ Result = ::connect(_socket_tcp, (sockaddr*)&_sockIn, sizeof(_sockIn));
+
+ if (Result < 0)
+ return ;
+
+ // Set the TCP_NODELAY option(Client Side)
+
+ TCPent = getprotobyname("tcp");
+ if (TCPent == NULL) {
+ cout << "Unable to retrieve TCP protocol number." << endl ;
+ return ;
+ }
+
+ if (setsockopt(_socket_tcp,
+ TCPent->p_proto,
+ TCP_NODELAY,
+ (char *) &optval,
+ sizeof(optval))) {
+ cout << "Error while calling setsockopt." << endl ;
+ return ;
+ }
+ D.Out(pdTrace, "Lecture des informations de connexion") ;
+ read(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ write(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ ::close(_socket_tcp);
+
+ D.Out(pdTrace, "Attachement de la memoire") ;
+ isServer = false;
+ //shmId = id_shm;
+ if ((shm = (SHM *) shmat(shmId, 0 ,0)) == (SHM *) -1)
+ { perror ("shmat"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Shared memory attached with id = %d", shmId) ;
+}
+
+
+// ----------------------------------------------------------------------------
+//! Constructor.
+SocketSHM::SocketSHM(void)
+{
+}
+// ----------------------------------------------------------------------------
+//! Destructor.
+SocketSHM::~SocketSHM(void)
+{
+ // Fermeture
+ //if (_est_init_tcp)
+ close();
+/*
+#ifdef RTI_PRINTS_STATISTICS
+ cout << endl ;
+ cout << "TCP Socket(" << _socket_tcp << "): Total Sent Bytes : "
+ << SentBytesCount << '.' << endl ;
+ cout << "TCP Socket(" << _socket_tcp << "): Total Received Bytes : "
+ << RcvdBytesCount << '.' << endl ;
+ cout << endl ;
+#endif
+*/
+}
+
+// ----------------------------------------------------------------------------
+//! send.
+void SocketSHM::send(void *Buffer, unsigned long Size)
+{
+ if(isServer){
+ D.Out(pdTrace, "Ecriture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en ecriture cote serveur") ;
+ while(shm->S_C.qui==FULL)D.Out(pdTrace, "S_C.qui : %c",shm->S_C.qui);
+ D.Out(pdTrace, "Ecriture debloque cote serveur : writing Header") ;
+ shm->S_C.Header = ((SharedMemory *)Buffer)->Header;
+ D.Out(pdTrace, "writing body") ;
+ shm->S_C.Body = ((SharedMemory *)Buffer)->Body;
+ shm->S_C.qui=FULL;
+ D.Out(pdTrace, "S_C.qui positionne a : %c",shm->S_C.qui) ;
+ }
+ else{
+ D.Out(pdTrace, "Ecriture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en Ecriture cote client") ;
+ int result=shm->C_S.qui;
+ while(result==FULL)result=shm->C_S.qui;
+ D.Out(pdTrace, "Ecriture debloque cote client : writing Header") ;
+ shm->C_S.Header = ((SharedMemory *)Buffer)->Header;
+ D.Out(pdTrace, "writing body") ;
+ shm->C_S.Body = ((SharedMemory *)Buffer)->Body;
+ shm->C_S.qui=FULL;
+ D.Out(pdTrace, "C_S.qui positionne a : %c",shm->C_S.qui) ;
+ }
+ /*long nSent = 0 ;
+ long total_sent = 0 ;
+ long expected_size = Size ;
+
+ assert(_est_init_tcp);
+
+ D.Out(pdDebug, "Beginning to send SHM message...");
+
+ while (total_sent < expected_size) {
+ nSent = ::send(_socket_tcp,
+ (char *) Buffer + total_sent,
+ expected_size - total_sent,
+ 0);
+
+ if (nSent < 0) {
+ D.Out(pdExcept, "Error while sending on TCP socket.");
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else {
+ perror("TCP Socket(EmettreTCP) ");
+ throw NetworkError("Error while sending TCP message.");
+ }
+ }
+
+ if (nSent == 0) {
+ D.Out(pdExcept, "No data could be sent, connection closed?.");
+ throw NetworkError("Could not send any data on TCP socket.");
+ }
+
+ total_sent += nSent ;
+ D.Out(pdTrace, "Sent %ld bytes out of %ld.", total_sent,
expected_size);
+ }
+
+ SentBytesCount += total_sent ;*/
+}
+
+// ----------------------------------------------------------------------------
+//! close.
+void SocketSHM::close(void)
+{
+ if(isServer){
+ /* detachement des segments memoire*/
+ if(shmdt(shm)){
+ perror("Echec du shmdt car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detachee cotee serveur") ;
+
+
+ /*Destruction des segments memoire */
+ if(shmctl(shmId, IPC_RMID,0)){
+ perror("Echec de shmctl(IPC_RMID) car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detruite") ;
+ }
+ else{
+ /* detachement des segments memoire*/
+ if(shmdt(shm)){
+ perror("Echec du shmdt car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detachee cotee client") ;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+/*! Return RTI_TRUE if any data as already been read from the system socket
+ and is waiting in the internal buffer, else RTI_FALSE.
+*/
+Boolean
+SocketSHM::isDataReady(void) const
+{
+ if(isServer){
+ if (shm->C_S.qui == FULL) return RTI_TRUE;
+ else return RTI_FALSE;
+ }
+ else{
+ if (shm->S_C.qui == FULL) return RTI_TRUE;
+ else return RTI_FALSE;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+//! receive.
+void SocketSHM::receive(void *Buffer, unsigned long Size)
+{
+ if(isServer){
+ D.Out(pdTrace, "Lecture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en lecture cote serveur") ;
+ while(shm->C_S.qui==EMPTY) {
+ D.Out(pdTrace, "C_S.qui : %c",shm->C_S.qui);
+ if (sched_yield ()) {
+ D.Out(pdError, " SocketSHM::receive : sched_yield problem"); exit
(-1) ;
+ }
+
+ }
+ D.Out(pdTrace, "Lecture debloque cote serveur : reading Header") ;
+ ((SharedMemory *)Buffer)->Header = shm->C_S.Header;
+ D.Out(pdTrace, "reading body") ;
+ ((SharedMemory *)Buffer)->Body = shm->C_S.Body;
+ shm->C_S.qui=EMPTY;
+ D.Out(pdTrace, "C_S.qui positionne a : %c",shm->C_S.qui) ;
+ }
+ else{
+ D.Out(pdTrace, "Lecture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en lecture cote client") ;
+ int result=shm->S_C.qui;
+ while(result==EMPTY) {
+ if (sched_yield ()) {
+ D.Out(pdError, " SocketSHM::receive : sched_yield problem"); exit
(-1) ;
+ }
+
+ result=shm->S_C.qui;
+ }
+ D.Out(pdTrace, "Lecture debloque cote client : reading Header") ;
+ ((SharedMemory *)Buffer)->Header = shm->S_C.Header;
+ D.Out(pdTrace, "reading body") ;
+ ((SharedMemory *)Buffer)->Body = shm->S_C.Body;
+ shm->S_C.qui=EMPTY;
+ D.Out(pdTrace, "S_C.qui positionne a : %c",shm->S_C.qui) ;
+ }
+
+ /*
+ assert(_est_init_tcp);
+
+ long nReceived = 0 ;
+#ifndef SOCKTCP_BUFFER_LENGTH
+ long RBLength = 0 ;
+#endif
+
+ D.Out(pdDebug, "Beginning to receive TCP message...");
+
+ while (RBLength < Size)
+ {
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ nReceived = recv(_socket_tcp,
+ ReadBuffer + RBLength,
+ SOCKTCP_BUFFER_LENGTH - RBLength,
+ 0);
+#else
+ nReceived = recv(_socket_tcp,
+ (char *) Buffer + RBLength,
+ Size - RBLength,
+ 0);
+#endif
+
+ if (nReceived < 0) {
+ D.Out(pdExcept, "Error while receiving on TCP socket.");
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else {
+ perror("TCP Socket(RecevoirTCP) ");
+ throw NetworkError("Error while receiving TCP message.");
+ }
+ }
+
+ if (nReceived == 0) {
+ D.Out(pdExcept, "TCP connection has been closed by peer.");
+ throw NetworkError("Connection closed by client.");
+ }
+
+ RBLength += nReceived ;
+ RcvdBytesCount += nReceived ;
+
+ D.Out(pdTrace, "Received %ld bytes out of %ld.", RBLength, Size);
+ }
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ memcpy(Buffer, (void *) ReadBuffer, Size);
+ memmove((void *) ReadBuffer,
+ (void *)(ReadBuffer + Size),
+ RBLength - Size);
+ RBLength -= Size ;
+#endif
+*/
+}
+
+// ----------------------------------------------------------------------------
+//! Returns the address.
+unsigned long
+SocketSHM::returnAdress(void) const
+{
+ return (unsigned long) shmId;
+}
+
+// ----------------------------------------------------------------------------
+//! Returns the socket.
+int
+SocketSHM::returnSocket(void) const
+{
+ return shmId;
+}
+
+}
+
+// $Id: SocketSHM.cc,v 1.1.2.1 2009/05/28 20:58:23 erk Exp $
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 28 May 2009 20:58:24 -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/05/28 20:58:24 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/05/28 20:58:24 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 28 May 2009 20:58:24 -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/05/28 20:58:24 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/05/28 20:58:24 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 28 May 2009 20:58:24 -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/05/28 20:58:24 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/05/28 20:58:24 erk Exp $
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 28 May 2009 20:58:25 -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/05/28 20:58:25 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/05/28 20:58:25 erk Exp $
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi RTIG/Federation.cc RTIG/FederationsList.c... [CERTI-SHM],
certi-cvs <=