HSocket.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /***********************************************************
  2. * File generated by the HALCON-Compiler hcomp version 20.11
  3. * Usage: Interface to C++
  4. *
  5. * Software by: MVTec Software GmbH, www.mvtec.com
  6. ***********************************************************/
  7. #ifndef HCPP_HSOCKET
  8. #define HCPP_HSOCKET
  9. namespace HalconCpp
  10. {
  11. // Represents an instance of a socket connection.
  12. class LIntExport HSocket : public HHandle
  13. {
  14. public:
  15. // Create an uninitialized instance
  16. HSocket():HHandle() {}
  17. // Copy constructor
  18. HSocket(const HSocket& source) : HHandle(source) {}
  19. // Copy constructor
  20. HSocket(const HHandle& handle);
  21. // Create HSocket from handle, taking ownership
  22. explicit HSocket(Hlong handle);
  23. bool operator==(const HHandle& obj) const
  24. {
  25. return HHandleBase::operator==(obj);
  26. }
  27. bool operator!=(const HHandle& obj) const
  28. {
  29. return HHandleBase::operator!=(obj);
  30. }
  31. protected:
  32. // Verify matching semantic type ('socket')!
  33. virtual void AssertType(Hphandle handle) const;
  34. public:
  35. /*****************************************************************************
  36. * Operator-based class constructors
  37. *****************************************************************************/
  38. // open_socket_connect: Open a socket and connect it to an accepting socket.
  39. explicit HSocket(const HString& HostName, Hlong Port, const HTuple& GenParamName, const HTuple& GenParamValue);
  40. // open_socket_connect: Open a socket and connect it to an accepting socket.
  41. explicit HSocket(const HString& HostName, Hlong Port, const HString& GenParamName, const HString& GenParamValue);
  42. // open_socket_connect: Open a socket and connect it to an accepting socket.
  43. explicit HSocket(const char* HostName, Hlong Port, const char* GenParamName, const char* GenParamValue);
  44. #ifdef _WIN32
  45. // open_socket_connect: Open a socket and connect it to an accepting socket.
  46. explicit HSocket(const wchar_t* HostName, Hlong Port, const wchar_t* GenParamName, const wchar_t* GenParamValue);
  47. #endif
  48. // open_socket_accept: Open a socket that accepts connection requests.
  49. explicit HSocket(Hlong Port, const HTuple& GenParamName, const HTuple& GenParamValue);
  50. // open_socket_accept: Open a socket that accepts connection requests.
  51. explicit HSocket(Hlong Port, const HString& GenParamName, const HString& GenParamValue);
  52. // open_socket_accept: Open a socket that accepts connection requests.
  53. explicit HSocket(Hlong Port, const char* GenParamName, const char* GenParamValue);
  54. #ifdef _WIN32
  55. // open_socket_accept: Open a socket that accepts connection requests.
  56. explicit HSocket(Hlong Port, const wchar_t* GenParamName, const wchar_t* GenParamValue);
  57. #endif
  58. /***************************************************************************
  59. * Operators *
  60. ***************************************************************************/
  61. // Receive an image over a socket connection.
  62. HImage ReceiveImage() const;
  63. // Send an image over a socket connection.
  64. void SendImage(const HImage& Image) const;
  65. // Receive regions over a socket connection.
  66. HRegion ReceiveRegion() const;
  67. // Send regions over a socket connection.
  68. void SendRegion(const HRegion& Region) const;
  69. // Receive an XLD object over a socket connection.
  70. HXLD ReceiveXld() const;
  71. // Send an XLD object over a socket connection.
  72. void SendXld(const HXLD& XLD) const;
  73. // Receive a tuple over a socket connection.
  74. HTuple ReceiveTuple() const;
  75. // Send a tuple over a socket connection.
  76. void SendTuple(const HTuple& Tuple) const;
  77. // Send a tuple over a socket connection.
  78. void SendTuple(const HString& Tuple) const;
  79. // Send a tuple over a socket connection.
  80. void SendTuple(const char* Tuple) const;
  81. #ifdef _WIN32
  82. // Send a tuple over a socket connection.
  83. void SendTuple(const wchar_t* Tuple) const;
  84. #endif
  85. // Receive arbitrary data from external devices or applications using a generic socket connection.
  86. HTuple ReceiveData(const HTuple& Format, HTuple* From) const;
  87. // Receive arbitrary data from external devices or applications using a generic socket connection.
  88. HTuple ReceiveData(const HString& Format, HString* From) const;
  89. // Receive arbitrary data from external devices or applications using a generic socket connection.
  90. HTuple ReceiveData(const char* Format, HString* From) const;
  91. #ifdef _WIN32
  92. // Receive arbitrary data from external devices or applications using a generic socket connection.
  93. HTuple ReceiveData(const wchar_t* Format, HString* From) const;
  94. #endif
  95. // Send arbitrary data to external devices or applications using a generic socket communication.
  96. void SendData(const HString& Format, const HTuple& Data, const HTuple& To) const;
  97. // Send arbitrary data to external devices or applications using a generic socket communication.
  98. void SendData(const HString& Format, const HString& Data, const HString& To) const;
  99. // Send arbitrary data to external devices or applications using a generic socket communication.
  100. void SendData(const char* Format, const char* Data, const char* To) const;
  101. #ifdef _WIN32
  102. // Send arbitrary data to external devices or applications using a generic socket communication.
  103. void SendData(const wchar_t* Format, const wchar_t* Data, const wchar_t* To) const;
  104. #endif
  105. // Get the value of a socket parameter.
  106. HTuple GetSocketParam(const HTuple& GenParamName) const;
  107. // Get the value of a socket parameter.
  108. HTuple GetSocketParam(const HString& GenParamName) const;
  109. // Get the value of a socket parameter.
  110. HTuple GetSocketParam(const char* GenParamName) const;
  111. #ifdef _WIN32
  112. // Get the value of a socket parameter.
  113. HTuple GetSocketParam(const wchar_t* GenParamName) const;
  114. #endif
  115. // Set a socket parameter.
  116. void SetSocketParam(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  117. // Set a socket parameter.
  118. void SetSocketParam(const HString& GenParamName, const HString& GenParamValue) const;
  119. // Set a socket parameter.
  120. void SetSocketParam(const char* GenParamName, const char* GenParamValue) const;
  121. #ifdef _WIN32
  122. // Set a socket parameter.
  123. void SetSocketParam(const wchar_t* GenParamName, const wchar_t* GenParamValue) const;
  124. #endif
  125. // Determine the HALCON data type of the next socket data.
  126. HString GetNextSocketDataType() const;
  127. // Get the socket descriptor of a socket used by the operating system.
  128. Hlong GetSocketDescriptor() const;
  129. // This operator is inoperable. It had the following function: Close all opened sockets.
  130. static void CloseAllSockets();
  131. // Close a socket.
  132. void CloseSocket() const;
  133. // Accept a connection request on a listening socket of the protocol type 'HALCON' or 'TCP'/'TCP4'/'TCP6'.
  134. HSocket SocketAcceptConnect(const HString& Wait) const;
  135. // Accept a connection request on a listening socket of the protocol type 'HALCON' or 'TCP'/'TCP4'/'TCP6'.
  136. HSocket SocketAcceptConnect(const char* Wait) const;
  137. #ifdef _WIN32
  138. // Accept a connection request on a listening socket of the protocol type 'HALCON' or 'TCP'/'TCP4'/'TCP6'.
  139. HSocket SocketAcceptConnect(const wchar_t* Wait) const;
  140. #endif
  141. // Open a socket and connect it to an accepting socket.
  142. void OpenSocketConnect(const HString& HostName, Hlong Port, const HTuple& GenParamName, const HTuple& GenParamValue);
  143. // Open a socket and connect it to an accepting socket.
  144. void OpenSocketConnect(const HString& HostName, Hlong Port, const HString& GenParamName, const HString& GenParamValue);
  145. // Open a socket and connect it to an accepting socket.
  146. void OpenSocketConnect(const char* HostName, Hlong Port, const char* GenParamName, const char* GenParamValue);
  147. #ifdef _WIN32
  148. // Open a socket and connect it to an accepting socket.
  149. void OpenSocketConnect(const wchar_t* HostName, Hlong Port, const wchar_t* GenParamName, const wchar_t* GenParamValue);
  150. #endif
  151. // Open a socket that accepts connection requests.
  152. void OpenSocketAccept(Hlong Port, const HTuple& GenParamName, const HTuple& GenParamValue);
  153. // Open a socket that accepts connection requests.
  154. void OpenSocketAccept(Hlong Port, const HString& GenParamName, const HString& GenParamValue);
  155. // Open a socket that accepts connection requests.
  156. void OpenSocketAccept(Hlong Port, const char* GenParamName, const char* GenParamValue);
  157. #ifdef _WIN32
  158. // Open a socket that accepts connection requests.
  159. void OpenSocketAccept(Hlong Port, const wchar_t* GenParamName, const wchar_t* GenParamValue);
  160. #endif
  161. // Receive a serialized item over a socket connection.
  162. HSerializedItem ReceiveSerializedItem() const;
  163. // Send a serialized item over a socket connection.
  164. void SendSerializedItem(const HSerializedItem& SerializedItemHandle) const;
  165. };
  166. // forward declarations and types for internal array implementation
  167. template<class T> class HSmartPtr;
  168. template<class T> class HHandleBaseArrayRef;
  169. typedef HHandleBaseArrayRef<HSocket> HSocketArrayRef;
  170. typedef HSmartPtr< HSocketArrayRef > HSocketArrayPtr;
  171. // Represents multiple tool instances
  172. class LIntExport HSocketArray : public HHandleBaseArray
  173. {
  174. public:
  175. // Create empty array
  176. HSocketArray();
  177. // Create array from native array of tool instances
  178. HSocketArray(HSocket* classes, Hlong length);
  179. // Copy constructor
  180. HSocketArray(const HSocketArray &tool_array);
  181. // Destructor
  182. virtual ~HSocketArray();
  183. // Assignment operator
  184. HSocketArray &operator=(const HSocketArray &tool_array);
  185. // Clears array and all tool instances
  186. virtual void Clear();
  187. // Get array of native tool instances
  188. const HSocket* Tools() const;
  189. // Get number of tools
  190. virtual Hlong Length() const;
  191. // Create tool array from tuple of handles
  192. virtual void SetFromTuple(const HTuple& handles);
  193. // Get tuple of handles for tool array
  194. virtual HTuple ConvertToTuple() const;
  195. protected:
  196. // Smart pointer to internal data container
  197. HSocketArrayPtr *mArrayPtr;
  198. };
  199. }
  200. #endif