From aff2250504e977123e6715cd3ca8e412b497f841 Mon Sep 17 00:00:00 2001 From: Francis Bouvier Date: Tue, 16 Apr 2024 01:02:44 +0200 Subject: [PATCH] Add Emulation domain Signed-off-by: Francis Bouvier --- src/cdp/cdp.zig | 3 +++ src/cdp/emulation.zig | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/cdp/emulation.zig diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index 1c07d9d3..c54b686f 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -8,6 +8,7 @@ const target = @import("target.zig").target; const page = @import("page.zig").page; const log = @import("log.zig").log; const runtime = @import("runtime.zig").runtime; +const emulation = @import("emulation.zig").emulation; pub const Error = error{ UnknonwDomain, @@ -31,6 +32,7 @@ const Domains = enum { Page, Log, Runtime, + Emulation, }; // The caller is responsible for calling `free` on the returned slice. @@ -62,6 +64,7 @@ pub fn do( .Page => page(alloc, id, iter.next().?, &scanner, ctx), .Log => log(alloc, id, iter.next().?, &scanner, ctx), .Runtime => runtime(alloc, id, iter.next().?, &scanner, ctx), + .Emulation => emulation(alloc, id, iter.next().?, &scanner, ctx), }; } diff --git a/src/cdp/emulation.zig b/src/cdp/emulation.zig new file mode 100644 index 00000000..1fd74f69 --- /dev/null +++ b/src/cdp/emulation.zig @@ -0,0 +1,34 @@ +const std = @import("std"); + +const server = @import("../server.zig"); +const Ctx = server.Cmd; +const result = @import("cdp.zig").result; +const getParams = @import("cdp.zig").getParams; +const stringify = @import("cdp.zig").stringify; + +const EmulationMethods = enum { + setEmulatedMedia, +}; + +pub fn emulation( + alloc: std.mem.Allocator, + id: u64, + action: []const u8, + scanner: *std.json.Scanner, + ctx: *Ctx, +) ![]const u8 { + const method = std.meta.stringToEnum(EmulationMethods, action) orelse + return error.UnknownMethod; + return switch (method) { + .setEmulatedMedia => setEmulatedMedia(alloc, id, scanner, ctx), + }; +} + +fn setEmulatedMedia( + alloc: std.mem.Allocator, + id: u64, + _: *std.json.Scanner, + _: *Ctx, +) ![]const u8 { + return result(alloc, id, null, null); +}