?? gc_basic_call_model.c
字號:
/***************************************************************************
* 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()
*
* %created_by: parikhn %
* %date_created: Fri Jun 29 17:32:48 2001 %
*
***************************************************************************/
/**********************************************************************
* Copyright (c) 2001 Dialogic Corporation.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Dialogic Corporation.
* The copyright notice above does not evidence any actual or
* intended publication of such source code
**********************************************************************/
#ifndef lint
static char *_csrc = "@(#) %filespec: gc_basic_call_model.c-11 % (%full_filespec: gc_basic_call_model.c-11: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>
/* Dialogic Header Files */
#include <gclib.h>
#include <anapi.h>
#include <gcisdn.h>
#include <srllib.h>
/* Macro Definitions */
#define MAXCHAN 60 /* Maximum number of channels that can be opened - 2 E1 spans */
#define MAX_DEVNAME 64 /* Maximum length of device name */
#define MAX_STRING_SIZE 1000 /* Maximum length of string that to write on log file */
/* Keep large */
/* 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 GC_RESULT_INFO 5 /* want GC result information */
#define MISC 6 /* None of the above */
#define MISC_WITH_NL 7 /* 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 /* Value for the user interrupted flag */
#define NO 0 /* Value for the user interrupted flag */
/* code assumes this value is 0 */
#define ALL_DEVICES -1 /* This value is used to write the miscellaneous */
/* statements into all log files */
/*
* Technology Types
*/
#define E1ORT1 1
#define ISDN 2
#define ANALOG 3
#define SS7 4
/* 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 */
/* Data structure which stores all information for each line device */
static struct channel {
LINEDEV ldev; /* GlobalCall line device handle */
CRN crn; /* GlobalCall call handle */
int index; /* Device index as loaded from cfg file */
int direction; /* Inbound (WaitCall will be issued)
or outbound (MakeCall will be issued) */
int call_state; /* state of first layer state machine */
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[MAXPHONENUM]; /* Phone */
int numb_calls; /* The No of calls on the device */
int waitcall_active; /* Flag for waitcall function for issuing only once*/
int dropcall_active; /* Flag for simultaneous disconnect check */
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 */
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, ISDN, ANALOG, */
/* this variable is in so know when to drop a call */
time_t dropcall_time; /* time to drop the call on the outbound side */
} port[MAXCHAN];
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 printandlog(int index, int log_type, /* Prints and logs */
METAEVENT *metavent, char *msg_str);
static void gc_demo_makecall(int index); /* Function for gc_MakeCall() */
static void exitdemo(int exitlevel); /* Exit routine */
static void intr_hdlr(void); /* For handling user interrupted signals */
static void set_calling_num(struct channel *pline, char *phone_num);
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 ANAPI */
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 process_event(void); /* Function handles the GlobalCall Events */
static void process_connected_event(struct channel *pline);
static void process_disconnected_event(struct channel *pline);
static void process_offered_event(METAEVENT *metaeventp, struct channel *pline);
static void process_inbound_event(struct channel *pline, METAEVENT *metaeventp); /* Function handles the GlobalCall Events for inbound */
static void process_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); /* 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);
/********************************************************************************
* 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(void)
{
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();
/* Function to open all the logfiles */
open_all_logfiles();
if (num_devices == 0) {
printf("No devices enabled - please modify gc_basic_call_model.cfg to enable desired technology\n");
exitdemo(1);
}
printandlog(ALL_DEVICES, MISC, NULL, "********** GC DEMO - BASIC CALL MODEL ***********\n");
/* Start GlobalCall */
if (gc_Start(NULL) != GC_SUCCESS) {
sprintf(str, "gc_Start(startp = NULL) Failed");
printandlog(ALL_DEVICES, GC_APIERR, NULL, str);
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);
/* 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);
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);
/* 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 (interrupted == YES) { /* flag set in intr_hdlr() */
exitdemo(1);
}
if (ret != -1) { /* i.e. not timeout */
process_event();
}
drop_outbound_calls_if_required(); /* an artifact of the demo program */
/* where the outbound side disconnects 1-2 */
/* seconds after connected */
}
} /* 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");
exitdemo(1);
}
printandlog(ALL_DEVICES, MISC, NULL, "SRL Model Set to SR_STASYNC | SR_POLLMODE");
#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 ");
exitdemo(1);
}
printandlog(ALL_DEVICES, MISC, NULL, "SRL mode ID set to SR_POLLMODE");
#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
****************************************************************/
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) {
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");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -