9#ifndef SNBMODULES_INCLUDE_SNBMODULES_BOOKKEEPER_HPP_
10#define SNBMODULES_INCLUDE_SNBMODULES_BOOKKEEPER_HPP_
37 std::string bookkeeper_id,
38 std::string file_log_path =
"",
40 std::string connection_prefix =
"snbmodules",
41 int timeout_send = 10,
42 int timeout_receive = 100)
61 void do_work(std::atomic<bool>& running_flag);
70 const std::string& protocol,
71 const std::string& src,
72 const std::set<std::string>& dests,
73 const std::set<std::filesystem::path>& files,
74 const nlohmann::json& protocol_options = nlohmann::json());
97 inline const std::map<std::string, std::vector<std::shared_ptr<TransferMetadata>>>&
get_transfers()
const
116 std::map<std::string, std::vector<std::shared_ptr<TransferMetadata>>>
m_transfers;
129 [[deprecated(
"Now only the uploader can start a transfer")]]
void start_transfers(
const std::string& transfer_id);
136 return session_name.substr(0, session_name.find(
"_"));
Bookkeeper(const IPFormat &listening_ip, std::string bookkeeper_id, std::string file_log_path="", int refresh_rate=5, std::string connection_prefix="snbmodules", int timeout_send=10, int timeout_receive=100)
Constructor with params.
void do_work(std::atomic< bool > &running_flag)
Start the bookkeeper thread to receive notifications.
void request_update_metadata(bool force=false)
Request the update of the metadata from every known clients to the bookkeeper. Only get from group tr...
void start_transfers(const std::string &transfer_id)
Start a new transfer.
std::map< std::string, GroupMetadata > m_grp_transfers
map of group_id -> group_transfers
void set_bookkeeper_id(std::string bookkeeper_id)
std::map< std::string, std::set< std::string > > m_clients_per_grp_transfer
map of grp_transfer_id -> clients_id
bool action_on_receive_notification(NotificationData notif) override
Action to do when receiving a notification.
bool start()
Start the bookkeeper, Only used for stand alone application.
void request_connection_and_available_files(const std::string &client)
Send a notification to a clients id or connection to get available files.
void set_ip(const IPFormat &ip)
void display_information()
Display the information of the bookkeeper either on the normal log or on a specific file depending on...
const std::map< std::string, GroupMetadata > & get_grp_transfers() const
void create_new_transfer(const std::string &protocol, const std::string &src, const std::set< std::string > &dests, const std::set< std::filesystem::path > &files, const nlohmann::json &protocol_options=nlohmann::json())
void add_update_grp_transfer(GroupMetadata grp_transfers)
std::string m_bookkeeper_id
Unique identifier for the bookkeeper.
void add_update_transfer(const std::string &client_id, const std::string &data)
std::map< std::string, GroupMetadata > & get_grp_transfers()
std::map< std::string, std::vector< std::shared_ptr< TransferMetadata > > > m_transfers
Map of files/current transfers, client_id -> set of transfers.
IPFormat m_ip
IP address of the bookkeeper.
std::string m_file_log_path
should the information pannel of transfers be displayed on the normal log or a specific file
int m_refresh_rate
Refresh rate of the information pannel of transfers in seconds.
const std::map< std::string, std::vector< std::shared_ptr< TransferMetadata > > > & get_transfers() const
std::map< std::string, std::vector< std::shared_ptr< TransferMetadata > > > & get_transfers()
std::string get_client_name_from_session_name(const std::string &session_name) const
Usefull convertion from session id to client id.
void input_action(char input)
Do action depending on the input, Used for stand alone application TODO: remake.
std::string get_bookkeeper_id() const
NotificationData class, represent a notification.