1 #ifndef _MADARA_KNOWLEDGE_FILE_REQUESTER_H_
2 #define _MADARA_KNOWLEDGE_FILE_REQUESTER_H_
45 int max_request_fragments = -1)
47 init(prefix, sync_key, filename, kb, max_request_fragments);
63 int max_request_fragments = -1)
121 size_t num_fragments = expected_size / 60000;
123 if (expected_size % 60000 > 0)
128 if (num_fragments > 0)
162 return fragments.size() != 0;
166 std::vector<int64_t> fragments;
172 for (
size_t i = 0; i < fragments.size(); ++i)
194 size_t num_fragments = expected_size / 60000;
196 if (expected_size % 60000 > 0)
201 for (
int i = 0; i < (int)num_fragments;
202 ++i, frag_file =
filename_ +
"." + std::to_string(i) + frag_suffix)
207 "FileRequester::clear_fragments: removing %s\n", frag_file.c_str());
209 remove(frag_file.c_str());
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
A helper class that can reconstruct files or request files be transferred in fragments from a Madara ...
void modify(void)
Remodifies the file size and crc.
knowledge::KnowledgeBase kb_
saves the kb for general usage
containers::Integer file_crc_
the crc of the file
FileRequester(const std::string &prefix, const std::string &sync_key, const std::string &filename, KnowledgeBase kb, int max_request_fragments=-1)
Constructor.
size_t get_size(void)
Returns the size of the file.
containers::Integer file_size_
the size of the file contents
containers::NativeIntegerVector sync_
The key that is being synced to.
std::string filename_
the name of the file on the hard drive being reconstructed
uint32_t get_crc(void)
Returns the crc of the file.
std::vector< int64_t > build_fragment_request(void)
Builds fragment request to send.
std::string get_filename(void)
Returns the name of the file.
void clear_fragments(void)
Clears any lingering file fragments.
double get_percent_complete(void)
Returns the percentage of transfer that is completed.
bool needs_request(void)
Builds fragment request to send.
int max_fragments
the maximum fragments allowed in a resend request
FileRequester()
Constructor.
void init(const std::string &prefix, const std::string &sync_key, const std::string &filename, KnowledgeBase kb, int max_request_fragments=-1)
Initializes the requester.
This class provides a distributed knowledge base to users.
This class stores a flexible map of strings and ints to KaRL variables FlexMap differs from Map in th...
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
void to_container(BufferVector &target) const
Fills a BufferVector container with all subkeys.
This class stores an integer within a variable context.
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the value as an integer (same as *)
This class stores a vector of doubles inside of KaRL.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
void modify(void)
Mark the value as modified.
int set(size_t index, type value)
Sets a knowledge variable to a specified value.
Provides functions and classes for the distributed knowledge base.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
bool file_exists(const std::string &filename)
Checks if a file exists.
MADARA_EXPORT size_t get_file_progress(const std::string &filename, uint32_t crc, size_t expected_size, size_t fragment_size=60000)
Builds a file from fragments that have the format: filename.
MADARA_EXPORT std::vector< int64_t > get_file_missing_fragments(const std::string &filename, uint32_t crc, size_t expected_size, int max_fragments=-1, size_t fragment_size=60000)
Attempts to builds a file from fragments that have the format: filename.
Copyright(c) 2020 Galois.