fixed compilation/running of directory updater

This commit is contained in:
mr-alice 2016-07-27 21:22:59 +02:00
parent 25c824fd5f
commit d86b89b15a
6 changed files with 309 additions and 94 deletions

View file

@ -4,61 +4,78 @@
#include "util/rsthreads.h"
#include "retroshare/rsfiles.h"
class HashCacheClient
class HashStorageClient
{
public:
virtual void hash_callback(const std::string& full_path,const RsFileHash& hash) ;
HashStorageClient() {}
virtual ~HashStorageClient() {}
virtual void hash_callback(uint32_t client_param, const std::string& name, const RsFileHash& hash, uint64_t size)=0;
};
class FileHashingThread: public RsTickingThread
class HashStorage: public RsTickingThread
{
public:
FileHashingThread() {}
HashStorage(const std::string& save_file_name) ;
virtual void data_tick() ;
};
/*!
* \brief requestHash Requests the hash for the given file, assuming size and mod_time are the same.
*
* \param full_path Full path to reach the file
* \param size Actual file size
* \param mod_time Actual file modification time
* \param known_hash Returned hash for the file.
* \param c Hash cache client to which the hash should be sent once calculated
* \param client_param Param to be passed to the client callback
*
* \return true if the supplied hash info is up to date.
*/
bool requestHash(const std::string& full_path, uint64_t size, time_t mod_time, RsFileHash& known_hash, HashStorageClient *c, uint32_t client_param) ;
class HashCache
{
public:
HashCache(const std::string& save_file_name) ;
bool requestHash(const std::string& full_path,uint64_t size,time_t mod_time,const RsFileHash& known_hash,HashCacheClient *c) ;
struct HashCacheInfo
struct HashStorageInfo
{
std::string filename ;
uint64_t size ;
uint32_t time_stamp ;
uint32_t time_stamp ; // last time the hash was tested/requested
uint32_t modf_stamp ;
RsFileHash hash ;
} ;
// interaction with GUI, called from p3FileLists
void setRememberHashFilesDuration(uint32_t days) { mMaxCacheDurationDays = days ; }
uint32_t rememberHashFilesDuration() const { return mMaxCacheDurationDays ; }
void setRememberHashFilesDuration(uint32_t days) { mMaxStorageDurationDays = days ; }
uint32_t rememberHashFilesDuration() const { return mMaxStorageDurationDays ; }
void clear() { mFiles.clear(); }
bool empty() const { return mFiles.empty() ; }
// Functions called by the thread
virtual void data_tick() ;
private:
void clean() ;
void save() ;
void load() ;
// threaded stuff
FileHashingThread mHashingThread ;
RsMutex mHashMtx ;
// Local configuration and storage
uint32_t mMaxCacheDurationDays ; // maximum duration of un-requested cache entries
std::map<std::string, HashCacheInfo> mFiles ;
uint32_t mMaxStorageDurationDays ; // maximum duration of un-requested cache entries
std::map<std::string, HashStorageInfo> mFiles ; // stored as (full_path, hash_info)
std::string mFilePath ;
bool mChanged ;
struct FileHashJob
{
std::string full_path;
HashStorageClient *client;
uint32_t client_param ;
};
// current work
std::map<std::string,HashCacheClient *> mFilesToHash ;
std::map<std::string,FileHashJob> mFilesToHash ;
// thread/mutex stuff
RsMutex mHashMtx ;
};