oacdef_h

/*
**	Copyright 1993-2015, Fermi Research Alliance, LLC.  All rights reserved.
*/
/*
**++
**  FACILITY:  Open Access Client (OAC): oacdef.h
**
**      Open Access Servers include Open Access Front-end (OAF) and
**	Open Access Model (OAM). These servers dispatch Retdat/Setdat
**	requests to their clients, or contributors, call Open Access
**	Clients (OAC).
**
**  ABSTRACT:
**
**	oacdef.h defines types and macros for use by an OAC application.
**
**  AUTHORS:  K. Cahill, R Joshel
**
**  MODIFICATION HISTORY:
**
**	 4 Aug 93  R Joshel	created with extraction from oacdag.h
**	22 Jan 97  D Finstrom	added ljoac util request info, expanded urq_t 
**--
**/
/******************************************************************************/

#ifndef	_oacdef_h	/* include only once */
#define	_oacdef_h
#include "oasdef.h"
#include "acnet.h"

/*******************************************************************************
** macros
*/
#define FTD_ISEVENT(f)		((f).ftd_whole < 0)	  /* TRUE if event */
#define FTD_ISONESH(f)		((f).ftd_whole == 0)	  /* TRUE if one_shot */
#define FTD_ISPERIODIC(f) 	((f).ftd_whole > 0)	  /* TRUE if periodic */
#define FTD_PERIOD(f)		((f).ftd_whole & 0x7FFF)  /* period (60 hz) */
#define FTD_EVENT(f)		((f).ftd_clockevent)	  /* clock event */

/* The following definition is necessary for historic reasons. (Do not remove!) */
#define	OAC_CLASS_STATES	6	/* OAC class: low-byte of SSDN */

#define	OAC_CLASS_MIOAC		98	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SNAP		1	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MCRVCR	2	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MIRROR	3	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_VSAOSC	4	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SRFILE	5	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_NETPNG	6	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_RRORBL	7	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BUNNY5	7	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TCHROM	8	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BUNNY6	8	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DSTATS	9	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_CRYOPC	9	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_CACHE		10	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_GLFRIG	11	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ACLDEV	11	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ECCOLL	12	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MCOPC		12	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ARF1RF	13	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BOOLOS	14	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_NUM118	15	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SDASRV	16	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_BOOOAC	17	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_XMLRPC	18	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_HEARTB	19	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVCAL	20	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_OPCOAC	21	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_LJOAC		22	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_DPMOAC	23	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_CHLOAC	24	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_DBSETS	25	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_LVTEST	26	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_BRFOAC	27	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_TESTJY	28	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_MACSET	29	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_MJRROR	30	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_MONITR	31	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_TEVCOL	32	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_LRHVAC	32	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_CBSHOT	33	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_RACKMN	33	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_JPLOT		34	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_EXPOPC	34	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_ESTORE	35	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_NOVAPS	35	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_REMOTE	36	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_PBSHOT	37	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_NUM121	38	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_EVENTS	39	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_LJALRM	40	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_CRYTST	41	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MTAEMT	41	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MIBLMS	41	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_EVENTH	42	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BLMLOG	43	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DECAYS	44	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SRSAVE	45	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BIGSAV	46	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ERRORZ	47	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_FRCONS	48	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_NMLOPC	50	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_EVENTN	51	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_TRREC		52	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_SCHSAV	53	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_DLLRF		54	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_NDOSPS	54	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_CDFMON	55	/* OAC class: low-byte of SSDN */
#define OAC_CLASS_BCCDB		55	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DIGTUN	56	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MACALC	57	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TIMEAV	58	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVMTN	59	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MTNRNG	59	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_CONSAR	60	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_AUTUNE	61	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_VACAVE	62	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_NETMON	63	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_HALORT	64	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BATCH		65	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_VLOGGR	66	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ECBCAL	67	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_FSMDEV	68	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ALARMS	69	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_COLDCO	70	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_JABDEV	71	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ACCBPM	72	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_RRSHOT	73	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_CONSAD	74	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEMSBD	75	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ESTATS	76	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVTUN	77	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_CCPEFF	78	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEMITF	79	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BACKUP	80	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BOOMON	81	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TESTZY	82	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_CHECKS	83	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVSKY	84	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_CRTEMP	85	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_VLOGV		86	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SETS		87	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BOOCOL	88	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_WEATHR	89	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DEBBPM	90	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_FLOWSM	91	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SHOTKY	92	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_LEVELS	93	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SYNTHE	94	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DAMPE1	95	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_NMLBBM	95	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DAMPE2	96	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DAMPE3	97	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DAMPE4	98	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DAMPE5	99	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVCRG	100	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_PIDLUP	101	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MUCOOL	102	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SERBAL	103	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVICS	104	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MIBBIM	105	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TOR910	106	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_NUM101	107	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_DEBEKI	108	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_ACCIKI	109	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SHOTPR	110	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MISWIC	110	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SHOTPB	111	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_PBARSA	112	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVHLX	113	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_RCYSCH	114	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_EMINOS	116	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_MAGLEV	117	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_INITEV	118	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SBDCAL	119	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TLONBP	120	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVTTT	121	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_FLXCAP	122	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVATF	123	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_AP2BPM	124	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_TEVMON	125	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_JAERS		126	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_SETSDB	127	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BUNNY0	128	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BUNNY1	129	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BUNNY2	130	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BUNNY3	131	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_BUNNY4	132	/* OAC class: low-byte of SSDN */
#define	OAC_CLASS_LINBPM	133	/* OAC class: low-byte of SSDN */

