Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / src / Communication / SenderFactory.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SALOME_Comm_i.hxx"
24 #include "SenderFactory.hxx"
25 #include "utilities.h"
26 #include "SALOMEMultiComm.hxx"
27
28 #ifdef COMP_CORBA_DOUBLE
29 #define SALOME_CorbaDoubleSender SALOME_CorbaDoubleNCSender_i
30 #else
31 #define SALOME_CorbaDoubleSender SALOME_CorbaDoubleCSender_i
32 #endif
33
34 #ifdef COMP_CORBA_LONG
35 #define SALOME_CorbaLongSender SALOME_CorbaLongNCSender_i
36 #else
37 #define SALOME_CorbaLongSender SALOME_CorbaLongCSender_i
38 #endif
39
40 SALOME::SenderDouble_ptr SenderFactory::buildSender(SALOMEMultiComm &multiCommunicator,const double *tab,long lgr,bool ownTab)throw(MultiCommException){
41   switch(multiCommunicator.getProtocol())
42     {
43     case SALOME::CORBA_:
44       {
45         SALOME_CorbaDoubleSender * retc=new SALOME_CorbaDoubleSender(tab,lgr,ownTab);
46         return retc->_this();
47       }
48 #ifdef HAVE_MPI2
49     case SALOME::MPI_:
50       {
51         SALOME_MPISenderDouble_i* retm=new SALOME_MPISenderDouble_i(tab,lgr,ownTab);
52         return retm->_this();
53       }
54 #endif
55 #ifdef HAVE_SOCKET
56     case SALOME::SOCKET_:
57       {
58         SALOME_SocketSenderDouble_i* rets=new SALOME_SocketSenderDouble_i(tab,lgr,ownTab);
59         return rets->_this();
60       }
61 #endif
62     default:
63       {
64         multiCommunicator.setProtocol(SALOME::CORBA_);
65         MESSAGE("PROTOCOL CHANGED TO CORBA");
66         SALOME_CorbaDoubleSender * retc=new SALOME_CorbaDoubleSender(tab,lgr,ownTab);
67         return retc->_this();
68       }
69 //       throw MultiCommException("Communication protocol not implemented");
70     }
71 }
72
73 SALOME::SenderInt_ptr SenderFactory::buildSender(SALOMEMultiComm &multiCommunicator,const int *tab,long lgr,bool ownTab)throw(MultiCommException){
74   switch(multiCommunicator.getProtocol())
75     {
76     case SALOME::CORBA_:
77       {
78         SALOME_CorbaLongSender * retc=new SALOME_CorbaLongSender(tab,lgr,ownTab);
79         return retc->_this();
80       }
81 #ifdef HAVE_MPI2
82     case SALOME::MPI_:
83       {
84         SALOME_MPISenderInt_i* retm=new SALOME_MPISenderInt_i(tab,lgr,ownTab);
85         return retm->_this();
86       }
87 #endif
88 #ifdef HAVE_SOCKET
89     case SALOME::SOCKET_:
90       {
91         SALOME_SocketSenderInt_i* rets=new SALOME_SocketSenderInt_i(tab,lgr,ownTab);
92         return rets->_this();
93       }
94 #endif
95     default:
96       {
97         multiCommunicator.setProtocol(SALOME::CORBA_);
98         SALOME_CorbaLongSender * retc=new SALOME_CorbaLongSender(tab,lgr,ownTab);
99         return retc->_this();
100       }
101 //       throw MultiCommException("Communication protocol not implemented"); 
102     }
103   }
104
105 SALOME::SenderDouble_ptr SenderFactory::buildSender(SALOME::TypeOfCommunication NewType,SALOME_SenderDouble_i *src)
106 {
107   SALOMEMultiComm mc(NewType);
108   long n;
109   const double *data=(const double *)src->getData(n);
110   bool own=src->getOwnerShip();
111   src->setOwnerShip(false);
112   return buildSender(mc,data,n,own);
113 }
114
115 SALOME::SenderInt_ptr SenderFactory::buildSender(SALOME::TypeOfCommunication NewType,SALOME_SenderInt_i *src)
116 {
117   SALOMEMultiComm mc(NewType);
118   long n;
119   const int *data=(const int *)src->getData(n);
120   bool own=src->getOwnerShip();
121   src->setOwnerShip(false);
122   return buildSender(mc,data,n,own);
123 }