summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src/t_timers.cpp
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-03-25 16:20:45 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-03-25 16:20:45 +0000
commitc0cb5774e9ceb7fdb40b2387217f8b5be70eb315 (patch)
treec82c5a64d631b0319a5ba933ccb76d9425e77cec /protocols/Telegram/src/t_timers.cpp
parent8e759e2624850a183d6e79a0b3a94a64e7895936 (diff)
Telegram: winapi timers
git-svn-id: http://svn.miranda-ng.org/main/trunk@16543 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Telegram/src/t_timers.cpp')
-rw-r--r--protocols/Telegram/src/t_timers.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/protocols/Telegram/src/t_timers.cpp b/protocols/Telegram/src/t_timers.cpp
new file mode 100644
index 0000000000..c897247fab
--- /dev/null
+++ b/protocols/Telegram/src/t_timers.cpp
@@ -0,0 +1,58 @@
+
+#include "stdafx.h"
+
+extern HANDLE hQueue;
+
+struct tgl_timer
+{
+ tgl_state *TLS;
+ void(*cb)(struct tgl_state *TLS, void *arg);
+ void *arg;
+ HANDLE hTimer;
+};
+
+VOID CALLBACK WaitOrTimerCallback(
+ _In_ PVOID lpParameter,
+ _In_ BOOLEAN TimerOrWaitFired
+ )
+{
+ tgl_timer *p = (tgl_timer*)lpParameter;
+ p->cb(p->TLS, p->arg);
+ p->hTimer = 0;
+}
+
+
+struct tgl_timer *mtgl_timer_alloc (struct tgl_state *TLS, void (*cb)(struct tgl_state *TLS, void *arg), void *arg)
+{
+ tgl_timer *p = (tgl_timer *)calloc(sizeof (tgl_timer), 1);
+ p->TLS = TLS;
+ p->cb = cb;
+ p->arg = arg;
+ return p;
+}
+
+void mtgl_timer_insert (struct tgl_timer *t, double p)
+{
+ HANDLE hNewTimer = 0;
+ CreateTimerQueueTimer(&hNewTimer, hQueue, WaitOrTimerCallback, t, (DWORD)(p * 1000), 0, 0);
+ t->hTimer = hNewTimer;
+}
+
+void mtgl_timer_delete (struct tgl_timer *t) {
+ DeleteTimerQueueTimer(hQueue, t->hTimer, 0);
+ t->hTimer = 0;
+}
+
+void mtgl_timer_free (struct tgl_timer *t)
+{
+ if (t->hTimer) mtgl_timer_delete(t);
+ free(t);
+}
+
+
+struct tgl_timer_methods mtgl_libevent_timers = {
+ mtgl_timer_alloc,
+ mtgl_timer_insert,
+ mtgl_timer_delete,
+ mtgl_timer_free
+}; \ No newline at end of file