📄 complex_intrpt.ex.c
字号:
///////////////////////////////////////////////////////////////////////////
///////////////// OPNET'S COMPLEX_INTRPT LIBRARY SOURCE FILE //////////////
///////////////////////////////////////////////////////////////////////////
///
/// Contains: The complex_intrpt library source code, which provides the
/// equivalent of a multiple_ici (one intrpt = one ici) service
///
/// Company: National Institute of Standards and Technology
/// Written by: Xavier Pallot
/// Date: 10/20/00
///
///////////////////////////////////////////////////////////////////////////
/// Description: This library provides the multi-ici service for Opnet.
/// With it you can associate with any intrpt a pointer,
/// wich means any kind of information. You have not the
/// OPNET limitation: one outgoing ici per process.
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////// INCLUDE /////////////////////////////
////
///////////////////////////////////////////////////////////////////////////
#include "complex_intrpt.h"
///////////////////////////////////////////////////////////////////////////
////////////////////////// FUNCTIONS DEFINITION ///////////////////////////
///////////////////////////////////////////////////////////////////////////
/************************* COMPLEX_INTRPT_NEW ****************************/
/* This function creates and initializes the structure used to manage the
/* mutiple_ici, also called complex_intrpt, service
/* return: a pointer to the new sComplexIntrpt structure
/* OPC_NIL if initialization failure
/*************************************************************************/
sComplexIntrpt* complex_intrpt_new()
{
sComplexIntrpt* complex_intrpt;
// allocate the memory used by the sComplexIntrpt structure
complex_intrpt=(sComplexIntrpt*)op_prg_mem_alloc(sizeof(sComplexIntrpt));
// if the memory allocation was successfull
if (complex_intrpt!=OPC_NIL)
{
// init this structure by calling the complex_intrpt_init function
if (!complex_intrpt_init(complex_intrpt))
{
// if a problem appears during this initialization, cancel the memory allocation, and will return OPC_NIL
op_prg_mem_free(complex_intrpt);
complex_intrpt=OPC_NIL;
}
}
// return the pointer to the new sComplexIntrpt structure (or OPC_NIL if failure)
return(complex_intrpt);
}
/************************* COMPLEX_INTRPT_INIT **************************/
/* This function initializes the structure used to manage the mutiple_ici,
/* also called complex_intrpt, service
/* sComplexIntrpt complex_intrpt: a pointer to the sComplexIntrpt
/* structure to initialize
/* return: 1 if successfull initialization
/* 0 otherwise (i.e impossible to allocate the memory
/* for the FIFO contained in the structure
/*************************************************************************/
int complex_intrpt_init(sComplexIntrpt* complex_intrpt)
{
// init the structure intrpt_id to 0
complex_intrpt->intrpt_id_number=0;
// create and initialize the FIFO used to manage and store the complex_intrpt
complex_intrpt->intrpt_data_fifo=fifo_new();
return (complex_intrpt->intrpt_data_fifo!=OPC_NIL)
;
}
/********************** COMPLEX_INTRPT_SCHEDULE_SELF *********************/
/* This function is used to schedule a complex self interruption, that is an
/* interruption with some data (equivalent to ici) associated. It replaces the
/* OPNET's op_intrpt_schedule_self function.
/* sComplexIntrpt complex_intrpt: the sComplexIntrpt structure used to
/* managed the complex_intrpt, that is the multiple ici service
/* double time: the time when the self interruption must be sent to the process
/* int intrpt_code: the code associated with the interruption
/* void* intrpt: a pointer to the data associated to the interruption
/* (note that these data could be of any type)
/* return: the event handle associated with the new scheduled self interruption
/*************************************************************************/
Evhandle complex_intrpt_schedule_self(sComplexIntrpt * complex_intrpt, double time, int intrpt_code, void* intrpt_data)
{
Evhandle evt;
sComplexIntrptObject* complex_intrpt_object;
// allocate the memory used to store the information associated with the scheduled interruption
complex_intrpt_object=(sComplexIntrptObject*)op_prg_mem_alloc(sizeof(sComplexIntrptObject));
// store in it the code that the user has associated with this interruption
complex_intrpt_object->intrpt_code=intrpt_code;
// and also store in it the data that the user has associated with this interruption
complex_intrpt_object->intrpt_data=intrpt_data;
// schedule this new self interruption in the OPNET kernel. Note that its code is an automatic number (id) that identifies the complex interruption.
evt=op_intrpt_schedule_self(time,complex_intrpt->intrpt_id_number);
// store the information associated with the interruption in a mutiplexing queue indexed with the complex interruption id
fifo_multiplex_insert(complex_intrpt->intrpt_data_fifo,complex_intrpt_object,complex_intrpt->intrpt_id_number)
;
// increment the complex interruption id... this new id will be used by the next complex interruption to be scheduled
complex_intrpt->intrpt_id_number++;
// return the event handle associated with this new scheduled self interruption
return(evt);
}
/********************* COMPLEX_INTRPT_SCHEDULE_REMOTE ********************/
/* This function is used to schedule a complex remote interruption, that is an
/* interruption with some data (equivalent to ici) associated. It replaces the
/* OPNET's op_intrpt_schedule_remote function.
/* sComplexIntrpt complex_intrpt: the sComplexIntrpt struture used to
/* managed the complex_intrpt, that is the multiple ici service
/* double time: the time when the remote interruption must be sent to
/* the wanted process
/* int intrpt_code: the code associated with the interruption
/* void* intrpt: a pointer to the data associated to the interruption
/* (note that these data could be of any type)
/* Objid process_id: the Objid that identifies the proccess that will
/* receive the scheduled interruption
/* return: the event handle associated with the new scheduled remote interruption
/*************************************************************************/
Evhandle complex_intrpt_schedule_remote(sComplexIntrpt * complex_intrpt, double time, int intrpt_code, void* intrpt_data, Objid process_objid)
{
Evhandle evt;
sComplexIntrptObject* complex_intrpt_object;
// allocate the memory used to store the information associated with the scheduled intrpt
complex_intrpt_object=(sComplexIntrptObject*)op_prg_mem_alloc(sizeof(sComplexIntrptObject));
// store in it the code that the user has associated with this interruption
complex_intrpt_object->intrpt_code=intrpt_code;
// and also store in it the data that the user has associated with this interruption
complex_intrpt_object->intrpt_data=intrpt_data;
// schedule this new remote interruption in the OPNET kernel. Note that its code is an automatic number (id) that identifies the complex interruption.
evt=op_intrpt_schedule_remote(time,complex_intrpt->intrpt_id_number,process_objid);
// store the information associated with the interruption in a mutiplexing queue indexed with the complex interruption id
fifo_multiplex_insert(complex_intrpt->intrpt_data_fifo,complex_intrpt_object,complex_intrpt->intrpt_id_number)
;
// increment the complex interruption id... this new id will be used by the next complex interruption to be scheduled
complex_intrpt->intrpt_id_number++;
// return the event handle associted with this new scheduled remote interruption
return(evt);
}
/************************** COMPLEX_INTRPT_CODE **************************/
/* This function returns the code associated with the current interruption. Thus
/* it replaces the op_intrpt_code function.
/* sComplexIntrpt complex_intrpt: the sComplexIntrpt struture used to
/* managed the complex_intrpt, that is the multiple ici service
/* return: the code of the current interruption
/* or -1 if the current interruption is unknown
/*************************************************************************/
int complex_intrpt_code(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_read(complex_intrpt->intrpt_data_fifo,intrpt_id);
// if these information were found
if (complex_intrpt_object!=OPC_NIL)
{
// return the code associated in the complex interruption
return(complex_intrpt_object->intrpt_code);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -