19 #ifndef MSG_HANDLER_HPP
20 #define MSG_HANDLER_HPP
23 #include <unordered_map>
28 #include "interp_ctx.hpp"
31 #include "net_handler.hpp"
40 virtual Global::conn_id_t connect(
const string& ip,
int port,
InterpCtx& ic) {
41 throw std::logic_error(
"sendReq not implemented");
43 virtual size_t sendReq(
InterpCtx* reqCtx, Global::reqid_t reqid, Global::reqid_t sourceid,
45 throw std::logic_error(
"sendReq not implemented");
47 virtual size_t sendRsp(Global::conn_id_t
id, Global::reqid_t reqid, Global::reqid_t sourceid,
48 const val::Value& rsp) {
49 throw std::logic_error(
"sendReq not implemented");
51 inline virtual void suspendKeyboardPoll() {
52 throw std::logic_error(
"suspendKeyboardPoll not implemented");
54 inline virtual void enableKeyboardPoll() {
55 throw std::logic_error(
"enableKeyboardPoll not implemented");
57 inline virtual void addTimer(
int fd, std::unique_ptr<InterpCtxTimer> ctx) {
58 throw std::logic_error(
"enableKeyboardPoll not implemented");
60 inline virtual void removeTimer(
int fd) {
61 throw std::logic_error(
"enableKeyboardPoll not implemented");
63 virtual const NetStats& getNetStats()
const {
64 throw std::logic_error(
"getNetStats not implemented");
66 virtual void resetNetStats() {
67 throw std::logic_error(
"resetNetStats not implemented");
70 throw std::logic_error(
"getNetInfo not implemented");
73 throw std::logic_error(
"getMsgInfo not implemented");
76 const MsgStats& getMsgStats() {
return stats; }
77 void resetMsgStats() { stats.reset(); }
88 interp::shpfrm& global_p,
91 int fd_input_p=STDIN_FILENO,
93 const std::string& initialCode=
"");
97 Global::conn_id_t connect(
const string& ip,
int port,
InterpCtx& ic);
99 Global::reqid_t reqid,
100 Global::reqid_t sourceid,
104 size_t sendRsp(Global::conn_id_t
id,
105 Global::reqid_t reqid,
106 Global::reqid_t sourceid,
107 const val::Value& rsp);
109 static volatile sig_atomic_t waitingOnResp;
111 void suspendKeyboardPoll();
112 void enableKeyboardPoll();
114 void addTimer(
int fd, std::unique_ptr<InterpCtxTimer> ctx);
115 void removeTimer(
int fd);
117 inline const InterpCtxLocal& getLocalCtx()
const {
return *localContext; }
119 const NetStats& getNetStats()
const;
120 void resetNetStats();
127 interp::shpfrm global;
133 unique_ptr<InterpCtxLocal> localContext;
136 unordered_map<Global::conn_id_t, unique_ptr<InterpCtx>> reqContexts;
137 unordered_map<Global::conn_id_t, InterpCtx&> rspContexts;
138 unordered_map<int, unique_ptr<InterpCtxTimer>> timerContexts;
141 epoll_event events[Global::EPOLL_MAX_EVENTS];
142 static const int EPOLL_TIMEOUT = 1000;