Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
ComputeThread.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include <signal.h>
5#include <thread>
6#include <set>
7#include <glibmm/spawn.h>
8#include "websocket_client.hh"
9
10#include "DataCell.hh"
11
12namespace cadabra {
13
14 class GUIBase;
15 class DocumentThread;
16
28
30 public:
33
34 ComputeThread(int server_port=0, std::string token="", std::string ip_address="127.0.0.1");
35 ComputeThread(const ComputeThread& )=delete; // You cannot copy this object
37
41
46
47 void run();
48
59
60 void execute_cell(DTree::iterator);
61
62 void execute_interactive(uint64_t id, const std::string& code);
63
66
67 void stop();
68
70
71 void restart_kernel();
72
78
79 bool complete(DTree::iterator, int pos, int alternative);
80
81 // Determine if there are still cells running on the server.
82 // FIXME: this does not guarantee thread-safety but at the moment
83 // is only used for updating status bars etc.
84 // FIXME: can be moved to DocumentThread.
85
86 int number_of_cells_executing(void) const;
87
90
91 void terminate();
92
94 bool kernel_is_connected() const;
95
96 private:
99
100 // For debugging purposes, we keep record of the gui thread id,
101 // so that we can flag when code runs on the wrong thread.
102 // Gets initialised in the ComputeThread constructor.
103 std::thread::id gui_thread_id;
104
105 // Keeping track of cells which are running on the server, in
106 // a form which allows us to look them up quickly based only
107 // on the id (which is all that the server knows about).
108
109 // FIXME: moving this away into documentthread, so that we only need to refer to id's.
110 std::map<DataCell::id_t, DTree::iterator> running_cells;
111
112 // WebSocket++ things.
115
116 void init();
117 void try_connect();
118 void try_spawn_server();
119 void on_open();
120 void on_fail(const boost::beast::error_code&);
121 void on_close();
122 void on_message(const std::string& msg);
123
125
129
130 std::set<uint64_t> interactive_cells;
131
132 // Self-started server
133 Glib::Pid server_pid;
135 unsigned short port;
140 };
141
142 }
Base class which talks to the server and sends Action objects back to the DocumentThread.
Definition ComputeThread.hh:29
void execute_cell(DTree::iterator)
In order to execute code on the server, call the following from the GUI thread.
Definition ComputeThread.cc:479
void init()
Definition ComputeThread.cc:47
void try_connect()
Definition ComputeThread.cc:52
void stop()
Stop the current cell execution on the server and remove all other cells from the run queue as well.
Definition ComputeThread.cc:560
~ComputeThread()
Definition ComputeThread.cc:29
std::thread::id gui_thread_id
Definition ComputeThread.hh:103
std::string authentication_token
Definition ComputeThread.hh:136
std::string forced_server_ip_address
Definition ComputeThread.hh:139
void run()
Main entry point, which will connect to the server and then start an event loop to handle communicati...
Definition ComputeThread.cc:66
Glib::Pid server_pid
Definition ComputeThread.hh:133
void on_open()
Definition ComputeThread.cc:205
std::string forced_server_token
Definition ComputeThread.hh:138
void on_close()
Definition ComputeThread.cc:234
bool kernel_is_connected() const
Return the status of the connection to the kernel.
Definition ComputeThread.cc:103
void restart_kernel()
Restart the kernel.
Definition ComputeThread.cc:584
ComputeThread(const ComputeThread &)=delete
bool connection_is_open
Definition ComputeThread.hh:114
int server_stdout
Definition ComputeThread.hh:134
bool restarting_kernel
Definition ComputeThread.hh:114
int forced_server_port
Definition ComputeThread.hh:137
void terminate()
Terminate the compute thread, in preparation for shutting down the client altogether.
Definition ComputeThread.cc:78
void cell_finished_running(DataCell::id_t)
Definition ComputeThread.cc:253
void try_spawn_server()
Definition ComputeThread.cc:144
GUIBase * gui
Definition ComputeThread.hh:97
websocket_client wsclient
Definition ComputeThread.hh:113
std::map< DataCell::id_t, DTree::iterator > running_cells
Definition ComputeThread.hh:110
DocumentThread * docthread
Definition ComputeThread.hh:98
std::set< uint64_t > interactive_cells
Definition ComputeThread.hh:130
int number_of_cells_executing(void) const
Definition ComputeThread.cc:555
void on_fail(const boost::beast::error_code &)
Definition ComputeThread.cc:122
void all_cells_nonrunning()
Set all cells to be non-running (e.g.
Definition ComputeThread.cc:108
void set_master(GUIBase *, DocumentThread *)
Determine the objects that this compute thread should be talking to.
Definition ComputeThread.cc:41
void execute_interactive(uint64_t id, const std::string &code)
Definition ComputeThread.cc:449
void on_message(const std::string &msg)
Definition ComputeThread.cc:264
int server_stderr
Definition ComputeThread.hh:134
unsigned short port
Definition ComputeThread.hh:135
Each cell is identified by a serial number 'id' which is used to keep track of it across network call...
Definition DataCell.hh:52
A base class with all the logic to manipulate a Cadabra notebook document.
Definition DocumentThread.hh:41
Abstract base class with methods that need to be implemented by any GUI.
Definition GUIBase.hh:16
Complete a set of coordinate rules so that they also cover related tensors.
Definition complete.hh:14
Definition websocket_client.hh:15
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83