/* ===========================================================================

  shareMem.h    common funcs functions

=============================================================================*/
#ifndef SHARED_MEM_H
#define SHARED_MEM_H

#ifdef SHARED_MEM_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

#define DA_MEDIUM_HGT       694
#define DA_MEDIUM_WID       694
#define DA_MEDIUM_WID_RHI   940
#define DA_LARGE_HGT        940
#define DA_LARGE_WID        940
#define DA_LARGE_WID_RHI   1150
#define DA_XLARGE_HGT      1150
#define DA_XLARGE_WID      1150
#define DA_XLARGE_WID_RHI  1350

#define MAX_NUM_SITES       5

#define RNG_RING_OFF     1
#define RNG_RING_ON      2
#define RNG_RING_NUMS    3
#define RNG_RING_LAT_LON 4

#define OVERLAY_MAPIO  "rtdisp"


/* globals */
/*************************
** C++ prototypes
***************************/ 

#ifdef SIGMET_SIG_RTDISP_H
struct SiteInfo
{
   struct rtd_v1_vol_header header;
   UINT4  iTimeCnt;
   UINT2  lAlloced;
   UINT2  iStatus;
};
#endif  /* #ifdef SIGMET_SIG_RTDISP_H */

struct color_scale_mod_def
{
  struct color_scale_def       current;
  UINT2  uniform_icolcnt;
  UINT2  uniform_iset_number;
  UINT4  cust_scale_idx;
};

#ifdef SIGMET_MISC_LIB_H
#ifdef SIGMET_TVSUBS_LIB_H
#ifdef SIGMET_SIG_RTDISP_H

struct SavedSharedData
{
  char   sVersion[8];
  char   sSelectedSiteName3[4];          // 3-char site name, null terminated
  UINT4  iRngUnits;
  UINT4  overlayLayerMask;
  UINT4  overlayRngRings;
  char   overlayName[30];
  UINT2  iRangeOptMenuPos;
  UINT4  iDataType;
  UINT4  iDrawAreaWidth;
  UINT4  iDrawAreaHeight;
  UINT4  iPortNum;
  UINT4  iRngVals[2][4];                 // rng idx 0 == km, idx 1 == naut mi
  UINT4  iTextColorIdx;
  struct latlon8 Old_latlon;
  struct rtray_config config;
  struct color_scale_mod_def refl;
  struct color_scale_mod_def velocity;
  struct color_scale_mod_def width;
};

struct SharedDataStruct
{
  struct SavedSharedData saved;
  UINT1  rtdImageBuffer[4*DA_XLARGE_HGT*DA_XLARGE_WID_RHI]; // 4bytes/pixel max
  UINT2  lReceivingData;
  BIN2   iAzimuth;
  BIN2   iElevation;
  UINT2  lDataParamChanged;
  UINT2  lImageSizeChanged;        /*  */
  UINT2  lOverlayChanged;          /* Major overlay change, blank screen */
  UINT2  lOverlayMoved;            /* Overlay has moved a little, do not blank*/
  UINT2  lVelUnChanged;
  UINT2  lPortChanged;
  UINT4  iXImageDepth;
  UINT4  iXImageByteOrder;
  FLT4   fVelUn[2];
  char   colScaleLeftLab[16][8];
  char   colScaleRightLab[16][8];
  UINT4  colScalePixVal[2][16];
  union  level_control dataToVTVMap;
  struct ymds_time ymdsTime;
  struct rtd_v1_vol_header header;
  struct SiteInfo site[MAX_NUM_SITES];
  struct color_setup color;           //Filled in from color_load
  Colormap colormap;                  //Filled in from  XsGetDesiredVisual  
  XVisualInfo visualInfo;           //Filled in from  XsGetDesiredVisual 
  struct color_def standardColormap[256]; //Fill in from ColormapFromSetup
  UINT4 iStandardVtvMapClient[256];  //Filled in from XsAllocStandardColors 
  Window   rtdDrawArea_win;
};

#endif  /* #ifdef SIGMET_SIG_RTDISP_H */
#endif  /* #ifdef SIGMET_XSIG_LIB_H */
#endif  /* #ifdef SIGMET_MISC_LIB_H */

class SharedMem 
{
   private :
      SINT4  iID;
      SINT4  iDataSize;
      void   createOrFind(SINT2 lcreate_a, UINT4 ishared_mem_key_idx_a);
   public  :
      struct SharedDataStruct *pData; 
      UINT4  create(void);
      void   find(UINT4 ishared_mem_key_idx_a);
      void   destroy(void);
      void   levelizeColormap(void);
};
EXTERN SharedMem sharedMem;

#undef EXTERN
#endif

