Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back to storing the request context instead of passing it to all publ… #401

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions include/xeus/xcomm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace xeus

void operator()(xcomm&& comm, xmessage request) const;

void publish_message(const std::string&, nl::json parent_header, nl::json, nl::json, buffer_sequence) const;
void publish_message(const std::string&, nl::json, nl::json, buffer_sequence) const;

void register_comm(xguid, xcomm*) const;
void unregister_comm(xguid) const;
Expand Down Expand Up @@ -87,9 +87,9 @@ namespace xeus
xcomm& operator=(xcomm&&);
xcomm& operator=(const xcomm&);

void open(nl::json parent_header, nl::json metadata, nl::json data, buffer_sequence buffers);
void close(nl::json parent_header, nl::json metadata, nl::json data, buffer_sequence buffers);
void send(nl::json parent_header, nl::json metadata, nl::json data, buffer_sequence buffers) const;
void open(nl::json metadata, nl::json data, buffer_sequence buffers);
void close(nl::json metadata, nl::json data, buffer_sequence buffers);
void send(nl::json metadata, nl::json data, buffer_sequence buffers) const;

xtarget& target() noexcept;
const xtarget& target() const noexcept;
Expand Down Expand Up @@ -118,12 +118,10 @@ namespace xeus
* }
*/
void send_comm_message(const std::string& msg_type,
nl::json parent_header,
nl::json metadata,
nl::json data,
buffer_sequence) const;
void send_comm_message(const std::string& msg_type,
nl::json parent_header,
nl::json metadata,
nl::json data,
buffer_sequence,
Expand Down Expand Up @@ -263,19 +261,17 @@ namespace xeus
}

inline void xcomm::send_comm_message(const std::string& msg_type,
nl::json parent_header,
nl::json metadata,
nl::json data,
buffer_sequence buffers) const
{
nl::json content;
content["comm_id"] = m_id;
content["data"] = std::move(data);
target().publish_message(msg_type, std::move(parent_header), std::move(metadata), std::move(content), std::move(buffers));
target().publish_message(msg_type, std::move(metadata), std::move(content), std::move(buffers));
}

inline void xcomm::send_comm_message(const std::string& msg_type,
nl::json parent_header,
nl::json metadata,
nl::json data,
buffer_sequence buffers,
Expand All @@ -285,8 +281,7 @@ namespace xeus
content["comm_id"] = m_id;
content["target_name"] = target_name;
content["data"] = std::move(data);
target().publish_message(
msg_type, std::move(parent_header), std::move(metadata), std::move(content), std::move(buffers));
target().publish_message(msg_type, std::move(metadata), std::move(content), std::move(buffers));
}

inline xcomm::xcomm(xcomm&& comm)
Expand Down Expand Up @@ -355,24 +350,23 @@ namespace xeus
}
}

inline void xcomm::open(nl::json parent_header, nl::json metadata, nl::json data, buffer_sequence buffers)
inline void xcomm::open(nl::json metadata, nl::json data, buffer_sequence buffers)
{
send_comm_message("comm_open",
std::move(parent_header),
std::move(metadata),
std::move(data),
std::move(buffers),
p_target->name());
}

inline void xcomm::close(nl::json parent_header, nl::json metadata, nl::json data, buffer_sequence buffers)
inline void xcomm::close(nl::json metadata, nl::json data, buffer_sequence buffers)
{
send_comm_message("comm_close", std::move(parent_header), std::move(metadata), std::move(data), std::move(buffers));
send_comm_message("comm_close", std::move(metadata), std::move(data), std::move(buffers));
}

inline void xcomm::send(nl::json parent_header, nl::json metadata, nl::json data, buffer_sequence buffers) const
inline void xcomm::send(nl::json metadata, nl::json data, buffer_sequence buffers) const
{
send_comm_message("comm_msg", std::move(parent_header), std::move(metadata), std::move(data), std::move(buffers));
send_comm_message("comm_msg", std::move(metadata), std::move(data), std::move(buffers));
}

inline xguid xcomm::id() const noexcept
Expand Down
2 changes: 0 additions & 2 deletions include/xeus/xinput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
#include <string>

#include "xeus/xeus.hpp"
#include "xeus/xrequest_context.hpp"

