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