/* **********************************************************************
 * *                                                                    *
 * *           Support Routines for BITE Configuration Files            *
 * *                                                                    *
 * **********************************************************************
 * File: bitex_limits.c
 *
 *                  COPYRIGHT (c) 2001, 2002, 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.
 */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "sigtypes.h"
#include "sigversion.h"
#include "headers.h"
#include "product.h"
#include "setup.h"
#include "user_lib.h"

#define LIM_DEFINITIONS
#define LIM_KERNEL window_limits_kernel
#include "config_lib.h"

MESSAGE window_limits
( const char *sname_a,		/* Name of structure */
  volatile void *item_a,	/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  void *file_a );		/* Diagnostic messages, or NULL */

static MESSAGE LIM_KERNEL
( const char *sname_a,		/* Name of structure */
  void *item_a,			/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  const char *spath_a,		/* Full path name of fields */
  void *ioarg_a ) ;		/* Diagnostic messages, or NULL */

MESSAGE window_limits
( const char *sname_a,		/* Name of structure */
  volatile void *item_a,	/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  void *file_a )		/* Diagnostic messages, or NULL */
{
  return( lim_toplevel( sname_a, item_a, ioper_a, file_a, LIM_KERNEL ) ) ;
}

/* ======================================================================
 * Internal routine to recursively descend the BITE structures.
 */
static MESSAGE LIM_KERNEL
( const char *sname_a,		/* Name of structure */
  void *item_a,			/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  const char *spath_a,		/* Full path name of fields */
  void *ioarg_a )		/* Diagnostic messages, or NULL */
{
  char spath[PATHNAME_SIZE], *sItem ; struct lim_inLine **pLine ;
  SINT4 idim1=0, idim2=0 ; MESSAGE istatus = SS_NORMAL ;

  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  if( 0 == strcmp( "SlideShowList", sname_a ) ) 
  {
    struct SlideShowList *item = item_a ;
    SCALAR   (    iSiteNumber,         0,          MAX_SITES-1,    0 ) ;
    SCALAR   (         iPType,         0,   NUM_DEFINED_DATA-1,    0 ) ;
    STRING   (         sPName,         "" ) ;
    SCALAR   (       iTimeLag,         0,                   15,    0 ) ;
    SCALAR   (     iDwellTime,         1,                  120,    1 ) ;
  }
  else if( 0 == strcmp( "WindowSetup", sname_a ) )
  {
    struct WindowSetup *item = item_a ;
    SCALAR   (    iSlidesInShow,       0, MAX_SLIDES_IN_SHOW-1,    0 ) ;
    SUBSTRUCTURE_1D(     SlideShowList,   slideShowList, MAX_SLIDES_IN_SHOW ) ;
  }
  else
    istatus = iMessageMod_va( CONFIG_LIM_BADSTRUCT, 1, sname_a ) ;

  return( istatus ) ;
}

/* ======================================================================
 * These routines load/save new values to the BITEX Widget config file
 */
MESSAGE window_load_conf
( const char *sRemoteHostname_a,
  volatile const UINT4 iWindowNumber,
  volatile struct WindowSetup *pWindowSetup_a )
{
  char sfilename[DIRECTORY_SIZE];
  memset( (void *)pWindowSetup_a, 0, sizeof(struct WindowSetup) ) ;

  sprintf(sfilename, "window%d.conf", iWindowNumber);
  return( lim_loadFile( sRemoteHostname_a, sfilename, "WindowSetup",
			pWindowSetup_a, window_limits ) ) ;
}
MESSAGE window_save_conf
( const char *sRemoteHostname_a, 
  volatile const UINT4 iWindowNumber,
  volatile const struct WindowSetup *pWindowSetup_a )
{
  char sfilename[DIRECTORY_SIZE];
  struct WindowSetup windowSetup = *pWindowSetup_a ;
  strncpy( windowSetup.sVersion, IRIS_VERSION, 8 ) ; 
  windowSetup.sVersion[7] = '\0' ; 

  sprintf(sfilename, "window%d.conf", iWindowNumber);
  return( lim_saveFile( sRemoteHostname_a, sfilename, "WindowSetup",
			pWindowSetup_a, window_limits ) ) ;
}
