Tweaked dbase functions for ftSearch functionality.

(made a bunch of functions "const")



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@674 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-08-09 16:06:01 +00:00
parent de2956637b
commit d7e1a90c28
8 changed files with 64 additions and 46 deletions

View File

@ -69,7 +69,7 @@ CacheSource::CacheSource(uint16_t t, bool m, CacheStrapper *cs, std::string cach
}
/* Mutex Stuff -> to be done... */
void CacheSource::lockData()
void CacheSource::lockData() const
{
#ifdef CS_DEBUG
std::cerr << "CacheSource::lockData()" << std::endl;
@ -77,7 +77,7 @@ void CacheSource::lockData()
cMutex.lock();
}
void CacheSource::unlockData()
void CacheSource::unlockData() const
{
#ifdef CS_DEBUG
std::cerr << "CacheSource::unlockData()" << std::endl;
@ -154,12 +154,12 @@ bool CacheSource::cachesAvailable(RsPeerId pid, std::map<CacheId, CacheData>
}
bool CacheSource::findCache(std::string hash, CacheData &data)
bool CacheSource::findCache(std::string hash, CacheData &data) const
{
lockData(); /* LOCK MUTEX */
bool found = false;
CacheSet::iterator it;
CacheSet::const_iterator it;
for(it = caches.begin(); it != caches.end(); it++)
{
if (hash == (it->second).hash)
@ -205,7 +205,7 @@ CacheStore::CacheStore(uint16_t t, bool m,
}
/* Mutex Stuff -> to be done... */
void CacheStore::lockData()
void CacheStore::lockData() const
{
#ifdef CS_DEBUG
std::cerr << "CacheStore::lockData()" << std::endl;
@ -213,7 +213,7 @@ void CacheStore::lockData()
cMutex.lock();
}
void CacheStore::unlockData()
void CacheStore::unlockData() const
{
#ifdef CS_DEBUG
std::cerr << "CacheStore::unlockData()" << std::endl;
@ -685,10 +685,10 @@ void CacheStrapper::listPeerStatus(std::ostream &out)
}
bool CacheStrapper::findCache(std::string hash, CacheData &data)
bool CacheStrapper::findCache(std::string hash, CacheData &data) const
{
/* can overwrite for more control! */
std::map<uint16_t, CachePair>::iterator it;
std::map<uint16_t, CachePair>::const_iterator it;
for(it = caches.begin(); it != caches.end(); it++)
{
if ((it->second).source->findCache(hash, data))

View File

@ -165,7 +165,7 @@ uint16_t getCacheType() { return cacheType; }
void listCaches(std::ostream &out);
/* search */
bool findCache(std::string hash, CacheData &data);
bool findCache(std::string hash, CacheData &data) const;
protected:
@ -174,15 +174,15 @@ bool findCache(std::string hash, CacheData &data);
CacheStrapper *mStrapper;
/*** MUTEX LOCKING */
void lockData();
void unlockData();
void lockData() const;
void unlockData() const;
CacheSet caches;
private:
std::string cacheDir;
RsMutex cMutex;
mutable RsMutex cMutex;
};
@ -221,8 +221,8 @@ void listCaches(std::ostream &out);
protected:
/*** MUTEX LOCKING */
void lockData();
void unlockData();
void lockData() const;
void unlockData() const;
/* This function is called to store Cache Entry in the CacheStore Table.
* it must be called from within a Mutex Lock....
@ -242,7 +242,7 @@ bool locked_getStoredCache(CacheData &data);
std::string cacheDir;
RsMutex cMutex;
mutable RsMutex cMutex;
std::map<RsPeerId, CacheSet> caches;
@ -299,7 +299,7 @@ void handleCacheQuery(RsPeerId id, std::map<CacheId, CacheData> &data);
/* search through CacheSources. */
bool findCache(std::string hash, CacheData &data);
bool findCache(std::string hash, CacheData &data) const;
/* display */
void listCaches(std::ostream &out);

View File

@ -57,7 +57,7 @@ FileIndexMonitor::~FileIndexMonitor()
}
bool FileIndexMonitor::findLocalFile(std::string hash,
std::string &fullpath, uint64_t &size)
std::string &fullpath, uint64_t &size) const
{
std::list<FileEntry *> results;
bool ok = false;
@ -80,7 +80,7 @@ bool FileIndexMonitor::findLocalFile(std::string hash,
#endif
std::string shpath = RsDirUtil::removeRootDir(de->path);
std::string basedir = RsDirUtil::getRootDir(de->path);
std::string realroot = findRealRoot(basedir);
std::string realroot = locked_findRealRoot(basedir);
/* construct full name */
if (realroot.length() > 0)
@ -119,7 +119,7 @@ bool FileIndexMonitor::convertSharedFilePath(std::string path, std::string &f
std::string shpath = RsDirUtil::removeRootDir(path);
std::string basedir = RsDirUtil::getRootDir(path);
std::string realroot = findRealRoot(basedir);
std::string realroot = locked_findRealRoot(basedir);
/* construct full name */
if (realroot.length() > 0)
@ -280,7 +280,7 @@ void FileIndexMonitor::updateCycle()
std::string rootdir = RsDirUtil::getRootDir(olddir->path);
std::string remdir = RsDirUtil::removeRootDir(olddir->path);
std::string realroot = findRealRoot(rootdir);
std::string realroot = locked_findRealRoot(rootdir);
std::string realpath = realroot;
if (remdir != "")
@ -602,6 +602,22 @@ void FileIndexMonitor::setSharedDirectories(std::list<std::string> dirs)
} fiMutex.unlock(); /* UNLOCKED DIRS */
}
/* interface */
void FileIndexMonitor::getSharedDirectories(std::list<std::string> &dirs)
{
fiMutex.lock(); { /* LOCKED DIRS */
/* get actual list (not pending stuff) */
std::map<std::string, std::string>::const_iterator it;
for(it = directoryMap.begin(); it != directoryMap.end(); it++)
{
dirs.push_back(it->second);
}
} fiMutex.unlock(); /* UNLOCKED DIRS */
}
/* interface */
void FileIndexMonitor::forceDirectoryCheck()
{
@ -700,7 +716,7 @@ bool FileIndexMonitor::internal_setSharedDirectories()
/* lookup directory function */
std::string FileIndexMonitor::findRealRoot(std::string rootdir)
std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const
{
/**** MUST ALREADY BE LOCKED ****/
std::string realroot = "";
@ -708,7 +724,7 @@ std::string FileIndexMonitor::findRealRoot(std::string rootdir)
std::map<std::string, std::string>::const_iterator cit;
if (directoryMap.end()== (cit=directoryMap.find(rootdir)))
{
std::cerr << "FileIndexMonitor::findRealRoot() Invalid RootDir: ";
std::cerr << "FileIndexMonitor::locked_findRealRoot() Invalid RootDir: ";
std::cerr << rootdir << std::endl;
}
else

View File

@ -72,7 +72,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
virtual ~FileIndexMonitor();
/* external interface for filetransfer */
bool findLocalFile(std::string hash, std::string &fullpath, uint64_t &size);
bool findLocalFile(std::string hash, std::string &fullpath, uint64_t &size) const;
/* external interface for local access to files */
bool convertSharedFilePath(std::string path, std::string &fullpath);
@ -89,6 +89,8 @@ virtual void run(); /* overloaded from RsThread */
void updateCycle();
void setSharedDirectories(std::list<std::string> dirs);
void getSharedDirectories(std::list<std::string> &dirs);
void setPeriod(int insecs);
void forceDirectoryCheck();
bool inDirectoryCheck();
@ -97,12 +99,12 @@ bool inDirectoryCheck();
private:
/* the mutex should be locked before calling... these. */
std::string findRealRoot(std::string base); /* To Implement */
std::string locked_findRealRoot(std::string base) const;
bool hashFile(std::string path, FileEntry &fi); /* To Implement */
/* data */
RsMutex fiMutex;
mutable RsMutex fiMutex;
FileIndex fi;

View File

@ -946,7 +946,7 @@ int DirEntry::saveEntry(std::ostringstream &oss)
}
int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results)
int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results) const
{
DirEntry *ndir = NULL;
std::list<DirEntry *> dirlist;
@ -978,7 +978,7 @@ int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results)
}
int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results)
int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results) const
{
DirEntry *ndir = NULL;
std::list<DirEntry *> dirlist;
@ -1029,7 +1029,7 @@ int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *>
return 0;
}
int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const
{
DirEntry *ndir = NULL;
std::list<DirEntry *> dirlist;

View File

@ -217,9 +217,9 @@ int loadIndex(std::string filename, std::string expectedHash, uint64_t size);
int saveIndex(std::string filename, std::string &fileHash, uint64_t &size);
/* search through this index */
int searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results);
int searchHash(std::string hash, std::list<FileEntry *> &results);
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results);
int searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results) const;
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
PersonEntry *root;
};

