dpmlib_h

/*
**	Copyright 1991-2016, Fermi Research Alliance, LLC.  All rights reserved.
*/

#ifndef DPMLIBH_DEFINED		/* do this only once */
#define	DPMLIBH_DEFINED

#include <acnet.h>
#include "cns_data_structs.h"

struct DPM_MB_MESSAGE {
  unsigned short typeCode;
#define DPM_MTC_PROC 1
#define DPM_MTC_TERM 2
  short unused;
  unsigned int pid;
  struct ASB_DEF *thisASB;
  unsigned short eventFlag;
  } __attribute__((packed));

#define DPM_CENUMTSKS 8		/* max number of tasks */

struct DPM_CEUSG {		/* defines the CRL entry summary by task */
  int crs_l_crlsizes;		/* # bytes CRL and data */
  int crs_l_crlnpro;		/* # processed */
  int crs_l_crlupro;		/* # unprocessed */
  int crs_l_crlmdel;		/* # marked for delete */
  int crs_l_crlinerr;		/* # in error */
  int crs_l_crlat15;		/* # at 15 hz */
  int crs_l_crlat1;		/* # at 1 hz */
  int crs_l_crlone;		/* # of one shots */
  int crs_l_crlnoshot;		/* # of no shots */
  int crs_l_crlglobal;		/* # of global FTD's */
  int crs_l_crlother;		/* # other FTD's */
  int crs_l_crlmore2;		/* # with > 2 quanta */
  char crs_l_crltask[8];	/* 8 characters task name */
  } __attribute__((packed));

struct DPM_FRUSG {	/* defines the free space statistics */
  int frs_l_freunused;		/* # bytes unused */
  int frs_l_frenumunused;	/* # unused */
  int frs_l_freused;		/* # bytes used */
  int frs_l_frenumused;	/* # used */
  int frs_l_frelrcontig;	/* # bytes lrgst contig. */
  int frs_l_frenlrcontig;	/* # this size */
  int frs_l_fremdelete;	/* # bytes mrked delete */
  int frs_l_frenummdelete;	/* # marked delete */
  int frs_l_frecrlalloc;	/* # bytes CRL allocated */
  int frs_l_frenumcrl;		/* # CRL allocated */
  int frs_l_fresdralloc;	/* # bytes SDR allocated */
  int frs_l_frenumsdr;		/* # SDR allocated */
  int frs_l_fresrdalloc;	/* # bytes SRD allocated */
  int frs_l_frenumsrd;		/* # SRD allocated */
  int frs_l_frelesscrl;	/* # FRE entries < CRL */
  int frs_l_frenumtsks;	/* number of connected tasks */
  } __attribute__((packed));

struct DPM_USAGE_INFO {
  struct DPM_FRUSG fssum;		/* Free Space Summary */
  struct DPM_CEUSG cetsk[DPM_CENUMTSKS];/* CRL entry summary by task */
  int tskid[DPM_CENUMTSKS];		/* value of task ID */
  } __attribute__((packed));

struct DPM_ACNET_MESSAGE {
  unsigned short typeCode;
#define DPM_NTC_STATS    1
#define DPM_NTC_PROC     2
#define DPM_NTC_WHACKIN  3
#define DPM_NTC_WHACKOUT 4
#define DPM_NTC_WHACKNUM 5
#define DPM_NTC_PING	 6
#define DPM_NTC_SCHED	 7
#define DPM_NTC_DIPI     8
#define DPM_NTC_NODE     9
#define DPM_NTC_CNCT     10
#define DPM_NTC_ALLCRL	 11
#define DPM_NTC_ONECRL	 12
#define DPM_NTC_WTC	 13
  char structure[ACNET_PACKET_SIZE-sizeof(unsigned short)];
  } __attribute__((packed));

struct DPM_WHACK_INFO {
  int di;
#define DPM_WTC_ALLDEVS (-1)
  char slot;
  char scope;
#define DPM_WTC_CNRUN  1	/* obsolete */
#define DPM_WTC_CHGPGM 2	/* obsolete */
#define DPM_WTC_APPLY  1
#define DPM_WTC_UNDO   3
#define DPM_WTC_DELETE 4
  unsigned short fe;
  unsigned short alt_ssdn;
  unsigned short req_node;
  int req_task;
  int req_time;
  short ssdn_more;
  } __attribute__((packed));

