certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi RTIA/Communications.cc RTIA/Communication...


From: certi-cvs
Subject: [certi-cvs] certi RTIA/Communications.cc RTIA/Communication...
Date: Sat, 11 Oct 2008 12:53:53 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Petr Gotthard <gotthardp>       08/10/11 12:53:53

Modified files:
        RTIA           : Communications.cc Communications.hh 
        libCERTI       : SocketUN.cc SocketUN.hh 

Log message:
        Replace multiple inheritance in the Communications object. (A step 
towards patch #6561.)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.cc?cvsroot=certi&r1=3.31&r2=3.32
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.hh?cvsroot=certi&r1=3.15&r2=3.16
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketUN.cc?cvsroot=certi&r1=3.26&r2=3.27
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketUN.hh?cvsroot=certi&r1=3.16&r2=3.17

Patches:
Index: RTIA/Communications.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/Communications.cc,v
retrieving revision 3.31
retrieving revision 3.32
diff -u -b -r3.31 -r3.32
--- RTIA/Communications.cc      23 Jun 2008 12:49:15 -0000      3.31
+++ RTIA/Communications.cc      11 Oct 2008 12:53:52 -0000      3.32
@@ -18,7 +18,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.31 2008/06/23 12:49:15 erk Exp $
+// $Id: Communications.cc,v 3.32 2008/10/11 12:53:52 gotthardp Exp $
 // ----------------------------------------------------------------------------
 
 #include <config.h>
@@ -72,14 +72,14 @@
 
     // Otherwise, wait for a message with same type than expected and with
     // same federate number.
-    msg = NM_Factory::receive((SecureTCPSocket *) this);    
+    msg = NM_Factory::receive(socketTCP);
 
     D.Out(pdProtocol, "TCP Message of Type %d has arrived.", type_msg);
 
     while ((msg->getType() != type_msg) ||
            ((numeroFedere != 0) && (msg->federate != numeroFedere))) {
         waitingList.push_back(msg);
-        msg = NM_Factory::receive((SecureTCPSocket *) this);        
+        msg = NM_Factory::receive(socketTCP);
         D.Out(pdProtocol, "Message of Type %d has arrived.", type_msg);
     }
     
@@ -91,13 +91,19 @@
 // ----------------------------------------------------------------------------
 //! Communications.
 Communications::Communications(int RTIA_port)
-    : SocketUN(), SecureTCPSocket(), SocketUDP()
 {
     char nom_serveur_RTIG[200] ;
     const char *default_host = "localhost" ;
 
+    socketUN = new SocketUN();
+#ifdef FEDERATION_USES_MULTICAST
+    socketMC = new SocketMC();
+#endif
+    socketTCP = new SecureTCPSocket();
+    socketUDP = new SocketUDP();
+
     // Federate/RTIA link creation.
-    acceptUN(RTIA_port);
+    socketUN->acceptUN(RTIA_port);
 
     // RTIG TCP link creation.
     const char *certihost = NULL ;
@@ -120,8 +126,8 @@
     if (tcp_port==NULL) tcp_port = PORT_TCP_RTIG ;
     if (udp_port==NULL) udp_port = PORT_UDP_RTIG ;
 
-    createTCPClient(atoi(tcp_port), certihost);
-    createUDPClient(atoi(udp_port), certihost);
+    socketTCP->createTCPClient(atoi(tcp_port), certihost);
+    socketUDP->createUDPClient(atoi(udp_port), certihost);
 }
 
 // ----------------------------------------------------------------------------
@@ -132,8 +138,15 @@
     G.Out(pdGendoc,"enter Communications::~Communications");
 
     NM_Close_Connexion closeMsg ;    
-    closeMsg.send((SecureTCPSocket *) this, NM_msgBufSend);
-    SecureTCPSocket::close();
+    closeMsg.send(socketTCP, NM_msgBufSend);
+    socketTCP->close();
+
+    delete socketUN;
+#ifdef FEDERATION_USES_MULTICAST
+    delete socketMC;
+#endif
+    delete socketTCP;
+    delete socketUDP;
 
     G.Out(pdGendoc,"exit  Communications::~Communications");
 }
@@ -147,7 +160,7 @@
     //               "type %d",req->type);
     assert(req != NULL);
     D.Out(pdRequest, "Sending Request to Federate, Type %d.", req->type);
