TipcMsgFile


Name

TipcMsgFile — user class for message file I/O operations

Synopsis

TipcMsgFile msg_file(file_name, create_mode); 
TipcMsgFile msg_file(file, create_mode); 

Inheritance

Description

The TipcMsgFile class provides a C++ binding to the SmartSockets TipcMsgFile API functions using a virtual I/O stream model. It allows you to create, read, write, append to and close SmartSockets message files using C++ stream I/O syntax.

Caution

None

Construction/Destruction

TipcMsgFile::TipcMsgFile

Syntax:
TipcMsgFile(T_STR file_name, 
            T_IPC_MSG_FILE_CREATE_MODE create_mode); 
Remarks:
Create a TipcMsgFile object with file_name and create_mode. file_name is the name of the file to use for the message file. create_mode specifies how to create the file.
C API:
TipcMsgFileCreate
 
  
Syntax:
TipcMsgFile(FILE *file,  
            T_IPC_MSG_FILE_CREATE_MODE create_mode); 
Remarks:
Create a TipcMsgFile object with file and create_mode. file is an existing file to use for the message file. create_mode specifies how to create (that is, open) the file.
C API:
TipcMsgFileCreateFromFile

TipcMsgFile::~TipcMsgFile

Syntax:
~TipcMsgFile(); 
Remarks:
Destroy a TipcMsgFile object. The destructor calls the C API function TipcMsgFileDestroy.
C API:
TipcMsgFileDestroy

Operators

TipcMsgFile::operator>>

Syntax:
virtual TipcMsgFile& operator>>(TipcMsg& msg); 
Remarks:
Read a message from a message file and assign it to the internal T_IPC_MSG field of a TipcMsg object. Any message that the object was managing at the time of the call is passed to TipcMsgDestroy().
C API:
TipcMsgFileRead

TipcMsgFile::operator<<

Syntax:
virtual TipcMsgFile& operator<<(TipcMsg& msg); 
Remarks:
Write the internal T_IPC_MSG field of a TipcMsg object to a message file.
C API:
TipcMsgFileWrite

Example

This example code fragment creates a file stream from the file data.msg, reads all the messages in the file using the extraction operator, and prints them out:

#include <rtworks/cxxipc.hxx> 
int main() 
{ 
  TipcMsgFile msg_file("data.msg", T_IPC_MSG_FILE_CREATE_READ); 
  if (!msg_file) { 
     // error 
  } 
  
TipcMsg msg_read; 
  while (1) { 
   msg_file >> msg_read; 
    if (!msg_file) { 
    break; 
  } 
  TutOut("Read a message.\n"); 
     
  msg_read.Print(TutOut); 
  } 
  // Note: file stream automatically destroyed 
} 

If the file data.msg contains this information:

numeric_data thermal { 
 voltage 33.4534 
 switch_pos -8843.8 
} 

The output is similar to this:

Read a message. 
type = numeric_data 
sender = <_file> 
dest = <thermal> 
max = 2048 
size = 75 
current = 0 
read_only = false 
priority = 0 
delivery_mode = best_effort 
ref_count = 1 
seq_num = 0 
resend_mode = false 
user_prop = 0 
data (num_fields = 4): 
  str "voltage" 
  real8 33.4534 
  str "switch_pos" 
  real8 -8843.8 

TIBCO SmartSockets™ cxxipc Class Library
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com