iot_file.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /**
  41. * @file iot_file.h
  42. * @brief IoT File abstraction API.
  43. */
  44. #ifndef IOT_FILE_H__
  45. #define IOT_FILE_H__
  46. #include "iot_common.h"
  47. #include "iot_file_port.h"
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /**
  52. * @ingroup iot_sdk_common
  53. * @addtogroup iot_file IoT File
  54. * @brief IoT File abstraction definition.
  55. * @{
  56. * @defgroup iot_file_abstraction IoT file abstraction
  57. * @{
  58. * @brief Structures and public API definition.
  59. */
  60. /**
  61. * @enum iot_file_evt_t
  62. * @brief List of events returned in callback for file ports with asynchronous operation
  63. * like open, read, write and close.
  64. */
  65. typedef enum {
  66. IOT_FILE_OPENED, /**< Event indicates that file has been opened.*/
  67. IOT_FILE_WRITE_COMPLETE, /**< Event indicates that single write operation has been completed.*/
  68. IOT_FILE_READ_COMPLETE, /**< Event indicates that single read operation has been completed.*/
  69. IOT_FILE_CLOSED, /**< Event indicates that file has been closed.*/
  70. IOT_FILE_ERROR /**< Event indicates that file encountered a problem.*/
  71. } iot_file_evt_t;
  72. /**
  73. * @brief IoT File user callback type definition.
  74. *
  75. * @param[in] p_file Reference to an IoT file instance.
  76. * @param[in] event Event structure describing what has happened.
  77. * @param[in] result Result code (should be NRF_SUCCESS for all events except errors).
  78. * @param[in] p_data Pointer to memory buffer.
  79. * @param[in] size Size of data stored in memory buffer.
  80. *
  81. * @retval None.
  82. */
  83. typedef void (*iot_file_callback_t) (iot_file_t * p_file, iot_file_evt_t event, uint32_t result, void * p_data, uint32_t size);
  84. /**
  85. * @brief Function to open IoT file. Depending on port, it should allocate required buffer.
  86. *
  87. * @param[in] p_file Pointer to an IoT file instance.
  88. * @param[in] requested_size Maximum number of bytes to be read/written.
  89. *
  90. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  91. * for failure.
  92. */
  93. uint32_t iot_file_fopen(iot_file_t * p_file, uint32_t requested_size);
  94. /**
  95. * @brief Function to write data buffer into a file.
  96. *
  97. * @param[in] p_file Pointer to an IoT file instance.
  98. * @param[in] p_data Pointer to data block which will be written into the file.
  99. * @param[in] size Number of bytes to be written.
  100. *
  101. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  102. * for failure.
  103. */
  104. uint32_t iot_file_fwrite(iot_file_t * p_file, const void * p_data, uint32_t size);
  105. /**
  106. * @brief Function to read data buffer from file.
  107. *
  108. * @param[in] p_file Pointer to an IoT file instance.
  109. * @param[in] p_data Pointer to data block to be filled with read data.
  110. * @param[in] size Number of bytes to be read.
  111. *
  112. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  113. * for failure.
  114. */
  115. uint32_t iot_file_fread(iot_file_t * p_file, void * p_data, uint32_t size);
  116. /**
  117. * @brief Function to read current cursor position.
  118. *
  119. * @param[in] p_file Pointer to an IoT file instance.
  120. * @param[out] p_cursor Current value of a cursor.
  121. *
  122. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  123. * for failure.
  124. */
  125. uint32_t iot_file_ftell(iot_file_t * p_file, uint32_t * p_cursor);
  126. /**
  127. * @brief Function to set current cursor position.
  128. *
  129. * @param[in] p_file Pointer to an IoT file instance.
  130. * @param[in] cursor New cursor value.
  131. *
  132. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  133. * for failure.
  134. */
  135. uint32_t iot_file_fseek(iot_file_t * p_file, uint32_t cursor);
  136. /**
  137. * @brief Function to rewind file cursor.
  138. *
  139. * @param[in] p_file Pointer to an IoT file instance.
  140. *
  141. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  142. * for failure.
  143. */
  144. uint32_t iot_file_frewind(iot_file_t * p_file);
  145. /**
  146. * @brief Function to close IoT file. Depending on port, it should free used buffer.
  147. *
  148. * @param[in] p_file Pointer to an IoT file instance.
  149. *
  150. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  151. * for failure.
  152. */
  153. uint32_t iot_file_fclose(iot_file_t * p_file);
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif // IOT_FILE_H__
  158. /** @} */
  159. /** @} */