srv_getobjname

Description

Get the name of a message queue or mutex with a specified identifier.

Syntax

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;

Parameters

obj_type

Indicates whether the object is a mutex (SRV_C_MUTEX) or a message queue (SRV_C_MQUEUE).

obj_id

The unique identifier of the object.

obj_namep

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.

obj_namelenp

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.

infop

A pointer to a CS_INT that is set to SRV_I_NOEXIST if the object with ID obj_id does not exist.

Returns

Table 3-55: Return values (srv_getobjname)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#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);
 }

Usage

See also

srv_createmsgq,srv_createmutex, srv_deletemsgq, srv_deletemutex, srv_getmsgq, srv_getobjid,srv_lockmutex, srv_putmsgq, srv_unlockmutex