TIBCO SmartSockets makes heavy use of callbacks let you see into its internal processing. A callback is an object-oriented mechanism that allows you to be notified when a specified event occurs, such as a message is placed into the input queue. The callback can be associated with a certain event or with all events of a certain type (called global callbacks). When the event occurs, the specified callback function is called to notify you that the event happened.
A very brief introduction to callbacks is provided in this tutorial. See the TIBCO SmartSockets Application Programming Interface reference for a more detailed discussion of callbacks.
All TIBCO SmartSockets callback functions have these common characteristics:
void
). Callback functions can be used to affect the processing of a program, or to simply receive notification of some event.
A callback function is created using the function TipcSrvType
CbCreate where Type
is replaced with one of the types listed in Callback Types. For example, to create an error callback function, such as my_srv_error_cb, that is invoked when a non-recoverable error occurs on your program’s connection to RTserver, add this code:
In general, you should always check to make sure the callback was successfully created. You also need to write the code for the callback function my_srv_error_cb
.
A callback function is looked up using the function TipcSrvTypeCbLookup, where Type is replaced with one of the types listed in the section Callback Types.
Callback functions are manipulated using these TIBCO SmartSockets TutCb* utility functions:
See the TIBCO SmartSockets Utilities reference for more details on these functions.
Callbacks should be destroyed when they are no longer needed to free memory and ensure they are not invoked accidentally. In TIBCO SmartSockets, callbacks are destroyed using the TutCbDestroy function.
Within TIBCO SmartSockets there are a number of different callback types associated with a connection. In this lesson, you work with callbacks that are associated with a program’s connection to RTserver. Callbacks are conceptually equivalent to dynamically adding a line of code to a program. This table gives a brief summary of the different callback types available within TIBCO SmartSockets.
These callbacks that TIBCO SmartSockets offers allow you to customize your code and usage of TIBCO SmartSockets to almost any level. For example, if you are interested in adding your own security, you may use the Encode, Decode, Server Create, and Server Destroy callbacks.
Although there are many types of callbacks available in TIBCO SmartSockets, you only need to understand Process or Subject callbacks to begin processing messages in an event-driven manner. In this Lesson, you will see some example programs which illustrate the use of the common types of callbacks.
For more information on callbacks, see the TIBCO SmartSockets User’s Guide.
TIBCO SmartSockets™ Tutorial Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |