pax_global_header 0000666 0000000 0000000 00000000064 14145762224 0014521 g ustar 00root root 0000000 0000000 52 comment=180b22d8260e76e739ec2b968964770bef8ba77a
data_importer-master/ 0000775 0000000 0000000 00000000000 14145762224 0015210 5 ustar 00root root 0000000 0000000 data_importer-master/Makefile 0000664 0000000 0000000 00000007014 14145762224 0016652 0 ustar 00root root 0000000 0000000 #================================================================================
EXEC_NAME=dataImporter-srv
INST_NAME=test
DEBUG_LEV=-v3
INSTALL_DIR=/usr/local/bin
VERSION := `git describe --tags`
TAR_NAME := `basename $(PWD)`
#================================================================================
INC_DIR=/usr/local/omniORB/include \
/usr/local/zeromq/include \
/usr/local/tango/include/tango \
/usr/local/boost/include \
/usr/local/soci/include \
/usr/local/soci/include/soci \
/usr/include/mysql \
/usr/include/soci \
/usr/local/protobuf/include \
./src
LIB_DIR=/usr/local/omniORB/lib \
/usr/local/zeromq/lib \
/usr/local/tango/lib \
/usr/local/boost/lib \
/usr/local/soci/lib64 \
/usr/local/protobuf/lib \
/usr/lib64/mysql
#================================================================================
CC=g++
CXX_DEBUG_FLAGS=-g -DVERBOSE_DEBUG
CXX_RELEASE_FLAGS=-O3
CXX_DEFAULT_FLAGS=-c -Wall -Wextra -std=c++0x -Wno-unused-local-typedefs -DHAVE_BOOST
LDFLAGS=-Wall -lomniORB4 -lomniDynamic4 -lCOS4 -lomnithread -ltango -llog4tango \
-lsoci_core -lsoci_mysql -lmysqlclient -lboost_system -lboost_thread \
-lboost_filesystem -lboost_date_time -lprotobuf -lssl -lcrypto -lpthread
INC_PARM=$(foreach d, $(INC_DIR), -I$d)
LIB_PARM=$(foreach d, $(LIB_DIR), -L$d)
PROTOC :=/usr/local/protobuf/bin/protoc
#================================================================================
SRC_DIR=./src
OBJ_DIR=./obj
BIN_DIR=./bin
PROTO_DIR=./proto
#================================================================================
EXECUTABLE := $(BIN_DIR)/$(EXEC_NAME)
CPP_FILES := $(wildcard $(SRC_DIR)/*.cpp)
OBJ_FILES := $(addprefix $(OBJ_DIR)/,$(notdir $(CPP_FILES:.cpp=.o)))
#================================================================================
PROTO_FILES := $(wildcard $(PROTO_DIR)/*.proto)
PROTO_HEADERS := $(addprefix $(SRC_DIR)/,$(notdir $(PROTO_FILES:.proto=.pb.h)))
PROTO_CLASSES := $(addprefix $(SRC_DIR)/,$(notdir $(PROTO_FILES:.proto=.pb.cc)))
CPP_FILES += $(PROTO_CLASSES)
OBJ_FILES += $(addprefix $(OBJ_DIR)/,$(notdir $(PROTO_CLASSES:.pb.cc=.pb.o)))
#================================================================================
.PHONY: all
all: debug
.PHONY: run
run: debug
$(EXECUTABLE) $(INST_NAME) $(DEBUG_LEV)
.PHONY: release
release: CXXFLAGS+=$(CXX_RELEASE_FLAGS) $(CXX_DEFAULT_FLAGS)
release: $(EXECUTABLE)
.PHONY: debug
debug: CXXFLAGS+=$(CXX_DEBUG_FLAGS) $(CXX_DEFAULT_FLAGS)
debug: $(EXECUTABLE)
$(EXECUTABLE): makedir $(OBJ_FILES)
$(CC) $(LDFLAGS) $(LIB_PARM) -o $@ $(OBJ_FILES)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CC) $(CXXFLAGS) $(INC_PARM) -o $@ $<
$(OBJ_DIR)/%.pb.o: $(SRC_DIR)/%.pb.cc
$(CC) $(CXXFLAGS) $(INC_PARM) -o $@ $<
.PHONY: protoc
protoc:
$(PROTOC) --proto_path=$(PROTO_DIR) --cpp_out=$(SRC_DIR) $(PROTO_FILES)
.PHONY: makedir
makedir:
-mkdir -p $(OBJ_DIR) $(BIN_DIR)
.PHONY: clean
clean:
-rm -rf $(OBJ_DIR) $(BIN_DIR)
.PHONY: deepclean
deepclean:
-rm -rf $(OBJ_DIR) $(BIN_DIR) $(PROTO_HEADERS) $(PROTO_CLASSES)
.PHONY: install
install:
-cp $(EXECUTABLE) $(INSTALL_DIR)
.PHONY: tar
tar:
-tar -czvf $(TAR_NAME)_$(VERSION).tar.gz --transform="s|^.|$(TAR_NAME)_$(VERSION)/|" $(PROTO_DIR) $(SRC_DIR) ./Makefile
.PHONY: echo
echo:
@echo EXECUTABLE:
@echo $(EXECUTABLE)
@echo CPP FILES:
@echo $(CPP_FILES)
@echo OBJ_FILES:
@echo $(OBJ_FILES)
@echo INC_PARM
@echo $(INC_PARM)
@echo LIB_PARM
@echo $(LIB_PARM)
@echo PROTO_FILES
@echo $(PROTO_FILES)
@echo PROTO_CLASSES
@echo $(PROTO_CLASSES)
@echo PROTO_HEADERS
@echo $(PROTO_HEADERS)
data_importer-master/proto/ 0000775 0000000 0000000 00000000000 14145762224 0016353 5 ustar 00root root 0000000 0000000 data_importer-master/proto/Request.proto 0000664 0000000 0000000 00000000351 14145762224 0021067 0 ustar 00root root 0000000 0000000 package DataImporter_ns;
message Request
{
required string username = 1;
required string password = 2;
required string schema = 3;
required string table = 4;
required int32 file_version = 5;
required string file_name = 6;
}
data_importer-master/proto/Response.proto 0000664 0000000 0000000 00000000643 14145762224 0021241 0 ustar 00root root 0000000 0000000 package DataImporter_ns;
message Response
{
enum State
{
REQUEST_ACCEPTED = 0;
ACCESS_DENY = 1;
TABLE_NOT_EXPORTED = 2;
METADATA_NOT_FOUND = 3;
FILE_NOT_DOWNLOADED = 4;
FILE_NOT_FOUND = 5;
GENERIC_ERROR = 6;
}
required State state = 1;
required string status = 2;
optional string file_path = 3;
optional int32 file_version = 4;
optional string file_name = 5;
optional uint64 file_size = 6;
}
data_importer-master/src/ 0000775 0000000 0000000 00000000000 14145762224 0015777 5 ustar 00root root 0000000 0000000 data_importer-master/src/ClassFactory.cpp 0000664 0000000 0000000 00000003565 14145762224 0021111 0 ustar 00root root 0000000 0000000 /*----- PROTECTED REGION ID(DataImporter::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.
//
// 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 .
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include
#include
// Add class header files if needed
/**
* Create DataImporter Class singleton and store it in DServer object.
*/
void Tango::DServer::class_factory()
{
// Add method class init if needed
add_class(DataImporter_ns::DataImporterClass::init("DataImporter"));
}
/*----- PROTECTED REGION END -----*/ // DataImporter::ClassFactory.cpp
data_importer-master/src/Client.cpp 0000664 0000000 0000000 00000040503 14145762224 0017723 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
namespace DataImporter_ns
{
//==============================================================================
// Client::Client()
//==============================================================================
Client::Client(DataImporter* dataImporter_p, Configuration::SP configuration_sp) :
Tango::LogAdapter(dataImporter_p), m_dataImporter_p(dataImporter_p),
m_configuration_sp(configuration_sp), m_resolver(m_ioService),
m_resetConnectionTimer(m_ioService), m_listsUpdateTimer(m_ioService)
{
DEBUG_STREAM << "Client::Client()" << endl;
GOOGLE_PROTOBUF_VERIFY_VERSION;
m_dBManager_sp = DBManager::create(dataImporter_p, configuration_sp);
m_state = Tango::OFF;
m_status="Disconnected";
}
//==============================================================================
// Client::~Client()
//==============================================================================
Client::~Client()
{
DEBUG_STREAM << "Client::~Client()" << endl;
m_ioService.stop();
m_work_sp.reset();
if(m_thread_sp)
{
//m_thread_sp->interrupt();
m_thread_sp->join();
}
google::protobuf::ShutdownProtobufLibrary();
}
//==============================================================================
// Client::start()
//==============================================================================
void Client::start()
{
DEBUG_STREAM << "Client::start()" << endl;
try
{
m_dBManager_sp->connectAll();
m_protocolManager_sp = ProtocolManager::create(m_dataImporter_p,
m_configuration_sp, m_dBManager_sp);
m_ioService.reset();
m_work_sp.reset(new boost::asio::io_service::work(m_ioService));
m_thread_sp.reset(new boost::thread(boost::bind(&Client::run, this)));
Client::startUpdateLists();
}
catch(std::exception& ex)
{
writeState(Tango::ALARM);
std::stringstream error_stream;
error_stream << "Client::start() " << ex.what() << std::endl;
writeStatus(error_stream.str());
}
catch(...)
{
writeState(Tango::ALARM);
writeStatus("Client::start() unknown error");
}
}
//==============================================================================
// Client::stop()
//==============================================================================
void Client::stop()
{
DEBUG_STREAM << "Client::stop()" << endl;
closeConnection();
m_ioService.stop();
m_work_sp.reset();
if(m_thread_sp)
{
//m_thread_sp->interrupt();
m_thread_sp->join();
}
m_thread_sp.reset();
m_protocolManager_sp.reset();
m_dBManager_sp->disconnectAll();
writeState(Tango::OFF);
writeStatus("Database loop paused");
}
//==============================================================================
// Client::readState()
//==============================================================================
Tango::DevState Client::readState()
{
DEBUG_STREAM << "Client::readState()" << endl;
boost::mutex::scoped_lock stateLock(m_stateMutex);
return m_state;
}
//==============================================================================
// Client::readStatus()
//==============================================================================
std::string Client::readStatus()
{
DEBUG_STREAM << "Client::readStatus()" << endl;
boost::mutex::scoped_lock statusLock(m_statusMutex);
return m_status;
}
//==============================================================================
// Client::writeState()
//==============================================================================
void Client::writeState(Tango::DevState state)
{
DEBUG_STREAM << "Client::writeState()" << endl;
boost::mutex::scoped_lock stateLock(m_stateMutex);
m_state = state;
}
//==============================================================================
// Client::writeStatus()
//==============================================================================
void Client::writeStatus(std::string status)
{
DEBUG_STREAM << "Client::writeStatus()" << endl;
boost::mutex::scoped_lock statusLock(m_statusMutex);
m_status = status;
}
//==============================================================================
// Client::run()
//==============================================================================
void Client::run()
{
DEBUG_STREAM << "Client::run() Starting" << endl;
while(true)
{
try
{
boost::system::error_code ec;
m_ioService.run(ec);
if(ec)
{
ERROR_STREAM << "Client::run() " << ec.message() << endl;
}
break;
}
catch(std::exception& ex)
{
ERROR_STREAM << "Client::run() " << ex.what() << endl;
}
catch(boost::thread_interrupted& ex)
{
DEBUG_STREAM << "Client::run() interrupt" << endl;
break;
}
}
DEBUG_STREAM << "Client::run() Stopping" << endl;
}
//==============================================================================
// Client::startUpdateLists()
//==============================================================================
void Client::startUpdateLists()
{
DEBUG_STREAM << "Client::startUpdateLists()" << endl;
try
{
m_protocolManager_sp->retrieveFiles();
writeState(Tango::ON);
writeStatus("Database loop active");
}
catch(std::exception& ec)
{
ERROR_STREAM << "Client::startUpdateLists() " << ec.what() << endl;
writeState(Tango::ALARM);
writeStatus(ec.what());
}
catch(...)
{
ERROR_STREAM << "Client::startUpdateLists() Unknown error" << endl;
writeState(Tango::ALARM);
writeStatus("Unknown error");
}
if(readState() == Tango::ON &&
m_protocolManager_sp->hasFilesToTransfer())
{
startResolve();
}
else
{
m_listsUpdateTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getRefreshTime()));
m_listsUpdateTimer.async_wait(boost::bind(&Client::handleUpdateLists,
this, boost::asio::placeholders::error));
}
}
//==============================================================================
// Client::handleUpdateLists()
//==============================================================================
void Client::handleUpdateLists(const boost::system::error_code& errorCode)
{
DEBUG_STREAM << "Client::handleUpdateLists()" << endl;
if(!errorCode)
{
startUpdateLists();
}
else if(errorCode == boost::asio::error::operation_aborted)
{
DEBUG_STREAM << "Client::handleUpdateLists() stopping" << endl;
}
else
{
ERROR_STREAM << "Client::handleUpdateLists() " << errorCode.message() << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
}
}
//==============================================================================
// Client::startResolve()
//==============================================================================
void Client::startResolve()
{
DEBUG_STREAM << "Client::startResolve()" << endl;
std::stringstream infoStream;
infoStream << "Resolving host: " << m_configuration_sp->getRemoteHost()
<< " port: " << m_configuration_sp->getRemotePort();
INFO_STREAM << "Client::startResolve() " << infoStream.str() << endl;
writeState(Tango::RUNNING);
writeStatus(infoStream.str());
boost::asio::ip::tcp::resolver::query query(m_configuration_sp->getRemoteHost(),
boost::lexical_cast(m_configuration_sp->getRemotePort()));
m_resetConnectionTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getTimeout()));
m_resolver.async_resolve(query, boost::bind(&Client::handleResolve, this,
boost::asio::placeholders::error, boost::asio::placeholders::iterator));
m_resetConnectionTimer.async_wait(boost::bind(&Client::resetConnection, this));
}
//==============================================================================
// Client::handleResolve()
//==============================================================================
void Client::handleResolve(const boost::system::error_code& errorCode,
boost::asio::ip::tcp::resolver::iterator endPointIterator)
{
DEBUG_STREAM << "Client::handleResolve()" << endl;
if(!errorCode)
{
startConnect(endPointIterator);
}
else
{
ERROR_STREAM << "Client::handleResolve() " << errorCode.message() << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
}
}
//==============================================================================
// Client::handleRequest()
//==============================================================================
void Client::handleWriteRequest(const boost::system::error_code& errorCode)
{
DEBUG_STREAM << "Client::handleRequest()" << endl;
if(!errorCode)
{
startReadResponseHeader();
}
else
{
ERROR_STREAM << "Client::handleRequest() " << errorCode.message() << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
}
}
//==============================================================================
// Client::handleReadResponseHeader()
//==============================================================================
void Client::handleReadResponseHeader(const boost::system::error_code& errorCode)
{
DEBUG_STREAM << "Client::handleReadResponseHeader()" << endl;
if(!errorCode)
{
boost::uint32_t bodySize = decodeHeader(m_readBuff);
startReadResponseBody(bodySize);
}
else
{
ERROR_STREAM << "Client::handleReadResponseHeader() " << errorCode.message() << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
}
}
//==============================================================================
// Client::handleReadResponseBody()
//==============================================================================
void Client::handleReadResponseBody(const boost::system::error_code& errorCode)
{
DEBUG_STREAM << "Client::handleReadResponseBody()" << endl;
if(!errorCode)
{
try
{
ResponseSP response_sp(new Response);
response_sp->ParseFromArray(&m_readBuff[HEADER_SIZE],
m_readBuff.size() - HEADER_SIZE);
startReadData(m_protocolManager_sp->processResponse(response_sp));
}
catch(std::logic_error& ec)
{
WARN_STREAM << "Client::handleReadResponseBody() " << ec.what() << endl;
onTransferFailed();
}
catch(std::exception& ec)
{
ERROR_STREAM << "Client::handleReadResponseBody() " << ec.what() << endl;
writeState(Tango::ALARM);
writeStatus(ec.what());
}
catch(...)
{
ERROR_STREAM << "Client::handleReadResponseBody() Unknown error" << endl;
writeState(Tango::ALARM);
writeStatus("Unknown error");
}
}
else
{
ERROR_STREAM << "Client::handleReadResponseBody() " << errorCode.message() << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
}
}
//==============================================================================
// Client::handleReadData()
//==============================================================================
void Client::handleReadData(FileWrapper::SP fileWrapper_sp, std::size_t recvBytes,
const boost::system::error_code& errorCode)
{
if(!errorCode)
{
if(!fileWrapper_sp->isBad())
{
if(recvBytes>0)
fileWrapper_sp->write(m_fileBuff, recvBytes);
if(!fileWrapper_sp->isCompleted())
{
startReadData(fileWrapper_sp);
}
else
{
onTransferCompleted(fileWrapper_sp);
}
}
else
{
WARN_STREAM << "Client::handleReadData() bad I/O" << endl;
fileWrapper_sp->cleanUp();
onTransferFailed();
}
}
else
{
ERROR_STREAM << "Client::handleReadData() "
<< errorCode.message() << " from " << m_remoteEndpoint << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
}
}
//==============================================================================
// Client::onTransferCompleted()
//==============================================================================
void Client::onTransferCompleted(FileWrapper::SP fileWrapper_sp)
{
DEBUG_STREAM << "Client::onTransferCompleted()" << endl;
try
{
m_protocolManager_sp->setCurrentFileDownloaded(fileWrapper_sp);
if(m_protocolManager_sp->hasNextFile())
{
startWriteRequest();
}
else
{
closeConnection();
startUpdateLists();
}
}
catch(std::exception& ec)
{
ERROR_STREAM << "Client::onTransferCompleted() " << ec.what() << endl;
writeState(Tango::ALARM);
writeStatus(ec.what());
}
catch(...)
{
ERROR_STREAM << "Client::onTransferCompleted() Unknown error" << endl;
writeState(Tango::ALARM);
writeStatus("Unknown error");
}
}
//==============================================================================
// Client::onTransferFailed()
//==============================================================================
void Client::onTransferFailed()
{
DEBUG_STREAM << "Client::onTransferFailed()" << endl;
try
{
m_protocolManager_sp->setCurrentFileFailed();
if(m_protocolManager_sp->hasNextFile())
{
startWriteRequest();
}
else
{
closeConnection();
startUpdateLists();
}
}
catch(std::exception& ec)
{
ERROR_STREAM << "Client::onTransferFailed() " << ec.what() << endl;
writeState(Tango::ALARM);
writeStatus(ec.what());
}
catch(...)
{
ERROR_STREAM << "Client::onTransferFailed() Unknown error" << endl;
writeState(Tango::ALARM);
writeStatus("Unknown error");
}
}
//==============================================================================
// Client::resetConnection()
//==============================================================================
void Client::resetConnection()
{
if(m_resetConnectionTimer.expires_at() <=
boost::asio::deadline_timer::traits_type::now())
{
ERROR_STREAM << "Client::resetConnection() Connection timeout" << endl;
m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin);
closeConnection();
startUpdateLists();
}
m_resetConnectionTimer.async_wait(boost::bind(&Client::resetConnection, this));
}
//==============================================================================
// Client::encodeHeader()
//==============================================================================
void Client::encodeHeader(std::vector& buf, boost::uint32_t size)
throw(std::runtime_error)
{
DEBUG_STREAM << "Client::encodeHeader()" << endl;
if(buf.size() < HEADER_SIZE)
throw std::runtime_error("Buffer to small to contain header!");
buf[0] = static_cast((size >> 24) & 0xFF);
buf[1] = static_cast((size >> 16) & 0xFF);
buf[2] = static_cast((size >> 8) & 0xFF);
buf[3] = static_cast(size & 0xFF);
}
//==============================================================================
// Client::decodeHeader()
//==============================================================================
boost::uint32_t Client::decodeHeader(std::vector& buf)
throw(std::runtime_error)
{
DEBUG_STREAM << "Client::decodeHeader()" << endl;
if(buf.size() < HEADER_SIZE)
throw std::runtime_error("Buffer to small to contain header!");
boost::uint32_t size = 0;
for (unsigned i = 0; i < HEADER_SIZE; ++i)
size = size * 256 + (static_cast(buf[i]) & 0xFF);
return size;
}
} //namespace data_importer-master/src/Client.h 0000664 0000000 0000000 00000016144 14145762224 0017374 0 ustar 00root root 0000000 0000000 #ifndef CLIENT_H
#define CLIENT_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace DataImporter_ns
{
class DataImporter;
class Client : public Tango::LogAdapter
{
public:
//------------------------------------------------------------------------------
// [Public] Shared pointer typedef
//------------------------------------------------------------------------------
typedef boost::shared_ptr SP;
protected:
//------------------------------------------------------------------------------
// [Protected] Constructor destructor
//------------------------------------------------------------------------------
Client(DataImporter*, Configuration::SP);
virtual ~Client();
public:
//------------------------------------------------------------------------------
// [Public] Thread management methods
//------------------------------------------------------------------------------
virtual void start();
virtual void stop();
//------------------------------------------------------------------------------
// [Public] Read state and status methods
//------------------------------------------------------------------------------
virtual Tango::DevState readState();
virtual std::string readStatus();
protected:
//------------------------------------------------------------------------------
// [Protected] Write state and status methods
//------------------------------------------------------------------------------
virtual void writeState(Tango::DevState);
virtual void writeStatus(std::string);
//------------------------------------------------------------------------------
// [Protected] IO service run thread method
//------------------------------------------------------------------------------
virtual void run();
//------------------------------------------------------------------------------
// [Protected] Lists update methods
//------------------------------------------------------------------------------
virtual void startUpdateLists();
virtual void handleUpdateLists(const boost::system::error_code&);
//------------------------------------------------------------------------------
// [Protected] Endpoint resolution methods
//------------------------------------------------------------------------------
virtual void startResolve();
virtual void handleResolve(const boost::system::error_code&,
boost::asio::ip::tcp::resolver::iterator);
//------------------------------------------------------------------------------
// [Protected] Connection initialization methods
//------------------------------------------------------------------------------
virtual void startConnect(boost::asio::ip::tcp::resolver::iterator) = 0;
virtual void handleConnect(const boost::system::error_code&,
boost::asio::ip::tcp::resolver::iterator) = 0;
//------------------------------------------------------------------------------
// [Protected] Write request methods
//------------------------------------------------------------------------------
virtual void startWriteRequest() = 0;
virtual void handleWriteRequest(const boost::system::error_code&);
//------------------------------------------------------------------------------
// [Protected] Read response header methods
//------------------------------------------------------------------------------
virtual void startReadResponseHeader() = 0;
virtual void handleReadResponseHeader(const boost::system::error_code&);
//------------------------------------------------------------------------------
// [Protected] Read response body methods
//------------------------------------------------------------------------------
virtual void startReadResponseBody(boost::uint32_t) = 0;
virtual void handleReadResponseBody(const boost::system::error_code&);
//------------------------------------------------------------------------------
// [Protected] Read data methods
//------------------------------------------------------------------------------
virtual void startReadData(FileWrapper::SP) = 0;
virtual void handleReadData(FileWrapper::SP, std::size_t,
const boost::system::error_code&);
//------------------------------------------------------------------------------
// [Protected] Protocol and transfer result handler methods
//------------------------------------------------------------------------------
void onTransferCompleted(FileWrapper::SP);
void onTransferFailed();
//------------------------------------------------------------------------------
// [Protected] Connection reset and timeout handler methods
//------------------------------------------------------------------------------
virtual void closeConnection() = 0;
virtual void resetConnection();
//------------------------------------------------------------------------------
// [Protected] Header encoding decoding methods
//------------------------------------------------------------------------------
virtual void encodeHeader(std::vector&, boost::uint32_t)
throw(std::runtime_error);
virtual boost::uint32_t decodeHeader(std::vector&)
throw(std::runtime_error);
//------------------------------------------------------------------------------
// [Protected] Class variables
//------------------------------------------------------------------------------
//Tango server class pointer
DataImporter* m_dataImporter_p;
//Configuration shared pointer
Configuration::SP m_configuration_sp;
//Database manager shared pointer
DBManager::SP m_dBManager_sp;
//Protocol manager shared pointer
ProtocolManager::SP m_protocolManager_sp;
//IO service instance
boost::asio::io_service m_ioService;
//Work IO service instance
boost::scoped_ptr m_work_sp;
//DNS resolver instance
boost::asio::ip::tcp::resolver m_resolver;
//Thread for IO service run scoped pointer
boost::scoped_ptr m_thread_sp;
//Connection write read timeout
boost::asio::deadline_timer m_resetConnectionTimer;
//File list update time
boost::asio::deadline_timer m_listsUpdateTimer;
//Tango state property mutex
boost::mutex m_stateMutex;
//Tango state property
Tango::DevState m_state;
//Tango status property mutex
boost::mutex m_statusMutex;
//Tango status property
std::string m_status;
//Address and port of remote endpoint
std::string m_remoteEndpoint;
//Header size on binary stream
static const unsigned HEADER_SIZE = 4;
//Buffer for binary data read from stream
std::vector m_readBuff;
//Read buffer size
static const boost::uint64_t BUFFER_SIZE = 40960;
//Buffer for file data read from stream
std::vector m_fileBuff;
};
} //End of namespace
#endif /* CLIENT_H */
data_importer-master/src/Configuration.h 0000664 0000000 0000000 00000017776 14145762224 0021001 0 ustar 00root root 0000000 0000000 #ifndef CONFIGURATION_H
#define CONFIGURATION_H
#include
namespace DataImporter_ns
{
class Configuration
{
public:
//------------------------------------------------------------------------------
// [Public] Shared pointer typedef
//------------------------------------------------------------------------------
typedef boost::shared_ptr SP;
private:
//------------------------------------------------------------------------------
// [Private] Constructor destructor deleter
//------------------------------------------------------------------------------
Configuration(std::string certificateFile, std::string storagePath,
std::string remoteHost, unsigned int remotePort,
std::string remoteUsername, std::string remotePassword,
std::string remoteSchema, std::string remoteTable,
std::string databaseHost, unsigned int databasePort,
std::string databaseUsername, std::string databasePassword,
std::string databaseSchema, std::string databaseTable,
unsigned int refreshTime, unsigned int timeout, unsigned int recoveryTime,
std::string auxDatabaseHost, unsigned int auxDatabasePort,
std::string auxDatabaseUsername, std::string auxDatabasePassword,
std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable,
std::string auxDatabaseFailedTable, std::string whereCondition) :
m_certificateFile (certificateFile), m_storagePath(storagePath),
m_remoteHost(remoteHost), m_remotePort(remotePort),
m_remoteUsername(remoteUsername), m_remotePassword(remotePassword),
m_remoteSchema(remoteSchema), m_remoteTable(remoteTable),
m_databaseHost(databaseHost), m_databasePort(databasePort),
m_databaseUsername(databaseUsername),
m_databasePassword(databasePassword), m_databaseSchema(databaseSchema),
m_databaseTable(databaseTable), m_refreshTime(refreshTime),
m_timeout(timeout), m_recoveryTime(recoveryTime),
m_auxDatabaseHost(auxDatabaseHost), m_auxDatabasePort(auxDatabasePort),
m_auxDatabaseUsername(auxDatabaseUsername),
m_auxDatabasePassword(auxDatabasePassword),
m_auxDatabaseSchema(auxDatabaseSchema),
m_auxDatabaseTimestampTable(auxDatabaseTimestampTable),
m_auxDatabaseFailedTable(auxDatabaseFailedTable),
m_whereCondition(whereCondition) { };
virtual ~Configuration() {}
class Deleter;
friend class Deleter;
class Deleter
{
public:
void operator()(Configuration* c) { delete c; }
};
public:
//------------------------------------------------------------------------------
// [Public] Create class method
//------------------------------------------------------------------------------
static Configuration::SP create(std::string certificateFile,
std::string storagePath, std::string remoteHost, unsigned int remotePort,
std::string remoteUsername, std::string remotePassword,
std::string remoteSchema, std::string remoteTable,
std::string databaseHost, unsigned int databasePort,
std::string databaseUsername, std::string databasePassword,
std::string databaseSchema, std::string databaseTable,
unsigned int refreshTime, unsigned int timeout, unsigned int recoveryTime,
std::string auxDatabaseHost, unsigned int auxDatabasePort,
std::string auxDatabaseUsername, std::string auxDatabasePassword,
std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable,
std::string auxDatabaseFailedTable, std::string whereCondition)
{
Configuration::SP c_sp(new Configuration(certificateFile, storagePath,
remoteHost, remotePort, remoteUsername, remotePassword, remoteSchema, remoteTable, databaseHost,
databasePort, databaseUsername, databasePassword, databaseSchema,
databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost,
auxDatabasePort, auxDatabaseUsername, auxDatabasePassword,
auxDatabaseSchema, auxDatabaseTimestampTable, auxDatabaseFailedTable,
whereCondition), Configuration::Deleter());
return c_sp;
}
//------------------------------------------------------------------------------
// [Public] Getter methods
//------------------------------------------------------------------------------
std::string getCertificateFile() const { return m_certificateFile; }
std::string getStoragePath() const { return m_storagePath; }
std::string getRemoteHost() const { return m_remoteHost; }
unsigned int getRemotePort() const { return m_remotePort; }
std::string getRemoteUsername() const { return m_remoteUsername; }
std::string getRemotePassword() const { return m_remotePassword; }
std::string getRemoteSchema() const { return m_remoteSchema; }
std::string getRemoteTable() const { return m_remoteTable; }
std::string getDatabaseHost() const { return m_databaseHost; }
unsigned int getDatabasePort() const { return m_databasePort; }
std::string getDatabaseUsername() const { return m_databaseUsername; }
std::string getDatabasePassword() const { return m_databasePassword; }
std::string getDatabaseSchema() const { return m_databaseSchema; }
std::string getDatabaseTable() const { return m_databaseTable; }
unsigned int getRefreshTime() const { return m_refreshTime; }
unsigned int getTimeout() const { return m_timeout; }
unsigned int getRecoveryTime() const { return m_recoveryTime; }
std::string getAuxDatabaseHost() const { return m_auxDatabaseHost; }
unsigned int getAuxDatabasePort() const { return m_auxDatabasePort; }
std::string getAuxDatabaseUsername() const { return m_auxDatabaseUsername; }
std::string getAuxDatabasePassword() const { return m_auxDatabasePassword; }
std::string getAuxDatabaseSchema() const { return m_auxDatabaseSchema; }
std::string getAuxDatabaseTimestampTable() const { return m_auxDatabaseTimestampTable; }
std::string getAuxDatabaseFailedTable() const { return m_auxDatabaseFailedTable; }
std::string getWhereCondition() const { return m_whereCondition; }
private:
//------------------------------------------------------------------------------
// [Private] class variables
//------------------------------------------------------------------------------
//Absolute path to certificate chain file
const std::string m_certificateFile;
//Absolute path to storage
const std::string m_storagePath;
//Metadata exporter remote host
const std::string m_remoteHost;
//Metadata exporter remote port
const unsigned int m_remotePort;
//Metadata exporter login username
const std::string m_remoteUsername;
//Metadata exporter remote password
const std::string m_remotePassword;
//Metadata remote database schema
const std::string m_remoteSchema;
//Metadata remote database table
const std::string m_remoteTable;
//Metadata local database host
const std::string m_databaseHost;
//Metadata local database port
const unsigned int m_databasePort;
//Metadata local database username
const std::string m_databaseUsername;
//Metadata local database password
const std::string m_databasePassword;
//Metadata local database schema
const std::string m_databaseSchema;
//Metadata local database table
const std::string m_databaseTable;
//Remote database request period (seconds)
const unsigned int m_refreshTime;
//Connection timeout (seconds)
const unsigned int m_timeout;
//Recovery time (seconds)
const unsigned int m_recoveryTime;
//Auxiliary database host
const std::string m_auxDatabaseHost;
//Auxiliary database port
const unsigned int m_auxDatabasePort;
//Auxiliary database username
const std::string m_auxDatabaseUsername;
//Auxiliary database password
const std::string m_auxDatabasePassword;
//Auxiliary database schema
const std::string m_auxDatabaseSchema;
//Auxiliary database timestamp table
const std::string m_auxDatabaseTimestampTable;
//Auxiliary database failed table
const std::string m_auxDatabaseFailedTable;
//Files retrieval where condition
const std::string m_whereCondition;
};
} //End of namespace
#endif /* CONFIGURATION_H */
data_importer-master/src/DBManager.cpp 0000664 0000000 0000000 00000027417 14145762224 0020276 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
namespace DataImporter_ns
{
//==============================================================================
// DBManager::DBManager()
//==============================================================================
DBManager::DBManager(Tango::DeviceImpl* deviceImpl_p,
Configuration::SP configuration_sp) : Tango::LogAdapter(deviceImpl_p),
m_configuration_sp(configuration_sp)
{
DEBUG_STREAM << "DBManager::DBManager()" << endl;
m_deviceName = deviceImpl_p->get_name_lower();
m_mainSession_sp.reset(new soci::session);
m_auxSession_sp.reset(new soci::session);
}
//==============================================================================
// DBManager::~DBManager()
//==============================================================================
DBManager::~DBManager()
{
DEBUG_STREAM << "DBManager::~DBManager()" << endl;
m_mainSession_sp->close();
m_auxSession_sp->close();
}
//==============================================================================
// DBManager::create()
//==============================================================================
DBManager::SP DBManager::create(Tango::DeviceImpl* deviceImpl_p,
Configuration::SP configuration_sp)
{
DBManager::SP d_sp(new DBManager(deviceImpl_p, configuration_sp),
DBManager::Deleter());
return d_sp;
}
//==============================================================================
// DBManager::connect()
//==============================================================================
void DBManager::connectAll() throw(soci::soci_error)
{
DEBUG_STREAM << "DBManager::connect()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
bool reconnect = true;
std::stringstream connection;
connection << " host=" << m_configuration_sp->getDatabaseHost();
connection << " port=" << m_configuration_sp->getDatabasePort();
connection << " user=" << m_configuration_sp->getDatabaseUsername();
connection << " password=" << m_configuration_sp->getDatabasePassword();
#ifdef VERBOSE_DEBUG
INFO_STREAM << "MAIN CONNECTION: " << connection.str() << endl;
#endif
m_mainSession_sp->open(soci::mysql, connection.str());
soci::mysql_session_backend* mainBackend =
static_cast(
m_mainSession_sp->get_backend());
MYSQL* mainMysql = mainBackend->conn_;
mysql_options(mainMysql, MYSQL_OPT_RECONNECT, &reconnect);
connection.str("");
connection << " host=" << m_configuration_sp->getAuxDatabaseHost();
connection << " port=" << m_configuration_sp->getAuxDatabasePort();
connection << " user=" << m_configuration_sp->getAuxDatabaseUsername();
connection << " password=" << m_configuration_sp->getAuxDatabasePassword();
#ifdef VERBOSE_DEBUG
INFO_STREAM << "AUX CONNECTION: " << connection.str() << endl;
#endif
m_auxSession_sp->open(soci::mysql, connection.str());
soci::mysql_session_backend* auxBackend =
static_cast(
m_auxSession_sp->get_backend());
MYSQL* auxMysql = auxBackend->conn_;
mysql_options(auxMysql, MYSQL_OPT_RECONNECT, &reconnect);
}
//==============================================================================
// DBManager::disconnect()
//==============================================================================
void DBManager::disconnectAll()
{
DEBUG_STREAM << "DBManager::disconnect()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
m_mainSession_sp->close();
m_auxSession_sp->close();
}
//==============================================================================
// DBManager::getMainTransaction()
//==============================================================================
DBManager::TransactionSP DBManager::getMainTransaction()
{
DEBUG_STREAM << "DBManager::getMainTransaction()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
TransactionSP transaction_sp(new soci::transaction(*m_mainSession_sp));
return transaction_sp;
}
//==============================================================================
// DBManager::getAuxTransaction()
//==============================================================================
DBManager::TransactionSP DBManager::getAuxTransaction()
{
DEBUG_STREAM << "DBManager::getAuxTransaction()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
TransactionSP transaction_sp(new soci::transaction(*m_auxSession_sp));
return transaction_sp;
}
//==============================================================================
// DBManager::retrieveLastTimestamp()
//==============================================================================
boost::posix_time::ptime DBManager::retrieveLastTimestamp()
throw(soci::soci_error)
{
DEBUG_STREAM << "DBManager::retrieveLastTimestamp()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
if(m_auxSession_sp->get_backend() == NULL)
m_auxSession_sp->reconnect();
std::tm tm_time;
*m_auxSession_sp << "select coalesce(max(last_timestamp),'1970-01-01 00:00:00')"
<< " from "<< m_configuration_sp->getAuxDatabaseSchema()
<< "." << m_configuration_sp->getAuxDatabaseTimestampTable()
<< " where device_name like :deviceName",
soci::use(m_deviceName, "deviceName"), soci::into(tm_time);
return boost::posix_time::ptime_from_tm(tm_time);
}
//==============================================================================
// DBManager::persistLastTimestamp()
//==============================================================================
void DBManager::persistLastTimestamp(boost::posix_time::ptime ptime)
throw(soci::soci_error)
{
DEBUG_STREAM << "DBManager::persistLastTimestamp()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
if(m_auxSession_sp->get_backend() == NULL)
m_auxSession_sp->reconnect();
*m_auxSession_sp << "insert into " << m_configuration_sp->getAuxDatabaseSchema()
<< "." << m_configuration_sp->getAuxDatabaseTimestampTable()
<< " (device_name, last_timestamp) values ('" << m_deviceName << "','"
<< boost::posix_time::to_iso_string(ptime) << "') on duplicate key update"
<< " last_timestamp='" << boost::posix_time::to_iso_string(ptime) << "'";
}
//==============================================================================
// DBManager::retrieveNewFiles()
//==============================================================================
DBManager::FileRowsetSP DBManager::retrieveNewFiles(boost::posix_time::ptime ptime)
throw(soci::soci_error)
{
DEBUG_STREAM << "DBManager::retrieveNewFiles()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
if(m_mainSession_sp->get_backend() == NULL)
m_mainSession_sp->reconnect();
std::string whereCondition = m_configuration_sp->getWhereCondition();
FileRowsetSP newFileRowset_sp;
if(whereCondition.empty())
{
newFileRowset_sp.reset(new FileRowset(m_mainSession_sp->prepare
<< "select storage_path, file_path, file_version, file_name, update_time "
<< "from " << m_configuration_sp->getDatabaseSchema() << "."
<< m_configuration_sp->getDatabaseTable() << " where update_time>'"
<< boost::posix_time::to_iso_string(ptime) << "' order by update_time asc"));
}
else
{
newFileRowset_sp.reset(new FileRowset(m_mainSession_sp->prepare
<< "select storage_path, file_path, file_version, file_name, update_time "
<< "from " << m_configuration_sp->getDatabaseSchema() << "."
<< m_configuration_sp->getDatabaseTable() << " where update_time>'"
<< boost::posix_time::to_iso_string(ptime) << "' and "
<< whereCondition << " order by update_time asc"));
}
return newFileRowset_sp;
}
//==============================================================================
// DBManager::updateNewFilePath()
//==============================================================================
void DBManager::updateNewFilePath(std::string storagePath, std::string filePath,
int fileVersion, std::string fileName) throw(soci::soci_error)
{
DEBUG_STREAM << "DBManager::updateNewFilePath()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
if(m_mainSession_sp->get_backend() == NULL)
m_mainSession_sp->reconnect();
*m_mainSession_sp << "update " << m_configuration_sp->getDatabaseSchema()
<< "." << m_configuration_sp->getDatabaseTable()
<< " set storage_path = :storagePath, file_path = :filePath "
<< " where file_version = :fileVersion and file_name like :fileName",
soci::use(storagePath, "storagePath"), soci::use(filePath, "filePath"),
soci::use(fileVersion, "fileVersion"), soci::use(fileName, "fileName");
}
//==============================================================================
// DBManager::addFailedFile()
//==============================================================================
void DBManager::addFailedFile(int fileVersion, std::string fileName)
throw(soci::soci_error)
{
DEBUG_STREAM << "DBManager::addFailedFile()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
if(m_auxSession_sp->get_backend() == NULL)
m_auxSession_sp->reconnect();
*m_auxSession_sp << "insert ignore into "
<< m_configuration_sp->getAuxDatabaseSchema() << "."
<< m_configuration_sp->getAuxDatabaseFailedTable()
<< " (device_name, file_version, file_name) values (:deviceName, "
<< ":fileVersion, :fileName)", soci::use(m_deviceName, "deviceName"),
soci::use(fileVersion, "fileVersion"), soci::use(fileName, "fileName");
}
//==============================================================================
// DBManager::removeFailedFile()
//==============================================================================
void DBManager::removeFailedFile(int fileVersion, std::string fileName)
throw(soci::soci_error)
{
DEBUG_STREAM << "DBManager::removeFailedFile()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
if(m_auxSession_sp->get_backend() == NULL)
m_auxSession_sp->reconnect();
*m_auxSession_sp << "delete from " << m_configuration_sp->getAuxDatabaseSchema()
<< "." << m_configuration_sp->getAuxDatabaseFailedTable()
<< " where device_name like :deviceName and file_version = :fileVersion"
<< " and file_name like :fileName", soci::use(m_deviceName, "deviceName"),
soci::use(fileVersion, "fileVersion"), soci::use(fileName, "fileName");
}
//==============================================================================
// DBManager::retrieveFailedFiles()
//==============================================================================
DBManager::FileRowsetSP DBManager::retrieveFailedFiles()
throw(soci::soci_error)
{
DEBUG_STREAM << "DBManager::retrieveFailedFiles()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
if(m_auxSession_sp->get_backend() == NULL)
m_auxSession_sp->reconnect();
FileRowsetSP failedFileRowset_sp(new FileRowset(
m_auxSession_sp->prepare << "select m.storage_path, m.file_path, "
<< " m.file_version, m.file_name, m.update_time from "
<< m_configuration_sp->getDatabaseSchema() << "."
<< m_configuration_sp->getDatabaseTable() << " as m join "
<< m_configuration_sp->getAuxDatabaseSchema() << "."
<< m_configuration_sp->getAuxDatabaseFailedTable() << " as f "
<< "on f.file_version = m.file_version and f.file_name = m.file_name "
<< "where device_name like '" << m_deviceName << "'"));
return failedFileRowset_sp;
}
} //namespace
data_importer-master/src/DBManager.h 0000664 0000000 0000000 00000011016 14145762224 0017727 0 ustar 00root root 0000000 0000000 /*
* File: DBManager.h
* Author: mdm
*
* Created on October 24, 2013, 2:57 PM
*/
#ifndef DBMANAGER_H
#define DBMANAGER_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace DataImporter_ns
{
class DBManager : public Tango::LogAdapter
{
public:
//------------------------------------------------------------------------------
// [Public] Shared pointer typedef
//------------------------------------------------------------------------------
typedef boost::shared_ptr SP;
protected:
//------------------------------------------------------------------------------
// [Protected] Constructor destructor deleter
//------------------------------------------------------------------------------
DBManager(Tango::DeviceImpl*, Configuration::SP);
virtual ~DBManager();
class Deleter;
friend class Deleter;
class Deleter
{
public:
void operator()(DBManager* d) { delete d; }
};
public:
//------------------------------------------------------------------------------
// [Public] Class creation method
//------------------------------------------------------------------------------
static DBManager::SP create(Tango::DeviceImpl*, Configuration::SP);
//------------------------------------------------------------------------------
// [Public] Connections handling methods
//------------------------------------------------------------------------------
virtual void connectAll() throw(soci::soci_error);
virtual void disconnectAll();
//------------------------------------------------------------------------------
// [Public] Transaction retriever methods
//------------------------------------------------------------------------------
typedef boost::shared_ptr TransactionSP;
TransactionSP getMainTransaction();
TransactionSP getAuxTransaction();
//------------------------------------------------------------------------------
// [Public] Timestamp methods
//------------------------------------------------------------------------------
virtual boost::posix_time::ptime retrieveLastTimestamp()
throw(soci::soci_error);
virtual void persistLastTimestamp(boost::posix_time::ptime)
throw(soci::soci_error);
//------------------------------------------------------------------------------
// [Public] File row set definition
//------------------------------------------------------------------------------
typedef boost::tuple< boost::optional,
boost::optional, boost::optional,
boost::optional, boost::optional > FileRow;
typedef soci::rowset< FileRow > FileRowset;
typedef boost::shared_ptr< FileRowset > FileRowsetSP;
//------------------------------------------------------------------------------
// [Public] New file method
//------------------------------------------------------------------------------
virtual FileRowsetSP retrieveNewFiles(boost::posix_time::ptime)
throw(soci::soci_error);
virtual void updateNewFilePath(std::string, std::string, int, std::string)
throw(soci::soci_error);
//------------------------------------------------------------------------------
// [Public] Failed file methods
//------------------------------------------------------------------------------
virtual void addFailedFile(int, std::string)
throw(soci::soci_error);
virtual void removeFailedFile(int, std::string)
throw(soci::soci_error);
virtual FileRowsetSP retrieveFailedFiles()
throw(soci::soci_error);
protected:
//------------------------------------------------------------------------------
// [Protected] Class variables
//------------------------------------------------------------------------------
//Device name
std::string m_deviceName;
//Configuration shared pointer
Configuration::SP m_configuration_sp;
//Metadata database connection mutex
boost::mutex m_sessionMutex;
//Main database connection scoped pointer
boost::scoped_ptr m_mainSession_sp;
//Auxiliary database connection scoped pointer
boost::scoped_ptr m_auxSession_sp;
};
} //End of namespace
#endif /* DBMANAGER_H */
data_importer-master/src/DataImporter.cpp 0000664 0000000 0000000 00000106060 14145762224 0021101 0 ustar 00root root 0000000 0000000 /*----- 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 .
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include
#include
#include
#include
#include
/*----- PROTECTED REGION END -----*/ // DataImporter.cpp
/**
* DataImporter class description:
*
*/
//================================================================
// The following table gives the correspondence
// between command and method names.
//
// Command name | Method name
//================================================================
// State | Inherited (no method)
// Status | Inherited (no method)
// On | on
// Off | off
// ResetCounter | reset_counter
//================================================================
//================================================================
// Attributes managed are:
//================================================================
// 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 -----*/
// Delete device allocated objects
/*----- 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_state(Tango::INIT);
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 -----*/
// Initialize property data members
/*----- PROTECTED REGION END -----*/ // DataImporter::get_device_property_before
// Read device properties from database.
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("CertificateFile"));
dev_prop.push_back(Tango::DbDatum("StoragePath"));
dev_prop.push_back(Tango::DbDatum("RemoteHost"));
dev_prop.push_back(Tango::DbDatum("RemotePort"));
dev_prop.push_back(Tango::DbDatum("RemoteUsername"));
dev_prop.push_back(Tango::DbDatum("RemotePassword"));
dev_prop.push_back(Tango::DbDatum("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);
// get instance on DataImporterClass to get class property
Tango::DbDatum def_prop, cl_prop;
DataImporterClass *ds_class =
(static_cast(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;
// 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;
// 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;
else {
// 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,
auxDatabaseSchema, auxDatabaseTimestampTable,
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 &attr_list))
{
DEBUG_STREAM << "DataImporter::read_attr_hardware(vector &attr_list) entering... " << endl;
/*----- PROTECTED REGION ID(DataImporter::read_attr_hardware) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // DataImporter::read_attr_hardware
}
//--------------------------------------------------------
/**
* 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 -----*/
//==============================================================================
// 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;
}
//==============================================================================
// 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
data_importer-master/src/DataImporter.h 0000664 0000000 0000000 00000021607 14145762224 0020551 0 ustar 00root root 0000000 0000000 /*----- PROTECTED REGION ID(DataImporter.h) ENABLED START -----*/
//=============================================================================
//
// file : DataImporter.h
//
// description : Include file for the DataImporter class
//
// 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 .
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#ifndef DataImporter_H
#define DataImporter_H
#include
#include
#include
/*----- PROTECTED REGION END -----*/ // DataImporter.h
/**
* DataImporter class description:
*
*/
namespace DataImporter_ns
{
/*----- PROTECTED REGION ID(DataImporter::Additional Class Declarations) ENABLED START -----*/
// Additional Class Declarations
/*----- PROTECTED REGION END -----*/ // DataImporter::Additional Class Declarations
class DataImporter : public TANGO_BASE_CLASS
{
/*----- PROTECTED REGION ID(DataImporter::Data Members) ENABLED START -----*/
//------------------------------------------------------------------------------
// [Private] Class variables
//------------------------------------------------------------------------------
//Configuration class shared pointer
Configuration::SP m_configuration_sp;
//Client class shared pointer
Client::SP m_client_sp;
//Regular file counter synchronization
boost::mutex m_regularCounterMutex;
//Failed file counter synchronization
boost::mutex m_failedCounterMutex;
//Max port number allowed value for data import database
static const unsigned int MAX_PORT_NUMBER = 65535;
//Max time between remote server requests
static const unsigned int MAX_REFRESH_TIME = 3600;
//Max time between remote server request and response
static const unsigned int MAX_TIMEOUT = 60;
//Time between failed download attempt
static const unsigned int MAX_RECOVERY_TIME = 86400;
/*----- PROTECTED REGION END -----*/ // DataImporter::Data Members
// Device property data members
public:
// CertificateFile: Absolute path to certificate chain file
string certificateFile;
// StoragePath: Absolute path to storage
string storagePath;
// RemoteHost: Metadata exporter remote host
string remoteHost;
// RemotePort: Metadata exporter remote port
Tango::DevULong remotePort;
// RemoteUsername: Metadata exporter login username
string remoteUsername;
// RemotePassword: Metadata exporter remote password
string remotePassword;
// RemoteSchema: Metadata remote database schema
string remoteSchema;
// RemoteTable: Metadata remote database table
string remoteTable;
// EnableSSL: Enable or disable SSL connections
Tango::DevBoolean enableSSL;
// DatabaseHost: Metadata local database host
string databaseHost;
// DatabasePort: Metadata local database port
Tango::DevULong databasePort;
// DatabaseUsername: Metadata local database username
string databaseUsername;
// DatabasePassword: Metadata local database password
string databasePassword;
// DatabaseSchema: Metadata local database schema
string databaseSchema;
// DatabaseTable: Metadata local database table
string databaseTable;
// RefreshTime: Local database request period (seconds)
Tango::DevULong refreshTime;
// Timeout: Connection timeout (seconds)
Tango::DevULong timeout;
// RecoveryTime: Time between failed file download attempt
Tango::DevULong recoveryTime;
// AutoStart: Exec On command after init if state is not fault
Tango::DevBoolean autoStart;
// AuxDatabaseHost: File transfer auxiliary database host
string auxDatabaseHost;
// AuxDatabasePort: File transfer auxiliary database port
Tango::DevULong auxDatabasePort;
// AuxDatabaseUsername: File transfer auxiliary database username
string auxDatabaseUsername;
// AuxDatabasePassword: File transfer auxiliary database password
string auxDatabasePassword;
// AuxDatabaseSchema: File transfer auxiliary database schema
string auxDatabaseSchema;
// AuxDatabaseTimestampTable: File transfer auxiliary database device timestamp table
string auxDatabaseTimestampTable;
// AuxDatabaseFailedTable: File transfer auxiliary database failed transfer table
string auxDatabaseFailedTable;
// WhereCondition: Files retrieval sql where condition
string whereCondition;
// Attribute data members
public:
Tango::DevULong *attr_RegularFileCounter_read;
Tango::DevULong *attr_FailedFileCounter_read;
// Constructors and destructors
public:
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device Name
*/
DataImporter(Tango::DeviceClass *cl,string &s);
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device Name
*/
DataImporter(Tango::DeviceClass *cl,const char *s);
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device name
* @param d Device description.
*/
DataImporter(Tango::DeviceClass *cl,const char *s,const char *d);
/**
* The device object destructor.
*/
~DataImporter() {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 : DataImporter::read_attr_hardware()
* Description : Hardware acquisition for attributes.
*/
//--------------------------------------------------------
virtual void read_attr_hardware(vector &attr_list);
/**
* Attribute RegularFileCounter related methods
* Description:
*
* Data type: Tango::DevULong
* Attr type: Scalar
*/
virtual void read_RegularFileCounter(Tango::Attribute &attr);
virtual bool is_RegularFileCounter_allowed(Tango::AttReqType type);
/**
* Attribute FailedFileCounter related methods
* Description:
*
* Data type: Tango::DevULong
* Attr type: Scalar
*/
virtual void read_FailedFileCounter(Tango::Attribute &attr);
virtual bool is_FailedFileCounter_allowed(Tango::AttReqType type);
//--------------------------------------------------------
/**
* Method : DataImporter::add_dynamic_attributes()
* Description : Add dynamic attributes if any.
*/
//--------------------------------------------------------
void add_dynamic_attributes();
// Command related methods
public:
/**
* Command On related method
* Description: Activate data importer
*
*/
virtual void on();
virtual bool is_On_allowed(const CORBA::Any &any);
/**
* Command Off related method
* Description: Deactivate data importer
*
*/
virtual void off();
virtual bool is_Off_allowed(const CORBA::Any &any);
/**
* Command ResetCounter related method
* Description:
*
*/
virtual void reset_counter();
virtual bool is_ResetCounter_allowed(const CORBA::Any &any);
/*----- PROTECTED REGION ID(DataImporter::Additional Method prototypes) ENABLED START -----*/
//------------------------------------------------------------------------------
// [Public] Counters methods
//------------------------------------------------------------------------------
virtual void incrementRegularCounter();
virtual void incrementFailedCounter();
virtual void decrementFailedCounter();
protected:
//------------------------------------------------------------------------------
// [Protected] Utilities methods
//------------------------------------------------------------------------------
virtual void checkIfFileExists(std::string)
throw(std::invalid_argument);
virtual void checkIfDirectoryExists(std::string)
throw(std::invalid_argument);
/*----- PROTECTED REGION END -----*/ // DataImporter::Additional Method prototypes
};
/*----- PROTECTED REGION ID(DataImporter::Additional Classes Definitions) ENABLED START -----*/
// Additional Classes Definitions
/*----- PROTECTED REGION END -----*/ // DataImporter::Additional Classes Definitions
} // End of namespace
#endif // DataImporter_H
data_importer-master/src/DataImporter.xmi 0000664 0000000 0000000 00000035406 14145762224 0021121 0 ustar 00root root 0000000 0000000
10
60
60
false
ON
FAULT
ALARM
RUNNING
OFF
FAULT
data_importer-master/src/DataImporterClass.cpp 0000664 0000000 0000000 00000114021 14145762224 0022063 0 ustar 00root root 0000000 0000000 /*----- PROTECTED REGION ID(DataImporterClass.cpp) ENABLED START -----*/
static const char *TagName = "$Name: $";
static const char *CvsPath = "$Source: $";
static const char *SvnPath = "$HeadURL: $";
static const char *HttpServer = "http://www.esrf.eu/computing/cs/tango/tango_doc/ds_doc/";
//=============================================================================
//
// file : DataImporterClass.cpp
//
// description : C++ source for the DataImporterClass.
// A singleton class derived from DeviceClass.
// It implements the command and attribute list
// and all properties and methods required
// by the DataImporter once per process.
//
// 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 .
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include
/*----- PROTECTED REGION END -----*/ // DataImporterClass.cpp
//-------------------------------------------------------------------
/**
* Create DataImporterClass singleton and
* return it in a C function for Python usage
*/
//-------------------------------------------------------------------
extern "C" {
#ifdef _TG_WINDOWS_
__declspec(dllexport)
#endif
Tango::DeviceClass *_create_DataImporter_class(const char *name) {
return DataImporter_ns::DataImporterClass::init(name);
}
}
namespace DataImporter_ns
{
//===================================================================
// Initialize pointer for singleton pattern
//===================================================================
DataImporterClass *DataImporterClass::_instance = NULL;
//--------------------------------------------------------
/**
* method : DataImporterClass::DataImporterClass(string &s)
* description : constructor for the DataImporterClass
*
* @param s The class name
*/
//--------------------------------------------------------
DataImporterClass::DataImporterClass(string &s):Tango::DeviceClass(s)
{
cout2 << "Entering DataImporterClass constructor" << endl;
set_default_property();
get_class_property();
write_class_property();
/*----- PROTECTED REGION ID(DataImporterClass::constructor) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporterClass::constructor
cout2 << "Leaving DataImporterClass constructor" << endl;
}
//--------------------------------------------------------
/**
* method : DataImporterClass::~DataImporterClass()
* description : destructor for the DataImporterClass
*/
//--------------------------------------------------------
DataImporterClass::~DataImporterClass()
{
/*----- PROTECTED REGION ID(DataImporterClass::destructor) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporterClass::destructor
_instance = NULL;
}
//--------------------------------------------------------
/**
* method : DataImporterClass::init
* description : Create the object if not already done.
* Otherwise, just return a pointer to the object
*
* @param name The class name
*/
//--------------------------------------------------------
DataImporterClass *DataImporterClass::init(const char *name)
{
if (_instance == NULL)
{
try
{
string s(name);
_instance = new DataImporterClass(s);
}
catch (bad_alloc &)
{
throw;
}
}
return _instance;
}
//--------------------------------------------------------
/**
* method : DataImporterClass::instance
* description : Check if object already created,
* and return a pointer to the object
*/
//--------------------------------------------------------
DataImporterClass *DataImporterClass::instance()
{
if (_instance == NULL)
{
cerr << "Class is not initialised !!" << endl;
exit(-1);
}
return _instance;
}
//===================================================================
// Command execution method calls
//===================================================================
//--------------------------------------------------------
/**
* method : OnClass::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 *OnClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OnClass::execute(): arrived" << endl;
((static_cast(device))->on());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : OffClass::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 *OffClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OffClass::execute(): arrived" << endl;
((static_cast(device))->off());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : ResetCounterClass::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 *ResetCounterClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "ResetCounterClass::execute(): arrived" << endl;
((static_cast(device))->reset_counter());
return new CORBA::Any();
}
//===================================================================
// Properties management
//===================================================================
//--------------------------------------------------------
/**
* Method : DataImporterClass::get_class_property()
* Description : Get the class property for specified name.
*/
//--------------------------------------------------------
Tango::DbDatum DataImporterClass::get_class_property(string &prop_name)
{
for (unsigned int i=0 ; i_UseDb==true)
get_db_class()->get_property(cl_prop);
Tango::DbDatum def_prop;
int i = -1;
// Try to extract CertificateFile value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> certificateFile;
else
{
// Check default value for CertificateFile
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> certificateFile;
cl_prop[i] << certificateFile;
}
}
// Try to extract StoragePath value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> storagePath;
else
{
// Check default value for StoragePath
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> storagePath;
cl_prop[i] << storagePath;
}
}
// Try to extract AuxDatabaseHost value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> auxDatabaseHost;
else
{
// Check default value for AuxDatabaseHost
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> auxDatabaseHost;
cl_prop[i] << auxDatabaseHost;
}
}
// Try to extract AuxDatabasePort value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> auxDatabasePort;
else
{
// Check default value for AuxDatabasePort
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> auxDatabasePort;
cl_prop[i] << auxDatabasePort;
}
}
// Try to extract AuxDatabaseUsername value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> auxDatabaseUsername;
else
{
// Check default value for AuxDatabaseUsername
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> auxDatabaseUsername;
cl_prop[i] << auxDatabaseUsername;
}
}
// Try to extract AuxDatabasePassword value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> auxDatabasePassword;
else
{
// Check default value for AuxDatabasePassword
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> auxDatabasePassword;
cl_prop[i] << auxDatabasePassword;
}
}
// Try to extract AuxDatabaseSchema value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> auxDatabaseSchema;
else
{
// Check default value for AuxDatabaseSchema
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> auxDatabaseSchema;
cl_prop[i] << auxDatabaseSchema;
}
}
// Try to extract AuxDatabaseTimestampTable value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> auxDatabaseTimestampTable;
else
{
// Check default value for AuxDatabaseTimestampTable
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> auxDatabaseTimestampTable;
cl_prop[i] << auxDatabaseTimestampTable;
}
}
// Try to extract AuxDatabaseFailedTable value
if (cl_prop[++i].is_empty()==false) cl_prop[i] >> auxDatabaseFailedTable;
else
{
// Check default value for AuxDatabaseFailedTable
def_prop = get_default_class_property(cl_prop[i].name);
if (def_prop.is_empty()==false)
{
def_prop >> auxDatabaseFailedTable;
cl_prop[i] << auxDatabaseFailedTable;
}
}
/*----- PROTECTED REGION ID(DataImporterClass::get_class_property_after) ENABLED START -----*/
// Check class property data members init
/*----- PROTECTED REGION END -----*/ // DataImporterClass::get_class_property_after
}
//--------------------------------------------------------
/**
* Method : DataImporterClass::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 DataImporterClass::set_default_property()
{
string prop_name;
string prop_desc;
string prop_def;
vector vect_data;
// Set Default Class Properties
prop_name = "CertificateFile";
prop_desc = "Absolute path to certificate chain file";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
prop_name = "StoragePath";
prop_desc = "Absolute path to storage";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
prop_name = "AuxDatabaseHost";
prop_desc = "File transfer auxiliary database host";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
prop_name = "AuxDatabasePort";
prop_desc = "File transfer auxiliary database port";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
prop_name = "AuxDatabaseUsername";
prop_desc = "File transfer auxiliary database username";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
prop_name = "AuxDatabasePassword";
prop_desc = "File transfer auxiliary database password";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
prop_name = "AuxDatabaseSchema";
prop_desc = "File transfer auxiliary database schema";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
prop_name = "AuxDatabaseTimestampTable";
prop_desc = "File transfer auxiliary database device timestamp table";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
prop_name = "AuxDatabaseFailedTable";
prop_desc = "File transfer auxiliary database failed transfer table";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
cl_def_prop.push_back(data);
add_wiz_class_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_class_prop(prop_name, prop_desc);
// Set Default device Properties
prop_name = "CertificateFile";
prop_desc = "Absolute path to certificate chain file";
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 = "StoragePath";
prop_desc = "Absolute path to storage";
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 = "RemoteHost";
prop_desc = "Metadata exporter remote host";
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 = "RemotePort";
prop_desc = "Metadata exporter remote port";
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 = "RemoteUsername";
prop_desc = "Metadata exporter login username";
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 = "RemotePassword";
prop_desc = "Metadata exporter remote password";
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 = "EnableSSL";
prop_desc = "Enable or disable SSL connections";
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 = "DatabaseHost";
prop_desc = "Metadata local database host";
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 = "DatabasePort";
prop_desc = "Metadata local database port";
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 = "DatabaseUsername";
prop_desc = "Metadata local database username";
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 = "DatabasePassword";
prop_desc = "Metadata local database password";
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 = "RemoteSchema";
prop_desc = "Metadata remote database schema";
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 = "DatabaseSchema";
prop_desc = "Metadata local database schema";
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 = "RemoteTable";
prop_desc = "Metadata remote database table";
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 = "DatabaseTable";
prop_desc = "Metadata local database table";
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 = "RefreshTime";
prop_desc = "Local database request period (seconds)";
prop_def = "10";
vect_data.clear();
vect_data.push_back("10");
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
dev_def_prop.push_back(data);
add_wiz_dev_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "Timeout";
prop_desc = "Connection timeout (seconds)";
prop_def = "60";
vect_data.clear();
vect_data.push_back("60");
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 = "RecoveryTime";
prop_desc = "Time between failed file download attempt";
prop_def = "60";
vect_data.clear();
vect_data.push_back("60");
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 = "AutoStart";
prop_desc = "Exec On command after init if state is not fault";
prop_def = "false";
vect_data.clear();
vect_data.push_back("false");
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 = "AuxDatabaseHost";
prop_desc = "File transfer auxiliary database host";
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 = "AuxDatabasePort";
prop_desc = "File transfer auxiliary database port";
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 = "AuxDatabaseUsername";
prop_desc = "File transfer auxiliary database username";
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 = "AuxDatabasePassword";
prop_desc = "File transfer auxiliary database password";
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 = "AuxDatabaseSchema";
prop_desc = "File transfer auxiliary database schema";
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 = "AuxDatabaseTimestampTable";
prop_desc = "File transfer auxiliary database device timestamp table";
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 = "AuxDatabaseFailedTable";
prop_desc = "File transfer auxiliary database failed transfer table";
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 = "WhereCondition";
prop_desc = "Files retrieval sql where condition";
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);
}
//--------------------------------------------------------
/**
* Method : DataImporterClass::write_class_property()
* Description : Set class description fields as property in database
*/
//--------------------------------------------------------
void DataImporterClass::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("Data importer");
title << str_title;
data.push_back(title);
// Put Description
Tango::DbDatum description("Description");
vector str_desc;
str_desc.push_back("");
description << str_desc;
data.push_back(description);
// put cvs or svn location
string filename("DataImporter");
filename += "Class.cpp";
// check for cvs information
string src_path(CvsPath);
start = src_path.find("/");
if (start!=string::npos)
{
end = src_path.find(filename);
if (end>start)
{
string strloc = src_path.substr(start, end-start);
// Check if specific repository
start = strloc.find("/cvsroot/");
if (start!=string::npos && start>0)
{
string repository = strloc.substr(0, start);
if (repository.find("/segfs/")!=string::npos)
strloc = "ESRF:" + strloc.substr(start, strloc.length()-start);
}
Tango::DbDatum cvs_loc("cvs_location");
cvs_loc << strloc;
data.push_back(cvs_loc);
}
}
// check for svn information
else
{
string src_path(SvnPath);
start = src_path.find("://");
if (start!=string::npos)
{
end = src_path.find(filename);
if (end>start)
{
header = "$HeadURL: ";
start = header.length();
string strloc = src_path.substr(start, (end-start));
Tango::DbDatum svn_loc("svn_location");
svn_loc << strloc;
data.push_back(svn_loc);
}
}
}
// Get CVS or SVN revision tag
// CVS tag
string tagname(TagName);
header = "$Name: ";
start = header.length();
string endstr(" $");
end = tagname.find(endstr);
if (end!=string::npos && end>start)
{
string strtag = tagname.substr(start, end-start);
Tango::DbDatum cvs_tag("cvs_tag");
cvs_tag << strtag;
data.push_back(cvs_tag);
}
// SVN tag
string svnpath(SvnPath);
header = "$HeadURL: ";
start = header.length();
end = svnpath.find(endstr);
if (end!=string::npos && end>start)
{
string strloc = svnpath.substr(start, end-start);
string tagstr ("/tags/");
start = strloc.find(tagstr);
if ( start!=string::npos )
{
start = start + tagstr.length();
end = strloc.find(filename);
string strtag = strloc.substr(start, end-start-1);
Tango::DbDatum svn_tag("svn_tag");
svn_tag << strtag;
data.push_back(svn_tag);
}
}
// Get URL location
string httpServ(HttpServer);
if (httpServ.length()>0)
{
Tango::DbDatum db_doc_url("doc_url");
db_doc_url << httpServ;
data.push_back(db_doc_url);
}
// Put inheritance
Tango::DbDatum inher_datum("InheritedFrom");
vector inheritance;
inheritance.push_back("TANGO_BASE_CLASS");
inher_datum << inheritance;
data.push_back(inher_datum);
// Call database and and values
get_db_class()->put_property(data);
}
//===================================================================
// Factory methods
//===================================================================
//--------------------------------------------------------
/**
* Method : DataImporterClass::device_factory()
* Description : Create the device object(s)
* and store them in the device list
*/
//--------------------------------------------------------
void DataImporterClass::device_factory(const Tango::DevVarStringArray *devlist_ptr)
{
/*----- PROTECTED REGION ID(DataImporterClass::device_factory_before) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // DataImporterClass::device_factory_before
// Create devices and add it into the device list
for (unsigned long i=0 ; ilength() ; i++)
{
cout4 << "Device name : " << (*devlist_ptr)[i].in() << endl;
device_list.push_back(new DataImporter(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
DataImporter *dev = static_cast(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(DataImporterClass::device_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // DataImporterClass::device_factory_after
}
//--------------------------------------------------------
/**
* Method : DataImporterClass::attribute_factory()
* Description : Create the attribute object(s)
* and store them in the attribute list
*/
//--------------------------------------------------------
void DataImporterClass::attribute_factory(vector &att_list)
{
/*----- PROTECTED REGION ID(DataImporterClass::attribute_factory_before) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // DataImporterClass::attribute_factory_before
// Attribute : RegularFileCounter
RegularFileCounterAttrib *regularfilecounter = new RegularFileCounterAttrib();
Tango::UserDefaultAttrProp regularfilecounter_prop;
// description not set for RegularFileCounter
// label not set for RegularFileCounter
// unit not set for RegularFileCounter
// standard_unit not set for RegularFileCounter
// display_unit not set for RegularFileCounter
// format not set for RegularFileCounter
// max_value not set for RegularFileCounter
// min_value not set for RegularFileCounter
// max_alarm not set for RegularFileCounter
// min_alarm not set for RegularFileCounter
// max_warning not set for RegularFileCounter
// min_warning not set for RegularFileCounter
// delta_t not set for RegularFileCounter
// delta_val not set for RegularFileCounter
regularfilecounter->set_default_properties(regularfilecounter_prop);
// Not Polled
regularfilecounter->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(regularfilecounter);
// Attribute : FailedFileCounter
FailedFileCounterAttrib *failedfilecounter = new FailedFileCounterAttrib();
Tango::UserDefaultAttrProp failedfilecounter_prop;
// description not set for FailedFileCounter
// label not set for FailedFileCounter
// unit not set for FailedFileCounter
// standard_unit not set for FailedFileCounter
// display_unit not set for FailedFileCounter
// format not set for FailedFileCounter
// max_value not set for FailedFileCounter
// min_value not set for FailedFileCounter
// max_alarm not set for FailedFileCounter
// min_alarm not set for FailedFileCounter
// max_warning not set for FailedFileCounter
// min_warning not set for FailedFileCounter
// delta_t not set for FailedFileCounter
// delta_val not set for FailedFileCounter
failedfilecounter->set_default_properties(failedfilecounter_prop);
// Not Polled
failedfilecounter->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(failedfilecounter);
// Create a list of static attributes
create_static_attribute_list(get_class_attr()->get_attr_list());
/*----- PROTECTED REGION ID(DataImporterClass::attribute_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // DataImporterClass::attribute_factory_after
}
//--------------------------------------------------------
/**
* Method : DataImporterClass::command_factory()
* Description : Create the command object(s)
* and store them in the command list
*/
//--------------------------------------------------------
void DataImporterClass::command_factory()
{
/*----- PROTECTED REGION ID(DataImporterClass::command_factory_before) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // DataImporterClass::command_factory_before
// Command On
OnClass *pOnCmd =
new OnClass("On",
Tango::DEV_VOID, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pOnCmd);
// Command Off
OffClass *pOffCmd =
new OffClass("Off",
Tango::DEV_VOID, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pOffCmd);
// Command ResetCounter
ResetCounterClass *pResetCounterCmd =
new ResetCounterClass("ResetCounter",
Tango::DEV_VOID, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pResetCounterCmd);
/*----- PROTECTED REGION ID(DataImporterClass::command_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // DataImporterClass::command_factory_after
}
//===================================================================
// Dynamic attributes related methods
//===================================================================
//--------------------------------------------------------
/**
* method : DataImporterClass::create_static_attribute_list
* description : Create the a list of static attributes
*
* @param att_list the ceated attribute list
*/
//--------------------------------------------------------
void DataImporterClass::create_static_attribute_list(vector &att_list)
{
for (unsigned long i=0 ; iget_name());
transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower);
defaultAttList.push_back(att_name);
}
cout2 << defaultAttList.size() << " attributes in default list" << endl;
/*----- PROTECTED REGION ID(DataImporterClass::create_static_att_list) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporterClass::create_static_att_list
}
//--------------------------------------------------------
/**
* method : DataImporterClass::erase_dynamic_attributes
* description : delete the dynamic attributes if any.
*
* @param devlist_ptr the device list pointer
* @param list of all attributes
*/
//--------------------------------------------------------
void DataImporterClass::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, vector &att_list)
{
Tango::Util *tg = Tango::Util::instance();
for (unsigned long i=0 ; ilength() ; i++)
{
Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((string)(*devlist_ptr)[i]).c_str());
DataImporter *dev = static_cast (dev_impl);
vector &dev_att_list = dev->get_device_attr()->get_attribute_list();
vector::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"))
continue;
vector::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name);
if (ite_str == defaultAttList.end())
{
cout2 << 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, false);
--ite_att;
}
}
}
/*----- PROTECTED REGION ID(DataImporterClass::erase_dynamic_attributes) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporterClass::erase_dynamic_attributes
}
//--------------------------------------------------------
/**
* Method : DataImporterClass::get_attr_by_name()
* Description : returns Tango::Attr * object found by name
*/
//--------------------------------------------------------
Tango::Attr *DataImporterClass::get_attr_object_by_name(vector &att_list, string attname)
{
vector::iterator it;
for (it=att_list.begin() ; itget_name()==attname)
return (*it);
// Attr does not exist
return NULL;
}
/*----- PROTECTED REGION ID(DataImporterClass::Additional Methods) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporterClass::Additional Methods
} // namespace
data_importer-master/src/DataImporterClass.h 0000664 0000000 0000000 00000017214 14145762224 0021536 0 ustar 00root root 0000000 0000000 /*----- PROTECTED REGION ID(DataImporterClass.h) ENABLED START -----*/
//=============================================================================
//
// file : DataImporterClass.h
//
// description : Include for the DataImporter root class.
// This class is the singleton class for
// the DataImporter device class.
// It contains all properties and methods which the
// DataImporter requires only once e.g. the commands.
//
// 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 .
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#ifndef DataImporterClass_H
#define DataImporterClass_H
#include
#include
/*----- PROTECTED REGION END -----*/ // DataImporterClass.h
namespace DataImporter_ns
{
/*----- PROTECTED REGION ID(DataImporterClass::classes for dynamic creation) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporterClass::classes for dynamic creation
//=========================================
// Define classes for attributes
//=========================================
// Attribute RegularFileCounter class definition
class RegularFileCounterAttrib: public Tango::Attr
{
public:
RegularFileCounterAttrib():Attr("RegularFileCounter",
Tango::DEV_ULONG, Tango::READ) {};
~RegularFileCounterAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast(dev))->read_RegularFileCounter(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast(dev))->is_RegularFileCounter_allowed(ty);}
};
// Attribute FailedFileCounter class definition
class FailedFileCounterAttrib: public Tango::Attr
{
public:
FailedFileCounterAttrib():Attr("FailedFileCounter",
Tango::DEV_ULONG, Tango::READ) {};
~FailedFileCounterAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast(dev))->read_FailedFileCounter(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast(dev))->is_FailedFileCounter_allowed(ty);}
};
//=========================================
// Define classes for commands
//=========================================
// Command On class definition
class OnClass : public Tango::Command
{
public:
OnClass(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) {};
OnClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~OnClass() {};
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(dev))->is_On_allowed(any);}
};
// Command Off class definition
class OffClass : public Tango::Command
{
public:
OffClass(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) {};
OffClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~OffClass() {};
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(dev))->is_Off_allowed(any);}
};
// Command ResetCounter class definition
class ResetCounterClass : public Tango::Command
{
public:
ResetCounterClass(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) {};
ResetCounterClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~ResetCounterClass() {};
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(dev))->is_ResetCounter_allowed(any);}
};
/**
* The DataImporterClass singleton definition
*/
#ifdef _TG_WINDOWS_
class __declspec(dllexport) DataImporterClass : public Tango::DeviceClass
#else
class DataImporterClass : public Tango::DeviceClass
#endif
{
/*----- PROTECTED REGION ID(DataImporterClass::Additionnal DServer data members) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporterClass::Additionnal DServer data members
// Class properties data members
public:
// CertificateFile: Absolute path to certificate chain file
string certificateFile;
// StoragePath: Absolute path to storage
string storagePath;
// AuxDatabaseHost: File transfer auxiliary database host
string auxDatabaseHost;
// AuxDatabasePort: File transfer auxiliary database port
Tango::DevULong auxDatabasePort;
// AuxDatabaseUsername: File transfer auxiliary database username
string auxDatabaseUsername;
// AuxDatabasePassword: File transfer auxiliary database password
string auxDatabasePassword;
// AuxDatabaseSchema: File transfer auxiliary database schema
string auxDatabaseSchema;
// AuxDatabaseTimestampTable: File transfer auxiliary database device timestamp table
string auxDatabaseTimestampTable;
// AuxDatabaseFailedTable: File transfer auxiliary database failed transfer table
string auxDatabaseFailedTable;
public:
// write class properties data members
Tango::DbData cl_prop;
Tango::DbData cl_def_prop;
Tango::DbData dev_def_prop;
// Method prototypes
static DataImporterClass *init(const char *);
static DataImporterClass *instance();
~DataImporterClass();
Tango::DbDatum get_class_property(string &);
Tango::DbDatum get_default_device_property(string &);
Tango::DbDatum get_default_class_property(string &);
protected:
DataImporterClass(string &);
static DataImporterClass *_instance;
void command_factory();
void attribute_factory(vector &);
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 &);
void erase_dynamic_attributes(const Tango::DevVarStringArray *,vector &);
vector defaultAttList;
Tango::Attr *get_attr_object_by_name(vector &att_list, string attname);
};
} // End of namespace
#endif // DataImporter_H
data_importer-master/src/DataImporterStateMachine.cpp 0000664 0000000 0000000 00000012455 14145762224 0023373 0 ustar 00root root 0000000 0000000 /*----- PROTECTED REGION ID(DataImporterStateMachine.cpp) ENABLED START -----*/
//=============================================================================
//
// file : DataImporterStateMachine.cpp
//
// description : State machine file for the DataImporter class
//
// 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 .
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include
/*----- PROTECTED REGION END -----*/ // DataImporter::DataImporterStateMachine.cpp
//================================================================
// States | Description
//================================================================
// ON | Data exporter is in ON state (searching new file to transfer)
// OFF | Data exporter is in OFF state (not searching for file to transfer)
// FAULT | Data exporter is in FAULT state (configuration error occurred)
// ALARM | Data exporter is in ALARM state (runtime error occured)
// RUNNING | Data exporter is in RUNNING state (file transfer in progress)
namespace DataImporter_ns
{
//=================================================
// Attributes Allowed Methods
//=================================================
//--------------------------------------------------------
/**
* Method : DataImporter::is_RegularFileCounter_allowed()
* Description : Execution allowed for RegularFileCounter attribute
*/
//--------------------------------------------------------
bool DataImporter::is_RegularFileCounter_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Not any excluded states for RegularFileCounter attribute in read access.
/*----- PROTECTED REGION ID(DataImporter::RegularFileCounterStateAllowed_READ) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporter::RegularFileCounterStateAllowed_READ
return true;
}
//--------------------------------------------------------
/**
* Method : DataImporter::is_FailedFileCounter_allowed()
* Description : Execution allowed for FailedFileCounter attribute
*/
//--------------------------------------------------------
bool DataImporter::is_FailedFileCounter_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Not any excluded states for FailedFileCounter attribute in read access.
/*----- PROTECTED REGION ID(DataImporter::FailedFileCounterStateAllowed_READ) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporter::FailedFileCounterStateAllowed_READ
return true;
}
//=================================================
// Commands Allowed Methods
//=================================================
//--------------------------------------------------------
/**
* Method : DataImporter::is_On_allowed()
* Description : Execution allowed for On attribute
*/
//--------------------------------------------------------
bool DataImporter::is_On_allowed(TANGO_UNUSED(const CORBA::Any &any))
{
// Compare device state with not allowed states.
if (get_state()==Tango::ON ||
get_state()==Tango::FAULT ||
get_state()==Tango::ALARM ||
get_state()==Tango::RUNNING)
{
/*----- PROTECTED REGION ID(DataImporter::OnStateAllowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporter::OnStateAllowed
return false;
}
return true;
}
//--------------------------------------------------------
/**
* Method : DataImporter::is_Off_allowed()
* Description : Execution allowed for Off attribute
*/
//--------------------------------------------------------
bool DataImporter::is_Off_allowed(TANGO_UNUSED(const CORBA::Any &any))
{
// Compare device state with not allowed states.
if (get_state()==Tango::OFF ||
get_state()==Tango::FAULT)
{
/*----- PROTECTED REGION ID(DataImporter::OffStateAllowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporter::OffStateAllowed
return false;
}
return true;
}
//--------------------------------------------------------
/**
* Method : DataImporter::is_ResetCounter_allowed()
* Description : Execution allowed for ResetCounter attribute
*/
//--------------------------------------------------------
bool DataImporter::is_ResetCounter_allowed(TANGO_UNUSED(const CORBA::Any &any))
{
// Not any excluded states for ResetCounter command.
/*----- PROTECTED REGION ID(DataImporter::ResetCounterStateAllowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // DataImporter::ResetCounterStateAllowed
return true;
}
} // End of namespace
data_importer-master/src/FileWrapper.cpp 0000664 0000000 0000000 00000013072 14145762224 0020726 0 ustar 00root root 0000000 0000000 #include
namespace DataImporter_ns
{
//==============================================================================
// FileWrapper::FileWrapper()
//==============================================================================
FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p,
std::string storagePath, std::string filePath, int fileVersion,
std::string fileName, boost::uint64_t totalFileSize) throw(std::logic_error)
: Tango::LogAdapter(deviceImpl_p), m_storagePath(storagePath),
m_filePath(filePath), m_fileVersion(fileVersion), m_fileName(fileName),
m_expectedFileSize(totalFileSize)
{
DEBUG_STREAM << "FileWrapper::FileWrapper()" << endl;
m_outputFilePath /= storagePath;
m_outputFilePath /= filePath;
std::stringstream fileStream;
fileStream << "/" << fileVersion;
m_outputFilePath /= fileStream.str();
try
{
if(!boost::filesystem::exists(m_outputFilePath))
boost::filesystem::create_directories(m_outputFilePath);
}
catch(boost::filesystem::filesystem_error& ex)
{
throw std::logic_error(ex.what());
}
if(!boost::filesystem::is_directory(m_outputFilePath))
throw std::logic_error("Destination path \'"
+ m_outputFilePath.string() + "\' is not a directory" );
m_outputFilePath /= fileName;
m_outputFileStream.open(m_outputFilePath.string(), std::ios::binary);
}
//==============================================================================
// FileWrapper::~FileWrapper()
//==============================================================================
FileWrapper::~FileWrapper()
{
DEBUG_STREAM << "FileWrapper::~FileWrapper()" << endl;
m_outputFileStream.close();
}
//==============================================================================
// FileWrapper::create()
//==============================================================================
FileWrapper::SP FileWrapper::create(Tango::DeviceImpl* deviceImpl_p,
std::string storagePath, std::string filePath, int fileVersion,
std::string fileName, boost::uint64_t fileSize)
throw(std::logic_error)
{
FileWrapper::SP d_sp(new FileWrapper(deviceImpl_p, storagePath, filePath,
fileVersion, fileName, fileSize), FileWrapper::Deleter());
return d_sp;
}
//==============================================================================
// FileWrapper::getStoragePath()
//==============================================================================
std::string FileWrapper::getStoragePath()
{
DEBUG_STREAM << "FileWrapper::getStoragePath()" << endl;
return m_storagePath;
}
//==============================================================================
// FileWrapper::getFilePath()
//==============================================================================
std::string FileWrapper::getFilePath()
{
DEBUG_STREAM << "FileWrapper::getFilePath()" << endl;
return m_filePath;
}
//==============================================================================
// FileWrapper::getFileVersion()
//==============================================================================
int FileWrapper::getFileVersion()
{
DEBUG_STREAM << "FileWrapper::getFileVersion()" << endl;
return m_fileVersion;
}
//==============================================================================
// FileWrapper::getFileName()
//==============================================================================
std::string FileWrapper::getFileName()
{
DEBUG_STREAM << "FileWrapper::getFileName()" << endl;
return m_fileName;
}
//==============================================================================
// FileWrapper::isOpen()
//==============================================================================
bool FileWrapper::isOpen()
{
return m_outputFileStream.is_open();
}
//==============================================================================
// FileWrapper::isBad()
//==============================================================================
bool FileWrapper::isBad()
{
return m_outputFileStream.bad();
}
//==============================================================================
// FileWrapper::isCompleted()
//==============================================================================
bool FileWrapper::isCompleted()
{
return (boost::uint64_t)m_outputFileStream.tellp() >= m_expectedFileSize;
}
//==============================================================================
// FileWrapper::getLeftToWrite()
//==============================================================================
boost::uint64_t FileWrapper::getLeftToWrite()
{
return m_expectedFileSize - (boost::uint64_t)m_outputFileStream.tellp();
}
//==============================================================================
// FileWrapper::write()
//==============================================================================
void FileWrapper::write(std::vector& writeBuff, boost::uint64_t& recvBytes)
{
m_outputFileStream.write(&writeBuff[0], (std::streamsize)recvBytes);
}
//==============================================================================
// FileWrapper::cleanUp()
//==============================================================================
void FileWrapper::cleanUp()
{
DEBUG_STREAM << "FileWrapper::cleanUp()" << endl;
if(m_outputFileStream.is_open())
m_outputFileStream.close();
boost::system::error_code errorCode;
if(boost::filesystem::exists(m_outputFilePath))
boost::filesystem::remove(m_outputFilePath, errorCode);
}
} //namespace
data_importer-master/src/FileWrapper.h 0000664 0000000 0000000 00000005641 14145762224 0020376 0 ustar 00root root 0000000 0000000 #ifndef FILEWRAPPER_H
#define FILEWRAPPER_H
#include
#include
namespace DataImporter_ns
{
class FileWrapper : public Tango::LogAdapter
{
public:
//------------------------------------------------------------------------------
// [Public] Shared pointer typedef
//------------------------------------------------------------------------------
typedef boost::shared_ptr SP;
protected:
//------------------------------------------------------------------------------
// [Protected] Constructor destructor deleter
//------------------------------------------------------------------------------
FileWrapper(Tango::DeviceImpl*, std::string, std::string, int, std::string,
boost::uint64_t) throw(std::logic_error);
virtual ~FileWrapper();
class Deleter;
friend class Deleter;
class Deleter
{
public:
void operator()(FileWrapper* d) { delete d; }
};
public:
//------------------------------------------------------------------------------
// [Public] Class creation method
//------------------------------------------------------------------------------
static FileWrapper::SP create(Tango::DeviceImpl*, std::string, std::string,
int, std::string, boost::uint64_t) throw(std::logic_error);
//------------------------------------------------------------------------------
// [Public] Properties getter methods
//------------------------------------------------------------------------------
virtual std::string getStoragePath();
virtual std::string getFilePath();
virtual int getFileVersion();
virtual std::string getFileName();
//------------------------------------------------------------------------------
// [Public] Input stream methods
//------------------------------------------------------------------------------
virtual bool isOpen();
virtual bool isBad();
virtual bool isCompleted();
boost::uint64_t getLeftToWrite();
virtual void write(std::vector&, boost::uint64_t&);
//------------------------------------------------------------------------------
// [Public] Clean up method
//------------------------------------------------------------------------------
virtual void cleanUp();
protected:
//------------------------------------------------------------------------------
// [Protected] Class variables
//------------------------------------------------------------------------------
//Storage path property
const std::string m_storagePath;
//File path property
const std::string m_filePath;
//File version property
const int m_fileVersion;
//File name property
const std::string m_fileName;
//Expected file size
boost::uint64_t m_expectedFileSize;
//Output file path
boost::filesystem::path m_outputFilePath;
//Output file stream
std::ofstream m_outputFileStream;
};
} //End of namespace
#endif /* FILEWRAPPER_H */
data_importer-master/src/PlainClient.cpp 0000664 0000000 0000000 00000020455 14145762224 0020713 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
#include
namespace DataImporter_ns
{
//==============================================================================
// PlainClient::PlainClient()
//==============================================================================
PlainClient::PlainClient(DataImporter* dataImporter_p,
Configuration::SP configuration_sp) : Client(dataImporter_p, configuration_sp),
m_plainSocket(m_ioService)
{
DEBUG_STREAM << "PlainClient::PlainClient()" << endl;
}
//==============================================================================
// PlainClient::~PlainClient()
//==============================================================================
PlainClient::~PlainClient()
{
DEBUG_STREAM << "PlainClient::~PlainClient()" << endl;
closeConnection();
}
//==============================================================================
// PlainClient::create()
//==============================================================================
Client::SP PlainClient::create(DataImporter* dataImporter_p,
Configuration::SP configuration_sp)
{
Client::SP c_sp(new PlainClient(dataImporter_p, configuration_sp),
PlainClient::Deleter());
return c_sp;
}
//==============================================================================
// PlainClient::startConnect()
//==============================================================================
void PlainClient::startConnect(boost::asio::ip::tcp::resolver::iterator endPointIterator)
{
DEBUG_STREAM << "PlainClient::startConnect()" << endl;
m_resetConnectionTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getTimeout()));
if(endPointIterator != boost::asio::ip::tcp::resolver::iterator())
{
std::stringstream infoStream;
infoStream << "Connecting to " << endPointIterator->endpoint();
DEBUG_STREAM << "PlainClient::startConnect() " << infoStream.str() << endl;
writeState(Tango::RUNNING);
writeStatus(infoStream.str());
m_plainSocket.async_connect(endPointIterator->endpoint(),
boost::bind(&PlainClient::handleConnect, this,
boost::asio::placeholders::error, endPointIterator));
}
else
{
ERROR_STREAM << "PlainClient::startConnect() no more endpoint" << endl;
writeState(Tango::ALARM);
writeStatus("No more endpoint");
}
}
//==============================================================================
// PlainClient::handleConnect()
//==============================================================================
void PlainClient::handleConnect(const boost::system::error_code& errorCode,
boost::asio::ip::tcp::resolver::iterator endPointIterator)
{
DEBUG_STREAM << "PlainClient::handleConnect()" << endl;
if(!errorCode)
{
m_remoteEndpoint = boost::lexical_cast(
m_plainSocket.remote_endpoint());
std::stringstream infoStream;
infoStream << "Connected to " << m_remoteEndpoint;
INFO_STREAM << "PlainClient::handleConnect() " << m_remoteEndpoint << endl;
writeState(Tango::RUNNING);
writeStatus(infoStream.str());
m_protocolManager_sp->setRemoteEndpoint(m_remoteEndpoint);
startWriteRequest();
}
else
{
ERROR_STREAM << "PlainClient::handleConnect() " << errorCode.message() << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
if(m_plainSocket.is_open())
m_plainSocket.close();
startConnect(++endPointIterator);
}
}
//==============================================================================
// PlainClient::startRequest()
//==============================================================================
void PlainClient::startWriteRequest()
{
DEBUG_STREAM << "PlainClient::startRequest()" << endl;
try
{
RequestSP request_sp = m_protocolManager_sp->createtRequest();
boost::uint32_t bodySize = request_sp->ByteSize();
#ifdef VERBOSE_DEBUG
INFO_STREAM << "PlainClient::startRequest() "
<< m_remoteEndpoint << " <<<< " << bodySize << " byte" << endl;
#endif
std::vector writeBuff;
writeBuff.resize(HEADER_SIZE + bodySize);
encodeHeader(writeBuff, bodySize);
request_sp->SerializeToArray(&writeBuff[HEADER_SIZE], bodySize);
m_resetConnectionTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getTimeout()));
boost::asio::async_write(m_plainSocket, boost::asio::buffer(writeBuff),
boost::bind(&PlainClient::handleWriteRequest, this,
boost::asio::placeholders::error));
}
catch(std::exception& ec)
{
ERROR_STREAM << "PlainClient::startWriteRequest() " << ec.what() << endl;
writeState(Tango::ALARM);
writeStatus(ec.what());
}
catch(...)
{
ERROR_STREAM << "PlainClient::startWriteRequest() unknown error" << endl;
writeState(Tango::ALARM);
writeStatus("Unknown error");
}
}
//==============================================================================
// PlainClient::startReadResponseHeader()
//==============================================================================
void PlainClient::startReadResponseHeader()
{
DEBUG_STREAM << "PlainClient::startReadResponseHeader()" << endl;
m_readBuff.resize(HEADER_SIZE);
m_resetConnectionTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getTimeout()));
boost::asio::async_read(m_plainSocket, boost::asio::buffer(m_readBuff),
boost::bind(&PlainClient::handleReadResponseHeader, this,
boost::asio::placeholders::error));
}
//==============================================================================
// PlainClient::startReadResponseBody()
//==============================================================================
void PlainClient::startReadResponseBody(boost::uint32_t bodySize)
{
DEBUG_STREAM << "PlainClient::startReadResponseBody()" << endl;
#ifdef VERBOSE_DEBUG
INFO_STREAM << "PlainClient::startReadResponseBody() "
<< m_remoteEndpoint << " >>>> " << bodySize << " byte" << endl;
#endif
m_readBuff.resize(HEADER_SIZE + bodySize);
boost::asio::mutable_buffers_1 mutableBuffer =
boost::asio::buffer(&m_readBuff[HEADER_SIZE], bodySize);
boost::asio::async_read(m_plainSocket, mutableBuffer,
boost::bind(&PlainClient::handleReadResponseBody, this,
boost::asio::placeholders::error));
}
//==============================================================================
// PlainClient::startReadData()
//==============================================================================
void PlainClient::startReadData(FileWrapper::SP fileWrapper_sp)
{
boost::uint64_t leftToWrite = fileWrapper_sp->getLeftToWrite();
boost::uint64_t bufferSize = 0;
if(leftToWritegetTimeout()));
boost::asio::async_read(m_plainSocket, boost::asio::buffer(m_fileBuff),
boost::bind(&PlainClient::handleReadData, this, fileWrapper_sp,
boost::asio::placeholders::bytes_transferred,
boost::asio::placeholders::error));
}
//==============================================================================
// PlainClient::closeConnection()
//==============================================================================
void PlainClient::closeConnection()
{
DEBUG_STREAM << "PlainClient::closeConnection()" << endl;
std::stringstream infoStream;
infoStream << "Disconnected from " << m_remoteEndpoint;
INFO_STREAM << "PlainClient::closeConnection() " << infoStream.str() << endl;
m_listsUpdateTimer.expires_at(boost::posix_time::pos_infin);
m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin);
boost::system::error_code errorCode;
m_plainSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode);
m_plainSocket.close(errorCode);
}
} //namespace
data_importer-master/src/PlainClient.h 0000664 0000000 0000000 00000004261 14145762224 0020355 0 ustar 00root root 0000000 0000000 #ifndef PLAINCLIENT_H
#define PLAINCLIENT_H
#include
namespace DataImporter_ns
{
class PlainClient : public Client
{
protected:
//------------------------------------------------------------------------------
// [Protected] Constructor destructor
//------------------------------------------------------------------------------
PlainClient(DataImporter*, Configuration::SP);
virtual ~PlainClient();
class Deleter;
friend class Deleter;
class Deleter
{
public:
void operator()(PlainClient* d) { delete d; }
};
public:
//------------------------------------------------------------------------------
// [Public] Class creation method
//------------------------------------------------------------------------------
static Client::SP create(DataImporter*, Configuration::SP);
protected:
//------------------------------------------------------------------------------
// [Protected] Connection initialization methods
//------------------------------------------------------------------------------
virtual void startConnect(boost::asio::ip::tcp::resolver::iterator);
virtual void handleConnect(const boost::system::error_code&,
boost::asio::ip::tcp::resolver::iterator);
//------------------------------------------------------------------------------
// [Protected] Request response methods
//------------------------------------------------------------------------------
virtual void startWriteRequest();
virtual void startReadResponseHeader();
virtual void startReadResponseBody(boost::uint32_t);
virtual void startReadData(FileWrapper::SP);
//------------------------------------------------------------------------------
// [Protected] Connection close method
//------------------------------------------------------------------------------
virtual void closeConnection();
//------------------------------------------------------------------------------
// [Protected] Class variables
//------------------------------------------------------------------------------
//Plain connection socket
boost::asio::ip::tcp::socket m_plainSocket;
};
} //End of namespace
#endif /* PLAINCLIENT_H */
data_importer-master/src/ProtocolManager.cpp 0000664 0000000 0000000 00000034311 14145762224 0021601 0 ustar 00root root 0000000 0000000 #include
#include
#include
namespace DataImporter_ns
{
//==============================================================================
// ProtocolManager::ProtocolManager()
//==============================================================================
ProtocolManager::ProtocolManager(DataImporter* dataImporter_p,
Configuration::SP configuration_sp, DBManager::SP dBManager_sp) :
Tango::LogAdapter(dataImporter_p), m_dataImporter_p(dataImporter_p),
m_configuration_sp(configuration_sp), m_dBManager_sp(dBManager_sp)
{
DEBUG_STREAM << "ProtocolManager::ProtocolManager()" << endl;
}
//==============================================================================
// ProtocolManager::~ProtocolManager()
//==============================================================================
ProtocolManager::~ProtocolManager()
{
DEBUG_STREAM << "ProtocolManager::~ProtocolManager()" << endl;
}
//==============================================================================
// ProtocolManager::create()
//==============================================================================
ProtocolManager::SP ProtocolManager::create(DataImporter* dataImporter_p,
Configuration::SP configuration_sp, DBManager::SP dBManager_sp)
{
ProtocolManager::SP d_sp(new ProtocolManager(dataImporter_p, configuration_sp,
dBManager_sp), ProtocolManager::Deleter());
return d_sp;
}
//==============================================================================
// ProtocolManager::setRemoteEndpoint()
//==============================================================================
void ProtocolManager::setRemoteEndpoint(std::string remoteEndpoint)
{
DEBUG_STREAM << "ProtocolManager::setRemoteEndpoint()" << endl;
m_remoteEndpoint = remoteEndpoint;
}
//==============================================================================
// ProtocolManager::retrieveFiles()
//==============================================================================
void ProtocolManager::retrieveFiles() throw(std::runtime_error)
{
DEBUG_STREAM << "ProtocolManager::retrieveFiles()" << endl;
boost::posix_time::ptime m_lastTimestamp =
m_dBManager_sp->retrieveLastTimestamp();
DEBUG_STREAM << "ProtocolManager::updateNewList() last timestamp "
<< boost::posix_time::to_simple_string(m_lastTimestamp) << endl;
m_newFileRowset_sp = m_dBManager_sp->retrieveNewFiles(m_lastTimestamp);
m_newFileRowsetIt = m_newFileRowset_sp->begin();
m_failedFileRowset_sp = m_dBManager_sp->retrieveFailedFiles();
m_failedFileRowsetIt = m_failedFileRowset_sp->begin();
}
//==============================================================================
// ProtocolManager::hasFilesToTransfer()
//==============================================================================
bool ProtocolManager::hasFilesToTransfer()
{
DEBUG_STREAM << "ProtocolManager::hasFilesToTransfer()" << endl;
if(m_newFileRowset_sp &&
m_newFileRowsetIt != m_newFileRowset_sp->end())
{
INFO_STREAM << "ProtocolManager::hasFilesToTransfer() in new list" << endl;
return true;
}
else if(m_failedFileRowset_sp &&
m_failedFileRowsetIt != m_failedFileRowset_sp->end())
{
if(isRecoveryTimeElapsed())
{
INFO_STREAM << "ProtocolManager::hasFilesToTransfer() in failed list" << endl;
return true;
}
}
return false;
}
//==============================================================================
// ProtocolManager::hasNextFile()
//==============================================================================
bool ProtocolManager::hasNextFile()
{
DEBUG_STREAM << "ProtocolManager::hasNextFile()" << endl;
if(m_newFileRowset_sp &&
m_newFileRowsetIt != m_newFileRowset_sp->end())
{
return true;
}
else if(m_failedFileRowset_sp &&
m_failedFileRowsetIt != m_failedFileRowset_sp->end())
{
return true;
}
else
{
return false;
}
}
//==============================================================================
// ProtocolManager::createtRequest()
//==============================================================================
RequestSP ProtocolManager::createtRequest() throw(std::runtime_error)
{
DEBUG_STREAM << "ProtocolManager::createtRequest()" << endl;
if(m_newFileRowset_sp &&
m_newFileRowsetIt != m_newFileRowset_sp->end())
{
return fillRequest(m_newFileRowsetIt);
}
else if(m_failedFileRowset_sp &&
m_failedFileRowsetIt != m_failedFileRowset_sp->end())
{
return fillRequest(m_failedFileRowsetIt);
}
else
{
throw std::runtime_error("Lists not initialized");
}
}
//==============================================================================
// ProtocolManager::processResponse()
//==============================================================================
FileWrapper::SP ProtocolManager::processResponse(ResponseSP response_sp)
throw(std::logic_error, std::runtime_error)
{
DEBUG_STREAM << "ProtocolManager::processResponse()" << endl;
if(!response_sp->IsInitialized())
throw std::runtime_error("Response not initialized");
if(response_sp->state() == Response::REQUEST_ACCEPTED)
{
std::string filePath = response_sp->file_path();
if(filePath.empty())
throw std::runtime_error("Empty file path received");
int fileVersion = response_sp->file_version();
std::string fileName = response_sp->file_name();
if(fileName.empty())
throw std::runtime_error("Empty file path received");
boost::uint64_t fileSize = response_sp->file_size();
INFO_STREAM << "ProtocolManager::processResponse() transfer file "
<< fileName << " version " << fileVersion << " size " << fileSize
<< " from " << m_remoteEndpoint << endl;
return FileWrapper::create(m_dataImporter_p,
m_configuration_sp->getStoragePath(), filePath,
fileVersion, fileName, fileSize);
}
else if(response_sp->state() == Response::METADATA_NOT_FOUND ||
response_sp->state() == Response::FILE_NOT_DOWNLOADED ||
response_sp->state() == Response::FILE_NOT_FOUND)
{
throw std::logic_error(response_sp->status());
}
else
throw std::runtime_error(response_sp->status());
}
//==============================================================================
// ProtocolManager::setCurrentFileDownloaded()
//==============================================================================
void ProtocolManager::setCurrentFileDownloaded(FileWrapper::SP fileWrapper_sp)
throw(std::runtime_error)
{
DEBUG_STREAM << "ProtocolManager::setCurrentFileDownloaded()" << endl;
std::string storagePath = fileWrapper_sp->getStoragePath();
std::string filePath = fileWrapper_sp->getFilePath();
if(m_newFileRowset_sp &&
m_newFileRowsetIt != m_newFileRowset_sp->end())
{
if(!m_newFileRowsetIt->get<2>())
throw std::runtime_error("Empty file version found");
int fileVersion = m_newFileRowsetIt->get<2>().get();
if(!m_newFileRowsetIt->get<3>())
throw std::runtime_error("Empty file name found");
std::string fileName = m_newFileRowsetIt->get<3>().get();
if(!m_newFileRowsetIt->get<4>())
throw std::runtime_error("Empty update time found");
std::tm currentTm = m_newFileRowsetIt->get<4>().get();
INFO_STREAM << "ProtocolManager::setNewFileTransfered() file "
<< fileName << " version " << fileVersion << " transfered" << endl;
boost::posix_time::ptime currentPtime =
boost::posix_time::ptime_from_tm(currentTm);
boost::posix_time::ptime nextPtime(boost::posix_time::pos_infin);
++m_newFileRowsetIt;
if(m_newFileRowsetIt != m_newFileRowset_sp->end())
{
if(!m_newFileRowsetIt->get<4>())
throw std::runtime_error("Empty next update time found");
std::tm nextTm = m_newFileRowsetIt->get<4>().get();
nextPtime =boost::posix_time::ptime_from_tm(nextTm);
}
DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction();
DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction();
if(nextPtime > currentPtime)
m_dBManager_sp->persistLastTimestamp(currentPtime);
m_dBManager_sp->updateNewFilePath(storagePath, filePath, fileVersion, fileName);
auxTransaction_sp->commit();
mainTransaction_sp->commit();
m_dataImporter_p->incrementRegularCounter();
}
else if(m_failedFileRowset_sp &&
m_failedFileRowsetIt != m_failedFileRowset_sp->end())
{
if(!m_failedFileRowsetIt->get<2>())
throw std::runtime_error("Empty file version found");
int fileVersion = m_failedFileRowsetIt->get<2>().get();
if(!m_failedFileRowsetIt->get<3>())
throw std::runtime_error("Empty file name found");
string fileName = m_failedFileRowsetIt->get<3>().get();
++m_failedFileRowsetIt;
DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction();
DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction();
m_dBManager_sp->removeFailedFile(fileVersion, fileName);
m_dBManager_sp->updateNewFilePath(storagePath, filePath, fileVersion, fileName);
auxTransaction_sp->commit();
mainTransaction_sp->commit();
m_dataImporter_p->decrementFailedCounter();
m_dataImporter_p->incrementRegularCounter();
}
else
{
throw std::runtime_error("Lists not initialized");
}
}
//==============================================================================
// ProtocolManager::setCurrentFileFailed()
//==============================================================================
void ProtocolManager::setCurrentFileFailed() throw(std::runtime_error)
{
DEBUG_STREAM << "ProtocolManager::setCurrentFileFailed()" << endl;
if(m_newFileRowset_sp &&
m_newFileRowsetIt != m_newFileRowset_sp->end())
{
if(!m_newFileRowsetIt->get<2>())
throw std::runtime_error("Empty file version found");
int fileVersion = m_newFileRowsetIt->get<2>().get();
if(!m_newFileRowsetIt->get<3>())
throw std::runtime_error("Empty file name found");
string fileName = m_newFileRowsetIt->get<3>().get();
if(!m_newFileRowsetIt->get<4>())
throw std::runtime_error("Empty update time found");
std::tm currentTm = m_newFileRowsetIt->get<4>().get();
INFO_STREAM << "ProtocolManager::setFileFailed() file "
<< fileName << " version " << fileVersion << " not transfered" << endl;
boost::posix_time::ptime currentPtime =
boost::posix_time::ptime_from_tm(currentTm);
boost::posix_time::ptime nextPtime(boost::posix_time::pos_infin);
++m_newFileRowsetIt;
if(m_newFileRowsetIt != m_newFileRowset_sp->end())
{
if(!m_newFileRowsetIt->get<4>())
throw std::runtime_error("Empty next update time found");
std::tm nextTm = m_newFileRowsetIt->get<4>().get();
nextPtime =boost::posix_time::ptime_from_tm(nextTm);
}
DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction();
DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction();
if(nextPtime > currentPtime)
m_dBManager_sp->persistLastTimestamp(currentPtime);
m_dBManager_sp->addFailedFile(fileVersion, fileName);
auxTransaction_sp->commit();
mainTransaction_sp->commit();
m_dataImporter_p->incrementFailedCounter();
}
else if(m_failedFileRowset_sp &&
m_failedFileRowsetIt != m_failedFileRowset_sp->end())
{
++m_failedFileRowsetIt;
}
else
{
throw std::runtime_error("Lists not initialized");
}
}
//==============================================================================
// ProtocolManager::isRecoveryTimeElapsed()
//==============================================================================
bool ProtocolManager::isRecoveryTimeElapsed()
{
DEBUG_STREAM << "ProtocolManager::isRecoveryTimeElapsed()" << endl;
boost::posix_time::ptime now(boost::posix_time::second_clock::local_time());
if(m_recoveryModeTime.is_not_a_date_time())
m_recoveryModeTime = now;
boost::posix_time::time_duration diff = now - m_recoveryModeTime;
DEBUG_STREAM << "ProtocolManager::isRecoveryTimeElapsed() " << diff.total_seconds()
<< "/" << (int)m_configuration_sp->getRecoveryTime() << endl;
if(diff.total_seconds() > (int)m_configuration_sp->getRecoveryTime())
{
m_recoveryModeTime = now;
return true;
}
else
{
return false;
}
}
//==============================================================================
// ProtocolManager::fillRequest()
//==============================================================================
RequestSP ProtocolManager::fillRequest(DBManager::FileRowset::const_iterator it)
throw(std::runtime_error)
{
DEBUG_STREAM << "ProtocolManager::fillRequest()" << endl;
RequestSP request_sp(new Request);
request_sp->set_username(m_configuration_sp->getDatabaseUsername());
request_sp->set_password(m_configuration_sp->getDatabasePassword());
request_sp->set_schema(m_configuration_sp->getRemoteSchema());
request_sp->set_table(m_configuration_sp->getRemoteTable());
if(!it->get<2>())
throw std::runtime_error("Empty file version found");
int fileVersion = it->get<2>().get();
if(!it->get<3>())
throw std::runtime_error("Empty file name found");
std::string fileName = it->get<3>().get();
request_sp->set_file_version(fileVersion);
request_sp->set_file_name(fileName);
INFO_STREAM << "ProtocolManager::fillRequest() file " << fileName
<< " version " << fileVersion << " to " << m_remoteEndpoint << endl;
if(!request_sp->IsInitialized())
throw std::runtime_error("Request not initialized");
return request_sp;
}
} //namespace
data_importer-master/src/ProtocolManager.h 0000664 0000000 0000000 00000010604 14145762224 0021245 0 ustar 00root root 0000000 0000000 #ifndef PROTOCOLMANAGER_H
#define PROTOCOLMANAGER_H
#include
#include
#include
#include
#include
#include
#include
namespace DataImporter_ns
{
class DataImporter;
//Protocol buffer request class shared pointer
typedef boost::shared_ptr RequestSP;
//Protocol buffer response class shared pointer
typedef boost::shared_ptr ResponseSP;
class ProtocolManager : public Tango::LogAdapter
{
public:
//------------------------------------------------------------------------------
// [Public] Shared pointer typedef
//------------------------------------------------------------------------------
typedef boost::shared_ptr SP;
protected:
//------------------------------------------------------------------------------
// [Protected] Constructor destructor deleter
//------------------------------------------------------------------------------
ProtocolManager(DataImporter*, Configuration::SP, DBManager::SP);
virtual ~ProtocolManager();
class Deleter;
friend class Deleter;
class Deleter
{
public:
void operator()(ProtocolManager* p) { delete p; }
};
public:
//------------------------------------------------------------------------------
// [Public] Class creation method
//------------------------------------------------------------------------------
static ProtocolManager::SP create(DataImporter*, Configuration::SP,
DBManager::SP);
//------------------------------------------------------------------------------
// [Public] Remote endpoint setter method
//------------------------------------------------------------------------------
virtual void setRemoteEndpoint(std::string);
//------------------------------------------------------------------------------
// [Public] Files lists methods
//------------------------------------------------------------------------------
virtual void retrieveFiles() throw(std::runtime_error);
virtual bool hasFilesToTransfer();
virtual bool hasNextFile();
//------------------------------------------------------------------------------
// [Public] Request response methods
//------------------------------------------------------------------------------
RequestSP createtRequest()
throw(std::runtime_error);
FileWrapper::SP processResponse(ResponseSP)
throw(std::logic_error, std::runtime_error);
//------------------------------------------------------------------------------
// [Public] Files status methods
//------------------------------------------------------------------------------
virtual void setCurrentFileDownloaded(FileWrapper::SP)
throw(std::runtime_error);
virtual void setCurrentFileFailed()
throw(std::runtime_error);
protected:
//------------------------------------------------------------------------------
// [Protected] Elapsed recovery time method
//------------------------------------------------------------------------------
virtual bool isRecoveryTimeElapsed();
//------------------------------------------------------------------------------
// [Protected] Fill request utility method
//------------------------------------------------------------------------------
virtual RequestSP fillRequest(DBManager::FileRowset::const_iterator)
throw(std::runtime_error);
//------------------------------------------------------------------------------
// [Protected] Class variables
//------------------------------------------------------------------------------
//Tango server class pointer
DataImporter* m_dataImporter_p;
//Configuration parameters shared pointer
Configuration::SP m_configuration_sp;
//Database manger shared pointer
DBManager::SP m_dBManager_sp;
//Address and port of remote endpoint
std::string m_remoteEndpoint;
//Processing file from failed list last timestamp
boost::posix_time::ptime m_recoveryModeTime;
//New file list shared pointer
DBManager::FileRowsetSP m_newFileRowset_sp;
//New file list iterator
DBManager::FileRowset::const_iterator m_newFileRowsetIt;
//Failed file list shared pointer
DBManager::FileRowsetSP m_failedFileRowset_sp;
//Failed file list iterator
DBManager::FileRowset::const_iterator m_failedFileRowsetIt;
};
} //End of namespace
#endif /* PROTOCOLMANAGER_H */
data_importer-master/src/Request.pb.cc 0000664 0000000 0000000 00000046773 14145762224 0020357 0 ustar 00root root 0000000 0000000 // Generated by the protocol buffer compiler. DO NOT EDIT!
// source: Request.proto
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include "Request.pb.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
// @@protoc_insertion_point(includes)
namespace DataImporter_ns {
namespace {
const ::google::protobuf::Descriptor* Request_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
Request_reflection_ = NULL;
} // namespace
void protobuf_AssignDesc_Request_2eproto() {
protobuf_AddDesc_Request_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"Request.proto");
GOOGLE_CHECK(file != NULL);
Request_descriptor_ = file->message_type(0);
static const int Request_offsets_[6] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Request, username_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Request, password_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Request, schema_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Request, table_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Request, file_version_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Request, file_name_),
};
Request_reflection_ =
new ::google::protobuf::internal::GeneratedMessageReflection(
Request_descriptor_,
Request::default_instance_,
Request_offsets_,
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Request, _has_bits_[0]),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Request, _unknown_fields_),
-1,
::google::protobuf::DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(Request));
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
inline void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_Request_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
Request_descriptor_, &Request::default_instance());
}
} // namespace
void protobuf_ShutdownFile_Request_2eproto() {
delete Request::default_instance_;
delete Request_reflection_;
}
void protobuf_AddDesc_Request_2eproto() {
static bool already_here = false;
if (already_here) return;
already_here = true;
GOOGLE_PROTOBUF_VERIFY_VERSION;
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\rRequest.proto\022\017DataImporter_ns\"u\n\007Requ"
"est\022\020\n\010username\030\001 \002(\t\022\020\n\010password\030\002 \002(\t\022"
"\016\n\006schema\030\003 \002(\t\022\r\n\005table\030\004 \002(\t\022\024\n\014file_v"
"ersion\030\005 \002(\005\022\021\n\tfile_name\030\006 \002(\t", 151);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"Request.proto", &protobuf_RegisterTypes);
Request::default_instance_ = new Request();
Request::default_instance_->InitAsDefaultInstance();
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_Request_2eproto);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_Request_2eproto {
StaticDescriptorInitializer_Request_2eproto() {
protobuf_AddDesc_Request_2eproto();
}
} static_descriptor_initializer_Request_2eproto_;
// ===================================================================
#ifndef _MSC_VER
const int Request::kUsernameFieldNumber;
const int Request::kPasswordFieldNumber;
const int Request::kSchemaFieldNumber;
const int Request::kTableFieldNumber;
const int Request::kFileVersionFieldNumber;
const int Request::kFileNameFieldNumber;
#endif // !_MSC_VER
Request::Request()
: ::google::protobuf::Message() {
SharedCtor();
}
void Request::InitAsDefaultInstance() {
}
Request::Request(const Request& from)
: ::google::protobuf::Message() {
SharedCtor();
MergeFrom(from);
}
void Request::SharedCtor() {
_cached_size_ = 0;
username_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
password_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
schema_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
table_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
file_version_ = 0;
file_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
::memset(_has_bits_, 0, sizeof(_has_bits_));
}
Request::~Request() {
SharedDtor();
}
void Request::SharedDtor() {
if (username_ != &::google::protobuf::internal::kEmptyString) {
delete username_;
}
if (password_ != &::google::protobuf::internal::kEmptyString) {
delete password_;
}
if (schema_ != &::google::protobuf::internal::kEmptyString) {
delete schema_;
}
if (table_ != &::google::protobuf::internal::kEmptyString) {
delete table_;
}
if (file_name_ != &::google::protobuf::internal::kEmptyString) {
delete file_name_;
}
if (this != default_instance_) {
}
}
void Request::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Request::descriptor() {
protobuf_AssignDescriptorsOnce();
return Request_descriptor_;
}
const Request& Request::default_instance() {
if (default_instance_ == NULL) protobuf_AddDesc_Request_2eproto();
return *default_instance_;
}
Request* Request::default_instance_ = NULL;
Request* Request::New() const {
return new Request;
}
void Request::Clear() {
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (has_username()) {
if (username_ != &::google::protobuf::internal::kEmptyString) {
username_->clear();
}
}
if (has_password()) {
if (password_ != &::google::protobuf::internal::kEmptyString) {
password_->clear();
}
}
if (has_schema()) {
if (schema_ != &::google::protobuf::internal::kEmptyString) {
schema_->clear();
}
}
if (has_table()) {
if (table_ != &::google::protobuf::internal::kEmptyString) {
table_->clear();
}
}
file_version_ = 0;
if (has_file_name()) {
if (file_name_ != &::google::protobuf::internal::kEmptyString) {
file_name_->clear();
}
}
}
::memset(_has_bits_, 0, sizeof(_has_bits_));
mutable_unknown_fields()->Clear();
}
bool Request::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
::google::protobuf::uint32 tag;
while ((tag = input->ReadTag()) != 0) {
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// required string username = 1;
case 1: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_username()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->username().data(), this->username().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(18)) goto parse_password;
break;
}
// required string password = 2;
case 2: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_password:
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_password()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->password().data(), this->password().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(26)) goto parse_schema;
break;
}
// required string schema = 3;
case 3: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_schema:
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_schema()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->schema().data(), this->schema().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(34)) goto parse_table;
break;
}
// required string table = 4;
case 4: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_table:
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_table()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->table().data(), this->table().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(40)) goto parse_file_version;
break;
}
// required int32 file_version = 5;
case 5: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
parse_file_version:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &file_version_)));
set_has_file_version();
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(50)) goto parse_file_name;
break;
}
// required string file_name = 6;
case 6: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_file_name:
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_file_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_name().data(), this->file_name().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectAtEnd()) return true;
break;
}
default: {
handle_uninterpreted:
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
return true;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, mutable_unknown_fields()));
break;
}
}
}
return true;
#undef DO_
}
void Request::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// required string username = 1;
if (has_username()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->username().data(), this->username().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
1, this->username(), output);
}
// required string password = 2;
if (has_password()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->password().data(), this->password().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
2, this->password(), output);
}
// required string schema = 3;
if (has_schema()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->schema().data(), this->schema().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
3, this->schema(), output);
}
// required string table = 4;
if (has_table()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->table().data(), this->table().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
4, this->table(), output);
}
// required int32 file_version = 5;
if (has_file_version()) {
::google::protobuf::internal::WireFormatLite::WriteInt32(5, this->file_version(), output);
}
// required string file_name = 6;
if (has_file_name()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_name().data(), this->file_name().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
6, this->file_name(), output);
}
if (!unknown_fields().empty()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
unknown_fields(), output);
}
}
::google::protobuf::uint8* Request::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
// required string username = 1;
if (has_username()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->username().data(), this->username().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
1, this->username(), target);
}
// required string password = 2;
if (has_password()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->password().data(), this->password().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
2, this->password(), target);
}
// required string schema = 3;
if (has_schema()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->schema().data(), this->schema().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
3, this->schema(), target);
}
// required string table = 4;
if (has_table()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->table().data(), this->table().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
4, this->table(), target);
}
// required int32 file_version = 5;
if (has_file_version()) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(5, this->file_version(), target);
}
// required string file_name = 6;
if (has_file_name()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_name().data(), this->file_name().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
6, this->file_name(), target);
}
if (!unknown_fields().empty()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
unknown_fields(), target);
}
return target;
}
int Request::ByteSize() const {
int total_size = 0;
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
// required string username = 1;
if (has_username()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->username());
}
// required string password = 2;
if (has_password()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->password());
}
// required string schema = 3;
if (has_schema()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->schema());
}
// required string table = 4;
if (has_table()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->table());
}
// required int32 file_version = 5;
if (has_file_version()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
this->file_version());
}
// required string file_name = 6;
if (has_file_name()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->file_name());
}
}
if (!unknown_fields().empty()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size;
}
void Request::MergeFrom(const ::google::protobuf::Message& from) {
GOOGLE_CHECK_NE(&from, this);
const Request* source =
::google::protobuf::internal::dynamic_cast_if_available(
&from);
if (source == NULL) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
MergeFrom(*source);
}
}
void Request::MergeFrom(const Request& from) {
GOOGLE_CHECK_NE(&from, this);
if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (from.has_username()) {
set_username(from.username());
}
if (from.has_password()) {
set_password(from.password());
}
if (from.has_schema()) {
set_schema(from.schema());
}
if (from.has_table()) {
set_table(from.table());
}
if (from.has_file_version()) {
set_file_version(from.file_version());
}
if (from.has_file_name()) {
set_file_name(from.file_name());
}
}
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
void Request::CopyFrom(const ::google::protobuf::Message& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
void Request::CopyFrom(const Request& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool Request::IsInitialized() const {
if ((_has_bits_[0] & 0x0000003f) != 0x0000003f) return false;
return true;
}
void Request::Swap(Request* other) {
if (other != this) {
std::swap(username_, other->username_);
std::swap(password_, other->password_);
std::swap(schema_, other->schema_);
std::swap(table_, other->table_);
std::swap(file_version_, other->file_version_);
std::swap(file_name_, other->file_name_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_unknown_fields_.Swap(&other->_unknown_fields_);
std::swap(_cached_size_, other->_cached_size_);
}
}
::google::protobuf::Metadata Request::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = Request_descriptor_;
metadata.reflection = Request_reflection_;
return metadata;
}
// @@protoc_insertion_point(namespace_scope)
} // namespace DataImporter_ns
// @@protoc_insertion_point(global_scope)
data_importer-master/src/Request.pb.h 0000664 0000000 0000000 00000043210 14145762224 0020200 0 ustar 00root root 0000000 0000000 // Generated by the protocol buffer compiler. DO NOT EDIT!
// source: Request.proto
#ifndef PROTOBUF_Request_2eproto__INCLUDED
#define PROTOBUF_Request_2eproto__INCLUDED
#include
#include
#if GOOGLE_PROTOBUF_VERSION < 2005000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 2005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
#include
#include
#include
#include
#include
// @@protoc_insertion_point(includes)
namespace DataImporter_ns {
// Internal implementation detail -- do not call these.
void protobuf_AddDesc_Request_2eproto();
void protobuf_AssignDesc_Request_2eproto();
void protobuf_ShutdownFile_Request_2eproto();
class Request;
// ===================================================================
class Request : public ::google::protobuf::Message {
public:
Request();
virtual ~Request();
Request(const Request& from);
inline Request& operator=(const Request& from) {
CopyFrom(from);
return *this;
}
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _unknown_fields_;
}
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const ::google::protobuf::Descriptor* descriptor();
static const Request& default_instance();
void Swap(Request* other);
// implements Message ----------------------------------------------
Request* New() const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const Request& from);
void MergeFrom(const Request& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required string username = 1;
inline bool has_username() const;
inline void clear_username();
static const int kUsernameFieldNumber = 1;
inline const ::std::string& username() const;
inline void set_username(const ::std::string& value);
inline void set_username(const char* value);
inline void set_username(const char* value, size_t size);
inline ::std::string* mutable_username();
inline ::std::string* release_username();
inline void set_allocated_username(::std::string* username);
// required string password = 2;
inline bool has_password() const;
inline void clear_password();
static const int kPasswordFieldNumber = 2;
inline const ::std::string& password() const;
inline void set_password(const ::std::string& value);
inline void set_password(const char* value);
inline void set_password(const char* value, size_t size);
inline ::std::string* mutable_password();
inline ::std::string* release_password();
inline void set_allocated_password(::std::string* password);
// required string schema = 3;
inline bool has_schema() const;
inline void clear_schema();
static const int kSchemaFieldNumber = 3;
inline const ::std::string& schema() const;
inline void set_schema(const ::std::string& value);
inline void set_schema(const char* value);
inline void set_schema(const char* value, size_t size);
inline ::std::string* mutable_schema();
inline ::std::string* release_schema();
inline void set_allocated_schema(::std::string* schema);
// required string table = 4;
inline bool has_table() const;
inline void clear_table();
static const int kTableFieldNumber = 4;
inline const ::std::string& table() const;
inline void set_table(const ::std::string& value);
inline void set_table(const char* value);
inline void set_table(const char* value, size_t size);
inline ::std::string* mutable_table();
inline ::std::string* release_table();
inline void set_allocated_table(::std::string* table);
// required int32 file_version = 5;
inline bool has_file_version() const;
inline void clear_file_version();
static const int kFileVersionFieldNumber = 5;
inline ::google::protobuf::int32 file_version() const;
inline void set_file_version(::google::protobuf::int32 value);
// required string file_name = 6;
inline bool has_file_name() const;
inline void clear_file_name();
static const int kFileNameFieldNumber = 6;
inline const ::std::string& file_name() const;
inline void set_file_name(const ::std::string& value);
inline void set_file_name(const char* value);
inline void set_file_name(const char* value, size_t size);
inline ::std::string* mutable_file_name();
inline ::std::string* release_file_name();
inline void set_allocated_file_name(::std::string* file_name);
// @@protoc_insertion_point(class_scope:DataImporter_ns.Request)
private:
inline void set_has_username();
inline void clear_has_username();
inline void set_has_password();
inline void clear_has_password();
inline void set_has_schema();
inline void clear_has_schema();
inline void set_has_table();
inline void clear_has_table();
inline void set_has_file_version();
inline void clear_has_file_version();
inline void set_has_file_name();
inline void clear_has_file_name();
::google::protobuf::UnknownFieldSet _unknown_fields_;
::std::string* username_;
::std::string* password_;
::std::string* schema_;
::std::string* table_;
::std::string* file_name_;
::google::protobuf::int32 file_version_;
mutable int _cached_size_;
::google::protobuf::uint32 _has_bits_[(6 + 31) / 32];
friend void protobuf_AddDesc_Request_2eproto();
friend void protobuf_AssignDesc_Request_2eproto();
friend void protobuf_ShutdownFile_Request_2eproto();
void InitAsDefaultInstance();
static Request* default_instance_;
};
// ===================================================================
// ===================================================================
// Request
// required string username = 1;
inline bool Request::has_username() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void Request::set_has_username() {
_has_bits_[0] |= 0x00000001u;
}
inline void Request::clear_has_username() {
_has_bits_[0] &= ~0x00000001u;
}
inline void Request::clear_username() {
if (username_ != &::google::protobuf::internal::kEmptyString) {
username_->clear();
}
clear_has_username();
}
inline const ::std::string& Request::username() const {
return *username_;
}
inline void Request::set_username(const ::std::string& value) {
set_has_username();
if (username_ == &::google::protobuf::internal::kEmptyString) {
username_ = new ::std::string;
}
username_->assign(value);
}
inline void Request::set_username(const char* value) {
set_has_username();
if (username_ == &::google::protobuf::internal::kEmptyString) {
username_ = new ::std::string;
}
username_->assign(value);
}
inline void Request::set_username(const char* value, size_t size) {
set_has_username();
if (username_ == &::google::protobuf::internal::kEmptyString) {
username_ = new ::std::string;
}
username_->assign(reinterpret_cast(value), size);
}
inline ::std::string* Request::mutable_username() {
set_has_username();
if (username_ == &::google::protobuf::internal::kEmptyString) {
username_ = new ::std::string;
}
return username_;
}
inline ::std::string* Request::release_username() {
clear_has_username();
if (username_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = username_;
username_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
inline void Request::set_allocated_username(::std::string* username) {
if (username_ != &::google::protobuf::internal::kEmptyString) {
delete username_;
}
if (username) {
set_has_username();
username_ = username;
} else {
clear_has_username();
username_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
}
}
// required string password = 2;
inline bool Request::has_password() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void Request::set_has_password() {
_has_bits_[0] |= 0x00000002u;
}
inline void Request::clear_has_password() {
_has_bits_[0] &= ~0x00000002u;
}
inline void Request::clear_password() {
if (password_ != &::google::protobuf::internal::kEmptyString) {
password_->clear();
}
clear_has_password();
}
inline const ::std::string& Request::password() const {
return *password_;
}
inline void Request::set_password(const ::std::string& value) {
set_has_password();
if (password_ == &::google::protobuf::internal::kEmptyString) {
password_ = new ::std::string;
}
password_->assign(value);
}
inline void Request::set_password(const char* value) {
set_has_password();
if (password_ == &::google::protobuf::internal::kEmptyString) {
password_ = new ::std::string;
}
password_->assign(value);
}
inline void Request::set_password(const char* value, size_t size) {
set_has_password();
if (password_ == &::google::protobuf::internal::kEmptyString) {
password_ = new ::std::string;
}
password_->assign(reinterpret_cast(value), size);
}
inline ::std::string* Request::mutable_password() {
set_has_password();
if (password_ == &::google::protobuf::internal::kEmptyString) {
password_ = new ::std::string;
}
return password_;
}
inline ::std::string* Request::release_password() {
clear_has_password();
if (password_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = password_;
password_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
inline void Request::set_allocated_password(::std::string* password) {
if (password_ != &::google::protobuf::internal::kEmptyString) {
delete password_;
}
if (password) {
set_has_password();
password_ = password;
} else {
clear_has_password();
password_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
}
}
// required string schema = 3;
inline bool Request::has_schema() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void Request::set_has_schema() {
_has_bits_[0] |= 0x00000004u;
}
inline void Request::clear_has_schema() {
_has_bits_[0] &= ~0x00000004u;
}
inline void Request::clear_schema() {
if (schema_ != &::google::protobuf::internal::kEmptyString) {
schema_->clear();
}
clear_has_schema();
}
inline const ::std::string& Request::schema() const {
return *schema_;
}
inline void Request::set_schema(const ::std::string& value) {
set_has_schema();
if (schema_ == &::google::protobuf::internal::kEmptyString) {
schema_ = new ::std::string;
}
schema_->assign(value);
}
inline void Request::set_schema(const char* value) {
set_has_schema();
if (schema_ == &::google::protobuf::internal::kEmptyString) {
schema_ = new ::std::string;
}
schema_->assign(value);
}
inline void Request::set_schema(const char* value, size_t size) {
set_has_schema();
if (schema_ == &::google::protobuf::internal::kEmptyString) {
schema_ = new ::std::string;
}
schema_->assign(reinterpret_cast(value), size);
}
inline ::std::string* Request::mutable_schema() {
set_has_schema();
if (schema_ == &::google::protobuf::internal::kEmptyString) {
schema_ = new ::std::string;
}
return schema_;
}
inline ::std::string* Request::release_schema() {
clear_has_schema();
if (schema_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = schema_;
schema_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
inline void Request::set_allocated_schema(::std::string* schema) {
if (schema_ != &::google::protobuf::internal::kEmptyString) {
delete schema_;
}
if (schema) {
set_has_schema();
schema_ = schema;
} else {
clear_has_schema();
schema_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
}
}
// required string table = 4;
inline bool Request::has_table() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void Request::set_has_table() {
_has_bits_[0] |= 0x00000008u;
}
inline void Request::clear_has_table() {
_has_bits_[0] &= ~0x00000008u;
}
inline void Request::clear_table() {
if (table_ != &::google::protobuf::internal::kEmptyString) {
table_->clear();
}
clear_has_table();
}
inline const ::std::string& Request::table() const {
return *table_;
}
inline void Request::set_table(const ::std::string& value) {
set_has_table();
if (table_ == &::google::protobuf::internal::kEmptyString) {
table_ = new ::std::string;
}
table_->assign(value);
}
inline void Request::set_table(const char* value) {
set_has_table();
if (table_ == &::google::protobuf::internal::kEmptyString) {
table_ = new ::std::string;
}
table_->assign(value);
}
inline void Request::set_table(const char* value, size_t size) {
set_has_table();
if (table_ == &::google::protobuf::internal::kEmptyString) {
table_ = new ::std::string;
}
table_->assign(reinterpret_cast(value), size);
}
inline ::std::string* Request::mutable_table() {
set_has_table();
if (table_ == &::google::protobuf::internal::kEmptyString) {
table_ = new ::std::string;
}
return table_;
}
inline ::std::string* Request::release_table() {
clear_has_table();
if (table_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = table_;
table_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
inline void Request::set_allocated_table(::std::string* table) {
if (table_ != &::google::protobuf::internal::kEmptyString) {
delete table_;
}
if (table) {
set_has_table();
table_ = table;
} else {
clear_has_table();
table_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
}
}
// required int32 file_version = 5;
inline bool Request::has_file_version() const {
return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void Request::set_has_file_version() {
_has_bits_[0] |= 0x00000010u;
}
inline void Request::clear_has_file_version() {
_has_bits_[0] &= ~0x00000010u;
}
inline void Request::clear_file_version() {
file_version_ = 0;
clear_has_file_version();
}
inline ::google::protobuf::int32 Request::file_version() const {
return file_version_;
}
inline void Request::set_file_version(::google::protobuf::int32 value) {
set_has_file_version();
file_version_ = value;
}
// required string file_name = 6;
inline bool Request::has_file_name() const {
return (_has_bits_[0] & 0x00000020u) != 0;
}
inline void Request::set_has_file_name() {
_has_bits_[0] |= 0x00000020u;
}
inline void Request::clear_has_file_name() {
_has_bits_[0] &= ~0x00000020u;
}
inline void Request::clear_file_name() {
if (file_name_ != &::google::protobuf::internal::kEmptyString) {
file_name_->clear();
}
clear_has_file_name();
}
inline const ::std::string& Request::file_name() const {
return *file_name_;
}
inline void Request::set_file_name(const ::std::string& value) {
set_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
file_name_ = new ::std::string;
}
file_name_->assign(value);
}
inline void Request::set_file_name(const char* value) {
set_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
file_name_ = new ::std::string;
}
file_name_->assign(value);
}
inline void Request::set_file_name(const char* value, size_t size) {
set_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
file_name_ = new ::std::string;
}
file_name_->assign(reinterpret_cast(value), size);
}
inline ::std::string* Request::mutable_file_name() {
set_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
file_name_ = new ::std::string;
}
return file_name_;
}
inline ::std::string* Request::release_file_name() {
clear_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = file_name_;
file_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
inline void Request::set_allocated_file_name(::std::string* file_name) {
if (file_name_ != &::google::protobuf::internal::kEmptyString) {
delete file_name_;
}
if (file_name) {
set_has_file_name();
file_name_ = file_name;
} else {
clear_has_file_name();
file_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
}
}
// @@protoc_insertion_point(namespace_scope)
} // namespace DataImporter_ns
#ifndef SWIG
namespace google {
namespace protobuf {
} // namespace google
} // namespace protobuf
#endif // SWIG
// @@protoc_insertion_point(global_scope)
#endif // PROTOBUF_Request_2eproto__INCLUDED
data_importer-master/src/Response.pb.cc 0000664 0000000 0000000 00000047560 14145762224 0020520 0 ustar 00root root 0000000 0000000 // Generated by the protocol buffer compiler. DO NOT EDIT!
// source: Response.proto
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include "Response.pb.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
// @@protoc_insertion_point(includes)
namespace DataImporter_ns {
namespace {
const ::google::protobuf::Descriptor* Response_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
Response_reflection_ = NULL;
const ::google::protobuf::EnumDescriptor* Response_State_descriptor_ = NULL;
} // namespace
void protobuf_AssignDesc_Response_2eproto() {
protobuf_AddDesc_Response_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"Response.proto");
GOOGLE_CHECK(file != NULL);
Response_descriptor_ = file->message_type(0);
static const int Response_offsets_[6] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Response, state_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Response, status_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Response, file_path_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Response, file_version_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Response, file_name_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Response, file_size_),
};
Response_reflection_ =
new ::google::protobuf::internal::GeneratedMessageReflection(
Response_descriptor_,
Response::default_instance_,
Response_offsets_,
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Response, _has_bits_[0]),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Response, _unknown_fields_),
-1,
::google::protobuf::DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(Response));
Response_State_descriptor_ = Response_descriptor_->enum_type(0);
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
inline void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_Response_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
Response_descriptor_, &Response::default_instance());
}
} // namespace
void protobuf_ShutdownFile_Response_2eproto() {
delete Response::default_instance_;
delete Response_reflection_;
}
void protobuf_AddDesc_Response_2eproto() {
static bool already_here = false;
if (already_here) return;
already_here = true;
GOOGLE_PROTOBUF_VERIFY_VERSION;
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\016Response.proto\022\017DataImporter_ns\"\272\002\n\010Re"
"sponse\022.\n\005state\030\001 \002(\0162\037.DataImporter_ns."
"Response.State\022\016\n\006status\030\002 \002(\t\022\021\n\tfile_p"
"ath\030\003 \001(\t\022\024\n\014file_version\030\004 \001(\005\022\021\n\tfile_"
"name\030\005 \001(\t\022\021\n\tfile_size\030\006 \001(\004\"\236\001\n\005State\022"
"\024\n\020REQUEST_ACCEPTED\020\000\022\017\n\013ACCESS_DENY\020\001\022\026"
"\n\022TABLE_NOT_EXPORTED\020\002\022\026\n\022METADATA_NOT_F"
"OUND\020\003\022\027\n\023FILE_NOT_DOWNLOADED\020\004\022\022\n\016FILE_"
"NOT_FOUND\020\005\022\021\n\rGENERIC_ERROR\020\006", 350);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"Response.proto", &protobuf_RegisterTypes);
Response::default_instance_ = new Response();
Response::default_instance_->InitAsDefaultInstance();
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_Response_2eproto);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_Response_2eproto {
StaticDescriptorInitializer_Response_2eproto() {
protobuf_AddDesc_Response_2eproto();
}
} static_descriptor_initializer_Response_2eproto_;
// ===================================================================
const ::google::protobuf::EnumDescriptor* Response_State_descriptor() {
protobuf_AssignDescriptorsOnce();
return Response_State_descriptor_;
}
bool Response_State_IsValid(int value) {
switch(value) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
return true;
default:
return false;
}
}
#ifndef _MSC_VER
const Response_State Response::REQUEST_ACCEPTED;
const Response_State Response::ACCESS_DENY;
const Response_State Response::TABLE_NOT_EXPORTED;
const Response_State Response::METADATA_NOT_FOUND;
const Response_State Response::FILE_NOT_DOWNLOADED;
const Response_State Response::FILE_NOT_FOUND;
const Response_State Response::GENERIC_ERROR;
const Response_State Response::State_MIN;
const Response_State Response::State_MAX;
const int Response::State_ARRAYSIZE;
#endif // _MSC_VER
#ifndef _MSC_VER
const int Response::kStateFieldNumber;
const int Response::kStatusFieldNumber;
const int Response::kFilePathFieldNumber;
const int Response::kFileVersionFieldNumber;
const int Response::kFileNameFieldNumber;
const int Response::kFileSizeFieldNumber;
#endif // !_MSC_VER
Response::Response()
: ::google::protobuf::Message() {
SharedCtor();
}
void Response::InitAsDefaultInstance() {
}
Response::Response(const Response& from)
: ::google::protobuf::Message() {
SharedCtor();
MergeFrom(from);
}
void Response::SharedCtor() {
_cached_size_ = 0;
state_ = 0;
status_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
file_path_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
file_version_ = 0;
file_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
file_size_ = GOOGLE_ULONGLONG(0);
::memset(_has_bits_, 0, sizeof(_has_bits_));
}
Response::~Response() {
SharedDtor();
}
void Response::SharedDtor() {
if (status_ != &::google::protobuf::internal::kEmptyString) {
delete status_;
}
if (file_path_ != &::google::protobuf::internal::kEmptyString) {
delete file_path_;
}
if (file_name_ != &::google::protobuf::internal::kEmptyString) {
delete file_name_;
}
if (this != default_instance_) {
}
}
void Response::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Response::descriptor() {
protobuf_AssignDescriptorsOnce();
return Response_descriptor_;
}
const Response& Response::default_instance() {
if (default_instance_ == NULL) protobuf_AddDesc_Response_2eproto();
return *default_instance_;
}
Response* Response::default_instance_ = NULL;
Response* Response::New() const {
return new Response;
}
void Response::Clear() {
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
state_ = 0;
if (has_status()) {
if (status_ != &::google::protobuf::internal::kEmptyString) {
status_->clear();
}
}
if (has_file_path()) {
if (file_path_ != &::google::protobuf::internal::kEmptyString) {
file_path_->clear();
}
}
file_version_ = 0;
if (has_file_name()) {
if (file_name_ != &::google::protobuf::internal::kEmptyString) {
file_name_->clear();
}
}
file_size_ = GOOGLE_ULONGLONG(0);
}
::memset(_has_bits_, 0, sizeof(_has_bits_));
mutable_unknown_fields()->Clear();
}
bool Response::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
::google::protobuf::uint32 tag;
while ((tag = input->ReadTag()) != 0) {
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// required .DataImporter_ns.Response.State state = 1;
case 1: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
input, &value)));
if (::DataImporter_ns::Response_State_IsValid(value)) {
set_state(static_cast< ::DataImporter_ns::Response_State >(value));
} else {
mutable_unknown_fields()->AddVarint(1, value);
}
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(18)) goto parse_status;
break;
}
// required string status = 2;
case 2: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_status:
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_status()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->status().data(), this->status().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(26)) goto parse_file_path;
break;
}
// optional string file_path = 3;
case 3: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_file_path:
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_file_path()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_path().data(), this->file_path().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(32)) goto parse_file_version;
break;
}
// optional int32 file_version = 4;
case 4: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
parse_file_version:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &file_version_)));
set_has_file_version();
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(42)) goto parse_file_name;
break;
}
// optional string file_name = 5;
case 5: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_file_name:
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_file_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_name().data(), this->file_name().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(48)) goto parse_file_size;
break;
}
// optional uint64 file_size = 6;
case 6: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
parse_file_size:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
input, &file_size_)));
set_has_file_size();
} else {
goto handle_uninterpreted;
}
if (input->ExpectAtEnd()) return true;
break;
}
default: {
handle_uninterpreted:
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
return true;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, mutable_unknown_fields()));
break;
}
}
}
return true;
#undef DO_
}
void Response::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// required .DataImporter_ns.Response.State state = 1;
if (has_state()) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
1, this->state(), output);
}
// required string status = 2;
if (has_status()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->status().data(), this->status().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
2, this->status(), output);
}
// optional string file_path = 3;
if (has_file_path()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_path().data(), this->file_path().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
3, this->file_path(), output);
}
// optional int32 file_version = 4;
if (has_file_version()) {
::google::protobuf::internal::WireFormatLite::WriteInt32(4, this->file_version(), output);
}
// optional string file_name = 5;
if (has_file_name()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_name().data(), this->file_name().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
5, this->file_name(), output);
}
// optional uint64 file_size = 6;
if (has_file_size()) {
::google::protobuf::internal::WireFormatLite::WriteUInt64(6, this->file_size(), output);
}
if (!unknown_fields().empty()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
unknown_fields(), output);
}
}
::google::protobuf::uint8* Response::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
// required .DataImporter_ns.Response.State state = 1;
if (has_state()) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
1, this->state(), target);
}
// required string status = 2;
if (has_status()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->status().data(), this->status().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
2, this->status(), target);
}
// optional string file_path = 3;
if (has_file_path()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_path().data(), this->file_path().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
3, this->file_path(), target);
}
// optional int32 file_version = 4;
if (has_file_version()) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(4, this->file_version(), target);
}
// optional string file_name = 5;
if (has_file_name()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->file_name().data(), this->file_name().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
5, this->file_name(), target);
}
// optional uint64 file_size = 6;
if (has_file_size()) {
target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(6, this->file_size(), target);
}
if (!unknown_fields().empty()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
unknown_fields(), target);
}
return target;
}
int Response::ByteSize() const {
int total_size = 0;
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
// required .DataImporter_ns.Response.State state = 1;
if (has_state()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->state());
}
// required string status = 2;
if (has_status()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->status());
}
// optional string file_path = 3;
if (has_file_path()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->file_path());
}
// optional int32 file_version = 4;
if (has_file_version()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
this->file_version());
}
// optional string file_name = 5;
if (has_file_name()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->file_name());
}
// optional uint64 file_size = 6;
if (has_file_size()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::UInt64Size(
this->file_size());
}
}
if (!unknown_fields().empty()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size;
}
void Response::MergeFrom(const ::google::protobuf::Message& from) {
GOOGLE_CHECK_NE(&from, this);
const Response* source =
::google::protobuf::internal::dynamic_cast_if_available(
&from);
if (source == NULL) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
MergeFrom(*source);
}
}
void Response::MergeFrom(const Response& from) {
GOOGLE_CHECK_NE(&from, this);
if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (from.has_state()) {
set_state(from.state());
}
if (from.has_status()) {
set_status(from.status());
}
if (from.has_file_path()) {
set_file_path(from.file_path());
}
if (from.has_file_version()) {
set_file_version(from.file_version());
}
if (from.has_file_name()) {
set_file_name(from.file_name());
}
if (from.has_file_size()) {
set_file_size(from.file_size());
}
}
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
void Response::CopyFrom(const ::google::protobuf::Message& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
void Response::CopyFrom(const Response& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool Response::IsInitialized() const {
if ((_has_bits_[0] & 0x00000003) != 0x00000003) return false;
return true;
}
void Response::Swap(Response* other) {
if (other != this) {
std::swap(state_, other->state_);
std::swap(status_, other->status_);
std::swap(file_path_, other->file_path_);
std::swap(file_version_, other->file_version_);
std::swap(file_name_, other->file_name_);
std::swap(file_size_, other->file_size_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_unknown_fields_.Swap(&other->_unknown_fields_);
std::swap(_cached_size_, other->_cached_size_);
}
}
::google::protobuf::Metadata Response::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = Response_descriptor_;
metadata.reflection = Response_reflection_;
return metadata;
}
// @@protoc_insertion_point(namespace_scope)
} // namespace DataImporter_ns
// @@protoc_insertion_point(global_scope)
data_importer-master/src/Response.pb.h 0000664 0000000 0000000 00000041757 14145762224 0020364 0 ustar 00root root 0000000 0000000 // Generated by the protocol buffer compiler. DO NOT EDIT!
// source: Response.proto
#ifndef PROTOBUF_Response_2eproto__INCLUDED
#define PROTOBUF_Response_2eproto__INCLUDED
#include
#include
#if GOOGLE_PROTOBUF_VERSION < 2005000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 2005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
#include
#include
#include
#include
#include
#include
// @@protoc_insertion_point(includes)
namespace DataImporter_ns {
// Internal implementation detail -- do not call these.
void protobuf_AddDesc_Response_2eproto();
void protobuf_AssignDesc_Response_2eproto();
void protobuf_ShutdownFile_Response_2eproto();
class Response;
enum Response_State {
Response_State_REQUEST_ACCEPTED = 0,
Response_State_ACCESS_DENY = 1,
Response_State_TABLE_NOT_EXPORTED = 2,
Response_State_METADATA_NOT_FOUND = 3,
Response_State_FILE_NOT_DOWNLOADED = 4,
Response_State_FILE_NOT_FOUND = 5,
Response_State_GENERIC_ERROR = 6
};
bool Response_State_IsValid(int value);
const Response_State Response_State_State_MIN = Response_State_REQUEST_ACCEPTED;
const Response_State Response_State_State_MAX = Response_State_GENERIC_ERROR;
const int Response_State_State_ARRAYSIZE = Response_State_State_MAX + 1;
const ::google::protobuf::EnumDescriptor* Response_State_descriptor();
inline const ::std::string& Response_State_Name(Response_State value) {
return ::google::protobuf::internal::NameOfEnum(
Response_State_descriptor(), value);
}
inline bool Response_State_Parse(
const ::std::string& name, Response_State* value) {
return ::google::protobuf::internal::ParseNamedEnum(
Response_State_descriptor(), name, value);
}
// ===================================================================
class Response : public ::google::protobuf::Message {
public:
Response();
virtual ~Response();
Response(const Response& from);
inline Response& operator=(const Response& from) {
CopyFrom(from);
return *this;
}
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _unknown_fields_;
}
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const ::google::protobuf::Descriptor* descriptor();
static const Response& default_instance();
void Swap(Response* other);
// implements Message ----------------------------------------------
Response* New() const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const Response& from);
void MergeFrom(const Response& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
typedef Response_State State;
static const State REQUEST_ACCEPTED = Response_State_REQUEST_ACCEPTED;
static const State ACCESS_DENY = Response_State_ACCESS_DENY;
static const State TABLE_NOT_EXPORTED = Response_State_TABLE_NOT_EXPORTED;
static const State METADATA_NOT_FOUND = Response_State_METADATA_NOT_FOUND;
static const State FILE_NOT_DOWNLOADED = Response_State_FILE_NOT_DOWNLOADED;
static const State FILE_NOT_FOUND = Response_State_FILE_NOT_FOUND;
static const State GENERIC_ERROR = Response_State_GENERIC_ERROR;
static inline bool State_IsValid(int value) {
return Response_State_IsValid(value);
}
static const State State_MIN =
Response_State_State_MIN;
static const State State_MAX =
Response_State_State_MAX;
static const int State_ARRAYSIZE =
Response_State_State_ARRAYSIZE;
static inline const ::google::protobuf::EnumDescriptor*
State_descriptor() {
return Response_State_descriptor();
}
static inline const ::std::string& State_Name(State value) {
return Response_State_Name(value);
}
static inline bool State_Parse(const ::std::string& name,
State* value) {
return Response_State_Parse(name, value);
}
// accessors -------------------------------------------------------
// required .DataImporter_ns.Response.State state = 1;
inline bool has_state() const;
inline void clear_state();
static const int kStateFieldNumber = 1;
inline ::DataImporter_ns::Response_State state() const;
inline void set_state(::DataImporter_ns::Response_State value);
// required string status = 2;
inline bool has_status() const;
inline void clear_status();
static const int kStatusFieldNumber = 2;
inline const ::std::string& status() const;
inline void set_status(const ::std::string& value);
inline void set_status(const char* value);
inline void set_status(const char* value, size_t size);
inline ::std::string* mutable_status();
inline ::std::string* release_status();
inline void set_allocated_status(::std::string* status);
// optional string file_path = 3;
inline bool has_file_path() const;
inline void clear_file_path();
static const int kFilePathFieldNumber = 3;
inline const ::std::string& file_path() const;
inline void set_file_path(const ::std::string& value);
inline void set_file_path(const char* value);
inline void set_file_path(const char* value, size_t size);
inline ::std::string* mutable_file_path();
inline ::std::string* release_file_path();
inline void set_allocated_file_path(::std::string* file_path);
// optional int32 file_version = 4;
inline bool has_file_version() const;
inline void clear_file_version();
static const int kFileVersionFieldNumber = 4;
inline ::google::protobuf::int32 file_version() const;
inline void set_file_version(::google::protobuf::int32 value);
// optional string file_name = 5;
inline bool has_file_name() const;
inline void clear_file_name();
static const int kFileNameFieldNumber = 5;
inline const ::std::string& file_name() const;
inline void set_file_name(const ::std::string& value);
inline void set_file_name(const char* value);
inline void set_file_name(const char* value, size_t size);
inline ::std::string* mutable_file_name();
inline ::std::string* release_file_name();
inline void set_allocated_file_name(::std::string* file_name);
// optional uint64 file_size = 6;
inline bool has_file_size() const;
inline void clear_file_size();
static const int kFileSizeFieldNumber = 6;
inline ::google::protobuf::uint64 file_size() const;
inline void set_file_size(::google::protobuf::uint64 value);
// @@protoc_insertion_point(class_scope:DataImporter_ns.Response)
private:
inline void set_has_state();
inline void clear_has_state();
inline void set_has_status();
inline void clear_has_status();
inline void set_has_file_path();
inline void clear_has_file_path();
inline void set_has_file_version();
inline void clear_has_file_version();
inline void set_has_file_name();
inline void clear_has_file_name();
inline void set_has_file_size();
inline void clear_has_file_size();
::google::protobuf::UnknownFieldSet _unknown_fields_;
::std::string* status_;
int state_;
::google::protobuf::int32 file_version_;
::std::string* file_path_;
::std::string* file_name_;
::google::protobuf::uint64 file_size_;
mutable int _cached_size_;
::google::protobuf::uint32 _has_bits_[(6 + 31) / 32];
friend void protobuf_AddDesc_Response_2eproto();
friend void protobuf_AssignDesc_Response_2eproto();
friend void protobuf_ShutdownFile_Response_2eproto();
void InitAsDefaultInstance();
static Response* default_instance_;
};
// ===================================================================
// ===================================================================
// Response
// required .DataImporter_ns.Response.State state = 1;
inline bool Response::has_state() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void Response::set_has_state() {
_has_bits_[0] |= 0x00000001u;
}
inline void Response::clear_has_state() {
_has_bits_[0] &= ~0x00000001u;
}
inline void Response::clear_state() {
state_ = 0;
clear_has_state();
}
inline ::DataImporter_ns::Response_State Response::state() const {
return static_cast< ::DataImporter_ns::Response_State >(state_);
}
inline void Response::set_state(::DataImporter_ns::Response_State value) {
assert(::DataImporter_ns::Response_State_IsValid(value));
set_has_state();
state_ = value;
}
// required string status = 2;
inline bool Response::has_status() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void Response::set_has_status() {
_has_bits_[0] |= 0x00000002u;
}
inline void Response::clear_has_status() {
_has_bits_[0] &= ~0x00000002u;
}
inline void Response::clear_status() {
if (status_ != &::google::protobuf::internal::kEmptyString) {
status_->clear();
}
clear_has_status();
}
inline const ::std::string& Response::status() const {
return *status_;
}
inline void Response::set_status(const ::std::string& value) {
set_has_status();
if (status_ == &::google::protobuf::internal::kEmptyString) {
status_ = new ::std::string;
}
status_->assign(value);
}
inline void Response::set_status(const char* value) {
set_has_status();
if (status_ == &::google::protobuf::internal::kEmptyString) {
status_ = new ::std::string;
}
status_->assign(value);
}
inline void Response::set_status(const char* value, size_t size) {
set_has_status();
if (status_ == &::google::protobuf::internal::kEmptyString) {
status_ = new ::std::string;
}
status_->assign(reinterpret_cast(value), size);
}
inline ::std::string* Response::mutable_status() {
set_has_status();
if (status_ == &::google::protobuf::internal::kEmptyString) {
status_ = new ::std::string;
}
return status_;
}
inline ::std::string* Response::release_status() {
clear_has_status();
if (status_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = status_;
status_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
inline void Response::set_allocated_status(::std::string* status) {
if (status_ != &::google::protobuf::internal::kEmptyString) {
delete status_;
}
if (status) {
set_has_status();
status_ = status;
} else {
clear_has_status();
status_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
}
}
// optional string file_path = 3;
inline bool Response::has_file_path() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void Response::set_has_file_path() {
_has_bits_[0] |= 0x00000004u;
}
inline void Response::clear_has_file_path() {
_has_bits_[0] &= ~0x00000004u;
}
inline void Response::clear_file_path() {
if (file_path_ != &::google::protobuf::internal::kEmptyString) {
file_path_->clear();
}
clear_has_file_path();
}
inline const ::std::string& Response::file_path() const {
return *file_path_;
}
inline void Response::set_file_path(const ::std::string& value) {
set_has_file_path();
if (file_path_ == &::google::protobuf::internal::kEmptyString) {
file_path_ = new ::std::string;
}
file_path_->assign(value);
}
inline void Response::set_file_path(const char* value) {
set_has_file_path();
if (file_path_ == &::google::protobuf::internal::kEmptyString) {
file_path_ = new ::std::string;
}
file_path_->assign(value);
}
inline void Response::set_file_path(const char* value, size_t size) {
set_has_file_path();
if (file_path_ == &::google::protobuf::internal::kEmptyString) {
file_path_ = new ::std::string;
}
file_path_->assign(reinterpret_cast(value), size);
}
inline ::std::string* Response::mutable_file_path() {
set_has_file_path();
if (file_path_ == &::google::protobuf::internal::kEmptyString) {
file_path_ = new ::std::string;
}
return file_path_;
}
inline ::std::string* Response::release_file_path() {
clear_has_file_path();
if (file_path_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = file_path_;
file_path_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
inline void Response::set_allocated_file_path(::std::string* file_path) {
if (file_path_ != &::google::protobuf::internal::kEmptyString) {
delete file_path_;
}
if (file_path) {
set_has_file_path();
file_path_ = file_path;
} else {
clear_has_file_path();
file_path_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
}
}
// optional int32 file_version = 4;
inline bool Response::has_file_version() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void Response::set_has_file_version() {
_has_bits_[0] |= 0x00000008u;
}
inline void Response::clear_has_file_version() {
_has_bits_[0] &= ~0x00000008u;
}
inline void Response::clear_file_version() {
file_version_ = 0;
clear_has_file_version();
}
inline ::google::protobuf::int32 Response::file_version() const {
return file_version_;
}
inline void Response::set_file_version(::google::protobuf::int32 value) {
set_has_file_version();
file_version_ = value;
}
// optional string file_name = 5;
inline bool Response::has_file_name() const {
return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void Response::set_has_file_name() {
_has_bits_[0] |= 0x00000010u;
}
inline void Response::clear_has_file_name() {
_has_bits_[0] &= ~0x00000010u;
}
inline void Response::clear_file_name() {
if (file_name_ != &::google::protobuf::internal::kEmptyString) {
file_name_->clear();
}
clear_has_file_name();
}
inline const ::std::string& Response::file_name() const {
return *file_name_;
}
inline void Response::set_file_name(const ::std::string& value) {
set_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
file_name_ = new ::std::string;
}
file_name_->assign(value);
}
inline void Response::set_file_name(const char* value) {
set_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
file_name_ = new ::std::string;
}
file_name_->assign(value);
}
inline void Response::set_file_name(const char* value, size_t size) {
set_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
file_name_ = new ::std::string;
}
file_name_->assign(reinterpret_cast(value), size);
}
inline ::std::string* Response::mutable_file_name() {
set_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
file_name_ = new ::std::string;
}
return file_name_;
}
inline ::std::string* Response::release_file_name() {
clear_has_file_name();
if (file_name_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = file_name_;
file_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
inline void Response::set_allocated_file_name(::std::string* file_name) {
if (file_name_ != &::google::protobuf::internal::kEmptyString) {
delete file_name_;
}
if (file_name) {
set_has_file_name();
file_name_ = file_name;
} else {
clear_has_file_name();
file_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
}
}
// optional uint64 file_size = 6;
inline bool Response::has_file_size() const {
return (_has_bits_[0] & 0x00000020u) != 0;
}
inline void Response::set_has_file_size() {
_has_bits_[0] |= 0x00000020u;
}
inline void Response::clear_has_file_size() {
_has_bits_[0] &= ~0x00000020u;
}
inline void Response::clear_file_size() {
file_size_ = GOOGLE_ULONGLONG(0);
clear_has_file_size();
}
inline ::google::protobuf::uint64 Response::file_size() const {
return file_size_;
}
inline void Response::set_file_size(::google::protobuf::uint64 value) {
set_has_file_size();
file_size_ = value;
}
// @@protoc_insertion_point(namespace_scope)
} // namespace DataImporter_ns
#ifndef SWIG
namespace google {
namespace protobuf {
template <>
inline const EnumDescriptor* GetEnumDescriptor< ::DataImporter_ns::Response_State>() {
return ::DataImporter_ns::Response_State_descriptor();
}
} // namespace google
} // namespace protobuf
#endif // SWIG
// @@protoc_insertion_point(global_scope)
#endif // PROTOBUF_Response_2eproto__INCLUDED
data_importer-master/src/SSLClient.cpp 0000664 0000000 0000000 00000023773 14145762224 0020317 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
namespace DataImporter_ns
{
//==============================================================================
// SSLClient::SSLClient()
//==============================================================================
SSLClient::SSLClient(DataImporter* dataImporter_p,
Configuration::SP configuration_sp) : Client(dataImporter_p, configuration_sp),
m_sSLContext(boost::asio::ssl::context::sslv23),
m_sSLSocket(m_ioService, m_sSLContext)
{
DEBUG_STREAM << "SSLClient::SSLClient()" << endl;
boost::system::error_code errorCode;
std::string certificateFile = m_configuration_sp->getCertificateFile();
INFO_STREAM << "SSLClient::SSLClient() " << certificateFile << endl;
m_sSLContext.load_verify_file(certificateFile, errorCode);
if(errorCode)
{
stringstream error_stream;
error_stream << "SSLClient::SSLClient() " << errorCode.message() << endl;
throw std::runtime_error(error_stream.str());
}
m_sSLSocket.set_verify_mode(boost::asio::ssl::verify_none);
}
//==============================================================================
// SSLClient::~SSLClient()
//==============================================================================
SSLClient::~SSLClient()
{
DEBUG_STREAM << "SSLClient::~SSLClient()" << endl;
closeConnection();
}
//==============================================================================
// SSLClient::create()
//==============================================================================
Client::SP SSLClient::create(DataImporter* dataImporter_p,
Configuration::SP configuration_sp)
{
Client::SP c_sp(new SSLClient(dataImporter_p, configuration_sp),
SSLClient::Deleter());
return c_sp;
}
//==============================================================================
// SSLClient::startConnect()
//==============================================================================
void SSLClient::startConnect(boost::asio::ip::tcp::resolver::iterator endPointIterator)
{
DEBUG_STREAM << "SSLClient::startConnect()" << endl;
m_resetConnectionTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getTimeout()));
if(endPointIterator != boost::asio::ip::tcp::resolver::iterator())
{
std::stringstream infoStream;
infoStream << "Connecting to " << endPointIterator->endpoint();
INFO_STREAM << "SSLClient::startConnect() " << infoStream.str() << endl;
writeState(Tango::RUNNING);
writeStatus(infoStream.str());
m_sSLSocket.lowest_layer().async_connect(endPointIterator->endpoint(),
boost::bind(&SSLClient::handleConnect, this,
boost::asio::placeholders::error, endPointIterator));
}
else
{
ERROR_STREAM << "SSLClient::startConnect() No more endpoint" << endl;
writeState(Tango::ALARM);
writeStatus("No more endpoint");
}
}
//==============================================================================
// SSLClient::handleConnect()
//==============================================================================
void SSLClient::handleConnect(const boost::system::error_code& errorCode,
boost::asio::ip::tcp::resolver::iterator endPointIterator)
{
DEBUG_STREAM << "SSLClient::handleConnect()" << endl;
if(!errorCode)
{
startHandShake();
}
else
{
ERROR_STREAM << "SSLClient::handleConnect() " << errorCode.message() << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
if(m_sSLSocket.lowest_layer().is_open())
m_sSLSocket.lowest_layer().close();
startConnect(++endPointIterator);
}
}
//==============================================================================
// SSLClient::startHandShake()
//==============================================================================
void SSLClient::startHandShake()
{
DEBUG_STREAM << "SSLClient::startHandShake()" << endl;
m_resetConnectionTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getTimeout()));
m_sSLSocket.async_handshake(boost::asio::ssl::stream_base::client,
boost::bind(&SSLClient::handleHandShake, this,
boost::asio::placeholders::error));
}
//==============================================================================
// SSLClient::handleHandShake()
//==============================================================================
void SSLClient::handleHandShake(const boost::system::error_code& errorCode)
{
DEBUG_STREAM << "SSLClient::handleHandShake()" << endl;
if(!errorCode)
{
m_remoteEndpoint = boost::lexical_cast(
m_sSLSocket.lowest_layer().remote_endpoint());
std::stringstream infoStream;
infoStream << "Connected to " << m_remoteEndpoint;
INFO_STREAM << "SSLClient::handleHandShake() " << infoStream.str() << endl;
writeState(Tango::RUNNING);
writeStatus(infoStream.str());
m_protocolManager_sp->setRemoteEndpoint(m_remoteEndpoint);
startWriteRequest();
}
else
{
ERROR_STREAM << "SSLClient::handleHandShake() " << errorCode.message() << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
}
}
//==============================================================================
// SSLClient::startWriteRequest()
//==============================================================================
void SSLClient::startWriteRequest()
{
DEBUG_STREAM << "SSLClient::startWriteRequest()" << endl;
try
{
RequestSP request_sp = m_protocolManager_sp->createtRequest();
boost::uint32_t bodySize = request_sp->ByteSize();
#ifdef VERBOSE_DEBUG
INFO_STREAM << "SSLClient::startWriteRequest() "
<< m_remoteEndpoint << " <<<< " << bodySize << " byte" << endl;
#endif
std::vector writeBuff;
writeBuff.resize(HEADER_SIZE + bodySize);
encodeHeader(writeBuff, bodySize);
request_sp->SerializeToArray(&writeBuff[HEADER_SIZE], bodySize);
m_resetConnectionTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getTimeout()));
boost::asio::async_write(m_sSLSocket, boost::asio::buffer(writeBuff),
boost::bind(&SSLClient::handleWriteRequest, this,
boost::asio::placeholders::error));
}
catch(std::exception& ec)
{
ERROR_STREAM << "SSLClient::startWriteRequest() " << ec.what() << endl;
writeState(Tango::ALARM);
writeStatus(ec.what());
}
catch(...)
{
ERROR_STREAM << "SSLClient::startWriteRequest() unknown error" << endl;
writeState(Tango::ALARM);
writeStatus("Unknown error");
}
}
//==============================================================================
// SSLClient::startReadResponseHeader()
//==============================================================================
void SSLClient::startReadResponseHeader()
{
DEBUG_STREAM << "SSLClient::startReadResponseHeader()" << endl;
m_readBuff.resize(HEADER_SIZE);
m_resetConnectionTimer.expires_from_now(
boost::posix_time::seconds(m_configuration_sp->getTimeout()));
boost::asio::async_read(m_sSLSocket, boost::asio::buffer(m_readBuff),
boost::bind(&SSLClient::handleReadResponseHeader, this,
boost::asio::placeholders::error));
}
//==============================================================================
// SSLClient::startReadResponseBody()
//==============================================================================
void SSLClient::startReadResponseBody(boost::uint32_t bodySize)
{
DEBUG_STREAM << "SSLClient::startReadResponseBody()" << endl;
#ifdef VERBOSE_DEBUG
INFO_STREAM << "SSLClient::startReadResponseBody() "
<< m_remoteEndpoint << " >>>> " << bodySize << " byte" << endl;
#endif
m_readBuff.resize(HEADER_SIZE + bodySize);
boost::asio::mutable_buffers_1 mutableBuffer =
boost::asio::buffer(&m_readBuff[HEADER_SIZE], bodySize);
boost::asio::async_read(m_sSLSocket, mutableBuffer,
boost::bind(&SSLClient::handleReadResponseBody, this,
boost::asio::placeholders::error));
}
//==============================================================================
// SSLClient::startReadData()
//==============================================================================
void SSLClient::startReadData(FileWrapper::SP fileWrapper_sp)
{
boost::uint64_t leftToWrite = fileWrapper_sp->getLeftToWrite();
boost::uint64_t bufferSize = 0;
if(leftToWritegetTimeout()));
boost::asio::async_read(m_sSLSocket, boost::asio::buffer(m_fileBuff),
boost::bind(&SSLClient::handleReadData, this, fileWrapper_sp,
boost::asio::placeholders::bytes_transferred,
boost::asio::placeholders::error));
}
//==============================================================================
// SSLClient::closeConnection()
//==============================================================================
void SSLClient::closeConnection()
{
DEBUG_STREAM << "SSLClient::closeConnection()" << endl;
std::stringstream infoStream;
infoStream << "Disconnected from " << m_remoteEndpoint;
INFO_STREAM << "SSLClient::closeConnection() " << infoStream.str() << endl;
m_listsUpdateTimer.expires_at(boost::posix_time::pos_infin);
m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin);
boost::system::error_code errorCode;
m_sSLSocket.lowest_layer().shutdown(
boost::asio::ip::tcp::socket::shutdown_both, errorCode);
m_sSLSocket.lowest_layer().close(errorCode);
}
} //namespace
data_importer-master/src/SSLClient.h 0000664 0000000 0000000 00000005142 14145762224 0017752 0 ustar 00root root 0000000 0000000 #ifndef SSLCLIENT_H
#define SSLCLIENT_H
#include
#include
namespace DataImporter_ns
{
class SSLClient : public Client
{
protected:
//------------------------------------------------------------------------------
// [Protected] Constructor destructor
//------------------------------------------------------------------------------
SSLClient(DataImporter*, Configuration::SP);
virtual ~SSLClient();
class Deleter;
friend class Deleter;
class Deleter
{
public:
void operator()(SSLClient* d) { delete d; }
};
public:
//------------------------------------------------------------------------------
// [Public] Class creation method
//------------------------------------------------------------------------------
static Client::SP create(DataImporter*, Configuration::SP);
protected:
//------------------------------------------------------------------------------
// [Protected] Connection initialization methods
//------------------------------------------------------------------------------
virtual void startConnect(boost::asio::ip::tcp::resolver::iterator);
virtual void handleConnect(const boost::system::error_code&,
boost::asio::ip::tcp::resolver::iterator);
//------------------------------------------------------------------------------
// [Protected] SSL handshake initialization methods
//------------------------------------------------------------------------------
virtual void startHandShake();
virtual void handleHandShake(const boost::system::error_code&);
//------------------------------------------------------------------------------
// [Protected] Request response methods
//------------------------------------------------------------------------------
virtual void startWriteRequest();
virtual void startReadResponseHeader();
virtual void startReadResponseBody(boost::uint32_t);
virtual void startReadData(FileWrapper::SP);
//------------------------------------------------------------------------------
// [Protected] Connection close method
//------------------------------------------------------------------------------
virtual void closeConnection();
//------------------------------------------------------------------------------
// [Protected] Class variables
//------------------------------------------------------------------------------
//SSL connection context
boost::asio::ssl::context m_sSLContext;
//SSL connection socket
boost::asio::ssl::stream m_sSLSocket;
};
} //End of namespace
#endif /* SSLCLIENT_H */
data_importer-master/src/main.cpp 0000664 0000000 0000000 00000004541 14145762224 0017433 0 ustar 00root root 0000000 0000000 /*----- PROTECTED REGION ID(DataImporter::main.cpp) ENABLED START -----*/
//=============================================================================
//
// file : main.cpp
//
// description : C++ source for the DataImporter 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.
//
// 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 .
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include
int main(int argc,char *argv[])
{
try
{
// Initialise the device server
//----------------------------------------
Tango::Util *tg = Tango::Util::init(argc,argv);
// Create the device server singleton
// which will create everything
//----------------------------------------
tg->server_init(false);
// Run the endless loop
//----------------------------------------
cout << "Ready to accept request" << endl;
tg->server_run();
}
catch (bad_alloc &)
{
cout << "Can't allocate memory to store device object !!!" << endl;
cout << "Exiting" << endl;
}
catch (CORBA::Exception &e)
{
Tango::Except::print_exception(e);
cout << "Received a CORBA_Exception" << endl;
cout << "Exiting" << endl;
}
Tango::Util::instance()->server_cleanup();
return(0);
}
/*----- PROTECTED REGION END -----*/ // DataImporter::main.cpp