request_sender.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "wasm_app.h"
  6. static void my_response_handler(response_t *response, void *user_data)
  7. {
  8. char *tag = (char *) user_data;
  9. if (response == NULL) {
  10. printf("[req] request timeout!\n");
  11. return;
  12. }
  13. printf("[req] response handler called mid:%d, status:%d, fmt:%d, payload:%p, len:%d, tag:%s\n",
  14. response->mid, response->status, response->fmt, response->payload,
  15. response->payload_len, tag);
  16. if (response->payload != NULL
  17. && response->payload_len > 0
  18. && response->fmt == FMT_ATTR_CONTAINER) {
  19. printf("[req] dump the response payload:\n");
  20. attr_container_dump((attr_container_t *) response->payload);
  21. }
  22. }
  23. static void test_send_request(char *url, char *tag)
  24. {
  25. request_t request[1];
  26. init_request(request, url, COAP_PUT, 0, NULL, 0);
  27. api_send_request(request, my_response_handler, tag);
  28. }
  29. void on_init()
  30. {
  31. test_send_request("/app/request_handler/url1", "a request to target app");
  32. test_send_request("url1", "a general request");
  33. }
  34. void on_destroy()
  35. {
  36. /* real destroy work including killing timer and closing sensor is
  37. accomplished in wasm app library version of on_destroy() */
  38. }