Changes
5 changed files (+470/-10)
-
-
@@ -26,6 +26,7 @@ double: void,char: void, bool: void, void: void, string: void, custom: []const u8, pub fn fromZigType(comptime T: type) CBaseType {
-
@@ -47,6 +48,10 @@ .void => .void,.pointer => |pointer| switch (@typeInfo(pointer.child)) { .@"struct" => .{ .custom = pointer.child.cname }, else => { if (pointer.child == u8 and pointer.is_const and pointer.size == .many and std.builtin.Type.Pointer.sentinel(pointer) == 0) { return .string; } @compileError( std.fmt.comptimePrint("Pointer to non-struct type {s} is not exportable.", .{@typeName(T)}), );
-
@@ -77,10 +82,7 @@ pointer.size == .many andstd.builtin.Type.Pointer.sentinel(pointer) == 0) { return .{ .pointer = .{ .type = .char, .@"const" = true, }, .value = .string, }; }
-
-
-
@@ -33,10 +33,18 @@ browse.load.Response,registry.info.Response, registry.register.Request, registry.register.Response, transport.NowPlaying, transport.PlaybackState, transport.OutputVolume, transport.Output, transport.Zone, transport.SeekChange, transport.ControlType, transport.SeekMode, transport.ChangeVolumeMode, transport.SubscribeZoneChanges.Request, transport.SubscribeZoneChanges.Response, transport.SubscribeZoneChanges.Event, transport.Control.Request, transport.Seek.Request, transport.ChangeVolume.Request,
-
-
-
@@ -22,6 +22,7 @@ fn writeBaseType(writer: anytype, t: ApiSpec.CBaseType) !void {switch (t) { .bool, .char, .float, .double, .void => try writer.writeAll(@tagName(t)), .custom => |name| try writer.writeAll(name), .string => try writer.writeAll("const char *"), .int, .uint => |bits| { try std.fmt.format(writer, "{s}{d}_t", .{ if (t == .int) "int" else "uint",
-
@@ -142,7 +143,10 @@for (info.fields) |field| { try writer.writeByte('\t'); try writeType(writer, field.type); if (field.type == .pointer and std.mem.endsWith(u8, field.name, "_ptr")) { if (field.type == .pointer and std.mem.endsWith(u8, field.name, "_ptr") and field.type.pointer.type == .custom) { try writer.writeByte('*'); } try writer.writeByte(' ');
-
-
-
@@ -20,7 +20,7 @@ const ApiSpec = @import("./ApiSpec.zig");fn writeBaseType(writer: anytype, t: ApiSpec.CBaseType) !void { switch (t) { .bool, .char, .float, .double, .void => try writer.writeAll(@tagName(t)), .bool, .char, .float, .double, .string, .void => try writer.writeAll(@tagName(t)), .custom => |name| try writeCNameAsValaName(writer, name), .int => |bits| try std.fmt.format(writer, "int{d}", .{bits}), .uint => |bits| try std.fmt.format(writer, "uint{d}", .{bits}),
-
@@ -113,10 +113,7 @@ if (std.mem.endsWith(u8, field.name, "_len")) {continue; } if (std.mem.endsWith(u8, field.name, "_ptr") and field.type == .pointer and field.type.pointer.type == .custom) { if (std.mem.endsWith(u8, field.name, "_ptr") and field.type == .pointer) { try std.fmt.format( writer, "[CCode (\n\tcname = \"{s}\",\n\tarray_length_cname = \"{s}_len\", array_length_type = \"size_t\"\n)]\n",
-
-
-
@@ -21,6 +21,303 @@ 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";
-
@@ -76,6 +373,158 @@ 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 {
-