DebugServer2
Loading...
Searching...
No Matches
ProtocolInterpreter.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/GDBRemote/PacketProcessor.h"
14
15namespace ds2 {
16namespace GDBRemote {
17
18class SessionBase;
19struct ProtocolHandler;
20
22public:
23 struct Handler {
24 typedef std::vector<Handler> Collection;
25 typedef void (ProtocolHandler::*Callback)(Handler const &handler,
26 std::string const &data);
27
28 enum Mode { kModeEquals, kModeStartsWith };
29
30 Mode mode;
31 std::string command;
32 ProtocolHandler *handler;
33 Callback callback;
34
35 int compare(std::string const &command) const;
36 };
37
38private:
39 SessionBase *_session;
40 Handler::Collection _handlers;
41 std::vector<std::string> _lastCommands;
42
43public:
45
46public:
47 inline void setSession(SessionBase *session) { _session = session; }
48 inline SessionBase *session() const {
49 return const_cast<ProtocolInterpreter *>(this)->_session;
50 }
51
52public:
53 void onCommand(std::string const &command, std::string const &arguments);
54
55public:
56 bool registerHandler(Handler const &handler);
57
58 template <typename CallbackType>
59 inline bool
60 registerHandler(Handler::Mode const &mode, std::string const &command,
61 ProtocolHandler *handler, CallbackType const &callback) {
62 Handler _handler = {mode, command, handler, (Handler::Callback)callback};
63 return registerHandler(_handler);
64 }
65
66private:
67 Handler const *findHandler(std::string const &command,
68 size_t &commandLength) const;
69
70public:
71 void onPacketData(std::string const &data, bool valid) override;
72 void onInvalidData(std::string const &data) override;
73
74public:
75 inline std::vector<std::string> const &lastCommands() const {
76 return _lastCommands;
77 }
78 inline void clearLastCommands() { _lastCommands.clear(); }
79};
80
82} // namespace GDBRemote
83} // namespace ds2
Definition ProtocolInterpreter.h:21
Definition SessionBase.h:30
Definition PacketProcessor.h:51
Definition ProtocolInterpreter.h:81
Definition ProtocolInterpreter.h:23