]> SALOME platform Git repositories - modules/kernel.git/blob - src/Communication/ReceiverFactory.cxx
Salome HOME
PR: mergefrom_BR_GEAY_05Nov04
[modules/kernel.git] / src / Communication / ReceiverFactory.cxx
1 #include "ReceiverFactory.hxx"
2 #include "Receivers.hxx"
3
4 #ifdef COMP_CORBA_DOUBLE
5 #define CorbaDNoCopyReceiver CorbaNCNoCopyReceiver
6 #define CorbaDWithCopyReceiver CorbaNCWithCopyReceiver
7 #else
8 #define CorbaDNoCopyReceiver CorbaWCNoCopyReceiver
9 #define CorbaDWithCopyReceiver CorbaWCWithCopyReceiver
10 #endif
11
12 #ifdef COMP_CORBA_LONG
13 #define CorbaINoCopyReceiver CorbaNCNoCopyReceiver
14 #define CorbaIWithCopyReceiver CorbaNCWithCopyReceiver
15 #else
16 #define CorbaINoCopyReceiver CorbaWCNoCopyReceiver
17 #define CorbaIWithCopyReceiver CorbaWCWithCopyReceiver
18 #endif
19
20 #ifdef HAVE_SOCKET
21 #include <rpc/xdr.h>
22 #endif
23
24 /*!
25   This method performs the transfert with the remote sender given. If it fails with this sender it tries with an another protocol (CORBA by default).
26  */
27 void *ReceiverFactory::getValue(SALOME::Sender_ptr sender,long &size)throw(MultiCommException)
28 {
29   void *ret;
30   try{
31     ret=getValueOneShot(sender,size);
32   }
33   catch(MultiCommException&)
34     {
35       SALOME::Sender_ptr newSender=sender->buildOtherWithProtocol(SALOME::CORBA_);
36       MESSAGE("PROTOCOL CHANGED TO CORBA");
37       sender->release();
38       CORBA::release(sender);
39       ret=getValueOneShot(newSender,size);
40     }
41   return ret;
42 }
43
44 /*!
45   This method performs the transfert with the remote sender given. If it fails an exception is thrown.
46  */
47 void *ReceiverFactory::getValueOneShot(SALOME::Sender_ptr sender,long &size)throw(MultiCommException)
48 {
49   SALOME::CorbaDoubleNCSender_ptr cncD_ptr;
50   SALOME::CorbaDoubleCSender_ptr cwcD_ptr;
51   SALOME::CorbaLongNCSender_ptr cncL_ptr;
52   SALOME::CorbaLongCSender_ptr cwcL_ptr;
53 #ifdef HAVE_MPI2
54   SALOME::MPISender_ptr mpi_ptr=SALOME::MPISender::_narrow(sender);
55 #endif
56 #ifdef HAVE_SOCKET
57   SALOME::SocketSender_ptr sock_ptr=SALOME::SocketSender::_narrow(sender);
58 #endif
59  switch(sender->getTypeOfDataTransmitted())
60     {
61     case SALOME::DOUBLE_:
62       cncD_ptr=SALOME::CorbaDoubleNCSender::_narrow(sender);
63       cwcD_ptr=SALOME::CorbaDoubleCSender::_narrow(sender);
64       if(!CORBA::is_nil(cncD_ptr))
65         {
66           CORBA::release(sender);
67           CorbaDNoCopyReceiver<double,CORBA::Double,SALOME::vectorOfDouble_var,SALOME::CorbaDoubleNCSender_ptr> rec(cncD_ptr);
68           return rec.getValue(size);
69         }
70       else if(!CORBA::is_nil(cwcD_ptr))
71         {
72           CORBA::release(sender);
73           CorbaDWithCopyReceiver<double,CORBA::Double,SALOME::vectorOfDouble_var,SALOME::CorbaDoubleCSender_ptr> rec(cwcD_ptr);
74           return rec.getValue(size);
75         }
76 #ifdef HAVE_MPI2
77       else if(!CORBA::is_nil(mpi_ptr))
78         {
79           CORBA::release(sender);
80           MPIReceiver<double,MPI_DOUBLE> rec(mpi_ptr);
81           return rec.getValue(size);
82         }
83 #endif
84 #ifdef HAVE_SOCKET
85       else if(!CORBA::is_nil(sock_ptr))
86         {
87           CORBA::release(sender);
88           SocketReceiver<double,xdr_double> rec(sock_ptr);
89           return rec.getValue(size);
90         }
91 #endif
92       else
93         {
94           throw MultiCommException("Unknown sender protocol");
95           return 0;
96         }
97     case SALOME::INT_:
98       cncL_ptr=SALOME::CorbaLongNCSender::_narrow(sender);
99       cwcL_ptr=SALOME::CorbaLongCSender::_narrow(sender);
100       if(!CORBA::is_nil(cncL_ptr))
101         {
102           CORBA::release(sender);
103           CorbaINoCopyReceiver<int,CORBA::Long,SALOME::vectorOfLong_var,SALOME::CorbaLongNCSender_ptr> rec(cncL_ptr);
104           return rec.getValue(size);
105         }
106       else if(!CORBA::is_nil(cwcL_ptr))
107         {
108           CORBA::release(sender);
109           CorbaIWithCopyReceiver<int,CORBA::Long,SALOME::vectorOfLong_var,SALOME::CorbaLongCSender_ptr> rec(cwcL_ptr);
110           return rec.getValue(size);
111         }
112 #ifdef HAVE_MPI2
113       else if(!CORBA::is_nil(mpi_ptr))
114         {
115           CORBA::release(sender);
116           MPIReceiver<int,MPI_INT> rec(mpi_ptr);
117           return rec.getValue(size);
118         }
119 #endif
120 #ifdef HAVE_SOCKET
121       else if(!CORBA::is_nil(sock_ptr))
122         {
123           CORBA::release(sender);
124           SocketReceiver<int,xdr_int> rec(sock_ptr);
125           return rec.getValue(size);
126         }
127 #endif
128       else
129         {
130           throw MultiCommException("Unknown sender protocol");
131           return 0;
132         }
133     default:
134       throw MultiCommException("unknown type of data transfered");
135       return 0;
136     }
137 }
138