Sync up miranda files with current libsipe branch
[siplcs.git] / src / miranda / miranda-schedule.c
blob6be9a7aecf49cf0e7b46364113e773c5567f506a
1 /**
2 * @file miranda-schedule.c
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <windows.h>
25 #include <glib.h>
27 #include "sipe-common.h"
28 #include "sipe-backend.h"
29 #include "sipe-core.h"
31 #include "newpluginapi.h"
32 #include "m_system.h"
34 struct time_entry {
35 gpointer core_data;
36 guint timeout;
37 HANDLE sem;
38 gboolean cancelled;
41 static unsigned __stdcall timeoutfunc(void* data)
43 struct time_entry *entry = (struct time_entry*)data;
44 DWORD ret;
46 SIPE_DEBUG_INFO("timeout start; <%08x> timeout is <%d>", entry, entry->timeout);
48 entry->sem = CreateSemaphore(NULL, 0, 100, NULL);
50 ret = WaitForSingleObjectEx( entry->sem, entry->timeout, FALSE);
51 if (ret == WAIT_TIMEOUT)
53 SIPE_DEBUG_INFO("<%08x> about to run", entry);
54 sipe_core_schedule_execute(entry->core_data);
55 SIPE_DEBUG_INFO("<%08x> exiting", entry);
57 else if (entry->cancelled == TRUE)
59 SIPE_DEBUG_INFO("<%08x> Timeout cancelled by caller", entry);
61 else
63 SIPE_DEBUG_INFO("<%08x> Something unexpected happened: <%d>", entry, ret);
66 CloseHandle(entry->sem);
67 g_free(entry);
68 return 0;
72 gpointer sipe_backend_schedule_mseconds(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
73 guint timeout,
74 gpointer data)
76 struct time_entry *entry;
78 entry = g_new0(struct time_entry,1);
79 entry->timeout = timeout;
80 entry->core_data = data;
81 entry->cancelled = FALSE;
83 CloseHandle((HANDLE) mir_forkthreadex( timeoutfunc, entry, 65536, NULL ));
85 return entry;
88 gpointer sipe_backend_schedule_seconds(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
89 guint timeout,
90 gpointer data)
92 return sipe_backend_schedule_mseconds( sipe_public, timeout*1000, data);
95 void sipe_backend_schedule_cancel(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
96 gpointer data)
98 struct time_entry *entry = (struct time_entry*) data;
100 if (entry && entry->sem)
102 SIPE_DEBUG_INFO("Cancelling timeout <%08x>", entry);
103 entry->cancelled = TRUE;
104 ReleaseSemaphore(entry->sem, 1, NULL);
110 Local Variables:
111 mode: c
112 c-file-style: "bsd"
113 indent-tabs-mode: t
114 tab-width: 8
115 End: