op_intrpt_schedule_call()

Abstract

Schedules an invocation of the specified procedure, at the specified time.

Syntax

op_intrpt_schedule_call (time, code, procedure, state_ptr)
Argument Type Description
time double scheduled time for the interrupt
[This value should be either an absolute simulation time or a constant from Table 58 “Interrupt Time Symbolic Constants“ on page 15).]
[If the “sim_time_quantum“ preference has a value other than 0.0, an absolute time will be truncated internally to a multiple of the specified quantum.]
code int user-defined numeric code that is passed to the called procedure
[This value is an arbitrary, user-defined integer that can be used as an identification code for the scheduled call. You can assign a text string that will be printed along with this code when it appears in ODB event banners and traces. See “Interrupt Code Map“ on page 507 for details.]
procedure Procedure procedure that is to be called by the scheduled event
[This value must be a pointer to a C function which takes two arguments (the state memory pointer discussed below, and the integer code discussed above), and which performs the desired simulation task.]
state_ptr void* pointer to a data structure (or simple variable) that is passed to the called procedure

Return Type

Evhandle

Event handle for the scheduled interrupt.

[This returned value can be stored in a state variable, for possible later use to identify the interrupt in an invocation of op_ev_cancel().]

Example

/* function block procedures */

static void
c3sim_pos_animate (void * v_state_ptr, int code)
	{
	struct Pos_DS *ndp_ds_ptr = (struct Pos_DS *) v_state_ptr;
	FIN (c3sim_pos_animate);
	gfx_package_node_plot (ndp_ds_ptr->lat, ndp_ds_ptr->long, ndp_ds_ptr->alt);
	FOUT;
	}

void
c3sim_sched_pos_animation (int ntimes, double sim_duration)
	{
	double d, anim_int;
	static struct Pos_DS node_ps_ds = {0, 0, 0};
	FIN (c3sim_sched_pos_animation);
	anim_int = sim_duration / ntimes;
	for (d = 0.0; d < sim_duration; d += anim_int)
		op_intrpt_schedule_call (d, 0, c3sim_pos_animate, &node_pos_ds);
	FOUT;
	}

Details

Invoking this KP places a new event on the simulation event list; this new event represents a procedure interrupt that is scheduled to be executed at the specified time. As soon as the event is scheduled, this KP returns control to the invoking process. The invoking process is free to pursue any activities. When all earlier events have been executed, and the procedure interrupt event is at the head of the simulation event list, its simulation time is established as the current simulation time and the event is executed. The execution of the event causes the specified procedure to be called. The called procedure is passed the specified state pointer and numeric code as arguments.

Note: If the “sim_time_quantum“ preference has a value other than 0.0, time will be truncated internally to a multiple of the specified quantum.

Using the constant OPC_INTRPT_SCHED_CALL_ENDSIM for the time argument results in the procedure being scheduled for the end of the simulation. In this case, the procedure interrupt is delivered before any endsim interrupts, but any interrupts scheduled by the procedure will not be delivered. Priorities are handled as for normal procedure interrupts.

In cases where a procedure interrupt is signifying an optional activity, it may be necessary to cancel it due to changing conditions. Cancelling an interrupt requires that the event handle returned by this KP be stored in a state variable and later passed to the KP op_ev_cancel(), as shown in the following example:

/* state variable declaration */
Evhandle \evh;

/* procedure interrupt scheduling */
evh = op_intrpt_schedule_call (stime, 22, f, ds_ptr);

/* procedure interrupt cancelling */
op_ev_cancel (evh);

Procedure interrupts scheduled from within process contexts will later execute as if within that process context, if it still exists. Thus, the called procedure will have access to the process’ resources, including streams, and state variables provided that the procedure is defined in the process model’s function block.

Purpose

Provides a mechanism for causing an arbitrary, user-written procedure to be scheduled and called at a specified simulation time. This is a convenient way of time-sequencing activities without having a dedicated process model handle interrupt trapping and procedure calling duties. Typically this KP is used to interface simulations with external libraries or user-written simulation procedures.

Errors

  • Program Abort: Allocation of memory failed.
  • Recoverable Error: Specified time (<time>) is less than current time.
  • Recoverable Error: Specified time (<time>) is an invalid double value.

Reference

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com