Commit 26e6b3e9 authored by Marco De Marco's avatar Marco De Marco
Browse files

Fits importer config properties added

parent 70ea56b3
Loading
Loading
Loading
Loading
+143 −1
Original line number Diff line number Diff line
@@ -138,7 +138,11 @@ void FitsImporter::init_device()
	
	/*----- PROTECTED REGION END -----*/	//	FitsImporter::init_device_before
	
	//	No device property to be read from database

	//	Get the device properties from database
	get_device_property();
	if (mandatoryNotDefined)
		return;
	

	/*----- PROTECTED REGION ID(FitsImporter::init_device) ENABLED START -----*/
@@ -148,6 +152,136 @@ void FitsImporter::init_device()
	/*----- PROTECTED REGION END -----*/	//	FitsImporter::init_device
}

//--------------------------------------------------------
/**
 *	Method      : FitsImporter::get_device_property()
 *	Description : Read database to initialize property data members.
 */
//--------------------------------------------------------
void FitsImporter::get_device_property()
{
	/*----- PROTECTED REGION ID(FitsImporter::get_device_property_before) ENABLED START -----*/
	
	//	Initialize property data members
	
	/*----- PROTECTED REGION END -----*/	//	FitsImporter::get_device_property_before

	mandatoryNotDefined = false;

	//	Read device properties from database.
	Tango::DbData	dev_prop;
	dev_prop.push_back(Tango::DbDatum("WatchPath"));
	dev_prop.push_back(Tango::DbDatum("WorkerNumber"));
	dev_prop.push_back(Tango::DbDatum("ConnectionNumber"));
	dev_prop.push_back(Tango::DbDatum("EventList"));
	dev_prop.push_back(Tango::DbDatum("WaitTime"));

	//	is there at least one property to be read ?
	if (dev_prop.size()>0)
	{
		//	Call database and extract values
		if (Tango::Util::instance()->_UseDb==true)
			get_db_device()->get_property(dev_prop);
	
		//	get instance on FitsImporterClass to get class property
		Tango::DbDatum	def_prop, cl_prop;
		FitsImporterClass	*ds_class =
			(static_cast<FitsImporterClass *>(get_device_class()));
		int	i = -1;

		//	Try to initialize WatchPath from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  watchPath;
		else {
			//	Try to initialize WatchPath from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  watchPath;
		}
		//	And try to extract WatchPath value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  watchPath;
		//	Property StartDsPath is mandatory, check if has been defined in database.
		check_mandatory_property(cl_prop, dev_prop[i]);

		//	Try to initialize WorkerNumber from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  workerNumber;
		else {
			//	Try to initialize WorkerNumber from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  workerNumber;
		}
		//	And try to extract WorkerNumber value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  workerNumber;

		//	Try to initialize ConnectionNumber from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  connectionNumber;
		else {
			//	Try to initialize ConnectionNumber from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  connectionNumber;
		}
		//	And try to extract ConnectionNumber value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  connectionNumber;

		//	Try to initialize EventList from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  eventList;
		else {
			//	Try to initialize EventList from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  eventList;
		}
		//	And try to extract EventList value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  eventList;

		//	Try to initialize WaitTime from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  waitTime;
		else {
			//	Try to initialize WaitTime from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  waitTime;
		}
		//	And try to extract WaitTime value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  waitTime;

	}

	/*----- PROTECTED REGION ID(FitsImporter::get_device_property_after) ENABLED START -----*/
	
	//	Check device property data members init
	
	/*----- PROTECTED REGION END -----*/	//	FitsImporter::get_device_property_after
}
//--------------------------------------------------------
/**
 *	Method      : FitsImporter::check_mandatory_property()
 *	Description : For mandatory properties check if defined in database.
 */
//--------------------------------------------------------
void FitsImporter::check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop)
{
	//	Check if all properties are empty
	if (class_prop.is_empty() && dev_prop.is_empty())
	{
		TangoSys_OMemStream	tms;
		tms << endl <<"Property \'" << dev_prop.name;
		if (Tango::Util::instance()->_UseDb==true)
			tms << "\' is mandatory but not defined in database";
		else
			tms << "\' is mandatory but cannot be defined without database";
		string	status(get_status());
		status += tms.str();
		set_status(status);
		mandatoryNotDefined = true;
		/*----- PROTECTED REGION ID(FitsImporter::check_mandatory_property) ENABLED START -----*/
		cerr << tms.str() << " for " << device_name << endl;
		
		/*----- PROTECTED REGION END -----*/	//	FitsImporter::check_mandatory_property
	}
}


