mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-23 06:24:09 -04:00
Secure all endpoints by returning 403(Forbidden) when USB is connected. Request screen passcode to enable secured endpoints.
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#pragma once
|
|
|
|
#include "MessageHandler.hpp"
|
|
#include "ParserUtils.hpp"
|
|
|
|
#include <json/json11.hpp>
|
|
|
|
#include <string>
|
|
|
|
namespace parserFSM
|
|
{
|
|
enum class State
|
|
{
|
|
NoMsg,
|
|
ReceivedPartialHeader,
|
|
ReceivedPartialPayload,
|
|
ReceivedPayload,
|
|
};
|
|
|
|
class StateMachine
|
|
{
|
|
public:
|
|
explicit StateMachine(sys::Service *OwnerService);
|
|
void processMessage(std::string &&msg);
|
|
[[nodiscard]] auto getCurrentState() const noexcept -> State
|
|
{
|
|
return state;
|
|
};
|
|
|
|
void setState(const parserFSM::State newState) noexcept
|
|
{
|
|
state = newState;
|
|
}
|
|
|
|
void setMessageHandler(std::unique_ptr<MessageHandler> handler);
|
|
|
|
private:
|
|
std::string receivedMsg;
|
|
parserFSM::State state = State::NoMsg;
|
|
std::string payload;
|
|
std::string header;
|
|
unsigned long payloadLength = 0;
|
|
sys::Service *OwnerServicePtr = nullptr;
|
|
std::unique_ptr<MessageHandler> messageHandler;
|
|
|
|
void parseHeader();
|
|
void parsePartialHeader();
|
|
void parseNewMessage();
|
|
void parsePartialMessage();
|
|
void parsePayload();
|
|
};
|
|
} // namespace parserFSM
|