summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_thread.h
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Tox/src/tox_thread.h')
-rw-r--r--protocols/Tox/src/tox_thread.h70
1 files changed, 65 insertions, 5 deletions
diff --git a/protocols/Tox/src/tox_thread.h b/protocols/Tox/src/tox_thread.h
index b476f54686..59caa7ee30 100644
--- a/protocols/Tox/src/tox_thread.h
+++ b/protocols/Tox/src/tox_thread.h
@@ -3,7 +3,7 @@
class CToxThread
{
-public:
+private:
Tox *tox;
ToxAV *toxAV;
bool isConnected;
@@ -11,10 +11,65 @@ public:
mir_cs toxLock;
- CToxThread() : tox(NULL), toxAV(NULL),
- isConnected(false), isTerminated(false) { }
+ mir_cs lock;
+
+public:
+ CToxThread(Tox_Options *options, TOX_ERR_NEW *error = NULL) : tox(NULL), toxAV(NULL),
+ isConnected(false), isTerminated(false)
+ {
+ tox = tox_new(options, error);
+ }
+
+ ~CToxThread()
+ {
+ if (toxAV)
+ {
+ toxav_kill(toxAV);
+ toxAV = NULL;
+ }
+
+ if (tox)
+ {
+ tox_kill(tox);
+ tox = NULL;
+ }
+ }
+
+ mir_cslock Lock()
+ {
+ return mir_cslock(lock);
+ }
+
+ Tox* Tox()
+ {
+ return tox;
+ }
+
+ ToxAV* ToxAV()
+ {
+ return toxAV;
+ }
+
+ bool IsConnected() const
+ {
+ return tox && isConnected;
+ }
+
+ void Connect()
+ {
+ Lock();
+
+ isConnected = true;
+ }
- void Do()
+ void Disconnect()
+ {
+ Lock();
+
+ isConnected = false;
+ }
+
+ void Iterate()
{
{
mir_cslock lock(toxLock);
@@ -23,10 +78,15 @@ public:
// toxav_iterate(toxAV);
}
uint32_t interval = tox_iteration_interval(tox);
- interval ++; /* Prevent zero sleep interval. */
+ interval = interval ? interval : 50;
Sleep(interval);
}
+ bool IsTerminated() const
+ {
+ return !tox || isTerminated;
+ }
+
void Stop() { isTerminated = true; }
};