//--------------------------------------------------------
/**
@@ -158,6 +292,14 @@ void FitsImporter::init_device()
void FitsImporter::always_executed_hook()
{
	INFO_STREAM << "FitsImporter::always_executed_hook()  " << device_name << endl;
	if (mandatoryNotDefined)
	{
		string	status(get_status());
		Tango::Except::throw_exception(
					(const char *)"PROPERTY_NOT_SET",
					status.c_str(),
					(const char *)"FitsImporter::always_executed_hook()");
	}
	/*----- PROTECTED REGION ID(FitsImporter::always_executed_hook) ENABLED START -----*/
	
	//	code always executed before all requests
+36 −0
Original line number Diff line number Diff line
@@ -65,6 +65,34 @@ class FitsImporter : public TANGO_BASE_CLASS

/*----- PROTECTED REGION END -----*/	//	FitsImporter::Data Members

//	Device property data members
public:
	//	WatchPath:	Absolute path where fits importer wait for a new file to ingest
	string	watchPath;
	//	WorkerNumber:	Number of worker thread to process new file
	Tango::DevUShort	workerNumber;
	//	ConnectionNumber:	Number of connection created in connection pool for each database entry in destination table
	Tango::DevUShort	connectionNumber;
	//	EventList:	Inotify event that trigger fits importer new file event. 
	//  Allowed event are:
	//  * IN_ACCESS
	//  * IN_MODIFY
	//  * IN_ATTRIB
	//  * IN_CLOSE_WRITE
	//  * IN_CLOSE_NOWRITE
	//  * IN_OPEN
	//  * IN_MOVED_FROM
	//  * IN_MOVED_TO
	//  * IN_DELETE
	//  * IN_DELETE_SELF
	//  * IN_CLOSE
	//  * IN_MOVE
	//  * IN_ALL_EVENTS
	vector<string>	eventList;
	//	WaitTime:	Time fits importer has to sleep between new time event and ingestion
	Tango::DevULong	waitTime;

	bool	mandatoryNotDefined;


//	Constructors and destructors
@@ -107,11 +135,19 @@ public:
	 *	Initialize the device
	 */
	virtual void init_device();
	/*
	 *	Read the device properties from database
	 */
	void get_device_property();
	/*
	 *	Always executed method before execution command method.
	 */
	virtual void always_executed_hook();

	/*
	 *	Check if mandatory property has been set
	 */
	 void check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop);

//	Attribute methods
public:
+34 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="ASCII"?>
<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
  <classes name="FitsImporter" pogoRevision="8.1">
    <description description="Fits importer device server" title="Fits importer device server" sourcePath="/home/mdm/workspace/nadir/fitsimporter" language="Cpp" filestogenerate="XMI   file,Code files" license="LGPL" hasMandatoryProperty="false" hasConcreteProperty="false" hasAbstractCommand="false" hasAbstractAttribute="false">
    <description description="Fits importer device server" title="Fits importer device server" sourcePath="/home/mdm/workspace/nadir/fits_importer/src" language="Cpp" filestogenerate="XMI   file,Code files" license="LGPL" hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
      <inheritances classname="Device_Impl" sourcePath=""/>
      <identification contact="at oats.inaf.it - demarco" author="demarco" emailDomain="oats.inaf.it" classFamily="Acquisition" siteSpecific="" platform="Unix Like" bus="Not Applicable" manufacturer="none" reference=""/>
    </description>
    <deviceProperties name="WatchPath" mandatory="true" description="Absolute path where fits importer wait for a new file to ingest">
      <type xsi:type="pogoDsl:StringType"/>
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
    </deviceProperties>
    <deviceProperties name="WorkerNumber" description="Number of worker thread to process new file">
      <type xsi:type="pogoDsl:UShortType"/>
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
      <DefaultPropValue>10</DefaultPropValue>
    </deviceProperties>
    <deviceProperties name="ConnectionNumber" description="Number of connection created in connection pool for each database entry in destination table">
      <type xsi:type="pogoDsl:UShortType"/>
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
      <DefaultPropValue>2</DefaultPropValue>
    </deviceProperties>
    <deviceProperties name="EventList" description="Inotify event that trigger fits importer new file event. &#xA;Allowed event are:&#xA;* IN_ACCESS&#xA;* IN_MODIFY&#xA;* IN_ATTRIB&#xA;* IN_CLOSE_WRITE&#xA;* IN_CLOSE_NOWRITE&#xA;* IN_OPEN&#xA;* IN_MOVED_FROM&#xA;* IN_MOVED_TO&#xA;* IN_DELETE&#xA;* IN_DELETE_SELF&#xA;* IN_CLOSE&#xA;* IN_MOVE&#xA;* IN_ALL_EVENTS">
      <type xsi:type="pogoDsl:StringVectorType"/>
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
      <DefaultPropValue>IN_CLOSE_WRITE</DefaultPropValue>
    </deviceProperties>
    <deviceProperties name="WaitTime" description="Time fits importer has to sleep between new time event and ingestion">
      <type xsi:type="pogoDsl:UIntType"/>
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
      <DefaultPropValue>0</DefaultPropValue>
    </deviceProperties>
    <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0">
      <argin description="none">
        <type xsi:type="pogoDsl:VoidType"/>
