#ifndef SCHEDULER_IDL_
#define SCHEDULER_IDL_

/* **************************************************************** */
/* IRA Istituto di Radioastronomia                                  */
/*                                                                  */
/* This code is under GNU General Public Licence (GPL)              */
/*                                                                  */
/* Who                                  	when            What        */
/* Andrea Orlati(aorlati@ira.inaf.it)		18/12/2008      created     */
/* Andrea Orlati(aorlati@ira.inaf.it)		03/09/2010      Added haltSchedule(), setDevice() and tracking attribute    */
/* Andrea Orlati(aorlati@ira.inaf.it)		24/10/2011      modified the signature of startSchedule()  */
/* Andrea Orlati(aorlati@ira.inaf.it)     29/05/2012      method  changeLogFile */
/* Andrea Orlati(aorlati@ira.inaf.it)     08/04/2013      added method skydip */

#include <baci.idl>
#include <ManagmentDefinitions.idl>
#include <ComponentErrors.idl>
#include <ManagementErrors.idl>
//#include <AntennaDefinitions.idl>


#pragma prefix "alma"

module Management { 
	
	/**
	 * This is the interface of the component that is in charge of controlling an observation.
	 * The observation typically consists of a schedule and some configuration files. This component
	 * accept one schedule file at a time and will execute it, pointing the telescope, configuring the
	 * devices and the backends. The final result of this is a sequence of files (as many as teh scans reported 
	 * in the schedule) that records the measurment. 
	 * @author <a href=mailto:a.orlati@ira.inaf.it>Andrea Orlati</a>,
 	 * Istituto di Radioastronomia, Italia
 	 * <br> 
 	 */
	interface Scheduler: ACS::CharacteristicComponent, CommandInterpreter  {
	
		/**
		 * This command allows to start a schedule by giving the name of the file and a line number to start from.
		 * @throw CORBA::SystemExcpetion
		 * @throw ComponentErrors::ComponentErrorsEx
		 * 	   @arg \c ComponentErrors::MemoryAllocationEx
		 * 	   @arg \c ComponentErrors::OperationErrorEx
		 *     @arg \c ComponentErrors::UnexpectedEx
		 *     @arg \c ComponentErrors::TimerErrorExImpl
		 * @throw ManagementErrors::ManagementErrorsEx
		 * 	   @arg \c ManagementErrors::ScheduleErrorEx
		 *     @arg \c ManagementErrors::AlreadyRunningEx
		 * @param fileName name of the schedule file
		 * @param startSubScan allows to give the subscan from which schedule should be started, format composed by two non negative integers separeted by an underscore: scanid_subscanid. 
		 *                                             The second number could me optional.
		 */
		void startSchedule(in string fileName,in string startSubScan) raises (ComponentErrors::ComponentErrorsEx,ManagementErrors::ManagementErrorsEx);
		
		/**
		 * This command stops immediately the execution of current schedule. If no schedule is runnig this has no effect.
		 * In order to open a new schedule the user must stop the current one.
		 * @throw CORBA::SystemExcpetion
		 */
		void stopSchedule();

		/**
		 * This command stops the execution of current schedule, only after the current scan is done. If no schedule is runnig this has no effect.
		 * @throw CORBA::SystemExcpetion
		 */
		void haltSchedule();
		
		/**
		 * @copyBrief CommandInterpreter::command
		 * This method can be used to execute a command or to setup a configuration The commands and configurations are given as strings.
		 * @attention the implmentation of this method must take care of logging the errors deriving from the execution of the command.
		 * @throw CORBA::SystemException 
		 * @param command this string contains the instruction to be executed, the command and the syntax may vary from implementation to implementation
		 * @param answer this string contains the answer of the system to the incoming command. It must frred by the caller
		 * @return  the result of the command, true after a succesful command invokation. false otherwise.
		 */
		
		/**
		 * This command will allow a client to acknwledge an error by resetting the <i>status</i> property. If <i>status</i> is already MNG_OK, then it does not do
		 * anything. 
		 * @throw CORBA::SystemExcpetion
		*/
		void clearStatus();
		
