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