⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gc_basic_call_model.c

📁 dialogic gcwithvoice
💻 C
📖 第 1 页 / 共 5 页
字号:

#ifdef _WIN32	/* Defined in Windows */  
	struct _timeb	  Timeb;										/* used to get milliseconds */
#else			/* Defined in Unix	*/
	struct timeb		Timeb;	  
#endif
	 
	/* Put time stamp	 - everything but the milliseconds */
	TimeStr[0] = '\0';
	time(&Timet);
	Time = localtime(&Timet);

#ifdef _WIN32	/* Defined in Windows */  
	_ftime(&Timeb);												/* needed to get the milliseconds */
#else			/* Defined in Unix	 */  
	ftime(&Timeb); 
#endif

	if (fp){
		fprintf(fp, "%02d/%02d %02d:%02d:%02d.%03d ", Time->tm_mon+1, Time->tm_mday, Time->tm_hour, Time->tm_min, Time->tm_sec, Timeb.millitm);
		fprintf(fp, ": %10s, %s\n", devname, messages);
		fclose(fp);
	}
	return;
}

/********************************************************************************
 *			NAME: main ()
 *DESCRIPTION: This is the entry point. 
 *					It loads the configuration file.
 *					Take cares the	 Event Handling process.
 *					Starts GC Library.
 *					Opens Configured Devices.
 *					Waits for user interrupted signal (ctrl+c).
 *					Whenever an event is received on any of the opened 
 *					devices, Depending upon the event received the proper 
 *					action will be taken.
 *		  INPUT: None
 *		RETURNS: 0 if success else -1
 ********************************************************************************/
int main(int argc, char *argv[])
{
	int						i, ret;
	char						str[MAX_STRING_SIZE], str1[MAX_STRING_SIZE];
	GC_CCLIB_STATUSALL	cclib_status_all;

	/* Note down the start time for the test */
	time(&start_time);

	
	/* Give control to Event Handler */ 
#ifdef _WIN32
	signal(SIGINT, (void (__cdecl*)(int)) intr_hdlr);
	signal(SIGTERM, (void (__cdecl*)(int)) intr_hdlr);
#else
	signal(SIGHUP, (void (*)()) intr_hdlr);
	signal(SIGQUIT, (void (*)()) intr_hdlr);
	signal(SIGINT, (void (*)()) intr_hdlr);
	signal(SIGTERM, (void (*)()) intr_hdlr);
#endif

	init_srl_mode();									/* set SRL mode to ASYNC, polled */

	/* Load Configuration file */
	load_config_file();
	if ( ( introfd = fileopen( INTRO_VOX, O_RDONLY ) ) == -1 ) {
      sprintf( tmpbuff, "Cannot fileopen %s", INTRO_VOX );
      QUIT( 1 );
   }

   if ( ( invalidfd = fileopen( INVALID_VOX, O_RDONLY ) ) == -1 ) {
      sprintf( tmpbuff, "Cannot fileopen %s", INVALID_VOX );
      QUIT( 1 );
   }

   if ( ( goodbyefd = fileopen( GOODBYE_VOX, O_RDONLY ) ) == -1 ) {
      sprintf( tmpbuff, "Cannot fileopen %s", GOODBYE_VOX );
      QUIT( 1 );
   }

   if ( ( blankfd = fileopen( BLANK_VOX, O_RDONLY ) ) == -1 ) {
      sprintf( tmpbuff, "Cannot fileopen %s", BLANK_VOX );
      QUIT( 1 );
   }

	/* Function to open all the logfiles */
	//printError("System", "Application start");
	//open_all_logfiles();
	if (num_devices == 0) {
		exitdemo(1);
	}
	printandlog(ALL_DEVICES, MISC, NULL, "********** GC DEMO - BASIC CALL MODEL ***********\n", 0);
	
	/* Start GlobalCall */
	if (gc_Start(NULL) != GC_SUCCESS) { 
		sprintf(str, "gc_Start(startp = NULL) Failed");
		printandlog(ALL_DEVICES, GC_APIERR, NULL, str, 0);
		exitdemo(1);
	}
	/* Set the flag gc_started to YES */
	gc_started = YES;
	sprintf(str, "gc_Start(startp = NULL) Success");
	printandlog(ALL_DEVICES, GC_APICALL, NULL, str, 0);


	/* this code is usefule for installation problem debugging */
	/* you may not wish to use this code in production systems */
	if (gc_CCLibStatusEx("GC_ALL_LIB", &cclib_status_all) != GC_SUCCESS) {
		sprintf(str, "gc_CCLibStatusEx(GC_ALL_LIB, &cclib_status_all) Failed");
		printandlog(ALL_DEVICES, GC_APIERR, NULL, str, 0);
		exitdemo(1);
	}	
	strcpy(str, " Call Control Library Status:\n");
	for (i = 0; i < GC_TOTAL_CCLIBS; i++) {
		switch (cclib_status_all.cclib_state[i].state) {
			case GC_CCLIB_CONFIGURED:
				sprintf(str1, "		  %s - configured\n", cclib_status_all.cclib_state[i].name);
				break;

			case GC_CCLIB_AVAILABLE:
				sprintf(str1, "		  %s - available\n", cclib_status_all.cclib_state[i].name);
				break;

			case GC_CCLIB_FAILED:
				sprintf(str1, "		  %s - is not available for use\n", cclib_status_all.cclib_state[i].name);
				break;

			default:
				sprintf(str1, "		  %s - unknown CCLIB status\n", cclib_status_all.cclib_state[i].name);
				break;


		}
		strcat(str, str1);
	}
	printandlog(ALL_DEVICES, MISC, NULL, str, 0);

	/* open all the GC devices */
	open_all_devices(); 
	
	/* 
	-- Forever loop where the main work is done - wait for an event or user requested exit
	*/
	for (;;) {
		ret = sr_waitevt(500);					/* 1/2 second */
		if (ret != -1) {							/* i.e. not timeout */
			process_event();
		}

		if (interrupted == NO) {				/* flag set in intr_hdlr() */
			drop_outbound_calls_if_required();/* an artifact of the demo program */
														/* where the outbound side disconnects 1-2 */
														/* seconds after connected */

			make_calls_if_required();			/* handles error conditions on makecall */
		} else {
			initiate_exit();
			if (reset_linedevs_left_to_complete == 0) {
				exitdemo(1);
			}
		}

	}
} /* End of Main */

