forked from jupyter-xeus/xeus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xkernel_core.hpp
140 lines (108 loc) · 4.92 KB
/
xkernel_core.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Martin Renou *
* Copyright (c) 2016, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XEUS_KERNEL_CORE_HPP
#define XEUS_KERNEL_CORE_HPP
#include <map>
#include <string>
#include "nlohmann/json.hpp"
#include "xeus/xcomm.hpp"
#include "xeus/xserver.hpp"
#include "xeus/xinterpreter.hpp"
#include "xeus/xhistory_manager.hpp"
#include "xeus/xdebugger.hpp"
#include "xeus/xmessage.hpp"
#include "xeus/xlogger.hpp"
namespace nl = nlohmann;
namespace xeus
{
class xkernel_core
{
public:
using logger_ptr = xlogger*;
using server_ptr = xserver*;
using interpreter_ptr = xinterpreter*;
using history_manager_ptr = xhistory_manager*;
using debugger_ptr = xdebugger*;
xkernel_core(const std::string& kernel_id,
const std::string& user_name,
const std::string& session_id,
logger_ptr logger,
server_ptr server,
interpreter_ptr p_interpreter,
history_manager_ptr p_history_manager,
debugger_ptr debugger,
nl::json::error_handler_t eh);
~xkernel_core();
xpub_message build_start_msg() const;
void dispatch_shell(xmessage msg);
void dispatch_control(xmessage msg);
void dispatch_stdin(xmessage msg);
nl::json dispatch_internal(nl::json msg);
void publish_message(const std::string& msg_type,
nl::json metadata,
nl::json content,
buffer_sequence buffers,
channel origin);
void send_stdin(const std::string& msg_type, nl::json metadata, nl::json content);
xcomm_manager& comm_manager() & noexcept;
const xcomm_manager& comm_manager() const & noexcept;
xcomm_manager comm_manager() const && noexcept;
const nl::json& parent_header(channel c) const noexcept;
private:
using handler_type = void (xkernel_core::*)(xmessage, channel);
using guid_list = xmessage::guid_list;
void dispatch(xmessage msg, channel c);
handler_type get_handler(const std::string& msg_type);
void execute_request(xmessage request, channel c);
void complete_request(xmessage request, channel c);
void inspect_request(xmessage request, channel c);
void history_request(xmessage request, channel c);
void is_complete_request(xmessage request, channel c);
void comm_info_request(xmessage request, channel c);
void comm_open(xmessage request, channel c);
void comm_close(xmessage request, channel c);
void comm_msg(xmessage request, channel c);
void kernel_info_request(xmessage request, channel c);
void shutdown_request(xmessage request, channel c);
void interrupt_request(xmessage request, channel c);
void debug_request(xmessage request, channel c);
void publish_status(const std::string& status, channel c);
void publish_execute_input(const std::string& code, int execution_count);
void send_reply(const std::string& reply_type,
nl::json metadata,
nl::json reply_content,
channel c);
void send_reply(const guid_list& id_list,
const std::string& reply_type,
nl::json parent_header,
nl::json metadata,
nl::json reply_content,
channel c);
void abort_request(xmessage msg);
std::string get_topic(const std::string& msg_type) const;
nl::json get_metadata() const;
void set_parent(const guid_list& list, const nl::json& parent, channel c);
const guid_list& get_parent_id(channel c) const;
nl::json get_parent_header(channel c) const;
std::string m_kernel_id;
std::string m_user_name;
std::string m_session_id;
std::map<std::string, handler_type> m_handler;
xcomm_manager m_comm_manager;
logger_ptr p_logger;
server_ptr p_server;
interpreter_ptr p_interpreter;
history_manager_ptr p_history_manager;
debugger_ptr p_debugger;
std::array<guid_list, 2> m_parent_id;
std::array<nl::json, 2> m_parent_header;
nl::json::error_handler_t m_error_handler;
};
}
#endif