Next: , Previous: , Up: Multinode Model   [Contents][Index]


4.16 Associating Parameters with a Model

When an application creates a multinode model, user variables of the model can be declared as global (or static global) ones and accessed from event handler functions as normal C variables. However, when an application creates several multinode models, the need may arise to associate a number of variables with a particular model.

There can be a number of pointers associated with a multinode model. They could point to statically or dynamically allocated memory blocks, possibly instances of structures holding variables specific to the model. The pointers are accessed by indices. The set of indices can be defined using the enum keyword.

Use the following functions to get a pointer associated with a model or associate a pointer with the model.

Function: void * qsmm_get_ptr (qsmm_t model, int ptr_idx)

This function returns a pointer with index ptr_idx associated with a multinode model specified by handle model. If a pointer with that index is not associated with the model, or the pointer is NULL, then NULL will be returned.

Function: int qsmm_set_ptr (qsmm_t model, int ptr_idx, void *ptr_p)

This function associates pointer ptr_p with a multinode model specified by handle model. That pointer can be fetched later by index ptr_idx. If a pointer with this index already existed, then it is overwritten.

The function returns a non-negative value on success or a negative error code on failure. Currently, the following error codes can be returned.

QSMM_ERR_INVAL

The value of ptr_idx is negative.

QSMM_ERR_NOMEM

There was not enough memory to perform the operation.

Starting from QSMM version 1.15, it is possibile to associate pointers not only with the whole multinode model but also with its particular nodes. Use the following functions to get a pointer associated with a node or associate a pointer with the node.

Function: void * qsmm_get_node_ptr (qsmm_t model, int node, int ptr_idx)

This function returns a pointer with index ptr_idx associated with a node of a multinode model specified by handle model. Argument node specifies the identifier of the node. If the node does not exist, or a pointer with that index is not associated with the node, or the pointer is NULL, then NULL will be returned.

Function: int qsmm_set_node_ptr (qsmm_t model, int node, int ptr_idx, void *ptr_p)

This function associates pointer ptr_p with a node of a multinode model specified by handle model. Argument node specifies the identifier of the node. That pointer can be fetched later by index ptr_idx. If a pointer with this index already existed, then it is overwritten.

The function returns a non-negative value on success or a negative error code on failure. Currently, the following error codes can be returned.

QSMM_ERR_INVAL

The value of ptr_idx is negative.

QSMM_ERR_NOTFOUND

A node with identifier node does not exist.

QSMM_ERR_NOMEM

There was not enough memory to perform the operation.


Next: , Previous: , Up: Multinode Model   [Contents][Index]