Skip to content

Commit

Permalink
Fixing linking errors due to nlohmann_json and addressing other minor…
Browse files Browse the repository at this point in the history
… changes
  • Loading branch information
anutosh491 committed Mar 26, 2024
1 parent 5fbf1d4 commit 157a987
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 32 deletions.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ message(STATUS "XEUS_ZMQ_BUILD_TESTS: ${XEUS_ZMQ_BUILD_TESTS}")
# ============

set(xeus_REQUIRED_VERSION 3.2.0)
set(nlohmann_json_REQUIRED_VERSION 3.2.0)
set(nlohmann_json_REQUIRED_VERSION 3.11.2)
set(cppzmq_REQUIRED_VERSION 4.8.1)
set(zeromq_REQUIRED_VERSION 4.3.2)

Expand Down Expand Up @@ -132,6 +132,7 @@ set(XEUS_ZMQ_HEADERS
${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xthread.hpp
${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xzmq_context.hpp
${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xzmq_serializer.hpp
${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xclient_zmq.hpp
)

set(XEUS_ZMQ_SOURCES
Expand Down Expand Up @@ -164,6 +165,15 @@ set(XEUS_ZMQ_SOURCES
${XEUS_ZMQ_SOURCE_DIR}/xzmq_messenger.hpp
${XEUS_ZMQ_SOURCE_DIR}/xzmq_messenger.cpp
${XEUS_ZMQ_SOURCE_DIR}/xzmq_serializer.cpp
${XEUS_ZMQ_SOURCE_DIR}/xclient_zmq.cpp
${XEUS_ZMQ_SOURCE_DIR}/xclient_messenger.hpp
${XEUS_ZMQ_SOURCE_DIR}/xclient_messenger.cpp
${XEUS_ZMQ_SOURCE_DIR}/xclient_zmq_impl.hpp
${XEUS_ZMQ_SOURCE_DIR}/xclient_zmq_impl.cpp
${XEUS_ZMQ_SOURCE_DIR}/xdealer_channel.hpp
${XEUS_ZMQ_SOURCE_DIR}/xdealer_channel.cpp
${XEUS_ZMQ_SOURCE_DIR}/xiopub_client.hpp
${XEUS_ZMQ_SOURCE_DIR}/xiopub_client.cpp
)

# Targets and link
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ See the [documentation](http://xeus.readthedocs.io/) for an exhaustive list of t
We have packaged all these dependencies on conda-forge. The simplest way to install them is to run:
```bash
mamba install cmake pkg-config zeromq cppzmq OpenSSL nlohmann_json xtl xeus -c conda-forge
mamba install cmake pkg-config zeromq cppzmq OpenSSL nlohmann_json=3.11.2 xtl xeus -c conda-forge
```

Once you have installed the dependencies, you can build and install `xeus-zmq`:
Expand Down
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- xeus>=3.2.0,<4.0
- OpenSSL=1
- libopenssl-static=1
- nlohmann_json
- nlohmann_json=3.11.2
# Test dependencies
- doctest >= 2.4.6
- pytest
Expand Down
6 changes: 5 additions & 1 deletion include/xeus-zmq/xclient_zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ namespace xeus
void notify_control_listener(xmessage msg);
void notify_iopub_listener(xmessage msg);

void start();
std::size_t iopub_queue_size() const;
std::optional<xmessage> pop_iopub_message();
void connect();
void stop_channels();
void start();
void wait_for_message();

private:
std::unique_ptr<xclient_zmq_impl> p_client_impl;
Expand Down
24 changes: 22 additions & 2 deletions src/xclient_zmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,36 @@ namespace xeus
p_client_impl->notify_iopub_listener(std::move(msg));
}

void xclient_zmq::start()
std::size_t xclient_zmq::iopub_queue_size() const
{
p_client_impl->start();
return p_client_impl->iopub_queue_size();
}

std::optional<xmessage> xclient_zmq::pop_iopub_message()
{
return p_client_impl->pop_iopub_message();
}

void xclient_zmq::connect()
{
p_client_impl->connect();
}

void xclient_zmq::stop_channels()
{
p_client_impl->stop_channels();
}

void xclient_zmq::start()
{
p_client_impl->start();
}

void xclient_zmq::wait_for_message()
{
p_client_impl->wait_for_message();
}

std::unique_ptr<xclient_zmq> make_xclient_zmq(xcontext& context,
const xconfiguration& config,
nl::json::error_handler_t eh)
Expand Down
11 changes: 3 additions & 8 deletions src/xclient_zmq_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace xeus
const xeus::xconfiguration& config,
nl::json::error_handler_t eh)
: p_auth(make_xauthentication(config.m_signature_scheme, config.m_key))
, m_shell_client(context, config)
, m_control_client(context, config)
, m_shell_client(context, config.m_transport, config.m_ip, config.m_shell_port)
, m_control_client(context, config.m_transport, config.m_ip, config.m_control_port)
, m_iopub_client(context, config)
, p_messenger(context)
, m_error_handler(eh)
Expand Down Expand Up @@ -93,11 +93,6 @@ namespace xeus
m_iopub_listener = l;
}

xclient_messenger& xclient_zmq_impl::get_client_messenger()
{
return p_messenger;
}

void xclient_zmq_impl::connect()
{
p_messenger.connect();
Expand Down Expand Up @@ -171,7 +166,7 @@ namespace xeus
void xclient_zmq_impl::start()
{
start_iopub_thread();
// TODO
// TODO : Introduce a client, xheartbeat_client that runs on its own thread, m_heartbeat_thread.
}

void xclient_zmq_impl::start_iopub_thread()
Expand Down
1 change: 0 additions & 1 deletion src/xclient_zmq_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ namespace xeus
// TODO

// client messenger
xclient_messenger& get_client_messenger();
void connect();
void stop_channels();

Expand Down
12 changes: 5 additions & 7 deletions src/xdealer_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ namespace xeus
{

xdealer_channel::xdealer_channel(zmq::context_t& context,
const xeus::xconfiguration& config)
const std::string& transport,
const std::string& ip,
const std::string& port)
: m_socket(context, zmq::socket_type::dealer)
, m_end_point("")
{
m_end_point = xeus::get_end_point(config.m_transport, config.m_ip, config.m_shell_port);

m_socket.connect(m_end_point);
m_socket.connect(get_end_point(transport, ip, port));
}

xdealer_channel::~xdealer_channel()
{
m_socket.disconnect(m_end_point);
}

void xdealer_channel::send_message(zmq::multipart_t& message)
Expand All @@ -37,7 +35,7 @@ namespace xeus
std::optional<zmq::multipart_t> xdealer_channel::receive_message(long timeout)
{
zmq::multipart_t wire_msg;
m_socket.set(zmq::sockopt::linger, timeout);
m_socket.set(zmq::sockopt::linger, static_cast<int>(timeout));
if (wire_msg.recv(m_socket))
{
return wire_msg;
Expand Down
6 changes: 3 additions & 3 deletions src/xdealer_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ namespace xeus
public:

xdealer_channel(zmq::context_t& context,
const xeus::xconfiguration& config);
const std::string& transport,
const std::string& ip,
const std::string& port);

~xdealer_channel();

Expand All @@ -34,9 +36,7 @@ namespace xeus
zmq::socket_t& get_socket();

private:

zmq::socket_t m_socket;
std::string m_end_point;
};
}

Expand Down
9 changes: 4 additions & 5 deletions src/xiopub_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@
#include "xclient_zmq_impl.hpp"

#include "xeus-zmq/xzmq_serializer.hpp"
#include "xeus-zmq/xmiddleware.hpp"

namespace xeus
{

xiopub_client::xiopub_client(zmq::context_t& context,
const xeus::xconfiguration& config)
: m_iopub(context, zmq::socket_type::sub)
, m_iopub_end_point("")
, m_controller(context, zmq::socket_type::rep)
{
m_iopub_end_point = xeus::get_end_point(config.m_transport, config.m_ip, config.m_iopub_port);

m_iopub.connect(m_iopub_end_point);
m_iopub.connect(get_end_point(config.m_transport, config.m_ip, config.m_iopub_port));
init_socket(m_controller, get_controller_end_point("iopub"));
}

xiopub_client::~xiopub_client()
{
m_iopub.disconnect(m_iopub_end_point);
}

std::size_t xiopub_client::iopub_queue_size() const
Expand Down
2 changes: 1 addition & 1 deletion src/xiopub_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace xeus

private:
zmq::socket_t m_iopub;
std::string m_iopub_end_point;
zmq::socket_t m_controller;

std::queue<xmessage> m_message_queue;
mutable std::mutex m_queue_mutex;
Expand Down
2 changes: 1 addition & 1 deletion xeus-zmqConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR};${CMAKE_MODULE_PATH}")
@XEUS_ZMQ_CONFIG_CODE@

include(CMakeFindDependencyMacro)
find_dependency(nlohmann_json @nlohmann_json_REQUIRED_VERSION@)
find_dependency(nlohmann_json @nlohmann_json_VERSION@ EXACT)
find_dependency(xeus @xeus_REQUIRED_VERSION@)

# On Unix platforms, ZeroMQ is built with autotools and pkg-config is
Expand Down

0 comments on commit 157a987

Please sign in to comment.