/*static char *SCCSID = "@(#)notify.h	6.2 92/01/31";*/
#include "NOTIFY.NAM"
/*
 **	NOTIFY - structure for tracking open DosFindNotify's
 *
 *	Copyright Microsoft  1988.
 *
 *	HISTORY
 *	    25-Aug-89 by JR (John Rogers, JohnRo@Microsoft)
 *		- Converted HPFS from OS/2 1.2 to run with OS/2 2.0 (really
 *		  changed comment style to not use slash-slash, as it generates
 *		  too many warnings under MSC 5.2 with /W3 switch).
 *		18-Sep-1988	Initial version by Thomas Fenwick [thomasf]
 */

/*
 * This define enables the find notify hooks.  Notify routines are not
 * needed if this is not defined.
 */

#define FIND_NOTIFY

typedef struct NOTIFY NOTIFY, far *PNOTIFY;

struct NOTIFY {
	PNOTIFY dcpNext;	/* chain of active NOTIFY structs for dir */
	PNOTIFY dcpPrev;
	PSUBDIR psbd;		/* address of SUBDIR structure for this dir */
	USHORT cusChanges;	/* # of changes since last DosFindNotifyFirst
				 * or DosFindNofifyNext returned */
	USHORT cusNeeded;	/* # of changes needed: -1 if nobody waiting */
	USHORT usLevel;		/* info level requested by DosFindNotifyFirst */
	USHORT usSearchAttr;	/* search attribute */
	PPASCALSTRING ppsPattern; /* match pattern as a PASCAL string
				   * The len includes the length byte.
				   * ppsPattern->c == 0 if the pattern
				   * is '*' or '*.*' */
	BOOL  bFlagsNtfy;	/* see NF_xxx, below */
};
#ifdef BUGBUG
typedef struct NOTIFY far *PNOTIFY;
typedef struct NOTIFY { /* NOTIFY */
	PNOTIFY dcpNext;	/* chain of active NOTIFY structs for dir */
	PNOTIFY dcpPrev;
	PSUBDIR psbd;		/* address of SUBDIR structure for this dir */
	USHORT cusChanges;	/* # of changes since last DosFindNotifyFirst
				 * or DosFindNofifyNext returned */
	USHORT cusNeeded;	/* # of changes needed: -1 if nobody waiting */
	USHORT usLevel;		/* info level requested by DosFindNotifyFirst */
	USHORT usSearchAttr;	/* search attribute */
	PPASCALSTRING ppsPattern; /* match pattern as a PASCAL string
				   * The len includes the length byte.
				   * ppsPattern->c == 0 if the pattern
				   * is '*' or '*.*' */
	BOOL  bFlagsNtfy;	/* see NF_xxx, below */
} NOTIFY;
#endif


#define NF_ACTIVE 0x0001	/* a FindNotifyNext is active (not completed) */
#define NF_CLOSED 0x0002	/* a FindNotifyClose is active (not
				 * completed) */


#ifndef FIND_NOTIFY
#define NotifyCheck(action, psbd, pde, pfrm)
#define NotifyChkRmdir(psbd)

#else

/*
 *	NotifyCheck - macro to check for FindNotify processing.
 *
 *	This macro is invoked with psbd pointing to the SUBDIR struct of the
 *	directory containing the object being modified and pde as the
 *	directory entry being changed.  Action indicates what kind of change
 *	is happening (eg. Create, Delete, etc.)	 It is not used in the first
 *	release, since we only need to count the changes.
 *
 *
 *	The strange form of the macro body is to allow statements of
 *	the form:
 *	    if (xx) NotifyCheck(); else foo();
 *	to compile correctly as if the macro were a function.  Simply
 *	enclosing the macro body in {} doesn't work correctly.
 */

#define NotifyCheck(action, psbd, pde, pfrm)				 \
	    if ((psbd)->dcpNotifyChain.pFwd)				 \
		NotifyScan((psbd)->dcpNotifyChain.pFwd,(pde), (pfrm));	 \
	    else    /* dangling else closed by ; on end of invokation. */

/*
 *	NotifyChkRmdir - macro to do special notify processing on Rmdir.
 *
 *	This macro is invoked with psbd pointing to the SUBDIR struct of
 *	the directory being removed.  It insures that we wakeup anybody
 *	waiting for changes in that directory, since there won't be any
 *	more changes once the directory is deleted.
 *
 *	See the note above about the odd macro style.
 */

#define NotifyChkRmdir(psbd)			    \
	    if ((psbd)->dcpNotifyChain.pFwd)		    \
		NotifyRmdir((psbd)->dcpNotifyChain.pFwd);	\
	    else    /* dangling else closed by ; on end of invokation. */

#endif

int
NotifyOpen(PCRACKEDPATH pcp,	/* pointer to path name */
	   USHORT usSrchAttr,	/* search attribute (hidden/system/dir) */
	   PNOTIFY pnot,	/* ptr to NOTIFY struct */
	   USHORT usLevel,	/* level of info requested (must be == 1) */
	   PFRAME pfrm);


void
NotifyClose(PNOTIFY pnot, PFRAME pfrm);	     /* ptr to NOTIFY struct */


void far
NotifyScan(PNOTIFY pnotHead,	/* ptr to first NOTIFY struct in the list */
	   PDIRENT pde,		/* directory entry of file that changed */
	   PFRAME  pfrm);


void far
NotifyRmdir(PNOTIFY pnotHead);	/* ptr to first NOTIFY struct in the list */


int
NotifyWait(PNOTIFY pnot,	/* ptr to NOTIFY struct to wait on */
	   PUSHORT pcMatch,	/* ptr to number of changes to wait for
				 * also output value of changes seen */
	   ULONG timeout,	/* number of millisec to wait */
	   PFRAME  pfrm);

#include "NOTIFY.SEG"
