Name
VStoqkey � Find the message queue key of the given process name
Synopsis
#include <sys/types.h>
#include VS.h
key_t VStoqkey(procName)
char *procName; /* unique name associated with process */
Description
VStoqkey searches the voice system Bulletin Board (BB) and returns the message queue key (Qkey) associated with the specified procName . If the procName is not found, VStoqkey will assign an unused Qkey and BB slot to the procName. The slot is then partially posted with the procName and Qkey. VStoqkey will return the Qkey of hardcoded processes (processes not using dynamically assigned Qkey numbers) as well as of dynamic processes.
VStoqkey waits to acquire the lock (process semaphore) on the BB before searching and writing, and releases the lock before returning to the calling routine.
VStoqkey attaches the BB if not attached through VSstartup. Before returning it detaches the BB if it attached it to begin with.
Caution:
Each call to VStoqkey involves a linear scan of the Bulletin Board. Therefore, it is recommended that a process call VStoqkey once for each procName it expects to reference and internally stored the returned Qkeys before entering its main processing loop. From then on, VStoqkey need not be invoked since the Qkeys are already available.
Also be aware that a process conceivably could use up all the VS message queues by repeatedly calling VStoqkey with non-existent procNames.
Examples
main () {
key_t DBDIPQKEY;
key_t VCTDIPQKEY;
key_t BRIDGEDIPQKEY;
key_t myQkey;
char *emsg;
int nbytesRead;
long rcvtime
struct ms_univ msg; /* see mesg.h */
/* Post myself in BB and init BB global variables */
myQkey = VSstartup("CallBridge", 0, DIP_PROC);
if (myQkey <= 0) {
emsg = VSerror(myQkey);
fprintf(stderr,"VSstartup failed: %s\n", emsg);
sleep(20); /* sleep to avoid continuously respawning. */
exit(1);
}
DBDIPQKEY = VStoqkey(dbdip);
VCTDIPQKEY = VStoqkey(vctdip);
BRIDGEDIPQKEY = VStoqkey(bridgedip);
if (DBDIPQKEY < 0 || VCTDIPQKEY <0 ||
BRIDGEDIPQKEY < 0) {
/* Could not get Qkey */
/* Report the using VSerror, et_send error and cleanup */
sleep(10); /* to slow down continuous respawns. */
exit(1);
}
/* main processing loop */
while (1) {
/* read next message queue and switch on sender Qkey */
nbytesRead = mesgrcv(myQkey, &msg, sizeof(msg), 0, 0,
&rcvtime);
switch (msg.hd.morig) {
case DBDIPQKEY:
/* process message from Database DIP */
break;
case VCTDIPQKEY:
/* process message from Voice Coding DIP */
break;
case BRIDGEDIPQKEY:
/* process message from bridging DIP */
break;
default:
/* unknown sender */
break;
}
}
}
Diagnostics
Upon successful completion, the Qkey value is returned; otherwise one of the following errors is returned:
Error |
Description |
VS_EINVAL |
procName argument cannot be NULL |
VS_ELEN |
Length of procName is zero or greater than 15 characters in length |
VS_ERESV |
procName is reserved for hardcoded processes and the specified procName is not posted already |
VS_ENOPRT |
Non-printable character found in procNam |
VS_ENOFREE |
No BB slots available for posting process |