Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
12 typedef websocketpp::client<websocketpp::config::asio_client> WebsocketClient;
13 typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
14 
15 namespace snoop {
16 
17  class SnoopImpl {
18  public:
19  SnoopImpl(Snoop *);
20  ~SnoopImpl();
21 
22  Snoop& operator<<(const Flush&);
23 
27 
28  void init(const std::string& app_name, const std::string& app_version,
29  std::string server="", std::string local_log_file="");
30 
33 
34  std::string get_user_uuid(const std::string& app_name);
35 
40 
41  Snoop& operator()(const std::string& type, std::string fl="", int loc=-1, std::string method="");
42 
47 
48  void sync_with_server(bool from_wsthread=false);
49 
51 
52  void sync_runs_with_server(bool from_wsthread=false);
53 
55 
56  void sync_logs_with_server(bool from_wsthread=false);
57 
59 
60  sqlite3 *db;
61 
64  std::string server_;
65 
69 
71 
74 
75  void create_tables();
76 
82 
83  void obtain_uuid();
84 
87 
90 
97 
98  bool store_log_entry(Snoop::LogEntry&, bool avoid_server_duplicates);
99 
103 
104  std::vector<Snoop::AppEntry> get_app_registrations(std::string uuid_filter="");
105 
107 
109  std::mutex sqlite_mutex;
110 
112 
114  std::thread wsclient_thread;
115  std::mutex connection_mutex;
116  std::condition_variable connection_cv;
118  WebsocketClient::connection_ptr connection;
119  websocketpp::connection_hdl our_connection_hdl;
120 
121  void on_client_open(websocketpp::connection_hdl hdl);
122  void on_client_fail(websocketpp::connection_hdl hdl);
123  void on_client_close(websocketpp::connection_hdl hdl);
124  void on_client_message(websocketpp::connection_hdl hdl, message_ptr msg);
125 
126  private:
127  std::mutex call_mutex;
128  };
129 }
std::mutex call_mutex
Definition: SnoopPrivate.hh:127
std::mutex connection_mutex
Definition: SnoopPrivate.hh:115
Snoop::AppEntry this_app_
Definition: SnoopPrivate.hh:62
void start_websocket_client()
Start the websocket client.
Definition: Snoop.cc:439
bool store_app_entry(Snoop::AppEntry &)
Store an app entry in the database.
Definition: Snoop.cc:316
sqlite3_stmt * insert_statement
Prepared statements (only need to prepare these once).
Definition: SnoopPrivate.hh:108
websocketpp::config::asio_client::message_type::ptr message_ptr
Definition: ComputeThread.hh:12
C++ representation of an run entry.
Definition: Snoop.hh:91
bool store_log_entry(Snoop::LogEntry &, bool avoid_server_duplicates)
Store a log entry in the local database.
Definition: Snoop.cc:372
~SnoopImpl()
Definition: Snoop.cc:810
std::thread wsclient_thread
Definition: SnoopPrivate.hh:114
std::vector< Snoop::AppEntry > get_app_registrations(std::string uuid_filter="")
Return a vector of all aps registered in the database.
Definition: Snoop.cc:655
Definition: SnoopPrivate.hh:17
std::mutex sqlite_mutex
Definition: SnoopPrivate.hh:109
void create_tables()
Ensure that the required tables are present in the database file.
Definition: Snoop.cc:221
Snoop::LogEntry this_log_
Definition: SnoopPrivate.hh:63
bool connection_attempt_failed
Definition: SnoopPrivate.hh:117
Logging class with functionality to send log information to a remote server using a websocket connect...
Definition: Snoop.hh:32
SnoopImpl(Snoop *)
Definition: Snoop.cc:62
WebsocketClient wsclient
Websocket client to talk to a remote logging server.
Definition: SnoopPrivate.hh:113
void sync_with_server(bool from_wsthread=false)
Ensure that the local database is synchronised with the server (this sends multiple app or log entrie...
Definition: Snoop.cc:479
Snoop * snoop_
Definition: SnoopPrivate.hh:58
bool store_app_entry_without_lock(Snoop::AppEntry &)
Definition: Snoop.cc:325
bool connection_is_open
Definition: SnoopPrivate.hh:117
void sync_runs_with_server(bool from_wsthread=false)
As above, but only for run entries.
Definition: Snoop.cc:496
WebsocketClient::connection_ptr connection
Definition: SnoopPrivate.hh:118
Definition: Snoop.hh:26
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 the log message as well as (optionally) the f...
Definition: Snoop.cc:850
std::string server_
Definition: SnoopPrivate.hh:64
std::condition_variable connection_cv
Definition: SnoopPrivate.hh:116
void on_client_close(websocketpp::connection_hdl hdl)
Definition: Snoop.cc:728
void on_client_message(websocketpp::connection_hdl hdl, message_ptr msg)
Definition: Snoop.cc:739
void obtain_uuid()
Obtain a uuid by finding the last AppEntry stored in the local database.
Definition: Snoop.cc:282
std::string get_user_uuid(const std::string &app_name)
Get a string which uniquely identifies the current user.
Definition: Snoop.cc:167
void on_client_fail(websocketpp::connection_hdl hdl)
Definition: Snoop.cc:718
websocketpp::client< websocketpp::config::asio_client > WebsocketClient
Definition: SnoopPrivate.hh:12
void sync_logs_with_server(bool from_wsthread=false)
As above, but only for log entries.
Definition: Snoop.cc:578
void init(const std::string &app_name, const std::string &app_version, std::string server="", std::string local_log_file="")
Initialise the logging stream.
Definition: Snoop.cc:75
void on_client_open(websocketpp::connection_hdl hdl)
Definition: Snoop.cc:707
C++ representation of a log entry.
Definition: Snoop.hh:119
sqlite3_stmt * id_for_uuid_statement
Definition: SnoopPrivate.hh:108
websocketpp::config::asio_client::message_type::ptr message_ptr
Definition: SnoopPrivate.hh:13
Snoop & operator<<(const Flush &)
Definition: Snoop.cc:869
sqlite3 * db
Definition: SnoopPrivate.hh:60
websocketpp::connection_hdl our_connection_hdl
Definition: SnoopPrivate.hh:119