]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
ajout du codage standard xdr avec les sockets.
authorageay <ageay>
Wed, 22 Sep 2004 13:04:37 +0000 (13:04 +0000)
committerageay <ageay>
Wed, 22 Sep 2004 13:04:37 +0000 (13:04 +0000)
src/Communication/ReceiverFactory.cxx
src/Communication/Receivers.cxx
src/Communication/Receivers.hxx
src/Communication/SALOME_Comm_i.cxx

index 781a37417d49f0d64a3e369de8b808764daa4b96..31bcb67685bfa12a89dc4cd45ff61ba49c79adc9 100644 (file)
 #define CorbaIWithCopyReceiver CorbaWCWithCopyReceiver
 #endif
 
+#ifdef HAVE_SOCKET
+#include <rpc/xdr.h>
+#endif
+
 /*!
   This method performs the transfert with the remote sender given. If it fails with this sender it tries with an another protocol (CORBA by default).
  */
@@ -81,7 +85,7 @@ void *ReceiverFactory::getValueOneShot(SALOME::Sender_ptr sender,long &size)thro
       else if(!CORBA::is_nil(sock_ptr))
        {
          CORBA::release(sender);
-         SocketReceiver<double> rec(sock_ptr);
+         SocketReceiver<double,xdr_double> rec(sock_ptr);
          return rec.getValue(size);
        }
 #endif
@@ -117,7 +121,7 @@ void *ReceiverFactory::getValueOneShot(SALOME::Sender_ptr sender,long &size)thro
       else if(!CORBA::is_nil(sock_ptr))
        {
          CORBA::release(sender);
-         SocketReceiver<int> rec(sock_ptr);
+         SocketReceiver<int,xdr_int> rec(sock_ptr);
          return rec.getValue(size);
        }
 #endif
index 04851c461eaa8175ecf77372686402c8de9752e7..e01125aa7f7530287bd92ef1f000dff444c1fe40 100644 (file)
@@ -218,16 +218,17 @@ void *MPIReceiver<T,T2>::getValue(long &size)
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <unistd.h>
+#include <rpc/xdr.h>
 
-template<class T>
-SocketReceiver<T>::SocketReceiver(SALOME::SocketSender_ptr mySender) : _mySender(mySender)
+template<class T,int (*myFunc)(XDR*,T*)>
+SocketReceiver<T,myFunc>::SocketReceiver(SALOME::SocketSender_ptr mySender) : _mySender(mySender)
 {
   _clientSockfd = -1;
   _senderDestruc=true;
 }
 
-template<class T>
-SocketReceiver<T>::~SocketReceiver()
+template<class T,int (*myFunc)(XDR*,T*)>
+SocketReceiver<T,myFunc>::~SocketReceiver()
 {
   if(_senderDestruc)
     {
@@ -236,17 +237,18 @@ SocketReceiver<T>::~SocketReceiver()
     }
 }
 
-template<class T>
-void *SocketReceiver<T>::getValue(long &size)
+template<class T,int (*myFunc)(XDR*,T*)>
+void *SocketReceiver<T,myFunc>::getValue(long &size)
 {
   return Receiver::getValue(size,_mySender);
 }
 
