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

📄 gc_basic_call_model.c

📁 dialogic gcwithvoice
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************
* C Source:	     gc_basic_call_model.c
* Description:   This is a demonstration program for a basic call model which performs,
*					  Basic make call and DropCall from Outbound end.It also shows the case 
*					  of simultaneous disconnect.
*					  which executes the program continuously until it encounters signal ctrl+c.
* General Notes: 1. The tab setting used for this file is 3. 
*					  2. Pagination is done with Courier New, 10 point, 64 lines per page
*					  3. For purposes of the demo, the outbound side waits 
*						  1-2 seconds in the connected state, then calls gc_DropCall()
*					  4. PDK as shipped has an issue where occasionally the first makecall may
*						  fail with an invalid state error. The demo program has a recovery
*						  mechanism built in. When connected to a switch, this should not be 
*						  a problem.
*					  5. gc_demo_open_isdn_channel may need to be modified for your environment,
*						  especially if you are using T1.

*
*	%created_by:	fiedorom %
*	%date_created: Tue May 25 11:21:03 2004 %
*
***************************************************************************/
/**********************************************************************
*  Copyright (C) 2000-2002 Intel Corporation.
*  All Rights Reserved
*
*  All names, products, and services mentioned herein are the 
*  trademarks or registered trademarks of their respective 
*  organizations and are the sole property of their respective owners.
**********************************************************************/

#ifndef lint
static char *_csrc = "@(#) %filespec: gc_basic_call_model.c-28 %  (%full_filespec: gc_basic_call_model.c-28:csrc:gc#1 %)";
#endif

/* OS Header Files */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <sys/timeb.h>
#include <fcntl.h>
#include <errno.h>

/**
  Intel Header Files
 **/
#include <srllib.h>
#include <dxxxlib.h>
#include <dtilib.h>


/* OS Socket API Headers */
#ifdef _WIN32
//#include <winsock2.h>
#else
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#endif

/* Dialogic Header Files */
#include <gcip.h>
#include <gclib.h>
#include <gcisdn.h>



/*
 * Vox Files to Open
 */
#define INTRO_VOX	"INTRO.VOX"
#define INVALID_VOX	"INVALID.VOX"
#define GOODBYE_VOX	"GOODBYE.VOX"
#define BLANK_VOX	"BLANK.VOX"

/*
 * Definition of states
 */
#define ST_WTRING	1	/* Waiting for an Incoming Call    */
#define ST_OFFHOOK	2	/* Going Off Hook to Accept Call   */
#define ST_INTRO	3	/* Play the intro.vox File         */
#define ST_GETDIGIT	4	/* Get DTMF Digits (Access Code)   */
#define ST_PLAY		5	/* Play the Caller's Message File  */
#define ST_RECORD	6	/* Recording Message from Caller   */
#define ST_INVALID	7	/* Play invalid.vox (Invalid Code) */
#define ST_GOODBYE	8	/* Play goodbye.vox                */
#define ST_ONHOOK	9	/* Go On Hook                      */
#define ST_ERROR	10	/* An Error has been Encountered   */
#define ST_DIAL	11	/* An Error has been Encountered   */
int introfd;
int invalidfd;
int goodbyefd;
int blankfd;

#ifdef _WIN32
#define QUIT( n )	/*endwin();*/	\
			exit( (n) )
#else
#define QUIT( n )	exit( (n) )
#endif

int fileopen(char *filename, int flags)
{
#ifdef _WIN32
	return dx_fileopen(filename, flags|O_BINARY, 0666);
#else
	return open(filename, flags, 0666);
#endif
}

int fileclose(int fhandle)
{
#ifdef _WIN32
	return dx_fileclose(fhandle);
#else
	return close(fhandle);
#endif
}



/* Macro Definitions */

char	tmpbuff[ 256 ];		/* Temporary Buffer */

