SDL_properties.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. * Get the global SDL properties
  36. *
  37. * \returns a valid property ID on success or 0 on failure; call
  38. * SDL_GetError() for more information.
  39. *
  40. * \since This function is available since SDL 3.0.0.
  41. *
  42. * \sa SDL_GetProperty
  43. * \sa SDL_SetProperty
  44. */
  45. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);
  46. /**
  47. * Create a set of properties
  48. *
  49. * All properties are automatically destroyed when SDL_Quit() is called.
  50. *
  51. * \returns an ID for a new set of properties, or 0 on failure; call
  52. * SDL_GetError() for more information.
  53. *
  54. * \threadsafety It is safe to call this function from any thread.
  55. *
  56. * \since This function is available since SDL 3.0.0.
  57. *
  58. * \sa SDL_DestroyProperties
  59. */
  60. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);
  61. /**
  62. * Lock a set of properties
  63. *
  64. * Obtain a multi-threaded lock for these properties. Other threads will wait
  65. * while trying to lock these properties until they are unlocked. Properties
  66. * must be unlocked before they are destroyed.
  67. *
  68. * The lock is automatically taken when setting individual properties, this
  69. * function is only needed when you want to set several properties atomically
  70. * or want to guarantee that properties being queried aren't freed in another
  71. * thread.
  72. *
  73. * \param props the properties to lock
  74. * \returns 0 on success or a negative error code on failure; call
  75. * SDL_GetError() for more information.
  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_UnlockProperties
  82. */
  83. extern DECLSPEC int SDLCALL SDL_LockProperties(SDL_PropertiesID props);
  84. /**
  85. * Unlock a set of properties
  86. *
  87. * \param props the properties to unlock
  88. *
  89. * \threadsafety It is safe to call this function from any thread.
  90. *
  91. * \since This function is available since SDL 3.0.0.
  92. *
  93. * \sa SDL_LockProperties
  94. */
  95. extern DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props);
  96. /**
  97. * Set a property on a set of properties
  98. *
  99. * \param props the properties to modify
  100. * \param name the name of the property to modify
  101. * \param value the new value of the property, or NULL to delete the property
  102. * \returns 0 on success or a negative error code on failure; call
  103. * SDL_GetError() for more information.
  104. *
  105. * \threadsafety It is safe to call this function from any thread.
  106. *
  107. * \since This function is available since SDL 3.0.0.
  108. *
  109. * \sa SDL_GetProperty
  110. * \sa SDL_SetPropertyWithCleanup
  111. */
  112. extern DECLSPEC int SDLCALL SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value);
  113. /**
  114. * Set a property on a set of properties with a cleanup function that is called when the property is deleted
  115. *
  116. * \param props the properties to modify
  117. * \param name the name of the property to modify
  118. * \param value the new value of the property, or NULL to delete the property
  119. * \param cleanup the function to call when this property is deleted, or NULL
  120. * if no cleanup is necessary
  121. * \param userdata a pointer that is passed to the cleanup function
  122. * \returns 0 on success or a negative error code on failure; call
  123. * SDL_GetError() for more information.
  124. *
  125. * \threadsafety It is safe to call this function from any thread.
  126. *
  127. * \since This function is available since SDL 3.0.0.
  128. *
  129. * \sa SDL_GetProperty
  130. * \sa SDL_SetProperty
  131. */
  132. extern DECLSPEC int SDLCALL SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata);
  133. /**
  134. * Get a property on a set of properties
  135. *
  136. * 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.
  137. *
  138. * \param props the properties to query
  139. * \param name the name of the property to query
  140. * \returns the value of the property, or NULL if it is not set.
  141. *
  142. * \threadsafety It is safe to call this function from any thread, although
  143. * the data returned is not protected and could potentially be
  144. * freed if you call SDL_SetProperty() or SDL_ClearProperty() on
  145. * these properties from another thread. If you need to avoid
  146. * this, use SDL_LockProperties() and SDL_UnlockProperties().
  147. *
  148. * \since This function is available since SDL 3.0.0.
  149. *
  150. * \sa SDL_SetProperty
  151. */
  152. extern DECLSPEC void *SDLCALL SDL_GetProperty(SDL_PropertiesID props, const char *name);
  153. /**
  154. * Clear a property on a set of properties
  155. *
  156. * \param props the properties to modify
  157. * \param name the name of the property to clear
  158. * \returns 0 on success or a negative error code on failure; call
  159. * SDL_GetError() for more information.
  160. *
  161. * \threadsafety It is safe to call this function from any thread.
  162. *
  163. * \since This function is available since SDL 3.0.0.
  164. *
  165. * \sa SDL_GetProperty
  166. */
  167. extern DECLSPEC int SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);
  168. /**
  169. * Destroy a set of properties
  170. *
  171. * All properties are deleted and their cleanup functions will be called, if
  172. * any.
  173. *
  174. * \param props the properties to destroy
  175. *
  176. * \threadsafety This function should not be called while these properties are
  177. * locked or other threads might be setting or getting values
  178. * from these properties.
  179. *
  180. * \since This function is available since SDL 3.0.0.
  181. *
  182. * \sa SDL_CreateProperties
  183. */
  184. extern DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props);
  185. /* Ends C function definitions when using C++ */
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #include <SDL3/SDL_close_code.h>
  190. #endif /* SDL_properties_h_ */