]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix freetdm win compilation
authorMoises Silva <moy@sangoma.com>
Thu, 8 Apr 2010 17:25:44 +0000 (13:25 -0400)
committerMoises Silva <moy@sangoma.com>
Thu, 8 Apr 2010 17:25:44 +0000 (13:25 -0400)
libs/freetdm/msvc/freetdm.2008.vcproj
libs/freetdm/src/ftdm_cpu_monitor.c
libs/freetdm/src/ftdm_io.c
libs/freetdm/src/ftdm_threadmutex.c
libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c

index 8540fce75e3200c32eca191a4c4e7cdf29a4af7b..801c368aefdc212ab5837a247f2ac4194c8d58e8 100644 (file)
                        UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
                        >
                        <File
-                               RelativePath="..\src\include\fsk.h"
+                               RelativePath="..\src\include\freetdm.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\g711.h"
+                               RelativePath="..\src\include\fsk.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\hashtable.h"
+                               RelativePath="..\src\include\ftdm_buffer.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\hashtable_itr.h"
+                               RelativePath="..\src\include\ftdm_config.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\hashtable_private.h"
+                               RelativePath="..\src\include\ftdm_dso.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\libteletone.h"
+                               RelativePath="..\src\include\ftdm_threadmutex.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\libteletone_detect.h"
+                               RelativePath="..\src\include\ftdm_types.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\libteletone_generate.h"
+                               RelativePath="..\src\include\g711.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\freetdm.h"
+                               RelativePath="..\src\include\hashtable.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\uart.h"
+                               RelativePath="..\src\include\hashtable_itr.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\ftdm_buffer.h"
+                               RelativePath="..\src\include\hashtable_private.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\ftdm_config.h"
+                               RelativePath="..\src\include\libteletone.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\ftdm_dso.h"
+                               RelativePath="..\src\include\libteletone_detect.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\ftdm_threadmutex.h"
+                               RelativePath="..\src\include\libteletone_generate.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\include\ftdm_types.h"
+                               RelativePath="..\src\include\uart.h"
                                >
                        </File>
                </Filter>
                                >
                        </File>
                        <File
-                               RelativePath="..\src\g711.c"
+                               RelativePath="..\src\ftdm_buffer.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\hashtable.c"
+                               RelativePath="..\src\ftdm_callerid.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\hashtable_itr.c"
+                               RelativePath="..\src\ftdm_config.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\libteletone_detect.c"
+                               RelativePath="..\src\ftdm_cpu_monitor.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\libteletone_generate.c"
+                               RelativePath="..\src\ftdm_dso.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\uart.c"
+                               RelativePath="..\src\ftdm_io.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\ftdm_buffer.c"
+                               RelativePath="..\src\ftdm_queue.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\ftdm_callerid.c"
+                               RelativePath="..\src\ftdm_threadmutex.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\ftdm_config.c"
+                               RelativePath="..\src\g711.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\ftdm_dso.c"
+                               RelativePath="..\src\hashtable.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\ftdm_io.c"
+                               RelativePath="..\src\hashtable_itr.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\ftdm_queue.c"
+                               RelativePath="..\src\libteletone_detect.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\src\ftdm_threadmutex.c"
+                               RelativePath="..\src\libteletone_generate.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\src\uart.c"
                                >
                        </File>
                </Filter>
index eebf922b98798ed0b5a6b6c9553c954c2bb29034..7c79a2e65ce8575b58e736128139ecfc3bfa3a1c 100644 (file)
@@ -201,28 +201,31 @@ FT_DECLARE(ftdm_status_t) ftdm_cpu_get_system_idle_time (struct ftdm_cpu_monitor
        return FTDM_SUCCESS;
 }
 
