Salome HOME
PR: mergefrom_BR_GEAY_05Nov04
[modules/kernel.git] / src / Communication / SALOME_Comm_i.hxx
1 #ifndef _SALOME_COMM_I_HXX_
2 #define _SALOME_COMM_I_HXX_
3
4 #include <set.h>
5 #include <string>
6 #include <SALOMEconfig.h>
7 #include CORBA_SERVER_HEADER(SALOME_Comm)
8 #ifdef HAVE_MPI2
9 #include "mpi.h"
10 #endif
11
12 #define TIMEOUT 20
13
14 using namespace std;
15
16 /*!
17   Generic servant class for senders that factorizes all the common methods and attributes necessary to senders.
18   All servant classes for senders have to inheritate from it.
19  */
20 class SALOME_Sender_i : public virtual POA_SALOME::Sender,
21                         public PortableServer::RefCountServantBase {
22 protected:
23   /*! Pointer to the generic array to transmit*/
24   const void *_tabToSend;
25   /*! Length of the generic array to transmit*/
26   long _lgrTabToSend;
27   /*! it represents the sizeof() of each component of the generic array:\n
28     Practically in terms of bytes the size to be transmitted is _lgrTabToSend*_sizeOf
29   */
30   int _sizeOf;
31   /*! Type the component of the array*/
32   SALOME::TypeOfDataTransmitted _type;
33
34   SALOME_Sender_i(SALOME::TypeOfDataTransmitted type,const void *tabToSend,long lgrTabToSend,int sizeOf);
35 public:
36   const void *getData(long &size) const;
37   int getSizeOf() const;
38   void release();
39   SALOME::TypeOfDataTransmitted getTypeOfDataTransmitted();
40   SALOME::Sender_ptr buildOtherWithProtocol(SALOME::TypeOfCommunication type);
41   static SALOME_Sender_i *find(SALOME::Sender_ptr pCorba);
42 };
43
44 /*! 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.
45  */
46 class SALOME_CorbaDoubleNCSender_i : public POA_SALOME::CorbaDoubleNCSender,
47                                      public SALOME_Sender_i
48 {
49 public:
50   SALOME_CorbaDoubleNCSender_i(const double *tabToSend,long lgrTabToSend);
51   ~SALOME_CorbaDoubleNCSender_i();
52   CORBA::ULong getSize();
53   SALOME::vectorOfDouble* sendPart(CORBA::ULong offset, CORBA::ULong length);
54   SALOME::vectorOfDouble* send();
55 };
56
57 /*! 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.
58  */
59 class SALOME_CorbaDoubleCSender_i : public POA_SALOME::CorbaDoubleCSender,
60                                     public SALOME_Sender_i
61 {
62 public:
63   SALOME_CorbaDoubleCSender_i(const double *tabToSend,const long lgrTabToSend);
64   ~SALOME_CorbaDoubleCSender_i();
65   CORBA::ULong getSize();
66   SALOME::vectorOfDouble* sendPart(CORBA::ULong offset, CORBA::ULong length);
67 };
68
69 /*! 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.
70  */
71 class SALOME_CorbaLongNCSender_i : public POA_SALOME::CorbaLongNCSender,
72                                    public SALOME_Sender_i
73 {
74 public:
75   SALOME_CorbaLongNCSender_i(const int *tabToSend,const long lgrTabToSend);
76   ~SALOME_CorbaLongNCSender_i();
77   CORBA::ULong getSize();
78   SALOME::vectorOfLong* sendPart(CORBA::ULong offset, CORBA::ULong length);
79   SALOME::vectorOfLong* send();
80 };
81
82 /*! 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.
83  */
84 class SALOME_CorbaLongCSender_i : public POA_SALOME::CorbaLongCSender,
85                                   public SALOME_Sender_i
86 {
87 public:
88   SALOME_CorbaLongCSender_i(const int *tabToSend,long lgrTabToSend);
89   ~SALOME_CorbaLongCSender_i();
90   CORBA::ULong getSize();
91   SALOME::vectorOfLong* sendPart(CORBA::ULong offset, CORBA::ULong length);
92   SALOME::CorbaLongCSender_ptr _this();
93 };
94
95 #ifdef HAVE_MPI2
96
97 /*! Servant class of sender using MPI2.
98  */
99 class SALOME_MPISender_i : public POA_SALOME::MPISender,
100                            public SALOME_Sender_i
101 {
102 private:
103   static unsigned long _tag1;
104   static unsigned long _tag2;
105   /*! Name of the port opened*/
106   char *_portName;
107   int _cproc;
108   /*! Tag 1 that identifies the transfert*/
109   int _tag1Inst;
110   /*! Tag 2 that identifies the transfert*/
111   int _tag2Inst;
112   /*! MPI communicator*/
113   MPI_Comm _com;
114   /*! Array of pointer for asynchronous invocation with omnithread*/
115   void **_argsForThr;
116   /*! Pointer to thread created on asynchronous invocation*/
117   omni_thread *_newThr;
118 public:
119   SALOME_MPISender_i(SALOME::TypeOfDataTransmitted type,const void *tabToSend,long lgrTabToSend,int sizeOf);
120   ~SALOME_MPISender_i();
121   SALOME::MPISender::param* getParam();
122   void send();
123   void close(const SALOME::MPISender::param& p);
124 private:
125   static void* myThread(void *args);
126 };
127
128 #endif
129
130 #ifdef HAVE_SOCKET
131
132 /*! Servant class of sender using Sockets.
133  */
134 class SALOME_SocketSender_i : public POA_SALOME::SocketSender,
135                               public SALOME_Sender_i
136 {
137 private:
138   int _serverSockfd;
139   int _clientSockfd;
140   int _port;
141   std::string _IPAddress;
142   void **_argsForThr;
143   omni_thread *_newThr;
144   bool _errorFlag;
145 public:
146   SALOME_SocketSender_i(SALOME::TypeOfDataTransmitted type,const void *tabToSend,long lgrTabToSend,int sizeOf);
147   ~SALOME_SocketSender_i();
148   SALOME::SocketSender::param* getParam();
149   void send();
150   void initCom() throw(SALOME::SALOME_Exception);
151   void acceptCom() throw(SALOME::SALOME_Exception);
152   void endOfCom();
153   void closeCom();
154 private:
155   static void* myThread(void *args);
156   std::string inetAddress();
157 };
158
159 #endif
160
161 #endif
162