diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.cpp index e3269994b8f317c9b070de8650e9f350ce9eb7c9..9315ca27814efd2a7922d0c70e8363913decf421 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.cpp @@ -25,7 +25,7 @@ namespace Silecs { CNVConnection::CNVConnection(PLC* thePLC) : - Connection(thePLC) + Connection{} { LOG(ALLOC) << "CNVConnection (create): " << thePLC->getName(); } diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp index f4d5eb9799180d57cef2963fb5d2cfde4bd431ba..a21bba42ad91cc432af825d6e7599f4c7f3bdb3a 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp @@ -28,7 +28,7 @@ namespace Silecs { MBConnection::MBConnection(PLC *thePLC) : - Connection(thePLC) + Connection{} { LOG(ALLOC) << "MBConnection (create): " << thePLC->getName(); @@ -61,14 +61,14 @@ MBConnection::~MBConnection() modbus_free(readCtx_); } -bool MBConnection::open(PLC *thePLC) +bool MBConnection::open(PLC*) { int readErr = modbus_connect(readCtx_); int writeErr = modbus_connect(writeCtx_); return ( (readErr != -1) && (writeErr != -1)); } -bool MBConnection::close(PLC *thePLC) +bool MBConnection::close(PLC*) { modbus_close(readCtx_); modbus_close(writeCtx_); diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp index c87d078c10fe7e532d463daff4b6681d45b92a6e..35d3ab1175d7dbc33844dc6a1d6476e567b9f87b 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp @@ -24,7 +24,7 @@ namespace Silecs { SNAP7Connection::SNAP7Connection(PLC* thePLC) : - Connection(thePLC) + Connection{} { rackNb_ = 0; //rackNb - common rack is 0 so far slotNb_ = -1; //slotNb - depends on hardware configuration (scan is required the first connect) @@ -97,7 +97,7 @@ bool SNAP7Connection::open(PLC* thePLC) return (ret); } -bool SNAP7Connection::close(PLC* thePLC) +bool SNAP7Connection::close(PLC*) { bool ret = (Cli_Disconnect(recvClient_) == 0) && (Cli_Disconnect(sendClient_) == 0); return ret; diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Utils.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Utils.cpp index 2307cfee72606167ce82097f1a5222b8874c6786..3ccd0ceb38f47e330b6b5445476fe792961866f2 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Utils.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Utils.cpp @@ -9,22 +9,20 @@ // Helper GET routines //============================================================================== -bool GetBitAt(void *Buffer, int Pos, int Bit) +bool GetBitAt(void *Buffer, unsigned long Pos, unsigned long Bit) { byte Mask[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; - if (Bit < 0) Bit = 0; if (Bit > 7) Bit = 7; - return (*(pbyte(Buffer)+Pos) & Mask[Bit]) != 0; + return (*(pbyte(Buffer) + Pos) & Mask[Bit]) != 0; } //============================================================================== // Helper SET routines //============================================================================== -void SetBitAt(void *Buffer, int Pos, int Bit, bool Value) +void SetBitAt(void *Buffer, unsigned long Pos, unsigned long Bit, bool Value) { byte Mask[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; pbyte p = pbyte(Buffer)+Pos; - if (Bit < 0) Bit = 0; if (Bit > 7) Bit = 7; (Value) ? *p |= Mask[Bit] : *p &= ~Mask[Bit]; } diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Utils.h b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Utils.h index e10f10f4ff5f7f56ec1535f7c8f983c76bbe6060..5be3e6eb26f832782935fdeadd5d26bcb8c43d95 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Utils.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Utils.h @@ -6,9 +6,9 @@ // They were no accessible in SNAP7 version 1.4.x //****************************************************************************** // GET -bool GetBitAt(void *Buffer, int Pos, int Bit); +bool GetBitAt(void *Buffer, unsigned long Pos, unsigned long Bit); // SET -void SetBitAt(void *Buffer, int Pos, int Bit, bool Value); +void SetBitAt(void *Buffer, unsigned long Pos, unsigned long Bit, bool Value); diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp index 3e2451ce804588579f43aa6aa952de3a062ddef3..b1f7810c7fb202a7556b9e33d7c1b9978b7b1caa 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp @@ -27,7 +27,7 @@ namespace Silecs bool Connection::isAlive_ = false; //------------------------------------------------------------------------------------------------------------------------------------------------ -Connection::Connection(PLC* thePLC) +Connection::Connection() { // Start the PLC Thread readMux_ = new Mutex("readMux"); @@ -243,25 +243,25 @@ bool Connection::isConnected() } //------------------------------------------------------------------------------------------------------------------- -int Connection::readUnitCode(PLC* thePLC, UnitCodeType& dataStruct) +int Connection::readUnitCode(PLC* thePLC, UnitCodeType&) { throw SilecsException(__FILE__, __LINE__, DIAG_PLC_REPORT_NOT_SUPPORTED, thePLC->getName()); return -1; } -int Connection::readUnitStatus(PLC* thePLC, UnitStatusType& dataStruct) +int Connection::readUnitStatus(PLC* thePLC, UnitStatusType&) { throw SilecsException(__FILE__, __LINE__, DIAG_PLC_REPORT_NOT_SUPPORTED, thePLC->getName()); return -1; } -int Connection::readCPUInfo(PLC* thePLC, CPUInfoType& dataStruct) +int Connection::readCPUInfo(PLC* thePLC, CPUInfoType&) { throw SilecsException(__FILE__, __LINE__, DIAG_PLC_REPORT_NOT_SUPPORTED, thePLC->getName()); return -1; } -int Connection::readCPInfo(PLC* thePLC, CPInfoType& dataStruct) +int Connection::readCPInfo(PLC* thePLC, CPInfoType&) { throw SilecsException(__FILE__, __LINE__, DIAG_PLC_REPORT_NOT_SUPPORTED, thePLC->getName()); return -1; diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h index f55e79f13358670daaf5547323f1f3439e0857ae..88796f5876239c6893a90b4445611b86e9c7b670 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h @@ -45,7 +45,7 @@ class Connection { public: - Connection(PLC* thePLC); + Connection(); virtual ~Connection(); virtual int readMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* buffer) = 0; diff --git a/silecs-communication-cpp/src/silecs-communication/interface/core/PLCSendAction.cpp b/silecs-communication-cpp/src/silecs-communication/interface/core/PLCSendAction.cpp index 8e5dfb509664868a60214a898591e70397352f35..8c6124e9dbf115771b42dd8881070e73b22bea30 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/core/PLCSendAction.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/core/PLCSendAction.cpp @@ -94,27 +94,27 @@ int PLCSendBlockMode::execute(Context* pContext) { case AccessArea::Digital: errorCode = pConn->writeDIO(theBlock_->getPLC(), usedAddress, //Base address (or DBn) of the block - usedDeviceOffset, //Device data address within the block - usedSize, //Set one device-block only - pBuffer //Buffer which contain the data - ); + usedDeviceOffset, //Device data address within the block + usedSize, //Set one device-block only + pBuffer //Buffer which contain the data + ); break; case AccessArea::Analog: { errorCode = pConn->writeAIO(theBlock_->getPLC(), usedAddress, //Base address (or DBn) of the block - usedDeviceOffset, //Device data address within the block - usedSize, //Set one device-block only - pBuffer //Buffer which contain the data - ); + usedDeviceOffset, //Device data address within the block + usedSize, //Set one device-block only + pBuffer //Buffer which contain the data + ); break; } case AccessArea::Memory: default: errorCode = pConn->writeMemory(theBlock_->getPLC(), usedAddress, //Base address (or DBn) of the block - usedDeviceOffset, //Device data address within the block - usedSize, //Set one device-block only - pBuffer //Buffer which contain the data - ); + usedDeviceOffset, //Device data address within the block + usedSize, //Set one device-block only + pBuffer //Buffer which contain the data + ); break; } } @@ -158,27 +158,27 @@ int PLCSendBlockMode::execute(Context* pContext) { case AccessArea::Digital: errorCode = pConn->writeDIO(theBlock_->getPLC(), theBlock_->getAddress(), //Base address (or DBn) of the block - 0, //Set all devices from the first one - ((PLCBlock*)theBlock_)->getBufferSize(), //Set blocks of all devices (full buffer size) - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data (full buffer) - ); + 0, //Set all devices from the first one + ((PLCBlock*)theBlock_)->getBufferSize(), //Set blocks of all devices (full buffer size) + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data (full buffer) + ); break; case AccessArea::Analog: { errorCode = pConn->writeAIO(theBlock_->getPLC(), theBlock_->getAddress(), //Base address (or DBn) of the block - 0, //Set all devices from the first one - ((PLCBlock*)theBlock_)->getBufferSize(), //Set blocks of all devices (full buffer size) - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data (full buffer) - ); + 0, //Set all devices from the first one + ((PLCBlock*)theBlock_)->getBufferSize(), //Set blocks of all devices (full buffer size) + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data (full buffer) + ); break; } case AccessArea::Memory: default: errorCode = pConn->writeMemory(theBlock_->getPLC(), theBlock_->getAddress(), //Base address (or DBn) of the block - 0, //Set all devices from the first one - ((PLCBlock*)theBlock_)->getBufferSize(), //Set blocks of all devices (full buffer size) - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data (full buffer) - ); + 0, //Set all devices from the first one + ((PLCBlock*)theBlock_)->getBufferSize(), //Set blocks of all devices (full buffer size) + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data (full buffer) + ); break; } } @@ -198,7 +198,7 @@ int PLCSendBlockMode::execute(Context* pContext) LOG(ERROR) << "SendAction (execute/ DeviceMode) on block: " << theBlock_->getName() << " has failed"; return ex.getCode(); } - return 0; + return errorCode; } int PLCSendDeviceMode::execute(Context* pContext) @@ -241,27 +241,27 @@ int PLCSendDeviceMode::execute(Context* pContext) { case AccessArea::Digital: errorCode = pConn->writeDIO(theBlock_->getPLC(), usedDeviceAddress, //Base address (or DBn) of the device - usedBlockAddress, //Block data address within the device - usedSize, //Set one device-block only - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data - ); + usedBlockAddress, //Block data address within the device + usedSize, //Set one device-block only + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data + ); break; case AccessArea::Analog: { errorCode = pConn->writeAIO(theBlock_->getPLC(), usedDeviceAddress, //Base address (or DBn) of the device - usedBlockAddress, //Block data address within the device - usedSize, //Set one device-block only - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data - ); + usedBlockAddress, //Block data address within the device + usedSize, //Set one device-block only + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data + ); break; } case AccessArea::Memory: default: errorCode = pConn->writeMemory(theBlock_->getPLC(), usedDeviceAddress, //Base address (or DBn) of the device - usedBlockAddress, //Block data address within the device - usedSize, //Set one device-block only - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data - ); + usedBlockAddress, //Block data address within the device + usedSize, //Set one device-block only + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data + ); break; } } @@ -302,27 +302,27 @@ int PLCSendDeviceMode::execute(Context* pContext) { case AccessArea::Digital: errorCode = pConn->writeDIO(theBlock_->getPLC(), pDev->getOutputAddress(area), //Base address (or DBn) of the device - theBlock_->getAddress(), //Block data address within the device - theBlock_->getMemSize(), //Set one device-block only - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data - ); + theBlock_->getAddress(), //Block data address within the device + theBlock_->getMemSize(), //Set one device-block only + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data + ); break; case AccessArea::Analog: { errorCode = pConn->writeAIO(theBlock_->getPLC(), pDev->getOutputAddress(area), //Base address (or DBn) of the device - theBlock_->getAddress(), //Block data address within the device - theBlock_->getMemSize(), //Set one device-block only - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data - ); + theBlock_->getAddress(), //Block data address within the device + theBlock_->getMemSize(), //Set one device-block only + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data + ); break; } case AccessArea::Memory: default: errorCode = pConn->writeMemory(theBlock_->getPLC(), pDev->getOutputAddress(area), //Base address (or DBn) of the device - theBlock_->getAddress(), //Block data address within the device - theBlock_->getMemSize(), //Set one device-block only - (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data - ); + theBlock_->getAddress(), //Block data address within the device + theBlock_->getMemSize(), //Set one device-block only + (unsigned char*)theBlock_->getBuffer() //Buffer which contain the data + ); break; } } @@ -343,7 +343,7 @@ int PLCSendDeviceMode::execute(Context* pContext) LOG(ERROR) << "SendAction (execute/ DeviceMode) failed"; return ex.getCode(); } - return 0; + return errorCode; } } // namespace diff --git a/silecs-communication-cpp/src/silecs-communication/interface/core/SilecsService.cpp b/silecs-communication-cpp/src/silecs-communication/interface/core/SilecsService.cpp index 30c41d5de04730e72e0dc6cc66f8196fd75ca659..ec59fb37b4d7d6f83dc5db976d33de98915aae6d 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/core/SilecsService.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/core/SilecsService.cpp @@ -284,7 +284,7 @@ bool Service::fileExists(std::string filename) } } //Unexpected error - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); } bool Service::checkArgs(int argc, char ** argv) diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/PLCRegister.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/PLCRegister.cpp index eef367fb5ca00e7814a53ec504e9ed6ea5768255..ba178e65ce26fbe60513fe85defd0d0bf1a4f97a 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/PLCRegister.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/PLCRegister.cpp @@ -15,7 +15,6 @@ Contributors: #include <silecs-communication/interface/communication/MBHardware.h> #include <silecs-communication/interface/communication/SNAP7Hardware.h> #include <silecs-communication/interface/communication/SNAP7Utils.h> -#include <snap7.h> namespace Silecs { @@ -360,7 +359,7 @@ void PLCRegister::importValue(void* pBuffer, timeval ts) } else { //should never occur! - throw SilecsException(__FILE__, __LINE__, (int)UNEXPECTED_ERROR, "Controller protocol type undefined!"); + throw SilecsException(__FILE__, __LINE__, UNEXPECTED_ERROR, "Controller protocol type undefined!"); } pData += dtSize; } @@ -452,7 +451,7 @@ void PLCRegister::exportValue(void* pBuffer) } else { //should never occur! - throw SilecsException(__FILE__, __LINE__, (int)UNEXPECTED_ERROR, "Controller protocol type undefined!"); + throw SilecsException(__FILE__, __LINE__, UNEXPECTED_ERROR, "Controller protocol type undefined!"); } pData += dtSize; } diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp index bc48ec2b9a983174c7431ab362ad144a86f25de2..d704aaae5a875db40c052a0ef7fd7b148a6363f8 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp @@ -1357,7 +1357,7 @@ void Register::setScalarfromString(std::string stringValue) uint16_t val = 0; if(!StringUtilities::from_string<uint16_t>(val, stringValue, std::dec)) throw SilecsException(__FILE__, __LINE__,"Conversion from string '" + stringValue + "'to uInt8 failed for register '" + name_ + "'"); - setValUInt8((uint16_t)val); + setValUInt8(static_cast<uint8_t>(val)); break; } case Int8: diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/Condition.cpp b/silecs-communication-cpp/src/silecs-communication/interface/utility/Condition.cpp index aa65b9fd693563b7e4e00f155ff33b7bfd095b7d..92c41a92aaf04c1980feaebb6b07ac8c646b4c85 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/utility/Condition.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/Condition.cpp @@ -29,7 +29,7 @@ Condition::Condition(std::string name) pMutex_ = new Mutex(name_); if ( (err = pthread_cond_init(&condVar_, NULL)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); } Condition::~Condition() @@ -37,7 +37,7 @@ Condition::~Condition() int err; if ( (err = pthread_cond_destroy(&condVar_)) != 0) { //can be broken by SIGKILL (just leave with no Exception) - //throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + //throw SilecsException(__FILE__, __LINE__, errno); } delete pMutex_; } @@ -56,7 +56,7 @@ void Condition::signal() { int err; if ( (err = pthread_cond_signal(&condVar_)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); LOG(LOCK) << "Has signaled condition: " << this->name_; } @@ -64,7 +64,7 @@ void Condition::broadcast() { int err; if ( (err = pthread_cond_broadcast(&condVar_)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); } void Condition::wait() @@ -72,7 +72,7 @@ void Condition::wait() int err; LOG(LOCK) << "Waiting for condition: " << this->name_; if ( (err = pthread_cond_wait(&condVar_, pMutex_->pMutex_)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); LOG(LOCK) << "Has get condition: " << this->name_; } diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/Mutex.cpp b/silecs-communication-cpp/src/silecs-communication/interface/utility/Mutex.cpp index 10c5c0b067f19d9a579a8c35a92239284eb48da7..a248a19ba5072edd2d1e6e5badc2f440884fe580 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/utility/Mutex.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/Mutex.cpp @@ -32,14 +32,14 @@ Mutex::Mutex(std::string name) pMutex_ = new pthread_mutex_t(); if ( (err = pthread_mutexattr_init(&attr_)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); //Mutex supports re-entrance for re-open mechanism inside send/recv action (doOpen() method call) if ( (err = pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); if ( (err = pthread_mutex_init(pMutex_, &attr_)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); } Mutex::~Mutex() @@ -50,11 +50,11 @@ Mutex::~Mutex() LOG(ALLOC) << "Mutex (delete): " << name_; if ( (err = pthread_mutexattr_destroy(&attr_)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); if ( (err = pthread_mutex_destroy(pMutex_)) != 0) { //can be broken by SIGKILL (just leave with no Exception) - //throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + //throw SilecsException(__FILE__, __LINE__, errno); } // patch by Stefano Magnoni (20-03-2012) @@ -73,7 +73,7 @@ void Mutex::lock() if ( (err = pthread_mutex_lock(pMutex_)) != 0) { // lock can be broken by SIGKILL (just release it with no Exception) pthread_mutex_unlock(pMutex_); - //throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + //throw SilecsException(__FILE__, __LINE__, errno); } LOG(LOCK) << "Has locked: " << this->name_; } @@ -84,7 +84,7 @@ void Mutex::unlock() if ( (err = pthread_mutex_unlock(pMutex_)) != 0) { // unlock can be broken by SIGKILL (just force release again but no Exception) pthread_mutex_unlock(pMutex_); - //throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + //throw SilecsException(__FILE__, __LINE__, errno); } LOG(LOCK) << "Has unlocked: " << this->name_; } diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsException.cpp b/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsException.cpp index c86f14615921961c02024952f9e74b19083c45fd..57245d264334b4d29f90ac9208afc55f448f6f54 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsException.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsException.cpp @@ -14,6 +14,7 @@ Contributors: #include "SilecsException.h" #include "SilecsLog.h" +#include <cstring> #include <string> namespace Silecs @@ -31,13 +32,13 @@ SilecsException::SilecsException(const std::string& file, const uint32_t line, c log(); } -SilecsException::SilecsException(const std::string& file, const uint32_t line, const int err, const char *str) +SilecsException::SilecsException(const std::string& file, const uint32_t line, const int err) { errFile_ = file; errLine_ = line; errCategory_ = CLIENT_SYSTEM_FAULT; errCode_ = UNEXPECTED_ERROR; - errMessage_ = str; + errMessage_ = std::strerror(err); buildFullMessage(); //Log the error to the std. output (if ERROR topic is enable) diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsException.h b/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsException.h index 28026c260d4392297866b2991fb83411e8a3b065..8e068369c23f3f663dcc1b740191140acbf348b1 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsException.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsException.h @@ -117,7 +117,7 @@ public: * \param file-name, line-number, error-no and error-str for system faults or extra-str if needed */ SilecsException(const std::string& file, const uint32_t line, const ErrorCode code, const std::string& extMsg = std::string()); - SilecsException(const std::string& file, const uint32_t line, const int err, const char *str); + SilecsException(const std::string& file, const uint32_t line, const int err); SilecsException(const std::string& file, const uint32_t line, const std::string& msg); /*! diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsLog.cpp b/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsLog.cpp index abc20924ded3d7e0d3e4a73acba4d40f95432e63..bdd994c846e274d08dff28f295df0aa82a39b8fe 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsLog.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/SilecsLog.cpp @@ -157,7 +157,7 @@ void Log::startSyslog(char* ident, unsigned long topics) { char hostName[128]; if (gethostname(hostName, 128) == -1) - throw SilecsException(__FILE__, __LINE__, errno, strerror(errno)); + throw SilecsException(__FILE__, __LINE__, errno); //remove domain name (.cern.ch) if any host_ = std::string(hostName); diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/Thread.h b/silecs-communication-cpp/src/silecs-communication/interface/utility/Thread.h index a883c29036a330b98f8d8ffe205736e5587bae56..82b17c4dcda29f389e6250920d70e668df40ba67 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/utility/Thread.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/Thread.h @@ -111,7 +111,7 @@ Thread<UserDataType>::Thread() : pTid_ = (pthread_t *)malloc(sizeof(pthread_t)); pThreadCompletion_->lock(); // The constructor will wait until thread is ready if ( (err = pthread_create(pTid_, NULL, run, this)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(err)); + throw SilecsException(__FILE__, __LINE__, err); //err = pthread_detach(*pTid_); not necessary because PLC thread are infinite loop pThreadCompletion_->wait(); // Wait until thread is ready pThreadCompletion_->unlock(); // Thread is ready @@ -131,7 +131,7 @@ void *Thread<UserDataType>::run(void *pThisThread) { int err; if ( (err = pthread_sigmask(SIG_BLOCK, &smask, NULL)) != 0) - throw SilecsException(__FILE__, __LINE__, errno, strerror(err)); + throw SilecsException(__FILE__, __LINE__, err); } pthis->execute(); return 0; diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/TimeStamp.cpp b/silecs-communication-cpp/src/silecs-communication/interface/utility/TimeStamp.cpp index 578e9469ac9255571abd6c645f6b6c627d8828eb..3ef15c9975d6dc8eaf96eb3b3f1a459d3fd591e5 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/utility/TimeStamp.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/TimeStamp.cpp @@ -83,6 +83,9 @@ void TsCounter::calibrateCountPeriod(unsigned int inDelay/*ms*/, unsigned int in } mPeriod = lPeriod/(inTimes-1); #else + // Cast to void to avoid unsued warnings. + static_cast<void>(inDelay); + static_cast<void>(inTimes); // use the microseconds of gettimeofday mPeriod = 0.000001; #endif diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/XMLParser.cpp b/silecs-communication-cpp/src/silecs-communication/interface/utility/XMLParser.cpp index 2dc28542ec780a408fd9292b857283241a6ac545..5c0cd06d7d9fe8158edaabf4d2b2fdd381126eab 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/utility/XMLParser.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/XMLParser.cpp @@ -144,7 +144,7 @@ boost::optional<boost::ptr_vector<ElementXML> > XMLParser::getElementsFromXPath( { for (int i = 0; i < xpathObject->nodesetval->nodeNr; ++i) { - std::auto_ptr<ElementXML> element(new ElementXML()); + std::unique_ptr<ElementXML> element(new ElementXML()); fillElement(xpathObject->nodesetval->nodeTab[i], *element); if (!elements) {