The Synchronous model is the least complex programming model. Typically, you can use this model to write code for a voice-processing device, then simply create a thread for each Dialogic device that needs to run this code. You do not need event-driven state machine processing because each Dialogic function runs uninterrupted to completion.
Choose the Synchronous model when you are programming an application that has:
Synchronous Model Advantages
Synchronous Model Disadvantages
Synchronous Model Programming Notes
Synchronous Model ExampleThe following example code shows a typical use of the Synchronous Programming model.
/*
* This synchronous mode sample application was designed to work with
* D/41ESC, VFX/40ESC, LSI/81SC, LSI/161SC and D/160SC-LS boards only.
* It was compiled using MS-VC++.
*/
/* C includes */
#include <stdio.h>
#include <process.h>
#include <conio.h>
#include <ctype.h>
#include <windows.h>
/* Dialogic includes */
#include <srllib.h>
#include <dxxxlib.h>
/* Defines */
#define MAX_CHAN 4 /* maximun number of voice channels in system */
/* Globals */
int Thrd_num[MAX_CHAN];
int Kbhit_flag = 0;
/* Prototypes */
int main();
DWORD WINAPI sample_begin(LPVOID);
/****************************************************************
* NAME : int main()
* DESCRIPTION : prepare screen for ouput, create threads and
* : poll for keyboard input
* INPUT : none
* OUTPUT : none
* RETURNS : 0 on success; 1 if a failure was encountered
* CAUTIONS : none
****************************************************************/
int main()
{
int cnt;
HANDLE thread_handles[MAX_CHAN];
DWORD threadID;
/* show application's title */
printf("Synchronous Mode Sample Application - hit any key to exit...\n");
/* create one thread for each voice channel in system */
for (cnt = 0; cnt < MAX_CHAN; cnt++) {
Thrd_num[cnt] = cnt;
if ((thread_handles[cnt] = (HANDLE)_beginthreadex(NULL,
0,
sample_begin,
(LPVOID)&Thrd_num[cnt],
0,
&threadID)) == (HANDLE)-1) {
/* Perform system error processing */
exit(1);
}
}
/* wait for Keyboard input to shutdown program */
getch();
Kbhit_flag++; /* let threads know it's time to abort */
/* sleep here until all threads have completed their tasks */
if (WaitForMultipleObjects(MAX_CHAN, thread_handles, TRUE, INFINITE)
== WAIT_FAILED) {
printf("ERROR: Failed WaitForMultipleObjects(): error = %ld\n",
GetLastError());
}
return(0);
}
/****************************************************************
* NAME : DWORD WINAPI sample_begin(LPVOID argp)
* DESCRIPTION : do all channel specific processing
* INPUT : LPVOID argp - pointer to the thread's index number
* OUTPUT : none
* RETURNS : 0 on success; 1 if a failure was encountered
* CAUTIONS : none
****************************************************************/
DWORD WINAPI sample_begin(LPVOID argp)
{
char channame[20];
int chdesc;
int thrd_num = *((int *)argp);
/* build name of voice channel */
sprintf(channame, "dxxxB%dC%d", (thrd_num / 4) + 1,
(thrd_num % 4) + 1);
/* open voice channel */
if ((chdesc = dx_open(channame, 0)) == -1) {
printf("%s - FAILED: dx_open(): system error = %d\n",
channame, dx_fileerrno());
return(1);
}
printf("%s - Voice channel opened\n", ATDV_NAMEP(chdesc));
/* loop until Keyboard input is received */
while (!Kbhit_flag) {
/* set the voice channel off-hook */
if (dx_sethook(chdesc, DX_OFFHOOK, EV_SYNC) == -1) {
printf("%s - FAILED: dx_sethook(DX_OFFHOOK): %s (error #%d)\n",
ATDV_NAMEP(chdesc), ATDV_ERRMSGP(chdesc), ATDV_LASTERR(chdesc));
return(1);
}
printf("%s - Voice channel off-hook\n",ATDV_NAMEP(chdesc));
/* dial number (without call progress) */
printf("%s - Voice channel dialing...\n",ATDV_NAMEP(chdesc));
if (dx_dial(chdesc, "12025551212", NULL, EV_SYNC) == -1) {
printf("%s - FAILED: dx_dial(): %s (error #%d)\n",
ATDV_NAMEP(chdesc), ATDV_ERRMSGP(chdesc), ATDV_LASTERR(chdesc));
return(1);
}
printf("%s - Voice channel Done dialing\n",ATDV_NAMEP(chdesc));
/* set the voice channel back on-hook */
if (dx_sethook(chdesc, DX_ONHOOK, EV_SYNC) == -1) {
printf("%s - FAILED: dx_sethook(DX_ONHOOK): %s (error #%d)\n",
ATDV_NAMEP(chdesc), ATDV_ERRMSGP(chdesc), ATDV_LASTERR(chdesc));
return(1);
}
printf("%s - Voice channel on-hook\n",ATDV_NAMEP(chdesc));
}
/* close the voice channel */
if (dx_close(chdesc) == -1) {
printf("%s - FAILED: dx_close(): %s (error #%d)\n",
ATDV_NAMEP(chdesc), ATDV_ERRMSGP(chdesc), ATDV_LASTERR(chdesc));
return(1);
}
printf("%s - Voice channel closed\n",channame);
return(0);
}
Click here to contact Dialogic Customer Engineering
Copyright 2001, Dialogic Corporation