Changes
4 changed files (+132/-1)
-
-
@@ -25,6 +25,7 @@#ifndef PLAC_CORE_H #define PLAC_CORE_H #include <stdbool.h> #include <stddef.h> #include <stdint.h>
-
@@ -72,10 +73,23 @@ const char *two_line_line2;const char *three_line_line1; const char *three_line_line2; const char *three_line_line3; uint64_t seek_position; uint64_t length; bool has_seek_position; bool has_length; } plac_transport_now_playing; plac_transport_now_playing *plac_transport_now_playing_retain(plac_transport_now_playing*); void plac_transport_now_playing_release(plac_transport_now_playing*); // transport.SeekChange typedef struct { void *__pri; const char *zone_id; uint64_t seek_position; } plac_transport_seek_change; plac_transport_seek_change *plac_transport_seek_change_retain(plac_transport_seek_change*); void plac_transport_seek_change_release(plac_transport_seek_change*); // transport.PlaybackState typedef enum { PLAC_TRANSPORT_PLAYBACK_LOADING = 0,
-
@@ -112,6 +126,8 @@ plac_transport_zone **changed_zones_ptr;size_t changed_zones_len; char **removed_zone_ids_ptr; size_t removed_zone_ids_len; plac_transport_seek_change **seek_changes_ptr; size_t seek_changes_len; } plac_transport_zone_list_event; plac_transport_zone_list_event *plac_transport_zone_list_event_retain(plac_transport_zone_list_event*); void plac_transport_zone_list_event_release(plac_transport_zone_list_event*);
-
-
-
@@ -96,6 +96,17 @@ public string? three_line_line3;} [CCode ( cname = "plac_transport_seek_change", ref_function = "plac_transport_seek_change_retain", unref_function = "plac_transport_seek_change_release" )] [Compact] public class SeekChange { public string zone_id; public uint64 seek_position; } [CCode ( cname = "plac_transport_playback_state", cprefix = "PLAC_TRANSPORT_PLAYBACK_", has_type_id = false
-
-
-
@@ -22,6 +22,8 @@ pub const TransportService = struct {pub const id = "com.roonlabs.transport:2"; pub const NowPlaying = struct { seek_position: ?u64, length: ?u64, one_line: struct { line1: []const u8, },
-
@@ -74,6 +76,11 @@ is_play_allowed: bool = false,is_seek_allowed: bool = false, }; pub const SeekChange = struct { zone_id: []const u8, seek_position: u64, }; pub const SubscribeZoneChanges = struct { pub const Request = struct { subscription_key: []const u8,
-
@@ -126,6 +133,7 @@ pub const Response = struct {zones_removed: []const []const u8 = &.{}, zones_added: []const Zone = &.{}, zones_changed: []const Zone = &.{}, zones_seek_changed: []const SeekChange = &.{}, }; pub fn response(
-
-
-
@@ -20,7 +20,7 @@ const Arc = @import("./Arc.zig");const TransportService = @import("./services/transport.zig").TransportService; pub const NowPlaying = extern struct { const cname = "plac_transport_zone"; const cname = "plac_transport_now_playing"; const allocator = std.heap.c_allocator; internal: *Internal,
-
@@ -30,6 +30,10 @@ two_line_line2: ?[*:0]const u8,three_line_line1: [*:0]const u8, three_line_line2: ?[*:0]const u8, three_line_line3: ?[*:0]const u8, seek_position: u64, length: u64, has_seek_position: bool, has_length: bool, pub const Internal = struct { arc: Arc = .{},
-
@@ -79,6 +83,10 @@ .two_line_line2 = if (two_line_line2) |slice| slice.ptr else null,.three_line_line1 = three_line_line1, .three_line_line2 = if (three_line_line2) |slice| slice.ptr else null, .three_line_line3 = if (three_line_line3) |slice| slice.ptr else null, .seek_position = src.seek_position orelse 0, .length = src.length orelse 0, .has_seek_position = src.seek_position != null, .has_length = src.length != null, }; return self;
-
@@ -122,6 +130,66 @@ @export(&release, .{ .name = std.fmt.comptimePrint("{s}_release", .{cname}) });} }; pub const SeekChange = extern struct { const cname = "plac_transport_seek_change"; const allocator = std.heap.c_allocator; internal: *Internal, zone_id: [*:0]const u8, seek_position: u64, pub const Internal = struct { arc: Arc = .{}, }; pub fn make(src: *const TransportService.SeekChange) std.mem.Allocator.Error!*SeekChange { const zone_id = try allocator.dupeZ(u8, src.zone_id); errdefer allocator.free(zone_id); const internal = try allocator.create(Internal); errdefer allocator.destroy(internal); internal.* = .{}; const self = try allocator.create(SeekChange); errdefer allocator.destroy(self); self.* = .{ .internal = internal, .zone_id = zone_id.ptr, .seek_position = src.seek_position, }; return self; } pub fn retain(ptr: ?*SeekChange) callconv(.C) *SeekChange { var self = ptr orelse @panic( std.fmt.comptimePrint("Received null pointer on {s}_{s}", .{ cname, @src().fn_name }), ); self.internal.arc.ref(); return self; } pub fn release(ptr: ?*SeekChange) callconv(.C) void { var self = ptr orelse @panic( std.fmt.comptimePrint("Received null pointer on {s}_{s}", .{ cname, @src().fn_name }), ); if (self.internal.arc.unref()) { std.log.debug("Releasing {*}...", .{self}); allocator.free(std.mem.span(self.zone_id)); allocator.destroy(self.internal); allocator.destroy(self); } } pub fn export_capi() void { @export(&retain, .{ .name = std.fmt.comptimePrint("{s}_retain", .{cname}) }); @export(&release, .{ .name = std.fmt.comptimePrint("{s}_release", .{cname}) }); } }; pub const PlaybackState = enum(c_int) { loading = 0, stopped = 1,
-
@@ -246,6 +314,8 @@ changed_zones_ptr: [*]const *Zone,changed_zones_len: usize, removed_zone_ids_ptr: [*]const [*:0]const u8, removed_zone_ids_len: usize, seek_changes_ptr: [*]const *SeekChange, seek_changes_len: usize, pub const Internal = struct { added_zones: []const *Zone,
-
@@ -300,6 +370,21 @@ removed_zone_ids[removed_i] = (try allocator.dupeZ(u8, id)).ptr;removed_i += 1; } const seek_changes = try allocator.alloc(*SeekChange, event.zones_seek_changed.len); errdefer allocator.free(seek_changes); var seek_i: usize = 0; errdefer { for (0..seek_i) |i| { seek_changes[i].release(); } } for (event.zones_seek_changed) |src| { const change = try SeekChange.make(&src); seek_changes[seek_i] = change.retain(); seek_i += 1; } const internal = try allocator.create(Internal); errdefer allocator.destroy(internal);
-
@@ -320,6 +405,8 @@ .changed_zones_ptr = changed_zones.ptr,.changed_zones_len = changed_zones.len, .removed_zone_ids_ptr = removed_zone_ids.ptr, .removed_zone_ids_len = removed_zone_ids.len, .seek_changes_ptr = seek_changes.ptr, .seek_changes_len = seek_changes.len, }; return self;
-
@@ -363,6 +450,8 @@ .changed_zones_ptr = undefined,.changed_zones_len = 0, .removed_zone_ids_ptr = undefined, .removed_zone_ids_len = 0, .seek_changes_ptr = undefined, .seek_changes_len = 0, }; return self;
-
@@ -398,6 +487,11 @@ allocator.free(std.mem.span(id));} allocator.free(self.internal.removed_zone_ids); for (self.seek_changes_ptr[0..self.seek_changes_len]) |change| { change.release(); } allocator.free(self.seek_changes_ptr[0..self.seek_changes_len]); allocator.destroy(self.internal); allocator.destroy(self); }
-
@@ -410,6 +504,8 @@ }}; pub fn export_capi() void { SeekChange.export_capi(); NowPlaying.export_capi(); Zone.export_capi(); ZoneListEvent.export_capi(); }
-