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