Salome HOME
Merge from V7_2_BR 09/08/2013
[modules/kernel.git] / src / Communication / Receivers.cxx
index f97b4a1a4bf52918dbadcc45ad3bd9b71130e91c..3d1aea2a32a95cda53dcef279c359d5419948c5f 100644 (file)
@@ -1,25 +1,27 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
+//
 // This library 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 
+// License as published by the Free Software Foundation; either
 // version 2.1 of the License.
-// 
-// This library 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 
+//
+// This library 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 library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-#include "poa.h"
+
+#include "omniORB4/poa.h"
 #include "utilities.h"
-using namespace std;
 
 #define TAILLE_SPLIT 100000
 #define TIMEOUT 20
@@ -65,13 +67,13 @@ T *CorbaNCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender,servForT,ptrForT>::get
   for(long i=0;i<size;i+=TAILLE_SPLIT)
     {
       if(size-i>TAILLE_SPLIT)
-       n=TAILLE_SPLIT;
+        n=TAILLE_SPLIT;
       else
-       n=size-i;
+        n=size-i;
       TSeqCorba seq=_mySender->sendPart(i,n);
       T *seqd=(T *)seq->get_buffer(0);
       for(long j=0;j<n;j++)
-       *iter++=*seqd++;
+        *iter++=*seqd++;
     }
   return ret;
 }
@@ -100,13 +102,13 @@ T *CorbaWCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender,servForT,ptrForT>::getDi
   for(long i=0;i<size;i+=TAILLE_SPLIT)
     {
       if(size-i>TAILLE_SPLIT)
-       n=TAILLE_SPLIT;
+        n=TAILLE_SPLIT;
       else
-       n=size-i;
+        n=size-i;
       TSeqCorba seq=_mySender->sendPart(i,n);
       TCorba *seqd=seq->get_buffer(0);
       for(long j=0;j<n;j++)
-       *iter++=*seqd++;
+        *iter++=*seqd++;
     }
   return ret;
 }
