-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDevice.zig
More file actions
58 lines (49 loc) · 1.49 KB
/
Device.zig
File metadata and controls
58 lines (49 loc) · 1.49 KB
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
const std = @import("std");
const Allocator = std.mem.Allocator;
const libdrm = @import("libdrm");
const Connector = @import("../../Connector.zig");
const Device = @import("../../Device.zig");
const Self = @This();
allocator: Allocator,
node: libdrm.Node,
base: Device,
pub fn create(alloc: Allocator, node: libdrm.Node) !*Device {
const self = try alloc.create(Self);
errdefer alloc.destroy(self);
self.* = .{
.allocator = alloc,
.node = node,
.base = .{
.ptr = self,
.vtable = &.{
.getConnectors = impl_getConnectors,
.destroy = impl_destroy,
},
},
};
return &self.base;
}
pub fn getConnectors(self: *Self) ![]const *Connector {
var list = std.ArrayList(*Connector).init(self.allocator);
defer list.deinit();
const modeCardRes = try self.node.getModeCardRes();
defer modeCardRes.deinit(self.allocator);
if (modeCardRes.connectorIds()) |connectorIds| {
for (connectorIds) |connectorId| {
std.debug.print("{}\n", .{connectorId});
}
}
return try list.toOwnedSlice();
}
pub fn destroy(self: *Self) void {
self.node.deinit();
self.allocator.destroy(self);
}
fn impl_getConnectors(ptr: *anyopaque) anyerror![]const *Connector {
const self: *Self = @alignCast(@ptrCast(ptr));
return self.getConnectors();
}
fn impl_destroy(ptr: *anyopaque) void {
const self: *Self = @alignCast(@ptrCast(ptr));
return self.destroy();
}