Commit fc5b30e0 authored by Arnaud Le Meillour's avatar Arnaud Le Meillour
Browse files

clean server files

parent 83726a95
Pipeline #58492 passed with stage
in 14 seconds
......@@ -12,6 +12,7 @@ obj/
bin/
build/
.project
.idea
/.metadata/
.settings/
core
......
//=============================================================================
//
// file : MultiClassessFactory.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 :
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <tango.h>
#include <SerialClass.h>
......
//=============================================================================
//
// file : main.cpp
//
// description : C++ source for the VacGaugeServer 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 : null
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <tango.h>
// Check if crash reporting is used.
......@@ -41,34 +10,15 @@
DECLARE_CRASH_HANDLER;
//=============================================================================
void reInitTango();
string threadList(vector<string> devices);
void putProperties(string serverName, vector<string> config);
vector<string> string2vecor(string str);
void configurePollingThreads(string instanceName);
//=============================================================================
//=============================================================================
int main(int argc,char *argv[])
{
INSTALL_CRASH_HANDLER
try
{
// Distribute devices to pool of polling threads
if (argc<=1) {
cerr << "usage : VacGaugeServer instance_name [-v[trace level]]" <<
" [-file=<file_name> | -nodb [-dlist <device name list>] ]" << endl;
exit(0);
}
string instanceName(argv[1]);
configurePollingThreads(instanceName);
reInitTango();
// Initialise the device server
//----------------------------------------
Tango::Util *tg = Tango::Util::init(argc,argv);
// Create the device server singleton
// which will create everything
//----------------------------------------
......@@ -78,7 +28,6 @@ int main(int argc,char *argv[])
//----------------------------------------
cout << "Ready to accept request" << endl;
tg->server_run();
}
catch (bad_alloc &)
{
......@@ -94,137 +43,4 @@ int main(int argc,char *argv[])
}
Tango::Util::instance()->server_cleanup();
return(0);
}
//=============================================================================
//=============================================================================
void reInitTango() {
Tango::ApiUtil *au = Tango::ApiUtil::instance();
size_t nb_db = au->get_db_vect().size();
for (size_t ctr=0 ; ctr<nb_db ; ctr++)
delete au->get_db_vect()[ctr];
au->get_db_vect().clear();
}
//=============================================================================
//=============================================================================
void configurePollingThreads(string instanceName)
{
// Query database for a list of classes and devices instancied by the specified server
setenv("SUPER_TANGO","true", 1);
Tango::Database *dbase = new Tango::Database();
string ds_name("VacGaugeServer/");
ds_name += instanceName;
Tango::DbDatum datum = dbase->get_device_class_list(ds_name);
vector<string> devClasses;
datum >> devClasses;
// sort devices by class type
vector<string> controller_dev;
vector<string> hardware_dev;
vector<string> software_dev;
for (unsigned int i=0 ; i<devClasses.size() ; i+=2) {
string deviceName = devClasses[i];
string className = devClasses[i+1];
//cout << className << " --> " << deviceName << endl;
if (className=="VacGauge") {
software_dev.push_back(deviceName);
}
else
if (className=="BalzersGauge" || className=="VarianDualIP") {
hardware_dev.push_back(deviceName);
}
else
if (className!="Serial" && className!="DServer" && className!="WindowProtocol") {
controller_dev.push_back(deviceName);
}
}
// If no controller, do nothing
if (controller_dev.size()==0) {
delete dbase;
return;
}
cout << controller_dev.size() << " controller devices" << endl;
cout << hardware_dev.size() << " hard devices" << endl;
cout << software_dev.size() << " soft devices" << endl;
// Build polling_threads_pool_conf property
TangoSys_OMemStream tms;
for (unsigned int i=0 ; i<controller_dev.size() ; i++)
tms << controller_dev[i] << endl;
tms << threadList(hardware_dev) << endl
<< threadList(software_dev);
string poolConf(tms.str());
//Convert a string with \n to a vector of strings (used by property)
vector<string> vPoolConf = string2vecor(poolConf);
putProperties(ds_name, vPoolConf);
delete dbase;
//unsetenv("SUPER_TANGO");
}
//=============================================================================
//=============================================================================
void putProperties(string serverName, vector<string> poolConfStr) {
// create a proxy on DServer to put properties
Tango::DeviceProxy *dserver;
try {
string dserverName = "dserver/";
dserverName += serverName;
dserver = new Tango::DeviceProxy(dserverName);
Tango::DbDatum poolConf("polling_threads_pool_conf"); poolConf << poolConfStr;
Tango::DbDatum poolSize("polling_threads_pool_size"); poolSize << (short)(poolConfStr.size()+1);
Tango::DbData dev_prop;
dev_prop.push_back(poolConf);
dev_prop.push_back(poolSize);
dserver->put_property(dev_prop);
}
catch (Tango::DevFailed &e) {
Tango::Except::print_exception(e);
}
delete dserver;
}
//=============================================================================
//=============================================================================
#define NbDevMaxByThread 6
string threadList(vector<string> devices) {
TangoSys_OMemStream tms;
for (unsigned int i=0 ; i<devices.size() ; i++) {
tms << devices[i];
if (i<devices.size()-1) {
if ( (i!=0) &&((i+1)%NbDevMaxByThread)==0)
tms << endl;
else
tms << ",";
}
}
return tms.str();
}
//=============================================================================
/**
* Convert a string with \n to a vector of strings (used by property)
*/
//=============================================================================
vector<string> string2vecor(string str) {
vector<string> v;
string::size_type start = 0;
string::size_type end = 0;
while ((end=str.find('\n', start))!=string::npos) {
string s = str.substr(start, (end-start));
v.push_back(s);
start = end+1; // +1 for \n itself
}
if (start<str.length()) {
string s = str.substr(start);
v.push_back(s);
}
for (unsigned int i=0 ; i<v.size() ; i++)
cout << v[i] << endl;
return v;
}
//=============================================================================
//=============================================================================
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment