Skip to content
DataImporter.cpp 16.8 KiB
Newer Older
Marco De Marco's avatar
Marco De Marco committed
/*----- PROTECTED REGION ID(DataImporter.cpp) ENABLED START -----*/
//=============================================================================
//
// file :        DataImporter.cpp
//
// description : C++ source for the DataImporter class and its commands.
//               The class is derived from Device. It represents the
//               CORBA servant object which will be accessed from the
//               network. All commands which can be executed on the
//               DataImporter are implemented in this file.
//
// project :     Data importer
//
// This file is part of Tango device class.
// 
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Tango.  If not, see <http://www.gnu.org/licenses/>.
// 
// $Author:  $
//
// $Revision:  $
// $Date:  $
//
// $HeadURL:  $
//
//=============================================================================
//                This file is generated by POGO
//        (Program Obviously used to Generate tango Object)
//=============================================================================


#include <DataImporter.h>
#include <DataImporterClass.h>

/*----- PROTECTED REGION END -----*/	//	DataImporter.cpp

/**
 *  DataImporter class description:
 *    
 */

//================================================================
//  The following table gives the correspondence
//  between command and method names.
//
//  Command name  |  Method name
//================================================================
//  State         |  Inherited (no method)
//  Status        |  Inherited (no method)
//  On            |  on
//  Off           |  off
Marco De Marco's avatar
Marco De Marco committed
//================================================================

//================================================================
//  Attributes managed is:
//================================================================
//================================================================

namespace DataImporter_ns
{
/*----- PROTECTED REGION ID(DataImporter::namespace_starting) ENABLED START -----*/

//	static initializations

/*----- PROTECTED REGION END -----*/	//	DataImporter::namespace_starting

//--------------------------------------------------------
/**
 *	Method      : DataImporter::DataImporter()
 *	Description : Constructors for a Tango device
 *                implementing the classDataImporter
 */
//--------------------------------------------------------
DataImporter::DataImporter(Tango::DeviceClass *cl, string &s)
 : TANGO_BASE_CLASS(cl, s.c_str())
{
	/*----- PROTECTED REGION ID(DataImporter::constructor_1) ENABLED START -----*/
	init_device();
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::constructor_1
}
//--------------------------------------------------------
DataImporter::DataImporter(Tango::DeviceClass *cl, const char *s)
 : TANGO_BASE_CLASS(cl, s)
{
	/*----- PROTECTED REGION ID(DataImporter::constructor_2) ENABLED START -----*/
	init_device();
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::constructor_2
}
//--------------------------------------------------------
DataImporter::DataImporter(Tango::DeviceClass *cl, const char *s, const char *d)
 : TANGO_BASE_CLASS(cl, s, d)
{
	/*----- PROTECTED REGION ID(DataImporter::constructor_3) ENABLED START -----*/
	init_device();
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::constructor_3
}

//--------------------------------------------------------
/**
 *	Method      : DataImporter::delete_device()
 *	Description : will be called at device destruction or at init command
 */
//--------------------------------------------------------
void DataImporter::delete_device()
{
	DEBUG_STREAM << "DataImporter::delete_device() " << device_name << endl;
	/*----- PROTECTED REGION ID(DataImporter::delete_device) ENABLED START -----*/
	
	//	Delete device allocated objects
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::delete_device
}

//--------------------------------------------------------
/**
 *	Method      : DataImporter::init_device()
 *	Description : will be called at device initialization.
 */
//--------------------------------------------------------
void DataImporter::init_device()
{
	DEBUG_STREAM << "DataImporter::init_device() create device " << device_name << endl;
	/*----- PROTECTED REGION ID(DataImporter::init_device_before) ENABLED START -----*/
	
	//	Initialization before get_device_property() call
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::init_device_before
	

	//	Get the device properties from database
	get_device_property();
Marco De Marco's avatar
Marco De Marco committed
	

	/*----- PROTECTED REGION ID(DataImporter::init_device) ENABLED START -----*/
	
	//	Initialize device
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::init_device
}

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


