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

vtkSocketCommunicator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSocketCommunicator.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00039 #ifndef __vtkSocketCommunicator_h
00040 #define __vtkSocketCommunicator_h
00041 
00042 #include "vtkCommunicator.h"
00043 
00044 #include "vtkByteSwap.h" // Needed for vtkSwap macros
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   //------------------ Communication --------------------
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   //BTX
00146 
00148   virtual void SetLogStream(ostream* stream);
00149   virtual ostream* GetLogStream();
00150   //ETX
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   // Wrappers around send/recv calls to implement loops.  Return 1 for
00185   // success, and 0 for failure.
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   // Internal utility methods.
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&);  // Not implemented.
00201   void operator=(const vtkSocketCommunicator&);  // Not implemented.
00202 
00203   int SelectSocket(int socket, unsigned long msec);
00204 
00205 //BTX
00206   // SwapBytesInReceiveData needs an invalid / not set.
00207   // This avoids checking length of endian handshake.
00208   enum ErrorIds {
00209     SwapOff = 0,
00210     SwapOn,
00211     SwapNotSet
00212   };
00213 //ETX
00214 };
00215 
00216 #endif

Generated on Mon Jan 21 23:07:34 2008 for VTK by  doxygen 1.4.3-20050530