📄 megacomgc.c
字号:
/********************************************************************************/
/* One of the terminations ends the call, so we have to bring down both */
/* terminations in state 4 */
/********************************************************************************/
int applOnHookDiscInd4(void)
{
RvMegacoSubtractCommand subtractCommand1, subtractCommand2;
int tempInd;
static int numTerm = 0;
sprintf(dispBuf, "In applOnHookDiscInd4(), termInd %d", termInd);
rvLogInfo3(&rvLog, dispBuf);
applInfo[termInd].actionOutPtr = /* Set up the action */
rvAllocAllocate(&rvDefaultAlloc,
(sizeof(RvMegacoSubtractCommand))*2);
rvMegacoActionConstruct(applInfo[termInd].actionOutPtr,
&applInfo[termInd].contextId);
rvMegacoSubtractCommandConstruct(&subtractCommand1,
&applInfo[termInd].terminationId);
rvMegacoSubtractCommandConstruct(&subtractCommand2,
&applInfo[termInd].rtpTerminationId);
rvMegacoActionAddCommand(applInfo[termInd].actionOutPtr, &subtractCommand1);
rvMegacoActionAddCommand(applInfo[termInd].actionOutPtr, &subtractCommand2);
sendRequest(SEND_ACTION);
numTerm++;
applInfo[termInd].nextEvent = E_OFF_HOOK_LISTEN_REQ;
rvMegacoSubtractCommandDestruct(&subtractCommand1);
rvMegacoSubtractCommandDestruct(&subtractCommand2);
rvMegacoActionDestruct(applInfo[termInd].actionOutPtr);
rvAllocDeallocate(&rvDefaultAlloc,
(sizeof(RvMegacoSubtractCommand))*2,
applInfo[termInd].actionOutPtr);
applInfo[termInd].actionOutPtr = NULL;
applInfo[termInd].callInProgress = rvFalse;
rvMegacoContextIdDestruct(&applInfo[termInd].contextId);
applInfo[termInd].requestId = 0;
if (applInfo[applInfo[termInd].remoteTermInd].inService == rvFalse)
{
numTerm = 0;
return NO_EVENT; /* If remote is out for this time*/
}
if (numTerm == 1) /* Check if 2nd term. -disconnect*/
/* responder - needs to be */
{ /* subtracted here - the phone */
numTerm = 0; /* never went off hook on a ring */
if (applInfo[termInd].remoteTermInd != -1) /* If in use */
{
tempInd = termInd; /* Save current */
termInd = applInfo[termInd].remoteTermInd;
applInfo[tempInd].remoteTermInd = -1; /* Local is taken care of */
applInfo[tempInd].connectInitiatorInd = -1;
applInfo[termInd].remoteTermInd = -1; /* Remote is taken care of */
/* If connection requester */
if (applInfo[termInd].connectInitiatorInd == termInd)
{
applInfo[termInd].connectInitiatorInd = -1;
}
else
if (applInfo[termInd].markedAction != A_STOP_RING_SIGNAL_REQ)
return E_ON_HOOK_DISC_IND;
else
{
return NO_EVENT;
}
}
}
numTerm = 0;
return NO_EVENT;
}
/********************************************************************************/
/* We come here in state 2 when the notification is delivered from MG that the */
/* telephone went off_hook. Now prepare this phone to collect digits according */
/* to requested dial plan and also be ready for on_hook event */
/* It's possible to use a function call */
/* rvMegacoTransactionConstructParse(RvMegacoTransaction *x, */
/* const char *text, */
/* RvParseError *error) */
/* */
/* and a prefabricated "canned" message text instead of constructing this */
/* command from separate elements. */
/* The text for the applOnHookListenReq() command will be as follows: */
/* */
/* "T=3{C=-{MF=terma{\n \ */
/* E=1{al/on,dd/ce{DigitMap=dialplan0}},SG{cg/dt},\n \ */
/* DM=dialplan0{xxxxxxx}}}}\n" */
/* */
/********************************************************************************/
int applOnHookListenReq(void)
{
RvMegacoEventsDescriptor eventsDescriptor;
RvMegacoRequestedEvent requestedEvent1, requestedEvent2;
RvMegacoPackageItem packageItem1, packageItem2, packageItem3;
RvMegacoSignalsDescriptor signalsDescriptor;
RvMegacoSignal signal;
RvMegacoDigitMap digitMap;
RvMegacoDigitMapDescriptor digitMapDescriptor;
RvMegacoDigitString digitString;
RvMegacoDigitPosition digitPosition1;
RvMegacoParameterValue paramValue2;
sprintf(dispBuf, "In applOnHookListenReq(), termInd %d", termInd);
rvLogInfo3(&rvLog, dispBuf);
applInfo[termInd].modifyCommandPtr =
rvAllocAllocate(&rvDefaultAlloc,
sizeof(RvMegacoModifyCommand));
rvMegacoModifyCommandConstruct(applInfo[termInd].modifyCommandPtr,
&applInfo[termInd].terminationId);
/* Create new streamDescriptor */
/* with the same streamId */
rvMegacoPackageItemConstruct(&packageItem1,/* Construct PackageItem we need*/
"al", /* Analog Line Supervisory Package*/
"on"); /* On_hook eventId */
rvMegacoPackageItemConstruct(&packageItem2,/* Construct PackageItem we need*/
"dd", /* DTMF detection package */
"ce"); /* DigitMap completion event */
/* Construct requestedEvent with */
/* our packageItem */
rvMegacoRequestedEventConstruct(&requestedEvent1, &packageItem1);
rvMegacoRequestedEventConstruct(&requestedEvent2, &packageItem2);
rvMegacoParameterValueConstruct(¶mValue2, "dialplan0");
rvMegacoRequestedEventSetParameter(&requestedEvent2,
"DigitMap",
¶mValue2);
/* Create new EventsDescriptor */
/* with the next requestId. It may*/
/* contain multiple events */
applInfo[termInd].requestId = 1;
rvMegacoEventsDescriptorConstruct(&eventsDescriptor, applInfo[termInd].requestId);
/* Add requestedEvent */
rvMegacoEventsDescriptorAddEvent(&eventsDescriptor, &requestedEvent1);
rvMegacoEventsDescriptorAddEvent(&eventsDescriptor, &requestedEvent2);
/* Add Events into command */
rvMegacoModifyCommandSetEvents(applInfo[termInd].modifyCommandPtr,
&eventsDescriptor);
/* Set up signals */
rvMegacoPackageItemConstruct(&packageItem3,/* Construct PackageItem we need*/
"cg", /* Call progress tones package */
"dt"); /* Dial tone signal */
rvMegacoSignalConstruct(&signal, &packageItem3);
rvMegacoSignalsDescriptorConstruct(&signalsDescriptor);
rvMegacoSignalsDescriptorAddSignal(&signalsDescriptor, &signal);
/* Add Signals into command */
rvMegacoModifyCommandSetSignals(applInfo[termInd].modifyCommandPtr,
&signalsDescriptor);
rvMegacoDigitMapConstruct(&digitMap); /* Set up digitMap */
rvMegacoDigitStringConstruct(&digitString);
rvMegacoDigitPositionConstruct(&digitPosition1);
rvMegacoDigitPositionAddEvents(&digitPosition1, (char) '0', (char) '9');
rvMegacoDigitStringAddElement(&digitString, &digitPosition1);
rvMegacoDigitStringAddElement(&digitString, &digitPosition1);
rvMegacoDigitStringAddElement(&digitString, &digitPosition1);
rvMegacoDigitStringAddElement(&digitString, &digitPosition1);
rvMegacoDigitStringAddElement(&digitString, &digitPosition1);
rvMegacoDigitStringAddElement(&digitString, &digitPosition1);
rvMegacoDigitStringAddElement(&digitString, &digitPosition1);
rvMegacoDigitMapAddPattern(&digitMap, &digitString);
rvMegacoDigitMapDescriptorConstruct(&digitMapDescriptor, "dialplan0", &digitMap);
/* Add Digit map into command */
rvMegacoModifyCommandSetDigitMap(applInfo[termInd].modifyCommandPtr,
&digitMapDescriptor);
rvMegacoContextIdDestruct(&applInfo[termInd].contextId);
/* Construct "- " */
rvMegacoContextIdConstructSpecial(&applInfo[termInd].contextId,
RV_MEGACOCONTEXTID_NULL);
applInfo[termInd].commandType = RV_MEGACOCOMMANDTYPE_MODIFY;
sendRequest(SEND_COMMAND);
/* Event to perform next if this */
/* request is confirmed */
applInfo[termInd].nextEvent = NO_EVENT; /* Sit idle and ready */
rvMegacoPackageItemDestruct(&packageItem1);
rvMegacoPackageItemDestruct(&packageItem2);
rvMegacoPackageItemDestruct(&packageItem3);
rvMegacoParameterValueDestruct(¶mValue2);
rvMegacoRequestedEventDestruct(&requestedEvent1);
rvMegacoRequestedEventDestruct(&requestedEvent2);
rvMegacoSignalDestruct(&signal);
rvMegacoDigitPositionDestruct(&digitPosition1);
rvMegacoDigitStringDestruct(&digitString);
rvMegacoDigitMapDestruct(&digitMap);
rvMegacoDigitMapDescriptorDestruct(&digitMapDescriptor);
rvMegacoSignalsDescriptorDestruct(&signalsDescriptor);
rvMegacoEventsDescriptorDestruct(&eventsDescriptor);
return NO_EVENT;
}
/********************************************************************************/
/* We know that MG received our command before timer expired, */
/* so go and do what was intended */
/********************************************************************************/
int applReceiveReply(void)
{
int event;
const RvMegacoMediaDescriptor *mediaDescr;
const RvMegacoStreamDescriptor *streamDescr;
const RvMegacoErrorDescriptor *errorDescr;
size_t size;
const char *ptr;
rvLogInfo3(&rvLog, "In applReceiveReply()");
errorDescr = rvMegacoCommandReplyGetError(applInfo[termInd].commandReplyInPtr);
if (rvMegacoErrorDescriptorIsSet(errorDescr))
{
ptr = rvMegacoErrorDescriptorGetDescription(errorDescr);
applInfo[termInd].error = rvMegacoErrorDescriptorGetCode(errorDescr);
sprintf(dispBuf, "Error: %d - %s in reply to termination %s, termInd %d",
applInfo[termInd].error,
ptr, applInfo[termInd].terminationId.name, termInd);
rvLogInfo3(&rvLog, dispBuf);
if (applInfo[termInd].error == RV_MEGACOERROR_UNKNWN_TERMID)
{
applInfo[termInd].inService = rvFalse;
applInfo[termInd].error = 0;
return NO_EVENT;
}
return E_ERROR_MSG_RESP;
}
switch (applInfo[termInd].commandType)
{
case RV_MEGACOCOMMANDTYPE_MODIFY:
mediaDescr =
rvMegacoCommandReplyGetMedia(applInfo[termInd].commandReplyInPtr);
/* Check if there are streams */
size = rvMegacoMediaDescriptorGetNumStreams(mediaDescr);
if (size != 0)
{ /* We expect 1 stream at most */
streamDescr = rvMegacoMediaDescriptorGetStream(mediaDescr, size-1);
size = rvMegacoStreamDescriptorGetNumLocalDescriptors(streamDescr);
if (size != 0)
{ /* We expect 1 LocalDescr at most */
applInfo[termInd].sdpMsgPtr =
rvMegacoStreamDescriptorGetLocalDescriptor(streamDescr,
size-1);
}
}
break;
case RV_MEGACOCOMMANDTYPE_ADD:
break;
case RV_MEGACOCOMMANDTYPE_SUBTRACT:
break;
default:
rvLogInfo3(&rvLog, "Command reply type is not implemented");
exit(1);
}
if (applInfo[termInd].nextEvent)
{
event = applInfo[termInd].nextEvent;
applInfo[termInd].nextEvent = NO_E
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -