Commit 5589b01c authored by Pavel Vainerman's avatar Pavel Vainerman

Изменения после проверки cppcheck (performance)

parent f49163bc
......@@ -458,12 +458,12 @@ int omap()
int setValue( const string& args, UInterface &ui, Configuration* conf )
{
int err = 0;
typedef std::list<UniSetTypes::ParamSInfo> SList;
SList sl = UniSetTypes::getSInfoList(args, conf);
cout << "====== setValue ======" << endl;
for( SList::iterator it=sl.begin(); it!=sl.end(); it++ )
{
for( SList::iterator it=sl.begin(); it!=sl.end(); ++it )
{
try
{
UniversalIO::IOType t = conf->getIOType(it->si.id);
......@@ -471,10 +471,10 @@ int setValue( const string& args, UInterface &ui, Configuration* conf )
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();
switch(t)
{
case UniversalIO::DI:
......@@ -494,9 +494,9 @@ int setValue( const string& args, UInterface &ui, Configuration* conf )
{
cerr << "(setValue): " << ex << endl;;
err = 1;
}
}
}
return err;
}
......@@ -504,11 +504,11 @@ int setValue( const string& args, UInterface &ui, Configuration* conf )
int getValue( const string& args, UInterface &ui, Configuration* conf )
{
int err = 0;
typedef std::list<UniSetTypes::ParamSInfo> SList;
SList sl = UniSetTypes::getSInfoList( args, UniSetTypes::conf );
cout << "====== getValue ======" << endl;
for( SList::iterator it=sl.begin(); it!=sl.end(); it++ )
for( SList::iterator it=sl.begin(); it!=sl.end(); ++it )
{
try
{
......@@ -516,10 +516,10 @@ int getValue( const string& args, UInterface &ui, Configuration* conf )
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();
switch(t)
{
case UniversalIO::DO:
......@@ -528,7 +528,7 @@ int getValue( const string& args, UInterface &ui, Configuration* conf )
case UniversalIO::AI:
cout << " value: " << ui.getValue(it->si.id,it->si.node) << endl;
break;
default:
cerr << "FAILED: Unknown 'iotype' for " << it->fname << endl;
err = 1;
......@@ -539,9 +539,9 @@ int getValue( const string& args, UInterface &ui, Configuration* conf )
{
cerr << "(getValue): " << ex << endl;
err = 1;
}
}
}
return err;
}
// --------------------------------------------------------------------------------------
......@@ -551,11 +551,11 @@ int getCalibrate( const std::string& args, UInterface &ui )
typedef std::list<UniSetTypes::ParamSInfo> SList;
SList sl = UniSetTypes::getSInfoList( args, UniSetTypes::conf );
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 )
it->si.node = conf->getLocalNode();
cout << " name: (" << it->si.id << ") " << it->fname << endl;
cout << " text: " << conf->oind->getTextName(it->si.id) << "\n";
try
......@@ -568,9 +568,9 @@ int getCalibrate( const std::string& args, UInterface &ui )
{
cerr << "(getCalibrate): " << ex << endl;;
err = 1;
}
}
}
return err;
}
......@@ -578,14 +578,14 @@ int getCalibrate( const std::string& args, UInterface &ui )
int getRawValue( 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 << "====== 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 )
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
......@@ -596,7 +596,7 @@ int getRawValue( const std::string& args, UInterface &ui )
{
cerr << "(getRawValue): " << ex << endl;;
err = 1;
}
}
}
return err;
}
......@@ -621,7 +621,7 @@ int logRotate( const string& arg, UInterface &ui )
cout << "(logrotate): name='" << arg << "' не найдено!!!\n";
return 1;
}
SystemMessage sm(SystemMessage::LogRotate);
TransportMessage tm(sm.transport_msg());
ui.send(id,tm);
......@@ -655,7 +655,7 @@ int configure( const string& arg, UInterface &ui )
ui.send(id,tm);
cout << "\nSend 'ReConfigure' to " << arg << " OK.\n";
}
return 0;
return 0;
}
// --------------------------------------------------------------------------------------
......@@ -667,7 +667,7 @@ int oinfo( const string& arg, UInterface &ui )
cout << "(oinfo): Не задан OID!"<< endl;
return 1;
}
UniSetTypes::ObjectVar o = ui.resolve(oid);
UniSetObject_i_var obj = UniSetObject_i::_narrow(o);
if(CORBA::is_nil(obj))
......@@ -679,7 +679,7 @@ int oinfo( const string& arg, UInterface &ui )
SimpleInfo_var inf = obj->getInfo();
cout << inf->info << endl;
}
return 0;
}
......
......@@ -270,7 +270,7 @@ int main(int argc, char* argv[])
}
usleep(1000000);
}
return 0;
}
......
......@@ -74,7 +74,7 @@ void RRDServer::initRRD( xmlNode* cnode, int tmID )
throw SystemError(err.str());
}
for(;it_rra.getCurrent(); it_rra++ )
for(;it_rra.getCurrent(); ++it_rra )
{
string rra( it_rra.getProp("rra") );
if( rra.empty() )
......
......@@ -10,7 +10,7 @@ using namespace UniSetTypes;
using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
SMDBServer::SMDBServer( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, SharedMemory* ic,
const string prefix ):
const string& prefix ):
DBServer_MySQL(objId),
prefix(prefix)
{
......@@ -178,7 +178,7 @@ void SMDBServer::help_print( int argc, const char* const* argv )
// -----------------------------------------------------------------------------
SMDBServer* SMDBServer::init_smdbserver( int argc, const char* const* argv,
UniSetTypes::ObjectId icID, SharedMemory* ic,
const std::string prefix )
const std::string& prefix )
{
string name = conf->getArgParam("--" + prefix + "-name","DBServer");
if( name.empty() )
......
......@@ -12,13 +12,13 @@ class SMDBServer:
{
public:
SMDBServer( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, SharedMemory* ic=0,
const std::string prefix="dbserver" );
const std::string& prefix="dbserver" );
virtual ~SMDBServer();
/*! глобальная функция для инициализации объекта */
static SMDBServer* init_smdbserver( int argc, const char* const* argv,
UniSetTypes::ObjectId shmID, SharedMemory* ic=0,
const std::string prefix="dbserver" );
const std::string& prefix="dbserver" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
......
......@@ -1448,7 +1448,7 @@ ModbusRTU::mbErrCode ModbusServer::replyFileTransfer( const std::string &fname,
}
return ModbusRTU::erNoError;
}
}
// -------------------------------------------------------------------------
ModbusRTU::mbErrCode ModbusServer::replySetDateTime( ModbusRTU::SetDateTimeMessage& query,
ModbusRTU::SetDateTimeRetMessage& reply,
......@@ -1462,15 +1462,16 @@ ModbusRTU::mbErrCode ModbusServer::replySetDateTime( ModbusRTU::SetDateTimeMessa
if( gettimeofday(&set,&tz) == 0 )
{
struct tm* t = localtime(&set.tv_sec);
t->tm_sec = query.sec;
t->tm_min = query.min;
t->tm_hour = query.hour;
t->tm_mday = query.day;
t->tm_mon = query.mon-1;
// t->tm_year = (query.century>19) ? query.year + query.century*10 - 1900 : query.year;
t->tm_year = (query.century>19) ? query.year + 2000 - 1900 : query.year;
set.tv_sec = mktime(t);
struct tm t;
localtime_r(&set.tv_sec,&t);
t.tm_sec = query.sec;
t.tm_min = query.min;
t.tm_hour = query.hour;
t.tm_mday = query.day;
t.tm_mon = query.mon-1;
// t.tm_year = (query.century>19) ? query.year + query.century*10 - 1900 : query.year;
t.tm_year = (query.century>19) ? query.year + 2000 - 1900 : query.year;
set.tv_sec = mktime(&t);
set.tv_usec = 0;
if( settimeofday(&set,&tz)==0 )
......
......@@ -385,14 +385,14 @@ const DataBits& DataBits::operator=( const ModbusByte& r )
{
for( unsigned int i=0; i<b.size(); i++ )
b[i] = r&(1<<i);
return (*this);
}
// -------------------------------------------------------------------------
std::ostream& ModbusRTU::operator<<(std::ostream& os, DataBits& d )
{
os << "[";
for( unsigned int i = (int)d.b.size()-1; i>=0; i-- )
for( int i=d.b.size()-1; i>=0; i-- )
os << d.b[i];
os << "]";
......@@ -404,10 +404,10 @@ std::ostream& ModbusRTU::operator<<(std::ostream& os, DataBits* d )
return os << (*d);
}
// -------------------------------------------------------------------------
DataBits16::DataBits16( std::string s ):
DataBits16::DataBits16( const std::string& s ):
b(s)
{
}
// -------------------------------------------------------------------------
DataBits16::DataBits16( ModbusData d )
......@@ -439,16 +439,17 @@ ModbusData DataBits16::mdata()
// -------------------------------------------------------------------------
const DataBits16& DataBits16::operator=( const ModbusData& r )
{
for( unsigned int i=0; i<b.size(); i++ )
const size_t sz = b.size();
for( unsigned int i=0; i<sz; i++ )
b[i] = r&(1<<i);
return (*this);
}
// -------------------------------------------------------------------------
std::ostream& ModbusRTU::operator<<(std::ostream& os, DataBits16& d )
{
os << "[";
for( unsigned int i=(int)d.b.size()-1; i>=0; i-- )
for( int i=d.b.size()-1; i>=0; i-- )
os << d.b[i];
os << "]";
......@@ -478,14 +479,14 @@ void ReadCoilRetMessage::init( ModbusMessage& m )
memset(this,0,sizeof(*this));
addr = m.addr;
func = m.func;
bcnt = m.data[0];
if( bcnt > MAXLENPACKET )
throw mbException(erPacketTooLong);
memcpy(&data,&(m.data[1]),bcnt);
memcpy(&crc,&(m.data[bcnt+1]),szCRC);
}
}
// -------------------------------------------------------------------------
int ReadCoilRetMessage::getDataLen( ModbusMessage& m )
{
......@@ -512,7 +513,7 @@ bool ReadCoilRetMessage::setBit( unsigned char dnum, unsigned char bnum, bool st
data[dnum] = d;
return true;
}
return false;
}
// -------------------------------------------------------------------------
......@@ -520,7 +521,7 @@ bool ReadCoilRetMessage::addData( DataBits d )
{
if( isFull() )
return false;
data[bcnt++] = d.mbyte();
return true;
}
......@@ -532,7 +533,7 @@ bool ReadCoilRetMessage::getData( unsigned char dnum, DataBits& d )
d = data[dnum];
return true;
}
return false;
}
// -------------------------------------------------------------------------
......@@ -551,7 +552,7 @@ ModbusMessage ReadCoilRetMessage::transport_msg()
// копируем заголовок и данные
memcpy(&mm,this,szModbusHeader);
memcpy(&mm.data,&bcnt,sizeof(bcnt));
memcpy(&mm.data,&bcnt,sizeof(bcnt));
int ind = sizeof(bcnt);
// копируем данные
......@@ -570,7 +571,7 @@ ModbusMessage ReadCoilRetMessage::transport_msg()
return mm;
}
// -------------------------------------------------------------------------
int ReadCoilRetMessage::szData()
size_t ReadCoilRetMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(bcnt)+bcnt+szCRC;
......@@ -639,7 +640,7 @@ void ReadInputStatusMessage::init( ModbusMessage& m )
assert( m.func == fnReadInputStatus );
memset(this,0,sizeof(*this));
memcpy(this,&m,sizeof(*this)); // m.len
// переворачиваем слова
start = SWAPSHORT(start);
count = SWAPSHORT(count);
......@@ -678,14 +679,14 @@ void ReadInputStatusRetMessage::init( ModbusMessage& m )
memset(this,0,sizeof(*this));
addr = m.addr;
func = m.func;
bcnt = m.data[0];
if( bcnt > MAXLENPACKET )
throw mbException(erPacketTooLong);
memcpy(&data,&(m.data[1]),bcnt);
memcpy(&crc,&(m.data[bcnt+1]),szCRC);
}
}
// -------------------------------------------------------------------------
int ReadInputStatusRetMessage::getDataLen( ModbusMessage& m )
{
......@@ -770,7 +771,7 @@ ModbusMessage ReadInputStatusRetMessage::transport_msg()
return mm;
}
// -------------------------------------------------------------------------
int ReadInputStatusRetMessage::szData()
size_t ReadInputStatusRetMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(bcnt)+bcnt+szCRC;
......@@ -989,7 +990,7 @@ ModbusMessage ReadOutputRetMessage::transport_msg()
return mm;
}
// -------------------------------------------------------------------------
int ReadOutputRetMessage::szData()
size_t ReadOutputRetMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(bcnt)+count*sizeof(ModbusData)+szCRC;
......@@ -1197,7 +1198,7 @@ ModbusMessage ReadInputRetMessage::transport_msg()
return mm;
}
// -------------------------------------------------------------------------
int ReadInputRetMessage::szData()
size_t ReadInputRetMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(bcnt)+count*sizeof(ModbusData)+szCRC;
......@@ -1370,7 +1371,7 @@ bool ForceCoilsMessage::checkFormat()
return ( func==fnForceMultipleCoils );
}
// -------------------------------------------------------------------------
int ForceCoilsMessage::szData()
size_t ForceCoilsMessage::szData()
{
return szHead()+bcnt+szCRC;
}
......@@ -1617,7 +1618,7 @@ bool WriteOutputMessage::checkFormat()
return ( (bcnt==(quant*sizeof(ModbusData))) && (func==fnWriteOutputRegisters) );
}
// -------------------------------------------------------------------------
int WriteOutputMessage::szData()
size_t WriteOutputMessage::szData()
{
return szHead()+bcnt+szCRC;
}
......@@ -1812,7 +1813,7 @@ bool ForceSingleCoilMessage::checkFormat()
return (func==fnForceSingleCoil);
}
// -------------------------------------------------------------------------
int ForceSingleCoilMessage::szData()
size_t ForceSingleCoilMessage::szData()
{
return szHead()+sizeof(ModbusData)+szCRC;
}
......@@ -1984,7 +1985,7 @@ bool WriteSingleOutputMessage::checkFormat()
return ( (func==fnWriteOutputSingleRegister) );
}
// -------------------------------------------------------------------------
int WriteSingleOutputMessage::szData()
size_t WriteSingleOutputMessage::szData()
{
return szHead()+sizeof(ModbusData)+szCRC;
}
......@@ -2266,7 +2267,7 @@ ModbusMessage DiagnosticMessage::transport_msg()
return mm;
}
// -------------------------------------------------------------------------
int DiagnosticMessage::szData()
size_t DiagnosticMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(subf)+count*sizeof(ModbusData)+szCRC;
......@@ -2595,7 +2596,7 @@ ModbusMessage MEIMessageRetRDI::transport_msg()
return mm;
}
// -------------------------------------------------------------------------
int MEIMessageRetRDI::szData()
size_t MEIMessageRetRDI::szData()
{
// заголовочные поля + фактическое число данных + контрольная сумма
return 6 + bcnt + szCRC;
......@@ -2761,7 +2762,7 @@ ModbusMessage JournalCommandRetMessage::transport_msg()
return mm;
}
// -------------------------------------------------------------------------
int JournalCommandRetMessage::szData()
size_t JournalCommandRetMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(bcnt)+count*sizeof(ModbusData)+szCRC;
......@@ -3097,12 +3098,12 @@ void RemoteServiceMessage::init( ModbusMessage& m )
// copy not include CRC
memcpy(this,&m,szModbusHeader+m.len);
// последний элемент это CRC
memcpy(&crc,&(m.data[m.len-szCRC]),szCRC);
}
// -------------------------------------------------------------------------
int RemoteServiceMessage::szData()
size_t RemoteServiceMessage::szData()
{
return szHead()+bcnt+szCRC;
}
......@@ -3162,7 +3163,7 @@ void RemoteServiceRetMessage::clear()
bcnt = 0;
}
// -------------------------------------------------------------------------
int RemoteServiceRetMessage::szData()
size_t RemoteServiceRetMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(bcnt)+count*sizeof(ModbusByte)+szCRC;
......@@ -3222,10 +3223,10 @@ void ReadFileRecordMessage::init( ModbusMessage& m )
assert( m.func == fnReadFileRecord );
memset(this,0,sizeof(*this));
// copy not include CRC
memcpy(this,&m,szModbusHeader+m.len);
// потом проверяем
if( !checkFormat() )
{
......@@ -3249,7 +3250,7 @@ void ReadFileRecordMessage::init( ModbusMessage& m )
}
}
// -------------------------------------------------------------------------
int ReadFileRecordMessage::szData()
size_t ReadFileRecordMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(bcnt)+count*sizeof(SubRequest)+szCRC;
......@@ -3419,7 +3420,7 @@ int FileTransferRetMessage::getDataLen( ModbusMessage& m )
return m.data[0];
}
// -----------------------------------------------------------------------
int FileTransferRetMessage::szData()
size_t FileTransferRetMessage::szData()
{
// фактическое число данных + контрольная сумма
return sizeof(ModbusByte)*2+sizeof(ModbusData)*3+dlen+szCRC;
......
......@@ -235,12 +235,12 @@ using namespace UniSetTypes;
std::list<UniSetTypes::ParamSInfo> UniSetTypes::getSInfoList( const string& str, Configuration* conf )
{
std::list<UniSetTypes::ParamSInfo> res;
std::list<std::string> l = UniSetTypes::explode_str(str,',');
for( std::list<std::string>::iterator it=l.begin(); it!=l.end(); it++ )
for( std::list<std::string>::iterator it=l.begin(); it!=l.end(); ++it )
{
UniSetTypes::ParamSInfo item;
std::list<std::string> p = UniSetTypes::explode_str((*it),'=');
std::string s = "";
if( p.size() == 1 )
......
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