mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
server: simplify onInspector methods
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -260,39 +260,31 @@ pub const Ctx = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onInspectorResp(cmd_opaque: *anyopaque, _: u32, msg: []const u8) void {
|
inline fn inspectorCtx(ctx_opaque: *anyopaque) *Ctx {
|
||||||
std.log.debug("onResp biz fn called: {s}", .{msg});
|
const aligned = @as(*align(@alignOf(Ctx)) anyopaque, @alignCast(ctx_opaque));
|
||||||
const aligned = @as(*align(@alignOf(Ctx)) anyopaque, @alignCast(cmd_opaque));
|
return @as(*Ctx, @ptrCast(aligned));
|
||||||
const self = @as(*Ctx, @ptrCast(aligned));
|
|
||||||
|
|
||||||
const tpl = "{s},\"sessionId\":\"{s}\"}}";
|
|
||||||
const msg_open = msg[0 .. msg.len - 1]; // remove closing bracket
|
|
||||||
const s = std.fmt.allocPrint(
|
|
||||||
self.alloc(),
|
|
||||||
tpl,
|
|
||||||
.{ msg_open, cdp.ContextSessionID },
|
|
||||||
) catch unreachable;
|
|
||||||
defer self.alloc().free(s);
|
|
||||||
|
|
||||||
sendSync(self, s) catch unreachable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onInspectorNotif(cmd_opaque: *anyopaque, msg: []const u8) void {
|
fn inspectorMsg(allocator: std.mem.Allocator, ctx: *Ctx, msg: []const u8) !void {
|
||||||
std.log.debug("onNotif biz fn called: {s}", .{msg});
|
// inject sessionID in cdp msg
|
||||||
const aligned = @as(*align(@alignOf(Ctx)) anyopaque, @alignCast(cmd_opaque));
|
|
||||||
const self = @as(*Ctx, @ptrCast(aligned));
|
|
||||||
|
|
||||||
const tpl = "{s},\"sessionId\":\"{s}\"}}";
|
const tpl = "{s},\"sessionId\":\"{s}\"}}";
|
||||||
const msg_open = msg[0 .. msg.len - 1]; // remove closing bracket
|
const msg_open = msg[0 .. msg.len - 1]; // remove closing bracket
|
||||||
const s = std.fmt.allocPrint(
|
const s = try std.fmt.allocPrint(allocator, tpl, .{ msg_open, cdp.ContextSessionID });
|
||||||
self.alloc(),
|
defer ctx.alloc().free(s);
|
||||||
tpl,
|
|
||||||
.{ msg_open, cdp.ContextSessionID },
|
|
||||||
) catch unreachable;
|
|
||||||
defer self.alloc().free(s);
|
|
||||||
std.log.debug("event: {s}", .{s});
|
|
||||||
|
|
||||||
sendSync(self, s) catch unreachable;
|
try sendSync(ctx, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn onInspectorResp(ctx_opaque: *anyopaque, _: u32, msg: []const u8) void {
|
||||||
|
std.log.debug("inspector resp: {s}", .{msg});
|
||||||
|
const ctx = inspectorCtx(ctx_opaque);
|
||||||
|
inspectorMsg(ctx.alloc(), ctx, msg) catch unreachable;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn onInspectorNotif(ctx_opaque: *anyopaque, msg: []const u8) void {
|
||||||
|
std.log.debug("inspector event: {s}", .{msg});
|
||||||
|
const ctx = inspectorCtx(ctx_opaque);
|
||||||
|
inspectorMsg(ctx.alloc(), ctx, msg) catch unreachable;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user