Index: RTIA/FederationManagement.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/FederationManagement.cc,v
retrieving revision 3.81
diff -u -r3.81 FederationManagement.cc
--- RTIA/FederationManagement.cc	7 Mar 2010 18:23:40 -0000	3.81
+++ RTIA/FederationManagement.cc	13 Mar 2010 15:44:25 -0000
@@ -53,7 +53,7 @@
     _numero_federation = 0 ;
     federate = 0 ;
 
-    _fin_execution = false ;
+    _connection_state = CONNECTION_PRELUDE;
 
     _est_membre_federation = false ;
 
Index: RTIA/FederationManagement.hh
===================================================================
RCS file: /sources/certi/certi/RTIA/FederationManagement.hh,v
retrieving revision 3.30
diff -u -r3.30 FederationManagement.hh
--- RTIA/FederationManagement.hh	7 Mar 2010 18:23:40 -0000	3.30
+++ RTIA/FederationManagement.hh	13 Mar 2010 15:44:26 -0000
@@ -108,7 +108,11 @@
     TimeManagement *tm ;
     Handle _numero_federation ;
     FederateHandle federate ;
-    bool _fin_execution ;
+    enum {
+        CONNECTION_PRELUDE, //!< Before OPEN_CONNEXION
+        CONNECTION_READY,
+        CONNECTION_FIN //!< After CLOSE_CONNEXION
+    } _connection_state;
 
 private:
     Communications *comm ;
Index: RTIA/RTIA.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/RTIA.cc,v
retrieving revision 3.31
diff -u -r3.31 RTIA.cc
--- RTIA/RTIA.cc	18 Nov 2009 18:50:48 -0000	3.31
+++ RTIA/RTIA.cc	13 Mar 2010 15:44:26 -0000
@@ -97,7 +97,7 @@
     NetworkMessage *msg_tcp_udp;
     int n ;
 
