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

📄 rvmdmpkg.c

📁 h.248协议源码
💻 C
📖 第 1 页 / 共 2 页
字号:
$*/
void rvMdmPackageRegisterEventParametersCB(RvMdmPackage* x,const char* id,RvMdmEventParamCB func) {
	RvString evStr;
	RvMdmEventInfo *eventInfo = NULL;

	rvStringConstruct(&evStr,id,&rvDefaultAlloc);
	eventInfo = (RvMdmEventInfo*)rvMapGetValue(RvIString,RvMdmEventInfo)(&x->eventInfo, &evStr);
	if(eventInfo!=NULL) {
		eventInfo->paramF = func;	
	}
	rvStringDestruct(&evStr);
}

/*$
{function:
	{name: rvMdmPackageRegisterEnableDetectEventCB }
	{class: RvMdmPackage}
	{include: rvmdm.h}
	{description:
		{p: Register a callback to  enable detection of this event.}
		{p: The MG set this callback if it needs to specifically enable the detection
		    of this event when is required.}
	}
	{proto: void rvMdmPackageRegisterEnableDetectEventCB(RvMdmPackage* x,const char* id,RvMdmTermEnableDetectEventCB func);
	}
	{params:
		{param: {n:x} {d:The package.}}
		{param: {n:id} {d:The event id.}}
		{param: {n:func} {d:The callback function.}}
	}
	{notes:
		{note: 
			In Megaco, detection of DTMF events is associated with the "ce" event.
		}
	}
}
$*/
void rvMdmPackageRegisterEnableDetectEventCB(RvMdmPackage* x,const char* id,RvMdmTermEnableDetectEventCB func) {
	RvString evStr;
	RvMdmEventInfo *eventInfo = NULL;

	rvStringConstruct(&evStr,id,&rvDefaultAlloc);
	eventInfo = (RvMdmEventInfo*)rvMapGetValue(RvIString,RvMdmEventInfo)(&x->eventInfo, &evStr);
	if(eventInfo!=NULL) {
		eventInfo->enableF = func;	
	}
	rvStringDestruct(&evStr);
}


/*$
{function:
	{name: rvMdmPackageRegisterTermStateProperty}
	{class: RvMdmPackage}
	{include: rvmdm.h}
	{description:
		{p: Register a property defined in the package for the termination state and the
		    possible values that the property can take.}
	}	
	{proto: void rvMdmPackageRegisterTermStateProperty(RvMdmPackage* x,const char* name,
													   const RvMegacoParameterValue* value);}
	{params:
		{param: {n:x} {d:The package object.}}
		{param: {n:name} {d:The property name.}}
		{param: {n:value} {d:The property possible values (unique,range or list).}}
	}
}
$*/
void rvMdmPackageRegisterTermStateProperty(RvMdmPackage* x,const char* name,const RvMegacoParameterValue* value) {
	RvMegacoPackageItem item;

	rvMegacoPackageItemConstructA(&item,rvStringGetData(&x->name),name,x->alloc);
	rvMegacoTerminationStateDescriptorSetParameter(&x->termStateProperties,&item,value);
	rvMegacoPackageItemDestruct(&item);
}

/*$
{function:
	{name: rvMdmPackageRegisterLocalControlProperty}
	{class: RvMdmPackage}
	{include: rvmdm.h}
	{description:
		{p: Register a property defined in the package for the local control field of the media and the
		    possible values that the property can take.}
	}	
	{proto: void rvMdmPackageRegisterLocalControlProperty(RvMdmPackage* x,const char* name,
													   const RvMegacoParameterValue* value);}
	{params:
		{param: {n:x} {d:The package object.}}
		{param: {n:name} {d:The property name.}}
		{param: {n:value} {d:The property possible values (unique,range or list).}}
	}
}
$*/
void rvMdmPackageRegisterLocalControlProperty(RvMdmPackage* x,const char* name, const RvMegacoParameterValue* value) {
	RvMegacoPackageItem item;

	rvMegacoPackageItemConstructA(&item,rvStringGetData(&x->name),name,x->alloc);
	rvMegacoParameterListSet(&x->localControlProperties,&item,value);
	rvMegacoPackageItemDestruct(&item);
}

/*$
{function:
	{name: rvMdmPackageRegisterStatistic}
	{class: RvMdmPackage}
	{include: rvmdm.h}
	{description:
		{p: Register a statistic defined in the package.}
	}	
	{proto: void rvMdmPackageRegisterStatistic(RvMdmPackage* x,const char* name);}
	{params:
		{param: {n:x} {d:The package object.}}
		{param: {n:name} {d:The statistic field name.}}
	}
}
$*/
void rvMdmPackageRegisterStatistic(RvMdmPackage* x,const char* name) {
	RvMegacoPackageItem item;

	rvMegacoPackageItemConstructA(&item,rvStringGetData(&x->name),name,x->alloc);
	/* There are no values, just statistics names */
	rvMegacoStatisticsDescriptorAddStatistic(&x->statistics,&item,"");
	rvMegacoPackageItemDestruct(&item);
}