/*******************************************************************************
** data types 
*/
/*
**  SSDN:  Many different things to many different people.  Thus the SSDN
**         is defined as a big union.  Individual device drivers and other
**	   routines might need their own private definitions added to this
**	   list. 
*/
typedef union SSDN
  {			/* Retdat SSDN: ssdn.r... */
  struct {
    ubyte_t typecode;	/* type code */
    ubyte_t subtypecode;/* expands on the type code */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ r;		    
	      		/* Raw dword SSDN: ssdn.l... */
    struct {
      int	dword0;	/* ssdn.l.dword0 */
      int	dword1;
      } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ l;
	      		/* Raw word SSDN: ssdn.w... */
  struct {
      short 	word0;	/* ssdn.w.word0 */
      short 	word1;
      short 	word2;
      short 	word3;
      } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ w;
	      		/* Raw byte SSDN: ssdn.b... */
  struct {
      ubyte_t	byte0;	/* ssdn.b.byte0 */
      ubyte_t	byte1;
      ubyte_t	byte2;
      ubyte_t	byte3;
      ubyte_t	byte4;
      ubyte_t	byte5;
      ubyte_t	byte6;
      ubyte_t	byte7;
      } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ b;
  } ssdn_t;

/*
** Frequency Time Descriptor
** etermines when data will be returned.  can be a clock event, repeatedly
** at a multiple of 60 HZ, or a single return
*/
typedef union FTD_OAC
  {
  short		ftd_whole;	/* the whole thing */
  ubyte_t 	ftd_clockevent;	/* clock event number */
  } ftd_t;

/*
** Device Entry Structure
** contains one device which is passed to an Open Access Client
*/
typedef struct DENTRY
  {
  ubyte_t 	dentry_di[3];   /* di */
  ubyte_t 	dentry_pi;	/* property index from database */
  ssdn_t	dentry_ssdn;	/* subsystem specific data block */
  uword_t 	dentry_len;	/* length of reply data	*/
  uword_t 	dentry_offset;  /* array offset */
  char    	dentry_data[1];	/* setting data; not used for requests */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ dentry_t;

/*
** Device List Header Block
** each device list which is sent to an Open Access Client 
** is an array of "struct DENTRY" entries.
*/
#define DLH_TC_RETDAT	0	/* RETDAT request */
typedef struct DLH
  {
  uword_t	dlh_tc;		/* typecode */
  uword_t 	dlh_ndevs;	/* number of device entries in this list */
  ftd_t		dlh_ftd;	/* Frequency Time Descriptor */
  ubyte_t	dlh_set;	/* setting flag when TRUE */
  ubyte_t	dlh_unused;	/* unused */
  dentry_t 	dlh_dentry[1];	/* list of entries */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ dlh_t;

/*
** Utility Request Block
** Miscellaneous non RETDAT/SETDAT requests
** 
*/
/*			0	reserved for RETDAT/SETDAT */
#define URQ_TC_STATS	1	/* statistics request */
#define URQ_TC_DUMP	2	/* spill some dump files */
#define URQ_TC_USER	3	/* user handled requests */
#define URQ_TC_RDOK	4	/* Retdat heartbeat to client uti */
#define URQ_TC_OPING	5	/* ping OAC */
#define URQ_TC_MIODMP	6	/* dump MIO stats */
#define URQ_TC_MIOCAN	7	/* cancel MIO pool */
#define URQ_TC_MIODEL	8	/* delete MIO pool */
#define URQ_TC_DBNEWS	9	/* register for dbnews messages */
#define URQ_TC_MIOSET	10	/* set MIO pool */
#define URQ_TC_LJON	11	/* lumberjack bugs on */
#define URQ_TC_LJOFF	12	/* lumberjack bugs off */
#define URQ_TC_LJOAC	13	/* ljoac util request */
#define URQ_TC_BUGS	14	/* toggle bugs flag */

#define LJ_SET_NODE     0       /* ljoac set node */
#define LJ_SET_ACCURACY 1       /* ljoac set accuracy */
#define LJ_SET_TIME     2       /* ljoac set start time */
#define LJ_SET_ALL      3       /* ljoac set node, accuracy, and start time */
#define LJ_READ_ALL     4       /* ljoac send node, accuracy, and start time */
#define LJ_ACTIVITY     5       /* time of last ljoac activity */

typedef struct URQ
  {
  uword_t	urq_tc;		/* typecode */
  uword_t	urq_stc;	/* sub-typecode */
  uword_t	urq_reqlen;	/* request length in bytes */
  uword_t	urq_rpylen;	/* reply length in bytes */
  ubyte_t	urq_data[1];	/* beginning of request data */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ urq_t;

typedef struct BIGURQ
  {
  urq_t		bigurq;		/* urq structure */
  ulong_t	bigurq_more[10];/* carrier for more information */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ bigurq_t;

/*
** Device Entry Reply Structure
** contains one reply passed to Open Access Server
** (setting request replies contain no 'devr_data', so 'devr_len' = 0)
*/
typedef struct DEVR
  {
  uword_t 	devr_len;	/* length of actual 'devr_data' in bytes */
  short 	devr_status;	/* status returned */
  char 		devr_data[1];	/* variable length: device reply data */
  } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ devr_t;	

/*	 
**  user service functions types
*/	 
typedef void	(*oac_usr_cleanup_t)(uword_t reqid, dlh_t *req);
typedef void	(*oac_reqfun_t)(uword_t reqid, dlh_t *request,
	  		oac_usr_cleanup_t *usrcleanup, devr_t *reply);
typedef void	(*oac_period_t)(void);
typedef void	(*oac_init_t)(void);
typedef void	(*oac_utilreq_t)(urq_t *reqdat, void *reply, uword_t *rpyid);
typedef void	(*oac_usr_dbnews_t)(dbnews_t *dbnarg);


/*******************************************************************************
** routines
*/

#ifdef __cplusplus
extern "C" {
#endif

int oac_mainloop(char *contrib_name, oac_reqfun_t read_func,
  		 oac_reqfun_t set_func, oac_period_t per_func,
	  	 int permin, oac_utilreq_t util_func, oac_init_t init_func);
int oac_user_reply(uword_t reqid);
void oac_free(void *ptr);
void *oac_malloc(int numbyt);
int oac_forward_sets(int numof, int *di, short *pi, char *setdat,
		     short *len, short *off);
int oac_timeout_adjust(short count_is);
int oac_dis(unsigned char oac_class, int *dis);
int oac_dbnews(oac_usr_dbnews_t usrfun);

#ifdef __cplusplus
}
#endif

#endif	/* include only once */