home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / utility / addnamedobject.c next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  3.6 KB  |  132 lines

  1. /*
  2.     $Id: addnamedobject.c,v 1.3 1997/01/27 13:17:12 digulla Exp $
  3.     $Log: addnamedobject.c,v $
  4.     Revision 1.3  1997/01/27 13:17:12  digulla
  5.     Added #include <proto/exec.h>
  6.  
  7.     Revision 1.2  1997/01/27 00:32:29  ldp
  8.     Polish
  9.  
  10.     Revision 1.1  1996/12/18 01:27:34  iaint
  11.     NamedObjects
  12.  
  13.     Desc: AddNamedObject() - adds a NamedObject to a given NameSpace.
  14.     Lang: english
  15. */
  16. #include <proto/exec.h>
  17. #include "utility_intern.h"
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <proto/utility.h>
  23.  
  24.     AROS_LH2(BOOL, AddNamedObject,
  25.  
  26. /*  SYNOPSIS */
  27.     AROS_LHA(struct NamedObject *, nameSpace, A0),
  28.     AROS_LHA(struct NamedObject *, object, A1),
  29.  
  30. /*  LOCATION */
  31.     struct UtilityBase *, UtilityBase, 37, Utility)
  32.  
  33. /*  FUNCTION
  34.     Adds a given NamedObject to a NameSpace which is addressed through
  35.     a second NamedObject. Allows you to link a common group of
  36.     NamedObjects together. If the NameSpace doesn't support duplicate
  37.     names, then a search for a duplicate will be made, and FALSE returned
  38.     if one is found.
  39.  
  40.     INPUTS
  41.     nameSpace   -    The NameSpace to add the NamedObject object to.
  42.             If this value is NULL, then the NamedObject will
  43.             be added to the root NameSpace. This is useful
  44.             for sharing NamedObjects between Tasks.
  45.     object        -    The NamedObject to add to the NameSpace.
  46.  
  47.     RESULT
  48.     If the NamedObject can be added to either the supplied NameSpace or
  49.     the system global NameSpace, this function will return TRUE.
  50.  
  51.     Otherwise it will return FALSE. This will generally happen when
  52.     the NSF_NODUPS flag is set and this NamedObject has the same name
  53.     as a second object, or when the object is already in a NameSpace.
  54.  
  55.     NOTES
  56.     See BUGS.
  57.  
  58.     EXAMPLE
  59.  
  60.     BUGS
  61.     Although the AmigaOS 3.1 autodocs did not say so, under 3.0 you
  62.     couldn't add a NamedObject to a NameSpace when the NamedObject you
  63.     were adding had a NameSpace itself. This has changed. This is
  64.     because the autodocs did not say this, and they are right :)
  65.  
  66.     SEE ALSO
  67.     utility/name.h, RemNamedObject()
  68.  
  69.     INTERNALS
  70.  
  71.     HISTORY
  72.     29-10-95    digulla automatically created from
  73.                 utility_lib.fd and clib/utility_protos.h
  74.  
  75. *****************************************************************************/
  76. {
  77.     AROS_LIBFUNC_INIT
  78.  
  79.     struct NameSpace *ns;
  80.     struct IntNamedObject  *no;  /* for object */
  81.     BOOL            ret; /* return value */
  82.  
  83.     /* Set to FALSE so lack of object returns FALSE */
  84.     ret = FALSE;
  85.  
  86.     if(object)
  87.     {
  88.     /* Set true since now only failure will set as false */
  89.     ret = TRUE;
  90.  
  91.     ns = GetNameSpace(nameSpace, UtilityBase);
  92.     no = GetIntNamedObject(object);
  93.  
  94.     /* First of all, see if we are already in a NameSpace, if so, just
  95.         exit. This way we don't do any damage to any linked lists.
  96.     */
  97.     if(no->no_ParentSpace)
  98.         return FALSE;
  99.  
  100.     ObtainSemaphore(&ns->ns_Lock);
  101.  
  102.     /*
  103.         By checking whether the Tail node exists, we check whether the
  104.         list has any nodes in it. If it doesn't then obviously we don't
  105.         have to check any other members of the list for name matches
  106.  
  107.         Don't use FindName() here because the comparison may not be
  108.         case sensitive. IntFindNamedObj() does all that.
  109.     */
  110.     if((ns->ns_Flags & NSF_NODUPS) && ns->ns_List.mlh_Tail)
  111.     {
  112.         if(IntFindNamedObj(ns, (struct Node *)ns->ns_List.mlh_Head, no->no_Node.ln_Name, UtilityBase))
  113.         ret = FALSE;
  114.         else
  115.         Enqueue((struct List *)ns, (struct Node *)&no->no_Node);
  116.     }
  117.     else
  118.         Enqueue((struct List *)ns, (struct Node *)&no->no_Node);
  119.  
  120.     if(ret == TRUE) /* Added to NameSpace ns */
  121.         no->no_ParentSpace = ns;
  122.  
  123.     ReleaseSemaphore( &ns->ns_Lock );
  124.  
  125.     } /* if( object ) */
  126.  
  127.     return ret;
  128.  
  129.     AROS_LIBFUNC_EXIT
  130.  
  131. } /* AddNamedObject */
  132.