Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cs/ds/alarm-handler
  • francesco.tripaldi/alarm-handler
2 results
Show changes
/*----- PROTECTED REGION ID(TestDevice::ClassFactory.cpp) ENABLED START -----*/
//=============================================================================
//
// file : ClassFactory.cpp
//
// description : C++ source for the class_factory method of the DServer
// device class. This method is responsible for the creation of
// all class singleton for a device server. It is called
// at device server startup.
//
// $Author: graziano $
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <tango/tango.h>
#include <TestDeviceClass.h>
// Add class header files if needed
/**
* Create TestDevice Class singleton and store it in DServer object.
*/
void Tango::DServer::class_factory()
{
// Add method class init if needed
add_class(TestDevice_ns::TestDeviceClass::init("TestDevice"));
}
/*----- PROTECTED REGION END -----*/
/*----- PROTECTED REGION ID(TestDevice.cpp) ENABLED START -----*/
//=============================================================================
//
// file : TestDevice.cpp
//
// description : C++ source for the TestDevice 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
// TestDevice are implemented in this file.
//
// $Author: graziano $
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <TestDevice.h>
#include <TestDeviceClass.h>
#include <math.h>
#include <iomanip>
#include <limits>
/*----- PROTECTED REGION END -----*/
/**
* TestDevice 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)
//================================================================
namespace TestDevice_ns
{
/*----- PROTECTED REGION ID(TestDevice::namespace_starting) ENABLED START -----*/
// static initializations
/*----- PROTECTED REGION END -----*/ // TestDevice::namespace_starting
//--------------------------------------------------------
/**
* Method : TestDevice::TestDevice()
* Description : Constructors for a Tango device
* implementing the class TestDevice
*/
//--------------------------------------------------------
TestDevice::TestDevice(Tango::DeviceClass *cl, string &s)
: TANGO_BASE_CLASS(cl, s.c_str())
{
/*----- PROTECTED REGION ID(TestDevice::constructor_1) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // TestDevice::constructor_1
}
//--------------------------------------------------------
TestDevice::TestDevice(Tango::DeviceClass *cl, const char *s)
: TANGO_BASE_CLASS(cl, s)
{
/*----- PROTECTED REGION ID(TestDevice::constructor_2) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // TestDevice::constructor_2
}
//--------------------------------------------------------
TestDevice::TestDevice(Tango::DeviceClass *cl, const char *s, const char *d)
: TANGO_BASE_CLASS(cl, s, d)
{
/*----- PROTECTED REGION ID(TestDevice::constructor_3) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // TestDevice::constructor_3
}
//--------------------------------------------------------
/**
* Method : TestDevice::delete_device()()
* Description : will be called at device destruction or at init command
*/
//--------------------------------------------------------
void TestDevice::delete_device()
{
/*----- PROTECTED REGION ID(TestDevice::delete_device) ENABLED START -----*/
// Delete device allocated objects
save_configuration();
map<std::string,map_data_t>::iterator it;
for(it = attr_data_map.begin(); it != attr_data_map.end(); it++)
{
if(it->second.type == Tango::DEV_DOUBLE)
delete [] (Tango::DevDouble *) it->second.value;
else if(it->second.type == Tango::DEV_LONG)
delete [] (Tango::DevLong *) it->second.value;
else if(it->second.type == Tango::DEV_BOOLEAN)
delete [] (Tango::DevBoolean *) it->second.value;
else if(it->second.type == Tango::DEV_STRING)
delete [] (char *) it->second.value; //TODO: !!!
}
/*----- PROTECTED REGION END -----*/ // TestDevice::delete_device
delete[] attr_ScalarDyn_read;
delete[] attr_Ref_read;
delete[] attr_Values_read;
}
//--------------------------------------------------------
/**
* Method : TestDevice::init_device()
* Description : // will be called at device initialization.
*/
//--------------------------------------------------------
void TestDevice::init_device()
{
DEBUG_STREAM << "TestDevice::init_device() create device " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::init_device_before) ENABLED START -----*/
// Initialization before get_device_property() call
dlastDB = 0.0;
waitingDB = false;
/*----- PROTECTED REGION END -----*/ // TestDevice::init_device_before
// Get the device properties (if any) from database
get_device_property();
attr_ScalarDyn_read = new Tango::DevString[1];
attr_Ref_read = new Tango::DevDouble[1024];
attr_Values_read = new Tango::DevString[1024];
/*----- PROTECTED REGION ID(TestDevice::init_device) ENABLED START -----*/
for (int i = 0; i < 1024; i++)
{
//ref_ptr[i] = ref_array[i];
attr_Values_read[i] = ref_array[i];
}
// Initialize device
gettimeofday(&last_read, NULL);
set_state(Tango::ON);
/*----- PROTECTED REGION END -----*/ // TestDevice::init_device
}
//--------------------------------------------------------
/**
* Method : TestDevice::get_device_property()
* Description : // Add your own code to initialize
*/
//--------------------------------------------------------
void TestDevice::get_device_property()
{
/*----- PROTECTED REGION ID(TestDevice::get_device_property_before) ENABLED START -----*/
// Initialize property data members
/*----- PROTECTED REGION END -----*/ // TestDevice::get_device_property_before
// Read device properties from database.
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("Attr_config"));
dev_prop.push_back(Tango::DbDatum("MinSaveDBPeriod"));
// 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 TestDeviceClass to get class property
Tango::DbDatum def_prop, cl_prop;
TestDeviceClass *ds_class =
(static_cast<TestDeviceClass *>(get_device_class()));
int i = -1;
// Try to initialize Attr_config from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> attr_config;
else {
// Try to initialize Attr_config from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> attr_config;
}
// And try to extract Attr_config value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> attr_config;
// Try to initialize MinSaveDBPeriod from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> minSaveDBPeriod;
else {
// Try to initialize MinSaveDBPeriod from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> minSaveDBPeriod;
}
// And try to extract MinSaveDBPeriod value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> minSaveDBPeriod;
}
/*----- PROTECTED REGION ID(TestDevice::get_device_property_after) ENABLED START -----*/
// Check device property data members init
/*----- PROTECTED REGION END -----*/ // TestDevice::get_device_property_after
}
//--------------------------------------------------------
/**
* Method : TestDevice::always_executed_hook()
* Description : method always executed before any command is executed
*/
//--------------------------------------------------------
void TestDevice::always_executed_hook()
{
//INFO_STREAM << "TestDevice::always_executed_hook() " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::always_executed_hook) ENABLED START -----*/
// code always executed before all requests
/*----- PROTECTED REGION END -----*/ // TestDevice::always_executed_hook
}
//--------------------------------------------------------
/**
* Method : TestDevice::read_attr_hardware()
* Description : Hardware acquisition for attributes.
*/
//--------------------------------------------------------
void TestDevice::read_attr_hardware(vector<long> &attr_list)
{
//DEBUG_STREAM << "TestDevice::read_attr_hardware(vector<long> &attr_list) entering... " << endl;
/*----- PROTECTED REGION ID(TestDevice::read_attr_hardware) ENABLED START -----*/
// Add your own code
if(waitingDB)
{
timeval now;
gettimeofday(&now, NULL);
double dnow=now.tv_sec + (double)now.tv_usec/1000000.0;
if(dnow - dlastDB > minSaveDBPeriod)
{
save_configuration();
dlastDB = dnow;
waitingDB = false;
}
}
/*----- PROTECTED REGION END -----*/ // TestDevice::read_attr_hardware
}
//--------------------------------------------------------
/**
* Read ScalarDyn attribute
* Description:
*
* Data type: Tango::DevDouble
* Attr type: Scalar
*/
//--------------------------------------------------------
void TestDevice::read_ScalarDyn(Tango::Attribute &attr)
{
//DEBUG_STREAM << "TestDevice::read_ScalarDyn(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(TestDevice::read_ScalarDyn) ENABLED START -----*/
map<std::string,map_data_t>::iterator it = attr_data_map.find(attr.get_name());
if(it == attr_data_map.end())
Tango::Except::throw_exception((const char*) "Exception reading attribute",
(const char*) "Attribute Not Found", __FUNCTION__, Tango::ERR);
if(it->second.type == Tango::DEV_DOUBLE)
{
attr.set_value_date_quality((Tango::DevDouble *) it->second.value,it->second.ts,Tango::ATTR_VALID, 1, 0, false);
}
else if(it->second.type == Tango::DEV_LONG)
{
attr.set_value_date_quality((Tango::DevLong *) it->second.value,it->second.ts,Tango::ATTR_VALID, 1, 0, false);
}
else if(it->second.type == Tango::DEV_BOOLEAN)
{
attr.set_value_date_quality((Tango::DevBoolean *) it->second.value,it->second.ts,Tango::ATTR_VALID, 1, 0, false);
}
else if(it->second.type == Tango::DEV_STRING)
{
*attr_ScalarDyn_read = (char *) it->second.value;
attr.set_value_date_quality(attr_ScalarDyn_read,it->second.ts,Tango::ATTR_VALID, 1, 0, false);
//attr.set_value_date_quality((Tango::DevString *) it->second.value,it->second.ts,Tango::ATTR_VALID, 1, 0, false);
}
/*----- PROTECTED REGION END -----*/ // TestDevice::read_ScalarDyn
}
//+----------------------------------------------------------------------------
//
// method : TestDevice::write_ScalarDyn
//
// description : Write ScalarDyn attribute values to hardware.
//
//-----------------------------------------------------------------------------
void TestDevice::write_ScalarDyn(Tango::WAttribute &attr)
{
DEBUG_STREAM << "TestDevice::write_ScalarDyn(Tango::WAttribute &attr) entering... "<< endl;
/*----- PROTECTED REGION ID(TestDevice::write_ScalarDyn) ENABLED START -----*/
map<std::string,map_data_t>::iterator it = attr_data_map.find(attr.get_name());
if(it == attr_data_map.end())
Tango::Except::throw_exception((const char*) "Exception reading attribute",
(const char*) "Attribute Not Found", __FUNCTION__, Tango::ERR);
gettimeofday(&(it->second.ts), NULL);
if(it->second.type == Tango::DEV_DOUBLE)
{
Tango::DevDouble w_val;
attr.get_write_value(w_val);
*(Tango::DevDouble *) it->second.value = w_val;
try{
push_change_event(attr.get_name(),(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
push_archive_event(attr.get_name(),(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_LONG)
{
Tango::DevLong w_val;
attr.get_write_value(w_val);
*(Tango::DevLong *) it->second.value = w_val;
try{
push_change_event(attr.get_name(),(Tango::DevLong *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
push_archive_event(attr.get_name(),(Tango::DevLong *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_BOOLEAN)
{
Tango::DevBoolean w_val;
attr.get_write_value(w_val);
*(Tango::DevBoolean *) it->second.value = w_val;
try{
push_change_event(attr.get_name(),(Tango::DevBoolean *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
push_archive_event(attr.get_name(),(Tango::DevBoolean *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_STRING)
{
Tango::DevString w_val;
attr.get_write_value(w_val);
memset((char *) it->second.value, 0, 1024);
strncpy((char *) it->second.value,w_val, 1023);
//try{
// push_change_event(attr.get_name(),(Tango::DevString *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
// push_archive_event(attr.get_name(),(Tango::DevString *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
//}catch(...){}
}
timeval now;
gettimeofday(&now, NULL);
double dnow=now.tv_sec + (double)now.tv_usec/1000000.0;
if(dnow - dlastDB > minSaveDBPeriod)
{
save_configuration();
dlastDB = dnow;
waitingDB = false;
}
else
{
waitingDB = true;
}
/*----- PROTECTED REGION END -----*/ // TestDevice::write_ScalarDyn
}
//--------------------------------------------------------
/**
* Read SpectrumDyn attribute
* Description:
*
* Data type: Tango::DevDouble
* Attr type: Spectrum
*/
//--------------------------------------------------------
void TestDevice::read_SpectrumDyn(Tango::Attribute &attr)
{
//DEBUG_STREAM << "TestDevice::read_SpectrumDyn(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(TestDevice::read_SpectrumDyn) ENABLED START -----*/
map<std::string,map_data_t>::iterator it = attr_data_map.find(attr.get_name());
if(it == attr_data_map.end())
Tango::Except::throw_exception((const char*) "Exception reading attribute",
(const char*) "Attribute Not Found", __FUNCTION__, Tango::ERR);
if(it->second.type == Tango::DEV_DOUBLE)
{
attr.set_value_date_quality((Tango::DevDouble *) it->second.value,it->second.ts,Tango::ATTR_VALID, it->second.size1, 0, false);
}
else if(it->second.type == Tango::DEV_LONG)
{
attr.set_value_date_quality((Tango::DevLong *) it->second.value,it->second.ts,Tango::ATTR_VALID, it->second.size1, 0, false);
}
else if(it->second.type == Tango::DEV_BOOLEAN)
{
attr.set_value_date_quality((Tango::DevBoolean *) it->second.value,it->second.ts,Tango::ATTR_VALID, it->second.size1, 0, false);
}
else if(it->second.type == Tango::DEV_STRING)
{
//NOT SUPPORTED
}
/*----- PROTECTED REGION END -----*/ // TestDevice::read_SpectrumDyn
}
//+----------------------------------------------------------------------------
//
// method : TestDevice::write_SpectrumDyn
//
// description : Write SpectrumDyn attribute values to hardware.
//
//-----------------------------------------------------------------------------
void TestDevice::write_SpectrumDyn(Tango::WAttribute &attr)
{
DEBUG_STREAM << "TestDevice::write_SpectrumDyn(Tango::WAttribute &attr) entering... "<< endl;
/*----- PROTECTED REGION ID(TestDevice::write_SpectrumDyn) ENABLED START -----*/
map<std::string,map_data_t>::iterator it = attr_data_map.find(attr.get_name());
if(it == attr_data_map.end())
Tango::Except::throw_exception((const char*) "Exception reading attribute",
(const char*) "Attribute Not Found", __FUNCTION__, Tango::ERR);
gettimeofday(&(it->second.ts), NULL);
size_t value_size = attr.get_write_value_length();
it->second.size1 = value_size > MAX_SPECTRUM_SIZE ? MAX_SPECTRUM_SIZE : value_size;
if(it->second.type == Tango::DEV_DOUBLE)
{
const Tango::DevDouble * w_val;
attr.get_write_value(w_val);
for(size_t ind=0; ind < it->second.size1; ind++)
{
((Tango::DevDouble *) it->second.value)[ind] = w_val[ind];
}
try{
push_change_event(attr.get_name(),(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ it->second.size1, 0, false);
push_archive_event(attr.get_name(),(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ it->second.size1, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_LONG)
{
const Tango::DevLong * w_val;
attr.get_write_value(w_val);
for(size_t ind=0; ind < it->second.size1; ind++)
{
((Tango::DevLong *) it->second.value)[ind] = w_val[ind];
}
try{
push_change_event(attr.get_name(),(Tango::DevLong *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ it->second.size1, 0, false);
push_archive_event(attr.get_name(),(Tango::DevLong *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ it->second.size1, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_BOOLEAN)
{
const Tango::DevBoolean * w_val;
attr.get_write_value(w_val);
for(size_t ind=0; ind<it->second.size1; ind++)
{
((Tango::DevBoolean *) it->second.value)[ind] = w_val[ind];
}
try{
push_change_event(attr.get_name(),(Tango::DevBoolean *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ it->second.size1, 0, false);
push_archive_event(attr.get_name(),(Tango::DevBoolean *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ it->second.size1, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_STRING)
{
//NOT SUPPORTED
}
timeval now;
gettimeofday(&now, NULL);
double dnow=now.tv_sec + (double)now.tv_usec/1000000.0;
if(dnow - dlastDB > minSaveDBPeriod)
{
save_configuration();
dlastDB = dnow;
waitingDB = false;
}
else
{
waitingDB = true;
}
/*----- PROTECTED REGION END -----*/ // TestDevice::write_SpectrumDyn
}
//--------------------------------------------------------
/**
* Read Ref attribute
* Description:
*
* Data type: Tango::DevString
* Attr type: Scalar
*/
//--------------------------------------------------------
void TestDevice::read_Ref(Tango::Attribute &attr)
{
//DEBUG_STREAM << "TestDevice::read_Ref(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(TestDevice::read_Ref) ENABLED START -----*/
map<std::string,map_data_t>::iterator it;
int i=0;
for(it = attr_data_map.begin(), i=0; it != attr_data_map.end() && i<1024; it++)
{
if(it->second.type == Tango::DEV_DOUBLE)
attr_Ref_read[i++] = *((Tango::DevDouble *) it->second.value);
}
attr.set_value(attr_Ref_read, i);
/*----- PROTECTED REGION END -----*/ // TestDevice::read_Ref
}
//+----------------------------------------------------------------------------
//
// method : TestDevice::write_Ref
//
// description : Write Ref attribute values to hardware.
//
//-----------------------------------------------------------------------------
void TestDevice::write_Ref(Tango::WAttribute &attr)
{
DEBUG_STREAM << "TestDevice::write_Ref(Tango::Attribute &attr) entering... " << endl;
// Retrieve write value
const Tango::DevDouble *w_val;
attr.get_write_value(w_val);
/*----- PROTECTED REGION ID(TestDevice::write_Ref) ENABLED START -----*/
int size_ref = attr.get_write_value_length();
size_ref = size_ref<1024 ? size_ref : 1024;
double tmp;
int i=0;
attr.get_write_value(tmp);
for(map<std::string,map_data_t>::iterator it=attr_data_map.begin(); it != attr_data_map.end() && i<size_ref; it++)
{
if(it->second.type == Tango::DEV_DOUBLE)
{
gettimeofday(&(it->second.ts), NULL);
*(Tango::DevDouble *) it->second.value = w_val[i++];
try {
push_change_event(it->first,(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
push_archive_event(it->first,(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
}catch(...){}
}
}
timeval now;
gettimeofday(&now, NULL);
double dnow=now.tv_sec + (double)now.tv_usec/1000000.0;
if(dnow - dlastDB > minSaveDBPeriod)
{
save_configuration();
dlastDB = dnow;
waitingDB = false;
}
else
{
waitingDB = true;
}
/*----- PROTECTED REGION END -----*/// TestDevice::write_Ref
}
//--------------------------------------------------------
/**
* Read Values attribute
* Description:
*
* Data type: Tango::DevString
* Attr type: Scalar
*/
//--------------------------------------------------------
void TestDevice::read_Values(Tango::Attribute &attr)
{
//DEBUG_STREAM << "TestDevice::read_Values(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(TestDevice::read_Values) ENABLED START -----*/
map<std::string,map_data_t>::iterator it;
int i;
for(it = attr_data_map.begin(), i=0; it != attr_data_map.end() && i<1024; it++, i++)
{
stringstream val;
if(it->second.type == Tango::DEV_DOUBLE)
{
for(size_t ind=0; ind<it->second.size1; ind++)
{
val << std::setprecision(std::numeric_limits<Tango::DevDouble>::digits10+2) << ((Tango::DevDouble *) it->second.value)[ind];
if(ind < it->second.size1-1)
val << ",";
}
sprintf(ref_array[i], "%s=%s", it->first.c_str(), val.str().c_str());
}
else if(it->second.type == Tango::DEV_LONG)
{
for(size_t ind=0; ind<it->second.size1; ind++)
{
val << std::setprecision(std::numeric_limits<Tango::DevLong>::digits10+2) << ((Tango::DevLong *) it->second.value)[ind];
if(ind < it->second.size1-1)
val << ",";
}
sprintf(ref_array[i], "%s=%s", it->first.c_str(), val.str().c_str());
}
else if(it->second.type == Tango::DEV_BOOLEAN)
{
for(size_t ind=0; ind<it->second.size1; ind++)
{
val << (((Tango::DevBoolean *) it->second.value)[ind] ? "true" : "false");
if(ind < it->second.size1-1)
val << ",";
}
sprintf(ref_array[i], "%s=%s", it->first.c_str(), val.str().c_str());
}
else if(it->second.type == Tango::DEV_STRING)
{
sprintf(ref_array[i], "%s=%s", it->first.c_str(), ((char *) it->second.value));
}
}
attr.set_value(attr_Values_read, i);
/*----- PROTECTED REGION END -----*/ // TestDevice::read_Values
}
//+----------------------------------------------------------------------------
//
// method : TestDevice::write_Ref
//
// description : Write Ref attribute values to hardware.
//
//-----------------------------------------------------------------------------
void TestDevice::write_Values(Tango::WAttribute &attr)
{
DEBUG_STREAM << "TestDevice::write_Values(Tango::Attribute &attr) entering... " << endl;
// Retrieve write value
const Tango::ConstDevString *w_val;
attr.get_write_value(w_val);
/*----- PROTECTED REGION ID(TestDevice::write_Values) ENABLED START -----*/
int size_ref = attr.get_write_value_length();
size_ref = size_ref<1024 ? size_ref : 1024;
double tmp;
int i=0;
attr.get_write_value(tmp);
for(i=0; i<size_ref; i++)
{
vector<string> results;
string_explode(w_val[i], "=", &results);
if(results.size() == 2)
{
map<std::string,map_data_t>::iterator it = attr_data_map.find(results[0]);
if(it == attr_data_map.end())
continue;
/*Tango::Except::throw_exception((const char*) "Exception writing attribute",
string("Attribute '") + string(results[0]) + string("' not found"), __FUNCTION__, Tango::ERR);*/
gettimeofday(&(it->second.ts), NULL);
vector<string> values;
string_explode(results[1], ",", &values);
if(it->second.type == Tango::DEV_BOOLEAN)
{
size_t ind=0;
for(vector<string>::iterator val=values.begin(); val != values.end() && ind<it->second.size1; val++)
{
if(*val == "true")
((Tango::DevBoolean *) it->second.value)[ind++] = true;
else if(*val == "false")
((Tango::DevBoolean *) it->second.value)[ind++] = false;
else
((Tango::DevBoolean *) it->second.value)[ind++] = atoi(val->c_str());
}
try {
set_write_value((Tango::DevBoolean *) it->second.value, results[0], it->second.size1);
push_change_event(it->first,(Tango::DevBoolean *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ it->second.size1/*size*/, 0, false);
push_archive_event(it->first,(Tango::DevBoolean *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ it->second.size1/*size*/, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_LONG)
{
size_t ind=0;
for(vector<string>::iterator val=values.begin(); val != values.end() && ind<it->second.size1; val++)
{
((Tango::DevLong *) it->second.value)[ind++] = atoi(results[1].c_str());
}
try {
set_write_value((Tango::DevLong *) it->second.value, results[0], it->second.size1);
push_change_event(it->first,(Tango::DevLong *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
push_archive_event(it->first,(Tango::DevLong *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_DOUBLE)
{
size_t ind=0;
for(vector<string>::iterator val=values.begin(); val != values.end() && ind<it->second.size1; val++)
{
((Tango::DevDouble *) it->second.value)[ind++] = atof(results[1].c_str());
}
try {
set_write_value((Tango::DevDouble *) it->second.value, results[0], it->second.size1);
push_change_event(it->first,(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
push_archive_event(it->first,(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
}catch(...){}
}
else if(it->second.type == Tango::DEV_STRING)
{
memset((char *) it->second.value, 0, 1024);
strncpy((char *) it->second.value,results[1].c_str(), 1023);
Tango::DevString str_ptr = (char *) it->second.value;
set_write_value((Tango::DevString ) str_ptr, results[0]);
}
}
}
timeval now;
gettimeofday(&now, NULL);
double dnow=now.tv_sec + (double)now.tv_usec/1000000.0;
if(dnow - dlastDB > minSaveDBPeriod)
{
save_configuration();
dlastDB = dnow;
waitingDB = false;
}
else
{
waitingDB = true;
}
//and now push events
/*----- PROTECTED REGION END -----*/// TestDevice::write_Ref
}
//--------------------------------------------------------
/**
* Method : TestDevice::TestDeviceClass::add_dynamic_attributes()
* Description : Create the dynamic attributes if any
* for specified device.
*/
//--------------------------------------------------------
void TestDevice::add_dynamic_attributes()
{
/*----- PROTECTED REGION ID(TestDevice::Class::add_dynamic_attributes) ENABLED START -----*/
// Add your own code to create and add dynamic attributes if any
DEBUG_STREAM << __FUNCTION__ << " entering...";
if (attr_config.empty() == false)
{
for(vector<string>::iterator it = attr_config.begin();it != attr_config.end(); it++)
{
vector<string> results;
string_explode(*it, ":", &results);
try
{
create_dynamic_attribute(results);
} catch(Tango::DevFailed &e)
{
INFO_STREAM << __FUNCTION__ << " Error reading creating attribute='" << e.errors[0].desc << "'";
}
}
}
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::add_dynamic_attributes
}
//========================================================
// Command execution methods
//========================================================
//--------------------------------------------------------
/**
* Execute the WriteAttrname command:
* Description: Delete all Double attributes and create new ones.
*
* @param argin List of double attributes to write.
* @returns
*/
//--------------------------------------------------------
void TestDevice::write_attrname(const Tango::DevVarDoubleStringArray *argin)
{
DEBUG_STREAM << "TestDevice::write_attrname() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::write_attrname) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
double tmp;
int lens, lend, lenmin;
string name;
int i=0;
lens = argin->svalue.length();
lend = argin->dvalue.length();
lenmin = (lens <= lend) ? lens : lend;
for(i=0; i<lenmin; i++)
{
name = string(argin->svalue[i]);
tmp = argin->dvalue[i];
map<std::string,map_data_t>::iterator it = attr_data_map.find(name);
if(it == attr_data_map.end())
Tango::Except::throw_exception((const char*) "Exception writing attribute", string("Attribute '") + name
+ string("' not found"), __FUNCTION__, Tango::ERR);
if(it->second.type != Tango::DEV_DOUBLE)
{
Tango::Except::throw_exception((const char*) "Exception writing attribute", string("Attribute '") + name
+ string("' is not of type double"), __FUNCTION__, Tango::ERR);
}
else
{
gettimeofday(&(it->second.ts), NULL);
*(Tango::DevDouble *) it->second.value = tmp;
try {
push_change_event(it->first,(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
push_archive_event(it->first,(Tango::DevDouble *)(it->second.value),/*NULL,Tango::ATTR_VALID,*/ 1/*size*/, 0, false);
}catch(...){}
timeval now;
gettimeofday(&now, NULL);
double dnow=now.tv_sec + (double)now.tv_usec/1000000.0;
if(dnow - dlastDB > minSaveDBPeriod)
{
save_configuration();
dlastDB = dnow;
waitingDB = false;
}
else
{
waitingDB = true;
}
}
}
/*----- PROTECTED REGION END -----*/// TestDevice::write_attrname
return;
}
//--------------------------------------------------------
/**
* Execute the ReadAttrname command:
* Description: Delete all Double attributes and create new ones.
*
* @param argin List of new double attributes.
* @returns
*/
//--------------------------------------------------------
Tango::DevVarDoubleArray * TestDevice::read_attrname(const Tango::DevVarStringArray *argin)
{
Tango::DevVarDoubleArray *argout;
DEBUG_STREAM << "TestDevice::read_attrname() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::read_attrname) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
argout = new Tango::DevVarDoubleArray();
vector<string> attributes;
attributes << (*argin);
double *tmp = new double[attributes.size()];
string name;
unsigned int index = 0;
for(vector<string>::iterator its = attributes.begin(); its != attributes.end(); its++)
{
name = *its;
map<std::string, map_data_t>::iterator it = attr_data_map.find(name);
if(it == attr_data_map.end())
{
delete [] tmp;
Tango::Except::throw_exception((const char*) "Exception reading attribute", string("Attribute '") + name
+ string("' not found"), __FUNCTION__, Tango::ERR);
}
if(it->second.type == Tango::DEV_DOUBLE)
{
tmp[index++] = *((Tango::DevDouble *) it->second.value);
}
else
{
delete [] tmp;
Tango::Except::throw_exception((const char*) "Exception reading attribute", string("Attribute '") + name
+ string("' is not of type double"), __FUNCTION__, Tango::ERR);
}
}
//if found all names
if(index == attributes.size())
{
argout->length(index);
for(unsigned int i=0; i<index; i++)
(*argout)[i] = tmp[i];
}
delete [] tmp;
/*----- PROTECTED REGION END -----*/// TestDevice::read_attrname
return argout;
}
//--------------------------------------------------------
/**
* Execute the Config command:
* Description: Delete all Double attributes and create new ones.
*
* @param argin List of new double attributes.
* @returns
*/
//--------------------------------------------------------
void TestDevice::config(const Tango::DevVarStringArray *argin)
{
DEBUG_STREAM << "TestDevice::config() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::config) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
vector<string> attributes;
attributes << (*argin);
#if 1
//TODO: verify memory leak
for(unsigned int i = 0; i < this->get_device_attr()->get_attr_nb(); i++)
{
string attr_name = get_device_attr()->get_attr_by_ind(i).get_name();
if((attr_name != "State") && (attr_name != "Status") && (attr_name != "Ref") && (attr_name != "Values"))
{
DEBUG_STREAM << "TestDevice::config: i=" << i << " removing attribute: "
<< attr_name << endl;
//TODO: update_idx=Flag set to true if the attributes object index
// used to retrieve the corresponding Attr object has to be
// updated (because one Attr object has been removed)
this->get_device_attr()->remove_attribute(attr_name, /*update_idx*/true);
i--;
}
}
#else
erase_dynamic_attributes() //TODO
#endif
map<std::string,map_data_t>::iterator it;
for(it = attr_data_map.begin(); it != attr_data_map.end(); it++)
{
if(it->second.type == Tango::DEV_DOUBLE)
delete [] (Tango::DevDouble *) it->second.value;
else if(it->second.type == Tango::DEV_LONG)
delete [] (Tango::DevLong *) it->second.value;
else if(it->second.type == Tango::DEV_BOOLEAN)
delete [] (Tango::DevBoolean *) it->second.value;
else if(it->second.type == Tango::DEV_STRING)
delete [] (char *) it->second.value;
}
try
{
attr_data_map.clear();
DEBUG_STREAM << "TestDevice::config: attr_data_map cleared !" << endl;
} catch(...)
{
WARN_STREAM << "TestDevice::delete_device: Could not clear attr_data_map !" << endl;
}
numAttr = attributes.size();
for(int j = 0; j < numAttr; j++)
{
Tango::Attr *cspec;
char attrname[256];
Tango::UserDefaultAttrProp attrprop;
sprintf(attrname, "%s", attributes[j].c_str());
cspec = new ScalarDynAttrib(attrname, Tango::DEV_DOUBLE);
/*sprintf(strtmp,"Dynamic Attribute %s reading channel %d ",attrname,num_ch);
if(unit != "")
{
attrprop.set_unit(unit.c_str());
attrprop.set_standard_unit("1.0");
attrprop.set_display_unit(unit.c_str());
}
attrprop.set_format("%.9g");
attrprop.set_description(strtmp);*/
cspec->set_default_properties(attrprop);
add_attribute(cspec);
struct timeval curr_time;
//gettimeofday(&curr_time,NULL);
curr_time.tv_sec = 0;
double *value = new double();
map_data_t tmp;
tmp.value = value;
tmp.size1 = 1;
tmp.size2 = 0;
tmp.max1 = 1;
tmp.max2 = 1;
tmp.type = Tango::DEV_DOUBLE;
tmp.ts = curr_time;
attr_data_map.insert(make_pair(attrname, tmp));
}
save_configuration();
/*----- PROTECTED REGION END -----*/// TestDevice::config
return;
}
//--------------------------------------------------------
/**
* Execute the Add command:
* Description: Create new attributes.
*
* @param argin List of new attributes.
* @returns
*/
//--------------------------------------------------------
void TestDevice::add(const Tango::DevVarStringArray *argin)
{
DEBUG_STREAM << "TestDevice::add() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::add) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
vector<string> attributes;
attributes << (*argin);
for(vector<string>::iterator it = attributes.begin();it != attributes.end(); it++)
{
DEBUG_STREAM << __func__ << ": adding '" << *it << "'";
vector<string> results;
string_explode(*it, ":", &results);
create_dynamic_attribute(results);
}
save_configuration();
/*----- PROTECTED REGION END -----*/// TestDevice::add
return;
}
//--------------------------------------------------------
/**
* Execute the AddDouble command:
* Description: Create new attributes.
*
* @param argin List of new attributes.
* @returns
*/
//--------------------------------------------------------
void TestDevice::add_double(const Tango::DevVarStringArray *argin)
{
DEBUG_STREAM << "TestDevice::add_double() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::add_double) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
vector<string> attributes;
attributes << (*argin);
for(vector<string>::iterator it = attributes.begin();it != attributes.end(); it++)
{
vector<string> results;
results.push_back(*it);
results.push_back("double");
results.push_back("0");
results.push_back("0");
create_dynamic_attribute(results);
}
save_configuration();
/*----- PROTECTED REGION END -----*/// TestDevice::add_double
return;
}
//--------------------------------------------------------
/**
* Execute the AddLong command:
* Description: Create new attributes.
*
* @param argin List of new attributes.
* @returns
*/
//--------------------------------------------------------
void TestDevice::add_long(const Tango::DevVarStringArray *argin)
{
DEBUG_STREAM << "TestDevice::add_long() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::add_long) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
vector<string> attributes;
attributes << (*argin);
for(vector<string>::iterator it = attributes.begin();it != attributes.end(); it++)
{
vector<string> results;
results.push_back(*it);
results.push_back("long");
results.push_back("0");
results.push_back("0");
create_dynamic_attribute(results);
}
save_configuration();
/*----- PROTECTED REGION END -----*/// TestDevice::add_long
return;
}
//--------------------------------------------------------
/**
* Execute the AddBool command:
* Description: Create new attributes.
*
* @param argin List of new attributes.
* @returns
*/
//--------------------------------------------------------
void TestDevice::add_bool(const Tango::DevVarStringArray *argin)
{
DEBUG_STREAM << "TestDevice::add_bool() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::add_bool) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
vector<string> attributes;
attributes << (*argin);
for(vector<string>::iterator it = attributes.begin();it != attributes.end(); it++)
{
vector<string> results;
results.push_back(*it);
results.push_back("bool");
results.push_back("0");
results.push_back("0");
create_dynamic_attribute(results);
}
save_configuration();
/*----- PROTECTED REGION END -----*/// TestDevice::add_bool
return;
}
//--------------------------------------------------------
/**
* Execute the AddString command:
* Description: Create new attributes.
*
* @param argin List of new attributes.
* @returns
*/
//--------------------------------------------------------
void TestDevice::add_string(const Tango::DevVarStringArray *argin)
{
DEBUG_STREAM << "TestDevice::add_string() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::add_string) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
vector<string> attributes;
attributes << (*argin);
for(vector<string>::iterator it = attributes.begin();it != attributes.end(); it++)
{
vector<string> results;
results.push_back(*it);
results.push_back("string");
results.push_back("0");
results.push_back("0");
create_dynamic_attribute(results);
}
save_configuration();
/*----- PROTECTED REGION END -----*/// TestDevice::add_string
return;
}
//--------------------------------------------------------
/**
* Execute the Remove command:
* Description: Remove attributes.
*
* @param argin List of attributes.
* @returns
*/
//--------------------------------------------------------
void TestDevice::remove(const Tango::DevVarStringArray *argin)
{
DEBUG_STREAM << "TestDevice::remove() - " << device_name << endl;
/*----- PROTECTED REGION ID(TestDevice::remove) ENABLED START -----*/
// Add your own code
// POGO has generated a method core with argout allocation.
// If you would like to use a static reference without copying,
// See "TANGO Device Server Programmer's Manual"
// (chapter : Writing a TANGO DS / Exchanging data)
//------------------------------------------------------------
// Add your own code to control device here
vector<string> attributes;
attributes << (*argin);
//TODO: verify memory leak
for(vector<string>::iterator it = attributes.begin(); it != attributes.end(); it++)
{
if((*it != "State") && (*it != "Status") && (*it != "Ref"))
{
map<std::string,map_data_t>::iterator it_attr = attr_data_map.find(*it);
if(it_attr == attr_data_map.end())
{
Tango::Except::throw_exception((const char*) "Exception removing attribute", string("Attribute '")
+ string(*it) + string("' not found"), __FUNCTION__, Tango::ERR);
}
DEBUG_STREAM << __FUNCTION__ << ": removing attribute: " << *it;
//TODO: update_idx=Flag set to true if the attributes object index
// used to retrieve the corresponding Attr object has to be
// updated (because one Attr object has been removed)
this->get_device_attr()->remove_attribute(*it, /*update_idx*/true);
try
{
if(it_attr->second.type == Tango::DEV_DOUBLE)
delete [] (Tango::DevDouble *) it_attr->second.value;
else if(it_attr->second.type == Tango::DEV_LONG)
delete [] (Tango::DevLong *) it_attr->second.value;
else if(it_attr->second.type == Tango::DEV_BOOLEAN)
delete [] (Tango::DevBoolean *) it_attr->second.value;
else if(it_attr->second.type == Tango::DEV_STRING)
delete [] (char *) it_attr->second.value;
attr_data_map.erase(/**it*/it_attr);
DEBUG_STREAM << __FUNCTION__ << ": " << *it << " removed from attr_data_map";
} catch(...)
{
WARN_STREAM << __FUNCTION__ << ": ERROR removing " << *it << " from attr_data_map";
}
save_configuration();
}
}
/*----- PROTECTED REGION END -----*/// TestDevice::remove
return;
}
/*----- PROTECTED REGION ID(TestDevice::namespace_ending) ENABLED START -----*/
// Additional Methods
//+------------------------------------------------------------------
/*
* method: TestDevice::create_dynamic_attribute
* Create and configure an attribute
*/
//+------------------------------------------------------------------
void TestDevice::create_dynamic_attribute(vector<string> config)
{
if(config.size() == 3 || config.size() == 4)
{
Tango::Attr *attr;
char attrname[256];
Tango::UserDefaultAttrProp attrprop;
struct timeval attr_time;
if(config.size() == 4)
{
vector<string> timestamp;
string_explode(config[3], ".", &timestamp);
if(timestamp.size() == 2)
{
attr_time.tv_sec = atoi(timestamp[0].c_str());
attr_time.tv_usec = atoi(timestamp[1].c_str());
if(attr_time.tv_sec == 0)
gettimeofday(&attr_time,NULL);
}
else
{
gettimeofday(&attr_time,NULL);
}
}
else
{
gettimeofday(&attr_time,NULL);
}
strcpy(attrname, config[0].c_str());
if(attr_data_map.find(attrname) != attr_data_map.end())
Tango::Except::throw_exception((const char*) "Exception creating attribute",
string("Attribute '") + string(attrname) + string("' already existing"), __FUNCTION__, Tango::ERR);
vector<string> values;
string_explode(config[2], ",", &values);
map_data_t tmp;
tmp.size1 = (values.size() > MAX_SPECTRUM_SIZE) ? MAX_SPECTRUM_SIZE : values.size();
tmp.size2 = 0;
tmp.max1 = 1;
tmp.max2 = 1;
tmp.ts = attr_time;
size_t value_size = (tmp.size1 > 1) ? MAX_SPECTRUM_SIZE : 1;
if(config[1] == "bool")
{
tmp.type = Tango::DEV_BOOLEAN;
Tango::DevBoolean *value = new Tango::DevBoolean[value_size];
size_t ind=0;
for(vector<string>::iterator val=values.begin(); val != values.end() && ind < tmp.size1; val++)
{
if(*val == "true")
value[ind++] = true;
else if(*val == "false")
value[ind++] = false;
else
value[ind++] = atoi(val->c_str());
}
tmp.value = value;
}
else if(config[1] == "long")
{
tmp.type = Tango::DEV_LONG;
Tango::DevLong *value = new Tango::DevLong[value_size];
size_t ind=0;
for(vector<string>::iterator val=values.begin(); val != values.end() && ind < tmp.size1; val++)
{
value[ind++] = atoi(val->c_str());
}
tmp.value = value;
}
else if(config[1] == "double")
{
tmp.type = Tango::DEV_DOUBLE;
Tango::DevDouble *value = new Tango::DevDouble[value_size];
size_t ind=0;
for(vector<string>::iterator val=values.begin(); val != values.end() && ind < tmp.size1; val++)
{
value[ind++] = atof(val->c_str());
}
tmp.value = value;
}
else if(config[1] == "string")
{
tmp.size1 = 1;
tmp.type = Tango::DEV_STRING;
char *value = new char[1024];
memset(value, 0, 1024);
strncpy(value, config[2].c_str(), 1023);
tmp.value = value;
}
if(tmp.size1 == 1)
attr = new ScalarDynAttrib(attrname, tmp.type);
else
attr = new SpectrumDynAttrib(attrname, tmp.type, MAX_SPECTRUM_SIZE);
/*sprintf(strtmp,"Dynamic Attribute %s reading channel %d ",attrname,num_ch);
if(unit != "")
{
attrprop.set_unit(unit.c_str());
attrprop.set_standard_unit("1.0");
attrprop.set_display_unit(unit.c_str());
}
attrprop.set_format("%.9g");
attrprop.set_description(strtmp);*/
attr->set_default_properties(attrprop);
add_attribute(attr);
set_change_event(attrname, true, false);
set_archive_event(attrname, true, false);
attr_data_map.insert(make_pair(attrname, tmp));
try
{
if(config[1] == "bool")
{
set_write_value(((Tango::DevBoolean *)tmp.value), attrname, tmp.size1);
}
else if(config[1] == "long")
{
set_write_value(((Tango::DevLong *)tmp.value), attrname, tmp.size1);
}
else if(config[1] == "double")
{
set_write_value(((Tango::DevDouble *)tmp.value), attrname, tmp.size1);
}
else if(config[1] == "string")
{
Tango::DevString str_ptr = (char *)tmp.value;
set_write_value((Tango::DevString)str_ptr, attrname);
}
} catch(Tango::DevFailed &e)
{
INFO_STREAM << __FUNCTION__ << " error seting write value=" << e.errors[0].desc;
}
}
}
//+------------------------------------------------------------------
/*
* method: TestDevice::string_explode
* Explode a string
*/
//+------------------------------------------------------------------
void TestDevice::string_explode(string str, string separator, vector<string>* results)
{
size_t found;
found = str.find_first_of(separator);
while(found != string::npos) {
if(found > 0) {
results->push_back(str.substr(0,found));
}
str = str.substr(found+1);
found = str.find_first_of(separator);
}
if(str.length() > 0) {
results->push_back(str);
}
}
//+------------------------------------------------------------------
/*
* method: TestDevice::save_configuration
* Save configuration on DB
*/
//+------------------------------------------------------------------
void TestDevice::save_configuration()
{
Tango::Database *db = new Tango::Database();
try
{
db->set_timeout_millis(10000); //10 s timeout
vector<string> configuration;
char conf_str[256];
map<std::string,map_data_t>::iterator it;
for(it = attr_data_map.begin(); it != attr_data_map.end(); it++)
{
double ts = (double)(it->second.ts.tv_sec) + ((double)it->second.ts.tv_usec)/1000000.0;
if(it->second.size1 == 1)
{
if(it->second.type == Tango::DEV_DOUBLE)
sprintf(conf_str, "%s:double:%.16e:%f", it->first.c_str(), *((Tango::DevDouble *) it->second.value), ts);
else if(it->second.type == Tango::DEV_LONG)
sprintf(conf_str, "%s:long:%d:%f", it->first.c_str(), *((Tango::DevLong *) it->second.value), ts);
else if(it->second.type == Tango::DEV_BOOLEAN)
sprintf(conf_str, "%s:bool:%d:%f", it->first.c_str(), *((Tango::DevBoolean *) it->second.value), ts);
else if(it->second.type == Tango::DEV_STRING)
sprintf(conf_str, "%s:string:%s:%f", it->first.c_str(), ((char *) it->second.value), ts);
}
else if(it->second.size1 > 1)
{
stringstream val;
if(it->second.type == Tango::DEV_DOUBLE)
{
for(size_t i=0; i<it->second.size1; i++)
{
val << std::setprecision(std::numeric_limits<double>::digits10+2) << ((Tango::DevDouble *) it->second.value)[i];
if(i < it->second.size1-1)
val << ",";
}
sprintf(conf_str, "%s:double:%s:%f", it->first.c_str(), val.str().c_str(), ts);
}
else if(it->second.type == Tango::DEV_LONG)
{
for(size_t i=0; i<it->second.size1; i++)
{
val << std::setprecision(std::numeric_limits<Tango::DevLong>::digits10+2) << ((Tango::DevLong *) it->second.value)[i];
if(i < it->second.size1-1)
val << ",";
}
sprintf(conf_str, "%s:long:%s:%f", it->first.c_str(), val.str().c_str(), ts);
}
else if(it->second.type == Tango::DEV_BOOLEAN)
{
for(size_t i=0; i<it->second.size1; i++)
{
val << std::setprecision(std::numeric_limits<Tango::DevBoolean>::digits10+2) << ((Tango::DevBoolean *) it->second.value)[i];
if(i < it->second.size1-1)
val << ",";
}
sprintf(conf_str, "%s:bool:%s:%f", it->first.c_str(), val.str().c_str(), ts);
}
else if(it->second.type == Tango::DEV_STRING)
{
//NOT SUPPORTED
}
}
configuration.push_back(conf_str);
DEBUG_STREAM << __FUNCTION__ << " saving " << conf_str;
}
Tango::DbDatum config("Attr_config");
Tango::DbData db_data_put;
config << configuration;
db_data_put.push_back(config);
db->put_device_property(get_name(), db_data_put);
//get_db_device()->put_property(db_data_put);
if(get_state()!=Tango::ON)
set_state(Tango::ON);
} catch(Tango::DevFailed &e)
{
INFO_STREAM << __FUNCTION__ << " error saving properties=" << e.errors[0].desc;
set_state(Tango::FAULT);
}
delete db;
}
long TestDevice::create_dynamic_command(const char* cmd_name, Tango::CmdArgType type_in, Tango::CmdArgType type_out, long size_in, long size_out)
{
std::vector< Tango::Command* >& command_list = get_device_class()->get_command_list();
command_list.push_back(new CmdClass(cmd_name,
type_in, type_out,
"LV argin",
"LV argout",
Tango::OPERATOR,
size_in,
this));
return 0;
}
template <typename Attr_type> void TestDevice::set_write_value(Attr_type *value, string attrname, long x)
{
Tango::WAttribute& wattr = get_device_attr()->get_w_attr_by_name(attrname.c_str());
if(x == 1)
wattr.set_write_value(*value);
else
wattr.set_write_value(value, x);
}
void TestDevice::set_write_value(Tango::DevString value, string attrname)
{
Tango::WAttribute& wattr = get_device_attr()->get_w_attr_by_name(attrname.c_str());
wattr.set_write_value(value);
}
/***************************************************************************
CmdClass class
***************************************************************************/
CORBA::Any *CmdClass::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any)
{
TANGO_LOG << "CmdClass::" << get_name() << ": entering..." << endl;
//const Tango::DevVarLongArray *argin;
//extract(in_any, argin);
return new CORBA::Any();
}
/*bool TestDevice::is_LVCmd_allowed(const CORBA::Any &any)
{
// End of Generated Code
// Re-Start of Generated Code
return true;
}*/
/*----- PROTECTED REGION END -----*/ // TestDevice::namespace_ending
} // namespace
/*----- PROTECTED REGION ID(TestDevice.h) ENABLED START -----*/
//=============================================================================
//
// file : TestDevice.h
//
// description : Include for the TestDevice class.
//
// $Author: graziano $
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#ifndef TestDevice_H
#define TestDevice_H
#include <tango/tango.h>
#define MAX_ATTR_SIZE 3000
#define MAX_SPECTRUM_SIZE 100
#ifndef TANGO_LOG
#define TANGO_LOG cout
#endif
#ifndef TANGO_LOG_INFO
#define TANGO_LOG_INFO cout2
#endif
#ifndef TANGO_LOG_DEBUG
#define TANGO_LOG_DEBUG cout4
#endif
/*----- PROTECTED REGION END -----*/
/**
* TestDevice class Description:
*
*/
namespace TestDevice_ns
{
/*----- PROTECTED REGION ID(TestDevice::Additional Class Declarations) ENABLED START -----*/
using namespace std;
// Additional Class Declarations
typedef struct {
void *value; //pointer to values
unsigned int size1; //actual size of dimension 1
unsigned int size2; //actual size of dimension 2
unsigned int max1; //max size of dimension 1
unsigned int max2; //max size of dimension 2
long type; //data type
unsigned char cmd_attr_type; //if data for attribute or for command
struct timeval ts;
} map_data_t;
enum { typeDouble, typeLong, typeBool, typeString, typeUchar};
/*----- PROTECTED REGION END -----*/ // TestDevice::Additional Class Declarations
class TestDevice : public TANGO_BASE_CLASS
{
friend class CmdClass;
/*----- PROTECTED REGION ID(TestDevice::Data Members) ENABLED START -----*/
// Add your own data members
protected:
map<std::string,map_data_t> attr_data_map;
void string_explode(string, string, vector<string>*);
void save_configuration();
void create_dynamic_attribute(vector<string> config);
long create_dynamic_command(const char* cmd_name, Tango::CmdArgType type_in, Tango::CmdArgType type_out, long size_in, long size_out);
template <typename Attr_type> void set_write_value(Attr_type *value, string attrname, long x = 1);
void set_write_value(Tango::DevString value, string attrname);
timeval last_read;
int numAttr;
char ref_array[1024][256];
double dlastDB;
bool waitingDB;
//Tango::DevString ref_ptr[1024];
/*----- PROTECTED REGION END -----*/ // TestDevice::Data Members
// Device property data members
public:
// Attr_config:
vector<string> attr_config;
// MinSaveDBPeriod:
Tango::DevLong minSaveDBPeriod;
// Attribute data members
public:
Tango::DevString *attr_ScalarDyn_read;
Tango::DevString attr_ScalarDyn_write;
Tango::DevDouble *attr_Ref_read;
Tango::DevString *attr_Values_read;
// Constructors and destructors
public:
/**
* Constructs a newly allocated Command object.
*
* @param cl Class.
* @param s Device Name
*/
TestDevice(Tango::DeviceClass *cl,string &s);
/**
* Constructs a newly allocated Command object.
*
* @param cl Class.
* @param s Device Name
*/
TestDevice(Tango::DeviceClass *cl,const char *s);
/**
* Constructs a newly allocated Command object.
*
* @param cl Class.
* @param s Device name
* @param d Device description.
*/
TestDevice(Tango::DeviceClass *cl,const char *s,const char *d);
/**
* The object destructor.
*/
~TestDevice() {delete_device();};
// Miscellaneous methods
public:
/**
* will be called at device destruction or at init command.
*/
void delete_device();
/**
* 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();
// Attribute methods
public:
/**
* Method : TestDevice::read_attr_hardware()
* Description : Hardware acquisition for attributes.
*/
virtual void read_attr_hardware(vector<long> &attr_list);
/**
* ScalarDyn attribute related methods.
* Description:
*
* Data type: Tango::DevString
* Attr type: Scalar
*/
virtual void read_ScalarDyn(Tango::Attribute &attr);
virtual void write_ScalarDyn(Tango::WAttribute &attr);
virtual bool is_ScalarDyn_allowed(Tango::AttReqType type);
/**
* SpectrumDyn attribute related methods.
* Description:
*
* Data type: Tango::DevString
* Attr type: Spectrum
*/
virtual void read_SpectrumDyn(Tango::Attribute &attr);
virtual void write_SpectrumDyn(Tango::WAttribute &attr);
virtual bool is_SpectrumDyn_allowed(Tango::AttReqType type);
/**
* Ref attribute related methods.
* Description:
*
* Data type: Tango::DevDouble
* Attr type: Spectrum
*/
virtual void read_Ref(Tango::Attribute &attr);
virtual void write_Ref(Tango::WAttribute &attr);
virtual bool is_Ref_allowed(Tango::AttReqType type);
/**
* Values attribute related methods.
* Description:
*
* Data type: Tango::DevString
* Attr type: Spectrum
*/
virtual void read_Values(Tango::Attribute &attr);
virtual void write_Values(Tango::WAttribute &attr);
virtual bool is_Values_allowed(Tango::AttReqType type);
/**
* Method : TestDevice::add_dynamic_attributes()
* Description : Add dynamic attributes if any.
*/
void add_dynamic_attributes();
// Command related methods
public:
/**
* Command WriteAttrname related methods.
*/
void write_attrname(const Tango::DevVarDoubleStringArray *);
virtual bool is_WriteAttrname_allowed(const CORBA::Any &any);
/**
* Command ReadAttrname related methods.
*/
Tango::DevVarDoubleArray *read_attrname(const Tango::DevVarStringArray *);
virtual bool is_ReadAttrname_allowed(const CORBA::Any &any);
/**
* Command Config related methods.
*/
void config(const Tango::DevVarStringArray *);
virtual bool is_Config_allowed(const CORBA::Any &any);
/**
* Command Add related methods.
*/
void add(const Tango::DevVarStringArray *);
virtual bool is_Add_allowed(const CORBA::Any &any);
/**
* Command AddDouble related methods.
*/
void add_double(const Tango::DevVarStringArray *);
virtual bool is_AddDouble_allowed(const CORBA::Any &any);
/**
* Command AddLong related methods.
*/
void add_long(const Tango::DevVarStringArray *);
virtual bool is_AddLong_allowed(const CORBA::Any &any);
/**
* Command AddBool related methods.
*/
void add_bool(const Tango::DevVarStringArray *);
virtual bool is_AddBool_allowed(const CORBA::Any &any);
/**
* Command AddString related methods.
*/
void add_string(const Tango::DevVarStringArray *);
virtual bool is_AddString_allowed(const CORBA::Any &any);
/**
* Command Remove related methods.
*/
void remove(const Tango::DevVarStringArray *);
virtual bool is_Remove_allowed(const CORBA::Any &any);
/*----- PROTECTED REGION ID(TestDevice::Additional Method prototypes) ENABLED START -----*/
// Additional Method prototypes
/*----- PROTECTED REGION END -----*/ // TestDevice::Additional Method prototypes
};
/*----- PROTECTED REGION ID(TestDevice::Additional Classes Definitions) ENABLED START -----*/
// Additional Classes definitions
class CmdClass : public Tango::Command
{
public:
CmdClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level,
int size_in,
Tango::DeviceImpl *dev)
:Command(name,in,out,in_desc,out_desc, level) {_max_in=size_in; mydevice=(TestDevice *)dev;};
CmdClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
int size_in,
Tango::DeviceImpl *dev)
:Command(name,in,out) {_max_in=size_in; mydevice=(TestDevice *)dev;};
~CmdClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return true/*(static_cast<TangoLib *>(dev))->is_Cmd_allowed(any)*/;}
int _max_in;
TestDevice *mydevice;
};
/*----- PROTECTED REGION END -----*/ // TestDevice::Additional Classes Definitions
} // namespace
#endif // TestDevice_H
/*----- PROTECTED REGION ID(TestDeviceClass.cpp) ENABLED START -----*/
//=============================================================================
//
// file : TestDeviceClass.cpp
//
// description : C++ source for the TestDeviceClass. A singleton
// class derived from DeviceClass. It implements the
// command list and all properties and methods required
// by the �name� once per process.
//
// $Author: graziano $
//
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <TestDeviceClass.h>
/*----- PROTECTED REGION END -----*/
//-------------------------------------------------------------------
/**
* Create TestDeviceClass singleton and
* return it in a C function for Python usage
*/
//-------------------------------------------------------------------
extern "C" {
#ifdef _TG_WINDOWS_
__declspec(dllexport)
#endif
Tango::DeviceClass *_create_TestDevice_class(const char *name) {
return TestDevice_ns::TestDeviceClass::init(name);
}
}
namespace TestDevice_ns
{
//===================================================================
// Initialize pointer for singleton pattern
//===================================================================
TestDeviceClass *TestDeviceClass::_instance = NULL;
//--------------------------------------------------------
/**
* method : TestDeviceClass::TestDeviceClass(string &s)
* description : constructor for the TestDeviceClass
*
* @param s The class name
*/
//--------------------------------------------------------
TestDeviceClass::TestDeviceClass(string &s):DeviceClass(s)
{
TANGO_LOG_INFO << "Entering TestDeviceClass constructor" << endl;
set_default_property();
get_class_property();
write_class_property();
/*----- PROTECTED REGION ID(TestDevice::Class::constructor) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::constructor
TANGO_LOG_INFO << "Leaving TestDeviceClass constructor" << endl;
}
//--------------------------------------------------------
/**
* method : TestDeviceClass::~TestDeviceClass()
* description : destructor for the TestDeviceClass
*/
//--------------------------------------------------------
TestDeviceClass::~TestDeviceClass()
{
/*----- PROTECTED REGION ID(TestDevice::Class::destructor) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::destructor
_instance = NULL;
}
//--------------------------------------------------------
/**
* method : TestDeviceClass::init
* description : Create the object if not already done.
* Otherwise, just return a pointer to the object
*
* @param name The class name
*/
//--------------------------------------------------------
TestDeviceClass *TestDeviceClass::init(const char *name)
{
if (_instance == NULL)
{
try
{
string s(name);
_instance = new TestDeviceClass(s);
}
catch (bad_alloc)
{
throw;
}
}
return _instance;
}
//--------------------------------------------------------
/**
* method : TestDeviceClass::instance
* description : Check if object already created,
* and return a pointer to the object
*/
//--------------------------------------------------------
TestDeviceClass *TestDeviceClass::instance()
{
if (_instance == NULL)
{
cerr << "Class is not initialised !!" << endl;
exit(-1);
}
return _instance;
}
//===================================================================
// Command execution method calls
//===================================================================
//--------------------------------------------------------
/**
* method : WriteAttrnameClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *WriteAttrnameClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "WriteAttrnameClass::execute(): arrived" << endl;
const Tango::DevVarDoubleStringArray *argin;
extract(in_any, argin);
((static_cast<TestDevice *>(device))->write_attrname(argin));
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : ReadAttrnameClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *ReadAttrnameClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "ReadAttrnameClass::execute(): arrived" << endl;
const Tango::DevVarStringArray *argin;
extract(in_any, argin);
return insert((static_cast<TestDevice *>(device))->read_attrname(argin));
}
//--------------------------------------------------------
/**
* method : ConfigClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *ConfigClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "ConfigClass::execute(): arrived" << endl;
const Tango::DevVarStringArray *argin;
extract(in_any, argin);
((static_cast<TestDevice *>(device))->config(argin));
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : AddClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *AddClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "AddClass::execute(): arrived" << endl;
const Tango::DevVarStringArray *argin;
extract(in_any, argin);
((static_cast<TestDevice *>(device))->add(argin));
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : AddDoubleClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *AddDoubleClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "AddDoubleClass::execute(): arrived" << endl;
const Tango::DevVarStringArray *argin;
extract(in_any, argin);
((static_cast<TestDevice *>(device))->add_double(argin));
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : AddLongClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *AddLongClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "AddLongClass::execute(): arrived" << endl;
const Tango::DevVarStringArray *argin;
extract(in_any, argin);
((static_cast<TestDevice *>(device))->add_long(argin));
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : AddBoolClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *AddBoolClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "AddBoolClass::execute(): arrived" << endl;
const Tango::DevVarStringArray *argin;
extract(in_any, argin);
((static_cast<TestDevice *>(device))->add_bool(argin));
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : AddStringClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *AddStringClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "AddStringClass::execute(): arrived" << endl;
const Tango::DevVarStringArray *argin;
extract(in_any, argin);
((static_cast<TestDevice *>(device))->add_string(argin));
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : RemoveClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *RemoveClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any)
{
TANGO_LOG_INFO << "RemoveClass::execute(): arrived" << endl;
const Tango::DevVarStringArray *argin;
extract(in_any, argin);
((static_cast<TestDevice *>(device))->remove(argin));
return new CORBA::Any();
}
//===================================================================
// Properties management
//===================================================================
//--------------------------------------------------------
/**
* method : TestDeviceClass::get_class_property
* description : Get the class property for specified name.
*
* @param name The property name
*/
//--------------------------------------------------------
Tango::DbDatum TestDeviceClass::get_class_property(string &prop_name)
{
for (unsigned int i=0 ; i<cl_prop.size() ; i++)
if (cl_prop[i].name == prop_name)
return cl_prop[i];
// if not found, returns an empty DbDatum
return Tango::DbDatum(prop_name);
}
//--------------------------------------------------------
/**
* Method : TestDevice::TestDeviceClass::get_default_device_property()()
* Description : Return the default value for device property.
*/
//--------------------------------------------------------
Tango::DbDatum TestDeviceClass::get_default_device_property(string &prop_name)
{
for (unsigned int i=0 ; i<dev_def_prop.size() ; i++)
if (dev_def_prop[i].name == prop_name)
return dev_def_prop[i];
// if not found, return an empty DbDatum
return Tango::DbDatum(prop_name);
}
//--------------------------------------------------------
/**
* Method : TestDevice::TestDeviceClass::get_default_class_property()()
* Description : Return the default value for class property.
*/
//--------------------------------------------------------
Tango::DbDatum TestDeviceClass::get_default_class_property(string &prop_name)
{
for (unsigned int i=0 ; i<cl_def_prop.size() ; i++)
if (cl_def_prop[i].name == prop_name)
return cl_def_prop[i];
// if not found, return an empty DbDatum
return Tango::DbDatum(prop_name);
}
//--------------------------------------------------------
/**
* Method : TestDevice::TestDeviceClass::get_class_property()
* Description : // Add your own code to initialize
*/
//--------------------------------------------------------
void TestDeviceClass::get_class_property()
{
}
//--------------------------------------------------------
/**
* Method : TestDevice::TestDeviceClass::set_default_property()
* Description : Set default property (class and device) for wizard.
* For each property, add to wizard property name and description.
* If default value has been set, add it to wizard property and.
* store it in a DbDatum.
*/
//--------------------------------------------------------
void TestDeviceClass::set_default_property()
{
string prop_name;
string prop_desc;
string prop_def;
vector<string> vect_data;
// Set Default Class Properties
// Set Default Device Properties
prop_name = "Attr_config";
prop_desc = "";
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 = "MinSaveDBPeriod";
prop_desc = "";
prop_def = "10";
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);
}
//--------------------------------------------------------
/**
* Method : TestDevice::TestDeviceClass::write_class_property()
* Description : Set class description fields as property in database
*/
//--------------------------------------------------------
void TestDeviceClass::write_class_property()
{
// First time, check if database used
if (Tango::Util::_UseDb == false)
return;
Tango::DbData data;
string classname = get_name();
string header;
string::size_type start, end;
// Put title
Tango::DbDatum title("ProjectTitle");
string str_title("Storage Ring Access");
title << str_title;
data.push_back(title);
// Put Description
Tango::DbDatum description("Description");
vector<string> str_desc;
str_desc.push_back("");
description << str_desc;
data.push_back(description);
// Put inheritance
Tango::DbDatum inher_datum("InheritedFrom");
vector<string> inheritance;
inheritance.push_back("Device_Impl");
inher_datum << inheritance;
data.push_back(inher_datum);
// Call database and and values
get_db_class()->put_property(data);
}
//===================================================================
// Factory methods
//===================================================================
//--------------------------------------------------------
/**
* method : TestDeviceClass::device_factory
* description : Create the device object(s)
* and store them in the device list
*
* @param *devlist_ptr The device name list
*/
//--------------------------------------------------------
void TestDeviceClass::device_factory(const Tango::DevVarStringArray *devlist_ptr)
{
/*----- PROTECTED REGION ID(TestDevice::Class::device_factory_before) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::device_factory_before
// Create devices and add it into the device list
for (unsigned long i=0 ; i<devlist_ptr->length() ; i++)
{
TANGO_LOG_DEBUG << "Device name : " << (*devlist_ptr)[i].in() << endl;
device_list.push_back(new TestDevice(this, (*devlist_ptr)[i]));
}
// Manage dynamic attributes if any
erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list());
// Export devices to the outside world
for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++)
{
// Add dynamic attributes if any
TestDevice *dev = static_cast<TestDevice *>(device_list[device_list.size()-i]);
dev->add_dynamic_attributes();
// Check before if database used.
if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false))
export_device(dev);
else
export_device(dev, dev->get_name().c_str());
}
/*----- PROTECTED REGION ID(TestDevice::Class::device_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::device_factory_after
}
//--------------------------------------------------------
/**
* Method : TestDevice::TestDeviceClass::attribute_factory()
* Description : Create the attribute object(s)
* and store them in the attribute list
*/
//--------------------------------------------------------
void TestDeviceClass::attribute_factory(vector<Tango::Attr *> &att_list)
{
/*----- PROTECTED REGION ID(TestDevice::Class::attribute_factory_before) ENABLED START -----*/
// Add your own code
// Attribute : Ref
RefAttrib *ref = new RefAttrib();
att_list.push_back(ref);
// Attribute : Values
ValuesAttrib *values = new ValuesAttrib();
att_list.push_back(values);
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::attribute_factory_before
// Create a list of static attributes
create_static_attribute_list(get_class_attr()->get_attr_list());
/*----- PROTECTED REGION ID(TestDevice::Class::attribute_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::attribute_factory_after
}
//--------------------------------------------------------
/**
* Method : TestDevice::TestDeviceClass::command_factory()
* Description : Create the command object(s)
* and store them in the command list
*/
//--------------------------------------------------------
void TestDeviceClass::command_factory()
{
/*----- PROTECTED REGION ID(TestDevice::Class::command_factory_before) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::command_factory_before
ConfigClass *pConfigCmd =
new ConfigClass("Config",
Tango::DEVVAR_STRINGARRAY, Tango::DEV_VOID,
"Array of attribute names (double) to be created removing everything else",
"",
Tango::OPERATOR);
command_list.push_back(pConfigCmd);
AddClass *pAddCmd =
new AddClass("Add",
Tango::DEVVAR_STRINGARRAY, Tango::DEV_VOID,
"Array of attribute to be added.\nSyntax= name:type:value:timestamp.\ntype=double, long, bool, string.\ntimestamp=0 means now.",
"",
Tango::OPERATOR);
command_list.push_back(pAddCmd);
AddDoubleClass *pAddDoubleCmd =
new AddDoubleClass("AddDouble",
Tango::DEVVAR_STRINGARRAY, Tango::DEV_VOID,
"Array of double attribute to be added.",
"",
Tango::OPERATOR);
command_list.push_back(pAddDoubleCmd);
AddLongClass *pAddLongCmd =
new AddLongClass("AddLong",
Tango::DEVVAR_STRINGARRAY, Tango::DEV_VOID,
"Array of long attribute to be added.",
"",
Tango::OPERATOR);
command_list.push_back(pAddLongCmd);
AddBoolClass *pAddBoolCmd =
new AddBoolClass("AddBool",
Tango::DEVVAR_STRINGARRAY, Tango::DEV_VOID,
"Array of boolean attribute to be added.",
"",
Tango::OPERATOR);
command_list.push_back(pAddBoolCmd);
AddStringClass *pAddStringCmd =
new AddStringClass("AddString",
Tango::DEVVAR_STRINGARRAY, Tango::DEV_VOID,
"Array of string attribute to be added.",
"",
Tango::OPERATOR);
command_list.push_back(pAddStringCmd);
RemoveClass *pRemoveCmd =
new RemoveClass("Remove",
Tango::DEVVAR_STRINGARRAY, Tango::DEV_VOID,
"Array of attribute names to be removed",
"",
Tango::OPERATOR);
command_list.push_back(pRemoveCmd);
WriteAttrnameClass *pWriteAttrnameCmd =
new WriteAttrnameClass("WriteAttrname",
Tango::DEVVAR_DOUBLESTRINGARRAY, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pWriteAttrnameCmd);
ReadAttrnameClass *pReadAttrnameCmd =
new ReadAttrnameClass("ReadAttrname",
Tango::DEVVAR_STRINGARRAY, Tango::DEVVAR_DOUBLEARRAY,
"",
"",
Tango::OPERATOR);
command_list.push_back(pReadAttrnameCmd);
/*----- PROTECTED REGION ID(TestDevice::Class::command_factory_after) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::command_factory_after
}
//===================================================================
// Dynamic attributes related methods
//===================================================================
//--------------------------------------------------------
/**
* method : TestDeviceClass::create_static_attribute_list
* description : Create the a list of static attributes
*
* @param att_list the ceated attribute list
*/
//--------------------------------------------------------
void TestDeviceClass::create_static_attribute_list(vector<Tango::Attr *> &att_list)
{
for (unsigned long i=0 ; i<att_list.size() ; i++)
{
string att_name(att_list[i]->get_name());
transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower);
defaultAttList.push_back(att_name);
}
TANGO_LOG_INFO << defaultAttList.size() << " attributes in default list" << endl;
/*----- PROTECTED REGION ID(TestDevice::Class::create_static_att_list) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::create_static_att_list
}
//--------------------------------------------------------
/**
* method : TestDeviceClass::erase_dynamic_attributes
* description : delete the dynamic attributes if any.
*
* @param devlist_ptr the device list pointer
* @param list of all attributes
*/
//--------------------------------------------------------
void TestDeviceClass::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, vector<Tango::Attr *> &att_list)
{
Tango::Util *tg = Tango::Util::instance();
for (unsigned long i=0 ; i<devlist_ptr->length() ; i++)
{
Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((string)(*devlist_ptr)[i]).c_str());
TestDevice *dev = static_cast<TestDevice *> (dev_impl);
vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list();
vector<Tango::Attribute *>::iterator ite_att;
for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att)
{
string att_name((*ite_att)->get_name_lower());
if ((att_name == "state") || (att_name == "status") || (att_name == "ref"))
continue;
vector<string>::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name);
if (ite_str == defaultAttList.end())
{
TANGO_LOG_INFO << att_name << " is a UNWANTED dynamic attribute for device " << (*devlist_ptr)[i] << endl;
Tango::Attribute &att = dev->get_device_attr()->get_attr_by_name(att_name.c_str());
dev->remove_attribute(att_list[att.get_attr_idx()],true);
--ite_att;
}
}
}
/*----- PROTECTED REGION ID(TestDevice::Class::erase_dynamic_attributes) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::erase_dynamic_attributes
}
/*----- PROTECTED REGION ID(TestDevice::Class::Additional Methods) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::Class::Additional Methods
} // namespace
/*----- PROTECTED REGION ID(TestDeviceClass.h) ENABLED START -----*/
//=============================================================================
//
// file : TestDeviceClass.h
//
// description : Include for the TestDeviceClass root class.
// This class is the singleton class for.
// the TestDevice device class..
// It contains all properties and methods which the .
// TestDevice requires only once e.g. the commands.
//
// $Author: graziano $
//
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#ifndef TestDeviceCLASS_H
#define TestDeviceCLASS_H
#include <tango/tango.h>
#include <TestDevice.h>
#ifndef TANGO_LOG
#define TANGO_LOG cout
#endif
#ifndef TANGO_LOG_INFO
#define TANGO_LOG_INFO cout2
#endif
#ifndef TANGO_LOG_DEBUG
#define TANGO_LOG_DEBUG cout4
#endif
/*----- PROTECTED REGION END -----*/
namespace TestDevice_ns
{
/*----- PROTECTED REGION ID(TestDevice::classes for dynamic creation) ENABLED START -----*/
using namespace std;
/*----- PROTECTED REGION END -----*/ // TestDevice::classes for dynamic creation
//=========================================
// Define classes for attributes
//=========================================
class SpectrumDynAttrib: public Tango::SpectrumAttr
{
public:
SpectrumDynAttrib():SpectrumAttr("SpectrumDyn",
Tango::DEV_DOUBLE, Tango::READ_WRITE, MAX_SPECTRUM_SIZE) {};
~SpectrumDynAttrib() {};
SpectrumDynAttrib(const string &att_name, long data_type, long s_size):SpectrumAttr(att_name.c_str(),
data_type, Tango::READ_WRITE, s_size) {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<TestDevice *>(dev))->read_SpectrumDyn(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<TestDevice *>(dev))->write_SpectrumDyn(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<TestDevice *>(dev))->is_SpectrumDyn_allowed(ty);}
};
class ScalarDynAttrib: public Tango::Attr
{
public:
ScalarDynAttrib():Attr("ScalarDyn",
Tango::DEV_STRING, Tango::READ_WRITE) {};
~ScalarDynAttrib() {};
ScalarDynAttrib(const string &att_name, long data_type):Attr(att_name.c_str(),
data_type, Tango::READ_WRITE) {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<TestDevice *>(dev))->read_ScalarDyn(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<TestDevice *>(dev))->write_ScalarDyn(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<TestDevice *>(dev))->is_ScalarDyn_allowed(ty);}
};
class RefAttrib: public Tango::SpectrumAttr
{
public:
RefAttrib():SpectrumAttr("Ref", Tango::DEV_DOUBLE, Tango::READ_WRITE, 1024) {};
~RefAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<TestDevice *>(dev))->read_Ref(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<TestDevice *>(dev))->write_Ref(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<TestDevice *>(dev))->is_Ref_allowed(ty);}
};
class ValuesAttrib: public Tango::SpectrumAttr
{
public:
ValuesAttrib():SpectrumAttr("Values", Tango::DEV_STRING, Tango::READ_WRITE, 1024) {};
~ValuesAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<TestDevice *>(dev))->read_Values(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<TestDevice *>(dev))->write_Values(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<TestDevice *>(dev))->is_Values_allowed(ty);}
};
//=========================================
// Define classes for commands
//=========================================
class WriteAttrnameClass : public Tango::Command
{
public:
WriteAttrnameClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
WriteAttrnameClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~WriteAttrnameClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_WriteAttrname_allowed(any);}
};
class ReadAttrnameClass : public Tango::Command
{
public:
ReadAttrnameClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
ReadAttrnameClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~ReadAttrnameClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_ReadAttrname_allowed(any);}
};
class ConfigClass : public Tango::Command
{
public:
ConfigClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
ConfigClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~ConfigClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_Config_allowed(any);}
};
class AddClass : public Tango::Command
{
public:
AddClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
AddClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~AddClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_Add_allowed(any);}
};
class AddDoubleClass : public Tango::Command
{
public:
AddDoubleClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
AddDoubleClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~AddDoubleClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_AddDouble_allowed(any);}
};
class AddLongClass : public Tango::Command
{
public:
AddLongClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
AddLongClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~AddLongClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_AddLong_allowed(any);}
};
class AddBoolClass : public Tango::Command
{
public:
AddBoolClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
AddBoolClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~AddBoolClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_AddBool_allowed(any);}
};
class AddStringClass : public Tango::Command
{
public:
AddStringClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
AddStringClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~AddStringClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_AddString_allowed(any);}
};
class RemoveClass : public Tango::Command
{
public:
RemoveClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
RemoveClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~RemoveClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<TestDevice *>(dev))->is_Remove_allowed(any);}
};
/**
* The TemplateDevServClass singleton definition
*/
class
#ifdef _TG_WINDOWS_
__declspec(dllexport)
#endif
TestDeviceClass : public Tango::DeviceClass
{
/*----- PROTECTED REGION ID(TestDevice::Additionnal DServer data members) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::Additionnal DServer data members
public:
// write class properties data members
Tango::DbData cl_prop;
Tango::DbData cl_def_prop;
Tango::DbData dev_def_prop;
// Method prototypes
static TestDeviceClass *init(const char *);
static TestDeviceClass *instance();
~TestDeviceClass();
Tango::DbDatum get_class_property(string &);
Tango::DbDatum get_default_device_property(string &);
Tango::DbDatum get_default_class_property(string &);
protected:
TestDeviceClass(string &);
static TestDeviceClass *_instance;
void command_factory();
void attribute_factory(vector<Tango::Attr *> &);
void write_class_property();
void set_default_property();
void get_class_property();
string get_cvstag();
string get_cvsroot();
private:
void device_factory(const Tango::DevVarStringArray *);
void create_static_attribute_list(vector<Tango::Attr *> &);
void erase_dynamic_attributes(const Tango::DevVarStringArray *,vector<Tango::Attr *> &);
vector<string> defaultAttList;
};
} // namespace
#endif // TestDeviceCLASS_H
/*----- PROTECTED REGION ID(TestDeviceStateMachine.cpp) ENABLED START -----*/
//=============================================================================
//
// file : TestDeviceStateMachine.cpp
//
// description : C++ source for the �name� and its alowed
// methods for commands and attributes
//
// $Author: graziano $
//
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <TestDevice.h>
#include <TestDeviceClass.h>
/*----- PROTECTED REGION END -----*/
/*
* TestDevice states description:
*
*/
namespace TestDevice_ns
{
//=================================================
// Attributes Allowed Methods
//=================================================
//--------------------------------------------------------
/**
* Method : TestDevice::is_ScalarDynState_allowed()
* Description : Execution allowed for ScalarDyn attribute.
*/
//--------------------------------------------------------
bool TestDevice::is_ScalarDyn_allowed(Tango::AttReqType type)
{
// Not any excluded states for ScalarDyn attribute in READ access.
/*----- PROTECTED REGION ID(TestDevice::is_ScalarDyn_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::is_ScalarDyn_allowed
return true;
}
bool TestDevice::is_SpectrumDyn_allowed(Tango::AttReqType type)
{
// Not any excluded states for SpectrumDyn attribute in READ access.
/*----- PROTECTED REGION ID(TestDevice::is_SpectrumDyn_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::is_SpectrumDyn_allowed
return true;
}
bool TestDevice::is_Ref_allowed(Tango::AttReqType type)
{
// Not any excluded states for Ref attribute in READ access.
/*----- PROTECTED REGION ID(TestDevice::is_Ref_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::is_Ref_allowed
return true;
}
bool TestDevice::is_Values_allowed(Tango::AttReqType type)
{
// Not any excluded states for Values attribute in READ access.
/*----- PROTECTED REGION ID(TestDevice::is_Values_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // TestDevice::is_Values_allowed
return true;
}
/*----- PROTECTED REGION ID(TestDevice::are_dynamic_attributes_allowed) ENABLED START -----*/
// Add your code to check if dynamic attributes are alowed
/*----- PROTECTED REGION END -----*/ // TestDevice::are_dynamic_attributes_allowed
//=================================================
// Commands Allowed Methods
//=================================================
//--------------------------------------------------------
/**
* Method : TestDevice::is_WriteAttrname_allowed()
* Description : Execution allowed for WriteAttrname command.
*/
//--------------------------------------------------------
bool TestDevice::is_WriteAttrname_allowed(const CORBA::Any &any)
{
// Not any excluded states for WriteAttrname command.
/*----- PROTECTED REGION ID(XPI::is_WriteAttrname_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_WriteAttrname_allowed
return true;
}
//--------------------------------------------------------
/**
* Method : TestDevice::is_ReadAttrname_allowed()
* Description : Execution allowed for ReadAttrname command.
*/
//--------------------------------------------------------
bool TestDevice::is_ReadAttrname_allowed(const CORBA::Any &any)
{
// Not any excluded states for ReadAttrname command.
/*----- PROTECTED REGION ID(XPI::is_ReadAttrname_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_ReadAttrname_allowed
return true;
}
//--------------------------------------------------------
/**
* Method : TestDevice::is_Config_allowed()
* Description : Execution allowed for Config command.
*/
//--------------------------------------------------------
bool TestDevice::is_Config_allowed(const CORBA::Any &any)
{
// Not any excluded states for Config command.
/*----- PROTECTED REGION ID(XPI::is_Config_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_Config_allowed
return true;
}
//--------------------------------------------------------
/**
* Method : TestDevice::is_Add_allowed()
* Description : Execution allowed for Add command.
*/
//--------------------------------------------------------
bool TestDevice::is_Add_allowed(const CORBA::Any &any)
{
// Not any excluded states for Add command.
/*----- PROTECTED REGION ID(XPI::is_Add_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_Add_allowed
return true;
}
//--------------------------------------------------------
/**
* Method : TestDevice::is_AddDouble_allowed()
* Description : Execution allowed for AddDouble command.
*/
//--------------------------------------------------------
bool TestDevice::is_AddDouble_allowed(const CORBA::Any &any)
{
// Not any excluded states for AddDouble command.
/*----- PROTECTED REGION ID(XPI::is_AddDouble_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_AddDouble_allowed
return true;
}
//--------------------------------------------------------
/**
* Method : TestDevice::is_AddLong_allowed()
* Description : Execution allowed for AddLong command.
*/
//--------------------------------------------------------
bool TestDevice::is_AddLong_allowed(const CORBA::Any &any)
{
// Not any excluded states for AddLong command.
/*----- PROTECTED REGION ID(XPI::is_AddLong_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_AddLong_allowed
return true;
}
//--------------------------------------------------------
/**
* Method : TestDevice::is_AddBool_allowed()
* Description : Execution allowed for AddBool command.
*/
//--------------------------------------------------------
bool TestDevice::is_AddBool_allowed(const CORBA::Any &any)
{
// Not any excluded states for AddBool command.
/*----- PROTECTED REGION ID(XPI::is_AddBool_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_AddBool_allowed
return true;
}
//--------------------------------------------------------
/**
* Method : TestDevice::is_AddString_allowed()
* Description : Execution allowed for AddString command.
*/
//--------------------------------------------------------
bool TestDevice::is_AddString_allowed(const CORBA::Any &any)
{
// Not any excluded states for AddString command.
/*----- PROTECTED REGION ID(XPI::is_AddString_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_AddString_allowed
return true;
}
//--------------------------------------------------------
/**
* Method : TestDevice::is_Remove_allowed()
* Description : Execution allowed for Remove command.
*/
//--------------------------------------------------------
bool TestDevice::is_Remove_allowed(const CORBA::Any &any)
{
// Not any excluded states for Remove command.
/*----- PROTECTED REGION ID(XPI::is_Remove_allowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // XPI::is_Remove_allowed
return true;
}
/*----- PROTECTED REGION ID(TestDevice::are_dynamic_commands_allowed) ENABLED START -----*/
// Add your code to check if dynamic commands are alowed
/*----- PROTECTED REGION END -----*/ // TestDevice::are_dynamic_commands_allowed
} // namespace TestDevice_ns
/*PROTECTED REGION ID(TestDevice::main.cpp) ENABLED START*/
//=============================================================================
//
// file : TestDevice.cpp
//
// description : C++ source for the TestDevice device server main.
// The main rule is to initialise (and create) the Tango
// system and to create the DServerClass singleton.
// The main should be the same for every Tango device server.
//
// $Author: graziano $
//
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <tango/tango.h>
#ifndef TANGO_LOG
#define TANGO_LOG cout
#endif
#ifndef TANGO_LOG_INFO
#define TANGO_LOG_INFO cout2
#endif
#ifndef TANGO_LOG_DEBUG
#define TANGO_LOG_DEBUG cout4
#endif
int main(int argc,char *argv[])
{
using namespace std;
Tango::Util *tg = NULL;
try
{
// Initialise the device server
//----------------------------------------
tg = Tango::Util::init(argc,argv);
// Create the device server singleton
// which will create everything
//----------------------------------------
tg->server_init(false);
// Run the endless loop
//----------------------------------------
TANGO_LOG << "Ready to accept request" << endl;
tg->server_run();
}
catch (bad_alloc)
{
TANGO_LOG << "Can't allocate memory to store device object !!!" << endl;
TANGO_LOG << "Exiting" << endl;
}
catch (CORBA::Exception &e)
{
Tango::Except::print_exception(e);
TANGO_LOG << "Received a CORBA_Exception" << endl;
TANGO_LOG << "Exiting" << endl;
}
if (tg!=NULL)
tg->server_cleanup();
return(0);
}
/*PROTECTED REGION END*/
//========================================================