📄 rvmegacoterm.c
字号:
/* Get the termination mutex */
rvMutexLock(&x->mutex);
}
void rvMegacoTermProcessCommandEnd(RvMegacoTerm * x) {
/* Reset the blocked event flag and process any
accumulated event */
rvMutexLock(&x->blockedEventMutex);
x->blockedEventState = rvFalse;
/* Use a timer so the reply to the command can go out before the
notify */
if(!rvListEmpty(&x->blockedEventBuffer) )
rvTimerReset(&x->blockedEventTimer,RV_MEGACOTERM_EVENTTIME);
rvMutexUnlock(&x->blockedEventMutex);
/* Release the termination mutex */
rvMutexUnlock(&x->mutex);
}
/*--------------------------------------------------------------------------------*/
/* Default state functions */
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/* Restore default state */
/*--------------------------------------------------------------------------------*/
static void setTermDefaultState(RvMegacoTerm* x) {
rvMegacoMediaDescriptorSetTerminationState(&x->mediaDescr,&x->defaultState.termState);
rvMegacoEventsDescriptorCopy(&x->eventsDescr,&x->defaultState.eventsDescr);
rvMegacoEventBufferDescriptorCopy(&x->eventBufferDescr,&x->defaultState.eventBufferDescr);
/* Process the default digitmap */
rvMegacoTermProcessDigitMap(x,&x->defaultState.digitMap,NULL);
}
void rvMegacoTermSetDefaultState(RvMegacoTerm* x,RvMdmTermDefaultProperties* defState) {
if(defState==NULL)
return;
rvMegacoTerminationStateDescriptorCopy(&x->defaultState.termState,&defState->termState);
rvMegacoEventsDescriptorCopy(&x->defaultState.eventsDescr,&defState->eventsDescr);
rvMegacoEventBufferDescriptorCopy(&x->defaultState.eventBufferDescr,&defState->eventBufferDescr);
rvMegacoDigitMapDescriptorCopy(&x->defaultState.digitMap,&defState->digitMap);
/* Update the termination */
setTermDefaultState(x);
}
/* Update both default value and actual value */
void rvMegacoTermUpdateDefaultProperty(RvMegacoTerm* x,const char* pkg,const char* name,
RvMegacoParameterValue* value) {
RvMegacoPackageItem item;
RvMegacoParameterList * defParams,* curParams;
RvMegacoTerminationStateDescriptor* termState;
rvMegacoPackageItemConstructA(&item,pkg,name,x->alloc);
/* Get default and current parameter list for the termination state */
defParams = (RvMegacoParameterList *)rvMegacoTerminationStateDescriptorGetParameterList(&x->defaultState.termState);
termState = (RvMegacoTerminationStateDescriptor*)rvMegacoMediaDescriptorGetTerminationState(&x->mediaDescr);
curParams = (RvMegacoParameterList *)rvMegacoTerminationStateDescriptorGetParameterList(termState);
/* This will overwrite the existing values */
rvMegacoParameterListSet(defParams,&item,value);
rvMegacoParameterListSet(curParams,&item,value);
rvMegacoPackageItemDestruct(&item);
}
/* Initialize default termination state for physical terminations, for both default and actual state */
void rvMegacoTermPhysInitDefState(RvMegacoTerm* x) {
RvMegacoTerminationStateDescriptor* termState,* defState;
defState = &x->defaultState.termState;
termState = (RvMegacoTerminationStateDescriptor*)rvMegacoMediaDescriptorGetTerminationState(&x->mediaDescr);
rvMegacoTerminationStateDescriptorSetServiceState(defState,RV_MEGACOSERVICESTATE_INSERVICE);
rvMegacoTerminationStateDescriptorSetLockstepMode(defState,rvFalse);
rvMegacoTerminationStateDescriptorSetServiceState(termState,RV_MEGACOSERVICESTATE_INSERVICE);
rvMegacoTerminationStateDescriptorSetLockstepMode(termState,rvFalse);
}
void rvMegacoTermResetDynamicFields(RvMegacoTerm* x) {
destructDynamicFields(x);
constructDynamicFields(x);
}
void rvMegacoTermRestoreDefaultState(RvMegacoTerm* x) {
RvMdmError error;
RvMegacoParameterList * params;
rvMdmErrorConstruct_(&error);
rvMegacoTermResetDynamicFields(x);
setTermDefaultState(x);
/* Reset the termination default state */
params = (RvMegacoParameterList *)rvMegacoTerminationStateDescriptorGetParameterList(&x->defaultState.termState);
rvMdmTermUpdateState_(rvMegacoTermGetMdmTerm(x),params,&error);
}
/*--------------------------------------------------------------------------------*/
/* Internal functions - implement the callbacks to the abstract Term Mgr */
/*--------------------------------------------------------------------------------*/
/*
static unsigned int getNumOfConnTerms(RvMdmXTerm* xTerm) {
RvMegacoTerm * term = (RvMegacoTerm *)xTerm;
RvMegacoTopology * t = &term->context->topology;
return rvMegacoTopologyGetNumTerm(t);
}
static RvMdmTerm* getConnTerms(RvMdmXTerm * xTerm,unsigned int i) {
RvMegacoTerm * term = (RvMegacoTerm *)xTerm;
RvMegacoTopology * t = &term->context->topology;
return rvMegacoTermGetMdmTerm(rvMegacoTopologyGetTermByIndex(t,i));
}
*/
static RvMdmTermType getType(RvMdmXTerm* xTerm) {
RvMegacoTerm * term = (RvMegacoTerm *)xTerm;
return term->type;
}
static const char* getId(RvMdmXTerm* xTerm) {
RvMegacoTerm * term = (RvMegacoTerm *)xTerm;
return rvMegacoTermGetId(term);
}
static void rvMegacoTermProcessObsEventWrap(RvMdmXTerm* term,
const char* pkg,const char* id, RvMdmMediaStream* media,RvMegacoParameterList * args)
{
rvMegacoTermQueueObsEvent((RvMdmTerm *)term, pkg, id, media, args);
}
void rvMegacoTermDisable(RvMegacoTerm* x) {
RvMegacoContext* context = x->context;
if(!rvMegacoTermIsInNullCtxt(x) )
rvMegacoTopologyDisconnectTerm(&context->topology,x,context->alloc);
rvMegacoTermEventStopSignals(x);
rvMegacoTermDeactivateDigitMap(x);
x->inactive = rvTrue;
}
void rvMegacoTermEnable(RvMegacoTerm* x) {
x->inactive = rvFalse;
}
static RvMdmXTermClbks mdmTermClbks = {
/* RvMdmXTermProcessEventCB processF; */
rvMegacoTermProcessObsEventWrap,
/* RvMdmXTermSignalStoppedCB signalStoppedF;*/
rvMegacoTermSignalStopped,
/* RvMdmXTermGetTypeCB getTypeF;*/
getType,
/* RvMdmXTermGetId getIdF;*/
getId
} ;
/* By now, all the callbacks are the same */
RvMdmXTermClbks * rvMegacoPhysTermMdmXClbks = &mdmTermClbks;
RvMdmXTermClbks * rvMegacoEphTermMdmXClbks= &mdmTermClbks;
RvMdmXTermClbks * rvMegacoRootTermMdmXClbks= &mdmTermClbks;
RvMdmXTermClbks * rvMegacoTmpTermMdmXClbks= &mdmTermClbks;
/*--------------------------------------------------------------------------------*/
/* Constructor, Destructor */
/*--------------------------------------------------------------------------------*/
/* Construct fields which change for every call */
static void constructDynamicFields(RvMegacoTerm * x) {
rvMegacoMediaDescriptorConstructA(&x->mediaDescr,x->alloc);
rvMegacoObservedEventsDescriptorConstructA(&x->obsEventsDescr,0,x->alloc);
/* Streams */
rvVectorConstruct(RvMegacoMediaStream)(&x->streamList,x->alloc);
/*----------------------------------*/
/* Event processing state variables */
/*----------------------------------*/
rvMegacoEventsDescriptorConstructA(&x->eventsDescr,0,x->alloc);
rvMegacoEventBufferDescriptorConstructA(&x->eventBufferDescr,x->alloc);;
x->lockStep = rvFalse;
x->bufferActive = rvFalse;
x->digitMapActive = rvFalse;
/* Event processed from the event buffer */
rvListConstruct(RvMegacoObservedEvent)(&x->eventBuffer,x->alloc);
x->bufferedTime = NULL;
rvMegacoDigitMapConstructA(&x->digitMap,x->alloc);
rvStringConstruct(&x->dialString,"",x->alloc);
x->digitMapEC = NULL;
/* Current status of the digitmap matching */
x->digitMapStat=0;
/* Requested event for digitmap event */
x->digitMapReqEvent=NULL;
/* Store previously defined digitmaps */
rvMegacoDigitMapDBConstruct(&x->storedDigitMaps,x->alloc);
/*----------------------------------*/
/* Signals variables */
/*----------------------------------*/
rvListConstruct(RvMegacoCurSignal)(&x->curSignals,x->alloc);
rvListConstruct(RvMegacoCurSignalList)(&x->curSignalLists,x->alloc);
/*-----------------------------------------------*/
/* Used to queue events when processing commands */
/*-----------------------------------------------*/
x->blockedEventState = rvFalse;
rvListConstruct(RvMegacoObservedEvent)(&x->blockedEventBuffer,x->alloc);
/* Serial number in context */
x->serial=0;
}
void rvMegacoTermConstruct(RvMegacoTerm * x,const char * id,RvMegacoContext * context,RvAlloc * alloc) {
/* Allocator */
x->alloc = alloc;
constructDynamicFields(x);
rvMutexConstruct(&x->mutex);
rvStringConstruct(&x->terminationId,id,x->alloc);
x->context = context;
x->oldContext = context;
x->type = RV_MDMTERMTYPE_UNKNOWN;
/* x->msgCounter = 0;
x->keepAliveTimer = 0; */
/*-----------------------------------------------*/
/* The digitmap timers */
/*-----------------------------------------------*/
rvMegacoTermDigitMapTimerConstruct(x);
/*-----------------------------------------------*/
/* Used to queue events when processing commands */
/*-----------------------------------------------*/
rvMutexConstruct(&x->blockedEventMutex);
rvTimerConstruct(&x->blockedEventTimer,RV_MEGACOTERM_EVENTTIME,rvMegacoTermPostEvent,x);
/*-------------------------------------------------------------------*/
/* Construct the default state */
/*-------------------------------------------------------------------*/
rvMdmTermDefaultPropertiesConstructA_(&x->defaultState,x->alloc);
x->inactive = rvFalse;
}
static void destructDynamicFields(RvMegacoTerm * x) {
rvMegacoMediaDescriptorDestruct(&x->mediaDescr);
rvMegacoObservedEventsDescriptorDestruct(&x->obsEventsDescr);
rvVectorDestruct(RvMegacoMediaStream)(&x->streamList);
/*----------------------------------*/
/* Event processing state variables */
/*----------------------------------*/
rvMegacoEventsDescriptorDestruct(&x->eventsDescr);
rvMegacoEventBufferDescriptorDestruct(&x->eventBufferDescr);
/* Event processed from the event buffer */
rvListDestruct(RvMegacoObservedEvent)(&x->eventBuffer);
rvMegacoDigitMapDestruct(&x->digitMap);
rvStringDestruct(&x->dialString);
/* Digitmap */
rvMegacoTermDeactivateDigitMap(x);
/* Store previously defined digitmaps */
rvMegacoDigitMapDBDestruct(&x->storedDigitMaps);
/*----------------------------------*/
/* Signals variables */
/*----------------------------------*/
rvListDestruct(RvMegacoCurSignal)(&x->curSignals);
rvListDestruct(RvMegacoCurSignalList)(&x->curSignalLists);
/*-----------------------------------------------*/
/* Used to queue events when processing commands */
/*-----------------------------------------------*/
rvListDestruct(RvMegacoObservedEvent)(&x->blockedEventBuffer);
}
void rvMegacoTermDestruct(RvMegacoTerm * x) {
destructDynamicFields(x);
/*-----------------------------------------------*/
/* Used to queue events when processing commands */
/*-----------------------------------------------*/
rvTimerStop(&x->blockedEventTimer);
/* Lock the mutex, in case that the timer event already hit */
rvMutexLock(&x->blockedEventMutex);
rvMutexUnlock(&x->blockedEventMutex);
/* Try to process all pending events */
while(!rvListEmpty(&x->blockedEventBuffer) )
rvThreadSleep(RV_MEGACOTERM_EVENTTIME*2);
rvMutexDestruct(&x->blockedEventMutex);
rvTimerDestruct(&x->blockedEventTimer);
/*-----------------------------------------------*/
/* The digitmap timers */
/*-----------------------------------------------*/
rvMegacoTermDigitMapTimerDestruct(x);
/*-------------------------------------------------------------------*/
/* Destruct the default state */
/*-------------------------------------------------------------------*/
rvMdmTermDefaultPropertiesDestruct(&x->defaultState);
/*-------------------------------------------------------------------*/
/* Destruct the termination mutex */
/*-------------------------------------------------------------------*/
rvMutexDestruct(&x->mutex);
rvStringDestruct(&x->terminationId);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -