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

📄 gc_basic_call_model.c

📁 dialogic 板卡globalcall 测试代码
💻 C
📖 第 1 页 / 共 5 页
字号:
					}
					break;

				case GCEV_OFFERED:
					process_offered_event(metaeventp, pline);
					break;
	
				default:
					unexpected_event = 1;
					break;
			}
			break;
			/* end of case GCST_NULL */
		}

		case GCST_OFFERED:
		{
			if (evttype == GCEV_ACCEPT) {
				pline->call_state = GCST_ACCEPTED;
				/* Note: if both answercall and acceptcall use 0 rings  */
				/* then the outbound side may not get an alerting event */
				/* this behavior is technology/protocol dependent		  */
				if (gc_AnswerCall(pline->crn, 0, EV_ASYNC) != GC_SUCCESS) {
					sprintf(str, "gc_AnswerCall(crn=0x%lx, # of rings=0, mode=EV_ASYNC) Failed", pline->crn);
					printandlog(index, GC_APIERR, NULL, str);
					exitdemo(1);
				}
				sprintf(str, "gc_AnswerCall(crn=0x%lx, mode=EV_ASYNC) Success", pline->crn);
				printandlog(index, GC_APICALL, NULL, str);
			} else {
				unexpected_event = 1;
			}
			break;
		}

		case GCST_ACCEPTED:
		{
			if (evttype == GCEV_ANSWERED) {
				/* Do nothing but change the state to connected. The call will be cleared from
				outbound side. Just wait for Disconnect */
				/* Your application specific code will go here */
				pline->call_state = GCST_CONNECTED;

				/* Increment the total calls on this device */
				pline->numb_calls++;
				/* Increment the total inbound calls on all devices */
				in_calls++;
				inbound_application(pline);			/* YOUR APPLICATION CODE IS CALLED HERE */
			} else {
				unexpected_event = 1;
			}
			break;
		}

		case GCST_CONNECTED:
		{
			/*************************************************/
			/* Depending upon your application, you may or	 */
			/* may not have application specific event		 */
			/* handling here for when in the connected state */
			/* You could also have your app specific code	 */
			/* in process_event()									 */
			/*************************************************/
			unexpected_event = 1;						/* recall that GCEV_DISCONNECTED is handled elsewhere */
			break;
		}

		/*************************************/
		/* now come the call teardown states */
		/*************************************/
		case GCST_DISCONNECTED:
		{
			if (evttype == GCEV_DROPCALL) {
				pline->dropcall_active = NO;

				/* Call ReleaseCall */
				pline->call_state = GCST_IDLE;

				if (gc_ReleaseCallEx(pline->crn, EV_ASYNC) != GC_SUCCESS) {
					sprintf(str, "gc_ReleaseCallEx(crn=0x%lx, EV_ASYNC) Failed", pline->crn);
					printandlog(index, GC_APIERR, NULL, str);
					exitdemo(1);
				}
				sprintf(str, "gc_ReleaseCallEx(crn=0x%lx, EV_ASYNC) Success", pline->crn);
				printandlog(index, GC_APICALL, NULL, str);
				fflush(stdout);
			} else {
				unexpected_event = 1;
			}
			break;
		}

		case GCST_IDLE:
		{
			if (evttype == GCEV_RELEASECALL) {
				pline->call_state = GCST_NULL;
			} else {
				unexpected_event = 1;
			}
			break;
		}

		default:
		{
			/* Should never get here */
			printandlog(index, MISC, NULL, "Invalid state in process_inbound_event()"); 
			printandlog(index, STATE, NULL, " ");
			break;
		}
	}

	if (unexpected_event && (evttype != GCEV_UNBLOCKED)) {
		printandlog(index, GC_RESULT_INFO, metaeventp, "Event was unexpected in the current state");
		printandlog(index, STATE, NULL, " ");
	}
}

