diff options
-rw-r--r-- | protocols/Tox/src/stdafx.h | 1 | ||||
-rw-r--r-- | protocols/Tox/src/tox_core.cpp | 30 | ||||
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 18 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 5 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 22 | ||||
-rw-r--r-- | protocols/Tox/src/tox_thread.h | 32 | ||||
-rw-r--r-- | protocols/Tox/src/tox_transfer.cpp | 11 |
7 files changed, 61 insertions, 58 deletions
diff --git a/protocols/Tox/src/stdafx.h b/protocols/Tox/src/stdafx.h index d8a31e85c9..537f414662 100644 --- a/protocols/Tox/src/stdafx.h +++ b/protocols/Tox/src/stdafx.h @@ -54,6 +54,7 @@ struct CToxProto; #include "resource.h"
#include "tox_menus.h"
#include "tox_logger.h"
+#include "tox_thread.h"
#include "tox_address.h"
#include "tox_dialogs.h"
#include "tox_profile.h"
diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index 929c0c2536..225e04b7df 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -41,7 +41,7 @@ Tox_Options* CToxProto::GetToxOptions() return options;
}
-bool CToxProto::InitToxCore(ToxThreadData *toxThread)
+bool CToxProto::InitToxCore(CToxThread *toxThread)
{
logger->Log(__FUNCTION__": initializing tox core");
@@ -112,34 +112,18 @@ bool CToxProto::InitToxCore(ToxThreadData *toxThread) return false;
}
-void CToxProto::UninitToxCore(ToxThreadData *toxThread)
+void CToxProto::UninitToxCore()
{
+ if (toxThread->toxAv)
+ toxav_kill(toxThread->toxAv);
+
if (toxThread->tox)
{
- for (size_t i = 0; i < transfers.Count(); i++)
- {
- FileTransferParam *transfer = transfers.GetAt(i);
- tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
- ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0);
- transfers.Remove(transfer);
- }
-
- //if (IsToxCoreInited())
- //{
- // ptrA nickname(mir_utf8encodeW(ptrT(getTStringA("Nick"))));
- // tox_set_name(tox, (uint8_t*)(char*)nickname, mir_strlen(nickname));
-
- // //temporary
- // ptrA statusmes(mir_utf8encodeW(ptrT(getTStringA("StatusMsg"))));
- // tox_set_status_message(tox, (uint8_t*)(char*)statusmes, mir_strlen(statusmes));
- //}
-
- if (toxThread->toxAv)
- toxav_kill(toxThread->toxAv);
+ CancelAllTransfers();
SaveToxProfile();
tox_kill(toxThread->tox);
- toxThread = NULL;
+ this->toxThread = NULL;
}
}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 956378d9c4..0071d9b3f8 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -141,21 +141,9 @@ void CToxProto::CheckConnection(int &retriesCount) }
}
-void DoTox(ToxThreadData &toxThread)
-{
- {
- mir_cslock lock(toxThread.toxLock);
- tox_iterate(toxThread.tox);
- if (toxThread.toxAv)
- toxav_do(toxThread.toxAv);
- }
- uint32_t interval = tox_iteration_interval(toxThread.tox);
- Sleep(interval);
-}
-
void CToxProto::PollingThread(void*)
{
- ToxThreadData toxThread;
+ CToxThread toxThread;
this->toxThread = &toxThread;
logger->Log(__FUNCTION__": entering");
@@ -175,10 +163,10 @@ void CToxProto::PollingThread(void*) while (!toxThread.isTerminated)
{
CheckConnection(retriesCount);
- DoTox(toxThread);
+ toxThread.Do();
}
- UninitToxCore(&toxThread);
+ UninitToxCore();
toxThread.isConnected = false;
logger->Log(__FUNCTION__": leaving");
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index a547cb3871..9d9cebee7b 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -62,7 +62,7 @@ void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*) void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
{
- ToxThreadData toxThread;
+ CToxThread toxThread;
ptrT profilePath(m_proto->GetToxProfilePath());
if (!m_proto->IsFileExists(profilePath))
@@ -91,7 +91,8 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*) Clist_CreateGroup(0, group);
m_proto->LoadFriendList(NULL);
- m_proto->UninitToxCore(&toxThread);
+ m_proto->SaveToxProfile();
+ tox_kill(toxThread.tox);
m_toxAddress.Enable();
m_toxAddress.SetTextA(ptrA(m_proto->getStringA(TOX_SETTINGS_ID)));
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index f465dcd713..f9efa6a059 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -1,21 +1,6 @@ #ifndef _TOX_PROTO_H_
#define _TOX_PROTO_H_
-struct ToxThreadData
-{
- Tox *tox;
- ToxAv *toxAv;
- bool isConnected;
- bool isTerminated;
-
- mir_cs toxLock;
-
- ToxThreadData() : tox(NULL), toxAv(NULL),
- isConnected(false), isTerminated(false) { }
-
- void Stop() { isTerminated = true; }
-};
-
struct CToxProto : public PROTO<CToxProto>
{
friend CToxPasswordEditor;
@@ -82,7 +67,7 @@ public: static int OnModulesLoaded(WPARAM, LPARAM);
private:
- ToxThreadData *toxThread;
+ CToxThread *toxThread;
mir_cs profileLock;
TCHAR *accountName;
HANDLE hNetlib, hPollingThread;
@@ -102,8 +87,8 @@ private: // tox core
Tox_Options* GetToxOptions();
- bool InitToxCore(ToxThreadData *toxThread);
- void UninitToxCore(ToxThreadData *toxThread);
+ bool InitToxCore(CToxThread *toxThread);
+ void UninitToxCore();
// tox network
bool IsOnline();
@@ -247,6 +232,7 @@ private: void PauseOutgoingTransfers(uint32_t friendNumber);
void ResumeIncomingTransfers(uint32_t friendNumber);
+ void CancelAllTransfers();
// avatars
TCHAR* GetAvatarFilePath(MCONTACT hContact = NULL);
diff --git a/protocols/Tox/src/tox_thread.h b/protocols/Tox/src/tox_thread.h new file mode 100644 index 0000000000..892322b11c --- /dev/null +++ b/protocols/Tox/src/tox_thread.h @@ -0,0 +1,32 @@ +#ifndef _TOX_THREAD_H_
+#define _TOX_THREAD_H_
+
+class CToxThread
+{
+public:
+ Tox *tox;
+ ToxAv *toxAv;
+ bool isConnected;
+ bool isTerminated;
+
+ mir_cs toxLock;
+
+ CToxThread() : tox(NULL), toxAv(NULL),
+ isConnected(false), isTerminated(false) { }
+
+ void Do()
+ {
+ {
+ mir_cslock lock(toxLock);
+ tox_iterate(tox);
+ if (toxAv)
+ toxav_do(toxAv);
+ }
+ uint32_t interval = tox_iteration_interval(tox);
+ Sleep(interval);
+ }
+
+ void Stop() { isTerminated = true; }
+};
+
+#endif //_TOX_THREAD_H_
\ No newline at end of file diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index fb6e6f7a48..fef6258058 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -348,6 +348,17 @@ void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber) }
}
+void CToxProto::CancelAllTransfers()
+{
+ for (size_t i = 0; i < transfers.Count(); i++)
+ {
+ FileTransferParam *transfer = transfers.GetAt(i);
+ tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0);
+ transfers.Remove(transfer);
+ }
+}
+
void CToxProto::OnFileRequest(Tox*, uint32_t friendNumber, uint32_t fileNumber, TOX_FILE_CONTROL control, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
|