-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
-
344
-
345
-
346
-
347
-
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
-
403
-
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
-
438
-
439
-
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
-
470
-
471
-
472
-
473
-
474
-
475
-
476
-
477
-
478
-
479
-
480
-
481
-
482
-
483
-
484
-
485
-
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
-
496
-
497
-
498
-
499
-
500
-
501
-
502
-
503
-
504
-
505
-
506
-
507
-
508
-
509
-
510
-
511
-
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
-
520
-
521
-
522
-
523
-
524
-
525
-
526
-
527
-
528
-
529
-
530
-
531
-
532
-
533
-
534
-
535
-
536
-
537
-
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-
546
-
547
-
548
-
549
-
550
-
551
-
552
-
553
-
554
-
555
-
556
-
557
-
558
-
559
-
560
-
561
-
562
-
563
-
564
-
565
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
-
574
-
575
-
576
-
577
-
578
-
579
-
580
-
581
-
582
-
583
-
584
-
585
-
586
-
587
-
588
-
589
-
590
-
591
-
592
-
593
-
594
-
595
-
596
-
597
-
598
-
599
-
600
-
601
-
602
-
603
-
604
-
605
-
606
-
607
-
608
-
609
-
610
-
611
-
612
-
613
-
614
-
615
-
616
-
617
-
618
-
619
-
620
-
621
-
622
-
623
-
624
-
625
-
626
// Copyright 2025 Shota FUJI
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
const std = @import("std");
const rc = @import("../rc.zig");
const json = @import("../json.zig");
const allocator = std.heap.c_allocator;
pub const NowPlaying = rc.RefCounted(extern struct {
pub const cname = "roon_transport_NowPlaying";
has_seek_info: bool,
seek_position: u64,
length: u64,
image_key: ?[*:0]const u8,
one_line_1: [*:0]const u8,
two_line_1: [*:0]const u8,
two_line_2: ?[*:0]const u8,
three_line_1: [*:0]const u8,
three_line_2: ?[*:0]const u8,
three_line_3: ?[*:0]const u8,
pub const Raw = struct {
seek_position: ?u64,
length: ?u64,
image_key: ?[]const u8 = null,
one_line: struct {
line1: []const u8,
},
two_line: struct {
line1: []const u8,
line2: ?[]const u8 = null,
},
three_line: struct {
line1: []const u8,
line2: ?[]const u8 = null,
line3: ?[]const u8 = null,
},
};
pub fn init(raw: Raw) !@This() {
const image_key = if (raw.image_key) |slice| try allocator.dupeZ(u8, slice) else null;
errdefer if (image_key) |slice| allocator.free(slice);
const one_line_1 = try allocator.dupeZ(u8, raw.one_line.line1);
errdefer allocator.free(one_line_1);
const two_line_1 = try allocator.dupeZ(u8, raw.two_line.line1);
errdefer allocator.free(two_line_1);
const two_line_2 = if (raw.two_line.line2) |slice| try allocator.dupeZ(u8, slice) else null;
errdefer if (two_line_2) |slice| allocator.free(slice);
const three_line_1 = try allocator.dupeZ(u8, raw.three_line.line1);
errdefer allocator.free(three_line_1);
const three_line_2 = if (raw.three_line.line2) |slice| try allocator.dupeZ(u8, slice) else null;
errdefer if (three_line_2) |slice| allocator.free(slice);
const three_line_3 = if (raw.three_line.line3) |slice| try allocator.dupeZ(u8, slice) else null;
errdefer if (three_line_3) |slice| allocator.free(slice);
return .{
.has_seek_info = raw.length != null and raw.seek_position != null,
.seek_position = raw.seek_position orelse 0,
.length = raw.length orelse 0,
.image_key = if (image_key) |slice| slice.ptr else null,
.one_line_1 = one_line_1.ptr,
.two_line_1 = two_line_1.ptr,
.two_line_2 = if (two_line_2) |slice| slice.ptr else null,
.three_line_1 = three_line_1.ptr,
.three_line_2 = if (three_line_2) |slice| slice.ptr else null,
.three_line_3 = if (three_line_3) |slice| slice.ptr else null,
};
}
pub fn deinit(self: *const @This()) void {
if (self.three_line_3) |ptr| {
allocator.free(std.mem.span(ptr));
}
if (self.three_line_2) |ptr| {
allocator.free(std.mem.span(ptr));
}
allocator.free(std.mem.span(self.three_line_1));
if (self.two_line_2) |ptr| {
allocator.free(std.mem.span(ptr));
}
allocator.free(std.mem.span(self.two_line_1));
allocator.free(std.mem.span(self.one_line_1));
if (self.image_key) |ptr| {
allocator.free(std.mem.span(ptr));
}
}
});
pub const PlaybackState = enum(c_int) {
pub const cname = "roon_transport_PlaybackState";
playing,
paused,
loading,
stopped,
};
pub const OutputVolume = rc.RefCounted(extern struct {
pub const cname = "roon_transport_OutputVolume";
type: [*:0]const u8,
has_min: bool,
min: f64,
has_max: bool,
max: f64,
has_value: bool,
value: f64,
has_step: bool,
step: f64,
is_muted: bool,
pub const Raw = struct {
type: []const u8,
min: ?f64 = null,
max: ?f64 = null,
value: ?f64 = null,
step: ?f64 = null,
is_muted: bool = false,
};
pub fn init(raw: Raw) !@This() {
const @"type" = try allocator.dupeZ(u8, raw.type);
errdefer allocator.free(@"type");
return .{
.type = @"type".ptr,
.has_min = raw.min != null,
.min = raw.min orelse 0,
.has_max = raw.max != null,
.max = raw.max orelse 0,
.has_value = raw.value != null,
.value = raw.value orelse 0,
.has_step = raw.step != null,
.step = raw.step orelse 0,
.is_muted = raw.is_muted,
};
}
pub fn deinit(self: *const @This()) void {
allocator.free(std.mem.span(self.type));
}
});
pub const Output = rc.RefCounted(extern struct {
pub const cname = "roon_transport_Output";
output_id: [*:0]const u8,
display_name: [*:0]const u8,
volume: ?*OutputVolume,
pub const Raw = struct {
output_id: []const u8,
display_name: []const u8,
volume: ?OutputVolume.Data.Raw = null,
};
pub fn init(raw: Raw) !@This() {
const output_id = try allocator.dupeZ(u8, raw.output_id);
errdefer allocator.free(output_id);
const display_name = try allocator.dupeZ(u8, raw.display_name);
errdefer allocator.free(display_name);
const volume = if (raw.volume) |volume_raw| try OutputVolume.new(try .init(volume_raw)) else null;
errdefer if (volume) |ptr| ptr.release();
return .{
.output_id = output_id.ptr,
.display_name = display_name,
.volume = volume,
};
}
pub fn deinit(self: *const @This()) void {
if (self.volume) |volume| {
volume.release();
}
allocator.free(std.mem.span(self.display_name));
allocator.free(std.mem.span(self.output_id));
}
});
pub const Zone = rc.RefCounted(extern struct {
pub const cname = "roon_transport_Zone";
zone_id: [*:0]const u8,
display_name: [*:0]const u8,
outputs_ptr: [*]*Output,
outputs_len: usize,
now_playing: ?*NowPlaying,
state: PlaybackState,
is_next_allowed: bool,
is_previous_allowed: bool,
is_pause_allowed: bool,
is_play_allowed: bool,
is_seek_allowed: bool,
pub const Raw = struct {
zone_id: []const u8,
display_name: []const u8,
outputs: []const Output.Data.Raw,
now_playing: ?NowPlaying.Data.Raw = null,
state: PlaybackState,
is_next_allowed: bool = false,
is_previous_allowed: bool = false,
is_pause_allowed: bool = false,
is_play_allowed: bool = false,
is_seek_allowed: bool = false,
};
pub fn init(raw: Raw) !@This() {
const zone_id = try allocator.dupeZ(u8, raw.zone_id);
errdefer allocator.free(zone_id);
const display_name = try allocator.dupeZ(u8, raw.display_name);
errdefer allocator.free(display_name);
const outputs = try allocator.alloc(*Output, raw.outputs.len);
errdefer allocator.free(outputs);
var i: usize = 0;
errdefer {
for (0..i) |j| {
outputs[j].release();
}
}
for (raw.outputs) |output| {
outputs[i] = try Output.new(try .init(output));
i += 1;
}
const now_playing = if (raw.now_playing) |n| try NowPlaying.new(try .init(n)) else null;
errdefer if (now_playing) |n| n.release();
return .{
.zone_id = zone_id.ptr,
.display_name = display_name.ptr,
.outputs_ptr = outputs.ptr,
.outputs_len = outputs.len,
.now_playing = now_playing,
.state = raw.state,
.is_next_allowed = raw.is_next_allowed,
.is_previous_allowed = raw.is_previous_allowed,
.is_pause_allowed = raw.is_pause_allowed,
.is_play_allowed = raw.is_play_allowed,
.is_seek_allowed = raw.is_seek_allowed,
};
}
pub fn deinit(self: *const @This()) void {
if (self.now_playing) |now_playing| {
now_playing.release();
}
for (self.outputs_ptr[0..self.outputs_len]) |output| {
output.release();
}
allocator.free(self.outputs_ptr[0..self.outputs_len]);
allocator.free(std.mem.span(self.display_name));
allocator.free(std.mem.span(self.zone_id));
}
});
pub const SeekChange = rc.RefCounted(extern struct {
pub const cname = "roon_transport_SeekChange";
zone_id: [*:0]const u8,
has_seek_position: bool,
seek_position: u64,
pub const Raw = struct {
zone_id: []const u8,
seek_position: ?u64 = null,
};
pub fn init(raw: Raw) !@This() {
const zone_id = try allocator.dupeZ(u8, raw.zone_id);
errdefer allocator.free(zone_id);
return .{
.zone_id = zone_id,
.has_seek_position = raw.seek_position != null,
.seek_position = raw.seek_position orelse 0,
};
}
pub fn deinit(self: *const @This()) void {
allocator.free(std.mem.span(self.zone_id));
}
});
pub const ControlType = enum(c_int) {
pub const cname = "roon_transport_ControlType";
play,
pause,
playpause,
stop,
previous,
next,
};
pub const SeekMode = enum(c_int) {
pub const cname = "roon_transport_SeekMode";
relative,
absolute,
};
pub const ChangeVolumeMode = enum(c_int) {
pub const cname = "roon_transport_ChangeVolumeMode";
absolute,
relative,
relative_step,
};
pub const SubscribeZoneChanges = struct {
pub const Request = json.Serializable(rc.RefCounted(struct {
pub const cname = "roon_transport_SubscribeZoneChanges_Request";
subscription_key: []const u8,
pub fn init(subscription_id: []const u8) @This() {
return .{ .subscription_key = subscription_id };
}
pub fn deinit(self: *const @This()) void {
allocator.free(self.subscription_key);
}
}), .{});
export fn roon_transport_SubscribeZoneChanges_Request_new(
subscription_id: [*:0]const u8,
) callconv(.C) ?*Request {
const copy = allocator.dupe(u8, std.mem.span(subscription_id)) catch {
std.log.err("Unable to copy subscription_id: out of memory", .{});
return null;
};
return Request.new(.init(copy)) catch {
std.log.err("Unable to create SubscribeZoneChange request: out of memory", .{});
allocator.free(copy);
return null;
};
}
pub const Response = json.Deserializable(rc.RefCounted(extern struct {
pub const cname = "roon_transport_SubscribeZoneChanges_Response";
pub const deserializable = true;
zones_ptr: [*]*Zone,
zones_len: usize,
pub const Raw = struct {
zones: []const Zone.Data.Raw,
};
pub fn init(raw: Raw) !@This() {
const zones = try allocator.alloc(*Zone, raw.zones.len);
errdefer allocator.free(zones);
var i: usize = 0;
errdefer {
for (0..i) |j| {
zones[j].release();
}
}
for (raw.zones) |zone| {
zones[i] = try Zone.new(try .init(zone));
i += 1;
}
return .{
.zones_ptr = zones.ptr,
.zones_len = zones.len,
};
}
pub fn deinit(self: *const @This()) void {
for (self.zones_ptr[0..self.zones_len]) |zone| {
zone.release();
}
allocator.free(self.zones_ptr[0..self.zones_len]);
}
}), .{});
pub const Event = json.Deserializable(rc.RefCounted(extern struct {
pub const cname = "roon_transport_SubscribeZoneChanges_Event";
pub const deserializable = true;
removed_zone_ids_ptr: [*][*:0]const u8,
removed_zone_ids_len: usize,
added_zones_ptr: [*]*Zone,
added_zones_len: usize,
changed_zones_ptr: [*]*Zone,
changed_zones_len: usize,
seek_changes_ptr: [*]*SeekChange,
seek_changes_len: usize,
pub const Raw = struct {
zones_removed: []const []const u8 = &.{},
zones_added: []const Zone.Data.Raw = &.{},
zones_changed: []const Zone.Data.Raw = &.{},
zones_seek_changed: []const SeekChange.Data.Raw = &.{},
};
pub fn init(raw: Raw) !@This() {
const removed_zone_ids = try allocator.alloc([*:0]const u8, raw.zones_removed.len);
errdefer allocator.free(removed_zone_ids);
var duped_removed_zone_ids: usize = 0;
errdefer {
for (0..duped_removed_zone_ids) |i| {
allocator.free(std.mem.span(removed_zone_ids[i]));
}
}
for (raw.zones_removed, 0..) |id, i| {
removed_zone_ids[i] = try allocator.dupeZ(u8, id);
duped_removed_zone_ids = i;
}
const added_zones = try allocator.alloc(*Zone, raw.zones_added.len);
errdefer allocator.free(added_zones);
var retained_added_zones: usize = 0;
errdefer {
for (0..retained_added_zones) |i| {
added_zones[i].release();
}
}
for (raw.zones_added, 0..) |zone, i| {
added_zones[i] = try Zone.new(try .init(zone));
retained_added_zones = i;
}
const changed_zones = try allocator.alloc(*Zone, raw.zones_changed.len);
errdefer allocator.free(changed_zones);
var retained_changed_zones: usize = 0;
errdefer {
for (0..retained_changed_zones) |i| {
changed_zones[i].release();
}
}
for (raw.zones_changed, 0..) |zone, i| {
changed_zones[i] = try Zone.new(try .init(zone));
retained_changed_zones = i;
}
const seek_changes = try allocator.alloc(*SeekChange, raw.zones_seek_changed.len);
errdefer allocator.free(seek_changes);
var retained_seek_changes: usize = 0;
errdefer {
for (0..retained_seek_changes) |i| {
seek_changes[i].release();
}
}
for (raw.zones_seek_changed, 0..) |seek_change, i| {
seek_changes[i] = try SeekChange.new(try .init(seek_change));
retained_seek_changes = i;
}
return .{
.removed_zone_ids_ptr = removed_zone_ids.ptr,
.removed_zone_ids_len = removed_zone_ids.len,
.added_zones_ptr = added_zones.ptr,
.added_zones_len = added_zones.len,
.changed_zones_ptr = changed_zones.ptr,
.changed_zones_len = changed_zones.len,
.seek_changes_ptr = seek_changes.ptr,
.seek_changes_len = seek_changes.len,
};
}
pub fn deinit(self: *const @This()) void {
for (self.seek_changes_ptr[0..self.seek_changes_len]) |seek_change| {
seek_change.release();
}
allocator.free(self.seek_changes_ptr[0..self.seek_changes_len]);
for (self.changed_zones_ptr[0..self.changed_zones_len]) |zone| {
zone.release();
}
allocator.free(self.changed_zones_ptr[0..self.changed_zones_len]);
for (self.added_zones_ptr[0..self.added_zones_len]) |zone| {
zone.release();
}
allocator.free(self.added_zones_ptr[0..self.added_zones_len]);
for (self.removed_zone_ids_ptr[0..self.removed_zone_ids_len]) |id| {
allocator.free(std.mem.span(id));
}
allocator.free(self.removed_zone_ids_ptr[0..self.removed_zone_ids_len]);
}
}), .{});
};
pub const Control = struct {
pub const Request = json.Serializable(rc.RefCounted(struct {
pub const cname = "roon_transport_Control_Request";
zone_or_output_id: []const u8,
control: ControlType,
pub fn init(zone_or_output_id: []const u8, control: ControlType) @This() {
return .{
.zone_or_output_id = zone_or_output_id,
.control = control,
};
}
pub fn deinit(self: *const @This()) void {
allocator.free(self.zone_or_output_id);
}
}), .{});
export fn roon_transport_Control_Request_new(
zone_or_output_id: [*:0]const u8,
control: ControlType,
) callconv(.C) ?*Request {
const copy = allocator.dupe(u8, std.mem.span(zone_or_output_id)) catch {
std.log.err("Unable to copy zone_or_output_id: out of memory", .{});
return null;
};
return Request.new(.init(copy, control)) catch {
std.log.err("Unable to create Control request: out of memory", .{});
allocator.free(copy);
return null;
};
}
};
pub const Seek = struct {
pub const Request = json.Serializable(rc.RefCounted(struct {
pub const cname = "roon_transport_Seek_Request";
zone_or_output_id: []const u8,
how: SeekMode = .relative,
seconds: i64 = 0,
pub fn init(zone_or_output_id: []const u8) @This() {
return .{ .zone_or_output_id = zone_or_output_id };
}
pub fn deinit(self: *const @This()) void {
allocator.free(self.zone_or_output_id);
}
}), .{});
export fn roon_transport_Seek_Request_new(zone_or_output_id: [*:0]const u8) callconv(.C) ?*Request {
const copy = allocator.dupe(u8, std.mem.span(zone_or_output_id)) catch {
std.log.err("Unable to copy zone_or_output_id: out of memory", .{});
return null;
};
return Request.new(.init(copy)) catch {
std.log.err("Unable to create Seek request: out of memory", .{});
allocator.free(copy);
return null;
};
}
};
pub const ChangeVolume = struct {
pub const Request = json.Serializable(rc.RefCounted(struct {
pub const cname = "roon_transport_ChangeVolume_Request";
output_id: []const u8,
how: ChangeVolumeMode = .relative,
value: f64 = 0,
pub fn init(output_id: []const u8) @This() {
return .{ .output_id = output_id };
}
pub fn deinit(self: *const @This()) void {
allocator.free(self.output_id);
}
}), .{});
export fn roon_transport_ChangeVolume_Request_new(output_id: [*:0]const u8) callconv(.C) ?*Request {
const copy = allocator.dupe(u8, std.mem.span(output_id)) catch {
std.log.err("Unable to copy output_id: out of memory", .{});
return null;
};
return Request.new(.init(copy)) catch {
std.log.err("Unable to create ChangeVolume request: out of memory", .{});
allocator.free(copy);
return null;
};
}
};