datastore.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2007 - 2008, Digium, Inc.
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*! \file
  17. * \brief Asterisk datastore objects
  18. */
  19. #ifndef _ASTERISK_DATASTORE_H
  20. #define _ASTERISK_DATASTORE_H
  21. #if defined(__cplusplus) || defined(c_plusplus)
  22. extern "C" {
  23. #endif
  24. #include "asterisk/linkedlists.h"
  25. /*! \brief Structure for a data store type */
  26. struct ast_datastore_info {
  27. const char *type; /*!< Type of data store */
  28. void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */
  29. void (*destroy)(void *data); /*!< Destroy function */
  30. /*!
  31. * \brief Fix up channel references on the masquerading channel
  32. *
  33. * \arg data The datastore data
  34. * \arg old_chan The old channel owning the datastore
  35. * \arg new_chan The new channel owning the datastore
  36. *
  37. * This is exactly like the fixup callback of the channel technology interface.
  38. * It allows a datastore to fix any pointers it saved to the owning channel
  39. * in case that the owning channel has changed. Generally, this would happen
  40. * when the datastore is set to be inherited, and a masquerade occurs.
  41. *
  42. * \return nothing.
  43. */
  44. void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan);
  45. /*!
  46. * \brief Fix up channel references on the channel being masqueraded into
  47. *
  48. * \arg data The datastore data
  49. * \arg old_chan The old channel owning the datastore
  50. * \arg new_chan The new channel owning the datastore
  51. *
  52. * This is the same as the above callback, except it is called for the channel
  53. * being masqueraded into instead of the channel that is masquerading.
  54. *
  55. * \return nothing.
  56. */
  57. void (*chan_breakdown)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan);
  58. };
  59. /*! \brief Structure for a data store object */
  60. struct ast_datastore {
  61. const char *uid; /*!< Unique data store identifier */
  62. void *data; /*!< Contained data */
  63. const struct ast_datastore_info *info; /*!< Data store type information */
  64. unsigned int inheritance; /*!< Number of levels this item will continue to be inherited */
  65. AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */
  66. };
  67. /*!
  68. * \brief Create a data store object
  69. * \param[in] info information describing the data store object
  70. * \param[in] uid unique identifer
  71. * \param file, line, function
  72. * \version 1.6.1 moved here and renamed from ast_channel_datastore_alloc
  73. */
  74. struct ast_datastore *__ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid,
  75. const char *file, int line, const char *function);
  76. #define ast_datastore_alloc(info, uid) __ast_datastore_alloc(info, uid, __FILE__, __LINE__, __PRETTY_FUNCTION__)
  77. /*!
  78. * \brief Free a data store object
  79. * \param[in] datastore datastore to free
  80. * \version 1.6.1 moved here and renamed from ast_channel_datastore_free
  81. */
  82. int ast_datastore_free(struct ast_datastore *datastore);
  83. #if defined(__cplusplus) || defined(c_plusplus)
  84. }
  85. #endif
  86. #endif /* _ASTERISK_DATASTORE_H */