gattc_cache_manager.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #ifndef GATTC_CACHE_MANAGER_H__
  13. #define GATTC_CACHE_MANAGER_H__
  14. #include <stdint.h>
  15. #include "sdk_errors.h"
  16. #include "ble.h"
  17. #include "ble_gap.h"
  18. #include "peer_manager_types.h"
  19. /**
  20. * @cond NO_DOXYGEN
  21. * @defgroup gattc_cache_manager GATT Client Cache Manager
  22. * @ingroup peer_manager
  23. * @{
  24. * @brief An internal module of @ref peer_manager. A module for managing persistent storing of GATT
  25. * attributes pertaining to the GATT client role of the local device.
  26. */
  27. /**@brief Events that can come from the GATT Cache Manager module.
  28. */
  29. typedef enum
  30. {
  31. GCCM_EVT_REMOTE_DB_UPDATED, /**< Values for the specified data has been updated in persistent storage. */
  32. GCCM_EVT_REMOTE_DB_STORED, /**< New values for the specified data has been written in persistent storage. */
  33. } gccm_evt_id_t;
  34. typedef struct
  35. {
  36. gccm_evt_id_t evt_id;
  37. pm_peer_id_t peer_id;
  38. } gccm_evt_t;
  39. /**@brief Event handler for events from the GATT Client Cache Manager module.
  40. *
  41. * @param[in] event The event that has happened.
  42. * @param[in] peer The id of the peer the event pertains to.
  43. * @param[in] flags The data the event pertains to.
  44. */
  45. typedef void (*gccm_evt_handler_t)(gccm_evt_t const * p_event);
  46. /**@brief Function for initializing the GATT Client Cache Manager module.
  47. *
  48. * @param[in] evt_handler Callback for events from the GATT Client Cache Manager module.
  49. *
  50. * @retval NRF_SUCCESS Initialization was successful.
  51. * @retval NRF_ERROR_NULL evt_handler was NULL.
  52. */
  53. ret_code_t gccm_init(gccm_evt_handler_t evt_handler);
  54. /**@brief Function for storing a discovered remote database persistently.
  55. *
  56. * @param[in] peer_id Peer to store the database for.
  57. * @param[in] p_remote_db Database values to store as an array. Can be NULL if n_services is 0.
  58. * @param[in] n_services Number of services in p_remote_db array. If 0, values are cleared.
  59. *
  60. * @retval NRF_SUCCESS Store procedure successfully started.
  61. * @retval NRF_ERROR_NOT_FOUND The peer id is invalid or unallocated.
  62. * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
  63. */
  64. ret_code_t gccm_remote_db_store(pm_peer_id_t peer_id,
  65. ble_gatt_db_srv_t * p_remote_db,
  66. uint32_t n_services);
  67. /**@brief Function for retrieving a persistently stored remote database.
  68. *
  69. * @param[in] peer_id Peer to retrieve data for.
  70. * @param[out] p_remote_db If p_n_services was large enough: Copied database values.
  71. * @param[inout] p_n_services In: Size of provided p_remote_db array. Out: Size of data in flash.
  72. *
  73. * @note p_n_services is always updated with the size of the data to be retrieved. The data is only
  74. * copied if p_remote_db is large enough (p_n_services is large enough initially).
  75. *
  76. * @retval NRF_SUCCESS Data retrieved successfully.
  77. * @retval NRF_ERROR_NOT_FOUND The peer ID is invalid or unallocated.
  78. * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
  79. */
  80. ret_code_t gccm_remote_db_retrieve(pm_peer_id_t peer_id,
  81. ble_gatt_db_srv_t * p_remote_db,
  82. uint32_t * p_n_services);
  83. /** @}
  84. * @endcond
  85. */
  86. #endif /* GATTC_CACHE_MANAGER_H__ */