00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00063 #ifndef __vtkSocketCommunicator_h
00064 #define __vtkSocketCommunicator_h
00065
00066 #if defined(_WIN32) && !defined(__CYGWIN__)
00067 #include <winsock2.h>
00068 #else
00069 #include <sys/types.h>
00070 #include <sys/socket.h>
00071 #include <netinet/in.h>
00072 #include <arpa/inet.h>
00073 #include <netdb.h>
00074 #include <unistd.h>
00075 #endif
00076
00077 #include "vtkObject.h"
00078 #include "vtkByteSwap.h"
00079 #include "vtkCommunicator.h"
00080
00081 #ifdef VTK_WORDS_BIGENDIAN
00082 # define vtkSwap4 vtkByteSwap::Swap4LE
00083 # define vtkSwap4Range vtkByteSwap::Swap4LERange
00084 # define vtkSwap8 vtkByteSwap::Swap8LE
00085 # define vtkSwap8Range vtkByteSwap::Swap8LERange
00086 #else
00087 # define vtkSwap4 vtkByteSwap::Swap4BE
00088 # define vtkSwap4Range vtkByteSwap::Swap4BERange
00089 # define vtkSwap8 vtkByteSwap::Swap8BE
00090 # define vtkSwap8Range vtkByteSwap::Swap8BERange
00091 #endif
00092
00093 class VTK_PARALLEL_EXPORT vtkSocketCommunicator : public vtkCommunicator
00094 {
00095 public:
00096 static vtkSocketCommunicator *New();
00097 vtkTypeMacro(vtkSocketCommunicator,vtkCommunicator);
00098 void PrintSelf(ostream& os, vtkIndent indent);
00099
00101 virtual int WaitForConnection(int port);
00102
00104 virtual void CloseConnection();
00105
00107 virtual int ConnectTo( char* hostName, int port);
00108
00110
00111 vtkGetMacro(SwapBytesInReceivedData, int);
00113
00115
00116 vtkGetMacro(IsConnected, int);
00118
00119
00120
00122
00124 int Send(int *data, int length, int remoteProcessId, int tag);
00125 int Send(unsigned long *data, int length, int remoteProcessId, int tag);
00126 int Send(char *data, int length, int remoteProcessId, int tag);
00127 int Send(unsigned char *data, int length, int remoteProcessId, int tag);
00128 int Send(float *data, int length, int remoteProcessId, int tag);
00129 int Send(double *data, int length, int remoteProcessId, int tag);
00130 #ifdef VTK_USE_64BIT_IDS
00131 int Send(vtkIdType *data, int length, int remoteProcessId, int tag);
00133 #endif
00134 int Send(vtkDataObject *data, int remoteId, int tag)
00135 {return this->vtkCommunicator::Send(data,remoteId,tag);}
00136 int Send(vtkDataArray *data, int remoteId, int tag)
00137 {return this->vtkCommunicator::Send(data,remoteId,tag);}
00138
00140
00143 int Receive(int *data, int length, int remoteProcessId, int tag);
00144 int Receive(unsigned long *data, int length, int remoteProcessId, int tag);
00145 int Receive(char *data, int length, int remoteProcessId, int tag);
00146 int Receive(unsigned char *data, int length, int remoteProcessId, int tag);
00147 int Receive(float *data, int length, int remoteProcessId, int tag);
00148 int Receive(double *data, int length, int remoteProcessId, int tag);
00149 #ifdef VTK_USE_64BIT_IDS
00150 int Receive(vtkIdType *data, int length, int remoteProcessId, int tag);
00152 #endif
00153 int Receive(vtkDataObject *data, int remoteId, int tag)
00154 {return this->vtkCommunicator::Receive(data, remoteId, tag);}
00155 int Receive(vtkDataArray *data, int remoteId, int tag)
00156 {return this->vtkCommunicator::Receive(data, remoteId, tag);}
00157
00158 protected:
00159
00160 int Socket;
00161 int IsConnected;
00162 int NumberOfProcesses;
00163 int SwapBytesInReceivedData;
00164
00165 vtkSocketCommunicator();
00166 ~vtkSocketCommunicator();
00167
00168 int ReceiveMessage(char *data, int size, int length, int tag );
00169 private:
00170 vtkSocketCommunicator(const vtkSocketCommunicator&);
00171 void operator=(const vtkSocketCommunicator&);
00172 };
00173
00174 #endif