#ifndef LIBRARIES_PATCH_H
#define LIBRARIES_PATCH_H
/*****************************************************************************/
/*
**	Filename:	libraries/patch.h
**	Release:	3.0
**	Date:		04.05.94
**
**	definition of patch.library public structures and returncodes
**
**	(C) Copyright 1993/94 Stefan Fuchs
**	All Rights Reserved
*/
/*****************************************************************************/

#ifndef	EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef	EXEC_LISTS_H
#include	<exec/lists.h>
#endif	/* EXEC_LISTS_H */

#ifndef	EXEC_LIBRARIES_H
#include	<exec/libraries.h>
#endif	/* EXEC_LIBRARIES_H */

#ifndef	EXEC_SEMAPHORES_H
#include	<exec/semaphores.h>
#endif	/* EXEC_SEMAPHORES_H */


/*----------------------------------------------------------------------------*/
/* Structure required to install new patches via patch.library/InstallPatch() */

struct NewPatch				/*this structure is OBSOLETE from V2 on */
{
	APTR	NPAT_NewCode;		/* pointer to the patch code to be installed */
	ULONG	NPAT_NewCodeSize;	/* optional length of NPAT_NewCode in bytes  */
	APTR	NPAT_LibraryName;	/* pointer to the LibraryName                */
	UWORD	NPAT_LibVersion;	/* version of Library to open                */
	WORD	NPAT_LVO;		/* LVO of function to patch                  */
	WORD	NPAT_Priority;		/* Priority (-127...+126) of the patch       */
	UWORD	NPAT_Flags;		/* currently none defined (keep zero)        */
	APTR	NPAT_PatchName;		/* optional pointer to an IDString           */
	APTR	NPAT_Result2;		/* optional pointer to longword for Result2  */
};

/*----------------------------------------------------------------------------*/

/* ErrorCodes */
#define PATERR_Ok		0	/* Everything Ok				*/
#define PATERR_PatchInUse	1	/* Patch Usecount <> 0				*/
#define PATERR_InvalidHandle	2	/* Pointer to patch is not (no longer) valid	*/
#define PATERR_OutOfMem		3	/* Out of memory				*/
#define PATERR_OpenLib		4	/* Failed to open requested library		*/
#define PATERR_FuncNotStd	5	/* Function to patch is not in the standard format */
#define PATERR_PatchInstalled	6	/* Can't remove patch because another program has  */
					/* installed a non-patch.library patch later       */
#define PATERR_InvalidTags	7	/* There was an error in the combination of the specified Tags */
#define PATERR_OpenDev		8	/* Failed to open requested device */
#define PATERR_NoTaskList	9	/* PATT_AddTask... or PATT_RemTask... was specified for a patch, */
					/* which had no PATT_CreateTaskList set */
#define PATERR_TaskListExists	10	/* PATT_CreateTaskList was specified, but there already exists a TaskList */
#define PATERR_InvalidTaskList	11	/* PATT_CreateTaskList was specified with a wrong parameter */
/*----------------------------------------------------------------------------*/
#define	PatchName "patch.library"

/*----------------------------------------------------------------------------*/




/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* The following structures are not needed by normal patch.library applications */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
struct PatchBase
{
	struct Library LibNode;
	UBYTE PB_Flags;					/* no public flags defined */
	UBYTE PB_reserved1;
	ULONG PB_private1;
	struct SignalSemaphore	PB_Semaphore;		/* Semaphore to protect MasterPatchList */
	struct List		PB_MasterPatchHeader;	/* Listheader Structure for MasterPatch */

	/* ... */

};

/*----------------------------------------------------------------------------*/
/* Before accessing this structure, make sure MPS_Node.ln_Type is PS_TYPE_MASTER */

struct MasterPatch			/* This structure is READONLY */
{
struct	Node	MPS_Node;		/* ln_Name may contain a pointer to the name of the patched library */
	UWORD	MPS_Flags;		/* no public flags defined */
struct	MinList	MPS_PatchHeader;	/* Listheader Structure for Patch structures */
struct	Library	*MPS_PatchedLibraryBase; /* Pointer to patched Library */
	UWORD	MPS_PatchedLVO;		/* Library Vektor Offset in patched library */

	/* ... */

};

/*----------------------------------------------------------------------------*/
/* Before accessing this structure, make sure PS_Node.ln_Type is either PS_TYPE_USER or PS_TYPE_SYSTEM */
/* Make sure your program can handle lists, that do not contain any nodes of */
/* PS_TYPE_USER or PS_TYPE_SYSTEM */

struct	Patch			/* This structure is READONLY */
{
struct	Node	PS_Node;	/* ln_Name may contain a pointer to the name of the patch */
	UWORD	PS_Flags;	/* no public flags defined */

	/* ... */

};

/*----------------------------------------------------------------------------*/
/* public types for patch and masterpatch structures: */
#define PS_TYPE_MASTER	1	/* node is MasterPatch structure */
#define PS_TYPE_USER	2	/* node was installed by an Application using the library interface */
#define PS_TYPE_SYSTEM	3	/* node was installed by a special patch.library Systemsoftware (not yet implemented) */



#endif	/* LIBRARIES_PATCH_H */
