TipcMsgTraverse


Name

TipcMsgTraverse — traverse all fields in a message

Synopsis

T_PTR TipcMsgTraverse(msg, func, arg) 
T_IPC_MSG msg; 
T_IPC_MSG_TRAV_FUNC func; 
T_PTR arg; 

Arguments

msg — message whose fields are traversed

func — function to call once for each field

arg — user-defined argument to pass to func

Return Values

The first non-null return value from func, or NULL if func always returns NULL.

Diagnostics

If TipcMsgTraverse fails or traverses all the fields in msg, it returns NULL and sets the global SmartSockets error number to one of:

Description

TipcMsgTraverse traverses a message’s data fields in order and calls func once for each field. When func returns a non-null value, then TipcMsgTraverse returns with that value.

One of the arguments passed to func is a T_IPC_MSG_TRAV pointer. This data structure contains a pointer to the field type (which is stored as a two-byte integer to save space), a pointer to the field value, and the array size. (Array size is set only if the field is an array type.)

Caution

If TipcMsgTraverse returns NULL, it may be because there was an error or simply because func always returned null.

See Also

TipcMsgPrint

Examples

This example prints a message’s field types:

T_PTR T_ENTRY print_one_field(msg, trav, arg) 
T_IPC_MSG msg; 
T_IPC_MSG_TRAV trav; 
T_PTR arg; /* really (T_INT4 *) */ 
{ 
  T_INT4 *counter_ptr = arg; 
 
  TutOut(" Field %d:\n", *counter_ptr); 
  (*counter_ptr)++; 
  TutOut(" Type: %d\n", (T_IPC_FT)(*trav->type_ptr)); 
 
  return NULL; /* continue traversal */ 
} /* print_one_field */ 
 
void print_field_offsets(msg) 
T_IPC_MSG msg; 
{ 
  T_INT4 num_fields; 
  T_INT4 counter; 
 
  if (!TipcMsgGetNumFields(msg, &num_fields)) { 
    return;  /* error */ 
  }  
  TutOut("This message has %d fields.\n", num_fields); 
 
  counter = 1; 
  (void)TipcMsgTraverse(msg, print_one_field, &counter); 
} /* print_field_offsets */ 
 

TIBCO SmartSockets™ Application Programming Interface
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com