TipcMsgWriteVa


Name

TipcMsgWriteVa — append fields to a message (va_list version)

Synopsis

T_BOOL TipcMsgWriteVa(msg, var_arg_list) 
T_IPC_MSG msg; 
va_list var_arg_list; 

Arguments

msg — message to append fields to

var_arg_list — argument list

Return Values

TRUE if all the fields were successfully appended, FALSE otherwise.

Diagnostics

If TipcMsgWriteVa fails, it returns FALSE and sets the global SmartSockets error number to one of:

Description

TipcMsgWriteVa is the non-varargs version of TipcMsgWrite (TipcMsgWrite actually calls TipcMsgWriteVa). TipcMsgWriteVa can be used to implement a varargs function.

In the C language, a varargs function (one that takes a variable number of arguments) cannot call another varargs function with the original arguments, due to the way that C implements varargs. A varargs function can (and usually does) call a helper function that takes a fixed number of arguments, with the last argument usually of type va_list. TipcMsgWriteVa is TipcMsgWrite’s helper function.

Caution

TipcMsgWriteVa does not send a message: it only appends fields to a message.

TipcMsgWriteVa does not support fields with a value of unknown.

See Also

TipcMsgRead, TipcMsgUpdateNamedBinary, TipcMsgAppend*

Examples

This example shows how to write a varargs function in ANSI C that creates a message and appends fields to it:

T_IPC_MSG T_ENTRY my_msg_create_write(T_INT4 mt_num, ...) 
{ 
  T_IPC_MT mt; 
  T_IPC_MSG msg; 
  va_list var_arg_list; 
  T_BOOL status; 
 
  /* look up the message type */ 
  mt = TipcMtLookupByNum(mt_num); 
  if (mt == NULL) { 
    return;  /* error */ 
  } 
 
  /* create the message */ 
  msg = TipcMsgCreate(mt); 
  if (msg == NULL) { 
    return;  /* error */ 
  } 
 
  /* An RTclient would typically set the destination of */ 
  /* a message at this point by calling TipcMsgSetDest. */ 
 
  /* retrieve the varargs and use them */ 
  va_start(var_arg_list, mt_num); 
  status = TipcMsgWriteVa(msg, var_arg_list); 
  va_end(var_arg_list); 
  if (!status) { 
    if (!TipcMsgDestroy(msg)) { 
      return;  /* error */ 
    } 
    msg = NULL; 
  } 
  
  return msg; 
} /* my_msg_create_write */ 
 
/* =========================================================== */ 
/*...code from calling function below */ 
 
/* fragment that uses my_msg_create_write */ 
T_IPC_MSG msg; 
 
msg = my_msg_create_write(T_MT_NUMERIC_DATA, 
                          T_IPC_PROP_PRIORITY, 2, 
                          T_IPC_FT_STR, "voltage", 
                          T_IPC_FT_REAL8, 120.0, 
                          T_IPC_FT_STR, "temperature", 
                          T_IPC_FT_REAL8, 98.6, 
                          NULL); 
if (msg == NULL) { 
  return;  /* error */ 
}  
 
/* A process would typically send a message at this point by */ 
/* calling TipcConnMsgSend or TipcSrvMsgSend. */ 
 
/* A process would typically destroy a message at this point by */ 
/* calling TipcMsgDestroy. */ 
 

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