View File

@ -140,12 +140,12 @@ int FileIndexStore::loadCache(const CacheData &data)
}
/* Search Interface - For Directory Access */
int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDetails &details)
int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDetails &details) const
{
/* lock it up */
lockData();
std::map<RsPeerId, FileIndex *>::iterator it;
std::map<RsPeerId, FileIndex *>::const_iterator it;
it = indices.find(uid);
bool found = true;
if (it == indices.end())
@ -164,11 +164,11 @@ int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDeta
return found;
}
int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const
{
lockData();
bool found = true;
std::map<RsPeerId, FileIndex *>::iterator pit;
std::map<RsPeerId, FileIndex *>::const_iterator pit;
/* so cast *ref to a DirEntry */
FileEntry *file = (FileEntry *) ref;
@ -339,10 +339,10 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
}
int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results) const
{
lockData();
std::map<RsPeerId, FileIndex *>::iterator pit;
std::map<RsPeerId, FileIndex *>::const_iterator pit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *> firesults;
@ -378,10 +378,10 @@ int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
}
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results)
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results) const
{
lockData();
std::map<RsPeerId, FileIndex *>::iterator pit;
std::map<RsPeerId, FileIndex *>::const_iterator pit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *> firesults;
@ -438,10 +438,10 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
}
int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &results)
int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &results) const
{
lockData();
std::map<RsPeerId, FileIndex *>::iterator pit;
std::map<RsPeerId, FileIndex *>::const_iterator pit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *> firesults;

View File

@ -71,18 +71,18 @@ virtual ~FileIndexStore();
virtual int loadCache(const CacheData &data); /* actual load, once data available */
/* Search Interface - For FileTransfer Lookup */
int SearchHash(std::string hash, std::list<FileDetail> &results);
int SearchHash(std::string hash, std::list<FileDetail> &results) const;
/* Search Interface - For Search Interface */
int SearchKeywords(std::list<std::string> terms, std::list<FileDetail> &results);
int SearchKeywords(std::list<std::string> terms, std::list<FileDetail> &results) const;
/* Search Interface - for Adv Search Interface */
int searchBoolExp(Expression * exp, std::list<FileDetail> &results);
int searchBoolExp(Expression * exp, std::list<FileDetail> &results) const;
/* Search Interface - For Directory Access */
int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const;
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const;
private:
int AboutToModify();