Get the name of a message queue or mutex with a specified identifier.
CS_RETCODE srv_getobjname(obj_type, obj_id, obj_namep, obj_namelenp, infop)
CS_INT obj_type; SRV_OBJID obj_id; CS_CHAR *obj_namep; CS_INT *obj_namelenp; CS_INT *infop;
Indicates whether the object is a mutex (SRV_C_MUTEX) or a message queue (SRV_C_MQUEUE).
The unique identifier of the object.
A pointer to a CS_CHAR buffer into which the name of the object is copied. The buffer must be large enough to accommodate the object name and, if obj_namelenp is NULL, a null character. The maximum length for an object name is SRV_MAXNAME characters, not including the null termination byte.
A pointer to a CS_INT that receives the length of the object. If obj_namelenp is NULL, the name that is found is copied into *obj_namep and terminated with a null character. Otherwise, the length of the name in *obj_namep is placed in *obj_namelenp.
A pointer to a CS_INT that is set to SRV_I_NOEXIST if the object with ID obj_id does not exist.
Returns |
To indicate |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
#include <ospublic.h>
#include <stdio.h>
/*
** Local Prototype
*/
CS_RETCODE ex_srv_getobjname PROTOTYPE((
CS_INT obj_type,
SRV_OBJID obj_id
));
/*
** EX_SRV_GETOBJNAME
** Example routine to illustrate the use of srv_getobjname to
** get the name of mutex or message queue with id = obj_id
** where obj_id was earlier returned by srv_createmutex or
** srv_createmsgq.
** Arguments:
** obj_type - Type of object; SRV_C_MUTEX or SRV_C_MQUEUE.
** obj_id - The unique identifier of the object.
** Returns:
** CS_SUCCEED Memory was allocated successfully.
** CS_FAIL Memory allocation failure occured.
*/
CS_RETCODE ex_srv_getobjname(obj_type, obj_id)
CS_INT obj_type;
SRV_OBJID obj_id;
{
CS_CHAR obj_name[SRV_MAXNAME+1];
CS_INT obj_namelen;
CS_INT info;
CS_RETCODE ret;
/* Get object name. */
ret = srv_getobjname(obj_type, obj_id, obj_name,
&obj_namelen, &info);
/* Print information depending on retcode */
switch(ret)
{
case CS_FAIL:
if (info == SRV_I_NOEXIST)
{
fprintf(stderr, “%s object with id: %d does not
exist\n”, (obj_type == SRV_C_MUTEX) ?
“Mutex” :“Message Queue”, (CS_INT)obj_id);
}
else
fprintf (stderr, “srv_getobjname failed\n”);
break;
case CS_SUCCEED:
fprintf (stderr, “%s name: %s for id: %d\n”,
(obj_type == SRV_C_MUTEX) ? “Mutex” : “Message Queue”,
obj_name, (CS_INT)obj_id);
break;
default:
fprintf (stderr, “Unknown return code from
srv_getobjname\n”);
ret = CS_FAIL;
break;
}
return (ret);
}
Open Server maintains a table that maps the unique identifiers of message queues and mutexes to their names. Given the identifier, srv_getobjname finds the name.
In some applications, it may make more sense to reference message queues or mutexes by name. srv_getobjid can be used to look up the identifier that is used by the mutex and message queue services.
srv_createmsgq,srv_createmutex, srv_deletemsgq, srv_deletemutex, srv_getmsgq, srv_getobjid,srv_lockmutex, srv_putmsgq, srv_unlockmutex