|
| 1 | +// Copyright (C) 2023-2024 Lightpanda (Selecy SAS) |
| 2 | +// |
| 3 | +// Francis Bouvier <[email protected]> |
| 4 | +// Pierre Tachoire <[email protected]> |
| 5 | +// |
| 6 | +// This program is free software: you can redistribute it and/or modify |
| 7 | +// it under the terms of the GNU Affero General Public License as |
| 8 | +// published by the Free Software Foundation, either version 3 of the |
| 9 | +// License, or (at your option) any later version. |
| 10 | +// |
| 11 | +// This program is distributed in the hope that it will be useful, |
| 12 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +// GNU Affero General Public License for more details. |
| 15 | +// |
| 16 | +// You should have received a copy of the GNU Affero General Public License |
| 17 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +const std = @import("std"); |
| 20 | + |
| 21 | +const server = @import("../server.zig"); |
| 22 | +const Ctx = server.Ctx; |
| 23 | +const cdp = @import("cdp.zig"); |
| 24 | +const result = cdp.result; |
| 25 | +const IncomingMessage = @import("msg.zig").IncomingMessage; |
| 26 | +const Input = @import("msg.zig").Input; |
| 27 | + |
| 28 | +const log = std.log.scoped(.cdp); |
| 29 | + |
| 30 | +const Methods = enum { |
| 31 | + enable, |
| 32 | +}; |
| 33 | + |
| 34 | +pub fn inspector( |
| 35 | + alloc: std.mem.Allocator, |
| 36 | + msg: *IncomingMessage, |
| 37 | + action: []const u8, |
| 38 | + ctx: *Ctx, |
| 39 | +) ![]const u8 { |
| 40 | + const method = std.meta.stringToEnum(Methods, action) orelse |
| 41 | + return error.UnknownMethod; |
| 42 | + |
| 43 | + return switch (method) { |
| 44 | + .enable => enable(alloc, msg, ctx), |
| 45 | + }; |
| 46 | +} |
| 47 | + |
| 48 | +fn enable( |
| 49 | + alloc: std.mem.Allocator, |
| 50 | + msg: *IncomingMessage, |
| 51 | + _: *Ctx, |
| 52 | +) ![]const u8 { |
| 53 | + // input |
| 54 | + const input = try Input(void).get(alloc, msg); |
| 55 | + defer input.deinit(); |
| 56 | + log.debug("Req > id {d}, method {s}", .{ input.id, "inspector.enable" }); |
| 57 | + |
| 58 | + return result(alloc, input.id, null, null, input.sessionId); |
| 59 | +} |
0 commit comments