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.

213 lines
6.9KB

  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. /** The key of this property (URI string). */
  31. const char* key;
  32. /** The property value (null-terminated string). */
  33. const char* data;
  34. /**
  35. * Type of data, either a MIME type or URI.
  36. *
  37. * If type is NULL or empty, the data is assumed to be a UTF-8 encoded
  38. * string (text/plain). The data is a null-terminated string regardless of
  39. * type, so values can always be copied, but clients should not try to
  40. * interpret values of an unknown type.
  41. *
  42. * Example values:
  43. * - image/png;base64 (base64 encoded PNG image)
  44. * - http://www.w3.org/2001/XMLSchema#int (integer)
  45. *
  46. * Official types are preferred, but clients may use any syntactically
  47. * valid MIME type (which start with a type and slash, like "text/...").
  48. * If a URI type is used, it must be a complete absolute URI
  49. * (which start with a scheme and colon, like "http:").
  50. */
  51. const char* type;
  52. } jack_property_t;
  53. /**
  54. * Set a property on @p subject.
  55. *
  56. * See the above documentation for rules about @p subject and @p key.
  57. * @param subject The subject to set the property on.
  58. * @param key The key of the property.
  59. * @param value The value of the property.
  60. * @param type The type of the property. See the discussion of
  61. * types in the definition of jack_property_t above.
  62. * @return 0 on success.
  63. */
  64. int
  65. jack_set_property(jack_client_t*,
  66. jack_uuid_t subject,
  67. const char* key,
  68. const char* value,
  69. const char* type);
  70. /**
  71. * Get a property on @p subject.
  72. *
  73. * @param subject The subject to get the property from.
  74. * @param key The key of the property.
  75. * @param value Set to the value of the property if found, or NULL otherwise.
  76. * The caller must free this value with jack_free().
  77. * @param type The type of the property if set, or NULL. See the discussion
  78. * of types in the definition of jack_property_t above.
  79. * If non-null, the caller must free this value with jack_free().
  80. *
  81. * @return 0 on success, -1 if the @p subject has no @p key property.
  82. */
  83. int
  84. jack_get_property(jack_uuid_t subject,
  85. const char* key,
  86. char** value,
  87. char** type);
  88. /**
  89. * A description of a subject (a set of properties).
  90. */
  91. typedef struct {
  92. jack_uuid_t subject; /**< Subject being described. */
  93. uint32_t property_cnt; /**< Number of elements in "properties". */
  94. jack_property_t* properties; /**< Array of properties. */
  95. uint32_t property_size; /**< Private, do not use. */
  96. } jack_description_t;
  97. /**
  98. * Free a description.
  99. *
  100. * @param desc a jack_description_t whose associated memory will all be released
  101. * @param free_description_itself if non-zero, then @param desc will also be passed to free()
  102. */
  103. void
  104. jack_free_description (jack_description_t* desc, int free_description_itself);
  105. /**
  106. * Get a description of @p subject.
  107. * @param subject The subject to get all properties of.
  108. * @param desc Set to the description of subject if found, or NULL otherwise.
  109. * The caller must free this value with jack_free_desription().
  110. * @return 0 on success, -1 if no @p subject with any properties exists.
  111. */
  112. int
  113. jack_get_properties (jack_uuid_t subject,
  114. jack_description_t* desc);
  115. /**
  116. * Get descriptions for all subjects with metadata.
  117. * @param subject The subject to get all properties of.
  118. * @param descs Set to a NULL-terminated array of descriptions.
  119. * The caller must free each of these with jack_free_desription(),
  120. * and the array itself with jack_free().
  121. * @return 0 on success.
  122. */
  123. int
  124. jack_get_all_properties (jack_description_t** descs);
  125. /**
  126. * Remove a single property on a subject.
  127. *
  128. * @param client The JACK client making the request to remove the property.
  129. * @param subject The subject to remove the property from.
  130. * @param key The key of the property to be removed.
  131. *
  132. * @return 0 on success, -1 otherwise
  133. */
  134. int jack_remove_property (jack_client_t*, jack_uuid_t subject, const char* key);
  135. /**
  136. * Remove all properties on a subject.
  137. *
  138. * @param client The JACK client making the request to remove some properties.
  139. * @param subject The subject to remove all properties from.
  140. *
  141. * @return a count of the number of properties removed, or -1 on error.
  142. */
  143. int jack_remove_properties (jack_client_t*, jack_uuid_t subject);
  144. /**
  145. * Remove all properties.
  146. *
  147. * WARNING!! This deletes all metadata managed by a running JACK server.
  148. * Data lost cannot be recovered (though it can be recreated by new calls
  149. * to jack_set_property()).
  150. *
  151. * @param client The JACK client making the request to remove all properties
  152. *
  153. * @return 0 on success, -1 otherwise
  154. */
  155. int jack_remove_all_properties (jack_client_t*);
  156. typedef enum {
  157. PropertyCreated,
  158. PropertyChanged,
  159. PropertyDeleted
  160. } jack_property_change_t;
  161. typedef void (*JackPropertyChangeCallback)(jack_uuid_t subject,
  162. const char* key,
  163. jack_property_change_t change,
  164. void* arg);
  165. /**
  166. * Arrange for @p client to call @p callback whenever a property is created,
  167. * changed or deleted.
  168. *
  169. * @return 0 success, -1 otherwise.
  170. */
  171. int jack_set_property_change_callback (jack_client_t* client,
  172. JackPropertyChangeCallback callback,
  173. void* arg);
  174. #ifdef __cplusplus
  175. } /* namespace */
  176. #endif
  177. /**
  178. * @}
  179. */
  180. extern const char* JACK_METADATA_PRETTY_NAME;
  181. extern const char* JACK_METADATA_HARDWARE;
  182. extern const char* JACK_METADATA_CONNECTED;
  183. extern const char* JACK_METADATA_PORT_GROUP;
  184. extern const char* JACK_METADATA_ICON_SMALL;
  185. extern const char* JACK_METADATA_ICON_LARGE;
  186. #endif /* __jack_metadata_h__ */