Commit 173d5daa authored by Pavel Vainerman's avatar Pavel Vainerman

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

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