Salome HOME
Base implementation of Notebook
[modules/kernel.git] / src / Communication / SALOME_Comm_i.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef _SALOME_COMM_I_HXX_
23 #define _SALOME_COMM_I_HXX_
24
25 #include "SALOME_Communication.hxx"
26
27 #ifdef HAVE_MPI2
28 #include "mpi.h"
29 #endif
30 #include <string>
31 #include <SALOMEconfig.h>
32 #include CORBA_SERVER_HEADER(SALOME_Comm)
33
34 #define TIMEOUT 20
35
36
37 /*!
38   Generic servant class for senders that factorizes all the common methods and attributes necessary to senders.
39   All servant classes for senders have to inheritate from it.
40  */
41 class COMMUNICATION_EXPORT SALOME_Sender_i : public virtual POA_SALOME::Sender
42 {
43 protected:
44   /*! Pointer to the generic array to transmit*/
45   const void *_tabToSend;
46   /*! Length of the generic array to transmit*/
47   long _lgrTabToSend;
48   /*! it represents the sizeof() of each component of the generic array:\n
49     Practically in terms of bytes the size to be transmitted is _lgrTabToSend*_sizeOf
50   */
51   int _sizeOf;
52   /*! Indicates if _tabToSend has to be deallocated */ 
53   bool _ownTabToSend;
54
55   SALOME_Sender_i(const void *tabToSend,long lgrTabToSend,int sizeOf,bool ownTabToSend=false);
56 public:
57   const void *getData(long &size) const;
58   int getSizeOf() const;
59   void setOwnerShip(bool own);
60   bool getOwnerShip() const { return _ownTabToSend; }
61   void release();
62   virtual ~SALOME_Sender_i() {}
63 };
64
65 class COMMUNICATION_EXPORT SALOME_SenderDouble_i : public virtual POA_SALOME::SenderDouble,
66                               public virtual SALOME_Sender_i
67 {
68 public:
69   SALOME_SenderDouble_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
70   SALOME::TypeOfDataTransmitted getTypeOfDataTransmitted() { return SALOME::DOUBLE_; }
71   SALOME::SenderDouble_ptr buildOtherWithProtocol(SALOME::TypeOfCommunication type);
72   virtual ~SALOME_SenderDouble_i();
73   static SALOME_SenderDouble_i *find(SALOME::SenderDouble_ptr pCorba);
74 };
75
76 class COMMUNICATION_EXPORT SALOME_SenderInt_i : public virtual POA_SALOME::SenderInt,
77                            public virtual SALOME_Sender_i
78 {
79 public:
80   SALOME_SenderInt_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
81   SALOME::TypeOfDataTransmitted getTypeOfDataTransmitted() { return SALOME::INT_; }
82   SALOME::SenderInt_ptr buildOtherWithProtocol(SALOME::TypeOfCommunication type);
83   virtual ~SALOME_SenderInt_i();
84   static SALOME_SenderInt_i *find(SALOME::SenderInt_ptr pCorba);
85 };
86
87 /*! 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.
88  */
89 class COMMUNICATION_EXPORT SALOME_CorbaDoubleNCSender_i : public POA_SALOME::CorbaDoubleNCSender,
90                                      public SALOME_SenderDouble_i
91 {
92 public:
93   SALOME_CorbaDoubleNCSender_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
94   ~SALOME_CorbaDoubleNCSender_i();
95   CORBA::ULong getSize();
96   SALOME::vectorOfDouble* sendPart(CORBA::ULong offset, CORBA::ULong length);
97   SALOME::vectorOfDouble* send();
98 };
99
100 /*! 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.
101  */
102 class COMMUNICATION_EXPORT SALOME_CorbaDoubleCSender_i : public POA_SALOME::CorbaDoubleCSender,
103                                     public SALOME_SenderDouble_i
104 {
105 public:
106   SALOME_CorbaDoubleCSender_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
107   ~SALOME_CorbaDoubleCSender_i();
108   CORBA::ULong getSize();
109   SALOME::vectorOfDouble* sendPart(CORBA::ULong offset, CORBA::ULong length);
110 };
111
112 /*! 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.
113  */
114 class COMMUNICATION_EXPORT SALOME_CorbaLongNCSender_i : public POA_SALOME::CorbaLongNCSender,
115                                    public SALOME_SenderInt_i
116 {
117 public:
118   SALOME_CorbaLongNCSender_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
119   ~SALOME_CorbaLongNCSender_i();
120   CORBA::ULong getSize();
121   SALOME::vectorOfLong* sendPart(CORBA::ULong offset, CORBA::ULong length);
122   SALOME::vectorOfLong* send();
123 };
124
125 /*! 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.
126  */
127 class COMMUNICATION_EXPORT SALOME_CorbaLongCSender_i : public POA_SALOME::CorbaLongCSender,
128                                   public SALOME_SenderInt_i
129 {
130 public:
131   SALOME_CorbaLongCSender_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
132   ~SALOME_CorbaLongCSender_i();
133   CORBA::ULong getSize();
134   SALOME::vectorOfLong* sendPart(CORBA::ULong offset, CORBA::ULong length);
135 #ifndef WIN32
136   SALOME::CorbaLongCSender_ptr _this();
137 #endif
138 };
139
140 #ifdef HAVE_MPI2
141
142 /*! Servant class of sender using MPI2.
143  */
144 class COMMUNICATION_EXPORT SALOME_MPISender_i : public virtual POA_SALOME::MPISender,
145                            public virtual SALOME_Sender_i
146 {
147 private:
148   static unsigned long _tag1;
149   static unsigned long _tag2;
150   /*! Name of the port opened*/
151   char *_portName;
152   int _cproc;
153   /*! Tag 1 that identifies the transfert*/
154   int _tag1Inst;
155   /*! Tag 2 that identifies the transfert*/
156   int _tag2Inst;
157   /*! MPI communicator*/
158   MPI_Comm _com;
159   /*! Array of pointer for asynchronous invocation with omnithread*/
160   void **_argsForThr;
161   /*! Pointer to thread created on asynchronous invocation*/
162   omni_thread *_newThr;
163   /*! Type the component of the array*/
164   SALOME::TypeOfDataTransmitted _type;
165 public:
166   SALOME_MPISender_i(const void *tabToSend,long lgrTabToSend,int sizeOf,bool ownTabToSend=false);
167   ~SALOME_MPISender_i();
168   SALOME::MPISender::param* getParam();
169   void send();
170   void close(const SALOME::MPISender::param& p);
171 private:
172   static void* myThread(void *args);
173 };
174
175 class COMMUNICATION_EXPORT SALOME_MPISenderDouble_i : public POA_SALOME::MPISenderDouble,
176                                  public SALOME_SenderDouble_i,
177                                  public SALOME_MPISender_i
178 {
179 public:
180   SALOME_MPISenderDouble_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
181 };
182
183 class COMMUNICATION_EXPORT SALOME_MPISenderInt_i : public POA_SALOME::MPISenderInt,
184                               public SALOME_SenderInt_i,
185                               public SALOME_MPISender_i
186 {
187 public:
188   SALOME_MPISenderInt_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
189 };
190
191 #endif
192
193 #ifdef HAVE_SOCKET
194
195 /*! Servant class of sender using Sockets.
196  */
197 class COMMUNICATION_EXPORT SALOME_SocketSender_i : public virtual POA_SALOME::SocketSender,
198                               public virtual SALOME_Sender_i
199 {
200 private:
201   int _serverSockfd;
202   int _clientSockfd;
203   int _port;
204   std::string _IPAddress;
205   void **_argsForThr;
206   omni_thread *_newThr;
207   bool _errorFlag;
208   /*! Type the component of the array*/
209   SALOME::TypeOfDataTransmitted _type;
210 public:
211   SALOME_SocketSender_i(const void *tabToSend,long lgrTabToSend,int sizeOf,bool ownTabToSend=false);
212   ~SALOME_SocketSender_i();
213   SALOME::SocketSender::param* getParam();
214   void send();
215   void initCom() throw(SALOME::SALOME_Exception);
216   void acceptCom() throw(SALOME::SALOME_Exception);
217   void endOfCom();
218   void closeCom();
219 private:
220   static void* myThread(void *args);
221   std::string inetAddress();
222 };
223
224 class COMMUNICATION_EXPORT SALOME_SocketSenderDouble_i : public POA_SALOME::SocketSenderDouble,
225                                     public SALOME_SenderDouble_i,
226                                     public SALOME_SocketSender_i
227 {
228 public:
229   SALOME_SocketSenderDouble_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
230 };
231
232 class COMMUNICATION_EXPORT SALOME_SocketSenderInt_i : public POA_SALOME::SocketSenderInt,
233                                  public SALOME_SenderInt_i,
234                                  public SALOME_SocketSender_i
235 {
236 public:
237   SALOME_SocketSenderInt_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
238 };
239
240 #endif
241
242 #endif
243