-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from anutosh491/implement_xshell_client
[WIP] Adding support for xshell_client class
- Loading branch information
Showing
14 changed files
with
785 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*************************************************************************** | ||
* 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_CLIENT_ZMQ_HPP | ||
#define XEUS_CLIENT_ZMQ_HPP | ||
|
||
#include <optional> | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
#include "xeus/xeus_context.hpp" | ||
#include "xeus/xkernel_configuration.hpp" | ||
#include "xeus/xmessage.hpp" | ||
|
||
#include "xeus-zmq.hpp" | ||
|
||
namespace xeus | ||
{ | ||
class xclient_zmq_impl; | ||
|
||
class XEUS_ZMQ_API xclient_zmq | ||
{ | ||
public: | ||
|
||
using listener = std::function<void(xmessage)>; | ||
|
||
explicit xclient_zmq(std::unique_ptr<xclient_zmq_impl> impl); | ||
~xclient_zmq(); | ||
|
||
void send_on_shell(xmessage msg); | ||
void send_on_control(xmessage msg); | ||
|
||
std::optional<xmessage> check_shell_answer(); | ||
std::optional<xmessage> check_control_answer(); | ||
|
||
void register_shell_listener(const listener& l); | ||
void register_control_listener(const listener& l); | ||
void register_iopub_listener(const listener& l); | ||
|
||
void notify_shell_listener(xmessage msg); | ||
void notify_control_listener(xmessage msg); | ||
void notify_iopub_listener(xmessage msg); | ||
|
||
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; | ||
}; | ||
|
||
XEUS_ZMQ_API | ||
std::unique_ptr<xclient_zmq> make_xclient_zmq(xcontext& context, | ||
const xconfiguration& config, | ||
nl::json::error_handler_t eh = nl::json::error_handler_t::strict); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*************************************************************************** | ||
* 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. * | ||
****************************************************************************/ | ||
|
||
#include "nlohmann/json.hpp" | ||
#include "xeus-zmq/xmiddleware.hpp" | ||
#include "xclient_messenger.hpp" | ||
|
||
namespace nl = nlohmann; | ||
|
||
namespace xeus | ||
{ | ||
xclient_messenger::xclient_messenger(zmq::context_t& context) | ||
: m_iopub_controller(context, zmq::socket_type::req) | ||
{ | ||
} | ||
|
||
xclient_messenger::~xclient_messenger() | ||
{ | ||
} | ||
|
||
void xclient_messenger::connect() | ||
{ | ||
m_iopub_controller.set(zmq::sockopt::linger, get_socket_linger()); | ||
m_iopub_controller.connect(get_controller_end_point("iopub")); | ||
} | ||
|
||
void xclient_messenger::stop_channels() | ||
{ | ||
zmq::message_t stop_msg("stop", 4); | ||
zmq::message_t response; | ||
|
||
// Wait for iopub answer | ||
m_iopub_controller.send(stop_msg, zmq::send_flags::none); | ||
(void)m_iopub_controller.recv(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*************************************************************************** | ||
* 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_CLIENT_MESSENGER_HPP | ||
#define XEUS_CLIENT_MESSENGER_HPP | ||
|
||
#include <zmq.hpp> | ||
|
||
namespace xeus | ||
{ | ||
class xclient_messenger | ||
{ | ||
public: | ||
explicit xclient_messenger(zmq::context_t& context); | ||
virtual ~xclient_messenger(); | ||
|
||
void connect(); | ||
void stop_channels(); | ||
|
||
private: | ||
zmq::socket_t m_iopub_controller; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/*************************************************************************** | ||
* 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. * | ||
****************************************************************************/ | ||
|
||
#include "xeus-zmq/xclient_zmq.hpp" | ||
#include "xclient_zmq_impl.hpp" | ||
|
||
namespace xeus | ||
{ | ||
|
||
xclient_zmq::xclient_zmq(std::unique_ptr<xclient_zmq_impl> impl) | ||
: p_client_impl(std::move(impl)) | ||
{ | ||
} | ||
|
||
// Has to be in the cpp because incomplete | ||
// types are used in unique_ptr in the header | ||
xclient_zmq::~xclient_zmq() = default; | ||
|
||
|
||
void xclient_zmq::send_on_shell(xmessage msg) | ||
{ | ||
p_client_impl->send_on_shell(std::move(msg)); | ||
} | ||
|
||
void xclient_zmq::send_on_control(xmessage msg) | ||
{ | ||
p_client_impl->send_on_control(std::move(msg)); | ||
} | ||
|
||
std::optional<xmessage> xclient_zmq::check_shell_answer() | ||
{ | ||
return p_client_impl->receive_on_shell(-1); | ||
} | ||
|
||
std::optional<xmessage> xclient_zmq::check_control_answer() | ||
{ | ||
return p_client_impl->receive_on_control(-1); | ||
} | ||
|
||
void xclient_zmq::register_shell_listener(const listener& l) | ||
{ | ||
p_client_impl->register_shell_listener(l); | ||
} | ||
|
||
void xclient_zmq::register_control_listener(const listener& l) | ||
{ | ||
p_client_impl->register_control_listener(l); | ||
} | ||
|
||
void xclient_zmq::register_iopub_listener(const listener& l) | ||
{ | ||
p_client_impl->register_iopub_listener(l); | ||
} | ||
|
||
void xclient_zmq::notify_shell_listener(xmessage msg) | ||
{ | ||
p_client_impl->notify_shell_listener(std::move(msg)); | ||
} | ||
|
||
void xclient_zmq::notify_control_listener(xmessage msg) | ||
{ | ||
p_client_impl->notify_control_listener(std::move(msg)); | ||
} | ||
|
||
void xclient_zmq::notify_iopub_listener(xmessage msg) | ||
{ | ||
p_client_impl->notify_iopub_listener(std::move(msg)); | ||
} | ||
|
||
std::size_t xclient_zmq::iopub_queue_size() const | ||
{ | ||
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) | ||
{ | ||
auto impl = std::make_unique<xclient_zmq_impl>(context.get_wrapped_context<zmq::context_t>(), config, eh); | ||
return std::make_unique<xclient_zmq>(std::move(impl)); | ||
} | ||
} |
Oops, something went wrong.