-    sendUN(req);
+    req->send(socketUN, msgBufSend);
     // G.Out(pdGendoc,"exit  Communications::requestFederateService");
 }
 
@@ -155,14 +168,14 @@
 unsigned long
 Communications::getAddress()
 {
-    return((SocketUDP *) this)->getAddr();
+    return socketUDP->getAddr();
 }
 
 // ----------------------------------------------------------------------------
 unsigned int
 Communications::getPort()
 {
-    return((SocketUDP *) this)->getPort();
+    return socketUDP->getPort();
 }
 
 // ----------------------------------------------------------------------------
@@ -174,8 +187,8 @@
 Communications::readMessage(int &n, NetworkMessage **msg_reseau, Message **msg,
                             struct timeval *timeout)
 {
-    const int tcp_fd(SecureTCPSocket::returnSocket());
-    const int udp_fd(SocketUDP::returnSocket());
+    const int tcp_fd(socketTCP->returnSocket());
+    const int udp_fd(socketUDP->returnSocket());
 
     int max_fd = 0; // not used for _WIN32
     fd_set fdset ;
@@ -189,9 +202,9 @@
 #endif
     }
     if (msg) {
-        FD_SET(_socket_un, &fdset);
+        FD_SET(socketUN->returnSocket(), &fdset);
 #ifndef _WIN32
-       max_fd = std::max(max_fd, _socket_un);
+       max_fd = std::max(max_fd, socketUN->returnSocket());
 #endif
     }
 
@@ -211,23 +224,23 @@
         waitingList.pop_front();                
         n = 1 ;
     }
