Prosody application note: writing applications for Microsoft Windows

This document provides additional information specific to the Microsoft Windows implementation of Prosody TiNG.

Building applications

Please see Prosody Guide - how to build applications to use Prosody.

File descriptors

If a large number of C run time library file descriptors are opened in an application, it may be necessary to invoke _setmaxstdio() to increase the default limit from default of 512 to a higher value (absolute max is 2048). See Microsoft C run time library documentation for more details.

Prosody Events

Prosody events must be created using smd_ev_create(). The Win32 API calls WaitForSingleObject() or WaitForMultipleObjects() may be used instead of smd_ev_wait() to wait on one or more Prosody events.

The example code below illustrates how to wait until another thread terminates, a DTMF digit occurs, or another thread sets an event to indicate the incoming call has been cleared down by the call originator. See Microsoft Win32 API documentation for more information about WaitForSingleObject() and WaitForMultipleObjects().

HANDLE current_handles[3];

/* create and associate event as before */

current_handles[0] = handleToAnotherThread;
current_handles[1] = chEvSetParms.event;
current_handles[2] = callToIdleStateEvent;

for (;!finished;) {
    switch (WaitForMultipleObjects(3, current_handles, FALSE, WAIT_TIME)) {
	case WAIT_OBJECT_0:
		/* handle another thread termination */
		break; 
	case WAIT_OBJECT_0 + 1:
		/* handle DTMF digit - do get recognised etc. */
		break; 
	case WAIT_OBJECT_0 + 2:
		/* handle incoming call being cleared to idle state */
		break; 
	case WAIT_TIMEOUT:
		/* handle timeout */
		break;
	default:
		/* handle error */
    }
}

/* free event etc */

Multi-process applications

Care should be taken with values of type like tSMChannelId. These are defined as pointers, and consequently are only valid in the process space in which they were allocated. Multiple threads in one process space may of course share use of these values.


Document reference: AN 1344