Commit 7c03e4dd authored by Pavel Vainerman's avatar Pavel Vainerman

make style

parent 9242dc0d
...@@ -539,6 +539,7 @@ int omap() ...@@ -539,6 +539,7 @@ int omap()
{ {
if( !quiet ) if( !quiet )
cerr << "std::exception: " << ex.what() << endl; cerr << "std::exception: " << ex.what() << endl;
return 1; return 1;
} }
...@@ -600,6 +601,7 @@ int setValue( const string& args, UInterface& ui ) ...@@ -600,6 +601,7 @@ int setValue( const string& args, UInterface& ui )
{ {
if( !quiet ) if( !quiet )
cerr << "std::exception: " << ex.what() << endl; cerr << "std::exception: " << ex.what() << endl;
err = 1; err = 1;
} }
} }
...@@ -666,6 +668,7 @@ int getValue( const string& args, UInterface& ui ) ...@@ -666,6 +668,7 @@ int getValue( const string& args, UInterface& ui )
{ {
if( !quiet ) if( !quiet )
cerr << "std::exception: " << ex.what() << endl; cerr << "std::exception: " << ex.what() << endl;
err = 1; err = 1;
} }
} }
...@@ -714,6 +717,7 @@ int getCalibrate( const std::string& args, UInterface& ui ) ...@@ -714,6 +717,7 @@ int getCalibrate( const std::string& args, UInterface& ui )
{ {
if( !quiet ) if( !quiet )
cerr << "std::exception: " << ex.what() << endl; cerr << "std::exception: " << ex.what() << endl;
err = 1; err = 1;
} }
} }
...@@ -758,6 +762,7 @@ int getRawValue( const std::string& args, UInterface& ui ) ...@@ -758,6 +762,7 @@ int getRawValue( const std::string& args, UInterface& ui )
{ {
if( !quiet ) if( !quiet )
cerr << "std::exception: " << ex.what() << endl; cerr << "std::exception: " << ex.what() << endl;
err = 1; err = 1;
} }
} }
...@@ -802,12 +807,14 @@ int getChangedTime( const std::string& args, UInterface& ui ) ...@@ -802,12 +807,14 @@ int getChangedTime( const std::string& args, UInterface& ui )
{ {
if( !quiet ) if( !quiet )
cerr << "CORBA::SystemException: " << ex.NP_minorString() << endl; cerr << "CORBA::SystemException: " << ex.NP_minorString() << endl;
err = 1; err = 1;
} }
catch( const CORBA::Exception& ) catch( const CORBA::Exception& )
{ {
if( !quiet ) if( !quiet )
cerr << "CORBA::Exception." << endl; cerr << "CORBA::Exception." << endl;
err = 1; err = 1;
} }
catch( const omniORB::fatalException& fe ) catch( const omniORB::fatalException& fe )
...@@ -819,20 +826,23 @@ int getChangedTime( const std::string& args, UInterface& ui ) ...@@ -819,20 +826,23 @@ int getChangedTime( const std::string& args, UInterface& ui )
cerr << " line: " << fe.line() << endl; cerr << " line: " << fe.line() << endl;
cerr << " mesg: " << fe.errmsg() << endl; cerr << " mesg: " << fe.errmsg() << endl;
} }
err = 1; err = 1;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
if( !quiet ) if( !quiet )
cerr << "std::exception: " << ex.what() << endl; cerr << "std::exception: " << ex.what() << endl;
err = 1; err = 1;
} }
catch(...) catch(...)
{ {
if( !quiet ) if( !quiet )
cerr << "Unknown exception.." << endl; cerr << "Unknown exception.." << endl;
err = 1; err = 1;
} }
} }
return err; return err;
...@@ -971,7 +981,7 @@ int oinfo( const string& args, UInterface& ui ) ...@@ -971,7 +981,7 @@ int oinfo( const string& args, UInterface& ui )
if( !quiet ) if( !quiet )
cerr << "Unknown exception.." << endl; cerr << "Unknown exception.." << endl;
} }
cout << endl << endl; cout << endl << endl;
} }
......
...@@ -165,7 +165,7 @@ int main( int argc, char** argv ) ...@@ -165,7 +165,7 @@ int main( int argc, char** argv )
case 'n': case 'n':
cmd = cmdCheck; cmd = cmdCheck;
break; break;
case 'e': case 'e':
{ {
...@@ -606,10 +606,10 @@ int main( int argc, char** argv ) ...@@ -606,10 +606,10 @@ int main( int argc, char** argv )
} }
} }
break; break;
case cmdCheck: case cmdCheck:
{ {
bool res = ModbusTCPMaster::checkConnection(iaddr,port,tout); bool res = ModbusTCPMaster::checkConnection(iaddr, port, tout);
cout << iaddr << ":" << port << " connection " << (res ? "OK" : "FAIL") << endl; cout << iaddr << ":" << port << " connection " << (res ? "OK" : "FAIL") << endl;
} }
break; break;
...@@ -676,6 +676,6 @@ char* checkArg( int i, int argc, char* argv[] ) ...@@ -676,6 +676,6 @@ char* checkArg( int i, int argc, char* argv[] )
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
void ping( const std::string& iaddr, int port ) void ping( const std::string& iaddr, int port )
{ {
cerr << "ping2: check connection " << ModbusTCPMaster::checkConnection(iaddr,port,1000) << endl; cerr << "ping2: check connection " << ModbusTCPMaster::checkConnection(iaddr, port, 1000) << endl;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -945,7 +945,7 @@ bool MBExchange::pollRTU( RTUDevice* dev, RegMap::iterator& it ) ...@@ -945,7 +945,7 @@ bool MBExchange::pollRTU( RTUDevice* dev, RegMap::iterator& it )
return false; return false;
} }
if( p->pollfactor>1 && ncycle%p->pollfactor!=0 ) if( p->pollfactor > 1 && ncycle % p->pollfactor != 0 )
return false; return false;
if( mblog->is_level3() ) if( mblog->is_level3() )
...@@ -2090,7 +2090,7 @@ MBExchange::RegInfo* MBExchange::addReg( RegMap& mp, ModbusRTU::RegID id, Modbus ...@@ -2090,7 +2090,7 @@ MBExchange::RegInfo* MBExchange::addReg( RegMap& mp, ModbusRTU::RegID id, Modbus
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
MBExchange::RSProperty* MBExchange::addProp( PList& plist, RSProperty&& p ) MBExchange::RSProperty* MBExchange::addProp( PList& plist, RSProperty&& p )
{ {
for( auto&& it : plist ) for( auto && it : plist )
{ {
if( it.si.id == p.si.id && it.si.node == p.si.node ) if( it.si.id == p.si.id && it.si.node == p.si.node )
return &it; return &it;
...@@ -2184,7 +2184,7 @@ bool MBExchange::initRegInfo( RegInfo* r, UniXML::iterator& it, MBExchange::RTU ...@@ -2184,7 +2184,7 @@ bool MBExchange::initRegInfo( RegInfo* r, UniXML::iterator& it, MBExchange::RTU
{ {
r->dev = dev; r->dev = dev;
r->mbval = IOBase::initIntProp(it, "default", prop_prefix, false); r->mbval = IOBase::initIntProp(it, "default", prop_prefix, false);
r->pollfactor = IOBase::initIntProp(it, "pollfactor", prop_prefix, false,0); r->pollfactor = IOBase::initIntProp(it, "pollfactor", prop_prefix, false, 0);
if( dev->dtype == MBExchange::dtRTU ) if( dev->dtype == MBExchange::dtRTU )
...@@ -2969,7 +2969,7 @@ void MBExchange::sensorInfo( const UniSetTypes::SensorMessage* sm ) ...@@ -2969,7 +2969,7 @@ void MBExchange::sensorInfo( const UniSetTypes::SensorMessage* sm )
if( !isWriteFunction(it.second->mbfunc) ) if( !isWriteFunction(it.second->mbfunc) )
continue; continue;
for( auto&& i : it.second->slst ) for( auto && i : it.second->slst )
{ {
if( sm->id == i.si.id && sm->node == i.si.node ) if( sm->id == i.si.id && sm->node == i.si.node )
{ {
...@@ -3237,7 +3237,8 @@ UniSetTypes::SimpleInfo* MBExchange::getInfo() ...@@ -3237,7 +3237,8 @@ UniSetTypes::SimpleInfo* MBExchange::getInfo()
inf << "LogServer: " << logserv_host << ":" << logserv_port << endl; inf << "LogServer: " << logserv_host << ":" << logserv_port << endl;
inf << "Devices:" << endl; inf << "Devices:" << endl;
for( const auto& it: rmap )
for( const auto& it : rmap )
inf << " " << it.second->getShortInfo() << endl; inf << " " << it.second->getShortInfo() << endl;
i->info = inf.str().c_str(); i->info = inf.str().c_str();
......
...@@ -415,7 +415,7 @@ void MBTCPMultiMaster::initIterators() ...@@ -415,7 +415,7 @@ void MBTCPMultiMaster::initIterators()
{ {
MBExchange::initIterators(); MBExchange::initIterators();
for( auto&& it : mblist ) for( auto && it : mblist )
shm->initIterator(it.respond_it); shm->initIterator(it.respond_it);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -500,9 +500,9 @@ const std::string MBTCPMultiMaster::MBSlaveInfo::getShortInfo() const ...@@ -500,9 +500,9 @@ const std::string MBTCPMultiMaster::MBSlaveInfo::getShortInfo() const
{ {
ostringstream s; ostringstream s;
s << myname << " respond=" << respond s << myname << " respond=" << respond
<< " (respond_id=" << respond_id << " respond_invert=" << respond_invert << " (respond_id=" << respond_id << " respond_invert=" << respond_invert
<< " recv_timeout=" << recv_timeout << " resp_force=" << respond_force << " recv_timeout=" << recv_timeout << " resp_force=" << respond_force
<< " use=" << use << " ignore=" << ignore << " priority=" << priority << ")"; << " use=" << use << " ignore=" << ignore << " priority=" << priority << ")";
return std::move(s.str()); return std::move(s.str());
} }
...@@ -514,7 +514,7 @@ UniSetTypes::SimpleInfo* MBTCPMultiMaster::getInfo() ...@@ -514,7 +514,7 @@ UniSetTypes::SimpleInfo* MBTCPMultiMaster::getInfo()
ostringstream inf; ostringstream inf;
inf << i->info << endl; inf << i->info << endl;
inf << "Gates: " << (checktime<=0 ? "/ check connections DISABLED /" : "") << endl; inf << "Gates: " << (checktime <= 0 ? "/ check connections DISABLED /" : "") << endl;
for( const auto& m : mblist ) for( const auto& m : mblist )
inf << " " << m.getShortInfo() << endl; inf << " " << m.getShortInfo() << endl;
......
...@@ -559,7 +559,7 @@ void MBSlave::execute_rtu() ...@@ -559,7 +559,7 @@ void MBSlave::execute_rtu()
} }
} }
for( auto&& it : iomap ) for( auto && it : iomap )
IOBase::processingThreshold(&it.second, shm, force); IOBase::processingThreshold(&it.second, shm, force);
} }
catch(...) {} catch(...) {}
...@@ -645,7 +645,7 @@ void MBSlave::execute_tcp() ...@@ -645,7 +645,7 @@ void MBSlave::execute_tcp()
} }
} }
for( auto&& it : iomap ) for( auto && it : iomap )
IOBase::processingThreshold(&it.second, shm, force); IOBase::processingThreshold(&it.second, shm, force);
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
......
...@@ -289,7 +289,7 @@ bool SharedMemory::activateObject() ...@@ -289,7 +289,7 @@ bool SharedMemory::activateObject()
itPulsar = myioEnd(); itPulsar = myioEnd();
for( auto&& it : hist ) for( auto && it : hist )
{ {
for( auto && hit : it.hlst ) for( auto && hit : it.hlst )
hit.ioit = myioEnd(); hit.ioit = myioEnd();
...@@ -331,7 +331,7 @@ void SharedMemory::checkHeartBeat() ...@@ -331,7 +331,7 @@ void SharedMemory::checkHeartBeat()
bool wdtpingOK = true; bool wdtpingOK = true;
for( auto&& it : hlist ) for( auto && it : hlist )
{ {
try try
{ {
...@@ -378,7 +378,7 @@ void SharedMemory::checkHeartBeat() ...@@ -378,7 +378,7 @@ void SharedMemory::checkHeartBeat()
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool SharedMemory::readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec ) bool SharedMemory::readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec )
{ {
for( auto&& r : lstRSlot ) for( auto && r : lstRSlot )
{ {
try try
{ {
...@@ -666,7 +666,7 @@ void SharedMemory::buildHistoryList( xmlNode* cnode ) ...@@ -666,7 +666,7 @@ void SharedMemory::buildHistoryList( xmlNode* cnode )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void SharedMemory::checkHistoryFilter( UniXML::iterator& xit ) void SharedMemory::checkHistoryFilter( UniXML::iterator& xit )
{ {
for( auto&& it : hist ) for( auto && it : hist )
{ {
if( xit.getProp(it.filter).empty() ) if( xit.getProp(it.filter).empty() )
continue; continue;
...@@ -701,9 +701,9 @@ void SharedMemory::saveHistory() ...@@ -701,9 +701,9 @@ void SharedMemory::saveHistory()
if( hist.empty() ) if( hist.empty() )
return; return;
for( auto&& it : hist ) for( auto && it : hist )
{ {
for( auto&& hit : it.hlst ) for( auto && hit : it.hlst )
{ {
try try
{ {
...@@ -743,7 +743,7 @@ void SharedMemory::updateHistory( std::shared_ptr<USensorInfo>& s_it, IOControll ...@@ -743,7 +743,7 @@ void SharedMemory::updateHistory( std::shared_ptr<USensorInfo>& s_it, IOControll
<< " value=" << value << " value=" << value
<< endl; << endl;
for( auto&& it1 : i->second ) for( auto && it1 : i->second )
{ {
History::iterator it = it1; History::iterator it = it1;
......
...@@ -745,7 +745,7 @@ void UNetExchange::initIterators() ...@@ -745,7 +745,7 @@ void UNetExchange::initIterators()
if( sender2 ) if( sender2 )
sender2->initIterators(); sender2->initIterators();
for( auto&& it : recvlist ) for( auto && it : recvlist )
it.initIterators(shm); it.initIterators(shm);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -814,7 +814,7 @@ std::shared_ptr<UNetExchange> UNetExchange::init_unetexchange( int argc, const c ...@@ -814,7 +814,7 @@ std::shared_ptr<UNetExchange> UNetExchange::init_unetexchange( int argc, const c
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetExchange::receiverEvent( const shared_ptr<UNetReceiver>& r, UNetReceiver::Event ev ) void UNetExchange::receiverEvent( const shared_ptr<UNetReceiver>& r, UNetReceiver::Event ev )
{ {
for( auto&& it : recvlist ) for( auto && it : recvlist )
{ {
if( it.r1 == r ) if( it.r1 == r )
{ {
......
...@@ -285,7 +285,7 @@ void UNetReceiver::real_update() ...@@ -285,7 +285,7 @@ void UNetReceiver::real_update()
if( sub >= maxDifferens ) if( sub >= maxDifferens )
{ {
// считаем сколько пакетов потеряли.. (pnum=0 - означает что мы только что запустились...) // считаем сколько пакетов потеряли.. (pnum=0 - означает что мы только что запустились...)
if( pnum!=0 && p.num > pnum ) if( pnum != 0 && p.num > pnum )
lostPackets += sub; lostPackets += sub;
} }
} }
......
...@@ -16,7 +16,7 @@ class UTCPStream: ...@@ -16,7 +16,7 @@ class UTCPStream:
void create( const std::string& hname, int port, bool throwflag = false, timeout_t timer = 0 ); void create( const std::string& hname, int port, bool throwflag = false, timeout_t timer = 0 );
// set keepalive params // set keepalive params
void setKeepAliveParams( timeout_t timeout_sec = 5, int conn_keepcnt = 1, int keepintvl=2 ); void setKeepAliveParams( timeout_t timeout_sec = 5, int conn_keepcnt = 1, int keepintvl = 2 );
protected: protected:
......
...@@ -43,7 +43,7 @@ void ModbusTCPMaster::setChannelTimeout( timeout_t msec ) ...@@ -43,7 +43,7 @@ void ModbusTCPMaster::setChannelTimeout( timeout_t msec )
if( tcp ) if( tcp )
{ {
tcp->setTimeout(msec); tcp->setTimeout(msec);
tcp->setKeepAliveParams((msec > 1000 ? msec/1000 : 1)); tcp->setKeepAliveParams((msec > 1000 ? msec / 1000 : 1));
} }
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -309,7 +309,7 @@ bool ModbusTCPMaster::checkConnection( const std::string& ip, int port, int time ...@@ -309,7 +309,7 @@ bool ModbusTCPMaster::checkConnection( const std::string& ip, int port, int time
// Проверяем просто попыткой создать соединение.. // Проверяем просто попыткой создать соединение..
UTCPStream t; UTCPStream t;
t.create(ip, port, true, timeout_msec); t.create(ip, port, true, timeout_msec);
t.setKeepAliveParams( (timeout_msec > 1000 ? timeout_msec/1000 : 1),1,1); t.setKeepAliveParams( (timeout_msec > 1000 ? timeout_msec / 1000 : 1), 1, 1);
t.disconnect(); t.disconnect();
return true; return true;
} }
...@@ -336,7 +336,7 @@ void ModbusTCPMaster::reconnect() ...@@ -336,7 +336,7 @@ void ModbusTCPMaster::reconnect()
tcp = make_shared<UTCPStream>(); tcp = make_shared<UTCPStream>();
tcp->create(iaddr, port, true, 500); tcp->create(iaddr, port, true, 500);
tcp->setTimeout(replyTimeOut_ms); tcp->setTimeout(replyTimeOut_ms);
tcp->setKeepAliveParams((replyTimeOut_ms > 1000 ? replyTimeOut_ms/1000 : 1)); tcp->setKeepAliveParams((replyTimeOut_ms > 1000 ? replyTimeOut_ms / 1000 : 1));
} }
catch( const std::exception& e ) catch( const std::exception& e )
{ {
...@@ -390,7 +390,7 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port ) ...@@ -390,7 +390,7 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
tcp = make_shared<UTCPStream>(); tcp = make_shared<UTCPStream>();
tcp->create(iaddr, port, true, 500); tcp->create(iaddr, port, true, 500);
tcp->setTimeout(replyTimeOut_ms); tcp->setTimeout(replyTimeOut_ms);
tcp->setKeepAliveParams((replyTimeOut_ms > 1000 ? replyTimeOut_ms/1000 : 1)); tcp->setKeepAliveParams((replyTimeOut_ms > 1000 ? replyTimeOut_ms / 1000 : 1));
} }
catch( const std::exception& e ) catch( const std::exception& e )
{ {
......
...@@ -60,7 +60,7 @@ void TCPCheck::check_thread() ...@@ -60,7 +60,7 @@ void TCPCheck::check_thread()
ost::Thread::setException(ost::Thread::throwException); ost::Thread::setException(ost::Thread::throwException);
UTCPStream t; UTCPStream t;
t.create(ip, port, true, tout_msec); t.create(ip, port, true, tout_msec);
t.setKeepAliveParams( (tout_msec > 1000 ? tout_msec/1000 : 1) ); t.setKeepAliveParams( (tout_msec > 1000 ? tout_msec / 1000 : 1) );
setResult(true); setResult(true);
t.disconnect(); t.disconnect();
} }
......
...@@ -27,8 +27,8 @@ void UTCPStream::setKeepAliveParams(timeout_t timeout_sec, int keepcnt, int keep ...@@ -27,8 +27,8 @@ void UTCPStream::setKeepAliveParams(timeout_t timeout_sec, int keepcnt, int keep
{ {
SOCKET fd = TCPStream::so; SOCKET fd = TCPStream::so;
int enable = 1; int enable = 1;
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,(void*)&enable,sizeof(enable)); setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&enable, sizeof(enable));
setsockopt(fd, SOL_TCP, TCP_KEEPCNT, (void *) &keepcnt, sizeof(keepcnt)); setsockopt(fd, SOL_TCP, TCP_KEEPCNT, (void*) &keepcnt, sizeof(keepcnt));
setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, (void*) &keepintvl, sizeof (keepintvl)); setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, (void*) &keepintvl, sizeof (keepintvl));
setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, (void*) &timeout_sec, sizeof (timeout_sec)); setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, (void*) &timeout_sec, sizeof (timeout_sec));
} }
......
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