Skip to content

Commit

Permalink
parent headers & execution count fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DerThorsten committed Feb 16, 2024
1 parent f2d1c81 commit 886a087
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
2 changes: 2 additions & 0 deletions include/xeus/xainterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace xeus
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_input(const std::string& code, int execution_count, nl::json parent_header);

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,
Expand Down
12 changes: 9 additions & 3 deletions include/xeus/xaresponse_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ namespace xeus
}

std::cout<<" in xaresponse_sender sending reply "<<std::endl;
m_post_send(std::move(msg), m_metadata);
m_post_send(std::move(m_parent_header), std::move(msg), m_metadata);

}

}
nl::json parent_header() const
{
return m_parent_header;
}
nl::json m_parent_header;
nl::json m_metadata;
std::function<void(nl::json, nl::json)> m_post_send = nullptr;
// void(nl::json, nl::json, nl::json) == void(parent, reply, metadata)
std::function<void(nl::json, nl::json, nl::json)> m_post_send = nullptr;
};

} // namespace xeus
Expand Down
10 changes: 5 additions & 5 deletions src/xainterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ namespace xeus
bool allow_stdin,
xaresponse_sender response_sender)
{
auto execution_count = m_execution_count;

if (!silent)
{
++m_execution_count;
publish_execution_input(code, m_execution_count);
}

auto execution_count = m_execution_count;

auto post_send = std::move(response_sender.m_post_send);
response_sender.m_post_send = [this,post_send, execution_count](nl::json reply, nl::json meta) {
response_sender.m_post_send = [this,post_send, execution_count](nl::json parent, nl::json reply, nl::json meta) {

std::cout<<" in xainterpreter sending reply "<<std::endl;
reply["execution_count"] = execution_count;
post_send(std::move(reply), std::move(meta));
post_send(std::move(parent), std::move(reply), std::move(meta));
};

async_execute_request_impl(
m_execution_count, code, silent,
execution_count, code, silent,
store_history, user_expressions, allow_stdin,
response_sender
);
Expand Down
40 changes: 31 additions & 9 deletions src/xkernel_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,32 @@ namespace xeus
}

void xkernel_core::publish_message(const std::string& msg_type,
nl::json parent_header,
nl::json metadata,
nl::json content,
buffer_sequence buffers,
channel c)
{
xpub_message msg(get_topic(msg_type),
make_header(msg_type, m_user_name, m_session_id),
get_parent_header(c),
std::move(parent_header),
std::move(metadata),
std::move(content),
std::move(buffers));
p_logger->log_iopub_message(msg);
p_server->publish(std::move(msg), c);
}


void xkernel_core::publish_message(const std::string& msg_type,
nl::json metadata,
nl::json content,
buffer_sequence buffers,
channel c)
{
publish_message(msg_type, get_parent_header(c), std::move(metadata), std::move(content), std::move(buffers), c);
}

void xkernel_core::send_stdin(const std::string& msg_type,
nl::json metadata,
nl::json content)
Expand Down Expand Up @@ -243,23 +254,21 @@ namespace xeus
const auto parent_header = get_parent_header(c);

p_interpreter->async_execute_request(



code, silent, store_history, std::move(user_expression), allow_stdin,
xaresponse_sender{std::move(metadata), [=](auto reply, auto meta)
xaresponse_sender{std::move(parent_header), std::move(metadata), [=](auto parent, auto reply, auto meta)
{
std::cout<<"in xkernelcore sender"<<std::endl;

int execution_count = reply.value("execution_count", 1);
std::string status = reply.value("status", "error");

std::cout<<"send reply "<<reply.dump(4)<<std::endl;
std::cout<<"parent header "<<parent.dump(4)<<std::endl;

send_reply(
parent_id,
"execute_reply",
parent_header,
parent,
std::move(meta),
std::move(reply),
c);
Expand All @@ -276,7 +285,7 @@ namespace xeus
}

// idle
publish_status("idle", c);
publish_status("idle", parent, c);
}}
);
}
Expand Down Expand Up @@ -383,20 +392,33 @@ namespace xeus
}
}

void xkernel_core::publish_status(const std::string& status, channel c)
void xkernel_core::publish_status(const std::string & status, nl::json parent_header, channel c)
{
nl::json content;
content["execution_state"] = status;
publish_message("status", nl::json::object(), std::move(content), buffer_sequence(), c);
publish_message("status", std::move(parent_header),nl::json::object(), std::move(content), buffer_sequence(), c);
}
void xkernel_core::publish_status(const std::string& status, channel c)
{
publish_status(status, get_parent_header(c), c);
}

void xkernel_core::publish_execute_input(const std::string& code,
int execution_count)
{
publish_execute_input(code, execution_count, get_parent_header(channel::SHELL));
}

void xkernel_core::publish_execute_input(const std::string& code,
int execution_count,
nl::json parent_header)
{

nl::json content;
content["code"] = code;
content["execution_count"] = execution_count;
publish_message("execute_input",
std::move(parent_header),
nl::json::object(),
std::move(content),
buffer_sequence(),
Expand Down
9 changes: 9 additions & 0 deletions src/xkernel_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ namespace xeus
buffer_sequence buffers,
channel origin);

void publish_message(const std::string& msg_type,
nl::json parent_header,
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;
Expand Down Expand Up @@ -100,8 +107,10 @@ namespace xeus
void debug_request(xmessage request, channel c);

void publish_status(const std::string& status, channel c);
void publish_status(const std::string& status, nl::json parent_header, channel c);

void publish_execute_input(const std::string& code, int execution_count);
void publish_execute_input(const std::string& code, int execution_count, nl::json parent_header);

void send_reply(const std::string& reply_type,
nl::json metadata,
Expand Down

0 comments on commit 886a087

Please sign in to comment.