head	39.2;
access;
symbols
	V39_14:39.2
	V39_13:39.2
	V39_12:39.2
	V39_11:39.1
	V39_10:39.1
	c3910:39.1
	V39_9:39.1;
locks; strict;
comment	@** @;


39.2
date	95.07.25.12.30.54;	author StRuppert;	state Exp;
branches;
next	39.1;

39.1
date	95.05.10.14.59.25;	author StRuppert;	state Exp;
branches;
next	;


desc
@initial
@


39.2
log
@some cleanup and one bug fixed (from NDK)
@
text
@/*
** $PROJECT: c.datatype
**
** $VER: classbase.c 39.2 (25.07.95)
**
** by
**
** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
**
** (C) Copyright 1995
** All Rights Reserved !
**
** $HISTORY:
**
** 25.07.95 : 039.002 : some cleanup and one bug fixed (from NDK)
** 06.03.95 : 039.001 : initial
*/

/* ------------------------------- includes ------------------------------- */

#include "classbase.h"

/* ------------------------------ functions ------------------------------- */

LibCall Class *ENGINE (REGA6 struct ClassBase *cb)
{
	return(cb->cb_Class);
}

LibCall struct Library *LibInit (REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct Library * sysbase)
{
	cb->cb_SegList = seglist;
	cb->cb_SysBase = sysbase;
	InitSemaphore (&cb->cb_Lock);

	DB(("c.datatype init !\n"));

	if(cb->cb_SysBase->lib_Version >= 39)
	{
		cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
		cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
		cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
		cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
	} else
		cb = NULL;

  return((struct Library *) cb);
}

LibCall LONG LibOpen (REGA6 struct ClassBase *cb)
{
	LONG retval = (LONG) cb;

	ObtainSemaphore (&cb->cb_Lock);

	cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;

	if(++cb->cb_Lib.lib_OpenCnt == 1 && cb->cb_Class == NULL)
	{
		retval = (LONG) NULL;

		if((cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39)))
		{
			if((cb->cb_SuperClassBase = OpenLibrary(SUPERCLASSDATATYPE,39)))
			{
				if((cb->cb_Class = initClass(cb)))
					retval = (LONG) cb;

				if(!retval)
				{
					CloseLibrary(cb->cb_SuperClassBase);
					cb->cb_SuperClassBase = NULL;
				}
			}

			if(!retval)
			{
				CloseLibrary(cb->cb_DataTypesBase);
				cb->cb_DataTypesBase = NULL;
			}
		}

		if(!retval)
			cb->cb_Lib.lib_OpenCnt--;
	}

	ReleaseSemaphore (&cb->cb_Lock);

	return (retval);
}

LibCall LONG LibClose (REGA6 struct ClassBase *cb)
{
	LONG retval = NULL;
	LONG dexpunge;

	ObtainSemaphore (&cb->cb_Lock);

	if((--cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class != NULL)
	{
		if(FreeClass(cb->cb_Class))
		{
			cb->cb_Class = NULL;
			CloseLibrary(cb->cb_SuperClassBase);
			cb->cb_SuperClassBase = NULL;
			CloseLibrary(cb->cb_DataTypesBase);
			cb->cb_DataTypesBase  = NULL;
		}
	}

	dexpunge = (cb->cb_Lib.lib_Flags & LIBF_DELEXP);

	ReleaseSemaphore (&cb->cb_Lock);

	if(dexpunge)
		retval = LibExpunge (cb);

	return (retval);
}

LibCall LONG LibExpunge(REGA6 struct ClassBase *cb)
{
	BPTR seg = NULL;

	cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
	if(cb->cb_Lib.lib_OpenCnt == 0 && cb->cb_Class == NULL)
	{
		seg = cb->cb_SegList;

		Remove((struct Node *) cb);

		CloseLibrary(cb->cb_UtilityBase);
		CloseLibrary(cb->cb_DOSBase);
		CloseLibrary(cb->cb_GfxBase);
		CloseLibrary(cb->cb_IntuitionBase);

		FreeMem((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
	}

	return((LONG) seg);
}

@


39.1
log
@*** empty log	message	***
@
text
@d4 1
a4 1
** $VER: classbase.c 39.1 (06.03.95)
d15 1
d19 2
d23 2
d27 1
a27 1
   return(cb->cb_Class);
d32 14
a45 14
   cb->cb_SegList = seglist;
   cb->cb_SysBase = sysbase;
   InitSemaphore (&cb->cb_Lock);

   DB(("c.datatype init !\n"));

   if(cb->cb_SysBase->lib_Version >= 39)
   {
      cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
      cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
      cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
      cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
   } else
      cb = NULL;
d52 1
a52 1
   LONG retval = (LONG) cb;
d54 1
a54 1
   ObtainSemaphore (&cb->cb_Lock);
d56 1
a56 37
   /* Use an internal use counter */
   cb->cb_Lib.lib_OpenCnt++;
   cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;

   if(cb->cb_Lib.lib_OpenCnt == 1 && cb->cb_Class == NULL)
   {
      retval = (LONG) NULL;

      if((cb->cb_IFFParseBase = OpenLibrary ("iffparse.library", 39)))
         if((cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39)))
            if((cb->cb_SuperClassBase = OpenLibrary(SUPERCLASSDATATYPE,39)))
               if((cb->cb_Class = initClass(cb)))
                  retval = (LONG) cb;

      if(!retval)
      {
         if(cb->cb_IFFParseBase)
         {
            CloseLibrary(cb->cb_IFFParseBase);
            cb->cb_IFFParseBase = NULL;
         }

         if(cb->cb_DataTypesBase)
         {
            CloseLibrary(cb->cb_DataTypesBase);
            cb->cb_DataTypesBase = NULL;
         }

         if(cb->cb_SuperClassBase)
         {
            CloseLibrary(cb->cb_SuperClassBase);
            cb->cb_SuperClassBase = NULL;
         }

         cb->cb_Lib.lib_OpenCnt--;
      }
   }
d58 28
a85 1
   ReleaseSemaphore (&cb->cb_Lock);
d87 3
a89 1
   return (retval);
d94 2
a95 1
   LONG retval = NULL;
d97 1
a97 1
   ObtainSemaphore (&cb->cb_Lock);
d99 11
a109 2
   if (cb->cb_Lib.lib_OpenCnt)
      cb->cb_Lib.lib_OpenCnt--;
d111 1
a111 11
   if((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
   {
      if(FreeClass (cb->cb_Class))
      {
         cb->cb_Class = NULL;
         CloseLibrary(cb->cb_SuperClassBase);
         CloseLibrary(cb->cb_DataTypesBase);
         CloseLibrary(cb->cb_IFFParseBase);
      } else
         cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
   }
d113 1
a113 2
   if(cb->cb_Lib.lib_Flags & LIBF_DELEXP)
       retval = LibExpunge (cb);
d115 2
a116 1
   ReleaseSemaphore (&cb->cb_Lock);
d118 1
a118 1
   return (retval);
d123 6
a128 1
   BPTR seg = cb->cb_SegList;
d130 1
a130 1
   Remove((struct Node *) cb);
d132 4
a135 4
   CloseLibrary(cb->cb_UtilityBase);
   CloseLibrary(cb->cb_DOSBase);
   CloseLibrary(cb->cb_GfxBase);
   CloseLibrary(cb->cb_IntuitionBase);
d137 2
a138 1
   FreeMem((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
d140 1
a140 1
   return((LONG) seg);
@
