Commit 5a94b914 authored by Pavel Vainerman's avatar Pavel Vainerman

(admin): добавил ключ --verbose (-v) и по умолчанию отключил подробный вывод

логов
parent 8471309a
......@@ -48,6 +48,7 @@ static struct option longopts[] = {
{ "getRawValue", required_argument, 0, 'w' },
{ "getCalibrate", required_argument, 0, 'y' },
{ "oinfo", required_argument, 0, 'p' },
{ "verbose", no_argument, 0, 'v' },
{ NULL, 0, 0, 0 }
};
......@@ -107,17 +108,19 @@ static void usage()
cout << endl;
print_help(36, "-w|--getRawValue id1@node1=val,id2@node2=val2,id3=val3,.. ","Получить 'сырое' значение.\n");
print_help(36, "-y|--getCalibrate id1@node1=val,id2@node2=val2,id3=val3,.. ","Получить параметры калибровки.\n");
print_help(36, "-v|--verbose","Подробный вывод логов.\n");
cout << endl;
}
// --------------------------------------------------------------------------------------
/*!
\todo Сделать по умолчанию режим silent и ключ --verbose.
/*!
\todo Оптимизировать commandToAll, т.к. сейчас НА КАЖДОМ ШАГЕ цикла
создаётся сообщение и происходит преобразование в TransportMessage.
TransportMessage можно создать один раз до цикла.
*/
// --------------------------------------------------------------------------------------
static bool verb = false;
int main(int argc, char** argv)
{
try
......@@ -125,7 +128,7 @@ int main(int argc, char** argv)
int optindex = 0;
char opt = 0;
while( (opt = getopt_long(argc, argv, "hc:beosfur:l:i:x:g:w:y:p:",longopts,&optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hc:beosfur:l:i:x:g:w:y:p:v",longopts,&optindex)) != -1 )
{
switch (opt) //разбираем параметры
{
......@@ -133,6 +136,10 @@ int main(int argc, char** argv)
usage();
return 0;
case 'v':
verb=true;
break;
case 'c': //--confile
conffile = optarg;
break;
......@@ -236,8 +243,9 @@ int main(int argc, char** argv)
commandToAll(conf->getServicesSection(), rep, (Command)cmd);
commandToAll(conf->getControllersSection(), rep, (Command)cmd);
commandToAll(conf->getObjectsSection(), rep, (Command)cmd);
delete rep;
cout<<"(finish): done"<<endl;
delete rep;
if( verb )
cout<<"(finish): done"<<endl;
}
return 0;
......@@ -269,7 +277,7 @@ int main(int argc, char** argv)
commandToAll(conf->getServicesSection(), rep, (Command)cmd);
commandToAll(conf->getControllersSection(), rep, (Command)cmd);
commandToAll(conf->getObjectsSection(), rep, (Command)cmd);
delete rep;
delete rep;
// cout<<"(foldUp): done"<<endl;
}
return 0;
......@@ -287,26 +295,33 @@ int main(int argc, char** argv)
}
catch(Exception& ex)
{
cout <<"admin(main): " << ex << endl;
if( verb )
cout <<"admin(main): " << ex << endl;
}
catch(CORBA::SystemException& ex)
{
cerr << "поймали CORBA::SystemException:" << ex.NP_minorString() << endl;
if( verb )
cerr << "поймали CORBA::SystemException:" << ex.NP_minorString() << endl;
}
catch(CORBA::Exception&)
{
cerr << "поймали CORBA::Exception." << endl;
if( verb )
cerr << "поймали CORBA::Exception." << endl;
}
catch(omniORB::fatalException& fe)
{
cerr << "поймали omniORB::fatalException:" << endl;
cerr << " file: " << fe.file() << endl;
cerr << " line: " << fe.line() << endl;
cerr << " mesg: " << fe.errmsg() << endl;
if( verb )
{
cerr << "поймали omniORB::fatalException:" << endl;
cerr << " file: " << fe.file() << endl;
cerr << " line: " << fe.line() << endl;
cerr << " mesg: " << fe.errmsg() << endl;
}
}
catch(...)
{
cerr << "неизвестное исключение" << endl;
if( verb )
cerr << "неизвестное исключение" << endl;
}
return 1;
......@@ -321,9 +336,10 @@ static bool commandToAll(const string& section, ObjectRepository *rep, Command c
{
ListObjectName ls;
rep->list(section.c_str(),&ls);
if(ls.empty())
if( ls.empty() )
{
cout << "пусто!!!!!!" << endl;
if( verb )
cout << "пусто!!!!!!" << endl;
return false;
}
......@@ -351,7 +367,8 @@ static bool commandToAll(const string& section, ObjectRepository *rep, Command c
if(CORBA::is_nil(obj)) break;
SystemMessage msg(SystemMessage::StartUp);
obj->push( Message::transport(msg) );
cout << setw(55) << ob <<" <--- start OK" << endl;
if( verb )
cout << setw(55) << ob <<" <--- start OK" << endl;
}
break;
......@@ -360,7 +377,8 @@ static bool commandToAll(const string& section, ObjectRepository *rep, Command c
if(CORBA::is_nil(obj)) break;
SystemMessage msg(SystemMessage::FoldUp);
obj->push( Message::transport(msg) );
cout << setw(55) << ob << " <--- foldUp OK" << endl;
if( verb )
cout << setw(55) << ob << " <--- foldUp OK" << endl;
}
break;
......@@ -369,15 +387,16 @@ static bool commandToAll(const string& section, ObjectRepository *rep, Command c
if(CORBA::is_nil(obj)) break;
SystemMessage msg(SystemMessage::Finish);
obj->push( Message::transport(msg) );
cout << setw(55)<< ob << " <--- finish OK" << endl;
if( verb )
cout << setw(55)<< ob << " <--- finish OK" << endl;
}
break;
case Exist:
{
if (obj->exist())
cout << setw(55) << ob << " <--- exist ok\n";
else
if( obj->exist() )
cout << setw(55) << ob << " <--- exist ok\n";
else
cout << setw(55) << ob << " <--- exist NOT OK\n";
}
break;
......@@ -386,7 +405,8 @@ static bool commandToAll(const string& section, ObjectRepository *rep, Command c
{
SystemMessage sm(SystemMessage::ReConfiguration);
obj->push(sm.transport_msg());
cout << setw(55) << ob << " <--- configure ok\n";
if( verb )
cout << setw(55) << ob << " <--- configure ok\n";
}
break;
......@@ -394,24 +414,28 @@ static bool commandToAll(const string& section, ObjectRepository *rep, Command c
{
SystemMessage msg(SystemMessage::LogRotate);
obj->push( Message::transport(msg) );
cout << setw(55) << ob << " <--- logrotate ok\n";
if( verb )
cout << setw(55) << ob << " <--- logrotate ok\n";
break;
}
default:
{
cout << "неизвестная команда -" << cmd << endl;
if( verb )
cout << "неизвестная команда -" << cmd << endl;
return false;
}
}
}
catch(Exception& ex)
{
cout << setw(55) << ob << " <--- " << ex << endl;
if( verb )
cout << setw(55) << ob << " <--- " << ex << endl;
}
catch( CORBA::SystemException& ex )
{
cout << setw(55) << ob << " <--- недоступен!!(CORBA::SystemException): " << ex.NP_minorString() << endl;
if( verb )
cout << setw(55) << ob << " <--- недоступен!!(CORBA::SystemException): " << ex.NP_minorString() << endl;
}
}
}
......@@ -433,7 +457,8 @@ static void createSections( UniSetTypes::Configuration* rconf )
repf.createRootSection(rconf->getObjectsSection());
repf.createRootSection(rconf->getControllersSection());
repf.createRootSection(rconf->getServicesSection());
cout<<"(create): created"<<endl;
if( verb )
cout<<"(create): created"<<endl;
}
// ==============================================================================================
......@@ -448,7 +473,8 @@ int omap()
}
catch( Exception& ex )
{
ucrit << " configuration init failed: " << ex << endl;
if( verb )
ucrit << " configuration init failed: " << ex << endl;
return 1;
}
return 0;
......@@ -461,16 +487,22 @@ int setValue( const string& args, UInterface &ui, Configuration* conf )
typedef std::list<UniSetTypes::ParamSInfo> SList;
SList sl = UniSetTypes::getSInfoList(args, conf);
cout << "====== setValue ======" << endl;
if( verb )
cout << "====== setValue ======" << endl;
for( SList::iterator it=sl.begin(); it!=sl.end(); ++it )
{
try
{
UniversalIO::IOType t = conf->getIOType(it->si.id);
cout << " value: " << it->val << endl;
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " iotype: " << t << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n\n";
if( verb )
{
cout << " value: " << it->val << endl;
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " iotype: " << t << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n\n";
}
if( it->si.node == DefaultObjectId )
it->si.node = conf->getLocalNode();
......@@ -485,14 +517,16 @@ int setValue( const string& args, UInterface &ui, Configuration* conf )
break;
default:
cerr << "FAILED: Unknown 'iotype' for " << it->fname << endl;
if( verb )
cerr << "FAILED: Unknown 'iotype' for " << it->fname << endl;
err = 1;
break;
}
}
catch(Exception& ex)
{
cerr << "(setValue): " << ex << endl;;
if( verb )
cerr << "(setValue): " << ex << endl;;
err = 1;
}
}
......@@ -507,15 +541,21 @@ int getValue( const string& args, UInterface &ui, Configuration* conf )
typedef std::list<UniSetTypes::ParamSInfo> SList;
SList sl = UniSetTypes::getSInfoList( args, UniSetTypes::conf );
cout << "====== getValue ======" << endl;
if( verb )
cout << "====== getValue ======" << endl;
for( SList::iterator it=sl.begin(); it!=sl.end(); ++it )
{
try
{
UniversalIO::IOType t = conf->getIOType(it->si.id);
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " iotype: " << t << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n\n";
if( verb )
{
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " iotype: " << t << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n\n";
}
if( it->si.node == DefaultObjectId )
it->si.node = conf->getLocalNode();
......@@ -526,18 +566,23 @@ int getValue( const string& args, UInterface &ui, Configuration* conf )
case UniversalIO::DI:
case UniversalIO::AO:
case UniversalIO::AI:
cout << " value: " << ui.getValue(it->si.id,it->si.node) << endl;
if( verb )
cout << " value: " << ui.getValue(it->si.id,it->si.node) << endl;
else
cout << ui.getValue(it->si.id,it->si.node);
break;
default:
cerr << "FAILED: Unknown 'iotype' for " << it->fname << endl;
if( verb )
cerr << "FAILED: Unknown 'iotype' for " << it->fname << endl;
err = 1;
break;
}
}
catch(Exception& ex)
{
cerr << "(getValue): " << ex << endl;
if( verb )
cerr << "(getValue): " << ex << endl;
err = 1;
}
}
......@@ -548,25 +593,36 @@ int getValue( const string& args, UInterface &ui, Configuration* conf )
int getCalibrate( const std::string& args, UInterface &ui )
{
int err = 0;
typedef std::list<UniSetTypes::ParamSInfo> SList;
typedef std::list<UniSetTypes::ParamSInfo> SList;
SList sl = UniSetTypes::getSInfoList( args, UniSetTypes::conf );
cout << "====== getCalibrate ======" << endl;
if( verb )
cout << "====== getCalibrate ======" << endl;
for( SList::iterator it=sl.begin(); it!=sl.end(); ++it )
{
if( it->si.node == DefaultObjectId )
it->si.node = conf->getLocalNode();
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n";
try
{
cout << "калибровка: ";
if( verb )
{
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n";
cout << "калибровка: ";
}
IOController_i::CalibrateInfo ci = ui.getCalibrateInfo(it->si);
cout << ci << endl;
if( verb )
cout << ci << endl;
else
cout << ci;
}
catch(Exception& ex)
{
cerr << "(getCalibrate): " << ex << endl;;
if( verb )
cerr << "(getCalibrate): " << ex << endl;;
err = 1;
}
}
......@@ -580,21 +636,28 @@ int getRawValue( const std::string& args, UInterface &ui )
int err = 0;
typedef std::list<UniSetTypes::ParamSInfo> SList;
SList sl = UniSetTypes::getSInfoList( args, UniSetTypes::conf );
cout << "====== getRawValue ======" << endl;
if( verb )
cout << "====== getRawValue ======" << endl;
for( SList::iterator it=sl.begin(); it!=sl.end(); ++it )
{
if( it->si.node == DefaultObjectId )
it->si.node = conf->getLocalNode();
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n\n";
try
{
cout << " value: " << ui.getRawValue(it->si) << endl;
if( verb )
{
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n\n";
cout << " value: " << ui.getRawValue(it->si) << endl;
}
else
cout << ui.getRawValue(it->si);
}
catch(Exception& ex)
{
cerr << "(getRawValue): " << ex << endl;;
if( verb )
cerr << "(getRawValue): " << ex << endl;;
err = 1;
}
}
......@@ -611,21 +674,23 @@ int logRotate( const string& arg, UInterface &ui )
commandToAll(conf->getServicesSection(), rep, (Command)LogRotate);
commandToAll(conf->getControllersSection(), rep, (Command)LogRotate);
commandToAll(conf->getObjectsSection(), rep, (Command)LogRotate);
delete rep;
delete rep;
}
else // посылка определённому объекту
{
UniSetTypes::ObjectId id = conf->oind->getIdByName(arg);
if( id == DefaultObjectId )
{
cout << "(logrotate): name='" << arg << "' не найдено!!!\n";
if( verb )
cout << "(logrotate): name='" << arg << "' не найдено!!!\n";
return 1;
}
TransportMessage tm( std::move(SystemMessage(SystemMessage::LogRotate).transport_msg()) );
ui.send(id,tm);
cout << "\nSend 'LogRotate' to " << arg << " OK.\n";
if( verb )
cout << "\nSend 'LogRotate' to " << arg << " OK.\n";
}
return 0;
}
......@@ -640,20 +705,22 @@ int configure( const string& arg, UInterface &ui )
commandToAll(conf->getServicesSection(), rep, (Command)Configure);
commandToAll(conf->getControllersSection(), rep, (Command)Configure);
commandToAll(conf->getObjectsSection(), rep, (Command)Configure);
delete rep;
delete rep;
}
else // посылка определённому объекту
{
UniSetTypes::ObjectId id = conf->oind->getIdByName(arg);
if( id == DefaultObjectId )
{
cout << "(configure): name='" << arg << "' не найдено!!!\n";
if( verb )
cout << "(configure): name='" << arg << "' не найдено!!!\n";
return 1;
}
TransportMessage tm( std::move( SystemMessage(SystemMessage::ReConfiguration).transport_msg() ));
ui.send(id,tm);
cout << "\nSend 'ReConfigure' to " << arg << " OK.\n";
if( verb )
cout << "\nSend 'ReConfigure' to " << arg << " OK.\n";
}
return 0;
}
......@@ -664,7 +731,8 @@ int oinfo( const string& arg, UInterface &ui )
UniSetTypes::ObjectId oid(uni_atoi(arg));
if( oid==0 )
{
cout << "(oinfo): Не задан OID!"<< endl;
if( verb )
cout << "(oinfo): Не задан OID!"<< endl;
return 1;
}
......@@ -672,7 +740,8 @@ int oinfo( const string& arg, UInterface &ui )
UniSetObject_i_var obj = UniSetObject_i::_narrow(o);
if(CORBA::is_nil(obj))
{
cout << "(oinfo): объект " << oid << " недоступен" << endl;
if( verb )
cout << "(oinfo): объект " << oid << " недоступен" << endl;
}
else
{
......
#!/bin/sh
./uniset2-start.sh -f "./uniset2-admin --confile test.xml --`basename $0 .sh` $1 $2 $3 $4"
./uniset2-start.sh -f "./uniset2-admin --confile test.xml --`basename $0 .sh` $1 $2 $3 $4 $5 $6"
exit $?
Markdown is supported
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