added a callback to fimonitor to be able to keep track of file hashing

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@909 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-01-04 20:28:48 +00:00
parent 148f8e067c
commit 6d6901e6e9
5 changed files with 24 additions and 1 deletions

View File

@ -43,7 +43,7 @@
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid)
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
pendingDirs(false), pendingForceCacheWrite(false),
mForceCheck(false), mInCheck(false)
mForceCheck(false), mInCheck(false),_hashing_info_callback(NULL)
{
updatePeriod = 60;
@ -184,8 +184,10 @@ void FileIndexMonitor::setPeriod(int period)
}
void FileIndexMonitor::run()
//void FileIndexMonitor::run(std::string& current_job)
{
// updateCycle(current_job);
updateCycle();
while(1)
@ -210,11 +212,13 @@ void FileIndexMonitor::run()
}
}
// updateCycle(current_job);
updateCycle();
}
}
//void FileIndexMonitor::updateCycle(std::string& current_job)
void FileIndexMonitor::updateCycle()
{
time_t startstamp = time(NULL);
@ -473,6 +477,8 @@ void FileIndexMonitor::updateCycle()
/* update files */
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
{
// currentJob = "Hashing file " + realpath ;
if (hashFile(realpath, (*hit)))
{
/* lock dirs */
@ -501,6 +507,7 @@ void FileIndexMonitor::updateCycle()
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
}
// currentJob = "" ;
}
fiMutex.lock(); { /* LOCKED DIRS */
@ -589,6 +596,8 @@ void FileIndexMonitor::updateCycle()
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
mInCheck = false;
}
if(_hashing_info_callback != NULL)
(*_hashing_info_callback)("") ;
}
/* interface */
@ -788,6 +797,9 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
unsigned char sha_buf[SHA_DIGEST_LENGTH];
unsigned char gblBuf[512];
if(_hashing_info_callback != NULL)
(*_hashing_info_callback)("Hashing "+f_hash) ;
#ifdef FIM_DEBUG
std::cerr << "File to hash = " << f_hash << std::endl;
#endif

View File

@ -85,6 +85,8 @@ bool updateCache(const CacheData &data); /* we call when we have a new cach
/* the FileIndexMonitor inner workings */
//virtual void run(std::string& currentJob); /* overloaded from RsThread */
//void updateCycle(std::string& currentJob);
virtual void run(); /* overloaded from RsThread */
void updateCycle();
@ -94,6 +96,7 @@ void getSharedDirectories(std::list<std::string> &dirs);
void setPeriod(int insecs);
void forceDirectoryCheck();
bool inDirectoryCheck();
void setFileHashingCallback(void (*cb)(const std::string&)) { _hashing_info_callback = cb ; }
/* util fns */
private:
@ -122,6 +125,7 @@ bool hashFile(std::string path, FileEntry &fi); /* To Implement */
std::list<std::string> pendingDirList;
bool internal_setSharedDirectories();
void (*_hashing_info_callback)(const std::string&) ;
};

View File

@ -400,6 +400,10 @@ bool ftServer::InDirectoryCheck()
{
return mFiMon->inDirectoryCheck();
}
void ftServer::setFileHashingCallback( void (*cb)(const std::string&) )
{
mFiMon->setFileHashingCallback( cb ) ;
}
bool ftServer::getSharedDirectories(std::list<std::string> &dirs)
{

View File

@ -149,6 +149,7 @@ virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
virtual void ForceDirectoryCheck();
virtual bool InDirectoryCheck();
virtual void setFileHashingCallback( void(*cb)(const std::string&));
/***
* Directory Handling

View File

@ -139,6 +139,8 @@ virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results) = 0;
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0;
virtual void ForceDirectoryCheck() = 0;
virtual bool InDirectoryCheck() = 0;
virtual void setFileHashingCallback( void(*cb)(const std::string&)) = 0;
/***