	//	Read device properties from database.
	Tango::DbData	dev_prop;
	dev_prop.push_back(Tango::DbDatum("CertificateFile"));
	dev_prop.push_back(Tango::DbDatum("StoragePath"));
	dev_prop.push_back(Tango::DbDatum("RemoteHost"));
	dev_prop.push_back(Tango::DbDatum("RemotePort"));
	dev_prop.push_back(Tango::DbDatum("RemoteUsername"));
	dev_prop.push_back(Tango::DbDatum("RemotePassword"));
	dev_prop.push_back(Tango::DbDatum("EnableSSL"));
	dev_prop.push_back(Tango::DbDatum("DatabaseHost"));
	dev_prop.push_back(Tango::DbDatum("DatabasePort"));
	dev_prop.push_back(Tango::DbDatum("DatabaseUsername"));
	dev_prop.push_back(Tango::DbDatum("DatabasePassword"));
	dev_prop.push_back(Tango::DbDatum("DatabaseSchema"));
	dev_prop.push_back(Tango::DbDatum("DatabaseTable"));
	dev_prop.push_back(Tango::DbDatum("Timeout"));

	//	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 DataImporterClass to get class property
		Tango::DbDatum	def_prop, cl_prop;
		DataImporterClass	*ds_class =
			(static_cast<DataImporterClass *>(get_device_class()));
		int	i = -1;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	}

	/*----- PROTECTED REGION ID(DataImporter::get_device_property_after) ENABLED START -----*/
	
	//	Check device property data members init
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::get_device_property_after
}
Marco De Marco's avatar
Marco De Marco committed

//--------------------------------------------------------
/**
 *	Method      : DataImporter::always_executed_hook()
 *	Description : method always executed before any command is executed
 */
//--------------------------------------------------------
void DataImporter::always_executed_hook()
{
	INFO_STREAM << "DataImporter::always_executed_hook()  " << device_name << endl;
	/*----- PROTECTED REGION ID(DataImporter::always_executed_hook) ENABLED START -----*/
	
	//	code always executed before all requests
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::always_executed_hook
}

//--------------------------------------------------------
/**
 *	Method      : DataImporter::read_attr_hardware()
 *	Description : Hardware acquisition for attributes
 */
//--------------------------------------------------------
void DataImporter::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
{
	DEBUG_STREAM << "DataImporter::read_attr_hardware(vector<long> &attr_list) entering... " << endl;
	/*----- PROTECTED REGION ID(DataImporter::read_attr_hardware) ENABLED START -----*/
	
	//	Add your own code
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::read_attr_hardware
}


//--------------------------------------------------------
/**
 *	Method      : DataImporter::add_dynamic_attributes()
 *	Description : Create the dynamic attributes if any
 *                for specified device.
 */
//--------------------------------------------------------
void DataImporter::add_dynamic_attributes()
{
	/*----- PROTECTED REGION ID(DataImporter::add_dynamic_attributes) ENABLED START -----*/
	
	//	Add your own code to create and add dynamic attributes if any
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::add_dynamic_attributes
}

//--------------------------------------------------------
/**
 *	Command On related method
 *	Description: Activate data importer
 *
 */
//--------------------------------------------------------
void DataImporter::on()
{
	DEBUG_STREAM << "DataImporter::On()  - " << device_name << endl;
	/*----- PROTECTED REGION ID(DataImporter::on) ENABLED START -----*/
	
	//	Add your own code
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::on
}
//--------------------------------------------------------
/**
 *	Command Off related method
 *	Description: Deactivate data importer
 *
 */
//--------------------------------------------------------
void DataImporter::off()
{
	DEBUG_STREAM << "DataImporter::Off()  - " << device_name << endl;
	/*----- PROTECTED REGION ID(DataImporter::off) ENABLED START -----*/
	
	//	Add your own code
	
	/*----- PROTECTED REGION END -----*/	//	DataImporter::off
}
Marco De Marco's avatar
Marco De Marco committed

/*----- PROTECTED REGION ID(DataImporter::namespace_ending) ENABLED START -----*/

//	Additional Methods

/*----- PROTECTED REGION END -----*/	//	DataImporter::namespace_ending
} //	namespace