TipcSrvConnSubjectCbCreate create a subject callback
T_CB TipcSrvConnSubjectCbCreate(srv
,subject
,mt
,func
,arg
) T_IPC_SRVsrv
; T_STRsubject
; T_IPC_MTmt
; T_IPC_SRV_SUBJECT_CB_FUNCfunc
; T_CB_ARGarg
;
srv
connection handle to RTserver
subject
subject to create callback for (null means all subjects)
mt
message type to create callback for (null means all message types)
func
callback function
arg
user-defined argument to pass to func
New callback if successful, NULL
otherwise.
If TipcSrvConnSubjectCbCreate fails, it returns NULL
and sets the global SmartSockets error number to one of:
TipcSrvConnSubjectCbCreate creates a subject callback. These callbacks are called by TipcSrvConnMsgProcess to process a message when it is received by the subject
. If subject
is null, then func
is called for all messages of type mt
received by this RTclient. If mt
is null, then func
is called for every type of message received by subject
. If both subject
and mt
are null, func
is called for every message received by this RTclient.
Subject wildcards (* or ...) are supported.
Do not use both subject callbacks and connection process callbacks at the same time. Each callback type represents a different way of partitioning data and they are not orthogonal. Connection process callbacks partition the data according to message type; subject callbacks partition according to subjects. If these types of callbacks are used together, connection process callbacks are always of higher priority. Connection process callbacks are called in priority order until the last connection process callback is called. Then the subject callbacks are called in priority order.
The T_ENTRY declaration specifier is required in the definition of all callback functions as well as their prototypes.
TipcSrvConnSubjectCbLookup, TipcSrvConnSubjectDefaultCbCreate, TipcSrvConnSubjectDefaultCbLookup; see the TIBCO SmartSockets Utilities for information on TutCbSetPriority.
This example creates a subject callback for T_MT_INFO messages that are received by the /stocks
subject. A second subject callback is created for all message types received by the /emergency
subject. The emergency callback has a higher priority so that it will be called first:
/* =============================================================== */
/*..info_subject_cb -- process INFO messages recvd by /stocks */
void T_ENTRY info_subject_cb(conn, data, arg) T_IPC_CONN conn; T_IPC_SRV_SUBJECT_CB_DATA data; T_CB_ARG arg;/* not used */
{ T_STR info_str; T_STR subject; if (!TipcMsgSetCurrent(data->msg, 0)) {return
; /* error */
} if (!TipcMsgNextStr(data->msg, &info_str)) {return
; /* error */
} if (!TipcMsgGetDest(data->msg, &subject)) {return
; /* error */
} TutOut("Information message received by %s is %s\n", subject, info_str); }/* info_subject_cb */
/* =============================================================== */
/*..emergency_cb -- process messages recvd by emergency subject */
void T_ENTRY emergency_cb(conn, data, arg) T_IPC_CONN conn; T_IPC_SRV_SUBJECT_CB_DATA data; T_CB_ARG arg;/* not used */
{ T_STR mt_name; T_IPC_MT mt; if (!TipcMsgGetType(data->msg, &mt)) {return
; /* error */
} if (!TipcMtGetName(mt, &mt_name)) {return
; /* error */
} TutOut("WARNING: Emergency message received: %s\n", mt_name); }/* emergency_cb */
/* =========================================================== */
/*...code from calling function is below */
mt = TipcMtLookupByNum(T_MT_INFO); if (mt == NULL) {return
; /* error */
} cb = TipcSrvConnSubjectCbCreate(srv, "/stocks", mt, info_subject_cb, NULL); if (cb == NULL) {return
; /* error */
} cb = TipcSrvConnSubjectCbCreate(srv, "/emergency", NULL, emergency_cb, NULL); if (cb == NULL) {return
; /* error */
} if (!TutCbSetPriority(cb, 100)) {return
; /* error */
}
TIBCO SmartSockets™ Application Programming Interface Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |