jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
7.1KB

  1. /*
  2. Copyright (C) 2011 David Robillard
  3. Copyright (C) 2013 Paul Davis
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /**
  17. * @file jack/metadata.h
  18. * @ingroup publicheader
  19. * @brief JACK Metadata API
  20. *
  21. */
  22. #ifndef __jack_metadata_h__
  23. #define __jack_metadata_h__
  24. #include <jack/types.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /**
  29. * @defgroup Metadata Metadata API.
  30. * @{
  31. */
  32. /**
  33. * A single property (key:value pair).
  34. */
  35. typedef struct {
  36. /** The key of this property (URI string). */
  37. const char* key;
  38. /** The property value (null-terminated string). */
  39. const char* data;
  40. /**
  41. * Type of data, either a MIME type or URI.
  42. *
  43. * If type is NULL or empty, the data is assumed to be a UTF-8 encoded
  44. * string (text/plain). The data is a null-terminated string regardless of
  45. * type, so values can always be copied, but clients should not try to
  46. * interpret values of an unknown type.
  47. *
  48. * Example values:
  49. * - image/png;base64 (base64 encoded PNG image)
  50. * - http://www.w3.org/2001/XMLSchema#int (integer)
  51. *
  52. * Official types are preferred, but clients may use any syntactically
  53. * valid MIME type (which start with a type and slash, like "text/...").
  54. * If a URI type is used, it must be a complete absolute URI
  55. * (which start with a scheme and colon, like "http:").
  56. */
  57. const char* type;
  58. } jack_property_t;
  59. /**
  60. * Set a property on @p subject.
  61. *
  62. * See the above documentation for rules about @p subject and @p key.
  63. * @param subject The subject to set the property on.
  64. * @param key The key of the property.
  65. * @param value The value of the property.
  66. * @param type The type of the property. See the discussion of
  67. * types in the definition of jack_property_t above.
  68. * @return 0 on success.
  69. */
  70. int
  71. jack_set_property(jack_client_t*,
  72. jack_uuid_t subject,
  73. const char* key,
  74. const char* value,
  75. const char* type);
  76. /**
  77. * Get a property on @p subject.
  78. *
  79. * @param subject The subject to get the property from.
  80. * @param key The key of the property.
  81. * @param value Set to the value of the property if found, or NULL otherwise.
  82. * The caller must free this value with jack_free().
  83. * @param type The type of the property if set, or NULL. See the discussion
  84. * of types in the definition of jack_property_t above.
  85. * If non-null, the caller must free this value with jack_free().
  86. *
  87. * @return 0 on success, -1 if the @p subject has no @p key property.
  88. */
  89. int
  90. jack_get_property(jack_uuid_t subject,
  91. const char* key,
  92. char** value,
  93. char** type);
  94. /**
  95. * A description of a subject (a set of properties).
  96. */
  97. typedef struct {
  98. jack_uuid_t subject; /**< Subject being described. */
  99. uint32_t property_cnt; /**< Number of elements in "properties". */
  100. jack_property_t* properties; /**< Array of properties. */
  101. uint32_t property_size; /**< Private, do not use. */
  102. } jack_description_t;
  103. /**
  104. * Free a description.
  105. *
  106. * @param desc a jack_description_t whose associated memory will all be released
  107. * @param free_description_itself if non-zero, then @param desc will also be passed to free()
  108. */
  109. void
  110. jack_free_description (jack_description_t* desc, int free_description_itself);
  111. /**
  112. * Get a description of @p subject.
  113. * @param subject The subject to get all properties of.
  114. * @param desc Set to the description of subject if found, or NULL otherwise.
  115. * The caller must free this value with jack_free_description().
  116. * @return 0 on success, -1 if no @p subject with any properties exists.
  117. */
  118. int
  119. jack_get_properties (jack_uuid_t subject,
  120. jack_description_t* desc);
  121. /**
  122. * Get descriptions for all subjects with metadata.
  123. * @param descs Set to a NULL-terminated array of descriptions.
  124. * The caller must free each of these with jack_free_description(),
  125. * and the array itself with jack_free().
  126. * @return 0 on success.
  127. */
  128. int
  129. jack_get_all_properties (jack_description_t** descs);
  130. /**
  131. * Remove a single property on a subject.
  132. *
  133. * @param client The JACK client making the request to remove the property.
  134. * @param subject The subject to remove the property from.
  135. * @param key The key of the property to be removed.
  136. *
  137. * @return 0 on success, -1 otherwise
  138. */
  139. int jack_remove_property (jack_client_t* client, jack_uuid_t subject, const char* key);
  140. /**
  141. * Remove all properties on a subject.
  142. *
  143. * @param client The JACK client making the request to remove some properties.
  144. * @param subject The subject to remove all properties from.
  145. *
  146. * @return a count of the number of properties removed, or -1 on error.
  147. */
  148. int jack_remove_properties (jack_client_t* client, jack_uuid_t subject);
  149. /**
  150. * Remove all properties.
  151. *
  152. * WARNING!! This deletes all metadata managed by a running JACK server.
  153. * Data lost cannot be recovered (though it can be recreated by new calls
  154. * to jack_set_property()).
  155. *
  156. * @param client The JACK client making the request to remove all properties
  157. *
  158. * @return 0 on success, -1 otherwise
  159. */
  160. int jack_remove_all_properties (jack_client_t* client);
  161. typedef enum {
  162. PropertyCreated,
  163. PropertyChanged,
  164. PropertyDeleted
  165. } jack_property_change_t;
  166. typedef void (*JackPropertyChangeCallback)(jack_uuid_t subject,
  167. const char* key,
  168. jack_property_change_t change,
  169. void* arg);
  170. /**
  171. * Arrange for @p client to call @p callback whenever a property is created,
  172. * changed or deleted.
  173. *
  174. * @param client the JACK client making the request
  175. * @param callback the function to be invoked when a property change occurs
  176. * @param arg the argument to be passed to @param callback when it is invoked
  177. *
  178. * @return 0 success, -1 otherwise.
  179. */
  180. int jack_set_property_change_callback (jack_client_t* client,
  181. JackPropertyChangeCallback callback,
  182. void* arg);
  183. #ifdef __cplusplus
  184. } /* namespace */
  185. #endif
  186. /**
  187. * @}
  188. */
  189. extern const char* JACK_METADATA_PRETTY_NAME;
  190. extern const char* JACK_METADATA_HARDWARE;
  191. extern const char* JACK_METADATA_CONNECTED;
  192. extern const char* JACK_METADATA_PORT_GROUP;
  193. extern const char* JACK_METADATA_ICON_SMALL;
  194. extern const char* JACK_METADATA_ICON_LARGE;
  195. #endif /* __jack_metadata_h__ */