]> SALOME platform Git repositories - modules/kernel.git/blob - src/Communication/SALOME_Comm_i.hxx
Salome HOME
e5e0c65ce301c708a94b56ec4be11276de1200f8
[modules/kernel.git] / src / Communication / SALOME_Comm_i.hxx
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 #ifndef _SALOME_COMM_I_HXX_
21 #define _SALOME_COMM_I_HXX_
22
23 #ifdef HAVE_MPI2
24 #include "mpi.h"
25 #endif
26 #include <string>
27 #include <SALOMEconfig.h>
28 #include CORBA_SERVER_HEADER(SALOME_Comm)
29
30 #define TIMEOUT 20
31
32
33 /*!
34   Generic servant class for senders that factorizes all the common methods and attributes necessary to senders.
35   All servant classes for senders have to inheritate from it.
36  */
37 class SALOME_Sender_i : public virtual POA_SALOME::Sender,
38                         public PortableServer::RefCountServantBase {
39 protected:
40   /*! Pointer to the generic array to transmit*/
41   const void *_tabToSend;
42   /*! Length of the generic array to transmit*/
43   long _lgrTabToSend;
44   /*! it represents the sizeof() of each component of the generic array:\n
45     Practically in terms of bytes the size to be transmitted is _lgrTabToSend*_sizeOf
46   */
47   int _sizeOf;
48   /*! Indicates if _tabToSend has to be deallocated */ 
49   bool _ownTabToSend;
50
51   SALOME_Sender_i(const void *tabToSend,long lgrTabToSend,int sizeOf,bool ownTabToSend=false);
52 public:
53   const void *getData(long &size) const;
54   int getSizeOf() const;
55   void setOwnerShip(bool own);
56   bool getOwnerShip() const { return _ownTabToSend; }
57   void release();
58   virtual ~SALOME_Sender_i() {}
59 };
60
61 class SALOME_SenderDouble_i : public virtual POA_SALOME::SenderDouble,
62                               public virtual SALOME_Sender_i
63 {
64 public:
65   SALOME_SenderDouble_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
66   SALOME::TypeOfDataTransmitted getTypeOfDataTransmitted() { return SALOME::DOUBLE_; }
67   SALOME::SenderDouble_ptr buildOtherWithProtocol(SALOME::TypeOfCommunication type);
68   virtual ~SALOME_SenderDouble_i();
69   static SALOME_SenderDouble_i *find(SALOME::SenderDouble_ptr pCorba);
70 };
71
72 class SALOME_SenderInt_i : public virtual POA_SALOME::SenderInt,
73                            public virtual SALOME_Sender_i
74 {
75 public:
76   SALOME_SenderInt_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
77   SALOME::TypeOfDataTransmitted getTypeOfDataTransmitted() { return SALOME::INT_; }
78   SALOME::SenderInt_ptr buildOtherWithProtocol(SALOME::TypeOfCommunication type);
79   virtual ~SALOME_SenderInt_i();
80   static SALOME_SenderInt_i *find(SALOME::SenderInt_ptr pCorba);
81 };
82
83 /*! Servant class for CORBA sender for double* when no copy of array _tabToSend is required, that is to say double and CORBA::Double are binary equal.
84  */
85 class SALOME_CorbaDoubleNCSender_i : public POA_SALOME::CorbaDoubleNCSender,
86                                      public SALOME_SenderDouble_i
87 {
88 public:
89   SALOME_CorbaDoubleNCSender_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
90   ~SALOME_CorbaDoubleNCSender_i();
91   CORBA::ULong getSize();
92   SALOME::vectorOfDouble* sendPart(CORBA::ULong offset, CORBA::ULong length);
93   SALOME::vectorOfDouble* send();
94 };
95
96 /*! Servant class for CORBA sender for double* when copy of array _tabToSend is required, that is to say double and CORBA::Double are NOT binary equal.
97  */
98 class SALOME_CorbaDoubleCSender_i : public POA_SALOME::CorbaDoubleCSender,
99                                     public SALOME_SenderDouble_i
100 {
101 public:
102   SALOME_CorbaDoubleCSender_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
103   ~SALOME_CorbaDoubleCSender_i();
104   CORBA::ULong getSize();
105   SALOME::vectorOfDouble* sendPart(CORBA::ULong offset, CORBA::ULong length);
106 };
107
108 /*! Servant class for CORBA sender for int* when no copy of array _tabToSend is required, that is to say int and CORBA::Long are binary equal.
109  */
110 class SALOME_CorbaLongNCSender_i : public POA_SALOME::CorbaLongNCSender,
111                                    public SALOME_SenderInt_i
112 {
113 public:
114   SALOME_CorbaLongNCSender_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
115   ~SALOME_CorbaLongNCSender_i();
116   CORBA::ULong getSize();
117   SALOME::vectorOfLong* sendPart(CORBA::ULong offset, CORBA::ULong length);
118   SALOME::vectorOfLong* send();
119 };
120
121 /*! Servant class for CORBA sender for int* when copy of array _tabToSend is required, that is to say int and CORBA::Long are NOT binary equal.
122  */
123 class SALOME_CorbaLongCSender_i : public POA_SALOME::CorbaLongCSender,
124                                   public SALOME_SenderInt_i
125 {
126 public:
127   SALOME_CorbaLongCSender_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
128   ~SALOME_CorbaLongCSender_i();
129   CORBA::ULong getSize();
130   SALOME::vectorOfLong* sendPart(CORBA::ULong offset, CORBA::ULong length);
131 #ifndef WNT
132   SALOME::CorbaLongCSender_ptr _this();
133 #endif
134 };
135
136 #ifdef HAVE_MPI2
137
138 /*! Servant class of sender using MPI2.
139  */
140 class SALOME_MPISender_i : public virtual POA_SALOME::MPISender,
141                            public virtual SALOME_Sender_i
142 {
143 private:
144   static unsigned long _tag1;
145   static unsigned long _tag2;
146   /*! Name of the port opened*/
147   char *_portName;
148   int _cproc;
149   /*! Tag 1 that identifies the transfert*/
150   int _tag1Inst;
151   /*! Tag 2 that identifies the transfert*/
152   int _tag2Inst;
153   /*! MPI communicator*/
154   MPI_Comm _com;
155   /*! Array of pointer for asynchronous invocation with omnithread*/
156   void **_argsForThr;
157   /*! Pointer to thread created on asynchronous invocation*/
158   omni_thread *_newThr;
159   /*! Type the component of the array*/
160   SALOME::TypeOfDataTransmitted _type;
161 public:
162   SALOME_MPISender_i(const void *tabToSend,long lgrTabToSend,int sizeOf,bool ownTabToSend=false);
163   ~SALOME_MPISender_i();
164   SALOME::MPISender::param* getParam();
165   void send();
166   void close(const SALOME::MPISender::param& p);
167 private:
168   static void* myThread(void *args);
169 };
170
171 class SALOME_MPISenderDouble_i : public POA_SALOME::MPISenderDouble,
172                                  public SALOME_SenderDouble_i,
173                                  public SALOME_MPISender_i
174 {
175 public:
176   SALOME_MPISenderDouble_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
177 };
178
179 class SALOME_MPISenderInt_i : public POA_SALOME::MPISenderInt,
180                               public SALOME_SenderInt_i,
181                               public SALOME_MPISender_i
182 {
183 public:
184   SALOME_MPISenderInt_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
185 };
186
187 #endif
188
189 #ifdef HAVE_SOCKET
190
191 /*! Servant class of sender using Sockets.
192  */
193 class SALOME_SocketSender_i : public virtual POA_SALOME::SocketSender,
194                               public virtual SALOME_Sender_i
195 {
196 private:
197   int _serverSockfd;
198   int _clientSockfd;
199   int _port;
200   std::string _IPAddress;
201   void **_argsForThr;
202   omni_thread *_newThr;
203   bool _errorFlag;
204   /*! Type the component of the array*/
205   SALOME::TypeOfDataTransmitted _type;
206 public:
207   SALOME_SocketSender_i(const void *tabToSend,long lgrTabToSend,int sizeOf,bool ownTabToSend=false);
208   ~SALOME_SocketSender_i();
209   SALOME::SocketSender::param* getParam();
210   void send();
211   void initCom() throw(SALOME::SALOME_Exception);
212   void acceptCom() throw(SALOME::SALOME_Exception);
213   void endOfCom();
214   void closeCom();
215 private:
216   static void* myThread(void *args);
217   std::string inetAddress();
218 };
219
220 class SALOME_SocketSenderDouble_i : public POA_SALOME::SocketSenderDouble,
221                                     public SALOME_SenderDouble_i,
222                                     public SALOME_SocketSender_i
223 {
224 public:
225   SALOME_SocketSenderDouble_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
226 };
227
228 class SALOME_SocketSenderInt_i : public POA_SALOME::SocketSenderInt,
229                                  public SALOME_SenderInt_i,
230                                  public SALOME_SocketSender_i
231 {
232 public:
233   SALOME_SocketSenderInt_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
234 };
235
236 #endif
237
238 #endif
239