op_hla_interaction_pk_struct_get()
Note: Requires High-Level Architecture functionality
Abstract
Extracts a data block from a packet field name.
Syntax
op_hla_interaction_pk_struct_get (pk_ptr, field_name, data_ptr, size_ptr)
| Argument | Type | Description |
|---|---|---|
pk_ptr |
Packet * |
Packet representing an incoming interaction |
field_name |
const char * |
Field name where data will be retrieved |
data_ptr |
char * * |
Pointer to variable to receive data block from field |
size_ptr |
size_t * |
Pointer to variable to receive size of data block, in bytes |
Return Type
Compcode
Completion code indicating success or failure in getting the data. The procedure returns OPC_COMPCODE_SUCCESS if the data was successfully retrieved. It returns OPC_COMPCODE_FAILURE if it could not retrieve the data.
Example
pk = op_pk_get (REQUEST_STRM);
op_pk_nfd_get (pk, "number ids", &num_ids);
if (num_ids != 0)
{
int data_size;
int * data;
int i;
op_hla_interaction_pk_struct_get (pk, "ids", &data, &data_size);
for (i = 0; i < num_ids; i++)
{
if (data [i] == my_id)
{
. . .
Details
RTI interactions have fields of either a simple type (short, long, double) or an arbitrary block of data that will need to be encoded by the sender and interpreted by the recipient of the interaction. Because the actual size of the data is not known beforehand, this KP allocates an appropriate block of memory (whose address is returned in data_ptr and whose size is set in size_ptr). The KP caller is responsible for freeing the allocated block of memory using op_prg_mem_free().
Purpose
Provides a mechanism to obtain a generic data block extracted from a packet representing an interaction.
Errors
- Recoverable Error: Unable to get field (
<field_name>) of interaction packet.
Reference
- Use the KP op_hla_interaction_pk_deregister() to stop being notified of incoming interactions
- Use the KP op_hla_interaction_pk_register() to be notified of incoming interactions
- Use the KP op_prg_mem_free() to free the block of memory returned in
data_ptr