		/**
		 * Chages the current log file name
		 * @param fileName name of the file without extension, the directory path is decided by configuration DB. 
		 * @throw CORBA::SystemException
		 * @throw ComponentErrors::ComponentErrorsEx
		 * @throw ManagementErrors::ManagementErrorsEx
		 */
		void changeLogFile(in string fileName) raises (ComponentErrors::ComponentErrorsEx,ManagementErrors::ManagementErrorsEx);
		
		/**
		 * Return the fundamental weather parameters
		 * @param temerature external temperature in °C
		 * @param humidity relative humidity (0..100)
		 * @param pressure atmospheric pressure (mbar)
		 * @param wind wind speed (Km/s) 
		 * @throw CORBA::SystemException
		 * @throw ComponentErrors::ComponentErrorsEx
		 * @throw ManagementErrors::ManagementErrorsEx
		 */		
		void weatherParamenters(out double temperature, out double humidity,out double pressure,out double wind)  raises (ComponentErrors::ComponentErrorsEx,ManagementErrors::ManagementErrorsEx);
		
		/**
		 * Performs the computation of the system temperature. The operation is executed by using the currently in use backend and the currently configured frontend. It could also be the default one.
		 * The measure is done for each of the sections of the backend. Each result is the returned as a sequence of doubles. The results are also published in the log file.
		 * This operation will also computes the ratio kelvin over counts for each backend section, this ratio is then set in the backend. This ratio can be used by the backend to convert the current TPI measure into a Tsys.
		 * @throw CORBA::SystemException
		 * @throw ComponentErrors::ComponentErrorsEx
		 * @throw ManagementErrors::ManagementErrorsEx
		 * @return the tsys for each backend section.
		 */
		ACS::doubleSeq systemTemperature() raises (ComponentErrors::ComponentErrorsEx,ManagementErrors::ManagementErrorsEx);
					
		/**
		 * Performs a cross scan using the main drives of the telescope. The operation consists of system temperature measurment (the telescope is sent 3 times the current beam size off)
		 * and then a longitude and a latitude On-The-Fly scans. 
		 * The frame, the span and the duration of both the On-The-Fly scans is determined by the arguments. A prerequisite is that a target has to be commanded to the telescope; this target is
		 * taken as the center of the On-the-Fly scans. The default backend and the defautl data recorder are used as data source and destination respectively.
		 * @throw ComponentErrors::ComponentErrorsEx
		 * @throw ManagementErrors::ManagementErrorsEx 
		 * @throw CORBA::SystemExcpetion 
		 * @param coordFrame it gives the frame in which the cross cran is performed. 
		 * @param span this is the overall length of the single scans (radians)
		 * @param duration this determine how long the single scan has to take.
		 */ 
		void crossScan(in TCoordinateFrame coordFrame,in double span,in ACS::TimeInterval duration) raises (ComponentErrors::ComponentErrorsEx,ManagementErrors::ManagementErrorsEx);
		
		/**
		 * Performs a focus scan moving the subreflector or the receiver along the optical axis of the telescope. The operation consists of system temperature measurement (the telescope is sent
		 * 3 times the current beam size off) and then a focus scan on the source. The default backend and the default data recorder are used as data source and destination respectively.
		 * @throw ComponentErrors::ComponentErrorsEx
		 * @throw ManagementErrors::ManagementErrorsEx
		 * @throw CORBA::SystemExcpetion
		 * @param span this is the overall length of the single scans (mm)
		 * @param duration this determine how long the scan has to take.
		 */
		void focusScan(in double span,in ACS::TimeInterval duration) raises (ComponentErrors::ComponentErrorsEx,ManagementErrors::ManagementErrorsEx);
		
		/**
		 * Performs a skydip using the main drives of the telescope. The scan is done at the current azimuth position and consists of moving the antenna between two elevation  positions. A system temperature measurment
		 * is perfomed at the higher specified elevation. The movement is done from the greater elevation toword the lower. 
		 * The default backend and the defautl data recorder are used as data source and destination respectively.
		 * @throw ComponentErrors::ComponentErrorsEx
		 * @throw ManagementErrors::ManagementErrorsEx 
		 * @throw CORBA::SystemExcpetion 
		 * @param coordFrame it gives the frame in which the cross cran is performed. 
		 * @param span this is the overall length of the single scans (radians)
		 * @param duration this determine how long the single scan has to take.
		 */ 		
		void skydip(in double elevation1,in double elevation2,in ACS::TimeInterval duration);
		
