ul_cnscom_all_h

/******************************************************************************/
/*
**      $Id: ul_cnscom_all.h,v 1.21 2017/11/02 16:37:45 smeding Exp $
**
**	Structs, #defines, and prototypes required/defined by console common
**	but also needed by ul_clib, etc.
**
*/
/******************************************************************************/

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

#include "ul_cnscom_noX11.h" // console common stuff not requiring X11 stuff
#include <X11/Xlib.h>

/******************************************************************************/
/*
**	Structs, #defines, and prototypes required/defined by console
**	common but also needed by ul_clib, etc. that were originally
**	in ul_clib's cns_misc.h.
**
*/
/******************************************************************************/
#define MAX_CONSOLES_ALLOC	4	/* number console instance structs allocated */

#define CMD_LIN_SIZ		1024	/* size of CHGPGM command line  */

#define NUM_CNS_COLORS		32
#define MAX_PLD_SLOTS_ALLOC	26	/* number of application slot structs allocated */
#define MAX_CACHE	5000
#define MAX_XSERVER	4

typedef struct {
    int	spare1[66];
    short current_max_cache;		/* current number of cached tasks */
    short current_max_slots;		/* current number application slots */
    int	spare3;				/* spare - old privileges */
    unsigned short acnet_tr_node;	/* ACNET trunk/node address */
    int spare4;				/* spare - old settings lock */
    int spare_sets_node;		/* former name of Settings Server  */
    int spare_sets_task;		/* former task name for Settings Server  */
    short dacnet_clear_on_init;		/* clear stats on pgm start when TRUE */
    short dp_get_ftd_counter;		/* for unique one-shot FTDs */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CNS_MISC;

/*
;+ CLK_INFO	** NEW, SUPPORTS MULTICAST V6 **
;     Provide structure definition for accelerator clock information area in
;     CNSCOM.
;-
*/
typedef struct {
   	unsigned int ticks_f;	/* 0F count at last event occurrence */
   	unsigned int ticks_2;	/* 02 count at last event occurrence */
	unsigned int tsus;	/* timestamp at last event occurrence */
	    			/* in 1 uS units since previous event 02 */
	unsigned int gblcount;	/* event count seen by multicast node */

	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CLK_INFO;

#define MAX_HISTORY_EVENTS	65536	/* max events to save for a supercycle */
#define MAX_HISTORY_CYCLES	3	/* number of cycles to save history */

/*
;+ CLK_SCOPE
;	Structure definition for clock scope structure.
;-
*/
typedef struct {
    short current_cycle;		/* curent history cycle index */
    short max_hist_cycles;		/* MAX_HISTORY_CYCLES */
    int max_hist_events;		/* MAX_HISTORY_EVENTS */
    int gaps;				/* # of clock multicast interruptions */
    int gap_ticks;			/* missing 0F ticks */
    unsigned int gap_serial[5];		/* serial numbers of last missing msgs */
    unsigned short gap_count[5];	/* number of missing multicasts */
    short spare;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CLK_SCOPE;


#define MAX_CLK_TYPES	(4)	/* # of clock types TCLK, MIBS, RRBS, TVBS */

/*
;+ CYCLE_INFO2
;     Provide structure definition for accelerator cycle information area in
;     CNSCOM.
;-
*/
typedef struct {
   	unsigned int ticks_f;	/* 0F count at last event occurrence */
   	unsigned int ticks_2;	/* 02 count at last event occurrence */
	unsigned int tsus;	/* timestamp at last event occurrence */
	    			/* in 1 uS units since previous event 02 */
	unsigned short reset_flags;
	short spare;
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CYCLE_INFO2;

/*
;+ CLK_HIST_ENT
;	Clock history event entry.
;-
*/
typedef struct {
    union {
	struct {
    	    unsigned event:8;		/* clock event number */
	    unsigned ts:24;		/* full timestamp for TCLK */
	    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ a;
	struct {
    	    unsigned event:8;		/* clock event number */
	    unsigned low_ts:20;		/* low order timestamp bits for BS clocks */
	    unsigned tag:4;	    	/* which clock ts or count */
#define CLK_HIST_TAG_MIBS	(5)
#define CLK_HIST_TAG_RRBS	(6)
#define CLK_HIST_TAG_TVBS	(7)
#define CLK_HIST_TAG_COUNT	(15)
	    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ b;
	struct {
   	    unsigned event:8;		/* clock event number */
	    unsigned count:16;		/* count for multiple events */
	    unsigned clk_type:4;	/* which clock type */
	    unsigned tag:4;
	    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ c;
	} u;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CLK_HIST_ENT;

/*
;+ CLK_HISTORY2
;	Provide structure definition for accelerator cycle history information
;	area in CNSCOM.
;-
*/
typedef struct {
    int total_events;			/* count of entries in 'events' array */
    int gaps;				/* # of clock multicast interruptions */
    int gap_ticks;			/* missing 0F ticks */
    time_t ev00_time;			/* start of supercycle in GMT since 1970 */
    short ev00_millitm;			/* milliseconds */
    short clock_source;			/* code for clock multicast node */
    short test_flag;			/* TRUE if test clock */
    short bad_ts_flag;			/* TRUE if timestamps are not resetting */
    int ref_ts;				/* timestamp of event 00 */
    int spare[122];
    unsigned int event_count[MAX_CLK_TYPES*256]; /* counts for TCLK, MIBS, RRBS, TVBS */
    CLK_HIST_ENT events[MAX_HISTORY_EVENTS]; /* event entries (ev, ts, & tags) */
					/* in chron order */
					/* except 06,07,0E,18 */
					/* ev in low byte, ts in high 3 bytes */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CLK_HISTORY2;


typedef struct {
    int sr_file_num;
    }  __attribute__((packed)) REDIR_SR;

typedef struct {
    int lj_node;
    unsigned int lj_date_time;
    unsigned int lj_accuracy;
    }  __attribute__((packed)) REDIR_LJ;

typedef struct {
    int sda_file;
    int sda_case;
    int sda_set;
    int sda_usage;
    int sda_trynum;
    }  __attribute__((packed)) REDIR_SDA;

typedef struct {
    int node;
    int redirect_node;
    }  __attribute__((packed)) REDIR_OAC;

#define	CNSCOM_REDIRECT_MODEL_NAME_LEN	16

typedef struct {
    char model_name[CNSCOM_REDIRECT_MODEL_NAME_LEN];
    int	model_node;
    int model_class;
    }  __attribute__((packed)) REDIR_MODEL;

typedef struct {
    short console_number;		/* our console number */
    short knob_count;			/* knob count */
    unsigned int console_privs;		/* console privilege mask */
#define PRIV_ISOFFSITE	0X00000001	/* X-display is offsite */
#define PRIV_LNOCHG	0X00000002	/* locks are disabled when SET */
#define PRIV_LSTART	0X00000004	/* unlocked at startup when SET */
#define PRIV_LSETREAD	0X00000008	/* allow set for read when SET */
#define PRIV_LLOBIT	0X00000010	/* time lock low bit */
#define PRIV_LHIBIT	0X00000020	/* time lock high bit */
#define PRIV_COMFORT	0X00000040	/* comfort display */
#define PRIV_SLOT_7	0X00000080	/* start slot 7 application */
#define PRIV_IDLESTOP	0X00000100	/* CNSSTOP idle console */
#define PRIV_ALARMS	0X00000200	/* start Alarms */
#define PRIV_ALMONLY	0X00000800	/* only create alarms window */

#define PRIV_TMO_TCODE	0X00007000	/* application timeout time code */
#define PRIV_OFFSITEOK	0X00008000	/* offsite settings allowed */
#define PRIV_TMO_SHIFT	12		/* AND and shift to get timeout code */
#define PRIV_TMO_0	0x7fffffff	/* timeout code 0 = forever */
#define PRIV_TMO_1	30*60		/* timeout code 1 = 30 min */
#define PRIV_TMO_2	3600		/* timeout code 2 = 1 hour */
#define PRIV_TMO_3	2*3600		/* timeout code 3 = 2 hours */
#define PRIV_TMO_4	4*3600		/* timeout code 4 = 4 hours */
#define PRIV_TMO_5	8*3600		/* timeout code 5 = 8 hours */
#define PRIV_TMO_6	16*3600		/* timeout code 6 = 16 hours */
#define PRIV_TMO_7	32*3600		/* timeout code 7 = 32 hours */

#define PRIV_PLT_PRIO	0X00300000	/* plot priority mask */
#define PRIV_PLT_SHIFT	20		/* AND and shift to extract priority */
#define PRIV_PLT_PRI_USER 0x00000000	/* General User plot priority (0) */
#define PRIV_PLT_PRI_CR   0x00100000	/* Aux Control Room plot priority (1) */
#define PRIV_PLT_PRI_MCR  0x00200000	/* MCR plot priority (2) */
#define PRIV_PLT_PRI_SDA  0x00300000	/* SDA plot priority (3) */

#define PRIV_CURS	0x00400000	/* don't use TV dot cursor */
    unsigned int setting_lock;		/* settings lock */
#define LOCK_UNLOCK	0X80000000	/* unlocked when SET */
#define LOCK_SR_SLOT1	0X00000001	/* set for read allowed when SET  */
    clib_time_t activity_time;		/* ctime() of last activity */
    int lxmgr_raise_mask;		/* mask of ids to raise */
    int lxmgr_lower_mask;		/* mask of ids to lower */
    int lxmgr_iconify_mask;		/* mask of ids to iconify */
    int console_classes;		/* mask of console classes for runs */
    int lxmgr_big_pixels_mask;		/* mask of ids to big/small pixels */

    char copies_cpy_to[10];  		/* Copy to value for each slot (obsolete) */
    char fshare_write_ok;		/* filesharing writes ok when TRUE */
    char vmsIsDead;			/* padding for space formerly occupied
                                           by chgpgmLinuxVMSPreferred */
    char copies_bw_print_sets;		/* Use default or saved options */
    char copies_clr_print_sets;		/* Use default or saved options */
    short copies_bw_qnum;		/* Queue number */
    short copies_clr_qnum;		/* Queue number */
    char copies_bw_hditem;		/* Heading item selected */
    char copies_bw_bwitem;		/* Black/White item selected */
    short copies_bw_byitem;		/* Blue/Yellow item selected */
    short copies_bw_szitem;		/* Size item selected */
    char copies_bw_bditem;		/* Bold item selected */
    char copies_clr_hditem;		/* Heading item selected */
    char copies_clr_bwitem;		/* Black/White item selected */
    char copies_clr_bditem;		/* Bold item selected */
    short copies_clr_byitem;		/* Blue/Yellow item selected */
    short copies_clr_szitem;		/* Size item selected */
    short copies_dest;			/* Last Copy to value used */
    short copies_expansion[2];		/* copies structure expansion area */
    int  chgpgm_redirect;		/* Rad50 taskname of redirect */
    char mouse_focus;			/* srv_inx+1 to warp knob box focus */
    char dpm_redirect_ok;		/* allow data acquistion whack when T */
    char mouse_server;			/* current srv_inx of cibox mouse focus */
    char dec_kbd;			/* TRUE if DEC keyboard */
    char username[12];			/* console instance Linux username */
    Window focus_win[MAX_XSERVER];	/* multi-screen focus windows */ // XXX: X needed
    Window edge_win[MAX_XSERVER];	/* multi-screen top/bot edge detection windows */
    char device_copy_name[16];		/* Device Copy/Paste name */
    short lxmgr_winid;			/* window id for window action */
    short lxmgr_action;			/* window action code */
    short lxmgr_xpos;			/* x position for move window */
    short lxmgr_ypos;			/* y position for move window */
    short vms_node; 	    	    	/* vms companion node */
    char db_redirect;			/* use test database flag */
    char mcast_type;   	    	    	/* clock multicast type */
    int lxmgr_hide_mask;		/* mask of ids to hide */
    int lxmgr_unhide_mask;		/* mask of ids to un-hide */
    int spare[10];			/* for future stuff */
	/* for Erlang DPM redirect */
    int redir_type;
    int redir_slot_mask;
    int redir_di;
    union {
	REDIR_SR sr;
	REDIR_LJ lj;
	REDIR_SDA sda;
	REDIR_OAC oac;
	REDIR_MODEL model;
	} redir_info;
    int redir_spare[7];
    unsigned int redir_counter;

    long long lxmgr_raise_msk;		/* mask of ids to raise */
    long long lxmgr_lower_msk;		/* mask of ids to lower */
    long long lxmgr_iconify_msk;	/* mask of ids to iconify */
    long long lxmgr_hide_msk;		/* mask of ids to hide */
    long long lxmgr_unhide_msk;		/* mask of ids to un-hide */
	/* for fake clock playback */
    int fake_flags;			/* flags for whacked slots */
    int fake_hist_inx;			/* index into fake_history array */
    CLK_INFO fake_clk[256];		/* fake playback events */
    CYCLE_INFO2 fake_cycle[3];		/* fake playback accel cycle info */
    CLK_HISTORY2 fake_history; 		/* clock supercycle to play back */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CNS_STUFF;

/*
;+ DISK_CACHE
;     Provide symbol definitions for an entry in the disk cache table area in
;     PLD.  Each symbol is equated to the offset from the beginning of the
;     disk cache table entry area in PLD.  Always 32 bytes long.
;-
*/
typedef struct {
	int cdctkn;		/* system-wide taskname (RAD-50) */
	char cdctknascii[6];	/* system-wide taskname (ASCII) */
	short cdctkvr;		/* (unused) VAX task version # */
	short cdctksz;		/* (unused) VAX task image size in blocks */
	short cdctvvr;		/* TV image version # */
	short cdctvsz;		/* TV image size in bytes */
	short cdctpvr;		/* TPD image version # */
	short cdctpsz;		/* TPD image size in bytes */
	short cdcsts;		/* status bits(dev,cache,...) */
#define PCACHE 1			/* permanently cached */
	short cdcusg;		/* task usage count */
	clib_time_t cdctftime;	/* task file time */
	short cdcunused[1];	/* expansion area */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ DISK_CACHE;

/*
;+ CNS_ASB
;     Provide symbol definitions for active task status block area in CNSCOM.
;     Each symbol is equated to the offset from the beginning of the active
;     task list area in CNSCOM.
;-
*/
typedef struct {
	struct timeval asbtimechgpgm;	/* time of CHGPGM */
	struct timeval asbtimepld0;	/* time of PLD wakeup */
	struct timeval asbtimepldcpld;	/* time of CPLD reply */
	struct timeval asbtimepldterm0;	/* time PLD tells ap to terminate */
	struct timeval asbtimepldterm1;	/* time PLD sees ap gone */
	struct timeval asbtimeplddone;	/* time PLD done */
	struct timeval asbtimeapterm0;	/* time of AP INTYPE terminate */
	struct timeval asbtimeapterm1;	/* time of termination complete */
	struct timeval asbtimeapinit0;	/* time of AP initialization intype */
	struct timeval asbtimeapinit1;	/* time of AP ntv_connect */
	struct timeval asbtimeapinit2;	/* time of AP intype init done */
	struct timeval asbtimeintype2;	/* time of AP user init done */
	struct timeval asbtimespare[4];	/* time of */
	int asbatn;		/* active task name(RAD-50) */
	int asbwtn;		/* waiting task name(RAD-50) */
	short asbcmd_len;	/* command buffer used length */
	short asbtks;		/* (unused) VAX task image size in blocks */
	short asbspn;		/* PA subpage number */
	short asbtvmx[10];	/* TVMX line 2 repair area */
	pid_t asbpid;		/* Process ID */
	int asbactivity;	/* time of last user interaction */
	char asbsetlock;	/* user/library settings lock */
	char asbfslock;		/* user/library filesharing lock */
	char asbpldterm;	/* countdown forcexit suspension */
				/* set to 1 by script record
				   set to 2 by index page  when debugging */
	char asbscriptstate;	/* script state: PLD, replayer, task_slot */
#define SCRIPT_STATE_PLDCLEAR	0	 /* cleared by PLD on a program load */
#define SCRIPT_STATE_REPLAYING	1	 /* script replay in progress */
#define SCRIPT_STATE_REPLAYDONE	2	 /* script replay done */
	short asbznum;		/* generic PA number when Z loads */
	char asbwhacked;	/* slot whacked when TRUE */
	unsigned char asbchgnetxflags;
	    	    	    	/* PLD CHGNETX message flags from network call */
	char asbcalling_pgm[6];	/* program which called chgpgm to start this slot */
	char asbslotlock;   	/* program holds this lock while running */
#define IO_PLD	    	0    	   /* PLD performing i/o */
#define IO_AVAILABLE   	1    	   /* i/o is available */
#define IO_APPLICATION	2    	   /* application is performing i/o (intype sets and clears) */
#define IO_RELEASE     	3   	   /* application has released (intype exit handler) */
    	pthread_mutex_t pld_sync ; /* coordinate with PLD chgpgm lock */
	char asbpldload; 	/* PLD competing for slot lock resources, true or false */
	char asbsuppressunhide;	/* default task suppress unhide on next load */
	char asbhidden;	    	/* slot windows hidden on Linux when true */
	short asbunused[5];	/* expansion area */
	int asbclb_len;		/* Command line buffer length used */
	char asbatnascii[6];	/* active task name in ASCII */
	char asbclb[80];	/* (old unused) command line buffer from CHGPGM */
	char asbclbf;		/* command line buffer flag */
#define CLB_EMPTY	0	  /* no data available */
#define CLB_FILLED	1	  /* data available */
#define CLB_PUTCMD	2	  /* data transferred or 15 Hz occurred */
#define CLB_SCRIPT	3	  /* command line buffer contains a script */
	char asbterminate;	/* terminate state */
#define TERM_NOT	0	/* don't terminate */
#define TERM_NOW	1	/* terminate now */
#define TERM_SOON	2	/* terminate soon */
	char asbpgm_type;	/* program type */
#define	PTY_SA		0	  /* SA */
#define PTY_PA		1	  /* PA */
#define PTY_UTIL	2	  /* Alarms and utilities */
	char asbclbf_ieee;	/* true when command buffer floats from ieee platform*/
	char unused_sets[1103];	/* former queued setting buffer */
	char asbstate;		/* state of process */
#define STATE_CHGPGM 	0	  /* chgpgm done; PLD or VMS working */
#define STATE_INIT	1	  /* intype delivered initialization ITYPE */
#define STATE_PERIODIC	2	  /* intype delivered periodic ITYPE */
	unsigned int asbsets;	/* mask of console classes for sets */
	int unused_sets_addr;	/* former pointer for old sets */
	clib_time_t asbtermtime; 	/* time of terminate order */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CNS_ASB;

/*
;+ CNS_INDEX
;	Provide symbol definitions for Index Page definitions.
;-
*/
#define NUM_INDEX_PAGE_ALLOC	5   /* Number of index page structs allocated */
typedef struct {
	char idxhom;		/* Home Index Page ASCII descriptor */
	char idxsub;		/* Subpage of Home Index Page */
	int idxcur;		/* Current PA task including index */
	int idxlid;		/* Last PA task including index */
	int idxler;		/* Last PA task exit status - never cleared */
	int idxlex;		/* Extended status of last task */
	short idxflg;		/* PLD/Index flag byte */
#define IDXPLDSTS 1		   /* Bit 0	0 - Task exit status
						1 - PLD status of task */
#define IDXERRMSG 2		   /* Bit 1	0 - Index no errors to display
						1 - Index display err msg  */
	int idxrid;		/* Last CHGPGM requested task */
	int idxrer;		/* Last CHGPGM request error */
#define PLD_NOTASK 1		/* No such task */
#define PLD_NOPRIV 2		/* Cannot run task on this console */
#define PLD_ISBUSY 3		/* Single user task is active on another console */
				/* see extended status, i.e., idxrex, which */
				/* will contain the number of the console */
				/* on which the application is alredy running. */
#define PLD_OPABRT 4		/* Operator initiated abort */
#define PLD_NOSTRT 5		/* Task failed to start in alloted time */
#define PLD_DOWN   6		/* Communications failure with CPLD */
#define PLD_NOT_AVAIL 7		/* PROGRAM NOT AVAILABLE FOR THIS TYPE OF CONSOLE */
#define PLD_BADARG 8	    	/* CPLD didn't like request */
#define PLD_LOCK_ERR 9		/* PROGRAM LOADS TEMPORARILY SUSPENDED BY THE MCR */
#define PLD_FORCE  30		/* Forcexit due to termination timeout */
	int idxrex;		/* Last CHGPGM extended status */
				/* Next PLD PA load request */
	int idxtxt;		/* ASCII page number including index */
	short idxtvvr;		/* TV version # or 0 */
	short idxtvsz;		/* TV image size in bytes */
	short idxtpv;		/* TPD version # or 0 */
	short idxtps;		/* TPD image size in bytes */
	short idxhvr;		/* Index header version number */
	int idxfid;		/* INDEXPAGE.TXT file ID (2 words) */
	int idxfer;		/* FORTRAN error #, last PA */
	int idxepc;		/* PC of FORTRAN error, last PA */
	char suppressPutIdx;	/* suppress putidx when exposing after VMS ap exit */
	char unused1;	    	/* expansion area */
	short idxunused[9];	/* expansion area */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CNS_INDEX;

/*
;+ XSERVER
;     Provide structure definition for XSERVER area in CNSCOM.
;     TVMGR and LXMGR use this to communicate about X display colors.
;-
*/
typedef struct {
    int plane_mask;			/* mask of our bits */
    int pixels[NUM_CNS_COLORS];		/* pixel color values */
    Colormap colormap;			/* Colormap to use */
    VisualID visualid;			/* ID of Visual to use */
    int depth;				/* depth of Visual to use */
    char blink_enable;			/* blinking supported flag */
    char tvmgr_msg;			/* message flags from TVMGR to PA0001 */
#define TVMGR_MSG_8COLOR	1	/* using  8 colors, no graphics blink */
#define TVMGR_MSG_PRIVATE	2	/* using private colormap */
#define TVMGR_MSG_NOFONTS	4	/* can't load ACNET fonts */
#define TVMGR_MSG_FONTPATH	8	/* added fontserver to fontpath */
    char unused_char[2];
    int unused_long[6];
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ XSERVER;

/* Function prototypes (ANSI C) */
#ifdef __cplusplus
extern "C" {
#endif
char *cnscom_date(void);
int get_cnscom_setpriv(unsigned char slot, int instance);
int get_cnscom_setpriv(unsigned char slot, int instance);
CNS_MISC* get_cnscom_ptr_misc ( void );
CNS_STUFF *get_cnscom_ptr_stuff ( int instance );
unsigned short int get_cnscom_local_node();
CNS_ASB* get_cnscom_ptr_cns_asb ( int index, int instance );
XSERVER* get_cnscom_ptr_xserver ( int index, int instance );
CLK_INFO *get_cnscom_ptr_clk_info ( int clk_type, int mcast_type );
int get_cnscom_console_class(int instance);
char *get_cnscom_idxptr_recall (int instance);
void get_cnscom_pld_sync_lock(CNS_ASB *asbP);
CLK_SCOPE *get_cnscom_ptr_clk_scope( int mcast_type=0 );
CNS_INDEX* get_cnscom_ptr_cns_index ( int index, int instance );
CNS_INDEX *get_cnscom_ptr_cns_index (int inx, int instance);
void free_cnscom_pld_sync_lock(CNS_ASB *asbP);
DISK_CACHE *get_cnscom_ptr_disk_cache();
DISK_CACHE *get_cnscom_ptr_disk_cache();
char is_cnscom_pld_initialized();
char is_cnscom_pld_initialized();
void get_cnscom_pld_chgpgm_lock();
void get_cnscom_pld_chgpgm_lock();
char *get_cnscom_ptr_cmd_lin_buf(int index, int instance);
CYCLE_INFO2 *get_cnscom_ptr_cycle_info2 ( int mcast_type=0 );
void free_cnscom_pld_chgpgm_lock();
void free_cnscom_pld_chgpgm_lock();
CLK_HISTORY2* get_cnscom_ptr_clk_history2 ( int cycle_number, int mcast_type=0 );
#ifdef __cplusplus
}
#endif

/******************************************************************************/
/*
**	Structs, #defines, and prototypes required/defined by console
**	common but also needed by ul_clib, etc. that were originally
**	in ul_clib's tv.h.
**
*/
/******************************************************************************/
#define TV_MAX_ROWS	65

#define TV_MAX_COLS	200

#define NUM_TVS_ALLOC	52		/* Number of TV structs allocated per console instance */
    	    	    			/* Only 17 of the TVs are used at this time.
					 * The rest are for possible future use.
                                         * TVs are maintained in console common as
                                         * cnscom.tv_share[console][0].title = "PA D16 Radix Conversion<NoSets>"
                                         * cnscom.tv_share[console][1].title = "PA: Touch Panel"
                                         * cnscom.tv_share[console][2].title = "PB D17 Phone Index<NoSets>"
                                         * cnscom.tv_share[console][3].title = "PB: Touch Panel"
                                         * cnscom.tv_share[console][4].title = "Accelerator Alarms"
                                         * cnscom.tv_share[console][5].title = "Utilities CLX39"
                                         * cnscom.tv_share[console][6].title = "PC D80 Examine Database<NoSets>"
                                         * cnscom.tv_share[console][7].title = "PC: Touch Panel"
                                         * cnscom.tv_share[console][8].title = "SA: TV pop up"
                                         * cnscom.tv_share[console][9].title = "SB: TV pop up"
                                         * cnscom.tv_share[console][10].title = "SC: TV pop up"
                                         */

#define NUM_SWITCHS	32		/* number of switches / touch panel */
#define NUM_TP		3		/* number of touch panels */

#define TV_QSIZE	100		/* number of entries in tv queue */
#define TV_ITITLE_LEN	30		/* length of TV icon title */
#define TV_TITLE_LEN	80		/* length of TV title */
#define KEY_FIFO_SIZE	(5*2)		/* size of key press FIFO */
    					/* (should be mult of 2 for alignment) */

/* Note!!!!!!!!!!!!!!!!
	This same structure is also defined in the file ul_clib/cns_data_structs.h.
	If this structure is changed, it should be changed in both files.
*/

#ifndef XCHAR_DEFINED

#define	XCHAR_DEFINED

typedef struct XCHAR {			/* TVMX character/color format */
    char ch;				/* C130 (ASCII) character */
    char xcolor;			/* C130 color/blink codes */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ XCHAR;

#endif

typedef struct {
    unsigned char uprow;				/* switch upper TV row */
    unsigned char lcol;				/* switch left TV column */
    unsigned char dnrow;				/* switch lower TV row */
    unsigned char rcol;				/* switch right column */
    char flags;				/* switch flags */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ SWITCH;

typedef struct {
    char code;
    unsigned char row;
    unsigned char col;
    char xcolor;
    short count;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_WTXT;

typedef struct {
    char code;
    unsigned char uprow;
    unsigned char lcol;
    unsigned char dnrow;
    unsigned char rcol;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_CLRRCT;

typedef struct {
    char code;
    unsigned char uprow;
    unsigned char lcol;
    unsigned char dnrow;
    unsigned char rcol;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_PNTRCT;

typedef struct {
    char code;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_CLEAR;

typedef struct {
    char code;
    unsigned char nrows;
    unsigned char ncols;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_SFMT;

typedef struct {
    char code;
    unsigned char rowa;
    unsigned char rowb;
    unsigned char locol;
    unsigned char hicol;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_SCRL;

typedef struct {
    char code;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_WTITLE;

typedef struct {
    char code;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_NOOP;

typedef struct {
    char code;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_URL;

typedef struct {
    char code;
    char move_flag;
    short x_offset;
    short y_offset;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_MAP;

typedef struct {
    char code;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_UNMAP;

typedef struct {
    char code;
    char fsize;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_FSIZE;

typedef struct {
    char code;
    short xpos;
    short ypos;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TV_WPOS;

typedef union {
    char code;				/* function code */
    TV_WTXT wtxt;
    TV_CLRRCT clrrct;
    TV_PNTRCT pntrct;
    TV_CLEAR clear;
    TV_SFMT sfmt;
    TV_SCRL scrl;
    TV_WTITLE wtitle;
    TV_NOOP tvnoop;
    TV_MAP tvmap;
    TV_UNMAP tvunmap;
    TV_URL tvurl;
    TV_FSIZE tvfsize;
    TV_WPOS tvwpos;
    } TVQITM;

typedef struct {			/* TV queue structure */
    short volatile nitems;		/* number of items in queue */
    short in_inx;			/* TV queue input index */
    short out_inx;			/* TV queue output index */
    short volatile flush_flag;		/* flush flag */
    TVQITM qitm[TV_QSIZE];		/* queue items */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TVQUEUE;


typedef struct {			/* Keyboard FIFO item structure */
    unsigned char row;			/* TV row key was pressed */
    unsigned char col;			/* TV col key was pressed */
    KeySym keysym;			/* keysym of key pressed */
    unsigned int modstate;		/* Button and key modifier state */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ KEY_FIFO_ITEM;

typedef struct {
    Window win;				/* window id for TV screen */
    Display *dpy;			/* TVMGR pointer to display structure */
    int srv_inx;			/* server index */
    int	pix_per_char_x;			/* pixels per character horz */
    int	pix_per_char_y;			/* pixels per character vert */
    short x_offset;			/* x offset in pixels */
    short y_offset;			/* y offset in pixels */
    int y_descent;			/* y descent under baseline in pixels */
    short xpos;				/* X - Position to tell XMoveWindow to  */
    short ypos;				/* Y - restore window on screen */
    int curs_row;			/* text cursor row */
    int curs_col;			/* text cursor col */
    int scrl_locol;			/* TVWNDO low column */
    int scrl_hicol;			/* TVWNDO high column */
    int mgr_events;			/* events selected by TVMGR process */
    int	kbd_time;			/* server time of last Button1 down */
    Cursor focus_curs;			/* cursor when window has focus */
    short nrows;			/* number of rows on TV */
    short ncols;			/* number of cols on TV */
    short user_nrows;		/* user's number of rows */
    short user_ncols;		/* user's number of cols */
    short width;			/* window width in pixels */
    short height;			/* window height in pixels */
    short old_ptr_x;			/* old mouse pointer x position */
    short old_ptr_y;			/* old mouse pointer y position */
    char url[160];			/* null-term www url to display */
    unsigned int modstate;		/* KB int modifier state */
    char kb_case;			/* keyboard case (upper,mixed,lower) */
    KEY_FIFO_ITEM key_fifo[KEY_FIFO_SIZE]; /* key FIFO*/
    short screen_width;			/* width of entire X server screen */
    short screen_height;		/* height of entire X server screen */
    char new_font_inx;			/* which font to change to */
    char spare_xxx[4684];		/* NOT USED, was old screen text */
    int wm_delay;			/* WM busy delay, 15th's */
    char manual_paste;  	    	/* application handles TV paste flag*/
    char clip_export;	    	    	/* export to clipboard flag */
    char ititle[TV_ITITLE_LEN];		/* icon title (null terminated) */
    char visible;			/* TRUE if tv window is visible */
    char scrolling;			/* TRUE if scroll in progress. */
    char font_inx;			/* which font for this window */
    char resize_count;			/* ConfigureNotify events to expect */
    char kb_xcolor;			/* keyboard color codes */
    char kb_upcase;			/* keyboard upper case flag NOT USED */
    char focus_flag;			/* keyboard focus flag */
    unsigned char blink_count;		/* blink processing counter */
    char kbd_int;			/* INTYPE keyboard interrupt flag */
    char win_typ;			/* TVMGR window type, PA, TP, SA */
#define	PA_WIN		0		/* PA/ALARM/UTIL main window */
#define TP_WIN		1		/* Touch Panel window */
#define SA_WIN		2		/* SA pop up window */
    char jitter_time;			/* text cursor de-jitter timer */
    char text_curs_color;		/* text cursor color */
    unsigned char down_row;		/* button down row */
    unsigned char down_col;		/* button down col */
    XSERVER *xs_ptr;			/* pointer to XSERVER structure */
    unsigned char up_row;		/* button up row */
    unsigned char up_col;		/* button up col */
    char report_up_flag; 		/* report button up flag */
    char iconified;			/* iconified state flag */

    unsigned short tvm;			/* start of statistics */
    unsigned short tvmx;
    unsigned short tvblnk;
    unsigned short tvceol;
    unsigned short tvceop;
    unsigned short tvclr;
    unsigned short tvcolr;
    unsigned short tvfill;
    unsigned short tvsfmt;
    unsigned short tvscrl;
    unsigned short tvscrs;
    unsigned short tvwndo;
    unsigned short tvdisp;
    unsigned short tvsave;
    unsigned short tvtitl;
    unsigned short wmake;
    unsigned short wdelet;
    unsigned short tvurl;
    unsigned short tvmap;
    unsigned short tvunmap;
    unsigned short tvfsize;
    unsigned short tv_last_char;

    unsigned short wtxt;
    unsigned short clrrct;
    unsigned short pntrct;
    unsigned short clear;
    unsigned short sfmt;
    unsigned short scrl;
    unsigned short scrs;

    unsigned short wtitle;
    unsigned short tvnoop;
    unsigned short wwwurl;
    unsigned short map;
    short unused_short1[3];

    unsigned short expose;
    unsigned short fcolor;
    unsigned short bcolor;
    XCHAR overwritten_char;		/* for tv_last_char */
    XCHAR new_char;			/* for tv_last_char */
    unsigned short unused_short2[2];

    unsigned int user_chars;
    unsigned int mgr_chars;
    time_t update_time;			/* time of last user write */
    unsigned int unused_long[7];	/* end of statistics */

    TVQUEUE tv_queue;			/* queue of requests to TVMGR */
    int unused_long2[15];
    short key_fifo_in_inx;		/* input index for key FIFO */
    unsigned char key_echo;		/* echo keyboard flag */

    char mapped;			/* Window is mapped */
    char title[TV_TITLE_LEN];		/* window title (null terminated) */
    char text[TV_MAX_ROWS][TV_MAX_COLS]; /* screen text */
    char xcolor[TV_MAX_ROWS][TV_MAX_COLS]; /* screen colors */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ TVSCREEN;

/* Function Prototypes. */
extern "C" {
int cnscom_get_tv_que(TVSCREEN *tv_ptr, TVQITM *qitm);
TVQUEUE *cnscom_get_tv_que_ptr(int index, int instance);
void cnscom_put_tv_que(TVSCREEN *tv_ptr, TVQITM *qitm);
TVSCREEN *get_cnscom_ptr_tv(int index, int instance);
void cnscom_init_tv_que(TVSCREEN *tv_ptr);
void cnscom_wait_tv_que(TVSCREEN *tv_ptr);
TVQUEUE *cnscom_get_tv_que_ptr(int index, int instance);
SWITCH *get_cnscom_ptr_switch(int tp_inx, int instance);
}

/******************************************************************************/
/*
**	Structs, #defines, and prototypes required/defined by console
**	common but also needed by ul_clib, etc. that were originally
**	in ul_clib's lx.h.
**
*/
/******************************************************************************/
#define MAX_VECTORS  100		/* max number chained vectors (even) */

#define NUM_LXS_ALLOC	104		/* number of Lexidata structs (graphics window) allocated */

typedef struct {
        Pixmap pix;             /* pixmap address */
	short unused_a[2];
        short split;        	/* pixmap used for */
#define P_NOEXIST	0		/* pixmap does not exist */
#define P_4HCOPY	1		/* for expose/hardcopy */
#define P_4BLINK	2		/* pixmap for truecolor blink */
        short unused_b[3];
	GC	pix_gc;		/* pixmap graphics context */
	int unused_c;
	Pixmap curs_pix;	/* cursor type */
	int unused_d[2];
	short  width;		/* width of LX window */
	short height;		/* height of LX window */
	short expansion[11];	/* expand safely */
        } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ LXPIXDEF;


#define LX_QSIZE 25002			/* number of bytes in LX_QUEUE */
typedef struct {			/* LX queue structure */
    volatile short nbytes;		/* number of bytes used in queue */
    short in_inx;			/* LX queue input byte index */
    short out_inx;			/* LX queue output byte index */
    volatile short flush_flag;		/* flush flag */
    char 	qitm[LX_QSIZE];		/* queue items */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ LXQUEUE;

typedef struct {
	Display *dpy;				/* display connection */
	Window win;				/* window id for LX screen */
	void (*flush_funct)();			/* function to flush */
 	GC win_gc;				/* window graphics context */
	Cursor focus_cursor;			/* focus cursor */
	Cursor nofocus_cursor;			/* no focus cursor */
	Cursor cursor;				/* cursor */
	GC	cursor_gc;			/* cursor pixmap graphics context */
	int gcfunction;				/* graphics function */
	int linewidth;				/* line width */
	int linestyle;				/* line style */
	int plane_mask;				/* plane mask */
	XPoint chainvectors[MAX_VECTORS];	/* chained vectors */
	short numchainvectors;			/* number of chained vectors */
	short blinkrate;			/* blink rate */
	short text_size;			/* text size */
	short text_rotation;			/* text rotation */
	short text_additive;			/* additive text write */
	short text_reverse;			/* reverse video text */
	short text_height;			/* text height */
	short text_width;			/* text width */
	short text_lbearing;			/* text lbearing */
	short text_ascent;			/* text ascent */
	short curslim_x1;			/* cursor limit x1 */
	short curslim_y1;			/* cursor limit y1 */
	short curslim_x2;			/* cursor limit x2 */
	short curslim_y2;			/* cursor limit y2 */
	short curs_intype;			/* 0-lxmgr stuffit, 1-stuffed,
						   2-deliverit */
	short curs_saved_x;			/* cursor saved x after int */
	short curs_saved_y;			/* cursor saved y after int */
	short curs_x;				/* cursor x */
	short curs_y;				/* cursor y */
	short winid;				/* window id for copies */
	unsigned short linepattrn;		/* last dashed line pattern */
	short linepatsiz;			/* last dashed pattern size */
	Window tv_popup_win;			/* TV popup window ID */
    	int unused_t[9];   	    	    	/* old title */
	char blinking;				/* blinking when TRUE */
	unsigned char hcmode;			/* hardcopy mode */
	unsigned char forecolor;		/* foreground color */
	unsigned char backcolor;		/* background color */
	unsigned char focus;			/* has focus when TRUE */
	unsigned char chaincolor;		/* color of chained vectors */
	unsigned char fillmode;			/* circ & rect filled on TRUE */
	unsigned char curs_type;		/* cursor type */
	unsigned char curs_blink;		/* cursor blink on TRUE */
	unsigned char curs_hotx;		/* cursor x hotspot */
	unsigned char curs_hoty;		/* cursor y hotspot */
	char blink_count;			/* blink cycle counter */
	LXPIXDEF *pixdef;			/* pixmap structure pointer */
	short doExpose;
	short fcolor;
	short bcolor;
	short querypointer;
	short readque;
	short fullque;
	short qarc;
	short qbmov;
	short qcatt;
	short qcir;
	short qcopy;
	short qctyp;
	short qcurs;
	short qcvec;
	short qelip;
	short qeras;
	short qhint;
	short qfill;
	short qmode;
	short qpatt;
	short qpnts;
	short qrcmd;
	short qrect;
	short qrst;
	short qtext;
	short qtitl;
	short qvec;
	short qvwid;
	short loadfont;
	short wait;
	short waitcount;
	short qclip;
	short waitsum;
	short qlfnt;
	short short_unused[5];
	char pix_forecolor;
	char pix_backcolor;
	char fore_blink;		/* foreground color is blinking */
	char back_blink;		/* background color is blinking */
	int cvec_num;
	int pnts_num;
	int rect_num;
	int text_num;
	int vec_num;
	time_t update_time;			/* time of last user write */
	unsigned int gc_forecolor;  	    	/* last fcolor set in gc */
	unsigned int gc_backcolor;  	    	/* last bcolor set in gc */
	unsigned int bgc_forecolor;  	    	/* last fcolor in TCblink gc */
	unsigned int bgc_backcolor;  	    	/* last bcolor in TCblink gc */
	short border_width;			/* border width cept vectors */
	short srv_inx;				/* XSERVER index */
	short width;		    	    	// width of LX window
	short height;		    	    	// height of LX window
        Pixmap pixe;                	    	// pixmap for expose
        Pixmap pixb;                	    	// pixmap for TCblink
	Pixmap curs_pix;	    	    	// cursor pixmap
	GC pixe_gc;		    	    	// expose pixmap graphics context
	GC pixb_gc;		    	    	// TCblink pixmap graphics context
	unsigned int egc_forecolor;  	    	/* last fcolor in expose gc */
	unsigned int egc_backcolor;  	    	/* last bcolor in expose gc */
	char unused_q[8170];			// old lx_queue
	LXPIXDEF lx_pixdef;			/* PIXMAP structure */
	unsigned char xxxxcolor[256];		/* current color map */
	char revert;				/* revert on LXRST when TRUE */
	char big;				/* big pixels when TRUE */
	Colormap colormap;			/* colormap to use */ // XXX: X needed
	short xposey;				/* transpose y value (511 def)*/
	struct LFONT_DAT *lxfont;		/* font if defined */
	int lx_xpos;				/* x position on screen */
	int lx_ypos;				/* y position on screen */
	unsigned int pix8color[256];		/* current color map */
	char ntitle[80];			/* new longer title */
	LXQUEUE lx_queue;			/* lxmgr queue */
	short lx_qend;				/* queue overflow diagnostic */
} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ LXSCREEN;

#define LXNOOP	0			/* function code for LX queue wrap */

typedef struct {
	char code;			/* function code */
	char specific_char;		/* specific to structure */
	short size;			/* structure size */
	short specific_short;		/* specific to structure */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ LX_GEN;

/*  function prototypes */
extern "C" {
LXSCREEN *get_cnscom_ptr_lx(int index, int instance);
LXQUEUE *get_cnscom_ptr_lx_queue(int index, int instance);
LXPIXDEF *get_cnscom_ptr_lx_pixdef(int index, int instance);
void cnscom_init_lx_que(LXSCREEN *lx_ptr);
short get_cnscom_lx_queue_end(int index, int instance);
LXQUEUE *get_cnscom_ptr_lx_queue(int index, int instance);
void put_cnscom_lx_queue_end(int index, int instance, short qend_value);
void cnscom_wait_lx_que_empty(LXSCREEN *lx_ptr);
LXPIXDEF *get_cnscom_ptr_lx_pixdef(int index, int instance);
LX_GEN *cnscom_get_lx_que_readptr(LXSCREEN *lx_ptr);
void cnscom_put_lx_que_readptr(LXSCREEN *lx_ptr, int size);
LX_GEN *cnscom_get_lx_que_writeptr(LXSCREEN *lx_ptr, int size, char wait);
void cnscom_put_lx_que_writeptr(LXSCREEN *lx_ptr, int size);
}

#endif