Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Parallel/vtkSocketCommunicator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSocketCommunicator.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00054 #ifndef __vtkSocketCommunicator_h
00055 #define __vtkSocketCommunicator_h
00056 
00057 #include "vtkCommunicator.h"
00058 
00059 #include "vtkByteSwap.h" // Needed for vtkSwap macros
00060 
00061 #ifdef VTK_WORDS_BIGENDIAN
00062 # define vtkSwap4 vtkByteSwap::Swap4LE
00063 # define vtkSwap4Range vtkByteSwap::Swap4LERange
00064 # define vtkSwap8 vtkByteSwap::Swap8LE
00065 # define vtkSwap8Range vtkByteSwap::Swap8LERange
00066 #else
00067 # define vtkSwap4 vtkByteSwap::Swap4BE
00068 # define vtkSwap4Range vtkByteSwap::Swap4BERange
00069 # define vtkSwap8 vtkByteSwap::Swap8BE
00070 # define vtkSwap8Range vtkByteSwap::Swap8BERange
00071 #endif
00072 
00073 class VTK_PARALLEL_EXPORT vtkSocketCommunicator : public vtkCommunicator
00074 {
00075 public:
00076   static vtkSocketCommunicator *New();
00077   vtkTypeRevisionMacro(vtkSocketCommunicator,vtkCommunicator);
00078   void PrintSelf(ostream& os, vtkIndent indent);
00079 
00081   virtual int WaitForConnection(int port);
00082 
00084   virtual void CloseConnection();
00085 
00087   virtual int ConnectTo( char* hostName, int port);
00088 
00090 
00091   vtkGetMacro(SwapBytesInReceivedData, int);
00093 
00095 
00096   vtkGetMacro(IsConnected, int);
00098 
00099   //------------------ Communication --------------------
00100   
00102 
00104   int Send(int *data, int length, int remoteProcessId, int tag);
00105   int Send(unsigned long *data, int length, int remoteProcessId, int tag);
00106   int Send(char *data, int length, int remoteProcessId, int tag);
00107   int Send(unsigned char *data, int length, int remoteProcessId, int tag);
00108   int Send(float *data, int length, int remoteProcessId, int tag);
00109   int Send(double *data, int length, int remoteProcessId, int tag);
00110 #ifdef VTK_USE_64BIT_IDS
00111   int Send(vtkIdType *data, int length, int remoteProcessId, int tag);
00113 #endif
00114   int Send(vtkDataObject *data, int remoteId, int tag)
00115     {return this->vtkCommunicator::Send(data,remoteId,tag);}
00116   int Send(vtkDataArray *data, int remoteId, int tag)
00117     {return this->vtkCommunicator::Send(data,remoteId,tag);}
00118 
00120 
00123   int Receive(int *data, int length, int remoteProcessId, int tag);
00124   int Receive(unsigned long *data, int length, int remoteProcessId, int tag);
00125   int Receive(char *data, int length, int remoteProcessId, int tag);
00126   int Receive(unsigned char *data, int length, int remoteProcessId, int tag);
00127   int Receive(float *data, int length, int remoteProcessId, int tag);
00128   int Receive(double *data, int length, int remoteProcessId, int tag);
00129 #ifdef VTK_USE_64BIT_IDS
00130   int Receive(vtkIdType *data, int length, int remoteProcessId, int tag);
00132 #endif
00133   int Receive(vtkDataObject *data, int remoteId, int tag)
00134     {return this->vtkCommunicator::Receive(data, remoteId, tag);}
00135   int Receive(vtkDataArray *data, int remoteId, int tag)
00136     {return this->vtkCommunicator::Receive(data, remoteId, tag);}
00137 
00139 
00141   vtkSetClampMacro(PerformHandshake, int, 0, 1);
00142   vtkBooleanMacro(PerformHandshake, int);
00143   vtkGetMacro(PerformHandshake, int);
00145 
00148   int ReceiveMessage(char *data, int *length, int maxlength);
00149 
00151   int SendMessage(const char *data, int length);
00152 
00153 protected:
00154 
00155   int Socket;
00156   int IsConnected;
00157   int NumberOfProcesses;
00158   int SwapBytesInReceivedData;
00159   int PerformHandshake;
00160 
00161   vtkSocketCommunicator();
00162   ~vtkSocketCommunicator();
00163 
00164   int ReceiveMessage(char *data, int size, int length, int tag );
00165 
00166   ofstream *TraceFile;
00167 
00168 private:
00169   vtkSocketCommunicator(const vtkSocketCommunicator&);  // Not implemented.
00170   void operator=(const vtkSocketCommunicator&);  // Not implemented.
00171 };
00172 
00173 #endif