#ifndef XPKMASTER_OBJECTS_C
#define XPKMASTER_OBJECTS_C

/* Routinesheader

	Name:		objects.c
	Main:		xpkmaster
	Versionstring:	$VER: objects.c 1.0 (27.12.96)
	Author:		SDI
	Distribution:	PD
	Description:	object allocation functions and prefs sem get funcs

 1.0   27.12.96 : first version
*/

#include <pragma/exec_lib.h>
#include <exec/memory.h>
#include <xpk/xpk.h>
#include <xpk/xpkprefs.h>

#ifdef __MAXON__
  #define __asm
#endif

struct XpkPrefsSemaphore *GetPrefsSem(void)
{
  struct XpkPrefsSemaphore *sem;
  Forbid();
  if((sem = (struct XpkPrefsSemaphore *) FindSemaphore(XPKPREFSSEMNAME)))
    ObtainSemaphoreShared((struct SignalSemaphore *) sem);
  Permit();
  
  return sem;
}

static ULONG GetXpkObjectSize(ULONG type)
{
  switch(type)
  {
  case XPKOBJ_FIB:		return sizeof(struct XpkFib); break;
  case XPKOBJ_PACKERINFO:	return sizeof(struct XpkPackerInfo); break;
  case XPKOBJ_MODE:		return sizeof(struct XpkMode); break;
  case XPKOBJ_PACKERLIST:	return sizeof(struct XpkPackerList); break;
  };
  return 0;
}

#ifdef __cplusplus
  extern "C"
#endif

APTR __asm LIBXpkAllocObject(register __d0 ULONG type, register __a0 struct
TagItem *tags)
{
  ULONG size;
  
  if((size = GetXpkObjectSize(type)))
    return AllocMem(size, MEMF_PUBLIC|MEMF_CLEAR);

  return 0;
}

#ifdef __cplusplus
  extern "C"
#endif

void __asm LIBXpkFreeObject(register __d0 ULONG type, register __a0 APTR object)
{
  ULONG size;
  
  if((size = GetXpkObjectSize(type)))
    FreeMem(object, size);
}

#endif	/* XPKMASTER_OBJECTS_C */