		/**
		 * Given the default backend. This methods allows to configure the default device. This device is used for calibration purposes and for the computation of the beamwidth, so calling
		 * this method will cause the beam width to be recomputed (usign the configuration of the section and the configuration of the receiver). If the device id is not existent inside the 
		 * current backend, an error is thrown. The set value can be read back from the <i>currentDevice</i> attribute. If not set the default value is 0 but if this method is not called there 
		 * is no guarantee that the backend configuration, the beamsize, the receiver configuration, and the current device are coherent.
		 * @throw ComponentErrors::ComponentErrorsEx
		 * @throw ManagementErrors::ManagementErrorsEx 
		 * @throw CORBA::SystemExcpetion 
		 * @param deviceID identifier of the device (section) inside the current default backend. If negative the current value is preserved.
		 */
		void setDevice(in long deviceID) raises (ComponentErrors::ComponentErrorsEx,ManagementErrors::ManagementErrorsEx);
		
		/**
		 * This method allows to change the instance of the backend choosen as default backend. The new backend is not loaded, it will the next time the default backend is required.
		 * The default backend is used (when no schedule is running) to perform some scheduler operations (@sa <i>setDevice()</i> and <i>systemTemperature</i>).
		 * @throw CORBA::SystemExcpetion  
		 * @param bckInstance name of the instance of the new default backend 
		 */
		void chooseDefaultBackend(in string bckInstance);
		
		/**
		 * This method allows to change the instance of the  data recorder choosen as default. The new component is not loaded, it will the next time the default data recorder is required. 
		 * @param rcvInstance name of the instance of the new default component
		 * @throw CORBA::SystemExcpetion  
		 */ 
		void chooseDefaultDataRecorder(in string rcvInstance);
		
		/**
		 * This method allows to change the value af the attribute <i>restFrequency</i>.
		 */
		void setRestFrequency(in ACS::doubleSeq rest);
		
		/**
		 * This method sets the current project code. If the project does not exists an error is thrown.
		 * @param code code of the project, if blank the selected code will be default one 
		 * @throw ManagementErrors::ManagementErrorsEx 
		 * @throw CORBA::SystemExcpetion 
		 */
		void setProjectCode(in string code) raises (ManagementErrors::ManagementErrorsEx);
			
		/**
		 * This attribute reports the scan identifier currently played by the scheduler.
		*/ 
		readonly attribute ACS::ROlong scanID;
		
		/**
		 * This attribute reports the subscan identifier currently played by the scheduler
		 */
		readonly attribute ACS::ROlong subScanID;
		
		/** 
		 * This attribute reports the current schedule file name that the scheduler is executing.
		 */
		readonly attribute ACS::ROstring scheduleName;
		
		/**
		 * This attribute reports on the status of the component
		 */
		readonly attribute Management::ROTSystemStatus status;
		
		/**
		 * This attributes summerizes the tracking and the status of the while telescope, in order to declare the telescope is tracking correctly all
		 * the subsystem must be ready and tracking
		 */ 
		readonly attribute Management::ROTBoolean tracking;
		
		/**
		 * This attribute reports the device id currently in use. This value can be changed by calling <i>setDevice()</i>
		 */
		readonly attribute ACS::ROlong currentDevice;
		
		/**
		 * This attribute reports the currently running project code, this code will be used for foutput files name, paths and to collect schedules 
		 */
		readonly attribute ACS::ROstring projectCode;
		
		/**
		 * This attribute reports the name of the instance of the currently used backend
		 */
		readonly attribute ACS::ROstring currentBackend;
		
		/**
		 * This attribute reports the name of the instance of the currently used data receiver
		 */
		readonly attribute ACS::ROstring currentRecorder;
		
		/**
		 * This attribute reports the rest frequency currently configured for each section of the backend (Mhz).  
		 * It can be changed using  the method <i>setRestFrequency</i>.
		*/		
		readonly attribute ACS::ROdoubleSeq restFrequency;
		
		
	};
};





#endif /*SCHEDULER_IDL_*/
