networklayer.h 1.5 KB

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