@@ -23,6 +47,15 @@
      </argout>
      <status abstract="true" inherited="true" concrete="true"/>
    </commands>
    <states name="OFF" description="Fits importer is in OFF state (not ready to ingest data)">
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
    </states>
    <states name="ON" description="Fits importer is in ON state (ready to ingest data)">
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
    </states>
    <states name="FAULT" description="Fits importer is in FAULT state (not ready to ingest data) &#xA;Status attribute contains fault description">
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
    </states>
    <preferences docHome="./doc_html" makefileHome="/usr/local/tango-8.1.2/share/pogo/preferences"/>
  </classes>
</pogoDsl:PogoSystem>
+69 −0
Original line number Diff line number Diff line
@@ -227,6 +227,75 @@ void FitsImporterClass::set_default_property()
	//	Set Default Class Properties

	//	Set Default device Properties
	prop_name = "WatchPath";
	prop_desc = "Absolute path where fits importer wait for a new file to ingest";
	prop_def  = "";
	vect_data.clear();
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "WorkerNumber";
	prop_desc = "Number of worker thread to process new file";
	prop_def  = "10";
	vect_data.clear();
	vect_data.push_back("10");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "ConnectionNumber";
	prop_desc = "Number of connection created in connection pool for each database entry in destination table";
	prop_def  = "2";
	vect_data.clear();
	vect_data.push_back("2");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "EventList";
	prop_desc = "Inotify event that trigger fits importer new file event. \nAllowed event are:\n* IN_ACCESS\n* IN_MODIFY\n* IN_ATTRIB\n* IN_CLOSE_WRITE\n* IN_CLOSE_NOWRITE\n* IN_OPEN\n* IN_MOVED_FROM\n* IN_MOVED_TO\n* IN_DELETE\n* IN_DELETE_SELF\n* IN_CLOSE\n* IN_MOVE\n* IN_ALL_EVENTS";
	prop_def  = "IN_CLOSE_WRITE";
	vect_data.clear();
	vect_data.push_back("IN_CLOSE_WRITE");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
	prop_name = "WaitTime";
	prop_desc = "Time fits importer has to sleep between new time event and ingestion";
	prop_def  = "0";
	vect_data.clear();
	vect_data.push_back("0");
	if (prop_def.length()>0)
	{
		Tango::DbDatum	data(prop_name);
		data << vect_data ;
		dev_def_prop.push_back(data);
		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
	}
	else
		add_wiz_dev_prop(prop_name, prop_desc);
}

//--------------------------------------------------------
+4 −0
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@ static const char *RcsId = "$Id: $";
//================================================================
//  States  |  Description
//================================================================
//  OFF     |  Fits importer is in OFF state (not ready to ingest data)
//  ON      |  Fits importer is in ON state (ready to ingest data)
//  FAULT   |  Fits importer is in FAULT state (not ready to ingest data) 
//          |  Status attribute contains fault description


namespace FitsImporter_ns