mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Emit an event when a shared file hashing complete
Properly notify when a shared file has been hashed Deprecate event with arbitrary data packed in std::string
This commit is contained in:
parent
58016fff65
commit
34593d1b6f
@ -187,9 +187,10 @@ void HashStorage::threadTick()
|
||||
else
|
||||
rs_sprintf(tmpout, "%lu/%lu (%s - %d%%) : %s", (unsigned long int)mHashCounter+1, (unsigned long int)mTotalFilesToHash, friendlyUnit(mTotalHashedSize).c_str(), int(mTotalHashedSize/double(mTotalSizeToHash)*100.0), job.full_path.c_str()) ;
|
||||
|
||||
//RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout) ;
|
||||
if(rsEvents)
|
||||
{
|
||||
/* Emit deprecated event only for retrocompatibility
|
||||
* TODO: create a proper event with structured data instead of a
|
||||
* formatted string */
|
||||
auto ev = std::make_shared<RsSharedDirectoriesEvent>();
|
||||
ev->mEventCode = RsSharedDirectoriesEventCode::HASHING_FILE;
|
||||
ev->mMessage = tmpout;
|
||||
@ -198,7 +199,7 @@ void HashStorage::threadTick()
|
||||
|
||||
double seconds_origin = rstime::RsScopeTimer::currentTime() ;
|
||||
|
||||
if(RsDirUtil::getFileHash(job.full_path, hash,size, this))
|
||||
if(RsDirUtil::getFileHash(job.full_path, hash, size, this))
|
||||
{
|
||||
// store the result
|
||||
|
||||
@ -218,8 +219,7 @@ void HashStorage::threadTick()
|
||||
mChanged = true ;
|
||||
mTotalHashedSize += size ;
|
||||
}
|
||||
else
|
||||
std::cerr << "ERROR: cannot hash file " << job.full_path << std::endl;
|
||||
else RS_ERR("Failure hashing file: ", job.full_path);
|
||||
|
||||
mHashingTime += rstime::RsScopeTimer::currentTime() - seconds_origin ;
|
||||
mHashedBytes += size ;
|
||||
@ -234,10 +234,17 @@ void HashStorage::threadTick()
|
||||
++mHashCounter ;
|
||||
}
|
||||
}
|
||||
// call the client
|
||||
|
||||
// call the client
|
||||
if(!hash.isNull())
|
||||
job.client->hash_callback(job.client_param, job.full_path, hash, size);
|
||||
|
||||
/* Notify we completed hashing a file */
|
||||
auto ev = std::make_shared<RsFileHashingCompletedEvent>();
|
||||
ev->mFilePath = job.full_path;
|
||||
ev->mHashingSpeed = mCurrentHashingSpeed;
|
||||
ev->mFileHash = hash;
|
||||
rsEvents->postEvent(ev);
|
||||
}
|
||||
|
||||
bool HashStorage::requestHash(const std::string& full_path,uint64_t size,rstime_t mod_time,RsFileHash& known_hash,HashStorageClient *c,uint32_t client_param)
|
||||
|
@ -91,7 +91,7 @@ enum class RsEventType : uint32_t
|
||||
/// @see RsGxsPostedEvent
|
||||
GXS_IDENTITY = 12,
|
||||
|
||||
/// @see RsFiles
|
||||
/// @see RsFiles @deprecated
|
||||
SHARED_DIRECTORIES = 13,
|
||||
|
||||
/// @see RsFiles
|
||||
@ -103,6 +103,9 @@ enum class RsEventType : uint32_t
|
||||
/// @see rspeers.h
|
||||
NETWORK = 16,
|
||||
|
||||
/** Emitted to update library clients about file hashing being completed */
|
||||
FILE_HASHING_COMPLETED = 20,
|
||||
|
||||
__MAX /// Used internally, keep last
|
||||
};
|
||||
|
||||
|
@ -194,7 +194,8 @@ enum class RsFileTransferEventCode: uint8_t {
|
||||
COMPLETED_FILES_REMOVED = 0x02, //
|
||||
};
|
||||
|
||||
struct RsSharedDirectoriesEvent: RsEvent
|
||||
struct RS_DEPRECATED_FOR("Packing arbitrary data into an std::string is bad idea")
|
||||
RsSharedDirectoriesEvent: RsEvent
|
||||
{
|
||||
RsSharedDirectoriesEvent() : RsEvent(RsEventType::SHARED_DIRECTORIES), mEventCode(RsSharedDirectoriesEventCode::UNKNOWN) {}
|
||||
~RsSharedDirectoriesEvent() override = default;
|
||||
@ -212,6 +213,31 @@ struct RsSharedDirectoriesEvent: RsEvent
|
||||
std::string mMessage;
|
||||
};
|
||||
|
||||
struct RsFileHashingCompletedEvent: RsEvent
|
||||
{
|
||||
RsFileHashingCompletedEvent():
|
||||
RsEvent(RsEventType::FILE_HASHING_COMPLETED), mHashingSpeed(0) {}
|
||||
|
||||
///* @see RsEvent @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RsEvent::serial_process(j, ctx);
|
||||
RS_SERIAL_PROCESS(mFilePath);
|
||||
RS_SERIAL_PROCESS(mFileHash);
|
||||
RS_SERIAL_PROCESS(mHashingSpeed);
|
||||
}
|
||||
|
||||
/// Complete path of the file being hashed
|
||||
std::string mFilePath;
|
||||
|
||||
/// File hash, null if error occurred
|
||||
RsFileHash mFileHash;
|
||||
|
||||
/// Hashing speed in MB/s
|
||||
double mHashingSpeed;
|
||||
};
|
||||
|
||||
struct RsFileTransferEvent: RsEvent
|
||||
{
|
||||
RsFileTransferEvent() : RsEvent(RsEventType::FILE_TRANSFER), mFileTransferEventCode(RsFileTransferEventCode::UNKNOWN) {}
|
||||
|
Loading…
Reference in New Issue
Block a user