Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
SnoopPrivate.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include <websocketpp/config/asio_no_tls_client.hpp>
5#include <websocketpp/client.hpp>
6#include <websocketpp/common/thread.hpp>
7#include <websocketpp/common/functional.hpp>
8#include <mutex>
9#include <condition_variable>
10#include <thread>
11#include <set>
12
13typedef websocketpp::client<websocketpp::config::asio_client> WebsocketClient;
14typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
15
16namespace snoop {
17
18 class SnoopImpl {
19 public:
22
24
31
32 void init(const std::string& app_name, const std::string& app_version,
33 std::string server="", std::string local_database_name="");
34
37
38 std::string get_user_uuid(const std::string& app_name);
39
41 Snoop& payload(const std::vector<char>&);
42
47
48 Snoop& operator()(const std::string& type, std::string fl="", int loc=-1, std::string method="");
49
50 void set_local_type(const std::string& type);
51
56
58
60
62
64
66
68
70
72
73 bool is_connected() const;
74
76
77 std::string last_seen_version(std::string machine_id);
78
82
83 bool authenticate(std::function<void (std::string, bool)>, std::string user="", std::string pass="");
84
86
87 bool is_ticket_valid(std::string ticket_uuid);
88
93
94 std::string ticket_for_login(std::string user, std::string password);
95
97
98 bool add_user(std::string user, std::string password);
99
101
103
106 std::string server_;
107
111
113
116
118
121
123
129
131
134
137
144
146
148
150
154
155 std::vector<Snoop::AppEntry> get_app_registrations(std::string uuid_filter="");
156
158
160 std::mutex sqlite_mutex;
161
163
165 std::thread wsclient_thread;
167 std::condition_variable connection_cv;
169 WebsocketClient::connection_ptr connection;
170 websocketpp::connection_hdl our_connection_hdl;
171
172 void on_client_open(websocketpp::connection_hdl hdl);
173 void on_client_fail(websocketpp::connection_hdl hdl);
174 void on_client_close(websocketpp::connection_hdl hdl);
175 void on_client_message(websocketpp::connection_hdl hdl, message_ptr msg);
176
177 private:
178 std::mutex call_mutex;
179 bool secure;
180
181 std::set<std::string> local_types;
182// std::set<std::string> ...
183 std::function<void (std::string, bool)> authentication_callback;
184
185 void store_ticket(std::string ticket_uuid, int user_id, bool valid);
186 };
187}
websocketpp::client< websocketpp::config::asio_client > client
Definition ComputeThread.cc:15
websocketpp::config::asio_client::message_type::ptr message_ptr
Definition ComputeThread.hh:14
websocketpp::client< websocketpp::config::asio_client > WebsocketClient
Definition Snoop.hh:39
websocketpp::client< websocketpp::config::asio_client > WebsocketClient
Definition SnoopPrivate.hh:13
websocketpp::config::asio_client::message_type::ptr message_ptr
Definition SnoopPrivate.hh:14
Definition Snoop.hh:48
C++ representation of a run entry.
Definition Snoop.hh:151
C++ representation of a log entry.
Definition Snoop.hh:180
C++ representation of a payload entry.
Definition Snoop.hh:209
Logging class with functionality to send log information to a remote server using a websocket connect...
Definition Snoop.hh:54
Definition SnoopPrivate.hh:18
void sync_payloads_with_server(bool from_wsthread=false)
As above, but only for payload data.
bool add_user(std::string user, std::string password)
Add a user/password combo to the user database.
void obtain_uuid()
Obtain a uuid by finding the last AppEntry stored in the local database.
void on_client_message(websocketpp::connection_hdl hdl, message_ptr msg)
sqlite3_stmt * insert_statement
Prepared statements (only need to prepare these once).
Definition SnoopPrivate.hh:159
bool connection_attempt_failed
Definition SnoopPrivate.hh:168
bool store_app_entry_without_lock(Snoop::AppEntry &)
void start_websocket_client()
Start the websocket client.
std::string get_user_uuid(const std::string &app_name)
Get a string which uniquely identifies the current user.
std::mutex connection_mutex
Definition SnoopPrivate.hh:166
bool store_app_entry(Snoop::AppEntry &)
Store an app entry in the database.
void on_client_close(websocketpp::connection_hdl hdl)
void create_tables()
Ensure that the required tables are present in the database file.
sqlite3_stmt * id_for_uuid_statement
Definition SnoopPrivate.hh:159
std::string last_seen_version(std::string machine_id)
Return version of last run seen on given device.
void on_client_fail(websocketpp::connection_hdl hdl)
Snoop & operator<<(const Flush &)
std::function< void(std::string, bool)> authentication_callback
Definition SnoopPrivate.hh:183
void sync_with_server(bool from_wsthread=false)
Ensure that the local database is synchronised with the.
Snoop * snoop_
Definition SnoopPrivate.hh:100
std::thread wsclient_thread
Definition SnoopPrivate.hh:165
void sync_logs_with_server(bool from_wsthread=false)
As above, but only for log entries.
std::mutex call_mutex
Definition SnoopPrivate.hh:178
void on_client_open(websocketpp::connection_hdl hdl)
WebsocketClient wsclient
Websocket client to talk to a remote logging server.
Definition SnoopPrivate.hh:164
bool store_payload_entry(Snoop::PayLoad &)
Store payload data in the local database.
void init(const std::string &app_name, const std::string &app_version, std::string server="", std::string local_database_name="")
Initialise the logging stream.
sqlite3 * auth_db
Definition SnoopPrivate.hh:102
std::vector< Snoop::AppEntry > get_app_registrations(std::string uuid_filter="")
Return a vector of all aps registered in the database.
Snoop::AppEntry this_app_
Definition SnoopPrivate.hh:104
bool connection_is_open
Definition SnoopPrivate.hh:168
bool store_log_entry(Snoop::LogEntry &, bool avoid_server_duplicates)
Store a log entry in the local database.
SnoopImpl(Snoop *)
void set_local_type(const std::string &type)
Snoop & payload(const std::vector< char > &)
Log payload data.
bool is_connected() const
Are we connected to the log server?
bool is_ticket_valid(std::string ticket_uuid)
Get status of a given authentication ticket.
Snoop::LogEntry this_log_
Definition SnoopPrivate.hh:105
Snoop & operator()(const std::string &type, std::string fl="", int loc=-1, std::string method="")
Operator to initialise a logging entry with the type of.
void create_authentication_tables()
Ensure that the required authentication tables are present in the authentication database.
std::mutex sqlite_mutex
Definition SnoopPrivate.hh:160
void sync_runs_with_server(bool from_wsthread=false)
As above, but only for run entries.
bool secure
Definition SnoopPrivate.hh:179
bool authenticate(std::function< void(std::string, bool)>, std::string user="", std::string pass="")
Authentication logic; passes ticket or credentials to server, and registers callback function for whe...
void store_ticket(std::string ticket_uuid, int user_id, bool valid)
std::set< std::string > local_types
Definition SnoopPrivate.hh:181
sqlite3 * payload_db
Definition SnoopPrivate.hh:102
sqlite3_stmt * payload_insert_statement
Definition SnoopPrivate.hh:159
std::string ticket_for_login(std::string user, std::string password)
Get status of given user/pass combo.
std::condition_variable connection_cv
Definition SnoopPrivate.hh:167
std::string server_
Definition SnoopPrivate.hh:106
sqlite3 * db
Definition SnoopPrivate.hh:102
WebsocketClient::connection_ptr connection
Definition SnoopPrivate.hh:169
websocketpp::connection_hdl our_connection_hdl
Definition SnoopPrivate.hh:170
Definition Snoop.hh:45