/****************************************************************
*			NAME: process_offered_event(struct channel *pline)
* DESCRIPTION: Function to process an offered event while in the NULL state
*		 INPUTS: pline - pointer to entry in port table
*		RETURNS: NA
*	  CAUTIONS: Assumes event logging already done
****************************************************************/
static void process_offered_event(METAEVENT *metaeventp, struct channel *pline)
{
	char		dnis[GC_ADDRSIZE];
	char		ani[GC_ADDRSIZE];
	char		_name[AN_MAXCALLIDNAME];
	char		str[MAX_STRING_SIZE];

	/* Save the CRN in port[index] and call Acceptcall */
	pline->call_state = GCST_OFFERED;
	pline->crn = metaeventp->crn;

	/* show some technology specific functionality */
	/* get DNIS, ANI if not ANALOG */
	if (pline->techtype != ANALOG) {
		/* first, get called party number */
		if (gc_GetDNIS(pline->crn, dnis) == GC_SUCCESS) {
			sprintf(str, "gc_GetDNIS(crn=0x%lx) Success - dnis = %s", pline->crn, dnis);
		} else {
			sprintf(str, "gc_GetDNIS(crn=0x%lx) Failure - dnis not available ", pline->crn);
		}
		printandlog(pline->index, GC_APICALL, NULL, str);
		/* do application specific dnis event processing here */
		/* For simplicity's sake, max DDI logic is not shown here */

		/* next get the ANI here */
		if (gc_GetANI(pline->crn, ani) == GC_SUCCESS) {
			sprintf(str, "gc_GetANI(crn=0x%lx) Success - ANI = %s", pline->crn, ani);
		} else {
			sprintf(str, "gc_GetANI(crn=0x%lx) Failure - ANI not available", pline->crn);
		}
		printandlog(pline->index, GC_APICALL, NULL, str);
	} else {
		/* ANI, call info if Analog */
		if (gc_GetANI(pline->crn, ani) == GC_SUCCESS) {
			/* get ANI */		
			sprintf(str, "gc_GetANI(crn=0x%lx) Success - ANI = %s", pline->crn, ani);
		} else {
			sprintf(str, "gc_GetANI(crn=0x%lx) Failure - ANI not available", pline->crn);
		}
		printandlog(pline->index, GC_APICALL, NULL, str);

		/* get the call info */
		if (gc_GetCallInfo(pline->crn, CALLNAME, caller_name) == GC_SUCCESS) {
			sprintf(str, "gc_GetCallInfo(crn=0x%lx, CALLNAME) Success, name = %s",
			pline->crn, caller_name);
		} else {
			sprintf(str, "gc_GetCallInfo(crn=0x%lx, CALLNAME) Failure, name not available",
					pline->crn);
		}
		printandlog(pline->index, GC_APICALL, NULL, str);
	}

	/* Note: if # of rings is == 0 then the outbound side */
	/* may not get the alerting event, depending upon the protocol */ 
	/* if the number of rings is 1, there is an occasional problem in */
	/* in the outbound side's ability to recognize the tone */
	if (gc_AcceptCall(pline->crn, 3, EV_ASYNC) != GC_SUCCESS) {
		sprintf(str, "gc_AcceptCall(crn=0x%lx, # of rings=3, mode=EV_ASYNC) Failed", pline->crn);
		printandlog(pline->index, GC_APIERR, NULL, str);
		exitdemo(1);
	}
	sprintf(str, "gc_AcceptCall(crn=0x%lx, mode=EV_ASYNC) Success", pline->crn);
	printandlog(pline->index, GC_APICALL, NULL, str);
}

