Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[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   /*! Type the component of the array*/
30   SALOME::TypeOfDataTransmitted _type;
31
32   SALOME_Sender_i(SALOME::TypeOfDataTransmitted type,const void *tabToSend,long lgrTabToSend,int sizeOf);
33 public:
34   const void *getData(long &size) const;
35   int getSizeOf() const;
36   void release();
37   SALOME::TypeOfDataTransmitted getTypeOfDataTransmitted();
38   SALOME::Sender_ptr buildOtherWithProtocol(SALOME::TypeOfCommunication type);
39   static SALOME_Sender_i *find(SALOME::Sender_ptr pCorba);
40 };
41
42 /*! 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.
43  */
44 class SALOME_CorbaDoubleNCSender_i : public POA_SALOME::CorbaDoubleNCSender,
45                                      public SALOME_Sender_i
46 {
47 public:
48   SALOME_CorbaDoubleNCSender_i(const double *tabToSend,long lgrTabToSend);
49   ~SALOME_CorbaDoubleNCSender_i();
50   CORBA::ULong getSize();
51   SALOME::vectorOfDouble* sendPart(CORBA::ULong offset, CORBA::ULong length);
52   SALOME::vectorOfDouble* send();
53 };
54
55 /*! 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.
56  */
57 class SALOME_CorbaDoubleCSender_i : public POA_SALOME::CorbaDoubleCSender,
58                                     public SALOME_Sender_i
59 {
60 public:
61   SALOME_CorbaDoubleCSender_i(const double *tabToSend,long lgrTabToSend);
62   ~SALOME_CorbaDoubleCSender_i();
63   CORBA::ULong getSize();
64   SALOME::vectorOfDouble* sendPart(CORBA::ULong offset, CORBA::ULong length);
65 };
66
67 /*! 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.
68  */
69 class SALOME_CorbaLongNCSender_i : public POA_SALOME::CorbaLongNCSender,
70                                    public SALOME_Sender_i
71 {
72 public:
73   SALOME_CorbaLongNCSender_i(const int *tabToSend,long lgrTabToSend);
74   ~SALOME_CorbaLongNCSender_i();
75   CORBA::ULong getSize();
76   SALOME::vectorOfLong* sendPart(CORBA::ULong offset, CORBA::ULong length);
77   SALOME::vectorOfLong* send();
78 };
79
80 /*! 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.
81  */
82 class SALOME_CorbaLongCSender_i : public POA_SALOME::CorbaLongCSender,
83                                   public SALOME_Sender_i
84 {
85 public:
86   SALOME_CorbaLongCSender_i(const int *tabToSend,long lgrTabToSend);
87   ~SALOME_CorbaLongCSender_i();
88   CORBA::ULong getSize();
89   SALOME::vectorOfLong* sendPart(CORBA::ULong offset, CORBA::ULong length);
90   SALOME::CorbaLongCSender_ptr _this();
91 };
92
93 #ifdef HAVE_MPI2
94
95 /*! Servant class of sender using MPI2.
96  */
97 class SALOME_MPISender_i : public POA_SALOME::MPISender,
98                            public SALOME_Sender_i
99 {
100 private:
101   static unsigned long _tag1;
102   static unsigned long _tag2;
103   /*! Name of the port opened*/
104   char *_portName;
105   int _cproc;
106   /*! Tag 1 that identifies the transfert*/
107   int _tag1Inst;
108   /*! Tag 2 that identifies the transfert*/
109   int _tag2Inst;
110   /*! MPI communicator*/
111   MPI_Comm _com;
112   /*! Array of pointer for asynchronous invocation with omnithread*/
113   void **_argsForThr;
114   /*! Pointer to thread created on asynchronous invocation*/
115   omni_thread *_newThr;
116 public:
117   SALOME_MPISender_i(SALOME::TypeOfDataTransmitted type,const void *tabToSend,long lgrTabToSend,int sizeOf);
118   ~SALOME_MPISender_i();
119   SALOME::MPISender::param* getParam();
120   void send();
121   void close(const SALOME::MPISender::param& p);
122 private:
123   static void* myThread(void *args);
124 };
125
126 #endif
127
128 #ifdef HAVE_SOCKET
129
130 /*! Servant class of sender using Sockets.
131  */
132 class SALOME_SocketSender_i : public POA_SALOME::SocketSender,
133                               public SALOME_Sender_i
134 {
135 private:
136   int _serverSockfd;
137   int _clientSockfd;
138   int _port;
139   std::string _IPAddress;
140   void **_argsForThr;
141   omni_thread *_newThr;
142   bool _errorFlag;
143 public:
144   SALOME_SocketSender_i(SALOME::TypeOfDataTransmitted type,const void *tabToSend,long lgrTabToSend,int sizeOf);
145   ~SALOME_SocketSender_i();
146   SALOME::SocketSender::param* getParam();
147   void send();
148   void initCom() throw(SALOME::SALOME_Exception);
149   void acceptCom() throw(SALOME::SALOME_Exception);
150   void endOfCom();
151   void closeCom();
152 private:
153   static void* myThread(void *args);
154   std::string inetAddress();
155 };
156
157 #endif
158
159 #endif
160