Newer
Older
/*----- PROTECTED REGION ID(DataImporter.cpp) ENABLED START -----*/
//=============================================================================
//
// file : DataImporter.cpp
//
// description : C++ source for the DataImporter class and its commands.
// The class is derived from Device. It represents the
// CORBA servant object which will be accessed from the
// network. All commands which can be executed on the
// DataImporter are implemented in this file.
//
// project : Data importer
//
// This file is part of Tango device class.
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <DataImporter.h>
#include <DataImporterClass.h>
#include <PlainClient.h>
#include <SSLClient.h>
#include <boost/filesystem.hpp>
/*----- PROTECTED REGION END -----*/ // DataImporter.cpp
/**
* DataImporter class description:
*/
//================================================================
// The following table gives the correspondence
// between command and method names.
//
// Command name | Method name
//================================================================
// State | Inherited (no method)
// Status | Inherited (no method)
//================================================================
//================================================================
//================================================================
// RegularFileCounter | Tango::DevULong Scalar
// FailedFileCounter | Tango::DevULong Scalar
//================================================================
namespace DataImporter_ns
{
/*----- PROTECTED REGION ID(DataImporter::namespace_starting) ENABLED START -----*/
// static initializations
/*----- PROTECTED REGION END -----*/ // DataImporter::namespace_starting
//--------------------------------------------------------
/**
* Method : DataImporter::DataImporter()
* Description : Constructors for a Tango device
* implementing the classDataImporter
*/
//--------------------------------------------------------
DataImporter::DataImporter(Tango::DeviceClass *cl, string &s)
: TANGO_BASE_CLASS(cl, s.c_str())
{
/*----- PROTECTED REGION ID(DataImporter::constructor_1) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // DataImporter::constructor_1
}
//--------------------------------------------------------
DataImporter::DataImporter(Tango::DeviceClass *cl, const char *s)
: TANGO_BASE_CLASS(cl, s)
{
/*----- PROTECTED REGION ID(DataImporter::constructor_2) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // DataImporter::constructor_2
}
//--------------------------------------------------------
DataImporter::DataImporter(Tango::DeviceClass *cl, const char *s, const char *d)
: TANGO_BASE_CLASS(cl, s, d)
{
/*----- PROTECTED REGION ID(DataImporter::constructor_3) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // DataImporter::constructor_3
}
//--------------------------------------------------------
/**
* Method : DataImporter::delete_device()
* Description : will be called at device destruction or at init command
*/
//--------------------------------------------------------
void DataImporter::delete_device()
{
DEBUG_STREAM << "DataImporter::delete_device() " << device_name << endl;
/*----- PROTECTED REGION ID(DataImporter::delete_device) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporter::delete_device
delete[] attr_RegularFileCounter_read;
delete[] attr_FailedFileCounter_read;
}
//--------------------------------------------------------
/**
* Method : DataImporter::init_device()
* Description : will be called at device initialization.
*/
//--------------------------------------------------------
void DataImporter::init_device()
{
DEBUG_STREAM << "DataImporter::init_device() create device " << device_name << endl;
/*----- PROTECTED REGION ID(DataImporter::init_device_before) ENABLED START -----*/
set_status("Initializing device");//Initialize regular file counters to zero
/*----- PROTECTED REGION END -----*/ // DataImporter::init_device_before
// Get the device properties from database
get_device_property();
attr_RegularFileCounter_read = new Tango::DevULong[1];
attr_FailedFileCounter_read = new Tango::DevULong[1];
/*----- PROTECTED REGION ID(DataImporter::init_device) ENABLED START -----*/
//Initialize regular file counters to zero
*attr_RegularFileCounter_read = 0;
//Initialize error file counters to zero
*attr_FailedFileCounter_read = 0;
if(get_state() != Tango::FAULT)
{
try
{
if(enableSSL)
m_client_sp = SSLClient::create(this, m_configuration_sp);
else
m_client_sp = PlainClient::create(this, m_configuration_sp);
//Start device if auto start enabled
if(autoStart)
{
INFO_STREAM << "FitsImporter::init_device() auto start enabled " << endl;
on();
}
}
catch(std::exception& ex)
{
set_state(Tango::FAULT);
std::stringstream error_stream;
error_stream << "DataImporter::init_device() " << ex.what();
set_status(error_stream.str());
}
catch(...)
{
set_state(Tango::FAULT);
set_status("DataImporter::init_device() unknown error");
}
}
/*----- PROTECTED REGION END -----*/ // DataImporter::init_device
}
//--------------------------------------------------------
/**
* Method : DataImporter::get_device_property()
* Description : Read database to initialize property data members.
*/
//--------------------------------------------------------
void DataImporter::get_device_property()
{
/*----- PROTECTED REGION ID(DataImporter::get_device_property_before) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporter::get_device_property_before
// Read device properties from database.
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("CertificateFile"));
dev_prop.push_back(Tango::DbDatum("StoragePath"));
dev_prop.push_back(Tango::DbDatum("RemoteHost"));
dev_prop.push_back(Tango::DbDatum("RemotePort"));
dev_prop.push_back(Tango::DbDatum("RemoteUsername"));
dev_prop.push_back(Tango::DbDatum("RemotePassword"));
dev_prop.push_back(Tango::DbDatum("RemoteSchema"));
dev_prop.push_back(Tango::DbDatum("RemoteTable"));
dev_prop.push_back(Tango::DbDatum("EnableSSL"));
dev_prop.push_back(Tango::DbDatum("DatabaseHost"));
dev_prop.push_back(Tango::DbDatum("DatabasePort"));
dev_prop.push_back(Tango::DbDatum("DatabaseUsername"));
dev_prop.push_back(Tango::DbDatum("DatabasePassword"));
dev_prop.push_back(Tango::DbDatum("DatabaseSchema"));
dev_prop.push_back(Tango::DbDatum("DatabaseTable"));
dev_prop.push_back(Tango::DbDatum("RefreshTime"));
dev_prop.push_back(Tango::DbDatum("Timeout"));
dev_prop.push_back(Tango::DbDatum("RecoveryTime"));
dev_prop.push_back(Tango::DbDatum("AutoStart"));
dev_prop.push_back(Tango::DbDatum("AuxDatabaseHost"));
dev_prop.push_back(Tango::DbDatum("AuxDatabasePort"));
dev_prop.push_back(Tango::DbDatum("AuxDatabaseUsername"));
dev_prop.push_back(Tango::DbDatum("AuxDatabasePassword"));
dev_prop.push_back(Tango::DbDatum("AuxDatabaseSchema"));
dev_prop.push_back(Tango::DbDatum("AuxDatabaseTimestampTable"));
dev_prop.push_back(Tango::DbDatum("AuxDatabaseFailedTable"));
dev_prop.push_back(Tango::DbDatum("WhereCondition"));
// 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);
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// get instance on DataImporterClass to get class property
Tango::DbDatum def_prop, cl_prop;
DataImporterClass *ds_class =
(static_cast<DataImporterClass *>(get_device_class()));
int i = -1;
// Try to initialize CertificateFile from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> certificateFile;
else {
// Try to initialize CertificateFile from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> certificateFile;
}
// And try to extract CertificateFile value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> certificateFile;
// Try to initialize StoragePath from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> storagePath;
else {
// Try to initialize StoragePath from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> storagePath;
}
// And try to extract StoragePath value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> storagePath;
// Try to initialize RemoteHost from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> remoteHost;
else {
// Try to initialize RemoteHost from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> remoteHost;
}
// And try to extract RemoteHost value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> remoteHost;
// Try to initialize RemotePort from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> remotePort;
else {
// Try to initialize RemotePort from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> remotePort;
}
// And try to extract RemotePort value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> remotePort;
// Try to initialize RemoteUsername from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> remoteUsername;
else {
// Try to initialize RemoteUsername from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> remoteUsername;
}
// And try to extract RemoteUsername value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> remoteUsername;
// Try to initialize RemotePassword from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> remotePassword;
else {
// Try to initialize RemotePassword from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> remotePassword;
}
// And try to extract RemotePassword value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> remotePassword;
// Try to initialize RemoteSchema from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> remoteSchema;
else {
// Try to initialize RemoteSchema from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> remoteSchema;
}
// And try to extract RemoteSchema value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> remoteSchema;
// Try to initialize RemoteTable from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> remoteTable;
else {
// Try to initialize RemoteTable from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> remoteTable;
}
// And try to extract RemoteTable value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> remoteTable;
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
// Try to initialize EnableSSL from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> enableSSL;
else {
// Try to initialize EnableSSL from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> enableSSL;
}
// And try to extract EnableSSL value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> enableSSL;
// Try to initialize DatabaseHost from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> databaseHost;
else {
// Try to initialize DatabaseHost from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> databaseHost;
}
// And try to extract DatabaseHost value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> databaseHost;
// Try to initialize DatabasePort from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> databasePort;
else {
// Try to initialize DatabasePort from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> databasePort;
}
// And try to extract DatabasePort value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> databasePort;
// Try to initialize DatabaseUsername from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> databaseUsername;
else {
// Try to initialize DatabaseUsername from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> databaseUsername;
}
// And try to extract DatabaseUsername value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> databaseUsername;
// Try to initialize DatabasePassword from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> databasePassword;
else {
// Try to initialize DatabasePassword from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> databasePassword;
}
// And try to extract DatabasePassword value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> databasePassword;
// Try to initialize DatabaseSchema from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> databaseSchema;
else {
// Try to initialize DatabaseSchema from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> databaseSchema;
}
// And try to extract DatabaseSchema value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> databaseSchema;
// Try to initialize DatabaseTable from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> databaseTable;
else {
// Try to initialize DatabaseTable from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> databaseTable;
}
// And try to extract DatabaseTable value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> databaseTable;
// Try to initialize RefreshTime from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> refreshTime;
else {
// Try to initialize RefreshTime from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> refreshTime;
}
// And try to extract RefreshTime value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> refreshTime;
// Try to initialize Timeout from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> timeout;
else {
// Try to initialize Timeout from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> timeout;
}
// And try to extract Timeout value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> timeout;
// Try to initialize RecoveryTime from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> recoveryTime;
else {
// Try to initialize RecoveryTime from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> recoveryTime;
}
// And try to extract RecoveryTime value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> recoveryTime;
// Try to initialize AutoStart from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> autoStart;
else {
// Try to initialize AutoStart from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> autoStart;
}
// And try to extract AutoStart value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> autoStart;
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
// Try to initialize AuxDatabaseHost from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> auxDatabaseHost;
else {
// Try to initialize AuxDatabaseHost from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> auxDatabaseHost;
}
// And try to extract AuxDatabaseHost value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabaseHost;
// Try to initialize AuxDatabasePort from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> auxDatabasePort;
else {
// Try to initialize AuxDatabasePort from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> auxDatabasePort;
}
// And try to extract AuxDatabasePort value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabasePort;
// Try to initialize AuxDatabaseUsername from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> auxDatabaseUsername;
else {
// Try to initialize AuxDatabaseUsername from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> auxDatabaseUsername;
}
// And try to extract AuxDatabaseUsername value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabaseUsername;
// Try to initialize AuxDatabasePassword from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> auxDatabasePassword;
else {
// Try to initialize AuxDatabasePassword from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> auxDatabasePassword;
}
// And try to extract AuxDatabasePassword value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabasePassword;
// Try to initialize AuxDatabaseSchema from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> auxDatabaseSchema;
else {
// Try to initialize AuxDatabaseSchema from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> auxDatabaseSchema;
}
// And try to extract AuxDatabaseSchema value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabaseSchema;
// Try to initialize AuxDatabaseTimestampTable from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> auxDatabaseTimestampTable;
else {
// Try to initialize AuxDatabaseTimestampTable from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> auxDatabaseTimestampTable;
}
// And try to extract AuxDatabaseTimestampTable value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabaseTimestampTable;
// Try to initialize AuxDatabaseFailedTable from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> auxDatabaseFailedTable;
else {
// Try to initialize AuxDatabaseFailedTable from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> auxDatabaseFailedTable;
}
// And try to extract AuxDatabaseFailedTable value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabaseFailedTable;
// Try to initialize WhereCondition from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> whereCondition;
// Try to initialize WhereCondition from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> whereCondition;
// And try to extract WhereCondition value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> whereCondition;
}
/*----- PROTECTED REGION ID(DataImporter::get_device_property_after) ENABLED START -----*/
try
{
if(enableSSL)
{
if(certificateFile.empty())
throw(invalid_argument("CertificateFile property is empty or not defined"));
checkIfFileExists(certificateFile);
}
if(storagePath.empty())
throw(invalid_argument("StoragePath property is empty or not defined"));
checkIfDirectoryExists(storagePath);
if(remoteHost.empty())
throw(invalid_argument("RemoteHost property is empty or not defined"));
if(remotePort<1 || remotePort>MAX_PORT_NUMBER)
throw(invalid_argument("RemotePort property out of range or not defined"));
if(remoteUsername.empty())
throw(invalid_argument("RemoteUsername property is empty or not defined"));
if(remotePassword.empty())
throw(invalid_argument("RemotePassword property is empty or not defined"));
// If remoteSchema is not set, use databaseSchema
if(remoteSchema.empty())
remoteSchema=databaseSchema;
// If remoteTable is not set, use databaseTable
if(remoteTable.empty())
remoteTable=databaseTable;
if(databaseHost.empty())
throw(invalid_argument("DatabaseHost property is empty or not defined"));
if(databasePort<1 || databasePort>MAX_PORT_NUMBER)
throw(invalid_argument("DatabasePort property out of range or not defined"));
if(databaseUsername.empty())
throw(invalid_argument("DatabaseUsername property is empty or not defined"));
if(databasePassword.empty())
throw(invalid_argument("DatabasePassword property is empty or not defined"));
if(databaseSchema.empty())
throw(invalid_argument("DatabaseSchema property is empty or not defined"));
if(databaseTable.empty())
throw(invalid_argument("DatabaseTable property is empty or not defined"));
if(refreshTime<1 || refreshTime>MAX_REFRESH_TIME)
throw(invalid_argument("RefreshTime property out of range or not defined"));
if(timeout<1 || timeout>MAX_TIMEOUT)
throw(invalid_argument("Timeout property out of range or not defined"));
if(recoveryTime<1 || recoveryTime>MAX_RECOVERY_TIME)
throw(invalid_argument("RecoveryTime property out of range or not defined"));
if(auxDatabaseHost.empty())
throw(invalid_argument("AuxDatabaseHost property is empty or not defined"));
if(auxDatabasePort<1 || auxDatabasePort>MAX_PORT_NUMBER)
throw(invalid_argument("AuxDatabasePort property out of range or not defined"));
if(auxDatabaseUsername.empty())
throw(invalid_argument("AuxDatabaseUsername property is empty or not defined"));
if(auxDatabasePassword.empty())
throw(invalid_argument("AuxDatabasePassword property is empty or not defined"));
if(auxDatabaseSchema.empty())
throw(invalid_argument("AuxDatabaseSchema property is empty or not defined"));
if(auxDatabaseTimestampTable.empty())
throw(invalid_argument("AuxDatabaseTimestampTable property is empty or not defined"));
if(auxDatabaseFailedTable.empty())
throw(invalid_argument("AuxDatabaseFailedTable property is empty or not defined"));
m_configuration_sp = Configuration::create(certificateFile, storagePath,
remoteHost, remotePort, remoteUsername, remotePassword, remoteSchema, remoteTable, databaseHost,
databasePort, databaseUsername, databasePassword, databaseSchema,
databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost,
auxDatabasePort, auxDatabaseUsername, auxDatabasePassword,
auxDatabaseFailedTable, whereCondition);
}
catch(invalid_argument& ex)
{
set_state(Tango::FAULT);
stringstream error_stream;
error_stream << "DataImporter::get_device_property() " << ex.what() << endl;
set_status(error_stream.str());
}
/*----- PROTECTED REGION END -----*/ // DataImporter::get_device_property_after
}
//--------------------------------------------------------
/**
* Method : DataImporter::always_executed_hook()
* Description : method always executed before any command is executed
*/
//--------------------------------------------------------
void DataImporter::always_executed_hook()
{
DEBUG_STREAM << "DataImporter::always_executed_hook() " << device_name << endl;
/*----- PROTECTED REGION ID(DataImporter::always_executed_hook) ENABLED START -----*/
if(get_state() != Tango::FAULT)
{
if(m_client_sp)
{
set_state(m_client_sp->readState());
set_status(m_client_sp->readStatus());
}
}
/*----- PROTECTED REGION END -----*/ // DataImporter::always_executed_hook
}
//--------------------------------------------------------
/**
* Method : DataImporter::read_attr_hardware()
* Description : Hardware acquisition for attributes
*/
//--------------------------------------------------------
void DataImporter::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
{
DEBUG_STREAM << "DataImporter::read_attr_hardware(vector<long> &attr_list) entering... " << endl;
/*----- PROTECTED REGION ID(DataImporter::read_attr_hardware) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporter::read_attr_hardware
}
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
//--------------------------------------------------------
/**
* Read attribute RegularFileCounter related method
* Description:
*
* Data type: Tango::DevULong
* Attr type: Scalar
*/
//--------------------------------------------------------
void DataImporter::read_RegularFileCounter(Tango::Attribute &attr)
{
DEBUG_STREAM << "DataImporter::read_RegularFileCounter(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(DataImporter::read_RegularFileCounter) ENABLED START -----*/
boost::mutex::scoped_lock regularCounterLock(m_regularCounterMutex);
attr.set_value(attr_RegularFileCounter_read);
/*----- PROTECTED REGION END -----*/ // DataImporter::read_RegularFileCounter
}
//--------------------------------------------------------
/**
* Read attribute FailedFileCounter related method
* Description:
*
* Data type: Tango::DevULong
* Attr type: Scalar
*/
//--------------------------------------------------------
void DataImporter::read_FailedFileCounter(Tango::Attribute &attr)
{
DEBUG_STREAM << "DataImporter::read_FailedFileCounter(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(DataImporter::read_FailedFileCounter) ENABLED START -----*/
boost::mutex::scoped_lock failedCounterLock(m_failedCounterMutex);
attr.set_value(attr_FailedFileCounter_read);
/*----- PROTECTED REGION END -----*/ // DataImporter::read_FailedFileCounter
}
//--------------------------------------------------------
/**
* Method : DataImporter::add_dynamic_attributes()
* Description : Create the dynamic attributes if any
* for specified device.
*/
//--------------------------------------------------------
void DataImporter::add_dynamic_attributes()
{
/*----- PROTECTED REGION ID(DataImporter::add_dynamic_attributes) ENABLED START -----*/
// Add your own code to create and add dynamic attributes if any
/*----- PROTECTED REGION END -----*/ // DataImporter::add_dynamic_attributes
}
//--------------------------------------------------------
/**
* Command On related method
* Description: Activate data importer
*
*/
//--------------------------------------------------------
void DataImporter::on()
{
DEBUG_STREAM << "DataImporter::On() - " << device_name << endl;
/*----- PROTECTED REGION ID(DataImporter::on) ENABLED START -----*/
if(m_client_sp)
m_client_sp->start();
/*----- PROTECTED REGION END -----*/ // DataImporter::on
}
//--------------------------------------------------------
/**
* Command Off related method
* Description: Deactivate data importer
*
*/
//--------------------------------------------------------
void DataImporter::off()
{
DEBUG_STREAM << "DataImporter::Off() - " << device_name << endl;
/*----- PROTECTED REGION ID(DataImporter::off) ENABLED START -----*/
if(m_client_sp)
m_client_sp->stop();
/*----- PROTECTED REGION END -----*/ // DataImporter::off
}
//--------------------------------------------------------
/**
* Command ResetCounter related method
* Description:
*
*/
//--------------------------------------------------------
void DataImporter::reset_counter()
{
DEBUG_STREAM << "DataImporter::ResetCounter() - " << device_name << endl;
/*----- PROTECTED REGION ID(DataImporter::reset_counter) ENABLED START -----*/
boost::mutex::scoped_lock regularCounterLock(m_regularCounterMutex);
*attr_RegularFileCounter_read = 0;
boost::mutex::scoped_lock failedCounterLock(m_failedCounterMutex);
*attr_FailedFileCounter_read = 0;
/*----- PROTECTED REGION END -----*/ // DataImporter::reset_counter
}
/*----- PROTECTED REGION ID(DataImporter::namespace_ending) ENABLED START -----*/
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
//==============================================================================
// DataImporter::incrementRegularCounter()
//==============================================================================
void DataImporter::incrementRegularCounter()
{
DEBUG_STREAM << "DataImporter::incrementRegularCounter() - " << device_name << endl;
boost::mutex::scoped_lock regularCounterLock(m_regularCounterMutex);
++*attr_RegularFileCounter_read;
}
//==============================================================================
// DataImporter::incrementFailedCounter()
//==============================================================================
void DataImporter::incrementFailedCounter()
{
DEBUG_STREAM << "DataImporter::incrementFailedCounter() - " << device_name << endl;
boost::mutex::scoped_lock failedCounterLock(m_failedCounterMutex);
++*attr_FailedFileCounter_read;
}
//==============================================================================
// DataImporter::decrementFailedCounter()
//==============================================================================
void DataImporter::decrementFailedCounter()
{
DEBUG_STREAM << "DataImporter::decrementFailedCounter() - " << device_name << endl;
boost::mutex::scoped_lock failedCounterLock(m_failedCounterMutex);
if(*attr_FailedFileCounter_read > 0)
--*attr_FailedFileCounter_read;
}
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
//==============================================================================
// DataImporter::checkIfFileExists()
//==============================================================================
void DataImporter::checkIfFileExists(std::string fileName)
throw(std::invalid_argument)
{
DEBUG_STREAM << "DataImporter::checkIfFileExists() - " << device_name << endl;
boost::filesystem::path path(fileName);
if(!boost::filesystem::exists(path))
{
std::stringstream errorStream;
errorStream << "File " << fileName
<< " not exists" << std::endl;
throw std::invalid_argument(errorStream.str());
}
INFO_STREAM << "DataImporter::checkIfFileExists() " << fileName << endl;
}
//==============================================================================
// DataImporter::checkIfDirectoryExists()
//==============================================================================
void DataImporter::checkIfDirectoryExists(std::string directoryName)
throw(std::invalid_argument)
{
DEBUG_STREAM << "DataImporter::checkIfFileExists() - " << device_name << endl;
boost::filesystem::path path(directoryName);
if(!boost::filesystem::exists(path))
{
std::stringstream errorStream;
errorStream << "Directory " << directoryName << " not exists" << std::endl;
throw std::invalid_argument(errorStream.str());
}
if(!boost::filesystem::is_directory(path))
{
std::stringstream errorStream;
errorStream << directoryName << " is not a directory" << std::endl;
throw std::invalid_argument(errorStream.str());
}
INFO_STREAM << "DataImporter::checkIfDirectoryExists() " << directoryName << endl;
}
/*----- PROTECTED REGION END -----*/ // DataImporter::namespace_ending
} // namespace