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

📄 complex_intrpt.ex.c

📁 afit的ad hoc路由协议源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	}
// otherwise the current interruption is unknown as an complex interruption
else
	{
	// and -1 is returned
	printf("Complex intrpt get code: I cannot find the actual intrpt in the fifo","","","");
	return (-1);
	}
}

/*********************** COMPLEX_INTRPT_DATA ******************************/
/* This function return the data associated with the current interruption. Thus 
/* it "replaces" the usual ici associated with an interruption.
/* Note that these data can be read/extracted only one time
/* 		sComplexIntrpt complex_intrpt: the sComplexIntrpt struture used to 
/* managed the complex_intrpt, that is the multiple ici service
/* 		return: a pointer to the data associted with the current interruption
/*				or OPC_NIL if the current interruption is unknown
/*************************************************************************/
void* complex_intrpt_data(sComplexIntrpt * complex_intrpt)
{
int intrpt_id;
sComplexIntrptObject* complex_intrpt_object;
void* data;
// extract the id of the complex interruption (which is memorised in the OPNET Kernel as the code of the interruption)
intrpt_id=op_intrpt_code();
// read the information associated with this id in the multiplexed FIFO
complex_intrpt_object=fifo_multiplex_read(complex_intrpt->intrpt_data_fifo,intrpt_id);
// if these information were found 
if (complex_intrpt_object!=OPC_NIL)
	{
	// read the data pointer associated in the complex interruption
	data=complex_intrpt_object->intrpt_data;
	// and consider these data as extracted from the complex interruption information structure by setting in it its value to OPC_NIL
	complex_intrpt_object->intrpt_data=OPC_NIL;
	// return the pointer to the read data
	return data;
	}
// otherwise the current interruption is unknown as an complex interruption
else
	{
	// and OPC_NIL is returned
	printf("Complex intrpt get data: I cannot find the actual intrpt in the fifo","","","");
	return (OPC_NIL);
	}
}

/************************* COMPLEX_INTRPT_CANCEL **************************/
/* This function cancels the given complex interruption event, and frees the 
/* memory used in the sComplexIntrpt structure used to store the information 
/* associated with it. Note that it also frees the data associated with the
/* interruption.
/* 		sComplexIntrpt complex_intrpt: the sComplexIntrpt struture used to 
/* managed the complex_intrpt, that is the multiple ici service
/*		Evhandle evt: the complex interruption event to cancel
/*		Return: 1 if success
/*				0 if there is a problem to cancel the event
/*************************************************************************/
int complex_intrpt_cancel(sComplexIntrpt * complex_intrpt, Evhandle evt)
{
int intrpt_id;
sComplexIntrptObject* complex_intrpt_object;
// extract the id of the complex interruption (which is memorised in the OPNET Kernel as the code of the futur interruption event)
intrpt_id=op_ev_code(evt);
// read the information associated with this id in the multiplexed FIFO
complex_intrpt_object=fifo_multiplex_extract(complex_intrpt->intrpt_data_fifo,intrpt_id);
// if these information were found 
if (complex_intrpt_object!=OPC_NIL)
	{
	// if some data are associated with the interruption
	if(complex_intrpt_object->intrpt_data!=OPC_NIL);
		{
		// free the memory used by these data
		op_prg_mem_free(complex_intrpt_object->intrpt_data);
		}
	// free the memory used to store the information associated with the current interruption
	free(complex_intrpt_object);
	// check if the complex interruption event is valid
	if (op_ev_valid(evt))
		{
		// check if the complex interruption event is still active
		if (op_ev_pending(evt) == OPC_FALSE)
			{
			printf("The complex interruption is not active: may be it already happened\n");
			return(0);
			}
		// cancel the complex interruption event in the OPNET Kernel
		else if (op_ev_cancel(evt)==OPC_COMPCODE_SUCCESS)
			{
			//printf("The complex interruption event is successfully cancelled\n");
			return(1);
			}
		}
	else
		{
		printf("The complex interruption is invalid\n");
		return(0);
		}
	}
// otherwise the current interruption is unknown as an complex interruption
else 
	{
	op_sim_end("Complex intrpt cancel: I cannot find the wanted intrpt event in the fifo","","","");
	return(0);
	}
}

/************************* COMPLEX_INTRPT_CLOSE **************************/
/* This function close the current interruption, that is free the memory used
/* in the sComplexIntrpt structure used to store the information associated with it.
/* Note that if the complex_intrpt_data function was called before, since the
/* data were extracted by the user, he must free himself the memory used by them. 
/* Otherwise this function automatically free this memory.
/* 		sComplexIntrpt complex_intrpt: the sComplexIntrpt struture used to 
/* managed the complex_intrpt, that is the multiple ici service
/*************************************************************************/
void complex_intrpt_close(sComplexIntrpt * complex_intrpt)
{
int intrpt_id;
sComplexIntrptObject* complex_intrpt_object;
// extract the id of the complex interruption (which is memorised in the OPNET Kernel as the code of the interruption)
intrpt_id=op_intrpt_code();
// read the information associated with this id in the multiplexed FIFO
complex_intrpt_object=fifo_multiplex_extract(complex_intrpt->intrpt_data_fifo,intrpt_id);
// if these information were found 
if (complex_intrpt_object!=OPC_NIL)
	{
	// if the data associated with the interruption were not extracted by the library user
	if(complex_intrpt_object->intrpt_data!=OPC_NIL);
		{
		// free the memory used by these data
		op_prg_mem_free(complex_intrpt_object->intrpt_data);
		}
	// free the memory used to store the information associated with the current interruption
	free(complex_intrpt_object);
	}
// otherwise the current interruption is unknown as an complex interruption
else 
	{
	// the simulation is stopped since the library user should see before (when he gets its code or data) that the current interruption is not a complex one
	op_sim_end("Complex intrpt close: I cannot find the actual intrpt in the fifo","","","");
	}
}

/************************ COMPLEX_INTRPT_DESTROY **************************/
/* This function frees the memory (allocated previously by the complex_intrpt_new
/* function) used by the structure allowing the management of the mutiple_ici, 
/* also called complex_intrpt, service
/* 		sComplexIntrpt complex_intrpt: a pointer to the sComplexIntrpt 
/* structure to destroy
/*************************************************************************/
void complex_intrpt_destroy(sComplexIntrpt* complex_intrpt)
{
// destroy the FIFO used to manage and store the complex_intrpt
fifo_destroy(complex_intrpt->intrpt_data_fifo);
// and free the memory used by the management structure
op_prg_mem_free(complex_intrpt)
;
}

///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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