提交 16b971f9 authored 作者: Arnaldo M Pereira's avatar Arnaldo M Pereira

made ftdm_sched.c also work on win32

上级 7d3c3c84
...@@ -34,6 +34,45 @@ ...@@ -34,6 +34,45 @@
#include "private/ftdm_core.h" #include "private/ftdm_core.h"
#ifdef __WINDOWS__
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else /* */
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif /* */
struct ftdm_timezone {
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tv, struct ftdm_timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag;
if (NULL != tv) {
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
/*converting file time to unix epoch */
tmpres /= 10; /*convert into microseconds */
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tv->tv_sec = (long) (tmpres / 1000000UL);
tv->tv_usec = (long) (tmpres % 1000000UL);
}
if (NULL != tz) {
if (!tzflag) {
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
#endif /* __WINDOWS__ */
typedef struct ftdm_timer ftdm_timer_t; typedef struct ftdm_timer ftdm_timer_t;
static struct { static struct {
...@@ -55,9 +94,7 @@ struct ftdm_sched { ...@@ -55,9 +94,7 @@ struct ftdm_sched {
struct ftdm_timer { struct ftdm_timer {
char name[80]; char name[80];
ftdm_timer_id_t id; ftdm_timer_id_t id;
#ifdef __linux__
struct timeval time; struct timeval time;
#endif
void *usrdata; void *usrdata;
ftdm_sched_callback_t callback; ftdm_sched_callback_t callback;
ftdm_timer_t *next; ftdm_timer_t *next;
...@@ -234,7 +271,6 @@ failed: ...@@ -234,7 +271,6 @@ failed:
FT_DECLARE(ftdm_status_t) ftdm_sched_run(ftdm_sched_t *sched) FT_DECLARE(ftdm_status_t) ftdm_sched_run(ftdm_sched_t *sched)
{ {
ftdm_status_t status = FTDM_FAIL; ftdm_status_t status = FTDM_FAIL;
#ifdef __linux__
ftdm_timer_t *runtimer; ftdm_timer_t *runtimer;
ftdm_timer_t *timer; ftdm_timer_t *timer;
ftdm_sched_callback_t callback; ftdm_sched_callback_t callback;
...@@ -300,10 +336,6 @@ tryagain: ...@@ -300,10 +336,6 @@ tryagain:
done: done:
ftdm_mutex_unlock(sched->mutex); ftdm_mutex_unlock(sched->mutex);
#else
ftdm_log(FTDM_LOG_CRIT, "Not implemented in this platform\n");
status = FTDM_NOTIMPL;
#endif
#ifdef __WINDOWS__ #ifdef __WINDOWS__
UNREFERENCED_PARAMETER(sched); UNREFERENCED_PARAMETER(sched);
#endif #endif
...@@ -315,7 +347,6 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_timer(ftdm_sched_t *sched, const char *name ...@@ -315,7 +347,6 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_timer(ftdm_sched_t *sched, const char *name
int ms, ftdm_sched_callback_t callback, void *data, ftdm_timer_id_t *timerid) int ms, ftdm_sched_callback_t callback, void *data, ftdm_timer_id_t *timerid)
{ {
ftdm_status_t status = FTDM_FAIL; ftdm_status_t status = FTDM_FAIL;
#ifdef __linux__
struct timeval now; struct timeval now;
int rc = 0; int rc = 0;
ftdm_timer_t *newtimer; ftdm_timer_t *newtimer;
...@@ -378,10 +409,6 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_timer(ftdm_sched_t *sched, const char *name ...@@ -378,10 +409,6 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_timer(ftdm_sched_t *sched, const char *name
done: done:
ftdm_mutex_unlock(sched->mutex); ftdm_mutex_unlock(sched->mutex);
#else
ftdm_log(FTDM_LOG_CRIT, "Not implemented in this platform\n");
status = FTDM_NOTIMPL;
#endif
#ifdef __WINDOWS__ #ifdef __WINDOWS__
UNREFERENCED_PARAMETER(sched); UNREFERENCED_PARAMETER(sched);
UNREFERENCED_PARAMETER(name); UNREFERENCED_PARAMETER(name);
...@@ -396,7 +423,6 @@ done: ...@@ -396,7 +423,6 @@ done:
FT_DECLARE(ftdm_status_t) ftdm_sched_get_time_to_next_timer(const ftdm_sched_t *sched, int32_t *timeto) FT_DECLARE(ftdm_status_t) ftdm_sched_get_time_to_next_timer(const ftdm_sched_t *sched, int32_t *timeto)
{ {
ftdm_status_t status = FTDM_FAIL; ftdm_status_t status = FTDM_FAIL;
#ifdef __linux__
int res = -1; int res = -1;
int ms = 0; int ms = 0;
struct timeval currtime; struct timeval currtime;
...@@ -445,10 +471,6 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_get_time_to_next_timer(const ftdm_sched_t * ...@@ -445,10 +471,6 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_get_time_to_next_timer(const ftdm_sched_t *
done: done:
ftdm_mutex_unlock(sched->mutex); ftdm_mutex_unlock(sched->mutex);
#else
ftdm_log(FTDM_LOG_ERROR, "Implement me!\n");
status = FTDM_NOTIMPL;
#endif
#ifdef __WINDOWS__ #ifdef __WINDOWS__
UNREFERENCED_PARAMETER(timeto); UNREFERENCED_PARAMETER(timeto);
UNREFERENCED_PARAMETER(sched); UNREFERENCED_PARAMETER(sched);
......
...@@ -156,7 +156,12 @@ typedef __int64 int64_t; ...@@ -156,7 +156,12 @@ typedef __int64 int64_t;
typedef __int32 int32_t; typedef __int32 int32_t;
typedef __int16 int16_t; typedef __int16 int16_t;
typedef __int8 int8_t; typedef __int8 int8_t;
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else #else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif /* _MSC_VER */
#else /* __WINDOWS__ */
#define FTDM_INVALID_SOCKET -1 #define FTDM_INVALID_SOCKET -1
typedef int ftdm_socket_t; typedef int ftdm_socket_t;
#include <stdio.h> #include <stdio.h>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论