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> 36 Server(
const std::string& socket);
59 void write(
const std::string& txt);
61 std::string
str()
const;
89 virtual uint64_t
send(
const std::string& output,
const std::string& msg_type, uint64_t parent_id=0,
bool last_in_sequence=
false);
93 bool handles(
const std::string& otype)
const;
106 void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket & s);
108 void on_open(websocketpp::connection_hdl hdl);
109 void on_close(websocketpp::connection_hdl hdl);
123 websocketpp::connection_hdl
hdl;
126 typedef std::map<websocketpp::connection_hdl,
Connection,
148 Block(websocketpp::connection_hdl,
const std::string&, uint64_t
id);
149 websocketpp::connection_hdl
hdl;
161 std::string
run_string(
const std::string&,
bool handle_output=
true);
173 virtual void on_complete_finished(websocketpp::connection_hdl hdl, uint64_t
id,
int pos,
int alternative, std::string original, std::string completed);
181 std::future<std::string>
job;
187 void dispatch_message(websocketpp::connection_hdl,
const std::string& json_string);
websocketpp::server< websocketpp::config::asio > WebsocketServer
Definition: Server.hh:105
std::string collect
Definition: Server.hh:63
Object representing a Cadabra server, capable of receiving messages on a websocket, running Python code, and sending output back to the client.
Definition: Server.hh:32
std::thread runner
Definition: Server.hh:140
std::future< std::string > job
Definition: Server.hh:181
void on_message(websocketpp::connection_hdl hdl, WebsocketServer::message_ptr msg)
Definition: Server.cc:339
virtual void on_kernel_fault(Block)
Definition: Server.cc:527
std::string error
Definition: Server.hh:152
std::string output
Definition: Server.hh:151
std::map< websocketpp::connection_hdl, Connection, std::owner_less< websocketpp::connection_hdl > > ConnectionMap
Definition: Server.hh:127
The Stopwach class provides a simple interace to allow timing function calls etc...
Definition: Stopwatch.hh:107
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:553
CatchOutput catchOut
Definition: Server.hh:66
WebsocketServer wserver
Definition: Server.hh:110
uint64_t cell_id
Definition: Server.hh:153
CatchOutput catchErr
Definition: Server.hh:66
virtual void on_complete_finished(websocketpp::connection_hdl hdl, uint64_t id, int pos, int alternative, std::string original, std::string completed)
Definition: Server.cc:504
void clear()
Definition: Server.cc:69
void on_open(websocketpp::connection_hdl hdl)
Definition: Server.cc:221
CatchOutput()
Definition: Server.cc:55
bool handles(const std::string &otype) const
Definition: Server.cc:432
void write(const std::string &txt)
Definition: Server.cc:63
Block(websocketpp::connection_hdl, const std::string &, uint64_t id)
Definition: Server.cc:334
pybind11::scoped_interpreter guard
Definition: Server.hh:190
std::string authentication_token
Definition: Server.hh:132
void stop_block()
Halt the currently running block and prevent execution of any further blocks that may still be on the...
Definition: Server.cc:326
Stopwatch server_stopwatch
Definition: Server.hh:68
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:247
Python output catching.
Definition: Server.hh:54
ConnectionMap connections
Definition: Server.hh:128
virtual void on_block_error(Block)
Definition: Server.cc:478
boost::uuids::uuid uuid
Definition: Server.hh:124
std::string socket_name
Definition: Server.hh:111
uint64_t current_id
Definition: Server.hh:157
void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket &s)
Definition: Server.cc:209
Definition: Server.hh:146
bool started
Definition: Server.hh:180
std::mutex ws_mutex
Definition: Server.hh:136
pybind11::module main_module
Definition: Server.hh:191
virtual void on_block_finished(Block)
Called by the run_block() thread upon completion of the task.
Definition: Server.cc:427
websocketpp::connection_hdl hdl
Definition: Server.hh:149
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:438
Connection()
Definition: Server.cc:216
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:356
std::string architecture() const
Definition: Server.cc:80
std::condition_variable block_available
Definition: Server.hh:142
bool exit_on_disconnect
Definition: Server.hh:143
std::mutex block_available_mutex
Definition: Server.hh:141
std::queue< Block > block_queue
Definition: Server.hh:155
Stopwatch sympy_stopwatch
Definition: Server.hh:69
std::string str() const
Definition: Server.cc:75
pybind11::object main_namespace
Definition: Server.hh:192
websocketpp::connection_hdl hdl
Definition: Server.hh:123
Server()
Definition: Server.cc:33
void on_close(websocketpp::connection_hdl hdl)
Definition: Server.cc:230
std::string input
Definition: Server.hh:150
void init()
Definition: Server.cc:100
Definition: Server.hh:119
websocketpp::config::asio_client::message_type::ptr message_ptr
Definition: ComputeThread.hh:13
websocketpp::connection_hdl current_hdl
Definition: Server.hh:156
virtual ~Server()
Definition: Server.cc:50
std::string run_string(const std::string &, bool handle_output=true)
Definition: Server.cc:156
void send_json(const std::string &)
Definition: Server.cc:471