#ifndef LRSAPP_H
#define LRSAPP_H

#include "supplier.h"
#undef _WINDOWS_

#include "microapp.h"
#include "callback.h"
#include "lrssampler.h"
#include "lrseventhandler.h"
#include "lrscfg.h"
#include "alarmmgr.h"
#include "types.h"
#include "ostime.h"
#include "inputhandler.h"
#include "sensor.h"


/*----------------------------------------------------------------
CLASS 
	LrsApp

DESCRIPTION
	LrsApp is the superclass used in the Laser Raman application.
	All object instances are contained in this class.
	
AUTHOR
	D.Cline. Copyright 2001 MBARI.
----------------------------------------------------------------*/
class LrsApp : public MicroApp
{
public:

	// Constructs all object used in the LrsApp. 
	LrsApp();

	virtual ~LrsApp();
	
	// Entry point for app to initialize. First function called from 
	// appframework run() method
	virtual int initialize(int argc, char *argv[]);	

	// Entry point for app to run.  Called within MicroApp::run after
	// MicroApp initialization and all tasks are spawned    
	int runApp();

	// Create EventHandler subclass object
	MicroEventHandler *createEventHandler();

	// Create PeriodicHandler subclass object
	MicroPeriodicHandler *createPeriodicHandler();

	// Fill in TasksParams structure for DmMonitor and MicroSampler tasks
	void setTaskParams();

	// Shutdown the LrsApp. Override's MicroApp method . 
	// Must also call MicroApp's exit method to shutdown the appframework
	virtual int exit();
	
	// Shutdown LrsApp. This will trigger a controlled shutdown of the application
	void shutdown();

	// Returns elapsed time since power up.
	Int32 elapsedTime();

	// LrsApp shutdown state, TRUE if in the process of shutting down
	// otherwise FALSE.
	MBool isShutdown();

	// LrsApp run-time state
	enum State {
		STARTUP,		// System startup						
		RUN,			// Run app specific tasks
		WAITFORSHUTDOWN,// Wait for shutdown signal
		CLEAN_UP,		// System clean-up, preparing for graceful shutdown	
		SHUTDOWN		// Shutting down
	};
	
	// Watchdog reset function
	void resetWatchdog(CallbackObject *);

	// Returns current LrsApp state
	State state();
	
	// Event and data supplier. Used by LRSEventHandler and LRSSampler
	Supplier *_pSupplier;

	// Housekeeping sensors one per each pressure vessel
	HousekeepingSensors *_pSpectrographSensor;
	HousekeepingSensors *_pElectronicsSensor;
	
	// Handler for keyboard input.
	InputHandler _ih;
private:		
	// Mission start time
	gmTime _mst;
	
	// State of Lrs application
	Nat16 _appstate;

	// Flag to indicate shutdown status. TRUE during shutdown only.
	MBool _shutdown;

	// AlarmManager Singleton
	AlarmManager *_pAlarmManager;

	// LrsEventHadler is a child of MicroEventHandler
	LrsEventHandler *_pLrsEventHandler;

	// LrsSampler is a child of MicroPeriodicHandler
	LrsSampler *_pLrsSampler;	

	// Lrs system configuration, contains calibration and configuration data
	// is a child of InstrumentCfg
	LrsCfg *_pLrsCfg;

	// ACE thread manager for managing ORB and ACE related threads
	ACE_Thread_Manager _thrManager;	

};

#endif 
