mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/sentry: add more Zig APIs
This commit is contained in:
8
pkg/sentry/level.zig
Normal file
8
pkg/sentry/level.zig
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/// sentry_level_t
|
||||||
|
pub const Level = enum(c_int) {
|
||||||
|
debug = -1,
|
||||||
|
info = 0,
|
||||||
|
warning = 1,
|
||||||
|
err = 2,
|
||||||
|
fatal = 3,
|
||||||
|
};
|
@ -1,5 +1,15 @@
|
|||||||
pub const c = @import("c.zig").c;
|
pub const c = @import("c.zig").c;
|
||||||
|
|
||||||
|
pub const Level = @import("level.zig").Level;
|
||||||
|
pub const Value = @import("value.zig").Value;
|
||||||
|
pub const UUID = @import("uuid.zig").UUID;
|
||||||
|
|
||||||
|
pub fn captureEvent(value: Value) ?UUID {
|
||||||
|
const uuid: UUID = .{ .value = c.sentry_capture_event(value.value) };
|
||||||
|
if (uuid.isNil()) return null;
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@import("std").testing.refAllDecls(@This());
|
@import("std").testing.refAllDecls(@This());
|
||||||
}
|
}
|
||||||
|
18
pkg/sentry/uuid.zig
Normal file
18
pkg/sentry/uuid.zig
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const assert = std.debug.assert;
|
||||||
|
const c = @import("c.zig").c;
|
||||||
|
|
||||||
|
/// sentry_uuid_t
|
||||||
|
pub const UUID = struct {
|
||||||
|
value: c.sentry_uuid_t,
|
||||||
|
|
||||||
|
pub fn isNil(self: UUID) bool {
|
||||||
|
return c.sentry_uuid_is_nil(&self.value) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn string(self: UUID) [37]u8 {
|
||||||
|
var buf: [37]u8 = undefined;
|
||||||
|
c.sentry_uuid_as_string(&self.value, &buf);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
};
|
34
pkg/sentry/value.zig
Normal file
34
pkg/sentry/value.zig
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const assert = std.debug.assert;
|
||||||
|
const c = @import("c.zig").c;
|
||||||
|
const Level = @import("level.zig").Level;
|
||||||
|
|
||||||
|
/// sentry_value_t
|
||||||
|
pub const Value = struct {
|
||||||
|
/// The underlying value. This is a union that could be represented with
|
||||||
|
/// an extern union but I don't want to risk C ABI issues so we wrap it
|
||||||
|
/// in a struct.
|
||||||
|
value: c.sentry_value_t,
|
||||||
|
|
||||||
|
pub fn initMessageEvent(
|
||||||
|
level: Level,
|
||||||
|
logger: ?[]const u8,
|
||||||
|
message: []const u8,
|
||||||
|
) Value {
|
||||||
|
return .{ .value = c.sentry_value_new_message_event_n(
|
||||||
|
@intFromEnum(level),
|
||||||
|
if (logger) |v| v.ptr else null,
|
||||||
|
if (logger) |v| v.len else 0,
|
||||||
|
message.ptr,
|
||||||
|
message.len,
|
||||||
|
) };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn decref(self: Value) void {
|
||||||
|
c.sentry_value_decref(self.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn incref(self: Value) Value {
|
||||||
|
c.sentry_value_incref(self.value);
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user