#define MAXCHAN			480		/* Maximum number of channels that can be opened - 2 E1 spans	*/
#define MAX_DEVNAME		64		/* Maximum length of device name											*/
#define MAX_CODECNAME	20		/* Maximum length of codec name											*/
#define MAX_STRING_SIZE 1000	/* Maximum length of string that to write on log file			*/
								/* Keep large																	*/
#define MAX_CALLS			2	/* Maximum number of calls per channel */
#define MIN_CONNECTED_TIME	30	/* Minimum connected time, artifact of test program				*/
								/* and most likely will not be needed for a production program */

#define	MIN_MAKECALL_RETRY_TIME	5	/* min time to wait before retrying makecall under		*/
									/* error conditions															*/
#define MAXCODECS			10	/* Maximum number of codecs per VoIP channel */
#define MAX_VADSTR		10		/* Maximum length of VAD string, e.g. "ON", "OFF", "N/A" */


/* Logging defines */

#define NON_GC_APIERR		0	/* Had error on non-GC API function										*/
#define EVENT				1	/* An event																		*/
#define GC_APICALL			2	/* GC API funtion call														*/
#define GC_APIERR			3	/* Had error on GC API function											*/
#define STATE				4	/* STATE message																*/
#define VOICE				5	/* VOICE message																*/
#define GC_RESULT_INFO		6	/* want GC result information												*/
#define MISC				7	/* None of the above															*/
#define MISC_WITH_NL		8	/* None of the above with new line codes								*/

/* Inbound or Outbound Direction of device */

#define DIR_IN				1
#define DIR_OUT			2

/* Miscellaneous declarations */

#define YES					1
#define NO					0

#define ALL_DEVICES	  -1		/* This value is used to write the */
										/* miscellaneous statements into all log files */ 
#define OUT_OF_RANGE	  -1		/* callindex is out of range */

/*
 * Technology Types
 */
#define E1ORT1_CAS		1
#define ISDN				2							/* includes both E1 and T1 ISDN */
#define ANALOG				3
#define SS7					4
#define H323				5
#define SIP					6

/* Global variables */
static char		logfile[] = "gc_basic_call_model";		/* log filename without the .log	 */
static char		cfgfile[] = "gc_basic_call_model.cfg"; /* config filename */

static int		num_devices;		/* Number of devices loaded from cfg file */
static int		interrupted = NO;	/* Flag for user interrupted signals		 */
static int		reset_linedevs_left_to_complete = 0; 

/* Data structure which stores call information for each line device */
typedef struct {
	CRN					crn;							/* GlobalCall call handle */
	int					call_state;					/* state of first layer state machine */
	int					dropcall_active;			/* Flag for simultaneous disconnect check	*/
} CALL;

/* TX and RX codecs for each line device although only used for H.323 or SIP */
typedef struct {
	char					txcodec[MAX_CODECNAME];	/* TX codec type (H.323 or SIP only)					*/
	int					txrate;						/* TX codec rate (H.323 or SIP only)					*/
	char					txVAD[MAX_VADSTR];		/* TX VAD enabled/disabled (H.323 or SIP only)		*/
	char					rxcodec[MAX_CODECNAME];	/* RX codec type (H.323 or SIP only)					*/
	int					rxrate;						/* RX codec rate (H.323 or SIP only)					*/
	char					rxVAD[MAX_VADSTR];		/* RX VAD enabled/disabled (H.323 or SIP only)		*/
} CODEC;

