26 typedef std::vector<Handler> Collection;
29 using CallbackType = Callback;
31 enum Mode { kModeEquals, kModeStartsWith };
38 int compare(std::string_view command)
const;
43 Handler::Collection _handlers;
44 std::vector<std::string> _lastCommands;
50 inline void setSession(
SessionBase *session) { _session = session; }
56 void onCommand(std::string_view command, std::string_view arguments);
59 bool registerHandler(Handler
const &handler);
61 template <
typename CallbackType>
63 registerHandler(Handler::Mode
const &mode, std::string
const &command,
64 ProtocolHandler *handler, CallbackType
const &callback) {
65 Handler _handler = {mode, command, handler, (Handler::Callback)callback};
66 return registerHandler(_handler);
70 Handler
const *findHandler(std::string_view command,
71 size_t &commandLength)
const;
74 void onPacketData(std::string
const &data,
bool valid)
override;
75 void onInvalidData(std::string
const &data)
override;
78 inline std::vector<std::string>
const &lastCommands()
const {
81 inline void clearLastCommands() { _lastCommands.clear(); }