-    else if (msg_reseau && SecureTCPSocket::isDataReady()) {
+    else if (msg_reseau && socketTCP->isDataReady()) {
         // Datas are in TCP waiting buffer.
         // Read a message from RTIG TCP link.
-       *msg_reseau = NM_Factory::receive((SecureTCPSocket *) this);        
+       *msg_reseau = NM_Factory::receive(socketTCP);
         n = 1 ;
     }
-    else if (msg_reseau && SocketUDP::isDataReady()) {
+    else if (msg_reseau && socketUDP->isDataReady()) {
         // Datas are in UDP waiting buffer.
         // Read a message from RTIG UDP link.
-       *msg_reseau = NM_Factory::receive((SocketUDP *) this);       
+       *msg_reseau = NM_Factory::receive(socketUDP);
         n = 1 ;
     }
-    else if (msg && SocketUN::isDataReady()) {
+    else if (msg && socketUN->isDataReady()) {
         // Datas are in UNIX waiting buffer.
         // Read a message from federate UNIX link.
        (*msg) = new Message();
-        (*msg)->receive((SocketUN *) this,msgBufReceive);
+        (*msg)->receive(socketUN, msgBufReceive);
         n = 2 ;
     }
     else {
@@ -261,20 +274,20 @@
         }
 #endif
 
-        if (FD_ISSET(SecureTCPSocket::returnSocket(), &fdset)) {
+        if (FD_ISSET(socketTCP->returnSocket(), &fdset)) {
             // Read a message coming from the TCP link with RTIG.
-               (*msg_reseau) = NM_Factory::receive((SecureTCPSocket *) this);  
          
+               (*msg_reseau) = NM_Factory::receive(socketTCP);
             n = 1 ;
         }
-        else if (FD_ISSET(SocketUDP::returnSocket(), &fdset)) {
+        else if (FD_ISSET(socketUDP->returnSocket(), &fdset)) {
             // Read a message coming from the UDP link with RTIG.
-               (*msg_reseau) = NM_Factory::receive((SocketUDP *) this);        
        
+               (*msg_reseau) = NM_Factory::receive(socketUDP);
             n = 1 ;
         }
-        else if (FD_ISSET(_socket_un, &fdset)) {
+        else if (FD_ISSET(socketUN->returnSocket(), &fdset)) {
             // Read a message coming from the federate.            
             (*msg) = new Message();
-            receiveUN(*msg);
+            (*msg)->receive(socketUN, msgBufReceive);
             n = 2 ;
         }
         else
@@ -320,23 +333,23 @@
 void
 Communications::sendMessage(NetworkMessage *Msg)
 {
-    Msg->send((SecureTCPSocket *) this,NM_msgBufSend);
+    Msg->send(socketTCP, NM_msgBufSend);
 }
 
 // ----------------------------------------------------------------------------
 void
 Communications::sendUN(Message *Msg)
 {
-    Msg->send((SocketUN *) this,msgBufSend);
+    Msg->send(socketUN, msgBufSend);
 }
 
 // ----------------------------------------------------------------------------
 void
 Communications::receiveUN(Message *Msg)
 {
-    Msg->receive((SocketUN *) this,msgBufReceive);
+    Msg->receive(socketUN, msgBufReceive);
 }
 
 }} // namespace certi/rtia
 
-// $Id: Communications.cc,v 3.31 2008/06/23 12:49:15 erk Exp $
+// $Id: Communications.cc,v 3.32 2008/10/11 12:53:52 gotthardp Exp $

Index: RTIA/Communications.hh
===================================================================
RCS file: /sources/certi/certi/RTIA/Communications.hh,v
retrieving revision 3.15
retrieving revision 3.16
diff -u -b -r3.15 -r3.16
--- RTIA/Communications.hh      23 Jun 2008 12:49:15 -0000      3.15
+++ RTIA/Communications.hh      11 Oct 2008 12:53:52 -0000      3.16
@@ -18,7 +18,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.15 2008/06/23 12:49:15 erk Exp $
+// $Id: Communications.hh,v 3.16 2008/10/11 12:53:52 gotthardp Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef _CERTI_COMMUNICATIONS_HH
@@ -39,12 +39,7 @@
 namespace certi {
 namespace rtia {
 
-class Communications : public SocketUN,
-#ifdef FEDERATION_USES_MULTICAST
-                       public SocketMC,
-#endif
-                       public SecureTCPSocket,
-                       public SocketUDP
+class Communications
 {
 public:
     Communications(int RTIA_port);
@@ -71,6 +66,14 @@
     MessageBuffer NM_msgBufSend,NM_msgBufReceive;
     MessageBuffer msgBufSend, msgBufReceive ;
 
+protected:
+    SocketUN *socketUN;
+#ifdef FEDERATION_USES_MULTICAST
+    SocketMC *socketMC;
+#endif
+    SocketTCP *socketTCP;
+    SocketUDP *socketUDP;
+
 private:
        /**
         * this is the wait list of message 
@@ -88,4 +91,4 @@
 
 #endif // _CERTI_COMMUNICATIONS_HH
 
-// $Id: Communications.hh,v 3.15 2008/06/23 12:49:15 erk Exp $
+// $Id: Communications.hh,v 3.16 2008/10/11 12:53:52 gotthardp Exp $

Index: libCERTI/SocketUN.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketUN.cc,v
retrieving revision 3.26
retrieving revision 3.27
diff -u -b -r3.26 -r3.27
--- libCERTI/SocketUN.cc        24 Jun 2008 14:08:24 -0000      3.26
+++ libCERTI/SocketUN.cc        11 Oct 2008 12:53:53 -0000      3.27
@@ -390,6 +390,17 @@
 }
 
 // ----------------------------------------------------------------------------
+#ifdef _WIN32
+SOCKET
+#else
+int
+#endif
+SocketUN::returnSocket()
+{
+    return _socket_un;
+}
+
+// ----------------------------------------------------------------------------
 void
 SocketUN::receive(const unsigned char *buffer, size_t Size)
     throw (NetworkError, NetworkSignal)

Index: libCERTI/SocketUN.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketUN.hh,v
retrieving revision 3.16
retrieving revision 3.17
diff -u -b -r3.16 -r3.17
--- libCERTI/SocketUN.hh        24 Jun 2008 08:56:49 -0000      3.16
+++ libCERTI/SocketUN.hh        11 Oct 2008 12:53:53 -0000      3.17
@@ -74,6 +74,12 @@
 
        bool isDataReady();
 
+    #ifdef _WIN32
+        SOCKET returnSocket();
+    #else
+        int returnSocket();
+    #endif
+
        void send(const unsigned char *, size_t)                throw 
(NetworkError, NetworkSignal);
        void receive(const unsigned char *, size_t)     throw (NetworkError, 
NetworkSignal);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]