00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00039 #ifndef __vtkSocketCommunicator_h
00040 #define __vtkSocketCommunicator_h
00041
00042 #include "vtkCommunicator.h"
00043
00044 #include "vtkByteSwap.h"
00045
00046 #ifdef VTK_WORDS_BIGENDIAN
00047 # define vtkSwap4 vtkByteSwap::Swap4LE
00048 # define vtkSwap4Range vtkByteSwap::Swap4LERange
00049 # define vtkSwap8 vtkByteSwap::Swap8LE
00050 # define vtkSwap8Range vtkByteSwap::Swap8LERange
00051 #else
00052 # define vtkSwap4 vtkByteSwap::Swap4BE
00053 # define vtkSwap4Range vtkByteSwap::Swap4BERange
00054 # define vtkSwap8 vtkByteSwap::Swap8BE
00055 # define vtkSwap8Range vtkByteSwap::Swap8BERange
00056 #endif
00057
00058 class VTK_PARALLEL_EXPORT vtkSocketCommunicator : public vtkCommunicator
00059 {
00060 public:
00061 static vtkSocketCommunicator *New();
00062 vtkTypeRevisionMacro(vtkSocketCommunicator,vtkCommunicator);
00063 void PrintSelf(ostream& os, vtkIndent indent);
00064
00068 virtual int OpenSocket(int port, const char* network = 0);
00069
00071 virtual int GetPort(int sock);
00072
00076 virtual int WaitForConnectionOnSocket(int socket, unsigned long timeout = 0);
00077
00079 virtual int WaitForConnection(int port);
00080
00082 virtual void CloseConnection();
00083
00085 virtual int ConnectTo( char* hostName, int port);
00086
00088
00089 vtkGetMacro(SwapBytesInReceivedData, int);
00091
00093
00094 vtkGetMacro(IsConnected, int);
00096
00097
00098
00100
00102 int Send(int *data, int length, int remoteProcessId, int tag);
00103 int Send(unsigned long *data, int length, int remoteProcessId, int tag);
00104 int Send(char *data, int length, int remoteProcessId, int tag);
00105 int Send(unsigned char *data, int length, int remoteProcessId, int tag);
00106 int Send(float *data, int length, int remoteProcessId, int tag);
00107 int Send(double *data, int length, int remoteProcessId, int tag);
00108 #ifdef VTK_USE_64BIT_IDS
00109 int Send(vtkIdType *data, int length, int remoteProcessId, int tag);
00111 #endif
00112 int Send(vtkDataObject *data, int remoteId, int tag)
00113 {return this->vtkCommunicator::Send(data,remoteId,tag);}
00114 int Send(vtkDataArray *data, int remoteId, int tag)
00115 {return this->vtkCommunicator::Send(data,remoteId,tag);}
00116
00118
00121 int Receive(int *data, int length, int remoteProcessId, int tag);
00122 int Receive(unsigned long *data, int length, int remoteProcessId, int tag);
00123 int Receive(char *data, int length, int remoteProcessId, int tag);
00124 int Receive(unsigned char *data, int length, int remoteProcessId, int tag);
00125 int Receive(float *data, int length, int remoteProcessId, int tag);
00126 int Receive(double *data, int length, int remoteProcessId, int tag);
00127 #ifdef VTK_USE_64BIT_IDS
00128 int Receive(vtkIdType *data, int length, int remoteProcessId, int tag);
00130 #endif
00131 int Receive(vtkDataObject *data, int remoteId, int tag)
00132 {return this->vtkCommunicator::Receive(data, remoteId, tag);}
00133 int Receive(vtkDataArray *data, int remoteId, int tag)
00134 {return this->vtkCommunicator::Receive(data, remoteId, tag);}
00135
00137
00139 vtkSetClampMacro(PerformHandshake, int, 0, 1);
00140 vtkBooleanMacro(PerformHandshake, int);
00141 vtkGetMacro(PerformHandshake, int);
00143
00144
00146
00148 virtual void SetLogStream(ostream* stream);
00149 virtual ostream* GetLogStream();
00150
00152
00154
00158 virtual int LogToFile(const char* name);
00159 virtual int LogToFile(const char* name, int append);
00161
00163
00164 vtkSetMacro(ReportErrors, int);
00165 vtkGetMacro(ReportErrors, int);
00167
00168 protected:
00169
00170 int Socket;
00171 int IsConnected;
00172 int NumberOfProcesses;
00173 int SwapBytesInReceivedData;
00174 int PerformHandshake;
00175
00176 int ReportErrors;
00177
00178 ofstream* LogFile;
00179 ostream* LogStream;
00180
00181 vtkSocketCommunicator();
00182 ~vtkSocketCommunicator();
00183
00184
00185
00186 int SendInternal(int socket, void* data, int length);
00187 int ReceiveInternal(int socket, void* data, int length);
00188 int SendTagged(void* data, int wordSize, int numWords, int tag,
00189 const char* logName);
00190 int ReceiveTagged(void* data, int wordSize, int numWords, int tag,
00191 const char* logName);
00192 int ReceivePartialTagged(void* data, int wordSize, int numWords, int tag,
00193 const char* logName);
00194
00195
00196 void LogTagged(const char* name, void* data, int wordSize, int numWords,
00197 int tag, const char* logName);
00198 int CheckForErrorInternal(int id);
00199 private:
00200 vtkSocketCommunicator(const vtkSocketCommunicator&);
00201 void operator=(const vtkSocketCommunicator&);
00202
00203 int SelectSocket(int socket, unsigned long msec);
00204
00205
00206
00207
00208 enum ErrorIds {
00209 SwapOff = 0,
00210 SwapOn,
00211 SwapNotSet
00212 };
00213
00214 };
00215
00216 #endif