Salome HOME
PR: mergefrom_BR_GEAY_05Nov04
[modules/kernel.git] / src / Communication / SenderFactory.cxx
1 #include "SenderFactory.hxx"
2 #include "utilities.h"
3 #include "SALOMEMultiComm.hxx"
4 #include "SALOME_Comm_i.hxx"
5
6 #ifdef COMP_CORBA_DOUBLE
7 #define SALOME_CorbaDoubleSender SALOME_CorbaDoubleNCSender_i
8 #else
9 #define SALOME_CorbaDoubleSender SALOME_CorbaDoubleCSender_i
10 #endif
11
12 #ifdef COMP_CORBA_LONG
13 #define SALOME_CorbaLongSender SALOME_CorbaLongNCSender_i
14 #else
15 #define SALOME_CorbaLongSender SALOME_CorbaLongCSender_i
16 #endif
17
18 SALOME::Sender_ptr SenderFactory::buildSender(SALOMEMultiComm &multiCommunicator,const double *tab,long lgr)throw(MultiCommException){
19   switch(multiCommunicator.getProtocol())
20     {
21     case SALOME::CORBA_:
22       {
23         SALOME_CorbaDoubleSender * retc=new SALOME_CorbaDoubleSender(tab,lgr);
24         return retc->_this();
25       }
26 #ifdef HAVE_MPI2
27     case SALOME::MPI_:
28       {
29         SALOME_MPISender_i* retm=new SALOME_MPISender_i(SALOME::DOUBLE_,tab,lgr,sizeof(double));
30         return retm->_this();
31       }
32 #endif
33 #ifdef HAVE_SOCKET
34     case SALOME::SOCKET_:
35       {
36         SALOME_SocketSender_i* rets=new SALOME_SocketSender_i(SALOME::DOUBLE_,tab,lgr,sizeof(double));
37         return rets->_this();
38       }
39 #endif
40     default:
41       {
42         multiCommunicator.setProtocol(SALOME::CORBA_);
43         MESSAGE("PROTOCOL CHANGED TO CORBA");
44         SALOME_CorbaDoubleSender * retc=new SALOME_CorbaDoubleSender(tab,lgr);
45         return retc->_this();
46       }
47 //       throw MultiCommException("Communication protocol not implemented");
48     }
49 }
50
51 SALOME::Sender_ptr SenderFactory::buildSender(SALOMEMultiComm &multiCommunicator,const int *tab,long lgr)throw(MultiCommException){
52   switch(multiCommunicator.getProtocol())
53     {
54     case SALOME::CORBA_:
55       {
56         SALOME_CorbaLongSender * retc=new SALOME_CorbaLongSender(tab,lgr);
57         return retc->_this();
58       }
59 #ifdef HAVE_MPI2
60     case SALOME::MPI_:
61       {
62         SALOME_MPISender_i* retm=new SALOME_MPISender_i(SALOME::INT_,tab,lgr,sizeof(int));
63         return retm->_this();
64       }
65 #endif
66 #ifdef HAVE_SOCKET
67     case SALOME::SOCKET_:
68       {
69         SALOME_SocketSender_i* rets=new SALOME_SocketSender_i(SALOME::INT_,tab,lgr,sizeof(int));
70         return rets->_this();
71       }
72 #endif
73     default:
74       {
75         multiCommunicator.setProtocol(SALOME::CORBA_);
76         SALOME_CorbaLongSender * retc=new SALOME_CorbaLongSender(tab,lgr);
77         return retc->_this();
78       }
79 //       throw MultiCommException("Communication protocol not implemented"); 
80     }
81   }
82
83 SALOME::Sender_ptr SenderFactory::buildSender(SALOME::TypeOfCommunication NewType,SALOME_Sender_i *src)
84 {
85   SALOMEMultiComm mc(NewType);
86   long n;
87   const void *data=src->getData(n);
88   switch(src->getTypeOfDataTransmitted())
89     {
90     case SALOME::DOUBLE_:
91       return buildSender(mc,(const double *)data,n);
92     case SALOME::INT_:
93       return buildSender(mc,(const int *)data,n);
94     }
95   
96 }
97
98