/*$
{function:
	{name: rvMdmPackageRegisterDigitMapData}
	{class: RvMdmPackage}
	{include: rvmdm.h}
	{description:
		{p: Register the object describing the package specific handling of digitmap events,
			including the mapping of package events to digitmap symbols and the production of the
		    digitmap completion event.}

		{p: Use only for packages implementing digitmaps events.
		    The RADVISION toolkit implements the DTMF package so this function has to 
			be called only when the user defines other packages implementing digitmap 
			events.}
	}	
	{proto: void rvMdmPackageRegisterDigitMapData(RvMdmPackage* x,RvMdmDigitMapData* data);}
	{params:
		{param: {n:x} {d:The package object.}}
		{param: {n:data} {d:The package specific digitmap data.}}
	}
}
$*/
void rvMdmPackageRegisterDigitMapData(RvMdmPackage* x,RvMdmDigitMapData* data){
	rvStringAssign(&data->pkgItem.package,x->name);
	rvMdmTermMgrSetDigitMapPkgInfo_(x->mgr,data);
}

/* Protected methods */
void rvMdmPackageConstruct_(RvMdmPackage* x,const char* name,RvMdmTermMgr* mgr,RvAlloc* a) {
	x->mgr = mgr;
	rvStringConstruct(&x->name,name,a);
	rvMegacoParameterListConstructA(&x->localControlProperties,a);
	rvMegacoTerminationStateDescriptorConstructA(&x->termStateProperties,a);
	rvMegacoStatisticsDescriptorConstructA(&x->statistics,a);
	rvMegacoSignalsDescriptorConstructA(&x->signals,a);
	rvMegacoEventsDescriptorConstructA(&x->events,0,a);
	rvMapConstruct(RvIString,RvMdmEventInfo)(&x->eventInfo, a);
	rvMapConstruct(RvIString,RvMdmSignalInfo)(&x->signalInfo, a);
	x->alloc = a;
	x->refs = 0;
}
void rvMdmPackageDestruct_(RvMdmPackage* x) {
	rvStringDestruct(&x->name);
	rvMegacoParameterListDestruct(&x->localControlProperties);
	rvMegacoTerminationStateDescriptorDestruct(&x->termStateProperties);
	rvMegacoStatisticsDescriptorDestruct(&x->statistics);
	rvMegacoSignalsDescriptorDestruct(&x->signals);
	rvMegacoEventsDescriptorDestruct(&x->events);
	rvMapDestruct(&x->eventInfo);
	rvMapDestruct(&x->signalInfo);
}


static void rvMdmPackagePtrConstructCopy(RvMdmPackagePtr *d, const RvMdmPackagePtr *s, RvAlloc *a)
{
	*d = *s;
	(*d)->refs++;
}

static void rvMdmPackagePtrDestruct(RvMdmPackagePtr *x)
{
	if(--(*x)->refs == 0)
	{
		rvMdmPackageDestruct_(*x);
		rvAllocDeallocate((*x)->alloc, sizeof(RvMdmPackage), *x);
	}
}

#define RvMdmPackagePtrConstructCopy rvMdmPackagePtrConstructCopy
#define RvMdmPackagePtrDestruct      rvMdmPackagePtrDestruct
rvDefineMap(RvIString,RvMdmPackagePtr)



static void registerEventInfo(RvMdmPackage* pkg,RvMdmEventData* event)
{
	RvString evStr;
	RvMdmEventInfo eventInfo;

	rvStringConstructCopy(&evStr,&event->id,pkg->alloc);
	rvStringMakeLowercase(&evStr);
/*	eventInfo.paramF = event->paramF;*/
	eventInfo.paramF = NULL;
	eventInfo.enableF = NULL;

	rvMapSetValue(RvIString, RvMdmEventInfo)(&pkg->eventInfo, &evStr, &eventInfo);

	rvStringDestruct(&evStr);
}

static void registerSignalInfo(RvMdmPackage *pkg,RvMdmSignalData* signal)
{
	RvString sigStr;
	RvMdmSignalInfo signalInfo;

	rvStringConstructCopy(&sigStr,&signal->id,pkg->alloc);
	rvStringMakeLowercase(&sigStr);
	signalInfo.type = signal->type;
	signalInfo.duration = signal->timeout;
	rvMapSetValue(RvIString, RvMdmSignalInfo)(&pkg->signalInfo, &sigStr, &signalInfo);
	rvStringDestruct(&sigStr);
}


