Revision
17246
Author
moy
Date
2010-04-08 12:25:44 -0500 (Thu, 08 Apr 2010)

Log Message

fix freetdm win compilation

Modified Paths

Diff

Modified: freeswitch/trunk/libs/freetdm/msvc/freetdm.2008.vcproj (17245 => 17246)


--- freeswitch/trunk/libs/freetdm/msvc/freetdm.2008.vcproj	2010-04-08 17:12:52 UTC (rev 17245)
+++ freeswitch/trunk/libs/freetdm/msvc/freetdm.2008.vcproj	2010-04-08 17:25:44 UTC (rev 17246)
@@ -327,63 +327,63 @@
 			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>
@@ -397,57 +397,61 @@
 				>
 			</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>
 	</Files>
 	<Globals>

Modified: freeswitch/trunk/libs/freetdm/src/ftdm_cpu_monitor.c (17245 => 17246)


--- freeswitch/trunk/libs/freetdm/src/ftdm_cpu_monitor.c	2010-04-08 17:12:52 UTC (rev 17245)
+++ freeswitch/trunk/libs/freetdm/src/ftdm_cpu_monitor.c	2010-04-08 17:25:44 UTC (rev 17246)
@@ -201,28 +201,31 @@
 	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;

Modified: freeswitch/trunk/libs/freetdm/src/ftdm_io.c (17245 => 17246)


--- freeswitch/trunk/libs/freetdm/src/ftdm_io.c	2010-04-08 17:12:52 UTC (rev 17245)
+++ freeswitch/trunk/libs/freetdm/src/ftdm_io.c	2010-04-08 17:25:44 UTC (rev 17246)
@@ -2855,6 +2855,7 @@
 	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 @@
 					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 @@
 	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)

Modified: freeswitch/trunk/libs/freetdm/src/ftdm_threadmutex.c (17245 => 17246)


--- freeswitch/trunk/libs/freetdm/src/ftdm_threadmutex.c	2010-04-08 17:12:52 UTC (rev 17245)
+++ freeswitch/trunk/libs/freetdm/src/ftdm_threadmutex.c	2010-04-08 17:25:44 UTC (rev 17246)
@@ -314,7 +314,7 @@
 		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 @@
 {
 	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_multiple_wait(ftdm_interrupt_t *interrupts[], ftdm_size_t size, int ms)
 {
-#ifndef WIN32
-	int i;
+	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;
-	int numdevices = 0;
 	char pipebuf[255];
 	struct pollfd ints[size*2];
 
@@ -432,6 +464,7 @@
 		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 @@
 			}
 		}
 	}
-
+#else
 #endif
 	return FTDM_SUCCESS;
 }

Modified: freeswitch/trunk/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c (17245 => 17246)


--- freeswitch/trunk/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c	2010-04-08 17:12:52 UTC (rev 17245)
+++ freeswitch/trunk/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c	2010-04-08 17:25:44 UTC (rev 17246)
@@ -101,8 +101,6 @@
 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 @@
 	}	
 	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 @@
 			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 @@
 	}
 #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;