/****************************************************************
*			NAME: void init_srl_mode(void)
* DESCRIPTION: Inits SR mode
*		RETURNS: None
*	  CAUTIONS: NA
****************************************************************/
static void init_srl_mode(void)
{
/* 
SRL MODEL TYPE - Single Threaded Async, event handler will be called in the Main thread 
*/
#ifdef _WIN32
	int	mode = SR_STASYNC | SR_POLLMODE; 
#else
	int	mode = SR_POLLMODE;
#endif
	

	/* Set SRL mode */
#ifdef _WIN32
	if (sr_setparm(SRL_DEVICE, SR_MODELTYPE, &mode) == -1) {
		printandlog(ALL_DEVICES, NON_GC_APIERR, NULL, "Unable to set to SR_STASYNC | SR_POLLMODE", 0);
		exitdemo(1);
	}
	printandlog(ALL_DEVICES, MISC, NULL, "SRL Model Set to SR_STASYNC | SR_POLLMODE", 0);
#else
	if (sr_setparm(SRL_DEVICE, SR_MODEID, &mode) == -1) {
		printandlog(ALL_DEVICES, NON_GC_APIERR, NULL, "Unable to set mode ID to SR_POLLMODE ", 0);
		exitdemo(1);
	}
	
	printandlog(ALL_DEVICES, MISC, NULL, "SRL mode ID set to SR_POLLMODE", 0);
#endif
}