/****************************************************************
*			NAME: process_outbound_event(struct channel *pline, METAEVENT *metaeventp)
* DESCRIPTION: Function to process outbound GlobalCall event
*		 INPUTS: pline - pointer to entry in port table
*					metaeventp - pointer to the metaevent structure
*		RETURNS: NA
*	  CAUTIONS: Tightly coupled with process_event() for pre-processing
*					Assumes event logging already done
*					Disconnected event already handled
****************************************************************/
static void process_outbound_event(struct channel *pline, METAEVENT *metaeventp)
{
	int		evttype, index, call_state;
	int		unexpected_event = 0;					/* till proven otherwise */
	char		str[MAX_STRING_SIZE];

	evttype = metaeventp->evttype;
	index = pline->index;
	call_state = pline->call_state;

	switch (call_state)
	{
		/************************************/
		/* first come the call setup states */
		/************************************/
		case GCST_NULL:
		{
			switch (evttype)
			{
				case GCEV_ALERTING:						/* just change the state to alerting - no other action is necessary */
					pline->call_state = GCST_ALERTING;
					break;

				case GCEV_RESETLINEDEV:
				case GCEV_UNBLOCKED:
					/* Make another call if possible */
					gc_demo_makecall(index); 
					break;

				/* This case can happen in some technologies/protocols if the inbound side */
				/* answered the call without ringing (i.e. if acceptcall was issued, */
				/* then the rings parameter in both acceptcall and anwercall was 0 */
				/* if only answercall was issued, then the # of rings was 0 */
				/* The internal GC call state should be Dialing, but the dialing event */
				/* is disabled by default and we did not enable it */
				case GCEV_CONNECTED:
					process_connected_event(pline);
					break;

				default:
					unexpected_event = 1;
					break;
			}
			break;
		}

		case GCST_ALERTING:
		{
			if (evttype == GCEV_CONNECTED) {
				process_connected_event(pline);
			} else {
				unexpected_event = 1;
			}
			break;
		}

		/*************************************/
		/* now come the call teardown states */
		/*************************************/
		case GCST_CONNECTED:
		{
			/*************************************************/
			/* Depending upon your application, you may or	 */
			/* may not have application specific event		 */
			/* handling here for when in the connected state */
			/* You could also have your app specific code	 */
			/* in process_event()									 */
			/*************************************************/
			if (evttype != GCEV_DROPCALL) {			/* recall the outbound side issues a gc_DropCall() */
				unexpected_event = 1;					/* for the purposes of this demo */
				break;
			}
			/* FALL THROUGH ON PURPOSE since this is one of the 2 ways of reaching Idle */
			/* the other being a disconnected event */
		}

		case GCST_DISCONNECTED:
		{
			if (evttype == GCEV_DROPCALL) {
				pline->dropcall_active = NO;

				/* Call ReleaseCall */
				pline->call_state = GCST_IDLE;

				if (gc_ReleaseCallEx(pline->crn, EV_ASYNC) != GC_SUCCESS) {
					sprintf(str, "gc_ReleaseCallEx(crn=0x%lx, EV_ASYNC) Failed", pline->crn);
					printandlog(index, GC_APIERR, NULL, str);
					exitdemo(1);
				}
				sprintf(str, "gc_ReleaseCallEx(crn=0x%lx, EV_ASYNC) Success", pline->crn);
				printandlog(index, GC_APICALL, NULL, str);
				fflush(stdout);
				break;
			} else {
				unexpected_event = 1;
			}
			break;
		}

		case GCST_IDLE:
		{
			if (evttype == GCEV_RELEASECALL) {
				pline->call_state = GCST_NULL;
				pline->makecall_active = NO;					/* makecall is no longer active */
				gc_demo_makecall(index); 
			} else {
				unexpected_event = 1;
			}
			break;
		}

		default:
		{
			/* Should never get here */
			printandlog(index, MISC, NULL, "Invalid state in process_outbound_event()"); 
			break;
		}
	}

	if (unexpected_event && (evttype != GCEV_UNBLOCKED)) {
		printandlog(index, GC_RESULT_INFO, metaeventp, "Event was unexpected in the current state");
		printandlog(index, EVENT, NULL, GCEV_MSG(evttype));
		printandlog(index, STATE, NULL, " ");
	}
}

/****************************************************************
*			NAME: process_connected_event(struct channel *pline)
* DESCRIPTION: Function to process a connected event
*		 INPUTS: pline - pointer to entry in port table
*		RETURNS: NA
*	  CAUTIONS: Assumes event logging already done
*					Recall that this is only done for the outbound side
*					as the GCEV_CONNECTED event is an outbound side event only
****************************************************************/
static void process_connected_event(struct channel *pline)
{
	char		str[MAX_STRING_SIZE];
	char		value;										/* for connect type */
	int		rc;

	/* print connect type */
	rc = gc_GetCallInfo(pline->crn, CONNECT_TYPE, &value);
	if (rc != GC_SUCCESS) {
		if (rc == EGC_UNSUPPORTED) {
			strcpy(str, "call connected - gc_GetCallInfo(CONNECT_TYPE) not supported");
		} else {
			strcpy(str, "call connected - gc_GetCallInfo(CONNECT_TYPE) error\n");
			sprintf(str, "gc_GetCallInfo(crn=0x%lx, CONNECT_TYPE, &value) failed", pline->crn);
			printandlog(pline->index, GC_APIERR, NULL, str);
		}

⌨️ 快捷键说明

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