This section includes a code example that shows how each of the monitoring classes can be used in an RTclient application. The source code file for this example is located in these directories:
This RTclient creates its connection to RTserver and performs IPC monitoring. The code for the monitoring example program is:
// mon.cxx -- RTclient example monitoring
#include <rtworks/cxxipc.hxx> #define MY_CLIENT_NAME "my_client"// ================================================================
//..mon_cb -- print monitoring msg type name
void mon_cb(T_IPC_CONN conn, T_IPC_CONN_PROCESS_CB_DATA data, T_CB_ARG arg) { TipcMsg msg(data->msg); TipcMt mt(msg.Type()); TutOut("%s call yields a %s response\n", (T_STR)arg, mt.Name()); }// mon_cb
// ================================================================
//..main -- main program
int main() { TipcMt mt; TipcSrv& server = TipcSrv::InstanceCreate(T_IPC_SRV_CONN_FULL); server.StdSubjectSetSubscribe(TRUE, FALSE); mt.Lookup(T_MT_MON_SUBJECT_SUBSCRIBE_STATUS); if (!mt) { TutOut("Message Type lookup failed.\n"); return T_EXIT_FAILURE; } if (server.ProcessCbCreate(mt, mon_cb, "mon.SubjectSubscribeWatch") == NULL) { TutOut("Failed to create process callback.\n"); return T_EXIT_FAILURE; } mt.Lookup(T_MT_MON_CLIENT_TIME_POLL_RESULT); if (!mt) { TutOut("Message Type lookup failed.\n"); return T_EXIT_FAILURE; } if (server.ProcessCbCreate(mt, mon_cb, "client_mon.TimePoll") == NULL) { TutOut("Failed to create process callback.\n"); return T_EXIT_FAILURE; } mt.Lookup(T_MT_MON_SERVER_GENERAL_POLL_RESULT); if (!mt) { TutOut("Message Type lookup failed.\n"); return T_EXIT_FAILURE; } if (server.ProcessCbCreate(mt, mon_cb, "server_mon.GeneralPoll") == NULL) { TutOut("Failed to create process callback.\n"); return T_EXIT_FAILURE; } TipcMon mon; TipcMonClient client_mon(T_IPC_MON_ALL); TipcMonServer server_mon(T_IPC_MON_ALL); if (!mon.SubjectSubscribeWatch("_all", TRUE)) { TutOut("Failed to setup watch.\n"); } if (!client_mon.TimePoll()) { TutOut("Failed to poll.\n"); } if (!server_mon.GeneralPoll()) { TutOut("Failed to poll.\n"); } if (!server.MainLoop(10.0)){ if (TutErrNumGet() != T_ERR_TIMEOUT_REACHED) { TutOut("Server main loop failed.\n"); } } return T_EXIT_SUCCESS; }// main
Compile and link the monitoring program (see Compiling, Linking, and Running on page 13 for generic instructions).
Start up RTserver, then use this command to run the monitoring program:
The output from the RTclient process is similar to this:
Connecting to project <rtworks> on <_node> RTserver. Using local protocol. Message from RTserver: Connection established. Start subscribing to subject </_workstation1_7876>. Start subscribing to subject </_workstation1>. Start subscribing to subject </_all>. mon.SubjectSubscribeWatch call yields a mon_subject_subscribe_status response server_mon.GeneralPoll call yields a mon_server_general_poll_result response client_mon.TimePoll call yields a mon_client_time_poll_result response
TIBCO SmartSockets™ cxxipc Class Library Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |