Optimized some small things in TransferDialog and SearchDialog.

Changed the parameter of the constructor of ftFileCreator and ftFileProvider and some methods of ftTransferModule from "std::string" to "const std::string&"

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4045 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-02-20 00:59:47 +00:00
parent 61b57ede65
commit db19db7e60
8 changed files with 40 additions and 33 deletions

View File

@ -17,7 +17,7 @@
*
***********************************************************/
ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash,bool assume_availability)
ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std::string& hash,bool assume_availability)
: ftFileProvider(path,size,hash), chunkMap(size,assume_availability)
{
/*

View File

@ -47,7 +47,7 @@ class ftFileCreator: public ftFileProvider
{
public:
ftFileCreator(std::string savepath, uint64_t size, std::string hash,bool assume_availability);
ftFileCreator(const std::string& savepath, uint64_t size, const std::string& hash,bool assume_availability);
~ftFileCreator();

View File

@ -23,7 +23,7 @@
static const time_t UPLOAD_CHUNK_MAPS_TIME = 20 ; // time to ask for a new chunkmap from uploaders in seconds.
ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string hash)
ftFileProvider::ftFileProvider(const std::string& path, uint64_t size, const std::string& hash)
: mSize(size), hash(hash), file_name(path), fd(NULL)
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/

View File

@ -38,7 +38,7 @@
class ftFileProvider
{
public:
ftFileProvider(std::string path, uint64_t size, std::string hash);
ftFileProvider(const std::string& path, uint64_t size, const std::string& hash);
virtual ~ftFileProvider();
virtual bool getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data);

View File

@ -95,7 +95,7 @@ ftTransferModule::~ftTransferModule()
{}
bool ftTransferModule::setFileSources(std::list<std::string> peerIds)
bool ftTransferModule::setFileSources(const std::list<std::string>& peerIds)
{
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
@ -106,7 +106,7 @@ bool ftTransferModule::setFileSources(std::list<std::string> peerIds)
std::cerr << " List of peers: " ;
#endif
std::list<std::string>::iterator it;
std::list<std::string>::const_iterator it;
for(it = peerIds.begin(); it != peerIds.end(); it++)
{
@ -136,7 +136,7 @@ bool ftTransferModule::getFileSources(std::list<std::string> &peerIds)
return true;
}
bool ftTransferModule::addFileSource(std::string peerId)
bool ftTransferModule::addFileSource(const std::string& peerId)
{
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit;
@ -167,7 +167,7 @@ bool ftTransferModule::addFileSource(std::string peerId)
return true;
}
bool ftTransferModule::removeFileSource(std::string peerId)
bool ftTransferModule::removeFileSource(const std::string& peerId)
{
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit;
@ -189,7 +189,7 @@ bool ftTransferModule::removeFileSource(std::string peerId)
return true;
}
bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t maxRate)
bool ftTransferModule::setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate)
{
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
#ifdef FT_DEBUG
@ -237,7 +237,7 @@ bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t m
}
bool ftTransferModule::getPeerState(std::string peerId,uint32_t &state,uint32_t &tfRate)
bool ftTransferModule::getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate)
{
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit;
@ -257,7 +257,7 @@ bool ftTransferModule::getPeerState(std::string peerId,uint32_t &state,uint32_t
return true;
}
uint32_t ftTransferModule::getDataRate(std::string peerId)
uint32_t ftTransferModule::getDataRate(const std::string& peerId)
{
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit;
@ -277,7 +277,7 @@ uint32_t ftTransferModule::getDataRate(std::string peerId)
//interface to client module
bool ftTransferModule::recvFileData(std::string peerId, uint64_t offset, uint32_t chunk_size, void *data)
bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data)
{
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::recvFileData()";
@ -316,7 +316,7 @@ bool ftTransferModule::recvFileData(std::string peerId, uint64_t offset, uint32_
return ok;
}
void ftTransferModule::requestData(std::string peerId, uint64_t offset, uint32_t chunk_size)
void ftTransferModule::requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size)
{
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::requestData()";

View File

@ -133,13 +133,13 @@ public:
~ftTransferModule();
//interface to download controller
bool setFileSources(std::list<std::string> peerIds);
bool addFileSource(std::string peerId);
bool removeFileSource(std::string peerId);
bool setPeerState(std::string peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
bool setFileSources(const std::list<std::string>& peerIds);
bool addFileSource(const std::string& peerId);
bool removeFileSource(const std::string& peerId);
bool setPeerState(const std::string& peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
bool getFileSources(std::list<std::string> &peerIds);
bool getPeerState(std::string peerId,uint32_t &state,uint32_t &tfRate);
uint32_t getDataRate(std::string peerId);
bool getPeerState(const std::string& peerId,uint32_t &state,uint32_t &tfRate);
uint32_t getDataRate(const std::string& peerId);
bool cancelTransfer();
bool cancelFileTransferUpward();
bool completeFileTransfer();
@ -148,9 +148,9 @@ public:
void addCRC32Map(const CRC32Map& map) ;
//interface to multiplex module
bool recvFileData(std::string peerId, uint64_t offset,
bool recvFileData(const std::string& peerId, uint64_t offset,
uint32_t chunk_size, void *data);
void requestData(std::string peerId, uint64_t offset, uint32_t chunk_size);
void requestData(const std::string& peerId, uint64_t offset, uint32_t chunk_size);
//interface to file creator
bool getChunk(const std::string& peer_id,uint32_t size_hint,uint64_t &offset, uint32_t &chunk_size);

View File

@ -334,16 +334,17 @@ void SearchDialog::download()
std::cerr << std::endl;
std::list<std::string> srcIds;
getSourceFriendsForHash((item->text(SR_HASH_COL)).toStdString(),srcIds) ;
std::string hash = item->text(SR_HASH_COL).toStdString();
getSourceFriendsForHash(hash,srcIds) ;
if(!rsFiles -> FileRequest((item->text(SR_NAME_COL)).toStdString(),
(item->text(SR_HASH_COL)).toStdString(),
hash,
(item->text(SR_SIZE_COL)).toULongLong(),
"", RS_FILE_HINTS_NETWORK_WIDE, srcIds))
attemptDownloadLocal = true ;
else
{
std::cout << "isuing file request from search dialog: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << (item->text(SR_HASH_COL)).toStdString() << "-" << (item->text(SR_SIZE_COL)).toULongLong() << "-ids=" ;
std::cout << "isuing file request from search dialog: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << hash << "-" << (item->text(SR_SIZE_COL)).toULongLong() << "-ids=" ;
for(std::list<std::string>::const_iterator it(srcIds.begin());it!=srcIds.end();++it)
std::cout << *it << "-" << std::endl ;
}
@ -365,17 +366,19 @@ void SearchDialog::downloadDirectory(const QTreeWidgetItem *item, const QString
+ "/" + base + "/";
QString cleanPath = QDir::cleanPath(path);
getSourceFriendsForHash((item->text(SR_HASH_COL)).toStdString(),srcIds) ;
std::string hash = item->text(SR_HASH_COL).toStdString();
getSourceFriendsForHash(hash,srcIds) ;
rsFiles->FileRequest(item->text(SR_NAME_COL).toStdString(),
item->text(SR_HASH_COL).toStdString(),
hash,
item->text(SR_SIZE_COL).toULongLong(),
cleanPath.toStdString(),RS_FILE_HINTS_NETWORK_WIDE, srcIds);
std::cout << "SearchDialog::downloadDirectory(): "\
"issuing file request from search dialog: -"
<< (item->text(SR_NAME_COL)).toStdString()
<< "-" << (item->text(SR_HASH_COL)).toStdString()
<< "-" << hash
<< "-" << (item->text(SR_SIZE_COL)).toULongLong()
<< "-ids=" ;
for(std::list<std::string>::const_iterator it(srcIds.begin());

View File

@ -923,13 +923,15 @@ void TransfersDialog::insertTransfers()
//first clean the model in case some files are not download anymore
//remove items that are not fiends anymore
int removeIndex = 0;
while (removeIndex < DLListModel->rowCount())
int rowCount = DLListModel->rowCount();
while (removeIndex < rowCount)
{
std::string hash = DLListModel->item(removeIndex, ID)->data(Qt::DisplayRole).toString().toStdString();
if(used_hashes.find(hash) == used_hashes.end())
if(used_hashes.find(hash) == used_hashes.end()) {
QListDelete (DLListModel->takeRow(removeIndex));
else
rowCount = DLListModel->rowCount();
} else
removeIndex++;
}
@ -1017,14 +1019,16 @@ void TransfersDialog::insertTransfers()
//first clean the model in case some files are not download anymore
//remove items that are not fiends anymore
removeIndex = 0;
while (removeIndex < ULListModel->rowCount())
rowCount = ULListModel->rowCount();
while (removeIndex < rowCount)
{
std::string hash = ULListModel->item(removeIndex, UHASH)->data(Qt::EditRole).toString().toStdString();
std::string peer = ULListModel->item(removeIndex, UUSERID)->data(Qt::EditRole).toString().toStdString();
if(used_hashes.find(hash + peer) == used_hashes.end())
if(used_hashes.find(hash + peer) == used_hashes.end()) {
QListDelete (ULListModel->takeRow(removeIndex));
else
rowCount = ULListModel->rowCount();
} else
removeIndex++;
}