SDL_properties.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. Simple DiretMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_properties.h
  20. *
  21. * Header file for SDL properties.
  22. */
  23. #ifndef SDL_properties_h_
  24. #define SDL_properties_h_
  25. #include <SDL3/SDL_begin_code.h>
  26. /* Set up for C function definitions, even when using C++ */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /**
  31. * SDL properties ID
  32. */
  33. typedef Uint32 SDL_PropertiesID;
  34. /**
  35. * Create a set of properties
  36. *
  37. * All properties are automatically destroyed when SDL_Quit() is called.
  38. *
  39. * \returns an ID for a new set of properties, or 0 on failure; call
  40. * SDL_GetError() for more information.
  41. *
  42. * \threadsafety It is safe to call this function from any thread.
  43. *
  44. * \since This function is available since SDL 3.0.0.
  45. *
  46. * \sa SDL_DestroyProperties
  47. */
  48. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);
  49. /**
  50. * Lock a set of properties
  51. *
  52. * Obtain a multi-threaded lock for these properties. Other threads will wait
  53. * while trying to lock these properties until they are unlocked. Properties
  54. * must be unlocked before they are destroyed.
  55. *
  56. * The lock is automatically taken when setting individual properties, this
  57. * function is only needed when you want to set several properties atomically
  58. * or want to guarantee that properties being queried aren't freed in another
  59. * thread.
  60. *
  61. * \param props the properties to lock
  62. * \returns 0 on success or a negative error code on failure; call
  63. * SDL_GetError() for more information.
  64. *
  65. * \threadsafety It is safe to call this function from any thread.
  66. *
  67. * \since This function is available since SDL 3.0.0.
  68. *
  69. * \sa SDL_UnlockProperties
  70. */
  71. extern DECLSPEC int SDLCALL SDL_LockProperties(SDL_PropertiesID props);
  72. /**
  73. * Unlock a set of properties
  74. *
  75. * \param props the properties to unlock
  76. *
  77. * \threadsafety It is safe to call this function from any thread.
  78. *
  79. * \since This function is available since SDL 3.0.0.
  80. *
  81. * \sa SDL_LockProperties
  82. */
  83. extern DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props);
  84. /**
  85. * Set a property on a set of properties
  86. *
  87. * \param props the properties to modify
  88. * \param name the name of the property to modify
  89. * \param value the new value of the property, or NULL to delete the property
  90. * \returns 0 on success or a negative error code on failure; call
  91. * SDL_GetError() for more information.
  92. *
  93. * \threadsafety It is safe to call this function from any thread.
  94. *
  95. * \since This function is available since SDL 3.0.0.
  96. *
  97. * \sa SDL_GetProperty
  98. * \sa SDL_SetPropertyWithCleanup
  99. */
  100. extern DECLSPEC int SDLCALL SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value);
  101. /**
  102. * Set a property on a set of properties with a cleanup function that is called when the property is deleted
  103. *
  104. * \param props the properties to modify
  105. * \param name the name of the property to modify
  106. * \param value the new value of the property, or NULL to delete the property
  107. * \param cleanup the function to call when this property is deleted, or NULL
  108. * if no cleanup is necessary
  109. * \param userdata a pointer that is passed to the cleanup function
  110. * \returns 0 on success or a negative error code on failure; call
  111. * SDL_GetError() for more information.
  112. *
  113. * \threadsafety It is safe to call this function from any thread.
  114. *
  115. * \since This function is available since SDL 3.0.0.
  116. *
  117. * \sa SDL_GetProperty
  118. * \sa SDL_SetProperty
  119. */
  120. extern DECLSPEC int SDLCALL SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata);
  121. /**
  122. * Get a property on a set of properties
  123. *
  124. * By convention, the names of properties that SDL exposes on objects will start with "SDL.", and properties that SDL uses internally will start with "SDL.internal.". These should be considered read-only and should not be modified by applications.
  125. *
  126. * \param props the properties to query
  127. * \param name the name of the property to query
  128. * \returns the value of the property, or NULL if it is not set.
  129. *
  130. * \threadsafety It is safe to call this function from any thread, although
  131. * the data returned is not protected and could potentially be
  132. * freed if you call SDL_SetProperty() or SDL_ClearProperty() on
  133. * these properties from another thread. If you need to avoid
  134. * this, use SDL_LockProperties() and SDL_UnlockProperties().
  135. *
  136. * \since This function is available since SDL 3.0.0.
  137. *
  138. * \sa SDL_SetProperty
  139. */
  140. extern DECLSPEC void *SDLCALL SDL_GetProperty(SDL_PropertiesID props, const char *name);
  141. /**
  142. * Clear a property on a set of properties
  143. *
  144. * \param props the properties to modify
  145. * \param name the name of the property to clear
  146. * \returns 0 on success or a negative error code on failure; call
  147. * SDL_GetError() for more information.
  148. *
  149. * \threadsafety It is safe to call this function from any thread.
  150. *
  151. * \since This function is available since SDL 3.0.0.
  152. *
  153. * \sa SDL_GetProperty
  154. */
  155. extern DECLSPEC int SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);
  156. /**
  157. * Destroy a set of properties
  158. *
  159. * All properties are deleted and their cleanup functions will be called, if
  160. * any.
  161. *
  162. * \param props the properties to destroy
  163. *
  164. * \threadsafety This function should not be called while these properties are
  165. * locked or other threads might be setting or getting values
  166. * from these properties.
  167. *
  168. * \since This function is available since SDL 3.0.0.
  169. *
  170. * \sa SDL_CreateProperties
  171. */
  172. extern DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props);
  173. /* Ends C function definitions when using C++ */
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #include <SDL3/SDL_close_code.h>
  178. #endif /* SDL_properties_h_ */