/* **********************************************************************
 * *                                                                    *
 * *                  Event Flags and Semaphores                        *
 * *                                                                    *
 * **********************************************************************
 * File: include/event_flags.h
 *
 *      COPYRIGHT (c) 1988, 1989, 1991, 1996, 1997, 1999, 2003  BY
 *         SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */

/* Semaphore and Event Flag allocations to clusters.  Each cluster is
 * limited in size to MAX_SEM_CLUSTER_SIZE, hence several clusters are
 * needed to define all of the required flags.  All SIGMET programs
 * should use this table to make sure they do not collide with another
 * library semphore number.
 */
#define MAX_SEM_CLUSTER_SIZE  32 /* Max number of elements in a cluster */
#define MAX_SEM_CLUSTERS       9 /* Max number of separate clusters */

#define IRIS_SEM_CLUSTER       (0 << 16) /* IRIS data locking */
#define IRIS_OUTEF_CLUSTER     (1 << 16) /* IRIS output processes */
#define IRIS_EVENT_CLUSTER     (2 << 16) /* IRIS process coordination */
#define IRIS_RIBBON_CLUSTER    (3 << 16) /* IRIS ribbon display */
#define IRIS_INPUTEF_CLUSTER   (4 << 16) /* IRIS input processes */
#define LIBS_ANTENNA_CLUSTER   (5 << 16) /* Routines in /libs/antenna */
#define LIBS_TSARCHIVE_CLUSTER (6 << 16) /* Routines in /ts/archlib */
#define RVP8_GLOBAL_CLUSTER    (7 << 16) /* RVP8/Main and RVP8/Proc */
#define APPS_GENERIC_CLUSTER   (8 << 16) /* Stand-alone apps using privately */
                                         /*   named, independent clusters. */

#define IRIS_SEM_CLUSTER_NAME      "iris_sem_cluster"
#define IRIS_OUTEF_CLUSTER_NAME    "iris_outef_cluster"
#define IRIS_EVENT_CLUSTER_NAME    "iris_event_cluster"
#define IRIS_INPUTEF_CLUSTER_NAME  "iris_inputef_cluster"
#define RVP8_GLOBAL_CLUSTER_NAME   "rvp8_global_cluster"

/* *******************
 * *                 *
 * * IRIS Semaphores *
 * *                 *
 * *******************
 */

/* The following semaphores are used for locking IRIS resources.  The
 * locks must be used whenever any data item in the locked resource is
 * being modified, or whenever any set of items are to be read out in
 * a mutually consistent state.  The programming philosophy should be
 * that the locks resolve conflicts that would only rarely occur,
 * i.e., what they are protecting against takes place with a small but
 * potentially disasterous probability.  When a resource is locked the
 * process should carry out subsequent actions quickly so that the
 * lock can soon be removed.
 *
 * Whenever it is necessary to lock two or more semaphores in a row,
 * it is important that the order of locks be the same between
 * processes.  If this is not done a deadly embrace could easily
 * result.  To avoid this, please adopt the convention that multiple
 * locks are always done in the order that the semaphores appear in
 * the list below.
 */

/* Semaphore to lock modifying the control sections of the
 * process_info structure.  Just checking the contents does not
 * require a lock.  To get a consistent snapshot (such as when
 * doing a RST save) this should be locked.  This is required
 * because automatic mode changes are made by several processes.
 */
#define RST_SEM   (IRIS_SEM_CLUSTER + 0)

/* Semaphore to lock the task schedule structure.
 */
#define TSC_SEM   (IRIS_SEM_CLUSTER + 1)

/* Lock the ingest file internal inventory.
 */
#define ING_INV_SEM (IRIS_SEM_CLUSTER + 2)

/* Lock the PRODUCT schedule structure.
 */
#define PSC_SEM   (IRIS_SEM_CLUSTER + 3)

/* Lock the product file internal inventory.
 */
#define PROD_INV_SEM (IRIS_SEM_CLUSTER + 4)

/* Lock the device table to see if you can get use of a device 
 */
#define DEVICE_SEM (IRIS_SEM_CLUSTER + 5)

/* Lock the archive inventories.  The size of these inventories can only
 * be changed by the ARCHIVE process, therefore it does not need to lock to
 * preserve the validity of a pointer to a slot.  All other processes
 * must do that.
 */