/* Append values, for audit */
void rvMdmPackageAppendSignals_(RvMdmPackage* pkg,RvMegacoSignalsDescriptor* sigDescr) {
	RvMegacoSignalsDescriptor* s = &pkg->signals;
	size_t i;

	for(i=0;i<rvMegacoSignalsDescriptorGetNumSignals(s);i++) 
		rvMegacoSignalsDescriptorAddSignal(sigDescr,rvMegacoSignalsDescriptorGetSignal(s,i));
}

void rvMdmPackageAppendEvents1_(RvMdmPackage* pkg,RvMegacoEventsDescriptor* evDescr) {
	RvMegacoEventsDescriptor* events = &pkg->events;
	size_t i;

	for(i=0;i<rvMegacoEventsDescriptorGetNumEvents(events);i++)
		rvMegacoEventsDescriptorAddEvent(evDescr,rvMegacoEventsDescriptorGetEvent(events,i));
}

void rvMdmPackageAppendEvents2_(RvMdmPackage* pkg,RvMegacoEventBufferDescriptor* evBufDescr) {
	RvMegacoEventsDescriptor* events = &pkg->events;
	size_t i;

	for(i=0;i<rvMegacoEventsDescriptorGetNumEvents(events);i++) {
		const RvMegacoRequestedEvent* reqEv = rvMegacoEventsDescriptorGetEvent(events,i);
		rvMegacoEventBufferDescriptorAddEvent(evBufDescr,&reqEv->event);
	}
}

void rvMdmPackageAppendEvents3_(RvMdmPackage* pkg,RvMegacoObservedEventsDescriptor* obsEvDescr,RvAlloc* a) {
	RvMegacoEventsDescriptor* events = &pkg->events;
	RvMegacoObservedEvent obsEvent;
	RvTimeStamp t;
	RvMegacoParameterList* params;
	size_t i;

	rvTimeStampConstructBlank(&t);
	for(i=0;i<rvMegacoEventsDescriptorGetNumEvents(events);i++) {
		const RvMegacoRequestedEvent* reqEv = rvMegacoEventsDescriptorGetEvent(events,i);
		rvMegacoObservedEventConstructA(&obsEvent,rvMegacoRequestedEventGetName(reqEv),&t,a);
		params = (RvMegacoParameterList*)rvMegacoObservedEventGetParameterList(&obsEvent);
		rvMegacoParameterListCopy(params,rvMegacoRequestedEventGetParameterList(reqEv));
		rvMegacoObservedEventsDescriptorAddEvent(obsEvDescr,&obsEvent);
		rvMegacoObservedEventDestruct(&obsEvent);
	}	
}


static void rvParameterAddFunc(const RvMegacoPackageItem *name, const RvMegacoParameterValue *value, void *data) {
	RvMegacoParameterList* list = (RvMegacoParameterList*)data;
	rvMegacoParameterListSet(list,name,value);
}

void rvMdmPackageAppendStats_(RvMdmPackage* pkg,RvMegacoStatisticsDescriptor* statsDescr) {
	const RvMegacoParameterList* source,* target ;
	source = rvMegacoStatisticsDescriptorGetStatistics(&pkg->statistics);
	target = rvMegacoStatisticsDescriptorGetStatistics(statsDescr);
	rvMegacoParameterListForEach(source,rvParameterAddFunc,(void*)target);
}

void rvMdmPackageAppendTermState_(RvMdmPackage* pkg,RvMegacoTerminationStateDescriptor* termStateDescr) {
	const RvMegacoParameterList* source, * target;
	source = rvMegacoTerminationStateDescriptorGetParameterList(&pkg->termStateProperties);
	target = rvMegacoTerminationStateDescriptorGetParameterList(termStateDescr);
	rvMegacoParameterListForEach(source,rvParameterAddFunc,(void*)target);
}

void rvMdmPackageAppendLocalControl_(RvMdmPackage* pkg,RvMegacoParameterList* localControl) {
	rvMegacoParameterListForEach(&pkg->localControlProperties,rvParameterAddFunc,localControl);
}


/*--------------------------------------------------------------------------*/
/* Used by the application in the EventParametersCB                         */
/* for the of-hook, on-hook cases                                           */
/*--------------------------------------------------------------------------*/
static RvMegacoParameterList* hookParamsTrue=NULL;

