TipcMsgFileWrite write a message to a message file
msg_file
message file
msg
message to write to message file
TRUE
if the message was successfully written to the message file, FALSE
otherwise.
If TipcMsgFileWrite fails, it returns FALSE
and sets the global SmartSockets error number to one of:
msg_file
was null or msg
was nullmsg_file
was not created with mode T_IPC_MSG_FILE_CREATE_WRITE, T_IPC_MSG_FILE_CREATE_WRITE_BINARY, or T_IPC_MSG_FILE_CREATE_APPENDmsg
was not a valid messageTipcMsgFileWrite writes a message to a message file. See TipcMsgFileCreate for more information on message files.
TipcMsgFileWrite writes the message type, then the destination (or _null
if the destination is null), and finally writes the fields to the file. The message source and priority are not written to the file. After all output has been written to the file, TipcMsgFileWrite flushes the file to disk.
TipcMsgFileWrite first looks up the message type with TipcMtLookupByNum. If the message type does not exist (this can happen if a process such as RTserver receives a message for which it has not created a message type with TipcMtCreate), then TipcMsgFileWrite writes the message type number (for example, 22
); otherwise it writes the message type name (for example, numeric_data
).
The message fields are written to the file in a verbose format if the message type does not exist or the message type grammar is "verbose"
. The verbose format uses a type name and value for each field (such as real8 34.567891
). Arrays are delimited by {}
.
If the verbose format is not used, then only the value is used for each field (such as 34.567891
). The message type grammar is used to help format the output. Both groups and arrays are delimited by {}
.
For text message files, TipcMsgFileWrite fails if the fields in the message do not match the grammar of the message type (for example, the number of fields in the grammar is not the same as the number of fields in the message, or the types of the fields in the grammar do not match the types of the fields in the message).
TipcMsgFileRead, TipcMtCreate, TipcMtLookup, TipcMtLookupByNum
This example creates a NUMERIC_DATA message and writes it to the message file data.msg
:
T_IPC_MSG_FILE msg_file; T_IPC_MT mt; T_IPC_MSG msg; msg_file = TipcMsgFileCreate("data.msg", T_IPC_MSG_FILE_CREATE_WRITE); if (msg_file == NULL) {return
; /* error */
} mt = TipcMtLookupByNum(T_MT_NUMERIC_DATA); if (mt == NULL) {return
; /* error */
} msg = TipcMsgCreate(mt); if (msg == NULL) {return
; /* error */
} if (!TipcMsgSetDest(msg, "/system/thermal")) {return
; /* error */
} if (!TipcMsgAppendStrReal8(msg, "bat1_voltage", 42.4)) {return
; /* error */
} if (!TipcMsgFileWrite(msg_file, msg)) {return
; /* error */
}
The output from this message in data.msg
would look like:
TIBCO SmartSockets™ Application Programming Interface Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |