/************************************************************************/
/* Copyright 1998 MBARI							*/
/************************************************************************/
#ifndef _DMGUIAPP_H
#define _DMGUIAPP_H
static char DmGuiApp_h_id[] = "$Header: /u/oreilly/rov/tmacs/RCS/DmGuiApp.h,v 1.8 1998/12/18 21:07:21 oreilly Exp $";

/*
$Log: DmGuiApp.h,v $
Revision 1.8  1998/12/18 21:07:21  oreilly
Added documentation

Revision 1.7  1997/10/03 09:29:17  oreilly
*** empty log message ***

 * Revision 1.6  97/09/10  08:48:30  08:48:30  oreilly (Thomas C. O'Reilly)
 * Load and save preferences
 * 
 * Revision 1.5  97/08/12  14:37:28  14:37:28  oreilly (Thomas C. O'Reilly)
 * *** empty log message ***
 * 
 * Revision 1.4  97/04/30  20:10:25  20:10:25  oreilly (Thomas C. O'Reilly)
 * return value from unregisterConsumer()
 * 
 * Revision 1.3  97/03/20  12:33:43  12:33:43  oreilly (Thomas C. O'Reilly)
 * *** empty log message ***
 * 
 * Revision 1.2  97/03/17  21:15:51  21:15:51  oreilly (Thomas C. O'Reilly)
 * Added method executeCmd() for executing a shell command
 * 
 * Revision 1.1  96/10/28  09:13:34  09:13:34  oreilly (Thomas C. O'Reilly)
 * Initial revision
 * 
*/

#include <Vk/VkApp.h>
#include "SList.h"
#include "DmGuiObject.h"
#include "PeriodicHandler.h"
#include "AperiodicHandler.h"
#include "SubPrograms.h"

#define defaultPreferencesFile "preferences"


/*
CLASS 
DmGuiApp

DESCRIPTION
DmGuiApp has several responsibilities, including
creation of AperiodicHandler and PeriodicHandler objects. 

AUTHOR
Tom O'Reilly
*/
class DmGuiApp : public VkApp 
{
  public:

  DmGuiApp(
	 char *appClassName,
	 int *argc,
	 char **argv,
	 XrmOptionDescRec *optionList = NULL,
	 int sizeOfOptionList = 0
	 );

  ~DmGuiApp();  

  /* Add DmGuiObject to list of all DmGuiObjects (called by DmGuiObject
   constructor) */
  void registerDmGuiObject(DmGuiObject *);
  
  /* Remove DmGuiObject to list of all DmGuiObjects (called by DmGuiObject
   destructor) */
  int unregisterDmGuiObject(DmGuiObject *);

  /* Register DmGuiObject with appropriate telemetry handler */
  int registerConsumer(DmGuiObject *obj, int period);

  /* Remove DmGuiObject from telemetry handler lists */
  int unregisterConsumer(DmGuiObject *obj);
  
  /* Start telemetry handlers prior to entering event loop */
  void startTelemetryHandlers();
  
  AperiodicHandler *aperiodicHandler();


  MBool debug()
  {
    return _debug;
  }

  // Gracefully exit 
  void exit(int stat);  

  // Execute a shell command
  int executeCmd(const char *cmd);

  SubPrograms *subPrograms;

  Boolean hasStickyConsumer(DM_Item dmItem);

  void preferencesFile(char *filename);

  int loadPreferences(char *errorBuf);

  int savePreferences(char *errorBuf);
  
  SList<DmGuiObject *> dmGuiObjectList;

  
  protected:
  PeriodicHandler *_periodicHandler;
  AperiodicHandler *_aperiodicHandler;  
  MBool _debug;
  
  void setSignalHandlers();
  void clearSignalHandlers();
  
  // signalHandler() is called as soon as signal is received.
  // Followup processing of signal is deferred to workproc 
  static void signalHandler(int sigNo);

  // followupSignalHandler() does additional processing of signal, as a 
  // workproc
  static Boolean followupSignalHandler(XtPointer clientData);

  char _preferencesFile[256]; 

};

#endif