/* Data structure which stores all information for each line device */
static struct channel {
	LINEDEV				ldev;							/* GlobalCall line device handle							*/
	LINEDEV				mediah;						/* Media handle - only for H323                    */
	CALL				call[MAX_CALLS];
	int					index;						/* Device index as loaded from cfg file				*/
	int					direction;					/* Inbound(WaitCall will be issued)
																or outbound(MakeCall will be issued)				*/
	int					blocked;						/* YES or NO													*/
	char				netdevice[MAX_DEVNAME]; /* Network device name										*/
	char				protname[MAX_DEVNAME];	/* Protocol name												*/
	char				voicedevice[MAX_DEVNAME]; /* Voice device name										*/ 
	char				devname[MAX_DEVNAME];	/* Argument to gc_OpenEx() function						*/
	char				destination_num[60]; /* Phone													*/
	int					num_codecs;					/* The No. of codecs specified (VoIP device only) 	*/
	CODEC					codec[MAXCODECS];			/* Codecs (VoIP device only)								*/
	int					numb_calls;					/* The No of calls on the device							*/
	int					waitcall_active;			/* Flag for waitcall function for issuing only once*/
	int					makecall_active;
	int					resetlinedev_active;		/* Necessary since must ignore call related GC		*/
															/* events with gc_ResetLineDev() active				*/
	int					resetlinedev_required_after_unblocked; /* for ISDN									*/
															/* and some error conditions								*/
													
	int					makecall_timeout;			/* necessary since not all technologies support		*/
															/* async makecall timeout and they might be			*/
															/* different for different technologies				*/
	GC_MAKECALL_BLK		makecallblk;				/* Variable for MAKECALL block							*/
	FILE					*log_fp;						/* logfile Pointer											*/
	int					techtype;					/* technology type: E1ORT1_CAS, ISDN, ANALOG,		*/

	time_t				makecall_time;				/* time before which makecall is not allowed       */
															/* this is to add robustness to the app				*/
															/* if makecall fails which it might under some		*/
															/* circumstances, but will work if try later			*/
															/* if this value is 0, then OK to do now           */

	/* this variable is in so know when to drop a call */
	/* it is an artifact of the demo program and 	   */
	/* and should not be used in production level 		*/
	/* programs														*/
	time_t				dropcall_time;				/* time to drop the call on the outbound side      */
															/* format is result of time() function call        */
															/* 0 <=> no dropcall required                      */
	time_t				intercall_time;			/* Time when the call was released. The next call  */
                                             /* would be made after intercall_time +            */
                                             /* intercall_delay seconds.                        */
   int               intercall_delay;        /* Inter-call delay in milliseconds                */
   int	    chdev;			/* Channel Device Descriptor    */
   int	    tsdev;			/* Timeslot Device Descriptor   */
   int	    state;			/* State of Channel             */
   int	    msg_fd;			/* File Desc for Message Files  */
   DV_DIGIT digbuf;			/* Buffer for DTMF Digits       */
   DX_IOTT  iott[ 1 ];			/* I/O Transfer Table		*/
   char	    msg_name[ MAX_DEVNAME+1 ];	/* Message Filename             */
} port[MAXCHAN];

/* codec translation table */
typedef struct {
	char*			codecname;
	int			codecvalue;
	int			isVADsupported;
} CODECXLAT;

static const CODECXLAT codecxlat[] = {
	{"G.711Alaw",	GCCAP_AUDIO_g711Alaw64k,			NO},
	{"G.711ulaw",	GCCAP_AUDIO_g711Ulaw64k,			NO},
	{"G.723_5.3k",	GCCAP_AUDIO_g7231_5_3k,				YES},
	{"G.723_6.3k",	GCCAP_AUDIO_g7231_6_3k,				YES},
	{"G.726_16k",	GCCAP_AUDIO_g726_16k,				YES},
	{"G.726_24k",	GCCAP_AUDIO_g726_24k,				YES},
	{"G.726_32k",	GCCAP_AUDIO_g726_32k,				YES},
	{"G.726_40k",	GCCAP_AUDIO_g726_40k,				YES},
	{"G.729",		GCCAP_AUDIO_g729		,				NO},
	{"G.729A",		GCCAP_AUDIO_g729AnnexA,				NO},
	{"G.729B",		GCCAP_AUDIO_g729wAnnexB,			YES},
	{"G.729AB",		GCCAP_AUDIO_g729AnnexAwAnnexB,	YES},
	{"GSM_FULL",	GCCAP_AUDIO_gsmFullRate,			YES},
	{"T.38UDP",		GCCAP_DATA_t38UDPFax,				NO},
	{"DONT_CARE",	GCCAP_dontCare,						NO}
};

