8 #include <jack/metadata.h>
10 #include <jack/session.h>
12 static int subject_is_client
= 0;
13 static int subject_is_port
= 0;
14 static jack_uuid_t uuid
= JACK_UUID_EMPTY_INITIALIZER
;
15 static char* subject
= NULL
;
20 fprintf (stderr
, "\nUsage: jack_property [options] UUID [ key [ value [ type ] ] ]\n");
21 fprintf (stderr
, "Set/Display JACK properties (metadata).\n\n");
22 fprintf (stderr
, "Set options:\n");
23 fprintf (stderr
, " -s, --set Set property \"key\" to \"value\" for \"UUID\" with optional MIME type \"type\"\n");
24 fprintf (stderr
, " -d, --delete Remove/delete property \"key\" for \"UUID\"\n");
25 fprintf (stderr
, " -d, --delete UUID Remove/delete all properties for \"UUID\"\n");
26 fprintf (stderr
, " -D, --delete-all Remove/delete all properties\n");
27 fprintf (stderr
, " --client Interpret UUID as a client name, not a UUID\n");
28 fprintf (stderr
, " --port \tInterpret UUID as a port name, not a UUID\n");
29 fprintf (stderr
, "\nDisplay options:\n");
30 fprintf (stderr
, " -l Show all properties\n");
31 fprintf (stderr
, " -l, --list UUID \tShow value for all properties of UUID\n");
32 fprintf (stderr
, " -l, --list UUID key Show value for key of UUID\n");
33 fprintf (stderr
, "\nFor more information see https://jackaudio.org/\n");
37 get_subject (jack_client_t
* client
, char* argv
[], int* optind
)
39 if (subject_is_client
) {
40 char* cstr
= argv
[(*optind
)++];
43 if ((ustr
= jack_get_uuid_for_client_name (client
, cstr
)) == NULL
) {
44 fprintf (stderr
, "cannot get UUID for client named %s\n", cstr
);
48 if (jack_uuid_parse (ustr
, &uuid
)) {
49 fprintf (stderr
, "cannot parse client UUID as UUID '%s' '%s'\n", cstr
, ustr
);
55 } else if (subject_is_port
) {
57 char* pstr
= argv
[(*optind
)++];
60 if ((port
= jack_port_by_name (client
, pstr
)) == NULL
) {
61 fprintf (stderr
, "cannot find port name %s\n", pstr
);
65 uuid
= jack_port_uuid (port
);
69 char* str
= argv
[(*optind
)++];
71 if (jack_uuid_parse (str
, &uuid
)) {
72 fprintf (stderr
, "cannot parse subject as UUID\n");
82 int main (int argc
, char* argv
[])
84 jack_client_t
* client
= NULL
;
85 jack_options_t options
= JackNoStartServer
;
95 struct option long_options
[] = {
97 { "delete", 0, 0, 'd' },
98 { "delete-all", 0, 0, 'D' },
99 { "list", 0, 0, 'l' },
100 { "client", 0, 0, 'c' },
101 { "port", 0, 0, 'p' },
110 while ((c
= getopt_long (argc
, argv
, "sdDlaApc", long_options
, &option_index
)) >= 0) {
145 subject_is_client
= 1;
155 if ((client
= jack_client_open ("jack-property", options
, NULL
)) == 0) {
156 fprintf (stderr
, "Cannot connect to JACK server\n");
162 if (jack_remove_all_properties (client
) == 0) {
163 printf ("JACK metadata successfully delete\n");
171 int args_left
= argc
- optind
;
178 /* argc == 3: delete all properties for a subject
179 argc == 4: delete value of key for subject
182 if (args_left
>= 2) {
184 if (get_subject (client
, argv
, &optind
)) {
188 key
= argv
[optind
++];
190 if (jack_remove_property (client
, uuid
, key
)) {
191 fprintf (stderr
, "\"%s\" property not removed for %s\n", key
, subject
);
197 if (get_subject (client
, argv
, &optind
)) {
201 if (jack_remove_properties (client
, uuid
) < 0) {
202 fprintf (stderr
, "cannot remove properties for UUID %s\n", subject
);
209 int args_left
= argc
- optind
;
211 if (get_subject (client
, argv
, &optind
)) {
215 key
= argv
[optind
++];
216 value
= argv
[optind
++];
218 if (args_left
>= 3) {
219 type
= argv
[optind
++];
224 if (jack_set_property (client
, uuid
, key
, value
, type
)) {
225 fprintf (stderr
, "cannot set value for key %s of %s\n", key
, subject
);
231 /* list properties */
233 int args_left
= argc
- optind
;
235 if (args_left
>= 2) {
237 /* list properties for a UUID/key pair */
239 if (get_subject (client
, argv
, &optind
)) {
243 key
= argv
[optind
++];
245 if (jack_get_property (uuid
, key
, &value
, &type
) == 0) {
246 printf ("%s\n", value
);
252 fprintf (stderr
, "Value not found for %s of %s\n", key
, subject
);
256 } else if (args_left
== 1) {
258 /* list all properties for a given UUID */
260 jack_description_t description
;
263 if (get_subject (client
, argv
, &optind
)) {
267 if ((cnt
= jack_get_properties (uuid
, &description
)) < 0) {
268 fprintf (stderr
, "could not retrieve properties for %s\n", subject
);
272 for (n
= 0; n
< cnt
; ++n
) {
273 if (description
.properties
[n
].type
) {
274 printf ("key: %s value: %s type: %s\n",
275 description
.properties
[n
].key
,
276 description
.properties
[n
].data
,
277 description
.properties
[n
].type
);
279 printf ("key: %s value: %s\n",
280 description
.properties
[n
].key
,
281 description
.properties
[n
].data
);
285 jack_free_description (&description
, 0);
289 /* list all properties */
291 jack_description_t
* description
;
294 char buf
[JACK_UUID_STRING_SIZE
];
296 if ((cnt
= jack_get_all_properties (&description
)) < 0) {
297 fprintf (stderr
, "could not retrieve all properties\n");
301 for (n
= 0; n
< cnt
; ++n
) {
302 jack_uuid_unparse (description
[n
].subject
, buf
);
303 printf ("%s\n", buf
);
304 for (p
= 0; p
< description
[n
].property_cnt
; ++p
) {
305 if (description
[n
].properties
[p
].type
) {
306 printf ("key: %s value: %s type: %s\n",
307 description
[n
].properties
[p
].key
,
308 description
[n
].properties
[p
].data
,
309 description
[n
].properties
[p
].type
);
311 printf ("key: %s value: %s\n",
312 description
[n
].properties
[p
].key
,
313 description
[n
].properties
[p
].data
);
316 jack_free_description (&description
[n
], 0);
324 (void) jack_client_close (client
);