#define ARCHIVE_INV_SEM (IRIS_SEM_CLUSTER + 6)

/* Lock the automatic mode switching table.
 */
#define MODE_SWITCHING_SEM (IRIS_SEM_CLUSTER + 7)

/* Lock changes to the modes in the process info structure.  This is
 * only required for the ingest and product processes.  These
 * processes should lock between checking a process command, and
 * setting a process mode.
 */
#define PROC_MODE_SEM (IRIS_SEM_CLUSTER + 8)

/* Lock changes to the socket server client state structure.  This is
 * only used between the various sserver processes.
 */
#define SSERVER_STATE_SEM (IRIS_SEM_CLUSTER + 9)

/* Lock the error logging structure in shared memory.  This should be
 * last, because otherwise it will not be possible to signal an error
 * while other semaphores are locked.
 */
#define MESSAGE_SEM   (IRIS_SEM_CLUSTER + 10)

#define IRIS_SEM_CLUSTER_NUM   (11)

/* ********************
 * *                  *
 * * IRIS Event Flags *
 * *                  *
 * ********************
 *
 * The following event flags are available for waking up processes or
 * groups of processes.  Their initial value is zero (Clear).
 */

/* --------------------------------------------------
 * Wake up the product output processes.  There is one process for
 * each output device, and these should be consecutive.
 */
#define OUTDEV1_EF    (IRIS_OUTEF_CLUSTER +  0)
#define OUTDEV2_EF    (IRIS_OUTEF_CLUSTER +  1)
#define OUTDEV3_EF    (IRIS_OUTEF_CLUSTER +  2)
#define OUTDEV4_EF    (IRIS_OUTEF_CLUSTER +  3)
#define OUTDEV5_EF    (IRIS_OUTEF_CLUSTER +  4)
#define OUTDEV6_EF    (IRIS_OUTEF_CLUSTER +  5)
#define OUTDEV7_EF    (IRIS_OUTEF_CLUSTER +  6)
#define OUTDEV8_EF    (IRIS_OUTEF_CLUSTER +  7)
#define OUTDEV9_EF    (IRIS_OUTEF_CLUSTER +  8)
#define OUTDEV10_EF   (IRIS_OUTEF_CLUSTER +  9)
#define OUTDEV11_EF   (IRIS_OUTEF_CLUSTER + 10)
#define OUTDEV12_EF   (IRIS_OUTEF_CLUSTER + 11)
#define OUTDEV13_EF   (IRIS_OUTEF_CLUSTER + 12)
#define OUTDEV14_EF   (IRIS_OUTEF_CLUSTER + 13)
#define OUTDEV15_EF   (IRIS_OUTEF_CLUSTER + 14)
#define OUTDEV16_EF   (IRIS_OUTEF_CLUSTER + 15)
#define OUTDEV17_EF   (IRIS_OUTEF_CLUSTER + 16)
#define OUTDEV18_EF   (IRIS_OUTEF_CLUSTER + 17)
#define OUTDEV19_EF   (IRIS_OUTEF_CLUSTER + 18)
#define OUTDEV20_EF   (IRIS_OUTEF_CLUSTER + 19)
#define OUTDEV21_EF   (IRIS_OUTEF_CLUSTER + 20)
#define OUTDEV22_EF   (IRIS_OUTEF_CLUSTER + 21)
#define OUTDEV23_EF   (IRIS_OUTEF_CLUSTER + 22)
#define OUTDEV24_EF   (IRIS_OUTEF_CLUSTER + 23)
#define OUTDEV25_EF   (IRIS_OUTEF_CLUSTER + 24)
#define OUTDEV26_EF   (IRIS_OUTEF_CLUSTER + 25)
#define OUTDEV27_EF   (IRIS_OUTEF_CLUSTER + 26)
#define OUTDEV28_EF   (IRIS_OUTEF_CLUSTER + 27)
#define OUTDEV29_EF   (IRIS_OUTEF_CLUSTER + 28)
#define OUTDEV30_EF   (IRIS_OUTEF_CLUSTER + 29)
#define OUTDEV31_EF   (IRIS_OUTEF_CLUSTER + 30)
#define OUTDEV32_EF   (IRIS_OUTEF_CLUSTER + 31)

/* The actual number of flags to be allocated within this cluster is
 * determined by the maximum number of output devices.
 */
