request_handler.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 url1_request_handler(request_t *request)
  7. {
  8. response_t response[1];
  9. attr_container_t *payload;
  10. printf("[resp] ### user resource 1 handler called\n");
  11. if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
  12. attr_container_dump((attr_container_t *) request->payload);
  13. payload = attr_container_create("wasm app response payload");
  14. if (payload == NULL)
  15. return;
  16. attr_container_set_string(&payload, "key1", "value1");
  17. attr_container_set_string(&payload, "key2", "value2");
  18. make_response_for_request(request, response);
  19. set_response(response, CONTENT_2_05,
  20. FMT_ATTR_CONTAINER,
  21. (void *)payload,
  22. attr_container_get_serialize_length(payload));
  23. api_response_send(response);
  24. attr_container_destroy(payload);
  25. }
  26. static void url2_request_handler(request_t *request)
  27. {
  28. response_t response[1];
  29. make_response_for_request(request, response);
  30. set_response(response, DELETED_2_02, 0, NULL, 0);
  31. api_response_send(response);
  32. printf("### user resource 2 handler called\n");
  33. }
  34. void on_init()
  35. {
  36. /* register resource uri */
  37. api_register_resource_handler("/url1", url1_request_handler);
  38. api_register_resource_handler("/url2", url2_request_handler);
  39. }
  40. void on_destroy()
  41. {
  42. /* real destroy work including killing timer and closing sensor is
  43. accomplished in wasm app library version of on_destroy() */
  44. }