2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-09-08 10:51:28 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
|
|
|
#include "Command.h"
|
|
|
|
|
|
|
|
#define IAC 0xff
|
|
|
|
|
|
|
|
class Parser {
|
|
|
|
public:
|
2022-04-01 20:58:27 +03:00
|
|
|
Function<void(Command const&)> on_command;
|
2021-11-11 02:55:02 +03:00
|
|
|
Function<void(StringView)> on_data;
|
2019-09-08 10:51:28 +03:00
|
|
|
Function<void()> on_error;
|
|
|
|
|
2021-11-11 02:55:02 +03:00
|
|
|
void write(StringView);
|
2019-09-08 10:51:28 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
enum State {
|
|
|
|
Free,
|
|
|
|
ReadCommand,
|
|
|
|
ReadSubcommand,
|
|
|
|
Error,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
State m_state { State::Free };
|
|
|
|
u8 m_command { 0 };
|
|
|
|
};
|