connection_lib.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef CONNECTION_LIB_H_
  6. #define CONNECTION_LIB_H_
  7. #include "bi-inc/attr_container.h"
  8. #include "wasm_export.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /**
  13. * This file defines connection library which should be implemented by
  14. * different platforms
  15. */
  16. /*
  17. * @brief Open a connection.
  18. *
  19. * @param name name of the connection, "TCP", "UDP" or "UART"
  20. * @param args connection arguments, such as: ip:127.0.0.1, port:8888
  21. *
  22. * @return 0~0xFFFFFFFE means id of the connection, otherwise(-1) means fail
  23. */
  24. typedef uint32 (*connection_open_f)(wasm_module_inst_t module_inst,
  25. const char *name, attr_container_t *args);
  26. /*
  27. * @brief Close a connection.
  28. *
  29. * @param handle of the connection
  30. */
  31. typedef void (*connection_close_f)(uint32 handle);
  32. /*
  33. * @brief Send data to the connection in non-blocking manner.
  34. *
  35. * @param handle of the connection
  36. * @param data data buffer to be sent
  37. * @param len length of the data in byte
  38. *
  39. * @return actual length sent, -1 if fail
  40. */
  41. typedef int (*connection_send_f)(uint32 handle, const char *data, int len);
  42. /*
  43. * @brief Configure connection.
  44. *
  45. * @param handle of the connection
  46. * @param cfg configurations
  47. *
  48. * @return true if success, false otherwise
  49. */
  50. typedef bool (*connection_config_f)(uint32 handle, attr_container_t *cfg);
  51. /* Raw connection interface for platform to implement */
  52. typedef struct _connection_interface {
  53. connection_open_f _open;
  54. connection_close_f _close;
  55. connection_send_f _send;
  56. connection_config_f _config;
  57. } connection_interface_t;
  58. /* Platform must define this interface */
  59. extern connection_interface_t connection_impl;
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif /* CONNECTION_LIB_H_ */