2007-11-14 22:18:48 -05:00
|
|
|
/*
|
|
|
|
* RetroShare FileCache Module: fimonitor.h
|
2009-08-25 16:49:50 -04:00
|
|
|
*
|
2007-11-14 22:18:48 -05:00
|
|
|
* Copyright 2004-2007 by Robert Fernie.
|
2009-08-25 16:49:50 -04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2007-11-14 22:18:48 -05:00
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
2009-08-25 16:49:50 -04:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
2007-11-14 22:18:48 -05:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FILE_INDEX_MONITOR_H
|
|
|
|
#define FILE_INDEX_MONITOR_H
|
|
|
|
|
|
|
|
#include "dbase/cachestrapper.h"
|
2008-03-03 09:41:15 -05:00
|
|
|
#include "dbase/findex.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "util/rsthreads.h"
|
2009-08-03 15:43:52 -04:00
|
|
|
#include "rsiface/rsfiles.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/******************************************************************************************
|
|
|
|
* The Local Monitoring Class: FileIndexMonitor.
|
|
|
|
*
|
|
|
|
* This periodically scans the directory tree, and updates any modified directories/files.
|
|
|
|
*
|
|
|
|
*****************************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************************
|
|
|
|
STILL TODO:
|
|
|
|
|
|
|
|
(1) Implement Hash function.
|
|
|
|
|
|
|
|
bool FileIndexMonitor::hashFile(std::string path, FileEntry &fi);
|
|
|
|
|
|
|
|
(2) Add Shared directory controls to Monitor.
|
|
|
|
|
|
|
|
int FileIndexMonitor::addSharedDirectory(std::path);
|
|
|
|
int FileIndexMonitor::removeSharedDirectory(std::path);
|
|
|
|
std::string FileIndexMonitor::findRealRoot(std::string base);
|
|
|
|
|
|
|
|
These must be split into <base>/<top> and the mapping saved.
|
|
|
|
eg: addSharedDirectory("c:/home/stuff/dir1") --> "c:/home/stuff" <-> "dir1"
|
|
|
|
This code has been written already, and can just be moved over.
|
|
|
|
|
|
|
|
FOR LATER:
|
|
|
|
(2) Port File/Directory lookup code to windoze. (or compile dirent.c under windoze)
|
|
|
|
(3) Add Load/Store interface to FileIndexMonitor. (later)
|
|
|
|
(4) Integrate with real Thread/Mutex code (last thing to do)
|
|
|
|
|
|
|
|
******************************************************************************************/
|
|
|
|
|
2009-01-22 16:06:54 -05:00
|
|
|
class NotifyBase ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-26 18:05:07 -05:00
|
|
|
class DirContentToHash
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<FileEntry> fentries ;
|
|
|
|
|
|
|
|
std::string realpath ;
|
|
|
|
std::string dirpath ;
|
|
|
|
};
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/******************************************************************************************
|
|
|
|
* FileIndexMonitor
|
|
|
|
*****************************************************************************************/
|
|
|
|
|
|
|
|
class FileIndexMonitor: public CacheSource, public RsThread
|
|
|
|
{
|
|
|
|
public:
|
2009-08-03 15:43:52 -04:00
|
|
|
FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in, std::string cachedir, std::string pid);
|
|
|
|
virtual ~FileIndexMonitor();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
/* external interface for filetransfer */
|
2009-08-10 15:44:45 -04:00
|
|
|
bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const;
|
2009-08-25 16:49:50 -04:00
|
|
|
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) ;
|
|
|
|
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,uint32_t flags) const ;
|
|
|
|
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const ;
|
2009-08-25 08:04:43 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
/* external interface for local access to files */
|
|
|
|
bool convertSharedFilePath(std::string path, std::string &fullpath);
|
2008-03-31 10:06:59 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
/* Interacting with CacheSource */
|
|
|
|
/* overloaded from CacheSource */
|
|
|
|
virtual bool loadLocalCache(const CacheData &data); /* called with stored data */
|
|
|
|
bool updateCache(const CacheData &data); /* we call when we have a new cache for others */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
/* 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();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-09 16:00:25 -04:00
|
|
|
// Interface for browsing dir hirarchy
|
|
|
|
int RequestDirDetails(void*, DirDetails&, uint32_t) const ;
|
|
|
|
int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const ;
|
|
|
|
|
|
|
|
// set/update shared directories
|
2009-08-03 15:43:52 -04:00
|
|
|
virtual void setSharedDirectories(std::list<SharedDirInfo> dirs);
|
|
|
|
void getSharedDirectories(std::list<SharedDirInfo>& dirs);
|
|
|
|
void updateShareFlags(const SharedDirInfo& info) ;
|
2008-08-09 12:06:01 -04:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
void setPeriod(int insecs);
|
|
|
|
void forceDirectoryCheck();
|
|
|
|
bool inDirectoryCheck();
|
2009-01-22 16:06:54 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
/* util fns */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
private:
|
2010-05-29 09:17:09 -04:00
|
|
|
/* the mutex should be locked before calling these 3. */
|
|
|
|
|
2009-08-09 12:32:31 -04:00
|
|
|
// saves file indexs and update the cache.
|
2009-08-09 16:00:25 -04:00
|
|
|
void locked_saveFileIndexes() ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-05-29 09:17:09 -04:00
|
|
|
// Finds the share flags associated with this file entry.
|
|
|
|
uint32_t locked_findShareFlags(FileEntry *fe) const ;
|
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
std::string locked_findRealRoot(std::string base) const;
|
2010-05-29 09:17:09 -04:00
|
|
|
|
2010-02-26 18:05:07 -05:00
|
|
|
void hashFiles(const std::vector<DirContentToHash>& to_hash) ;
|
2009-08-03 15:43:52 -04:00
|
|
|
bool hashFile(std::string path, FileEntry &fi); /* To Implement */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
/* data */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
mutable RsMutex fiMutex;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
FileIndex fi;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
int updatePeriod;
|
|
|
|
std::map<std::string, SharedDirInfo> directoryMap; /* used by findRealRoot */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
/* flags to kick - if we were busy or sleeping */
|
|
|
|
bool pendingDirs;
|
|
|
|
bool pendingForceCacheWrite;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
/* flags to force Check, to tell if we're in check */
|
|
|
|
bool mForceCheck;
|
|
|
|
bool mInCheck;
|
2008-03-31 10:06:59 -04:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
std::list<SharedDirInfo> pendingDirList;
|
|
|
|
bool internal_setSharedDirectories();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-03 15:43:52 -04:00
|
|
|
NotifyBase *cb ;
|
2007-11-14 22:18:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|