static void buildHookEventParams(void) {
	RvMegacoParameterValue value;
	/* Allocate and construct two parameter list,for true and false */
	hookParamsTrue = rvAllocAllocate(&rvDefaultAlloc,sizeof(RvMegacoParameterList));
	rvMegacoParameterListConstructA(hookParamsTrue,&rvDefaultAlloc);

	rvMegacoParameterValueConstruct(&value,"True");
	rvMegacoParameterListSet2(hookParamsTrue,"init",&value);		
	rvMegacoParameterValueDestruct(&value);
}

/*$
{function:
	{name: rvMdmHookEventProcessParams}
	{include: rvmdmpkg.h}
	{description:
		{p: Helper function used to implement the RvMdmEventParamCB callback for the
		    Megaco hook state events (on-hook, of-hook). The application needs to 
			first determine the hook state and then call this function.}
	}
	{proto: RvBool rvMdmHookEventProcessParams(RvMdmTerm* term,const char* pkg,const char* name,
										 RvBool onHook, const RvMegacoParameterList* parameters,
										 RvMdmError* errorInfo);}
	{params:
		{param: {n:term} {d:The termination where the event is requested.}}
		{param: {n:pkg}  {d:The package to which the event belongs.}}
		{param: {n:name} {d:The event id.}}
		{param: {n:onHook} {d:The hook state, set to rvTrue if the termination is
		                      on-hook, rvFalse otherwise.}}
		{param: {n:value} {d:The list of parameter.}}
		{param: {n:errorInfo} {d:Error information will be set here if required.}}
	}
	{returns: 
		Return "rvFalse" if the MG cannot currently detect this event. 
	}
	{notes:
		{note: 
			All the function arguments except onHook came from the callback call.
			In the callback implementation,the application can simply find the hook state 
			and return with a call to this function.
		}
	}
}
$*/
RvBool rvMdmHookEventProcessParams(RvMdmTerm* term,const char* pkg,const char* name,
										 RvBool onHook, const RvMegacoParameterList* parameters,
										 RvMdmError* errorInfo) {
	const RvMegacoParameterValue* value;
	const char * strict;
	
	value = rvMegacoParameterListGet2(parameters,"strict");
	if(value!=NULL)
		strict = rvMegacoParameterValueGetValue(value);	
	else
		strict = "state"; /* This will be the default value */

	/* Check if the state is already set */
	if( (!rvStrIcmp(name,"of") && !onHook ) || (!rvStrIcmp(name,"on") && onHook ) ) {
		/* Ignore the state, only detect actual transition */
		/* TODO: Verify that error doesn't need to be set */
		if(!rvStrIcmp(strict,"exact") ) 
			return rvTrue;
		if(!rvStrIcmp(strict,"state") ) {
			if(hookParamsTrue==NULL)
				buildHookEventParams();
			rvMdmTermProcessEvent(term,pkg,name,NULL,hookParamsTrue);
			return rvTrue;
		}
		if(!rvStrIcmp(strict,"failWrong") ) {
			rvMdmErrorSet(errorInfo,540,"Unexpected initial hook state");
			return rvFalse;	
		}
	}	
	return rvTrue;
}

/* Use to build packages */
static void registerEvent(RvMdmPackage* pkg,const char* id) {
	RvMdmEventData event;

	/* Register the events*/
	rvMdmEventDataConstruct(&event,id);
	rvMdmPackageRegisterEvent(pkg,&event);
	rvMdmEventDataDestruct(&event);
}

void rvMdmPackageBuildGenericPkg(RvMdmPackage* pkg) {
	RvMegacoParameterValue param;

	registerEvent(pkg,"Generalcause");
	registerEvent(pkg,"sc");

	rvMegacoParameterValueConstruct(&param, "NR");
	rvMegacoParameterValueOr(&param, "UR");
	rvMegacoParameterValueOr(&param, "FT");
	rvMegacoParameterValueOr(&param, "FP");
	rvMegacoParameterValueOr(&param, "IW");
	rvMegacoParameterValueOr(&param, "UN");
	rvMdmPackageRegisterLocalControlProperty(pkg, "Generalcause", &param);

	rvMegacoParameterValueConstruct(&param, "");
	rvMdmPackageRegisterLocalControlProperty(pkg, "Failurecause", &param);
	rvMdmPackageRegisterLocalControlProperty(pkg, "SigID", &param);

	rvMegacoParameterValueConstruct(&param, "TO");
	rvMegacoParameterValueOr(&param, "EV");
	rvMegacoParameterValueOr(&param, "SD");
	rvMegacoParameterValueOr(&param, "NC");
	rvMdmPackageRegisterLocalControlProperty(pkg, "Meth", &param);
}

⌨️ 快捷键说明

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