#define IRIS_OUTEF_CLUSTER_NUM   MAX_OUT_DEVICES

/* --------------------------------------------------
 * Wake up the product output processes.  There is one process for
 * each output device, and these should be consecutive.
 */ 
#define INPUT1_EF    (IRIS_INPUTEF_CLUSTER +  0)
#define INPUT2_EF    (IRIS_INPUTEF_CLUSTER +  1)
#define INPUT3_EF    (IRIS_INPUTEF_CLUSTER +  2)
#define INPUT4_EF    (IRIS_INPUTEF_CLUSTER +  3)
#define INPUT5_EF    (IRIS_INPUTEF_CLUSTER +  4)
#define INPUT6_EF    (IRIS_INPUTEF_CLUSTER +  5)
#define INPUT7_EF    (IRIS_INPUTEF_CLUSTER +  6)
#define INPUT8_EF    (IRIS_INPUTEF_CLUSTER +  7)
#define INPUT9_EF    (IRIS_INPUTEF_CLUSTER +  8)
#define INPUT10_EF   (IRIS_INPUTEF_CLUSTER +  9)
#define INPUT11_EF   (IRIS_INPUTEF_CLUSTER + 10)
#define INPUT12_EF   (IRIS_INPUTEF_CLUSTER + 11)
#define INPUT13_EF   (IRIS_INPUTEF_CLUSTER + 12)
#define INPUT14_EF   (IRIS_INPUTEF_CLUSTER + 13)
#define INPUT15_EF   (IRIS_INPUTEF_CLUSTER + 14)
#define INPUT16_EF   (IRIS_INPUTEF_CLUSTER + 15)
#define INPUT17_EF   (IRIS_INPUTEF_CLUSTER + 16)
#define INPUT18_EF   (IRIS_INPUTEF_CLUSTER + 17)
#define INPUT19_EF   (IRIS_INPUTEF_CLUSTER + 18)
#define INPUT20_EF   (IRIS_INPUTEF_CLUSTER + 19)
#define INPUT21_EF   (IRIS_INPUTEF_CLUSTER + 20)
#define INPUT22_EF   (IRIS_INPUTEF_CLUSTER + 21)
#define INPUT23_EF   (IRIS_INPUTEF_CLUSTER + 22)
#define INPUT24_EF   (IRIS_INPUTEF_CLUSTER + 23)
#define INPUT25_EF   (IRIS_INPUTEF_CLUSTER + 24)
#define INPUT26_EF   (IRIS_INPUTEF_CLUSTER + 25)
#define INPUT27_EF   (IRIS_INPUTEF_CLUSTER + 26)
#define INPUT28_EF   (IRIS_INPUTEF_CLUSTER + 27)
#define INPUT29_EF   (IRIS_INPUTEF_CLUSTER + 28)
#define INPUT30_EF   (IRIS_INPUTEF_CLUSTER + 29)
#define INPUT31_EF   (IRIS_INPUTEF_CLUSTER + 30)
#define INPUT32_EF   (IRIS_INPUTEF_CLUSTER + 31)

/* The actual number of flags to be allocated within this cluster is
 * determined by the maximum number of input devices.
 */
#define IRIS_INPUTEF_CLUSTER_NUM   MAX_INPUT_DEVICES

/* --------------------------------------------------
 * Miscellaneous IRIS event flags
 */

/* Wake up the socket server
 */
#define SSERVER_EF       (IRIS_EVENT_CLUSTER + 0)

/* Flag for waking up data ingest process INGEST.  This flag should be
 * set whenever there is a possibility that INGEST's notion of task
 * scheduling times is wrong -- e.g., whenever a new task is put into
 * the scheduled mode.  INGEST also performes a timer wait on this
 * flag to autumatically wake itself up when it knows the time of the
 * next scheduled run.
 */
#define INGEST_EF        (IRIS_EVENT_CLUSTER + 1)

/* Flags for coordinating INGEST and INGFIO processes during the
 * acquisition of data.  INGEST wakes up the file I/O process INGFIO
 * whenever there is a sweep of data ready to be written to disk.
 * INGFIO sets the "W" reply flag when it has finished writing out the
 * data; the "M" flag is set when INGFIO has sucessfully mapped the
 * data.
*/
#define INGFIO_EF        (IRIS_EVENT_CLUSTER + 2) /* Wake up INGFIO */
#define INGFIO_M_EF      (IRIS_EVENT_CLUSTER + 3) /* Set by INGFIO after mapping */
#define INGFIO_W_EF      (IRIS_EVENT_CLUSTER + 4) /* Set by INGFIO when all done */