-    while (!fm->_fin_execution) {
+    while (fm->_connection_state != FederationManagement::CONNECTION_FIN) {
        
         /* 
          * readMessage call will allocate EITHER a Network Message or a Message 
@@ -148,7 +148,7 @@
             /* timev is undefined after select() */
         }
         catch (NetworkSignal) {
-            fm->_fin_execution = true ;
+            fm->_connection_state = FederationManagement::CONNECTION_FIN;
             n = 0 ;
             delete msg_un ;
             delete msg_tcp_udp ;
Index: RTIA/RTIA.hh
===================================================================
RCS file: /sources/certi/certi/RTIA/RTIA.hh,v
retrieving revision 3.19
diff -u -r3.19 RTIA.hh
--- RTIA/RTIA.hh	27 Feb 2010 16:53:36 -0000	3.19
+++ RTIA/RTIA.hh	13 Mar 2010 15:44:26 -0000
@@ -104,6 +104,8 @@
      */
     void processFederateRequest(Message *request);
 
+    void initFederateProcessing(Message *request, Message* answer);
+
     /**
      * The method called by processFederateRequest in order to
      * effectively process the request and build the appropriate
Index: RTIA/RTIA_federate.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/RTIA_federate.cc,v
retrieving revision 3.105
diff -u -r3.105 RTIA_federate.cc
--- RTIA/RTIA_federate.cc	7 Mar 2010 18:23:40 -0000	3.105
+++ RTIA/RTIA_federate.cc	13 Mar 2010 15:44:30 -0000
@@ -51,6 +51,7 @@
 	//D.Mes(pdMessage, 'N', type);
 
 	switch (type) {
+	case Message::OPEN_CONNEXION:
 	case Message::CLOSE_CONNEXION:
 	case Message::RESIGN_FEDERATION_EXECUTION:
 	case Message::TICK_REQUEST:
@@ -112,7 +113,7 @@
 	case Message::CLOSE_CONNEXION:
 		D.Out(pdTrace,
 				"Receiving Message from Federate, type CloseConnexion.");
-		fm->_fin_execution = true;
+		fm->_connection_state = FederationManagement::CONNECTION_FIN;
 		// the this->comm can now be used only to sent the CLOSE_CONNEXION response
 		break ;
 
@@ -1313,6 +1314,36 @@
 } /* RTIA::processOngoingTick() */
 
 void
+RTIA::initFederateProcessing(Message *request, Message* answer)
+{
+	if(request->getType() == Message::OPEN_CONNEXION) {
+		M_Open_Connexion *OCq, *OCr;
+		OCq = static_cast<M_Open_Connexion *>(request);
+		OCr = static_cast<M_Open_Connexion *>(answer);
+
+		if(OCq->getVersionMajor() == CERTI_Message::versionMajor) {
+			unsigned int minorEffective = OCq->getVersionMinor() < CERTI_Message::versionMinor
+				? OCq->getVersionMinor() : CERTI_Message::versionMinor;
+			OCr->setVersionMajor(CERTI_Message::versionMajor);
+			OCr->setVersionMinor(minorEffective);
+
+			fm->_connection_state = FederationManagement::CONNECTION_READY;
+		}
+		else {
+			std::cerr << "RTIA protocol version mismatch"
+				<< "; federate " << OCq->getVersionMajor() << "." << OCq->getVersionMinor()
+				<< ", RTIA " << CERTI_Message::versionMajor << "." << CERTI_Message::versionMinor
+				<< std::endl;
+			answer->setException(e_RTIinternalError);
+		}
+	}
+	else {
+		std::cerr << "RTIA protocol version mismatch; expecting OPEN_CONNECTION first." << std::endl;
+		answer->setException(e_RTIinternalError);
+	}
+}
+
+void
 RTIA::processFederateRequest(Message *req)
 {
 	/* use virtual constructor in order to build  *
@@ -1322,10 +1353,26 @@
 	G.Out(pdGendoc,"enter RTIA::processFederateRequest");
 
 	try {
-		TypeException exc ;
-		chooseFederateProcessing(req, rep.get(), exc);
-		if ( exc != e_RTIinternalError && exc != e_NO_EXCEPTION) {
-			rep->setException(exc);
+		switch(fm->_connection_state) {
+		case FederationManagement::CONNECTION_PRELUDE:
+			initFederateProcessing(req, rep.get());
+			break;
+
+		case FederationManagement::CONNECTION_READY:
+		{
+			TypeException exc ;
+			chooseFederateProcessing(req, rep.get(), exc);
+			if ( exc != e_RTIinternalError && exc != e_NO_EXCEPTION) {
+				rep->setException(exc);
+			}
+			break;
+		}
+
+		case FederationManagement::CONNECTION_FIN:
+		default:
+			std::cerr << "RTIA connection already closed." << std::endl;
+			rep->setException(e_RTIinternalError);
+			break;
 		}
 	}
 	// FIXME should
Index: RTIA/Statistics.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/Statistics.cc,v
retrieving revision 3.21
diff -u -r3.21 Statistics.cc
--- RTIA/Statistics.cc	19 Nov 2009 18:15:30 -0000	3.21
+++ RTIA/Statistics.cc	13 Mar 2010 15:44:31 -0000
@@ -56,6 +56,7 @@
 	myDisplay = false ;
 
     if (!initialized) {
+        FED_MSG_NAME(Message::OPEN_CONNEXION);
         FED_MSG_NAME(Message::CLOSE_CONNEXION);
 
         // Federation
Index: libCERTI/Message.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Message.hh,v
retrieving revision 3.61
diff -u -r3.61 Message.hh
--- libCERTI/Message.hh	7 Mar 2010 18:23:39 -0000	3.61
+++ libCERTI/Message.hh	13 Mar 2010 15:44:51 -0000
@@ -45,6 +45,7 @@
 
     enum Type {
         NOT_USED = 0,
+        OPEN_CONNEXION,
         CLOSE_CONNEXION,
 
         // gestion federation
Index: libCERTI/PrettyDebEx.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/PrettyDebEx.cc,v
retrieving revision 4.9
diff -u -r4.9 PrettyDebEx.cc
--- libCERTI/PrettyDebEx.cc	7 Mar 2010 18:23:39 -0000	4.9
+++ libCERTI/PrettyDebEx.cc	13 Mar 2010 15:44:53 -0000
@@ -66,6 +66,7 @@
 
 	switch (testMess)
 		{
+		case certi::Message::OPEN_CONNEXION : strcat(theMessage,"OPEN_CONNEXION"); break;
 		case certi::Message::CLOSE_CONNEXION : strcat(theMessage,"CLOSE_CONNEXION"); break;
 		case certi::Message::CREATE_FEDERATION_EXECUTION :							strcat(theMessage,"CREATE_FEDERATION_EXECUTION"); break;
 		case certi::Message::DESTROY_FEDERATION_EXECUTION :						strcat(theMessage,"DESTROY_FEDERATION_EXECUTION"); break;
@@ -229,6 +230,7 @@
 	{
 	switch (testMess)
 		{//NetworkMessage.h
+		case certi::NetworkMessage::OPEN_CONNEXION : strcat(theMessage,"OPEN_CONNEXION"); break;
 		case certi::NetworkMessage::CLOSE_CONNEXION :										strcat(theMessage,"CLOSE_CONNEXION"); break;
 		case certi::NetworkMessage::MESSAGE_NULL :											strcat(theMessage,"MESSAGE_NULL"); break;
 		case certi::NetworkMessage::CREATE_FEDERATION_EXECUTION :						strcat(theMessage,"CREATE_FEDERATION_EXECUTION"); break;
Index: libRTI/RTIambassador.cc
===================================================================
RCS file: /sources/certi/certi/libRTI/RTIambassador.cc,v
retrieving revision 3.114
diff -u -r3.114 RTIambassador.cc
--- libRTI/RTIambassador.cc	7 Mar 2010 18:23:39 -0000	3.114
+++ libRTI/RTIambassador.cc	13 Mar 2010 15:44:59 -0000
@@ -322,6 +322,13 @@
 	}
 #endif
 
+	M_Open_Connexion req, rep ;
+	req.setVersionMajor(CERTI_Message::versionMajor);
+	req.setVersionMinor(CERTI_Message::versionMinor);
+
+	G.Out(pdGendoc,"        ====>executeService OPEN_CONNEXION");
+	privateRefs->executeService(&req, &rep);
+
 	G.Out(pdGendoc,"exit  RTIambassador::RTIambassador");
 }
 
Index: scripts/CERTI_Message.msg
===================================================================
RCS file: /sources/certi/certi/scripts/CERTI_Message.msg,v
retrieving revision 1.15
diff -u -r1.15 CERTI_Message.msg
--- scripts/CERTI_Message.msg	11 Mar 2010 10:38:01 -0000	1.15
+++ scripts/CERTI_Message.msg	13 Mar 2010 15:45:01 -0000
@@ -23,6 +23,7 @@
 // ----------------------------------------------------------------------------
 // The messages related classes will be placed in the certi package
 package certi
+version 1.0
 
 // Message is the base class for
 // message exchanged between RTIA and Federate (libRTI) AKA CERTI Message. 
@@ -164,6 +165,12 @@
 }        
 
 // Closing connexion message
+message M_Open_Connexion : merge Message {
+    required uint16 versionMajor
+    required uint16 versionMinor
+}
+
+// Closing connexion message
 message M_Close_Connexion : merge Message {
 }
 
Index: scripts/CERTI_NetworkMessage.msg
===================================================================
RCS file: /sources/certi/certi/scripts/CERTI_NetworkMessage.msg,v
retrieving revision 1.16
diff -u -r1.16 CERTI_NetworkMessage.msg
--- scripts/CERTI_NetworkMessage.msg	11 Mar 2010 10:39:18 -0000	1.16
+++ scripts/CERTI_NetworkMessage.msg	13 Mar 2010 15:45:01 -0000
@@ -23,6 +23,7 @@
 // ----------------------------------------------------------------------------
 // The messages related classes will be placed in the certi package
 package certi
+version 1.0
 
 // Network message is the base class
 // for message exchanged between RTIA and RTIG
Index: scripts/GenMsgAST.py
===================================================================
RCS file: /sources/certi/certi/scripts/GenMsgAST.py,v
retrieving revision 1.5
diff -u -r1.5 GenMsgAST.py
--- scripts/GenMsgAST.py	8 Mar 2010 12:52:11 -0000	1.5
+++ scripts/GenMsgAST.py	13 Mar 2010 15:45:03 -0000
@@ -101,6 +101,7 @@
     def __init__(self,name):
         super(MessageAST,self).__init__(name=name)
         self.__package            = None
+        self.__version            = None
         self.__factory            = None
         self.__nativeTypes        = []
         self.__messageTypes       = []
@@ -134,6 +135,15 @@
     # pythonic getter/setter using properties   
     package = property(fget=__getPackage,fset=__setPackage,fdel=None,doc=None)
 
+    def hasVersion(self):
+        return self.__version != None
+    def __getVersion(self):
+        return self.__version
+    def __setVersion(self,version):
+        self.__version = version
+    # pythonic getter/setter using properties   
+    version = property(fget=__getVersion,fset=__setVersion,fdel=None,doc=None)
+
     def hasFactory(self):
         return self.__factory != None
     def __getFactory(self):
@@ -186,6 +196,8 @@
                 self.addMessageType(any)
             elif isinstance(any,Package):
                 self.package = any
+            elif isinstance(any,Version):
+                self.version = any
             elif isinstance(any,Factory):
                 self.factory = any
             # Handle comment block preceding other AST element
@@ -294,6 +306,20 @@
     def __repr__(self):
         return "package %s" % self.name
 
+class Version(ASTElement):
+    """
+    Represents a version number.
+    
+    A C{Version} is a simple C{ASTElement} whose
+    name is a C{string}.
+    """
+    def __init__(self,number):
+        super(Version,self).__init__(name="Version")
+        self.number = number
+          
+    def __repr__(self):
+        return "version %d.%d" % self.number
+
 class Factory(ASTElement):
     """
     Represents a factory.
Index: scripts/GenMsgCXX.py
===================================================================
RCS file: /sources/certi/certi/scripts/GenMsgCXX.py,v
retrieving revision 1.7
diff -u -r1.7 GenMsgCXX.py
--- scripts/GenMsgCXX.py	11 Mar 2010 10:38:01 -0000	1.7
+++ scripts/GenMsgCXX.py	13 Mar 2010 15:45:04 -0000
@@ -285,13 +285,22 @@
                            self.writeComment(stream, native)
                            stream.write(self.getIndent()+stmt+"\n")
                            self.typedefed[stmt]=1                                    
-            
-            # Generate enum
-            lastname = ""
+
             # Put enum in a namespace in order to avoid conflict
             stream.write(self.getIndent())
             stream.write("namespace %s {\n" % self.AST.name.split(".")[0])
             self.indent()
+
+            # Generate version
+            if self.AST.hasVersion():
+                major,minor = self.AST.version.number
+                stream.write(self.getIndent())
+                stream.write("static const unsigned int versionMajor = %d;\n" % major)
+                stream.write(self.getIndent())
+                stream.write("static const unsigned int versionMinor = %d;\n" % minor)
+
+            # Generate enum
+            lastname = ""
             for enum in self.AST.enums:            
                 self.writeComment(stream, enum)
                 stream.write(self.getIndent())
Index: scripts/GenerateMessages.py
===================================================================
RCS file: /sources/certi/certi/scripts/GenerateMessages.py,v
retrieving revision 1.35
diff -u -r1.35 GenerateMessages.py
--- scripts/GenerateMessages.py	8 Mar 2010 11:34:54 -0000	1.35
+++ scripts/GenerateMessages.py	13 Mar 2010 15:45:04 -0000
@@ -137,6 +137,7 @@
 # reserved keywords
 reserved = {
    'package'        : 'PACKAGE',
+   'version'        : 'VERSION',
    'factory'        : 'FACTORY',
    'factoryCreator' : 'FACTORY_CREATOR',
    'factoryReceiver': 'FACTORY_RECEIVER',   
@@ -275,6 +276,7 @@
 def p_statement(p):
     '''statement : comment_block
                  | package
+                 | version
                  | factory
                  | message                 
                  | native                 
@@ -303,6 +305,10 @@
     else:
         p[0]=p[1]+"."+p[3]
 
+def p_version(p):
+    '''version : VERSION INTEGER_VALUE PERIOD INTEGER_VALUE'''
+    p[0]=GenMsgAST.Version((p[2],p[4]))
+
 def p_factory(p):
     '''factory : FACTORY ID LBRACE factory_creator factory_receiver RBRACE'''
     p[0] = GenMsgAST.Factory(p[2],p[4],p[5])