-#elif defined (WIN32) || defined (WIN64)
+#elif defined (__WINDOWS__)
 FT_DECLARE(ftdm_status_t) ftdm_cpu_get_system_idle_time(struct ftdm_cpu_monitor_stats *p, double *idle_percentage)
 {
        FILETIME idleTime;
        FILETIME kernelTime;
        FILETIME userTime;
+       int64_t i64UserTime;
+       int64_t i64KernelTime;
+       int64_t i64IdleTime;
   
-       if (!::GetSystemTimes(&idleTime, &kernelTime, &userTime)) {
-               return false;
+       if (!GetSystemTimes(&idleTime, &kernelTime, &userTime)) {
+               return FTDM_FAIL;
        }
   
-       __int64 i64UserTime = (__int64)userTime.dwLowDateTime | ((__int64)userTime.dwHighDateTime << 32);
+       i64UserTime = (int64_t)userTime.dwLowDateTime | ((int64_t)userTime.dwHighDateTime << 32);
 
-       __int64 i64KernelTime = (__int64)kernelTime.dwLowDateTime | ((__int64)kernelTime.dwHighDateTime << 32);
+       i64KernelTime = (int64_t)kernelTime.dwLowDateTime | ((int64_t)kernelTime.dwHighDateTime << 32);
 
-       __int64 i64IdleTime = (__int64)idleTime.dwLowDateTime | ((__int64)idleTime.dwHighDateTime << 32);
+       i64IdleTime = (int64_t)idleTime.dwLowDateTime | ((int64_t)idleTime.dwHighDateTime << 32);
 
        if (p->valid_last_times) {
-               __int64 i64User = i64UserTime - p->i64LastUserTime;
-               __int64 i64Kernel = i64KernelTime - p->i64LastKernelTime;
-               __int64 i64Idle = i64IdleTime - p->i64LastIdleTime;
-               __int64 i64System = i64User + i64Kernel;
+               int64_t i64User = i64UserTime - p->i64LastUserTime;
+               int64_t i64Kernel = i64KernelTime - p->i64LastKernelTime;
+               int64_t i64Idle = i64IdleTime - p->i64LastIdleTime;
+               int64_t i64System = i64User + i64Kernel;
                *idle_percentage = 100.0 * i64Idle / i64System;
        } else {
                *idle_percentage = 100.0;
index 033a25d6753394a9a28be195e1984edad1f9bc06..2cacf69d9045715697acba215506f20267dc556a 100644 (file)
@@ -2855,6 +2855,7 @@ static ftdm_status_t load_config(void)
        ftdm_config_t cfg;
        char *var, *val;
        int catno = -1;
+       int intparam = 0;
        int currindex = 0;
        ftdm_span_t *span = NULL;
        unsigned configured = 0, d = 0;
@@ -3059,14 +3060,16 @@ static ftdm_status_t load_config(void)
                                        ftdm_log(FTDM_LOG_ERROR, "Invalid cpu monitoring interval %s\n", val);
                                }
                        } else if (!strncasecmp(var, "cpu_set_alarm_threshold", sizeof("cpu_set_alarm_threshold")-1)) {
-                               if (atoi(val) > 0 && atoi(val) < 100) {
-                                       globals.cpu_monitor.set_alarm_threshold = atoi(val);
+                               intparam = atoi(val);
+                               if (intparam > 0 && intparam < 100) {
+                                       globals.cpu_monitor.set_alarm_threshold = (uint8_t)intparam;
                                } else {
                                        ftdm_log(FTDM_LOG_ERROR, "Invalid cpu alarm set threshold %s\n", val);
                                }
                        } else if (!strncasecmp(var, "cpu_reset_alarm_threshold", sizeof("cpu_reset_alarm_threshold")-1)) {
-                               if (atoi(val) > 0 && atoi(val) < 100) {
-                                       globals.cpu_monitor.reset_alarm_threshold = atoi(val);
+                               intparam = atoi(val);
+                               if (intparam > 0 && intparam < 100) {
+                                       globals.cpu_monitor.reset_alarm_threshold = (uint8_t)intparam;
                                        if (globals.cpu_monitor.reset_alarm_threshold > globals.cpu_monitor.set_alarm_threshold) {
                                                globals.cpu_monitor.reset_alarm_threshold = globals.cpu_monitor.set_alarm_threshold - 10;
                                                ftdm_log(FTDM_LOG_ERROR, "Cpu alarm reset threshold must be lower than set threshold"
@@ -3652,6 +3655,9 @@ static void *ftdm_cpu_monitor_run(ftdm_thread_t *me, void *obj)
        ftdm_delete_cpu_monitor(cpu_stats);
        monitor->running = 0;
        return NULL;
+#ifdef __WINDOWS__
+       UNREFERENCED_PARAMETER(me);
+#endif
 }
 
 static ftdm_status_t ftdm_cpu_monitor_start(void)
index 8e9c62ff4c9e98fcf80b93ecab34cc13f10f928b..9eca9eeb3d7f50b66849f46684e96d891ec58b94 100644 (file)
@@ -314,7 +314,7 @@ FT_DECLARE(ftdm_status_t) ftdm_interrupt_wait(ftdm_interrupt_t *interrupt, int m
                num++;
                ints[1] = interrupt->device;
        }
-       res = WaitForMultipleObjects(num, &ints, FALSE, ms >= 0 ? ms : INFINITE);
+       res = WaitForMultipleObjects(num, ints, FALSE, ms >= 0 ? ms : INFINITE);
        switch (res) {
        case WAIT_TIMEOUT:
                return FTDM_TIMEOUT;
@@ -366,7 +366,7 @@ FT_DECLARE(ftdm_status_t) ftdm_interrupt_signal(ftdm_interrupt_t *interrupt)
 {
        ftdm_assert_return(interrupt != NULL, FTDM_FAIL, "Interrupt is null!\n");
 #ifdef WIN32
-       if (!SetEvent(interrupt->interrupt)) {
+       if (!SetEvent(interrupt->event)) {
                ftdm_log(FTDM_LOG_ERROR, "Failed to signal interrupt\n");
                return FTDM_FAIL;
        }
@@ -400,10 +400,42 @@ FT_DECLARE(ftdm_status_t) ftdm_interrupt_destroy(ftdm_interrupt_t **ininterrupt)
 
 FT_DECLARE(ftdm_status_t) ftdm_interrupt_multiple_wait(ftdm_interrupt_t *interrupts[], ftdm_size_t size, int ms)
 {
-#ifndef WIN32
-       int i;
-       int res = 0;
        int numdevices = 0;
+       unsigned i;
+#if defined(__WINDOWS__)
+       DWORD res = 0;
+       HANDLE ints[20];
+       if (size > (ftdm_array_len(ints)/2)) {
+               /* improve if needed: dynamically allocate the list of interrupts *only* when exceeding the default size */
+               ftdm_log(FTDM_LOG_CRIT, "Unsupported size of interrupts: %d, implement me!\n", size);
+               return FTDM_FAIL;
+       }
+
+       for (i = 0; i < size; i++) {
+               ints[i] = interrupts[i]->event;
+               if (interrupts[i]->device != FTDM_INVALID_SOCKET) {
+                       ints[i+numdevices] = interrupts[i]->device;
+                       numdevices++;
+               }
+       }
+
+       res = WaitForMultipleObjects(size+numdevices, ints, FALSE, ms >= 0 ? ms : INFINITE);
+
+       switch (res) {
+       case WAIT_TIMEOUT:
+               return FTDM_TIMEOUT;
+       case WAIT_FAILED:
+       case WAIT_ABANDONED: /* is it right to fail with abandoned? */
+               return FTDM_FAIL;
+       default:
+               if (res >= (size+numdevices)) {
+                       ftdm_log(FTDM_LOG_ERROR, "Error waiting for freetdm interrupt event (WaitForSingleObject returned %d)\n", res);
+                       return FTDM_FAIL;
+               }
+               /* fall-through to FTDM_SUCCESS at the end of the function */
+       }
+#elif defined(__linux__)
+       int res = 0;
        char pipebuf[255];
        struct pollfd ints[size*2];
 
@@ -432,6 +464,7 @@ FT_DECLARE(ftdm_status_t) ftdm_interrupt_multiple_wait(ftdm_interrupt_t *interru
                return FTDM_TIMEOUT;
        }
 
+       /* check for events in the pipes, NOT in the devices */
        for (i = 0; i < size; i++) {
                if (ints[i].revents & POLLIN) {
                        res = read(ints[i].fd, pipebuf, sizeof(pipebuf));
@@ -440,7 +473,7 @@ FT_DECLARE(ftdm_status_t) ftdm_interrupt_multiple_wait(ftdm_interrupt_t *interru
                        }
                }
        }
-
+#else
 #endif
        return FTDM_SUCCESS;
 }
index 46be23f60b0a728ec84ee4b6f9c4b1ce4b0f677e..b941e641de80050b0bea0317669192e45459e664 100644 (file)
@@ -101,8 +101,6 @@ static struct {
 FIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event);
 FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event);
 
-#define WP_INVALID_SOCKET -1 
-
 /**
  * \brief Poll for event on a wanpipe socket
  * \param fd Wanpipe socket descriptor
@@ -224,7 +222,7 @@ static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start
        }       
        for(x = start; x < end; x++) {
                ftdm_channel_t *chan;
-               ftdm_socket_t sockfd = WP_INVALID_SOCKET;
+               ftdm_socket_t sockfd = FTDM_INVALID_SOCKET;
                const char *dtmf = "none";
                if (!strncasecmp(span->name, "smg_prid_nfas", 8) && span->trunk_type == FTDM_TRUNK_T1 && x == 24) {
 #ifdef LIBSANGOMA_VERSION
@@ -236,7 +234,7 @@ static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start
                        sockfd = tdmv_api_open_span_chan(spanno, x);
                }
 
-               if (sockfd == WP_INVALID_SOCKET) {
+               if (sockfd == FTDM_INVALID_SOCKET) {
                        ftdm_log(FTDM_LOG_ERROR, "Failed to open wanpipe device span %d channel %d\n", spanno, x);
                        continue;
                }
@@ -1166,9 +1164,8 @@ static FIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy)
        }
 #endif
 
-       if (ftdmchan->sockfd > -1) {
-               close(ftdmchan->sockfd);
-               ftdmchan->sockfd = WP_INVALID_SOCKET;
+       if (ftdmchan->sockfd != FTDM_INVALID_SOCKET) {
+               sangoma_close(&ftdmchan->sockfd);
        }
 
        return FTDM_SUCCESS;