Skip to content

Commit

Permalink
Added initial interface fro xshell_client
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Feb 16, 2024
1 parent 26bca15 commit 1ea2ae9
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
34 changes: 34 additions & 0 deletions include/xeus-zmq/xclient_zmq.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/***************************************************************************
* 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 <nlohmann/json.hpp>

namespace xeus
{
class xclient_zmq_impl;

class XEUS_ZMQ_API xclient_zmq
{
public:
explicit xclient_zmq(std::unique_ptr<xclient_zmq_impl> impl);
~xclient_zmq();

void send_shell(const nl::json& message);

nl::json check_shell_answer();

private:
std::unique_ptr<xclient_zmq_impl> p_client_impl;
};
}

#endif
31 changes: 31 additions & 0 deletions src/xclient_messenger.hpp
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_shell_controller;
// Add more controller sockets as needed for other channels
};
}
54 changes: 54 additions & 0 deletions src/xclient_zmq_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/***************************************************************************
* 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_IMPL_HPP
#define XEUS_CLIENT_ZMQ_IMPL_HPP

#include "xshell_client.hpp"
#include "xclient_messenger.hpp"

#include <nlohmann/json.hpp>

namespace xeus
{
class xclient_zmq_impl
{
public:

virtual ~xclient_zmq_impl() = default;

xclient_zmq_impl(const xclient_zmq_impl&) = delete;
xclient_zmq_impl& operator=(const xclient_zmq_impl&) = delete;

xclient_zmq_impl(xclient_zmq_impl&&) = delete;
xclient_zmq_impl& operator=(xclient_zmq_impl&&) = delete;

xclient_messenger& get_client_messenger();

void start_channels();

void send_shell_message(const nl::json& message);

void create_shell_client();

protected:

xclient_zmq_impl() = default;

private:

using client_messenger_ptr = std::unique_ptr<xclient_messenger>;
client_messenger_ptr p_messenger;

xshell_client m_shell_client;
// Other channel clients can be added here
};
}

#endif
64 changes: 64 additions & 0 deletions src/xshell_client.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/***************************************************************************
* 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_SHELL_CLIENT_HPP
#define XEUS_SHELL_CLIENT_HPP

#include "zmq.hpp"
#include "nlohmann/json.hpp"
#include "xeus/xkernel_configuration.hpp"
#include "xeus-zmq/xauthentication.hpp"

namespace xeus
{

class xshell_client
{
public:

xshell_client(zmq::context_t& context,
const std::string& user_name,
const xeus::xconfiguration& config);

~xshell_client();

protected:

void send_on_shell(nl::json header,
nl::json parent_header,
nl::json metadata,
nl::json content);

nl::json receive_on_shell();

nl::json check_received_message(long timeout);

zmq::socket& get_socket();

private:
void send_message(nl::json header,
nl::json parent_header,
nl::json metadata,
nl::json content,
zmq::socket_t& socket,
const xeus::xauthentication& auth);

nl::json receive_message(zmq::socket_t& socket,
const xeus::xauthentication& auth);

using authentication_ptr = std::unique_ptr<xeus::xauthentication>;
authentication_ptr p_authentication;

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

#endif

0 comments on commit 1ea2ae9

Please sign in to comment.