Cadabra
Computer algebra system for field theory problems
|
#include <SnoopPrivate.hh>
Public Member Functions | |
SnoopImpl (Snoop *) | |
~SnoopImpl () | |
Snoop & | operator<< (const Flush &) |
void | init (const std::string &app_name, const std::string &app_version, std::string server="", std::string local_database_name="") |
Initialise the logging stream. More... | |
std::string | get_user_uuid (const std::string &app_name) |
Get a string which uniquely identifies the current user. More... | |
Snoop & | payload (const std::vector< char > &) |
Log payload data. More... | |
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. More... | |
void | set_local_type (const std::string &type) |
void | sync_with_server (bool from_wsthread=false) |
Ensure that the local database is synchronised with the. More... | |
void | sync_runs_with_server (bool from_wsthread=false) |
As above, but only for run entries. More... | |
void | sync_logs_with_server (bool from_wsthread=false) |
As above, but only for log entries. More... | |
void | sync_payloads_with_server (bool from_wsthread=false) |
As above, but only for payload data. More... | |
bool | is_connected () const |
Are we connected to the log server? More... | |
std::string | last_seen_version (std::string machine_id) |
Return version of last run seen on given device. More... | |
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 when the response comes back. More... | |
bool | is_ticket_valid (std::string ticket_uuid) |
Get status of a given authentication ticket. More... | |
std::string | ticket_for_login (std::string user, std::string password) |
Get status of given user/pass combo. More... | |
bool | add_user (std::string user, std::string password) |
Add a user/password combo to the user database. More... | |
void | start_websocket_client () |
Start the websocket client. More... | |
void | create_tables () |
Ensure that the required tables are present in the database file. More... | |
void | create_authentication_tables () |
Ensure that the required authentication tables are present in the authentication database. More... | |
void | obtain_uuid () |
Obtain a uuid by finding the last AppEntry stored in the local database. More... | |
bool | store_app_entry (Snoop::AppEntry &) |
Store an app entry in the database. More... | |
bool | store_app_entry_without_lock (Snoop::AppEntry &) |
bool | store_log_entry (Snoop::LogEntry &, bool avoid_server_duplicates) |
Store a log entry in the local database. More... | |
bool | store_payload_entry (Snoop::PayLoad &) |
Store payload data in the local database. More... | |
std::vector< Snoop::AppEntry > | get_app_registrations (std::string uuid_filter="") |
Return a vector of all aps registered in the database. More... | |
void | on_client_open (websocketpp::connection_hdl hdl) |
void | on_client_fail (websocketpp::connection_hdl hdl) |
void | on_client_close (websocketpp::connection_hdl hdl) |
void | on_client_message (websocketpp::connection_hdl hdl, message_ptr msg) |
Public Attributes | |
Snoop * | snoop_ |
sqlite3 * | db |
sqlite3 * | payload_db |
sqlite3 * | auth_db |
Snoop::AppEntry | this_app_ |
Snoop::LogEntry | this_log_ |
std::string | server_ |
sqlite3_stmt * | insert_statement |
Prepared statements (only need to prepare these once). More... | |
sqlite3_stmt * | id_for_uuid_statement |
sqlite3_stmt * | payload_insert_statement |
std::mutex | sqlite_mutex |
WebsocketClient | wsclient |
Websocket client to talk to a remote logging server. More... | |
std::thread | wsclient_thread |
std::mutex | connection_mutex |
std::condition_variable | connection_cv |
bool | connection_is_open |
bool | connection_attempt_failed |
WebsocketClient::connection_ptr | connection |
websocketpp::connection_hdl | our_connection_hdl |
Private Member Functions | |
void | store_ticket (std::string ticket_uuid, int user_id, bool valid) |
Private Attributes | |
std::mutex | call_mutex |
bool | secure |
std::set< std::string > | local_types |
std::function< void(std::string, bool)> | authentication_callback |
snoop::SnoopImpl::SnoopImpl | ( | Snoop * | ) |
snoop::SnoopImpl::~SnoopImpl | ( | ) |
bool snoop::SnoopImpl::add_user | ( | std::string | user, |
std::string | password | ||
) |
Add a user/password combo to the user database.
bool snoop::SnoopImpl::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 when the response comes back.
void snoop::SnoopImpl::create_authentication_tables | ( | ) |
Ensure that the required authentication tables are present in the authentication database.
Only used on the server.
void snoop::SnoopImpl::create_tables | ( | ) |
Ensure that the required tables are present in the database file.
std::vector<Snoop::AppEntry> snoop::SnoopImpl::get_app_registrations | ( | std::string | uuid_filter = "" | ) |
Return a vector of all aps registered in the database.
If the uuid filter is non-empty, will filter on the given uuid.
std::string snoop::SnoopImpl::get_user_uuid | ( | const std::string & | app_name | ) |
Get a string which uniquely identifies the current user.
This is stored in ~/.config/snoop/appname.conf.
void snoop::SnoopImpl::init | ( | const std::string & | app_name, |
const std::string & | app_version, | ||
std::string | server = "" , |
||
std::string | local_database_name = "" |
||
) |
Initialise the logging stream.
Should be called once at program startup, but can be called multiple times without causing problems. The 'local_database_name' should be a full path but without extension; the main database name will be this path with '.sql' added, while the payload database will have '_payload.sql' at the end.
bool snoop::SnoopImpl::is_connected | ( | ) | const |
Are we connected to the log server?
bool snoop::SnoopImpl::is_ticket_valid | ( | std::string | ticket_uuid | ) |
Get status of a given authentication ticket.
std::string snoop::SnoopImpl::last_seen_version | ( | std::string | machine_id | ) |
Return version of last run seen on given device.
void snoop::SnoopImpl::obtain_uuid | ( | ) |
Obtain a uuid by finding the last AppEntry stored in the local database.
Will attempt to re-turn a previously generated uuid but will do so only if one is stored for the current pid; if no entry with the current pid is stored then a new one will always be generated.
void snoop::SnoopImpl::on_client_close | ( | websocketpp::connection_hdl | hdl | ) |
void snoop::SnoopImpl::on_client_fail | ( | websocketpp::connection_hdl | hdl | ) |
void snoop::SnoopImpl::on_client_message | ( | websocketpp::connection_hdl | hdl, |
message_ptr | msg | ||
) |
void snoop::SnoopImpl::on_client_open | ( | websocketpp::connection_hdl | hdl | ) |
Snoop& snoop::SnoopImpl::operator() | ( | const std::string & | type, |
std::string | fl = "" , |
||
int | loc = -1 , |
||
std::string | method = "" |
||
) |
Operator to initialise a logging entry with the type of.
the log message as well as (optionally) the file, line number and method. Thread-safe: can be called from different threads at the same time.
Snoop& snoop::SnoopImpl::payload | ( | const std::vector< char > & | ) |
Log payload data.
void snoop::SnoopImpl::set_local_type | ( | const std::string & | type | ) |
void snoop::SnoopImpl::start_websocket_client | ( | ) |
Start the websocket client.
This tries to connect to the server and then waits in a separate thread until the server sends us something (typically in response to something the main thread makes by calling wsclient.send).
bool snoop::SnoopImpl::store_app_entry | ( | Snoop::AppEntry & | ) |
Store an app entry in the database.
Will update the 'id' field in the AppEntry.
bool snoop::SnoopImpl::store_app_entry_without_lock | ( | Snoop::AppEntry & | ) |
bool snoop::SnoopImpl::store_log_entry | ( | Snoop::LogEntry & | , |
bool | avoid_server_duplicates | ||
) |
Store a log entry in the local database.
Generates its own receive_millis field (the one given gets overwritten). Will update the 'id' field in the LogEntry. Returns 'true' if the entry was stored, or 'false' if an entry with this client_log_id was already present (except when it is 0).
bool snoop::SnoopImpl::store_payload_entry | ( | Snoop::PayLoad & | ) |
Store payload data in the local database.
|
private |
void snoop::SnoopImpl::sync_logs_with_server | ( | bool | from_wsthread = false | ) |
As above, but only for log entries.
void snoop::SnoopImpl::sync_payloads_with_server | ( | bool | from_wsthread = false | ) |
As above, but only for payload data.
void snoop::SnoopImpl::sync_runs_with_server | ( | bool | from_wsthread = false | ) |
As above, but only for run entries.
void snoop::SnoopImpl::sync_with_server | ( | bool | from_wsthread = false | ) |
Ensure that the local database is synchronised with the.
server (this sends multiple app or log entries in one websocket message). Leave the bool argument at its default argument under all normal circumstances.
std::string snoop::SnoopImpl::ticket_for_login | ( | std::string | user, |
std::string | password | ||
) |
Get status of given user/pass combo.
This queries the underlying authentication database table. If the login is valid, a ticket will be inserted in the database and returned. An empty string is returned if login is invalid.
sqlite3 * snoop::SnoopImpl::auth_db |
|
private |
|
private |
WebsocketClient::connection_ptr snoop::SnoopImpl::connection |
bool snoop::SnoopImpl::connection_attempt_failed |
std::condition_variable snoop::SnoopImpl::connection_cv |
bool snoop::SnoopImpl::connection_is_open |
std::mutex snoop::SnoopImpl::connection_mutex |
sqlite3* snoop::SnoopImpl::db |
sqlite3_stmt * snoop::SnoopImpl::id_for_uuid_statement |
sqlite3_stmt* snoop::SnoopImpl::insert_statement |
Prepared statements (only need to prepare these once).
|
private |
websocketpp::connection_hdl snoop::SnoopImpl::our_connection_hdl |
sqlite3 * snoop::SnoopImpl::payload_db |
sqlite3_stmt * snoop::SnoopImpl::payload_insert_statement |
|
private |
std::string snoop::SnoopImpl::server_ |
Snoop* snoop::SnoopImpl::snoop_ |
std::mutex snoop::SnoopImpl::sqlite_mutex |
Snoop::AppEntry snoop::SnoopImpl::this_app_ |
Snoop::LogEntry snoop::SnoopImpl::this_log_ |
WebsocketClient snoop::SnoopImpl::wsclient |
Websocket client to talk to a remote logging server.
std::thread snoop::SnoopImpl::wsclient_thread |