esp_local_ctrl_priv.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // Copyright 2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <esp_err.h>
  19. #include <protocomm.h>
  20. #include <esp_local_ctrl.h>
  21. /**
  22. * @brief `esp_local_ctrl` transport specific structure
  23. *
  24. * Every supported transport layer should have the following functions
  25. * implemented for starting, stopping and configuring a protocomm service
  26. */
  27. struct esp_local_ctrl_transport {
  28. /**
  29. * Handler for starting a protocomm service as per specified configuration
  30. */
  31. esp_err_t (*start_service) (protocomm_t *pc,
  32. const esp_local_ctrl_transport_config_t *config);
  33. /**
  34. * Handler for stopping a protocomm service
  35. */
  36. void (*stop_service) (protocomm_t *pc);
  37. /**
  38. * Handler for creating a copy of the transport specific configuration
  39. */
  40. esp_err_t (*copy_config) (esp_local_ctrl_transport_config_t *dest_config,
  41. const esp_local_ctrl_transport_config_t *src_config);
  42. /**
  43. * Handler for allocating resources corresponding to a protocomm endpoint.
  44. * Usually when adding a new endpoint `protocomm_endpoint_add()` API is used,
  45. * but the transport layer may need to perform resource allocation for
  46. * each endpoint, prior to starting the protocomm instance. This handler
  47. * is useful in that case, as it is called before `start_service()`.
  48. */
  49. esp_err_t (*declare_ep) (esp_local_ctrl_transport_config_t *config,
  50. const char *ep_name, uint16_t ep_uuid);
  51. /**
  52. * Handler for freeing a transport specific configuration
  53. */
  54. void (*free_config) (esp_local_ctrl_transport_config_t *config);
  55. };
  56. /**
  57. * @brief Protocomm handler for `esp_local_ctrl`
  58. *
  59. * This is the handler which is responsible for processing incoming requests
  60. * over a protocomm channel, then invokes one of the following functions
  61. * depending upon the request type:
  62. * - `esp_local_ctrl_get_prop_count()`
  63. * - `esp_local_ctrl_get_prop_values()`
  64. * -` esp_local_ctrl_set_prop_values()`
  65. * The output of the above functions are used to form the response messages
  66. * corresponding to request types. The formed response messages are packed and
  67. * sent back via the protocomm channel.
  68. *
  69. * @param[in] session_id A number to identify an ongoing session between
  70. * device and client
  71. * @param[in] inbuf Buffer which holds serialized / packed request data
  72. * @param[in] inlen Length of input buffer
  73. * @param[out] outbuf Buffer which holds serialized / packed response data
  74. * @param[out] outlen Length of output buffer
  75. * @param[in] priv_data Private data associated with `esp_local_ctrl` endpoint
  76. *
  77. * @return
  78. * - ESP_OK : Success
  79. * - ESP_FAIL : Failure
  80. */
  81. esp_err_t esp_local_ctrl_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen,
  82. uint8_t **outbuf, ssize_t *outlen, void *priv_data);
  83. /**
  84. * @brief Use this for obtaining total number of properties registered
  85. * with `esp_local_ctrl` service
  86. *
  87. * @param[out] count Pointer to variable where the result is to be stored
  88. *
  89. * @return
  90. * - ESP_OK : Success
  91. * - ESP_FAIL : Failure
  92. */
  93. esp_err_t esp_local_ctrl_get_prop_count(size_t *count);
  94. /**
  95. * @brief Get descriptions and values of multiple properties at the same time.
  96. * The properties are requested by indices. This internally calls the
  97. * `get_prop_values` handler specified in the `esp_local_ctrl_handlers_t`
  98. * structure. Since `get_prop_values` accepts property structure, the
  99. * indices are first converted to the corresponding `esp_local_ctrl_prop_t`
  100. * internally.
  101. *
  102. * @param[in] total_indices The number of elements in the `indices` array argument
  103. * @param[in] indices An array of indices, that specify which properties to get
  104. * @param[out] props A pre-allocated array of empty property structures, elements of
  105. * which are to be populated with names, types and flags of those
  106. * properties which correspond to the provided indices
  107. * @param[out] values A pre-allocated array of empty value structures, elements of
  108. * which are to be populated with values and sizes of those
  109. * properties which correspond to the provided indices
  110. *
  111. * @return
  112. * - ESP_OK : Success
  113. * - ESP_FAIL : Failure
  114. */
  115. esp_err_t esp_local_ctrl_get_prop_values(size_t total_indices, uint32_t *indices,
  116. esp_local_ctrl_prop_t *props,
  117. esp_local_ctrl_prop_val_t *values);
  118. /**
  119. * @brief Set values of multiple properties at the same time. The properties to
  120. * set are specified by indices. This internally calls the `set_prop_values`
  121. * handler specified in the `esp_local_ctrl_handlers_t` structure. Since
  122. * `set_prop_values` accepts property structures, the indices are first
  123. * converted to the corresponding `esp_local_ctrl_prop_t` internally.
  124. *
  125. * @param[in] total_indices The number of elements in the `indices` array argument
  126. * @param[in] indices An array of indices, that specify which properties to set
  127. * @param[in] values A array of values. Every value should have the correct
  128. * size, if it is for setting a fixed size property, else
  129. * error will be generated and none of the properties will
  130. * be set to any of the given values
  131. *
  132. * @return
  133. * - ESP_OK : Success
  134. * - ESP_FAIL : Failure
  135. */
  136. esp_err_t esp_local_ctrl_set_prop_values(size_t total_indices, uint32_t *indices,
  137. const esp_local_ctrl_prop_val_t *values);
  138. #ifdef __cplusplus
  139. }
  140. #endif