/****************************************************************
*			NAME: open_all_logfiles(void)
* DESCRIPTION: Function to Open the Logfiles and put file pointers in file 
*					pointer field of port array. Later depending upon the index the
*					particular file can be accessed to dump the data.
*					If the network device name is present, then the log file
*					uses the network device name
*					else it uses the voice device name
*		RETURNS: returns 1 if successful
*	  CAUTIONS: Assumes device name includes network device name or a voice device name
****************************************************************/
static int open_all_logfiles(void)
{	
	char		temp_filename[MAX_DEVNAME], temp_str[MAX_STRING_SIZE];
	char		*i;
	int		index;

	for (index = 0; index < num_devices; index++) {
		/* build up temp_filename */
		strcpy(temp_filename, logfile);

		/* case 1: if dti name exists, use it */
		if (strcmp(port[index].netdevice, "NONE") != 0) {
			/* IP has different "dti" name than NON-IP */
			if (port[index].netdevice[0] == 'i') {
				sscanf(port[index].devname, ":N_ipt%[^:]", temp_str); 
			} else {
				if (strstr(port[index].devname,"N_dum")){
					sscanf(port[index].devname, ":N_dum%[^:]", temp_str); 
				}else{
					sscanf(port[index].devname, ":N_dti%[^:]", temp_str); 
				}
			}
			strcat(temp_filename,  "_");
			strcat(temp_filename, temp_str);
		}
		/* case 2: if voice name exists, use it */
		else if (strcmp(port[index].voicedevice, "NONE") != 0) {
			i = (char *)strstr(port[index].voicedevice, "B");
			strcpy(temp_str, i);
			strcat(temp_filename,  "_");
			strcat(temp_filename, temp_str);
		} else {
			//printf("Missing both DTI and Voice resource in config file device name (%s)\n", port[index].devname);
			exitdemo(1);
		}		
		strcat(temp_filename, ".log");

		if ((port[index].log_fp = fopen(temp_filename, "w")) == NULL) {
			//printf("\nCannot open log file %s for write\n", temp_filename);
			perror("Reason is: ");
			exitdemo(1);
		}
		//printf("%s successfully opened\n", temp_filename); 
		
	} /* End of for loop */
	return 1;
}

/****************************************************************
*			NAME: inbound_application(struct channel *pline)
* DESCRIPTION: Place holder for your inbound application code in the connected state
*		  INPUT: pline - pointer to port data structure
*		RETURNS: NA
*	  CAUTIONS: none
****************************************************************/
static void inbound_application(struct channel *pline)
{
	/* Place holder - your app code goes here */
	int channum = pline->index;
	
	if (pline->chdev == 0){
		return;
	}

	pline->state = ST_INTRO;
	if (dx_clrdigbuf(pline->chdev) == -1) { 
		printandlog(pline->index, VOICE, NULL, "dx_clrdigbuf failed!\n", 0);
	}
	
	if ( play( channum, INTRO_VOX ) == -1 ) {
		sprintf( tmpbuff, "Error playing Introduction on channel %s", ATDV_NAMEP( pline->chdev ) );
		printandlog(pline->index, VOICE, NULL, tmpbuff, 0);
	}else{
		sprintf( tmpbuff, "Playing Introduction on channel %s", ATDV_NAMEP( pline->chdev ) );
		printandlog(pline->index, VOICE, NULL, tmpbuff, 0);
	}

}
/****************************************************************
*			NAME: outbound_application(struct channel *pline)
* DESCRIPTION: Place holder for your outbound application code in the connected state
*		  INPUT: pline - pointer to port data structure
*		RETURNS: NA
*	  CAUTIONS: none
****************************************************************/
static void outbound_application(struct channel *pline)
{

	// Place holder - your app code goes here
	int channum = pline->index;
	
	if (pline->chdev == 0){
		return;
	}

	pline->state = ST_PLAY;

	if (dx_clrdigbuf(pline->chdev) == -1) { 
		printandlog(pline->index, VOICE, NULL, "dx_clrdigbuf failed!\n", 0);
	}
	if ( play( channum, GOODBYE_VOX ) == -1 ) {
		sprintf( tmpbuff, "Error playing Goodbye on channel %s", ATDV_NAMEP( pline->chdev ) );
		printandlog(pline->index, VOICE, NULL, tmpbuff, 0);
	}


}

/****************************************************************
*			NAME: drop_outbound_calls_if_required(void)
* DESCRIPTION: This drops outbound side calls if required
*					For purposes of the demo, a call stays in the connected
*					state state for a second or two, then is dropped by the outbound side
*					Your application does not need this code
*					and hence it is not optimized
*		RETURNS: NA
*	  CAUTIONS: none
****************************************************************/
static void drop_outbound_calls_if_required(void)
{
	int					index;
	struct channel		*pline;
	time_t				current_time;								/* in seconds */
	char					str[MAX_STRING_SIZE];
	int					callindex;

	/* get the current time in seconds */
	time(&current_time);

	/* check all devices for an "expired" drop call time */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -