Skip to content

Commit 210edc5

Browse files
committed
Add support for metadata properties
Closes #40.
1 parent deb22cc commit 210edc5

File tree

5 files changed

+408
-5
lines changed

5 files changed

+408
-5
lines changed

doc/fake__jack.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class Fake(object):
2424
JackTransportStarting = 3
2525
JackTransportNetStarting = 4
2626

27+
PropertyCreated = 0
28+
PropertyChanged = 1
29+
PropertyDeleted = 2
30+
2731
def dlopen(self, _):
2832
return self
2933

examples/chatty_client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ def xrun(delay):
9393
print('xrun; delay', delay, 'microseconds')
9494

9595

96+
try:
97+
@client.set_property_change_callback
98+
def property_change(subject, key, changed):
99+
print('subject {}: '.format(subject), end='')
100+
if not key:
101+
assert changed == jack.PROPERTY_DELETED
102+
print('all properties were removed')
103+
return
104+
print('property {!r} was {}'.format(key, {
105+
jack.PROPERTY_CREATED: 'created',
106+
jack.PROPERTY_CHANGED: 'changed',
107+
jack.PROPERTY_DELETED: 'removed',
108+
}[changed]))
109+
except jack.JackError as e:
110+
print(e)
111+
112+
96113
print('activating JACK')
97114
with client:
98115
print('#' * 80)

examples/metadata.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
"""Set/get/remove client/port metadata."""
3+
from pprint import pprint
4+
5+
import jack
6+
7+
client = jack.Client('Metadata-Client')
8+
port = client.inports.register('input')
9+
10+
client.set_property(client.uuid, jack.METADATA_PRETTY_NAME, 'Best Client Ever')
11+
print('Client "pretty" name:',
12+
jack.get_property(client.uuid, jack.METADATA_PRETTY_NAME))
13+
14+
client.set_property(
15+
port.uuid, jack.METADATA_PRETTY_NAME, b'a good port', 'text/plain')
16+
print('Port "pretty" name:',
17+
jack.get_property(port.uuid, jack.METADATA_PRETTY_NAME))
18+
19+
print('All client properties:')
20+
pprint(jack.get_properties(client.uuid))
21+
22+
print('All port properties:')
23+
pprint(jack.get_properties(port.uuid))
24+
25+
print('All properties:')
26+
pprint(jack.get_all_properties())
27+
28+
client.remove_property(port.uuid, jack.METADATA_PRETTY_NAME)
29+
client.remove_properties(client.uuid)
30+
client.remove_all_properties()

jack_build.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,45 @@
244244
/* session.h */
245245
246246
char* jack_client_get_uuid(jack_client_t* client);
247+
248+
/* uuid.h */
249+
250+
extern int jack_uuid_parse(const char* buf, jack_uuid_t*);
251+
252+
/* metadata.h */
253+
254+
typedef struct {
255+
const char* key;
256+
const char* data;
257+
const char* type;
258+
} jack_property_t;
259+
int jack_set_property(jack_client_t*, jack_uuid_t subject, const char* key, const char* value, const char* type);
260+
int jack_get_property(jack_uuid_t subject, const char* key, char** value, char** type);
261+
typedef struct {
262+
jack_uuid_t subject;
263+
uint32_t property_cnt;
264+
jack_property_t* properties;
265+
uint32_t property_size;
266+
} jack_description_t;
267+
void jack_free_description(jack_description_t* desc, int free_description_itself);
268+
int jack_get_properties(jack_uuid_t subject, jack_description_t* desc);
269+
int jack_get_all_properties(jack_description_t** descs);
270+
int jack_remove_property(jack_client_t* client, jack_uuid_t subject, const char* key);
271+
int jack_remove_properties(jack_client_t* client, jack_uuid_t subject);
272+
int jack_remove_all_properties(jack_client_t* client);
273+
typedef enum {
274+
PropertyCreated,
275+
PropertyChanged,
276+
PropertyDeleted,
277+
} jack_property_change_t;
278+
typedef void (*JackPropertyChangeCallback)(jack_uuid_t subject, const char* key, jack_property_change_t change, void* arg);
279+
int jack_set_property_change_callback(jack_client_t* client, JackPropertyChangeCallback callback, void* arg);
280+
extern const char* JACK_METADATA_PRETTY_NAME;
281+
extern const char* JACK_METADATA_HARDWARE;
282+
extern const char* JACK_METADATA_CONNECTED;
283+
extern const char* JACK_METADATA_PORT_GROUP;
284+
extern const char* JACK_METADATA_ICON_SMALL;
285+
extern const char* JACK_METADATA_ICON_LARGE;
247286
""")
248287

249288
# Packed structure

0 commit comments

Comments
 (0)