Commit edfd4a80 authored by Pavel Vainerman's avatar Pavel Vainerman

(UniSetObject): добавил в вывод getInfo() дату и время.

Мелкий рефакторинг: "const и auto где можно", поправил коментарии,
parent 4ecc9a59
...@@ -429,15 +429,17 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -429,15 +429,17 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
uniset::ios_fmt_restorer ifs(cout); uniset::ios_fmt_restorer ifs(cout);
cout.setf(ios::left, ios::adjustfield);
try try
{ {
ListObjectName ls; ListObjectName olist;
rep->list(section, &ls); rep->list(section, &olist);
if( ls.empty() ) if( olist.empty() )
{ {
if( verb ) if( verb )
cout << "пусто!!!!!!" << endl; cout << "пусто!" << endl;
return false; return false;
} }
...@@ -445,16 +447,10 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -445,16 +447,10 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
UniSetManager_i_var proc; UniSetManager_i_var proc;
UniSetObject_i_var obj; UniSetObject_i_var obj;
string fullName; string fullName;
ListObjectName::const_iterator li;
string buf;
cout.setf(ios::left, ios::adjustfield);
for ( li = ls.begin(); li != ls.end(); ++li) for( const auto& oname: olist )
{ {
string ob(*li); fullName = section + "/" + oname;
buf = section + "/" + ob;
fullName = buf;
try try
{ {
...@@ -467,7 +463,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -467,7 +463,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
{ {
if( CORBA::is_nil(obj) ) if( CORBA::is_nil(obj) )
{ {
errDoNotResolve(ob); errDoNotResolve(oname);
break; break;
} }
...@@ -475,7 +471,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -475,7 +471,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
obj->push( Message::transport(msg) ); obj->push( Message::transport(msg) );
if( verb ) if( verb )
cout << setw(55) << ob << " <--- start OK" << endl; cout << setw(55) << oname << " <--- start OK" << endl;
} }
break; break;
...@@ -483,7 +479,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -483,7 +479,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
{ {
if(CORBA::is_nil(obj)) if(CORBA::is_nil(obj))
{ {
errDoNotResolve(ob); errDoNotResolve(oname);
break; break;
} }
...@@ -491,7 +487,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -491,7 +487,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
obj->push( Message::transport(msg) ); obj->push( Message::transport(msg) );
if( verb ) if( verb )
cout << setw(55) << ob << " <--- foldUp OK" << endl; cout << setw(55) << oname << " <--- foldUp OK" << endl;
} }
break; break;
...@@ -499,7 +495,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -499,7 +495,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
{ {
if(CORBA::is_nil(obj)) if(CORBA::is_nil(obj))
{ {
errDoNotResolve(ob); errDoNotResolve(oname);
break; break;
} }
...@@ -507,16 +503,16 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -507,16 +503,16 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
obj->push( Message::transport(msg) ); obj->push( Message::transport(msg) );
if( verb ) if( verb )
cout << setw(55) << ob << " <--- finish OK" << endl; cout << setw(55) << oname << " <--- finish OK" << endl;
} }
break; break;
case Exist: case Exist:
{ {
if( obj->exist() ) if( obj->exist() )
cout << "(" << setw(6) << obj->getId() << ")" << setw(55) << ob << " <--- exist ok\n"; cout << "(" << setw(6) << obj->getId() << ")" << setw(55) << oname << " <--- exist ok\n";
else else
cout << "(" << setw(6) << obj->getId() << ")" << setw(55) << ob << " <--- exist NOT OK\n"; cout << "(" << setw(6) << obj->getId() << ")" << setw(55) << oname << " <--- exist NOT OK\n";
} }
break; break;
...@@ -526,7 +522,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -526,7 +522,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
obj->push(sm.transport_msg()); obj->push(sm.transport_msg());
if( verb ) if( verb )
cout << setw(55) << ob << " <--- configure ok\n"; cout << setw(55) << oname << " <--- configure ok\n";
} }
break; break;
...@@ -536,7 +532,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -536,7 +532,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
obj->push( Message::transport(msg) ); obj->push( Message::transport(msg) );
if( verb ) if( verb )
cout << setw(55) << ob << " <--- logrotate ok\n"; cout << setw(55) << oname << " <--- logrotate ok\n";
break; break;
} }
...@@ -553,12 +549,12 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -553,12 +549,12 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
if( !quiet ) if( !quiet )
cerr << setw(55) << ob << " <--- " << ex << endl; cerr << setw(55) << oname << " <--- " << ex << endl;
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
if( !quiet ) if( !quiet )
cerr << setw(55) << ob << " <--- недоступен!!(CORBA::SystemException): " << ex.NP_minorString() << endl; cerr << setw(55) << oname << " <--- недоступен!!(CORBA::SystemException): " << ex.NP_minorString() << endl;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
......
...@@ -376,32 +376,36 @@ bool MBTCPMultiMaster::MBSlaveInfo::check() ...@@ -376,32 +376,36 @@ bool MBTCPMultiMaster::MBSlaveInfo::check()
{ {
mbtcp->connect(ip, port, false); mbtcp->connect(ip, port, false);
// результат возврата функции нам не важен
// т.к. если не будет связи будет выкинуто исключение
// если пришёл хоть какой-то ответ, значит связь есть
// (по крайней мере со шлюзом)
switch(checkFunc) switch(checkFunc)
{ {
case ModbusRTU::fnReadCoilStatus: case ModbusRTU::fnReadCoilStatus:
{ {
auto ret = mbtcp->read01(checkAddr, checkReg, 1); (void)mbtcp->read01(checkAddr, checkReg, 1);
return true; return true;
} }
break; break;
case ModbusRTU::fnReadInputStatus: case ModbusRTU::fnReadInputStatus:
{ {
auto ret = mbtcp->read02(checkAddr, checkReg, 1); (void)mbtcp->read02(checkAddr, checkReg, 1);
return true; return true;
} }
break; break;
case ModbusRTU::fnReadOutputRegisters: case ModbusRTU::fnReadOutputRegisters:
{ {
auto ret = mbtcp->read03(checkAddr, checkReg, 1); (void)mbtcp->read03(checkAddr, checkReg, 1);
return true; return true;
} }
break; break;
case ModbusRTU::fnReadInputRegisters: case ModbusRTU::fnReadInputRegisters:
{ {
auto ret = mbtcp->read04(checkAddr, checkReg, 1); (void)mbtcp->read04(checkAddr, checkReg, 1);
return true; return true;
} }
break; break;
......
...@@ -121,7 +121,7 @@ namespace uniset ...@@ -121,7 +121,7 @@ namespace uniset
mutable std::string nsName; mutable std::string nsName;
std::shared_ptr<uniset::Configuration> uconf; std::shared_ptr<uniset::Configuration> uconf;
bool list(const std::string& section, uniset::ListObjectName* ls, unsigned int how_many, ObjectType type) const; bool list(const std::string& section, uniset::ListObjectName* ls, size_t how_many, ObjectType type) const;
/*! Создание нового контекста(секции) */ /*! Создание нового контекста(секции) */
bool createContext( const std::string& cname, CosNaming::NamingContext_ptr ctx); bool createContext( const std::string& cname, CosNaming::NamingContext_ptr ctx);
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
// класс обёртка, понадобился только для того, чтобы достучаться до "сырого" сокета
// и иметь возможность использоватб его с libev
class USocket: class USocket:
public Poco::Net::Socket public Poco::Net::Socket
{ {
......
...@@ -62,8 +62,7 @@ namespace uniset ...@@ -62,8 +62,7 @@ namespace uniset
typedef size_t KeyType; /*!< уникальный ключ объекта */ typedef size_t KeyType; /*!< уникальный ключ объекта */
/*! генератор уникального положительного ключа /*! генератор уникального положительного ключа
* Уникальность гарантируется только для пары значений * Уникальность гарантируется только для пары значений id и node.
* id и node.
* \warning что тут у нас с переполнением.. * \warning что тут у нас с переполнением..
* \warning Уникальность генерируемого ключа еще не проверялась, * \warning Уникальность генерируемого ключа еще не проверялась,
но нареканий по использованию тоже не было :) но нареканий по использованию тоже не было :)
......
...@@ -132,7 +132,7 @@ namespace uniset ...@@ -132,7 +132,7 @@ namespace uniset
*/ */
std::string pretty_str( int namewidth = NameWidth, int colnum = ColCount ); std::string pretty_str( int namewidth = NameWidth, int colnum = ColCount );
// функции добавления.. // перегрузки для стандартных типов..
VMON_DEF_FUNC2(int); VMON_DEF_FUNC2(int);
VMON_DEF_FUNC2(long); VMON_DEF_FUNC2(long);
VMON_DEF_FUNC2(short); VMON_DEF_FUNC2(short);
...@@ -156,6 +156,7 @@ namespace uniset ...@@ -156,6 +156,7 @@ namespace uniset
private: private:
// определения для стандартных типов
VMON_DEF_MAP2(int); VMON_DEF_MAP2(int);
VMON_DEF_MAP2(long); VMON_DEF_MAP2(long);
VMON_DEF_MAP2(short); VMON_DEF_MAP2(short);
......
...@@ -333,13 +333,12 @@ bool ObjectRepository::listSections(const string& in_section, ListObjectName* ls ...@@ -333,13 +333,12 @@ bool ObjectRepository::listSections(const string& in_section, ListObjectName* ls
* \param how_many - максимальное количество заносимых элементов * \param how_many - максимальное количество заносимых элементов
* \param in_section - полное имя секции начиная с Root. * \param in_section - полное имя секции начиная с Root.
* \param type - тип вынимаемых(заносимых в список) объектов. * \param type - тип вынимаемых(заносимых в список) объектов.
* \return Функция возвращает true, если в список были внесены не все элементы. Т.е. действительное * \return Функция возвращает false, если в список были внесены не все элементы. Т.е. действительное
* количество объектов в этой секции превышает заданное how_many. * количество объектов в этой секции превышает заданное how_many.
* \exception ORepFailed - генерируется если произошла при получении доступа к секции * \exception ORepFailed - генерируется если произошла при получении доступа к секции
*/ */
bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned int how_many, ObjectType type) const bool ObjectRepository::list( const string& section, ListObjectName* olist, size_t how_many, ObjectType type ) const
{ {
// Возвращает false если вынут не весь список...
CosNaming::NamingContext_var ctx; CosNaming::NamingContext_var ctx;
try try
...@@ -363,7 +362,7 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned ...@@ -363,7 +362,7 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned
CosNaming::BindingIterator_var bi; CosNaming::BindingIterator_var bi;
ctx->list(how_many, bl, bi); ctx->list(how_many, bl, bi);
// хитрая проверка на null приобращении к bl // хитрая проверка на null при обращении к bl
// coverity говорит потенциально это возможно // coverity говорит потенциально это возможно
// т.к. там возвращается указатель, который по умолчанию null // т.к. там возвращается указатель, который по умолчанию null
if( !bl.operator->() ) if( !bl.operator->() )
...@@ -371,7 +370,7 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned ...@@ -371,7 +370,7 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned
bool res = true; bool res = true;
if(how_many >= bl->length()) if( how_many >= bl->length() )
how_many = bl->length(); how_many = bl->length();
else else
{ {
...@@ -381,14 +380,14 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned ...@@ -381,14 +380,14 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned
// cout << "получили список "<< section << " размером " << bl->length()<< endl; // cout << "получили список "<< section << " размером " << bl->length()<< endl;
for( unsigned int i = 0; i < how_many; i++) for( size_t i = 0; i < how_many; i++ )
{ {
switch( type ) switch( type )
{ {
case ObjectRef: case ObjectRef:
{ {
if(bl[i].binding_type == CosNaming::nobject) if(bl[i].binding_type == CosNaming::nobject)
ls->emplace_front(omniURI::nameToString(bl[i].binding_name)); olist->emplace_front(omniURI::nameToString(bl[i].binding_name));
break; break;
} }
...@@ -396,7 +395,7 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned ...@@ -396,7 +395,7 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned
case Section: case Section:
{ {
if( bl[i].binding_type == CosNaming::ncontext) if( bl[i].binding_type == CosNaming::ncontext)
ls->emplace_front(omniURI::nameToString(bl[i].binding_name)); olist->emplace_front(omniURI::nameToString(bl[i].binding_name));
break; break;
} }
...@@ -565,13 +564,13 @@ bool ObjectRepository::createContext( const string& cname, CosNaming::NamingCont ...@@ -565,13 +564,13 @@ bool ObjectRepository::createContext( const string& cname, CosNaming::NamingCont
*/ */
void ObjectRepository::printSection( const string& fullName ) const void ObjectRepository::printSection( const string& fullName ) const
{ {
ListObjectName ls; ListObjectName olist;
try try
{ {
list(fullName.c_str(), &ls); list(fullName.c_str(), &olist);
if( ls.empty() ) if( olist.empty() )
cout << fullName << " пуст!!!" << endl; cout << fullName << " пуст!!!" << endl;
} }
catch( ORepFailed ) catch( ORepFailed )
...@@ -580,9 +579,9 @@ void ObjectRepository::printSection( const string& fullName ) const ...@@ -580,9 +579,9 @@ void ObjectRepository::printSection( const string& fullName ) const
return ; return ;
} }
cout << fullName << "(" << ls.size() << "):" << endl; cout << fullName << "(" << olist.size() << "):" << endl;
for( auto v : ls ) for( const auto& v: olist )
cout << v << endl; cout << v << endl;
} }
......
...@@ -896,9 +896,12 @@ namespace uniset ...@@ -896,9 +896,12 @@ namespace uniset
{ {
ostringstream info; ostringstream info;
info.setf(ios::left, ios::adjustfield); info.setf(ios::left, ios::adjustfield);
info << "(" << myid << ")" << setw(40) << myname << "\n==================================================\n"; info << "(" << myid << ")" << setw(40) << myname
info << "pid=" << setw(10) << Poco::Process::id(); << " date: " << uniset::dateToString()
info << " tid=" << setw(10); << " time: " << uniset::timeToString()
<< "\n===============================================================================\n"
<< " pid=" << setw(10) << Poco::Process::id()
<< " tid=" << setw(10);
if( threadcreate ) if( threadcreate )
{ {
......
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