namespace xeus
{
XEUS_API
std::string blocking_input_request(
xrequest_context context,
const std::string& prompt,
bool password
);
Expand Down
26 changes: 15 additions & 11 deletions include/xeus/xinterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,31 @@ namespace xeus
using publisher_type = std::function<void(xrequest_context, const std::string&, nl::json, nl::json, buffer_sequence)>;
void register_publisher(const publisher_type& publisher);

void publish_stream(xrequest_context, const std::string& name, const std::string& text);
void display_data(xrequest_context, nl::json data, nl::json metadata, nl::json transient);
void update_display_data(xrequest_context, nl::json data, nl::json metadata, nl::json transient);
void publish_execution_input(xrequest_context, const std::string& code, int execution_count);
void publish_execution_result(xrequest_context, int execution_count, nl::json data, nl::json metadata);
void publish_execution_error(xrequest_context,
const std::string& ename,
void publish_stream(const std::string& name, const std::string& text);
void display_data(nl::json data, nl::json metadata, nl::json transient);
void update_display_data(nl::json data, nl::json metadata, nl::json transient);
void publish_execution_input(const std::string& code, int execution_count);
void publish_execution_result(int execution_count, nl::json data, nl::json metadata);
void publish_execution_error(const std::string& ename,
const std::string& evalue,
const std::vector<std::string>& trace_back);
void clear_output(xrequest_context, bool wait);
void clear_output(bool wait);

// send_stdin(msg_type, metadata, content)
using stdin_sender_type = std::function<void(xrequest_context, const std::string&, nl::json, nl::json)>;
void register_stdin_sender(const stdin_sender_type& sender);
using input_reply_handler_type = std::function<void(const std::string&)>;
void register_input_handler(const input_reply_handler_type& handler);

void input_request(xrequest_context context, const std::string& prompt, bool pwd);
void input_request(const std::string& prompt, bool pwd);
void input_reply(const std::string& value);

void register_comm_manager(xcomm_manager* manager);
xcomm_manager& comm_manager() noexcept;
const xcomm_manager& comm_manager() const noexcept;

const nl::json& parent_header() const noexcept;

void register_control_messenger(xcontrol_messenger& messenger);

void register_history_manager(const xhistory_manager& history);
Expand All @@ -108,8 +109,7 @@ namespace xeus

virtual void configure_impl() = 0;

virtual void execute_request_impl(xrequest_context request_context,
send_reply_callback cb,
virtual void execute_request_impl(send_reply_callback cb,
int execution_counter,
const std::string& code,
execute_request_config config,
Expand All @@ -132,13 +132,17 @@ namespace xeus

nl::json build_display_content(nl::json data, nl::json metadata, nl::json transient);

virtual void set_request_context(xrequest_context context);
virtual const xrequest_context& get_request_context() const noexcept;

publisher_type m_publisher;
stdin_sender_type m_stdin;
int m_execution_count;
xcomm_manager* p_comm_manager;
input_reply_handler_type m_input_reply_handler;
xcontrol_messenger* p_messenger;
const xhistory_manager* p_history;
xrequest_context m_request_context;
};

inline xcomm_manager& xinterpreter::comm_manager() noexcept
Expand Down
8 changes: 3 additions & 5 deletions include/xeus/xrequest_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "xeus/xeus.hpp"
#include "xeus/xjson.hpp"
#include "xeus/xmessage.hpp" // for xmessage::guid_list
#include "xeus/xserver.hpp" // for channel

namespace nl = nlohmann;

Expand All @@ -26,16 +25,15 @@ namespace xeus

using guid_list = xmessage::guid_list;

xrequest_context(nl::json header, channel origin, guid_list id);
xrequest_context() = default;
xrequest_context(nl::json header, guid_list id);

const nl::json& header() const;
channel origin() const;
const guid_list& id() const;

private:

nl::json m_header;
channel m_origin;
nl::json m_header = nl::json::object();
guid_list m_id;
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/xcomm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
namespace xeus
{
void xtarget::publish_message(const std::string& msg_type,
nl::json parent_header,
nl::json metadata,
nl::json content,
buffer_sequence buffers) const
{
if (p_manager->p_kernel != nullptr)
{
p_manager->p_kernel->publish_message(
msg_type, std::move(parent_header),
msg_type, p_manager->p_kernel->parent_header(),
std::move(metadata), std::move(content),
std::move(buffers), channel::SHELL
);
Expand Down
3 changes: 1 addition & 2 deletions src/xinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace xeus
{
std::string blocking_input_request(
xrequest_context context,
const std::string& prompt,
bool password
)
Expand All @@ -27,7 +26,7 @@ namespace xeus
interpreter.register_input_handler([&value](const std::string& v) { value = v; });

// Send the input request
interpreter.input_request(std::move(context), prompt, password);
interpreter.input_request(prompt, password);

// Remove input handler
interpreter.register_input_handler(nullptr);
Expand Down
Loading