JACK API headers
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.

207 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. #ifndef __jack_metadata_h__
  17. #define __jack_metadata_h__
  18. #include <jack/types.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @defgroup Metadata Metadata API.
  24. * @{
  25. */
  26. /**
  27. * A single property (key:value pair).
  28. */
  29. typedef struct {
  30. const char* key; /**< The key of this property (URI string). */
  31. const char* data; /**< The property value (null-terminated string) */
  32. const char* type; /**< MIME type of data. Likely values are:
  33. *
  34. * text/utf8 (for an null terminated string)
  35. * image/png;base64 (for a data-URI converted image)
  36. *
  37. * If type is null (or empty), the type should
  38. * be assumed to be "text/utf8" and the memory
  39. * pointed to by "data" should be interpreted
  40. * as a null-terminated string encoded using UTF-8.
  41. *
  42. * If the type is image/png;base64, the memory
  43. * pointed to by "data" should be interpreted as
  44. * a base64 encoded PNG image.
  45. *
  46. * Other types are subject to the shared understanding
  47. * of the mime type by both the setter and retriever
  48. * of the property.
  49. */
  50. } jack_property_t;
  51. /**
  52. * Set a property on @c subject.
  53. *
  54. * See the above documentation for rules about @c subject and @c key.
  55. * @param subject The subject to set the property on.
  56. * @param key The key of the property.
  57. * @param value The value of the property.
  58. * @param type The MIME type of the property. See the discussion of
  59. * types in the definition of jack_property_t above.
  60. * @return 0 on success.
  61. */
  62. int
  63. jack_set_property(jack_client_t*,
  64. jack_uuid_t subject,
  65. const char* key,
  66. const char* value,
  67. const char* type);
  68. /**
  69. * Get a property on @c subject.
  70. *
  71. * @param subject The subject to get the property from.
  72. * @param key The key of the property.
  73. * @param value Set to the value of the property if found, or NULL otherwise.
  74. * The caller must free this value with jack_free().
  75. * @param type The MIME type of the property if set, or
  76. * NULL. See the discussion of types in the definition of
  77. * jack_property_t above. If non-null, the caller must free
  78. * this value with jack_free().
  79. *
  80. * @return 0 on success, -1 if the @c subject has no @c key property.
  81. */
  82. int
  83. jack_get_property(jack_uuid_t subject,
  84. const char* key,
  85. char** value,
  86. char** type);
  87. /**
  88. * A description of a subject (a set of properties).
  89. */
  90. typedef struct {
  91. jack_uuid_t subject; /**< The subject being described. */
  92. uint32_t property_cnt;/**< The number of properties stored in "properties" */
  93. jack_property_t* properties; /**< An array of properties. */
  94. uint32_t property_size; /**< private, don't use or touch */
  95. } jack_description_t;
  96. /**
  97. * Free a description.
  98. *
  99. * @param desc a jack_description_t whose associated memory will all be released
  100. * @param free_description_itself if non-zero, then @param desc will also be passed to free()
  101. */
  102. void
  103. jack_free_description(jack_description_t* desc, int free_description_itself);
  104. /**
  105. * Get a description of @c subject.
  106. * @param subject The subject to get all properties of.
  107. * @param desc Set to the description of subject if found, or NULL otherwise.
  108. * The caller must free this value with jack_free_desription().
  109. * @return 0 on success, -1 if no @c subject with any properties exists.
  110. */
  111. int
  112. jack_get_properties (jack_uuid_t subject,
  113. jack_description_t* desc);
  114. /**
  115. * Get descriptions for all subjects with metadata.
  116. * @param subject The subject to get all properties of.
  117. * @param descs Set to a NULL-terminated array of descriptions.
  118. * The caller must free each of these with jack_free_desription(),
  119. * and the array itself with jack_free().
  120. * @return 0 on success.
  121. */
  122. int
  123. jack_get_all_properties (jack_description_t** descs);
  124. /** Remove a single property on a subject
  125. *
  126. * @param client The JACK client making the request to remove the property.
  127. * @param subject The subject to remove the property from.
  128. * @param key The key of the property to be removed.
  129. *
  130. * @return 0 on success, -1 otherwise
  131. */
  132. int jack_remove_property (jack_client_t*, jack_uuid_t subject, const char* key);
  133. /** Remove all properties on a subject
  134. *
  135. * @param client The JACK client making the request to remove some properties.
  136. * @param subject The subject to remove all properties from.
  137. *
  138. * @return a count of the number of properties removed, or -1 if an error occurs
  139. */
  140. int jack_remove_properties (jack_client_t*, jack_uuid_t subject);
  141. /** Remove all properties
  142. *
  143. * WARNING!! This deletes all metadata managed by a running JACK server.
  144. * Data lost cannot be recovered (though it can be recreated by new calls
  145. * to jack_set_property()).
  146. *
  147. * @param client The JACK client making the request to remove all properties
  148. *
  149. * @return 0 on success, -1 otherwise
  150. */
  151. int jack_remove_all_properties (jack_client_t*);
  152. typedef enum {
  153. PropertyCreated,
  154. PropertyChanged,
  155. PropertyDeleted
  156. } jack_property_change_t;
  157. typedef void (*JackPropertyChangeCallback)(jack_uuid_t subject,
  158. const char* key,
  159. jack_property_change_t change,
  160. void* arg);
  161. /** Arrange for @param client to call @param callback whenever
  162. * a property is created, changed or deleted.
  163. *
  164. * @return 0 success, -1 otherwise.
  165. */
  166. int jack_set_property_change_callback (jack_client_t* client,
  167. JackPropertyChangeCallback callback,
  168. void *arg);
  169. #ifdef __cplusplus
  170. } /* namespace */
  171. #endif
  172. /**
  173. * @}
  174. */
  175. extern const char* JACK_METADATA_PRETTY_NAME;
  176. extern const char* JACK_METADATA_HARDWARE;
  177. extern const char* JACK_METADATA_CONNECTED;
  178. extern const char* JACK_METADATA_PORT_GROUP;
  179. extern const char* JACK_METADATA_ICON_SMALL;
  180. extern const char* JACK_METADATA_ICON_LARGE;
  181. #endif /* __jack_metadata_h__ */