-template<class T>
-void* SocketReceiver<T>::getDistValue(long &size)
+template<class T,int (*myFunc)(XDR*,T*)>
+void* SocketReceiver<T,myFunc>::getDistValue(long &size)
 {
   int n=0, m;
   T *v;
+  XDR xp; /* pointeur sur le decodeur XDR */
 
   try{
     initCom();
@@ -260,6 +262,7 @@ void* SocketReceiver<T>::getDistValue(long &size)
   
     _mySender->send();
 
+    xdrmem_create(&xp,(char*)v,size*sizeof(T),XDR_DECODE );
     while( n < size*sizeof(T) ){
       m = read(_clientSockfd, (char*)v+n, size*sizeof(T)-n);
       if( m < 0 ){
@@ -272,6 +275,8 @@ void* SocketReceiver<T>::getDistValue(long &size)
       }
       n += m;
     }
+    xdr_vector( &xp, (char*)v, size, sizeof(T), (xdrproc_t)myFunc);
+    xdr_destroy( &xp );
     
     _mySender->endOfCom();
     closeCom();
@@ -290,8 +295,8 @@ void* SocketReceiver<T>::getDistValue(long &size)
   return v;
 }
 
-template<class T>
-void SocketReceiver<T>::initCom()
+template<class T,int (*myFunc)(XDR*,T*)>
+void SocketReceiver<T,myFunc>::initCom()
 {
   try{
     _mySender->initCom();
@@ -319,8 +324,8 @@ void SocketReceiver<T>::initCom()
 
 }
 
-template<class T>
-void SocketReceiver<T>::connectCom(const char *dest_address, int port)
+template<class T,int (*myFunc)(XDR*,T*)>
+void SocketReceiver<T,myFunc>::connectCom(const char *dest_address, int port)
 {
   struct sockaddr_in serv_addr;
   struct hostent * server;
@@ -371,8 +376,8 @@ void SocketReceiver<T>::connectCom(const char *dest_address, int port)
 }
 
 
-template<class T>
-void SocketReceiver<T>::closeCom()
+template<class T,int (*myFunc)(XDR*,T*)>
+void SocketReceiver<T,myFunc>::closeCom()
 {
   _mySender->closeCom();
   if( _clientSockfd >= 0 ){
index 917a32c1a068c1abe5b46ef0b84f2414c2bdd003..4fd2581ee0a9e313f3556882976d78137c130327 100644 (file)
@@ -90,10 +90,13 @@ private:
 #endif
 
 #ifdef HAVE_SOCKET
+
+class XDR;
+
 /*!
   Receiver for transfert with sockets.
  */
-template<class T>
+template<class T,int (*myFunc)(XDR*,T*)>
 class SocketReceiver : public Receiver
 {
 private:
index 74ca7b244b957a501dd55c5b948e96fc31409b7c..00fe36a1138ff32ac9cbe74cea7944a1adef64ef 100644 (file)
@@ -1,3 +1,4 @@
+#include <rpc/xdr.h>
 #include "SALOME_Comm_i.hxx"
 #include "poa.h"
 #include "omnithread.h"
@@ -308,12 +309,13 @@ SALOME::SocketSender::param * SALOME_SocketSender_i::getParam()
 
 void SALOME_SocketSender_i::send()
 {
-  _argsForThr=new (void *)[5];
+  _argsForThr=new void *[6];
   _argsForThr[0]=&_serverSockfd;
   _argsForThr[1]=&_clientSockfd;
   _argsForThr[2]=&_lgrTabToSend;
   _argsForThr[3]=(void *)_tabToSend;
   _argsForThr[4]=&_errorFlag;
+  _argsForThr[5]=&_type;
 
   _newThr=new omni_thread(SALOME_SocketSender_i::myThread,_argsForThr);
   _newThr->start();
@@ -328,23 +330,64 @@ void* SALOME_SocketSender_i::myThread(void *args)
   long *lgrTabToSend=(long *)argsTab[2];
   void *tabToSend=argsTab[3];
   bool *errorFlag=(bool*)argsTab[4];
-
-  *errorFlag = false;
-  while( n < *lgrTabToSend*sizeof(double) ){
-    m = write(*clientSockfd, (char*)tabToSend+n, *lgrTabToSend*sizeof(double)-n);
-    if( m < 0 ){
-      if( *clientSockfd >= 0 ){
-       ::close(*clientSockfd);
-       *clientSockfd = -1;
+  SALOME::TypeOfDataTransmitted *type=(SALOME::TypeOfDataTransmitted *)argsTab[5];
+  
+  XDR xp; /* pointeur sur le decodeur XDR */
+  
+  switch(*type)
+    { 
+    case SALOME::DOUBLE_:
+      xdrmem_create(&xp,(char*)tabToSend,(*lgrTabToSend)*sizeof(double),XDR_ENCODE );
+      xdr_vector( &xp, (char*)tabToSend, *lgrTabToSend, sizeof(double), (xdrproc_t)xdr_double );
+
+      *errorFlag = false;
+      while( n < *lgrTabToSend*sizeof(double) ){
+       m = write(*clientSockfd, (char*)tabToSend+n, *lgrTabToSend*sizeof(double)-n);
+       if( m < 0 ){
+         if( *clientSockfd >= 0 ){
+           ::close(*clientSockfd);
+           *clientSockfd = -1;
+         }
+         if( *serverSockfd >= 0 ){
+           ::close(*serverSockfd);
+           *serverSockfd = -1;
+         }
+         *errorFlag = true;
+       }
+       n += m;
       }
-      if( *serverSockfd >= 0 ){
-       ::close(*serverSockfd);
-       *serverSockfd = -1;
+      xdr_destroy( &xp );
+
+      xdrmem_create(&xp,(char*)tabToSend,(*lgrTabToSend)*sizeof(double),XDR_DECODE );
+      xdr_vector( &xp, (char*)tabToSend, *lgrTabToSend, sizeof(double), (xdrproc_t)xdr_double );
+      xdr_destroy( &xp );
+      break;
+    case SALOME::INT_:
+      xdrmem_create(&xp,(char*)tabToSend,(*lgrTabToSend)*sizeof(int),XDR_ENCODE );
+      xdr_vector( &xp, (char*)tabToSend, *lgrTabToSend, sizeof(int), (xdrproc_t)xdr_int );
+
+      *errorFlag = false;
+      while( n < *lgrTabToSend*sizeof(int) ){
+       m = write(*clientSockfd, (char*)tabToSend+n, *lgrTabToSend*sizeof(int)-n);
+       if( m < 0 ){
+         if( *clientSockfd >= 0 ){
+           ::close(*clientSockfd);
+           *clientSockfd = -1;
+         }
+         if( *serverSockfd >= 0 ){
+           ::close(*serverSockfd);
+           *serverSockfd = -1;
+         }
+         *errorFlag = true;
+       }
+       n += m;
       }
-      *errorFlag = true;
+      xdr_destroy( &xp );
+
+      xdrmem_create(&xp,(char*)tabToSend,(*lgrTabToSend)*sizeof(int),XDR_DECODE );
+      xdr_vector( &xp, (char*)tabToSend, *lgrTabToSend, sizeof(int), (xdrproc_t)xdr_int );
+      xdr_destroy( &xp );
     }
-    n += m;
-  }
 }
 
 void SALOME_SocketSender_i::initCom() throw(SALOME::SALOME_Exception)