/* Flag for waking up the watchdog process.  This process wakes up
 * periodically on its own, using this same event flag.  Setting the
 * flag here will cause more timely execution, if ever needed.
 */
#define WATCHDOG_EF      (IRIS_EVENT_CLUSTER + 5)

/* Flag to indicate that someone has mapped the "IRIS_G" global
 * section so IRIS_STARTUP can exit safely.
 */
#define GLOBAL_MAPPED_EF (IRIS_EVENT_CLUSTER + 6)

/* Wake up the PRODUCT generator process.  This flag should be set
 * whenever the product configuration list changes, or whenever a new
 * INGEST file appears on disk.
 */
#define PRODUCT_EF       (IRIS_EVENT_CLUSTER + 7)

/* Wake up the REINGEST process
 */
#define REINGEST_EF    (IRIS_EVENT_CLUSTER + 8)

/* Wake up the TCP/IP Network process
 */
#define NETWORK_EF     (IRIS_EVENT_CLUSTER + 9)

/* Wake up a Network child process.  Should be consecutive.
 */
#define NETCHILD1_EF   (IRIS_EVENT_CLUSTER + 10)
#define NETCHILD2_EF   (IRIS_EVENT_CLUSTER + 11)
#define NETCHILD3_EF   (IRIS_EVENT_CLUSTER + 12)
#define NETCHILD4_EF   (IRIS_EVENT_CLUSTER + 13)
#define NETCHILD5_EF   (IRIS_EVENT_CLUSTER + 14)
#define NETCHILD6_EF   (IRIS_EVENT_CLUSTER + 15)
#define NETCHILD7_EF   (IRIS_EVENT_CLUSTER + 16)
#define NETCHILD8_EF   (IRIS_EVENT_CLUSTER + 17)
#define NETCHILD9_EF   (IRIS_EVENT_CLUSTER + 18)
#define NETCHILD10_EF  (IRIS_EVENT_CLUSTER + 19)
#define NETCHILD11_EF  (IRIS_EVENT_CLUSTER + 20)
#define NETCHILD12_EF  (IRIS_EVENT_CLUSTER + 21)
#define NETCHILD13_EF  (IRIS_EVENT_CLUSTER + 22)
#define NETCHILD14_EF  (IRIS_EVENT_CLUSTER + 23)
#define NETCHILD15_EF  (IRIS_EVENT_CLUSTER + 24)
#define NETCHILD16_EF  (IRIS_EVENT_CLUSTER + 25)
#define NETCHILD17_EF  (IRIS_EVENT_CLUSTER + 26)
#define NETCHILD18_EF  (IRIS_EVENT_CLUSTER + 27)

/* Wake up the Nordrad process
 */
#define NORDRAD_EF     (IRIS_EVENT_CLUSTER + 28)

/* Wake up the ribbon builder process
 */
#define RIBBON_EF      (IRIS_EVENT_CLUSTER + 29)

#define IRIS_EVENT_CLUSTER_NUM  (30)

/* ------------------------------
 * Parameters which define more specifically what memory has been
 * changed, which memory changes may affect the contents of a menu
 * screen.
 */
#define MC_TSC            (0x000001) /* TSC_G  (Task schedule) */
#define MC_ING_INV        (0x000002) /* Ingest inventory */
#define MC_PSC            (0x000004) /* PSC_G  (Product schedule) */
#define MC_PROD_INV       (0x000008) /* Product inventory, excluding overlay list*/
#define MC_OVERLAY        (0x000020) /* Overlay list within PROD_G */
#define MC_DEVST          (0x000040) /* DEVST_G (Device status table) */
#define MC_MODCMD         (0x000080) /* PINFO_G (Process info) */
#define MC_ARCHIVE        (0x000100) /* TAPE_G and TINV_G (tape variables) */
#define MC_MODE_SWITCHING (0x000200) /* Automatic Mode switching table */
#define MC_ERROR          (0x000400) /* Error variables in share */
#define MC_OVR_MASK       (0x000800) /* Overlay mask names */
#define MC_NUMBER_BITS          (12) /* Number of Menu Change bits */


