connection_lib.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. *****************
  14. * This file defines connection library which should be implemented by different platforms
  15. *****************
  16. */
  17. /*
  18. * @brief Open a connection.
  19. *
  20. * @param name name of the connection, "TCP", "UDP" or "UART"
  21. * @param args connection arguments, such as: ip:127.0.0.1, port:8888
  22. *
  23. * @return 0~0xFFFFFFFE means id of the connection, otherwise(-1) means fail
  24. */
  25. typedef uint32 (*connection_open_f)(wasm_module_inst_t module_inst,
  26. const char *name, attr_container_t *args);
  27. /*
  28. * @brief Close a connection.
  29. *
  30. * @param handle of the connection
  31. */
  32. typedef void (*connection_close_f)(uint32 handle);
  33. /*
  34. * @brief Send data to the connection in non-blocking manner.
  35. *
  36. * @param handle of the connection
  37. * @param data data buffer to be sent
  38. * @param len length of the data in byte
  39. *
  40. * @return actual length sent, -1 if fail
  41. */
  42. typedef int (*connection_send_f)(uint32 handle, const char *data, int len);
  43. /*
  44. * @brief Configure connection.
  45. *
  46. * @param handle of the connection
  47. * @param cfg configurations
  48. *
  49. * @return true if success, false otherwise
  50. */
  51. typedef bool (*connection_config_f)(uint32 handle, attr_container_t *cfg);
  52. /* Raw connection interface for platform to implement */
  53. typedef struct _connection_interface {
  54. connection_open_f _open;
  55. connection_close_f _close;
  56. connection_send_f _send;
  57. connection_config_f _config;
  58. } connection_interface_t;
  59. /* Platform must define this interface */
  60. extern connection_interface_t connection_impl;
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* CONNECTION_LIB_H_ */