Back to index

salome-kernel  6.5.0
ReceiverFactory.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifdef HAVE_MPI2
00024 #include "mpi.h"
00025 #endif
00026 #include "ReceiverFactory.hxx"
00027 #include "Receivers.hxx"
00028 
00029 #ifdef COMP_CORBA_DOUBLE
00030 #define CorbaDNoCopyReceiver CorbaNCNoCopyReceiver
00031 #define CorbaDWithCopyReceiver CorbaNCWithCopyReceiver
00032 #else
00033 #define CorbaDNoCopyReceiver CorbaWCNoCopyReceiver
00034 #define CorbaDWithCopyReceiver CorbaWCWithCopyReceiver
00035 #endif
00036 
00037 #ifdef COMP_CORBA_LONG
00038 #define CorbaINoCopyReceiver CorbaNCNoCopyReceiver
00039 #define CorbaIWithCopyReceiver CorbaNCWithCopyReceiver
00040 #else
00041 #define CorbaINoCopyReceiver CorbaWCNoCopyReceiver
00042 #define CorbaIWithCopyReceiver CorbaWCWithCopyReceiver
00043 #endif
00044 
00045 #ifdef HAVE_SOCKET
00046 #include <rpc/xdr.h>
00047 #endif
00048 
00052 double *ReceiverFactory::getValue(SALOME::SenderDouble_ptr sender,long &size)throw(MultiCommException)
00053 {
00054   double *ret;
00055   try{
00056     ret=getValueOneShot(sender,size);
00057   }
00058   catch(MultiCommException&)
00059     {
00060       SALOME::SenderDouble_ptr newSender=sender->buildOtherWithProtocol(SALOME::CORBA_);
00061       MESSAGE("PROTOCOL CHANGED TO CORBA");
00062       sender->release();
00063       ret=getValueOneShot(newSender,size);
00064       CORBA::release(newSender);
00065     }
00066   return ret;
00067 }
00068 
00072 int *ReceiverFactory::getValue(SALOME::SenderInt_ptr sender,long &size)throw(MultiCommException)
00073 {
00074   int *ret;
00075   try{
00076     ret=getValueOneShot(sender,size);
00077   }
00078   catch(MultiCommException&)
00079     {
00080       SALOME::SenderInt_ptr newSender=sender->buildOtherWithProtocol(SALOME::CORBA_);
00081       MESSAGE("PROTOCOL CHANGED TO CORBA");
00082       sender->release();
00083       ret=getValueOneShot(newSender,size);
00084       CORBA::release(newSender);
00085     }
00086   return ret;
00087 }
00088 
00092 double *ReceiverFactory::getValueOneShot(SALOME::SenderDouble_ptr sender,long &size)throw(MultiCommException)
00093 {
00094   SALOME::CorbaDoubleNCSender_ptr cncD_ptr;
00095   SALOME::CorbaDoubleCSender_ptr cwcD_ptr;
00096 #ifdef HAVE_MPI2
00097   SALOME::MPISenderDouble_ptr mpi_ptr=SALOME::MPISenderDouble::_narrow(sender);
00098 #endif
00099 #ifdef HAVE_SOCKET
00100   SALOME::SocketSenderDouble_ptr sock_ptr=SALOME::SocketSenderDouble::_narrow(sender);
00101 #endif
00102   cncD_ptr=SALOME::CorbaDoubleNCSender::_narrow(sender);
00103   cwcD_ptr=SALOME::CorbaDoubleCSender::_narrow(sender);
00104   if(!CORBA::is_nil(cncD_ptr))
00105     {
00106       CORBA::release(sender);
00107       CorbaDNoCopyReceiver<double,CORBA::Double,SALOME::vectorOfDouble_var,SALOME::CorbaDoubleNCSender_ptr,SALOME::SenderDouble_ptr,SALOME_SenderDouble_i> rec(cncD_ptr);
00108       return rec.getValue(size);
00109     }
00110   else if(!CORBA::is_nil(cwcD_ptr))
00111     {
00112       CORBA::release(sender);
00113       CorbaDWithCopyReceiver<double,CORBA::Double,SALOME::vectorOfDouble_var,SALOME::CorbaDoubleCSender_ptr,SALOME::SenderDouble_ptr,SALOME_SenderDouble_i> rec(cwcD_ptr);
00114       return rec.getValue(size);
00115     }
00116 #ifdef HAVE_MPI2
00117   else if(!CORBA::is_nil(mpi_ptr))
00118     {
00119       CORBA::release(sender);
00120       MPIReceiver<double,SALOME::MPISenderDouble_ptr,SALOME::SenderDouble_ptr,SALOME_SenderDouble_i> rec(mpi_ptr);
00121       return rec.getValue(size);
00122     }
00123 #endif
00124 #ifdef HAVE_SOCKET
00125   else if(!CORBA::is_nil(sock_ptr))
00126     {
00127       CORBA::release(sender);
00128       SocketReceiver<double,xdr_double,SALOME::SocketSenderDouble_ptr,SALOME::SenderDouble_ptr,SALOME_SenderDouble_i> rec(sock_ptr);
00129       return rec.getValue(size);
00130     }
00131 #endif
00132   else
00133     {
00134       throw MultiCommException("Unknown sender protocol");
00135       return 0;
00136     }
00137 }
00138 
00142 int *ReceiverFactory::getValueOneShot(SALOME::SenderInt_ptr sender,long &size)throw(MultiCommException)
00143 {
00144   SALOME::CorbaLongNCSender_ptr cncL_ptr;
00145   SALOME::CorbaLongCSender_ptr cwcL_ptr;
00146 #ifdef HAVE_MPI2
00147   SALOME::MPISenderInt_ptr mpi_ptr=SALOME::MPISenderInt::_narrow(sender);
00148 #endif
00149 #ifdef HAVE_SOCKET
00150   SALOME::SocketSenderInt_ptr sock_ptr=SALOME::SocketSenderInt::_narrow(sender);
00151 #endif
00152   cncL_ptr=SALOME::CorbaLongNCSender::_narrow(sender);
00153   cwcL_ptr=SALOME::CorbaLongCSender::_narrow(sender);
00154   if(!CORBA::is_nil(cncL_ptr))
00155     {
00156       CORBA::release(sender);
00157       CorbaINoCopyReceiver<int,CORBA::Long,SALOME::vectorOfLong_var,SALOME::CorbaLongNCSender_ptr,SALOME::SenderInt_ptr,SALOME_SenderInt_i> rec(cncL_ptr);
00158       return rec.getValue(size);
00159     }
00160   else if(!CORBA::is_nil(cwcL_ptr))
00161     {
00162       CORBA::release(sender);
00163       CorbaIWithCopyReceiver<int,CORBA::Long,SALOME::vectorOfLong_var,SALOME::CorbaLongCSender_ptr,SALOME::SenderInt_ptr,SALOME_SenderInt_i> rec(cwcL_ptr);
00164       return rec.getValue(size);
00165     }
00166 #ifdef HAVE_MPI2
00167   else if(!CORBA::is_nil(mpi_ptr))
00168     {
00169       CORBA::release(sender);
00170       MPIReceiver<int,SALOME::MPISenderInt_ptr,SALOME::SenderInt_ptr,SALOME_SenderInt_i> rec(mpi_ptr);
00171       return rec.getValue(size);
00172     }
00173 #endif
00174 #ifdef HAVE_SOCKET
00175   else if(!CORBA::is_nil(sock_ptr))
00176     {
00177       CORBA::release(sender);
00178       SocketReceiver<int,xdr_int,SALOME::SocketSenderInt_ptr,SALOME::SenderInt_ptr,SALOME_SenderInt_i> rec(sock_ptr);
00179       return rec.getValue(size);
00180     }
00181 #endif
00182   else
00183     {
00184       throw MultiCommException("Unknown sender protocol");
00185       return 0;
00186     }
00187 }
00188