Previous: , Up: Creating a Multinode Model   [Contents][Index]


4.2.7 Associating Parameters with a Model

When creating a multinode model, you can declare the custom parameters of this model as global variables and access them from event handler functions. However, when you create multiple models existing concurrently and sharing the same event handler functions, you may need to associate a number of variables with a particular model.

You can associate a number of pointers with a multinode model. They can address statically or dynamically allocated memory blocks. Every pointer has a unique index. In the simplest case, you can associate a single pointer with index 0 addressing an instance of a structure holding variables specific to a model.

Use the following functions to get a pointer associated with a multinode 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. If the model does not have a pointer with this index, or the pointer is NULL, the function returns NULL.

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

This function associates a pointer ptr_p with a multinode model. You can fetch this pointer later by index ptr_idx. If a pointer with this index already exists, the function overwrites it.

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

QSMM_ERR_INVAL

The argument ptr_idx is negative.

QSMM_ERR_NOMEM

There was not enough memory to perform the operation.

It is possible to associate pointers not only with the entire 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, qsmm_sig_t node, int ptr_idx)

This function returns a pointer with index ptr_idx associated with a node of a multinode model. The argument node specifies the identifier of this node. If the node does not exist, or the node does not have a pointer with this index, or the pointer is NULL, the function returns NULL.

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

This function associates a pointer ptr_p with a node of a multinode model. The argument node specifies the identifier of this node. You can fetch the pointer later by index ptr_idx. If a pointer with this index already exists, the function overwrites it.

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

QSMM_ERR_INVAL

The argument 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.


Previous: , Up: Creating a Multinode Model   [Contents][Index]