#define	DIO_MODEL_NAME_LEN	8

struct DPM_WHACK_REQUEST {
  int di;
  char slot;
  char scope;
  char test;
  char model[DIO_MODEL_NAME_LEN];
  short ssdn_more;
  } __attribute__((packed));

struct DPM_WHACK_LIST {
  int di;
  char slot;
  char scope;
  char model[DIO_MODEL_NAME_LEN];
  char test;
  char unused;
  unsigned short req_node;
  int req_task;
  int req_time;
  short ssdn_more;
  } __attribute__((packed));

struct DPM_WHACK_MESSAGE {
    int num_whacks;
#define DPM_WHACK_HEADER (sizeof(int))
    struct DPM_WHACK_INFO whack[1];
  } __attribute__((packed));

struct DPM_DI_LIST {
  struct DPM_WHACK_INFO di;
  struct DPM_DI_LIST *next;
  } __attribute__((packed));

#define MAX_WHACKS \
((ACNET_PACKET_SIZE-DPM_WHACK_HEADER)/sizeof(struct DPM_WHACK_INFO))

struct DPM_WHACK_NUM {
  int slot[MAX_CONSOLES*MAX_PLD_SLOTS];
  } __attribute__((packed));

struct DPMUSING {
  int using_slot_index;		/* slot index if applicable */
  int using_r50_name;		/* ACNET rad50 taskname */
  int using_taskid;		/* process id */
  int	using_count;		/* count of matching entries this process */
  } __attribute__((packed));

struct DPMWHO {
  short dpmwho_status;		/* status return */
  unsigned int dpmwho_dipi;	/* device and property index */
  short dpmwho_node;		/* ACNET node number */
  short dpmwho_num_using;	/* number processes using di/pi */
  struct DPMUSING dpmwho_using[1]; /* 0 or more users */
  } __attribute__((packed));

struct DPMWHOREQ {
  short dpmwhoreq_tc;		/* request typecode */
  unsigned int dpmwhoreq_dipi;	/* device and property index */
  } __attribute__((packed));

typedef struct DPM_CNSCOM_REDIRECTION_INFO
    {
    int		redirection_type;
    unsigned int	redirection_slot_mask;
    int		redirection_di;
    union
	{
	DIO_SR_SPEC		sr;
	DIO_DL_SPEC		logger;
	DIO_SDA_SPEC		sda;
	DIO_TEST_OAC_SPEC	oac;
	DIO_MODEL_SPEC		model;
	} redirection_info;
    int		redirection_spare[7];
    unsigned int	redirection_counter;
    } __attribute__((packed)) DPM_CNSCOM_REDIRECTION_INFO;


/******************************************************************************/
/* 
**	function prototypes
*/
/******************************************************************************/

extern "C" {
int dio_read_cnscom_redirection_info(DPM_CNSCOM_REDIRECTION_INFO *redirect_info);
int dio_redirect(unsigned int num_redirects, short console,
		 struct DPM_WHACK_REQUEST *what, char central,
		 void const *data_source_info=(void *) NULL);
int dio_redirect_status(unsigned int *num_redirects, short console,
			struct DPM_WHACK_LIST **what, char central,
			void *data_source_info=(void *) NULL,
			int *redirect_type=(int *) NULL);
int dio_model_names(unsigned int *num_names, char ***names, char **flags);
void *dpm_alloc(unsigned short *num_bytes, int lock);
void dpm_dealoc(void *mem_addr, unsigned short num_bytes);
void dpm_dbareq(DBAREQ_INFO *dbareq, struct CRL_DEF *crl_entry);
void dpm_dpmdly();
struct DPM_STATICS *dpm_dpminit(short *error=(short *) NULL);
void dpm_freasblck();
void dpm_frefrelck();
void dpm_freprolck();
void dpm_getasblck();
void dpm_getfrelck();
void dpm_getprolck();
}

#endif