networklayer.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef NETWORKLAYER_H_
  2. #define NETWORKLAYER_H_
  3. #include "ua_types.h"
  4. #include "ua_transport.h"
  5. #include "ua_transport_binary.h"
  6. #include "util/ua_list.h"
  7. #ifdef MULTITHREADING
  8. #include <pthread.h> // pthreadcreate, pthread_t
  9. #endif
  10. // fd_set, FD_ZERO, FD_SET
  11. #ifdef WIN32
  12. #include <winsock2.h>
  13. #else
  14. #include <sys/select.h>
  15. #endif
  16. #define NL_MAXCONNECTIONS_DEFAULT 10
  17. enum NL_UA_ENCODING_enum {
  18. NL_UA_ENCODING_BINARY = 0,
  19. NL_UA_ENCODING_XML = 1,
  20. };
  21. enum NL_CONNECTIONTYPE_enum {
  22. NL_CONNECTIONTYPE_TCPV4 = 0,
  23. NL_CONNECTIONTYPE_TCPV6 = 1,
  24. };
  25. typedef struct NL_Description {
  26. UA_Int32 encoding;
  27. UA_Int32 connectionType;
  28. UA_Int32 maxConnections;
  29. TL_Buffer localConf;
  30. } NL_Description;
  31. extern NL_Description NL_Description_TcpBinary;
  32. typedef struct NL_data {
  33. NL_Description* tld;
  34. UA_String endpointUrl;
  35. UA_list_List connections;
  36. fd_set readerHandles;
  37. int maxReaderHandle;
  38. } NL_data;
  39. struct NL_Connection;
  40. typedef void* (*NL_Reader)(struct NL_Connection *c);
  41. typedef struct NL_Connection {
  42. UA_TL_Connection *connection;
  43. UA_Int32 state;
  44. UA_UInt32 connectionHandle;
  45. NL_Reader reader;
  46. #ifdef MULTITHREADING
  47. pthread_t readerThreadHandle;
  48. #endif
  49. NL_data* networkLayer;
  50. } NL_Connection;
  51. NL_data* NL_init(NL_Description* tlDesc, UA_Int32 port);
  52. UA_Int32 NL_Connection_close(UA_TL_Connection *connection);
  53. UA_Int32 NL_msgLoop(NL_data* nl, struct timeval *tv, UA_Int32(*worker)(void*), void *arg, UA_Boolean *running);
  54. UA_Int32 NL_TCP_writer(UA_Int32 connectionHandle, UA_ByteString const * const * gather_buf, UA_UInt32 gather_len);
  55. #endif /* NETWORKLAYER_H_ */