Salome HOME
Porting to Mandrake 10.1 and new products:
[modules/kernel.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   SALOME::CorbaLongCSender_ptr _this();
113 };
114
115 #ifdef HAVE_MPI2
116
117 /*! Servant class of sender using MPI2.
118  */
119 class SALOME_MPISender_i : public virtual POA_SALOME::MPISender,
120                            public virtual SALOME_Sender_i
121 {
122 private:
123   static unsigned long _tag1;
124   static unsigned long _tag2;
125   /*! Name of the port opened*/
126   char *_portName;
127   int _cproc;
128   /*! Tag 1 that identifies the transfert*/
129   int _tag1Inst;
130   /*! Tag 2 that identifies the transfert*/
131   int _tag2Inst;
132   /*! MPI communicator*/
133   MPI_Comm _com;
134   /*! Array of pointer for asynchronous invocation with omnithread*/
135   void **_argsForThr;
136   /*! Pointer to thread created on asynchronous invocation*/
137   omni_thread *_newThr;
138   /*! Type the component of the array*/
139   SALOME::TypeOfDataTransmitted _type;
140 public:
141   SALOME_MPISender_i(const void *tabToSend,long lgrTabToSend,int sizeOf,bool ownTabToSend=false);
142   ~SALOME_MPISender_i();
143   SALOME::MPISender::param* getParam();
144   void send();
145   void close(const SALOME::MPISender::param& p);
146 private:
147   static void* myThread(void *args);
148 };
149
150 class SALOME_MPISenderDouble_i : public POA_SALOME::MPISenderDouble,
151                                  public SALOME_SenderDouble_i,
152                                  public SALOME_MPISender_i
153 {
154 public:
155   SALOME_MPISenderDouble_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
156 };
157
158 class SALOME_MPISenderInt_i : public POA_SALOME::MPISenderInt,
159                               public SALOME_SenderInt_i,
160                               public SALOME_MPISender_i
161 {
162 public:
163   SALOME_MPISenderInt_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
164 };
165
166 #endif
167
168 #ifdef HAVE_SOCKET
169
170 /*! Servant class of sender using Sockets.
171  */
172 class SALOME_SocketSender_i : public virtual POA_SALOME::SocketSender,
173                               public virtual SALOME_Sender_i
174 {
175 private:
176   int _serverSockfd;
177   int _clientSockfd;
178   int _port;
179   std::string _IPAddress;
180   void **_argsForThr;
181   omni_thread *_newThr;
182   bool _errorFlag;
183   /*! Type the component of the array*/
184   SALOME::TypeOfDataTransmitted _type;
185 public:
186   SALOME_SocketSender_i(const void *tabToSend,long lgrTabToSend,int sizeOf,bool ownTabToSend=false);
187   ~SALOME_SocketSender_i();
188   SALOME::SocketSender::param* getParam();
189   void send();
190   void initCom() throw(SALOME::SALOME_Exception);
191   void acceptCom() throw(SALOME::SALOME_Exception);
192   void endOfCom();
193   void closeCom();
194 private:
195   static void* myThread(void *args);
196   std::string inetAddress();
197 };
198
199 class SALOME_SocketSenderDouble_i : public POA_SALOME::SocketSenderDouble,
200                                     public SALOME_SenderDouble_i,
201                                     public SALOME_SocketSender_i
202 {
203 public:
204   SALOME_SocketSenderDouble_i(const double *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
205 };
206
207 class SALOME_SocketSenderInt_i : public POA_SALOME::SocketSenderInt,
208                                  public SALOME_SenderInt_i,
209                                  public SALOME_SocketSender_i
210 {
211 public:
212   SALOME_SocketSenderInt_i(const int *tabToSend,long lgrTabToSend,bool ownTabToSend=false);
213 };
214
215 #endif
216
217 #endif
218