Skip to content

Commit

Permalink
Merge pull request #47 from anutosh491/ipc
Browse files Browse the repository at this point in the history
Updating the ipc client based on the new client framework
  • Loading branch information
JohanMabille authored Apr 18, 2024
2 parents e196690 + 9a37747 commit 2c01fe7
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 27 deletions.
8 changes: 4 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ set_tests_properties(test_kernel_shell
PROPERTIES
ENVIRONMENT "JUPYTER_PATH=${CMAKE_CURRENT_BINARY_DIR}")

# TODO: enable this again when the ipc client
# is implemented
if (FALSE)
if (UNIX)

# Test_kernel_ipc
# ===============
Expand All @@ -183,10 +181,12 @@ if (FALSE)
# ===============

set(TEST_CLIENT_IPC_SOURCES
xipc_client.cpp
xipc_client.hpp
client_ipc.cpp)

add_executable(test_client_ipc ${TEST_CLIENT_IPC_SOURCES})
target_link_libraries(test_client_ipc PRIVATE ${xeus-zmq_TARGET} Threads::Threads)
target_compile_features(test_client_ipc PRIVATE cxx_std_17)

endif (FALSE)
endif (UNIX)
51 changes: 28 additions & 23 deletions test/client_ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

// TODO: this client should be reimplemented with
// the new client framework. Notice that it was not
// tested in the CI but was here for trying to reproduce
// some issue with IPC.

/*#include <iostream>
#include <iostream>

#include "zmq_addon.hpp"
#include "nlohmann/json.hpp"
#include "xeus/xguid.hpp"
#include "xeus/xmessage.hpp"
#include "xeus-zmq/xauthentication.hpp"
#include "xeus-zmq/xmiddleware.hpp"
#include "xeus-zmq/xzmq_serializer.hpp"
#include "xeus/xkernel_configuration.hpp"
#include "xeus-zmq/xzmq_context.hpp"
#include "xipc_client.hpp"

namespace nl = nlohmann;

int main(int, char**)
{
zmq::context_t context;
zmq::socket_t cli(context, zmq::socket_type::dealer);
xeus::xguid socket_id = xeus::new_xguid();
//cli.set(ZMQ_IDENTITY, socket_id.c_str(), socket_id.size());
cli.set(zmq::sockopt::linger, xeus::get_socket_linger());
cli.connect(xeus::get_end_point("ipc", "localhost", "shell"));
auto context_ptr = xeus::make_zmq_context();
xeus::xconfiguration config;
config.m_transport = "ipc";
config.m_ip = "localhost";
config.m_control_port = "control";
config.m_shell_port = "shell";
config.m_stdin_port = "stdin";
config.m_iopub_port = "iopub";
config.m_hb_port = "heartbeat";
config.m_signature_scheme = "none";
config.m_key = "";

auto auth = xeus::make_xauthentication("none", "");
xeus::xipc_client ipc_client(*context_ptr, config);

xeus::xguid socket_id = xeus::new_xguid();
nl::json header = xeus::make_header("execute_request", "tester", "DAEDZFAEDE12");
std::string code = "std::cout << \"this is a test\" << std::endl;";
nl::json req = {
Expand All @@ -48,15 +49,19 @@ int main(int, char**)
nl::json::object(),
xeus::buffer_sequence()
);
auto wire_msg = xeus::xzmq_serializer::serialize(std::move(msg), *auth);
wire_msg.send(cli);

zmq::multipart_t resp_msg;
resp_msg.recv(cli);
ipc_client.send_on_shell(std::move(msg));

auto resp = xeus::xzmq_serializer::deserialize(resp_msg, *auth);
std::cout << resp.content().dump(4) << std::endl;
auto response = ipc_client.check_shell_answer();
if (response.has_value())
{
std::cout << response->content().dump(4) << std::endl;
}
else
{
std::cout << "No response received" << std::endl;
}

return 0;
}*/
}

28 changes: 28 additions & 0 deletions test/xipc_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/***************************************************************************
* Copyright (c) 2016, Johan Mabille and Sylvain Corlay *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "xipc_client.hpp"

namespace xeus
{

xipc_client::xipc_client(xcontext& context, const xconfiguration& config)
: p_client(make_xclient_zmq(context, config))
{
}

void xipc_client::send_on_shell(xmessage msg)
{
p_client->send_on_shell(std::move(msg));
}

std::optional<xmessage> xipc_client::check_shell_answer()
{
return p_client->check_shell_answer();
}
}
31 changes: 31 additions & 0 deletions test/xipc_client.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/***************************************************************************
* Copyright (c) 2016, Johan Mabille and Sylvain Corlay *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XEUS_IPC_CLIENT_HPP
#define XEUS_IPC_CLIENT_HPP

#include "xeus-zmq/xclient_zmq.hpp"

namespace xeus
{
class xipc_client
{
public:
using client_ptr = std::unique_ptr<xclient_zmq>;

xipc_client(xcontext& context, const xconfiguration& config);

void send_on_shell(xmessage msg);
std::optional<xmessage> check_shell_answer();

private:
client_ptr p_client;
};
}

#endif

0 comments on commit 2c01fe7

Please sign in to comment.