@@ -135,9 +137,9 @@ T *CorbaWCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender,servForT,ptrForT>::get
   for(long i=0;i<size;i+=TAILLE_SPLIT)
     {
       if(size-i>TAILLE_SPLIT)
-       n=TAILLE_SPLIT;
+        n=TAILLE_SPLIT;
       else
-       n=size-i;
+        n=size-i;
       TSeqCorba seq=_mySender->sendPart(i,n);
       TCorba *seqd=seq->get_buffer(0);
       for(long j=0;j<n;j++)
@@ -154,24 +156,23 @@ T *CorbaWCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender,servForT,ptrForT>::get
 
 #ifdef HAVE_MPI2
 
-template<class T,MPI_Datatype T2,class CorbaSender,class servForT,class ptrForT>
-MPIReceiver<T,T2,CorbaSender,servForT,ptrForT>::MPIReceiver(CorbaSender mySender):_mySender(mySender){
+template<class T,class CorbaSender,class servForT,class ptrForT>
+MPIReceiver<T,CorbaSender,servForT,ptrForT>::MPIReceiver(CorbaSender mySender):_mySender(mySender){
 }
 
-template<class T,MPI_Datatype T2,class CorbaSender,class servForT,class ptrForT>
-MPIReceiver<T,T2,CorbaSender,servForT,ptrForT>::~MPIReceiver(){
+template<class T,class CorbaSender,class servForT,class ptrForT>
+MPIReceiver<T,CorbaSender,servForT,ptrForT>::~MPIReceiver(){
   _mySender->release();
 }
 
-template<class T,MPI_Datatype T2,class CorbaSender,class servForT,class ptrForT>
-T *MPIReceiver<T,T2,CorbaSender,servForT,ptrForT>::getDistValue(long &size){
+template<class T,class CorbaSender,class servForT,class ptrForT>
+T *MPIReceiver<T,CorbaSender,servForT,ptrForT>::getDistValue(long &size){
   int i=0;
   int myproc;
   int sproc;
   MPI_Status status;
   MPI_Comm com; 
   char   port_name_clt [MPI_MAX_PORT_NAME];
-  float telps, tuser, tsys, tcpu;
   T *_v;
   long _n;
 
@@ -193,8 +194,8 @@ T *MPIReceiver<T,T2,CorbaSender,servForT,ptrForT>::getDistValue(long &size){
   else{
     //       Connect to service, get the inter-communicator server
     //      Attention MPI_Comm_connect est un appel collectif :
-    //         - Si lancement mpirun -c n -----> uniquement     MPI_COMM_SELF fonctionne
-    //         - Si lancement client_server&client_server ----> MPI_COMM_WORLD fonctionne
+    //  - Si lancement mpirun -c n -----> uniquement     MPI_COMM_SELF fonctionne
+    //  - Si lancement client_server&client_server ----> MPI_COMM_WORLD fonctionne
     
     //      TIMEOUT is inefficient since MPI_Comm_Connect doesn't return if we asked for
     //        a service that has been unpublished !
@@ -211,15 +212,15 @@ T *MPIReceiver<T,T2,CorbaSender,servForT,ptrForT>::getDistValue(long &size){
   }
   MPI_Recv( &_n, 1, MPI_LONG, sproc,p->tag1,com,&status);
   _v = new T[_n];
-  MPI_Recv( _v, _n, T2, sproc,p->tag2,com,&status);
+  MPI_Recv( _v, _n, MPITRAITS<T>::MpiType, sproc,p->tag2,com,&status);
   _mySender->close(p);
   MPI_Comm_disconnect( &com );  
   size=_n;
   return _v;
 }
 
-template<class T,MPI_Datatype T2,class CorbaSender,class servForT,class ptrForT>
-T *MPIReceiver<T,T2,CorbaSender,servForT,ptrForT>::getValue(long &size)
+template<class T,class CorbaSender,class servForT,class ptrForT>
+T *MPIReceiver<T,CorbaSender,servForT,ptrForT>::getValue(long &size)
 {
   return Receiver<T,servForT,ptrForT>::getValue(size,_mySender);
 }
@@ -280,12 +281,12 @@ T* SocketReceiver<T,myFunc,CorbaSender,servForT,ptrForT>::getDistValue(long &siz
     while( n < size*sizeof(T) ){
       m = read(_clientSockfd, (char*)v+n, size*sizeof(T)-n);
       if( m < 0 ){
-       closeCom();
-       delete [] v;
-       SALOME::ExceptionStruct es;
-       es.type = SALOME::COMM;
-       es.text = "error read Socket exception";
-       throw SALOME::SALOME_Exception(es);
+        closeCom();
+        delete [] v;
+        SALOME::ExceptionStruct es;
+        es.type = SALOME::COMM;
+        es.text = "error read Socket exception";
+        throw SALOME::SALOME_Exception(es);
       }
       n += m;
     }
@@ -298,9 +299,9 @@ T* SocketReceiver<T,myFunc,CorbaSender,servForT,ptrForT>::getDistValue(long &siz
   catch(SALOME::SALOME_Exception &ex){
     if( ex.details.type == SALOME::COMM )
       {
-       _senderDestruc=false;
-       cout << ex.details.text << endl;
-       throw MultiCommException("Unknown sender protocol");
+        _senderDestruc=false;
+               std::cout << ex.details.text << std::endl;
+        throw MultiCommException("Unknown sender protocol");
       }
     else
       throw ex;
@@ -328,9 +329,9 @@ void SocketReceiver<T,myFunc,CorbaSender,servForT,ptrForT>::initCom()
   catch(SALOME::SALOME_Exception &ex){
     if( ex.details.type == SALOME::COMM )
       {
-       _senderDestruc=false;
-       cout << ex.details.text << endl;
-       throw MultiCommException("Unknown sender protocol");
+        _senderDestruc=false;
+               std::cout << ex.details.text << std::endl;
+        throw MultiCommException("Unknown sender protocol");
       }
     else
       throw ex;
@@ -361,8 +362,8 @@ void SocketReceiver<T,myFunc,CorbaSender,servForT,ptrForT>::connectCom(const cha
     serv_addr.sin_family = AF_INET;
     serv_addr.sin_addr.s_addr = INADDR_ANY;
     bcopy((char *)server->h_addr, 
-         (char *)&serv_addr.sin_addr.s_addr,
-         server->h_length);
+          (char *)&serv_addr.sin_addr.s_addr,
+          server->h_length);
     serv_addr.sin_port = htons(port);
     
     if( connect(_clientSockfd, (struct sockaddr *) & serv_addr, sizeof(struct sockaddr)) < 0 ){
@@ -379,9 +380,9 @@ void SocketReceiver<T,myFunc,CorbaSender,servForT,ptrForT>::connectCom(const cha
   catch(SALOME::SALOME_Exception &ex){
     if( ex.details.type == SALOME::COMM )
       {
-       _senderDestruc=false;
-       cout << ex.details.text << endl;
-       throw MultiCommException("Unknown sender protocol");
+        _senderDestruc=false;
+        std::cout << ex.details.text << std::endl;
+        throw MultiCommException("Unknown sender protocol");
       }
     else
       throw ex;