Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  
igtlSocket.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Open IGT Link Library
4  Module: $HeadURL: http://svn.na-mic.org/NAMICSandBox/trunk/OpenIGTLink/Source/igtlSocket.h $
5  Language: C++
6  Date: $Date: 2010-06-09 16:16:36 -0400 (Wed, 09 Jun 2010) $
7  Version: $Revision: 6525 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10 
11  This software is distributed WITHOUT ANY WARRANTY; without even
12  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the above copyright notices for more information.
14 
15 =========================================================================*/
16 /*=========================================================================
17 
18  Program: Visualization Toolkit
19  Module: $RCSfile: igtlSocket.h,v $
20 
21  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
22  All rights reserved.
23  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
24 
25  This software is distributed WITHOUT ANY WARRANTY; without even
26  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
27  PURPOSE. See the above copyright notice for more information.
28 
29 =========================================================================*/
30 
42 #ifndef __igtlSocket_h
43 #define __igtlSocket_h
44 
45 #include "igtlObject.h"
46 #include "igtlObjectFactory.h"
47 #include "igtlMacro.h"
48 #include "igtlWin32Header.h"
49 
50 namespace igtl
51 {
52 
53 class SocketCollection;
54 
55 // class IGTL_EXPORT Socket
57 {
58  public:
59  typedef Socket Self;
60  typedef Object Superclass;
63 
65  igtlNewMacro(igtl::Socket);
66 
67 public:
68 
69  // ----- Status API ----
70  // Description:
71  // Check is the socket is alive.
72  int GetConnected() { return (this->m_SocketDescriptor >=0); }
73 
74  // Description:
75  // Close the socket.
76  void CloseSocket() {this->CloseSocket(this->m_SocketDescriptor);}
77 
78  // ------ Communication API ---
79  // Description:
80  // These methods send data over the socket.
81  // Returns 1 on success, 0 on error and raises vtkCommand::ErrorEvent.
82  int Send(const void* data, int length);
83 
84  // Description:
85  // Receive data from the socket.
86  // This call blocks until some data is read from the socket.
87  // When readFully is set, this call will block until all the
88  // requested data is read from the socket.
89  // 0 on error, else number of bytes read is returned. On error,
90  // vtkCommand::ErrorEvent is raised.
91  int Receive(void* data, int length, int readFully=1);
92 
93  // Description:
94  // Skip reading data from the socket.
95  // The Skip() call has been newly introduced to the igtlSocket,
96  // after the class is imported from VTK, thus the call is
97  // not available in vtkSocket class.
98  int Skip(int length, int skipFully=1);
99 
100 protected:
101  Socket();
102  ~Socket();
103 
104  void PrintSelf(std::ostream& os) const;
105 
107  igtlGetMacro(SocketDescriptor, int);
108 
109  //BTX
110  friend class vtkSocketCollection;
111  //ETX
112 
113  // Description:
114  // Creates an endpoint for communication and returns the descriptor.
115  // -1 indicates error.
116  int CreateSocket();
117 
118  // Description:
119  // Close the socket.
120  void CloseSocket(int socketdescriptor);
121 
122  // Description:
123  // Binds socket to a particular port.
124  // Returns 0 on success other -1 is returned.
125  int BindSocket(int socketdescriptor, int port);
126 
127  // Description:
128  // Selects a socket ie. waits for it to change status.
129  // Returns 1 on success; 0 on timeout; -1 on error. msec=0 implies
130  // no timeout.
131  int SelectSocket(int socketdescriptor, unsigned long msec);
132 
133  // Description:
134  // Accept a connection on a socket. Returns -1 on error. Otherwise
135  // the descriptor of the accepted socket.
136  int Accept(int socketdescriptor);
137 
138  // Description:
139  // Listen for connections on a socket. Returns 0 on success. -1 on error.
140  int Listen(int socketdescriptor);
141 
142  // Description:
143  // Connect to a server socket. Returns 0 on success, -1 on error.
144  int Connect(int socketdescriptor, const char* hostname, int port);
145 
146  // Description:
147  // Returns the port to which the socket is connected.
148  // 0 on error.
149  int GetPort(int socketdescriptor);
150 
151  // Description:
152  // Selects set of sockets. Returns 0 on timeout, -1 on error.
153  // 1 on success. Selected socket's index is returned thru
154  // selected_index
155  static int SelectSockets(const int* sockets_to_select, int size,
156  unsigned long msec, int* selected_index);
157 private:
158  Socket(const Socket&); // Not implemented.
159  void operator=(const Socket&); // Not implemented.
160 };
161 
162 }
163 
164 #endif
165 

Generated at Thu Mar 20 2014 16:32:06 for OpenIGTLink by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2000