From 09fa77d73829e76123ac7a9b73bc90def12e9d9c Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 1 Feb 2015 09:23:58 +0000 Subject: Tox: - refactoring - updated tox core git-svn-id: http://svn.miranda-ng.org/main/trunk@11970 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_transfer.h | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'protocols/Tox/src/tox_transfer.h') diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h index f0732ca3b0..7cbbffe3ee 100644 --- a/protocols/Tox/src/tox_transfer.h +++ b/protocols/Tox/src/tox_transfer.h @@ -6,6 +6,7 @@ enum FILE_TRANSFER_STATUS NONE, STARTED, PAUSED, + BROKEN, FAILED, CANCELED, FINISHED, @@ -17,6 +18,7 @@ struct FileTransferParam PROTOFILETRANSFERSTATUS pfts; FILE_TRANSFER_STATUS status; FILE *hFile; + mir_cs fileLock; int friendNumber; int fileNumber; @@ -45,37 +47,37 @@ struct FileTransferParam return hFile != NULL; } - void Start(Tox *tox) + int Start(Tox *tox) { status = STARTED; - tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_ACCEPT, NULL, 0); + return tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_ACCEPT, NULL, 0); } - void Resume(Tox *tox) + int Resume(Tox *tox) { status = STARTED; - tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_RESUME_BROKEN, (uint8_t*)&pfts.currentFileProgress, sizeof(uint64_t)); + return tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_RESUME_BROKEN, (uint8_t*)&pfts.currentFileProgress, sizeof(pfts.currentFileProgress)); } - void Fail(Tox *tox) + int Fail(Tox *tox) { status = FAILED; - tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_KILL, NULL, 0); + return tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_KILL, NULL, 0); } - void Cancel(Tox *tox) + int Cancel(Tox *tox) { status = FINISHED; - tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_KILL, NULL, 0); + return tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_KILL, NULL, 0); } - void Finish(Tox *tox) + int Finish(Tox *tox) { status = FINISHED; - tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_FINISHED, NULL, 0); + return tox_file_send_control(tox, friendNumber, GetDirection(), fileNumber, TOX_FILECONTROL_FINISHED, NULL, 0); } - void RenameName(const TCHAR* fileName) + void Rename(const TCHAR* fileName) { pfts.ptszFiles[0] = replaceStrT(pfts.tszCurrentFile, fileName); } @@ -94,9 +96,10 @@ struct FileTransferParam } mir_free(pfts.pszFiles[0]); mir_free(pfts.pszFiles); - if (hFile) + if (hFile != NULL) { fclose(hFile); + hFile = NULL; } } }; @@ -107,7 +110,7 @@ private: std::map transfers; public: - int Count() const + size_t Count() const { return transfers.size(); } @@ -120,7 +123,7 @@ public: } } - FileTransferParam * Get(uint8_t fileNumber) + FileTransferParam* Get(uint8_t fileNumber) { if (transfers.find(fileNumber) != transfers.end()) { @@ -129,9 +132,9 @@ public: return NULL; } - FileTransferParam * At(int index) + FileTransferParam* GetAt(size_t index) { - if (Count() < index) + if (index < Count()) { std::map::iterator it = transfers.begin(); std::advance(it, index); -- cgit v1.2.3