static int		in_calls, out_calls;					/* Counters for Inbound calls and Outbound calls	*/
static int		gc_started = NO;						/* Flag is set if gc_Start() is Success				*/
time_t			start_time;								/* To note down the start time for the test			*/

/* Function prototype(s) */

static void		init_srl_mode(void);							/* inits SRL mode */
static void		load_config_file(void);						/* Loads Configuration File									*/
static void		drop_outbound_calls_if_required(void); /* used by demo to make repeated calls */
static void		make_calls_if_required(void);				/* used by demo to handle makecall error conditions 	*/
static void		printandlog(int index, int log_type,	/* Prints and logs												*/ 
								METAEVENT *metavent, char *msg_str, int callindex);
static void		gc_demo_makecall(int index);				/* Function for gc_MakeCall()									*/ 
static void		exitdemo(int exitlevel);					/* Exit routine													*/
static void		initiate_exit(void);
static void		intr_hdlr(void);								/* For handling user interrupted signals					*/
static void		set_calling_num(struct channel *pline, char *phone_num);
static void		enable_alarm_notification(struct channel *pline);/* enable alarm notification                */
static void		gc_demo_open_isdn_channel(int index);	/* Technology specific initialization for ISDN			*/
static void		gc_demo_open_E1orT1_channel(int index);/* Technology specific initialization for PDK			*/ 
static void		gc_demo_open_ss7_channel(int index);	/* Technology specific initialization for SS7			*/
static void		gc_demo_open_analog_channel(int index);/* Technology specific initialization for Analog		*/
static void		gc_demo_open_H323_channel(int index);	/* Technology specific initialization for H323  		*/
static void		gc_demo_open_SIP_channel(int index);	/* Technology specific initialization for SIP   		*/
static void		gc_set_channel_codecs(int index);		/* VoIP specific initialization of codecs					*/
static void		open_all_devices(void);						/* Function invokes Technology specific initilization 
																			functions to open all devices								*/
static void		open_device(int index);						/* Function invokes Technology specific initilization 
																			functions to open specific device						*/
static void		inbound_application(struct channel *pline); /* PLACE HOLDER FOR YOUR APPLICATION CODE			*/
static void		outbound_application(struct channel *pline); /* PLACE HOLDER FOR YOUR APPLICATION CODE			*/
static void		print_alarm_info(METAEVENTP metaeventp, struct channel *pline);
static void		process_event(void);							/* Function handles the GlobalCall Events					*/
static void		process_connected_event(struct channel *pline, METAEVENT *metaeventp);
static void		process_disconnected_event(struct channel *pline, METAEVENT *metaeventp);
static void		process_offered_event(METAEVENT *metaeventp, struct channel *pline);
static void		process_call_related_inbound_event(struct channel *pline, METAEVENT *metaeventp); /* Function handles the GlobalCall Events for inbound */
static void		process_call_related_outbound_event(struct channel *pline, METAEVENT *metaeventp); /* Function handles the GlobalCall Events for outbound */
static int		open_all_logfiles(void);					/* Function to open the logfiles								*/
static void		append_call_state_name(char *buffer, int index, int callindex);	/* append call state name to buffer	*/
static void		format_error_info(char *dest_buffer);		/* formats error information									*/
static void		format_result_info(int index, METAEVENT *metaeventp, /* formats event result information									*/
											char *dest_buffer);
static int		existCRN(CRN crn, struct channel *pline);	/* Retrieve CRN if available */
static int		process_voice_event(int channum);
int				routevoice(int index);

void printError(char *devname, char *messages)
{
	struct tm			*Time;
	time_t				Timet;
	char					TimeStr[MAX_STRING_SIZE];			/* will hold the time string when built */
	FILE *fp = fopen ("Error.log", "a+");

⌨️ 快捷键说明

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