4 #include <websocketpp/server.hpp>
5 #include <websocketpp/config/asio_no_tls.hpp>
6 #include <websocketpp/common/functional.hpp>
9 #include <boost/uuid/uuid.hpp>
11 #include <pybind11/pybind11.h>
12 #include <pybind11/embed.h>
13 #include "nlohmann/json.hpp"
37 Server(
const std::string& socket);
60 void write(
const std::string& txt);
62 std::string
str()
const;
90 virtual uint64_t
send(
const std::string& output,
const std::string& msg_type, uint64_t parent_id=0,
bool last_in_sequence=
false);
96 bool handles(
const std::string& otype)
const;
109 void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket & s);
111 void on_open(websocketpp::connection_hdl hdl);
112 void on_close(websocketpp::connection_hdl hdl);
126 websocketpp::connection_hdl
hdl;
129 typedef std::map<websocketpp::connection_hdl,
Connection,
151 Block(websocketpp::connection_hdl,
const std::string&, uint64_t
id,
const std::string&
msg_type);
152 websocketpp::connection_hdl
hdl;
169 std::string
run_string(
const std::string&,
bool handle_output=
true);
188 std::future<std::string>
job;
194 void dispatch_message(websocketpp::connection_hdl,
const std::string& json_string);
websocketpp::config::asio_client::message_type::ptr message_ptr
Definition: ComputeThread.hh:14
Definition: Server.hh:149
Block(websocketpp::connection_hdl, const std::string &, uint64_t id, const std::string &msg_type)
Definition: Server.cc:374
std::string input
Definition: Server.hh:154
uint64_t cell_id
Definition: Server.hh:157
websocketpp::connection_hdl hdl
Definition: Server.hh:152
std::string output
Definition: Server.hh:155
std::string msg_type
Definition: Server.hh:153
std::string error
Definition: Server.hh:156
nlohmann::json response
Definition: Server.hh:161
Python output catching.
Definition: Server.hh:55
void clear()
Definition: Server.cc:69
std::string str() const
Definition: Server.cc:75
CatchOutput()
Definition: Server.cc:55
std::string collect
Definition: Server.hh:64
void write(const std::string &txt)
Definition: Server.cc:63
Definition: Server.hh:122
boost::uuids::uuid uuid
Definition: Server.hh:127
websocketpp::connection_hdl hdl
Definition: Server.hh:126
Connection()
Definition: Server.cc:256
Object representing a Cadabra server, capable of receiving messages on a websocket,...
Definition: Server.hh:33
websocketpp::server< websocketpp::config::asio > WebsocketServer
Definition: Server.hh:108
void send_progress_update(const std::string &msg, int n, int total)
Definition: Server.cc:546
void init()
Definition: Server.cc:138
websocketpp::connection_hdl current_hdl
Definition: Server.hh:164
CatchOutput catchErr
Definition: Server.hh:67
virtual void on_block_error(Block)
Definition: Server.cc:576
virtual void on_block_finished(Block)
Called by the run_block() thread upon completion of the task.
Definition: Server.cc:475
pybind11::object main_namespace
Definition: Server.hh:199
std::thread runner
Definition: Server.hh:143
std::string authentication_token
Definition: Server.hh:135
pybind11::module main_module
Definition: Server.hh:198
virtual void on_kernel_fault(Block)
Definition: Server.cc:602
ConnectionMap connections
Definition: Server.hh:131
std::future< std::string > job
Definition: Server.hh:188
std::string socket_name
Definition: Server.hh:114
virtual ~Server()
Definition: Server.cc:50
Stopwatch sympy_stopwatch
Definition: Server.hh:70
std::mutex ws_mutex
Definition: Server.hh:139
WebsocketServer wserver
Definition: Server.hh:113
CatchOutput catchOut
Definition: Server.hh:67
void on_close(websocketpp::connection_hdl hdl)
Definition: Server.cc:270
void wait_for_job()
Start a thread which waits for blocks to appear on the block queue, and executes them in turn.
Definition: Server.cc:287
void on_message(websocketpp::connection_hdl hdl, WebsocketServer::message_ptr msg)
Definition: Server.cc:383
bool handles(const std::string &otype) const
Definition: Server.cc:505
virtual uint64_t send(const std::string &output, const std::string &msg_type, uint64_t parent_id=0, bool last_in_sequence=false)
Raw code to send a string (which must be JSON formatted) as a message to the client.
Definition: Server.cc:511
std::map< websocketpp::connection_hdl, Connection, std::owner_less< websocketpp::connection_hdl > > ConnectionMap
Definition: Server.hh:130
void run(int port=0, bool exit_on_disconnect=true)
The only user-visible part: just instantiate a server object and start it with run().
Definition: Server.cc:628
Server(const Server &)=delete
std::string architecture() const
Definition: Server.cc:80
void on_open(websocketpp::connection_hdl hdl)
Definition: Server.cc:261
std::mutex block_available_mutex
Definition: Server.hh:144
pybind11::scoped_interpreter guard
Definition: Server.hh:197
std::string run_string(const std::string &, bool handle_output=true)
Definition: Server.cc:196
std::queue< Block > block_queue
Definition: Server.hh:163
Server()
Definition: Server.cc:33
bool exit_on_disconnect
Definition: Server.hh:146
std::condition_variable block_available
Definition: Server.hh:145
void stop_block()
Halt the currently running block and prevent execution of any further blocks that may still be on the...
Definition: Server.cc:366
void send_json(const std::string &)
Definition: Server.cc:569
void dispatch_message(websocketpp::connection_hdl, const std::string &json_string)
Takes a JSON encoded message and performs the required action to process it.
Definition: Server.cc:400
Stopwatch server_stopwatch
Definition: Server.hh:69
void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket &s)
Definition: Server.cc:249
uint64_t current_id
Definition: Server.hh:165
bool started
Definition: Server.hh:187
The Stopwach class provides a simple interace to allow timing function calls etc.....
Definition: Stopwatch.hh:107