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