2 * @file miranda-schedule.c
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
27 #include "sipe-common.h"
28 #include "sipe-backend.h"
29 #include "sipe-core.h"
31 #include "newpluginapi.h"
41 static unsigned __stdcall
timeoutfunc(void* data
)
43 struct time_entry
*entry
= (struct time_entry
*)data
;
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
);
63 SIPE_DEBUG_INFO("<%08x> Something unexpected happened: <%d>", entry
, ret
);
66 CloseHandle(entry
->sem
);
72 gpointer
sipe_backend_schedule_mseconds(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
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
));
88 gpointer
sipe_backend_schedule_seconds(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
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
,
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
);