Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix different coding/C++ issues #568

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions qslog/QsLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

namespace QsLogging
{
typedef QVector<DestinationPtr> DestinationList;
using DestinationList = QVector<DestinationPtr>;

static const char TraceString[] = "TRACE";
static const char DebugString[] = "DEBUG";
Expand All @@ -47,7 +47,7 @@ static const char ErrorString[] = "ERROR";
static const char FatalString[] = "FATAL";

// not using Qt::ISODate because we need the milliseconds too
static const QString fmtDateTime("yyyy-MM-ddThh:mm:ss.zzz");
static auto fmtDateTime = "yyyy-MM-ddThh:mm:ss.zzz";

static Logger* sInstance = 0;

Expand Down Expand Up @@ -77,9 +77,10 @@ static const char* LevelToText(Level theLevel)

class LogWriterRunnable : public QRunnable
{
Q_DISABLE_COPY(LogWriterRunnable)
public:
LogWriterRunnable(QString message, Level level);
virtual void run();
void run() override;

private:
QString mMessage;
Expand All @@ -90,16 +91,16 @@ class LoggerImpl
{
public:
LoggerImpl();

friend class Logger;
private:
QThreadPool threadPool;
QMutex logMutex;
Level level;
Level level { Level::InfoLevel };
DestinationList destList;
};

LogWriterRunnable::LogWriterRunnable(QString message, Level level)
: QRunnable()
, mMessage(message)
: mMessage(message)
, mLevel(level)
{
}
Expand All @@ -111,7 +112,6 @@ void LogWriterRunnable::run()


LoggerImpl::LoggerImpl()
: level(InfoLevel)
{
// assume at least file + console
destList.reserve(2);
Expand Down Expand Up @@ -224,9 +224,8 @@ void Logger::enqueueWrite(const QString& message, Level level)
void Logger::write(const QString& message, Level level)
{
QMutexLocker lock(&d->logMutex);
for (DestinationList::iterator it = d->destList.begin(),
endIt = d->destList.end();it != endIt;++it) {
(*it)->write(message, level);
for (auto &it:d->destList) {
it->write(message, level);
}
}

Expand Down
1 change: 1 addition & 0 deletions qslog/QsLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class QSLOG_SHARED_OBJECT Logger
/// log message.
class QSLOG_SHARED_OBJECT Helper
{
Q_DISABLE_COPY (Helper)
public:
explicit Helper(Level logLevel) :
level(logLevel),
Expand Down
2 changes: 2 additions & 0 deletions qslog/QsLogDest.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ namespace QsLogging

class QSLOG_SHARED_OBJECT Destination
{
Q_DISABLE_COPY(Destination)
public:
typedef void (*LogFunction)(const QString &message, Level level);

public:
Destination() = default;
virtual ~Destination();
virtual void write(const QString& message, Level level) = 0;
virtual bool isValid() = 0; // returns whether the destination was created correctly
Expand Down
3 changes: 3 additions & 0 deletions qslog/QsLogDestFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ namespace QsLogging
{
class RotationStrategy
{
Q_DISABLE_COPY(RotationStrategy)
public:
RotationStrategy() = default;
virtual ~RotationStrategy();

virtual void setInitialInfo(const QFile &file) = 0;
Expand All @@ -49,6 +51,7 @@ class RotationStrategy
class NullRotationStrategy : public RotationStrategy
{
public:
NullRotationStrategy() = default;
virtual void setInitialInfo(const QFile &) {}
virtual void includeMessageInCalculation(const QString &) {}
virtual bool shouldRotate() { return false; }
Expand Down
6 changes: 4 additions & 2 deletions tests/trikKernelTests/differentOwnedPointerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ using namespace trikKernel;
/// Helper class that provides something to construct and destruct and a means to verify its destruction.
class TestHelper
{
Q_DISABLE_COPY(TestHelper)
public:
/// Class that can report that it was destroyed.
class Destructable
{
Q_DISABLE_COPY(Destructable)
public:
Destructable(TestHelper &parent)
: mParent(parent)
explicit Destructable(TestHelper &parent) : mParent(parent)
{
}

Expand All @@ -40,6 +41,7 @@ class TestHelper
TestHelper &mParent;
};

TestHelper() = default;
~TestHelper()
{
if (!mDestroyed)
Expand Down
2 changes: 1 addition & 1 deletion trikCommunicator/src/trikCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TrikCommunicator::TrikCommunicator(const trikKernel::DifferentOwnerPointer<trikS


connect(runner.data(), &trikScriptRunner::TrikScriptRunner::textInStdOut
, this, [this](QString text){
, this, [this](const QString &text){
sendMessage(QString("print: %1").arg(text));
});

Expand Down
2 changes: 1 addition & 1 deletion trikControl/src/abstractVirtualSensorWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <cerrno>

#include <trikHal/hardwareAbstractionInterface.h>

Expand Down
4 changes: 2 additions & 2 deletions trikControl/src/configurerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int ConfigurerHelper::configureInt(const trikKernel::Configurer &configurer, Dev
bool ok = false;
int parameter = configurer.attributeByPort(port, parameterName).toInt(&ok, 0);
if (!ok) {
QLOG_ERROR() << QString("Incorrect configuration for parameter \"%1\" for port \"%2\": \"%3\" ")
QLOG_ERROR() << QString(R"(Incorrect configuration for parameter "%1" for port "%2": "%3" )")
.arg(parameterName).arg(port).arg(configurer.attributeByPort(port, parameterName));
state.fail();
return 0;
Expand All @@ -52,7 +52,7 @@ qreal ConfigurerHelper::configureReal(const trikKernel::Configurer &configurer,
bool ok = false;
const qreal parameter = configurer.attributeByPort(port, parameterName).toDouble(&ok);
if (!ok) {
QLOG_ERROR() << QString("Incorrect configuration for parameter \"%1\" for port \"%2\": \"%3\" ")
QLOG_ERROR() << QString(R"(Incorrect configuration for parameter "%1" for port "%2": "%3" )")
.arg(parameterName).arg(port).arg(configurer.attributeByPort(port, parameterName));

state.fail();
Expand Down
2 changes: 1 addition & 1 deletion trikControl/src/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public slots:
bool hasData() const override;

private slots:
void onNewLine(const QString &data);
void onNewLine(const QString &line);
void onNewData(const QVector<uint8_t> &data);
void onReadError();

Expand Down
2 changes: 1 addition & 1 deletion trikControl/src/guiWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ void GuiWorker::repaintGraphicsWidget()

QColor GuiWorker::colorByName(const QString &name)
{
return QColor(name.toLower());
return {name.toLower()};
}
2 changes: 1 addition & 1 deletion trikControl/src/gyroSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,5 @@ QVector3D GyroSensor::getEulerAngles(const QQuaternion &q)
pitch = pitch * RAD_TO_MDEG;
yaw = yaw * RAD_TO_MDEG;
roll = roll * RAD_TO_MDEG;
return QVector3D(pitch, roll, yaw);
return {pitch, roll, yaw};
}
6 changes: 3 additions & 3 deletions trikControl/src/tonePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ void TonePlayer::initializeAudio()
}
}

void TonePlayer::play(int hzFreq, int msDuration)
void TonePlayer::play(int freqHz, int durationMs)
{
mDevice->start(hzFreq);
mDevice->start(freqHz);
const auto state = mOutput->state();
QLOG_INFO() << "Device started. Output state is" << state;
switch (state) {
Expand All @@ -74,7 +74,7 @@ void TonePlayer::play(int hzFreq, int msDuration)
break;
}

mTimer.setInterval(msDuration);
mTimer.setInterval(durationMs);
mTimer.start();
}

Expand Down
6 changes: 3 additions & 3 deletions trikGui/openSocketIndicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

using namespace trikGui;

OpenSocketIndicator::OpenSocketIndicator(const QString &openPicFile
OpenSocketIndicator::OpenSocketIndicator(const QString &openFilePic
, bool status
, QWidget *parent)
: QLabel(parent)
, mOpenPic(openPicFile)
, mOpenPic(openFilePic)
{
setPixmap(openPicFile);
setPixmap(openFilePic);
status ? show() : hide();
}

Expand Down
4 changes: 2 additions & 2 deletions trikGui/openSocketIndicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class OpenSocketIndicator : public QLabel
{
Q_OBJECT
public:
/// @param openFile, closedFile - paths to pictures for open and closed connection status
/// @param openFilePic - path to picture for open connection status
/// @param status - initial connection status
OpenSocketIndicator(const QString &openFile, bool status, QWidget *parent = 0);
OpenSocketIndicator(const QString &openFilePic, bool status, QWidget *parent = 0);

public slots:
/// Changes status of indicator to a given value.
Expand Down
1 change: 1 addition & 0 deletions trikHal/include/trikHal/mspUsbInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace trikHal {
/// Communicates with MSP processor over USB bus.
class MspUsbInterface
{
Q_DISABLE_COPY(MspUsbInterface)
public:
MspUsbInterface() = default;
virtual ~MspUsbInterface() = default;
Expand Down
2 changes: 1 addition & 1 deletion trikHal/src/stub/stubSystemConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StubSystemConsole : public SystemConsoleInterface
int system(const QString &command) override;
bool startProcess(const QString &processName, const QStringList &arguments) override;
bool startProcessSynchronously(const QString &processName, const QStringList &arguments
, QString * output = nullptr) override;
, QString * output) override;
};

}
Expand Down
2 changes: 1 addition & 1 deletion trikHal/src/trik/trikEventFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool TrikEventFile::close()
}

if (::close(mEventFileDescriptor) != 0) {
QLOG_ERROR() << QString("%1: close failed: %2").arg(mFileName).arg(strerror(errno));
QLOG_ERROR() << QString("%1: close failed: %2").arg(mFileName, strerror(errno));
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions trikHal/src/trik/trikI2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ int TrikI2c::read(const QByteArray &data)
if (data.size() == 2) {
return i2c_smbus_read_word_data(mDeviceFileDescriptor, data[0]);
} else {
__u8 buffer[4] = {0};
i2c_smbus_read_i2c_block_data(mDeviceFileDescriptor, data[0], 4, buffer);
std::array<uint8_t, 4> buffer {};
i2c_smbus_read_i2c_block_data(mDeviceFileDescriptor, data[0], 4, buffer.data());
return buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0];
}
}
Expand Down
23 changes: 12 additions & 11 deletions trikHal/src/trik/usbMsp/usbMSP430Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* Author: Rostislav Varzar
*/

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <cerrno>
#include <termios.h>

#include <QtCore/QByteArray>
Expand Down Expand Up @@ -53,6 +53,7 @@ uint8_t addr_table_i2c_usb[84] = // Correspondence address table (between I2C an
/// Delays class
class Sleeper : public QThread
{
Q_OBJECT
public:
static void usleep(unsigned long usecs){QThread::usleep(usecs);}
static void msleep(unsigned long msecs){QThread::msleep(msecs);}
Expand Down Expand Up @@ -717,20 +718,20 @@ uint32_t read_URM04_dist(uint8_t dev_addr, uint8_t urm04_addr)
uint8_t pack2[6] = {0x55, 0xAA, urm04_addr, 0x00, 0x02, crc_b};
uint8_t buf1[8] = {0};
// Trigger device
for (int i = 0; i < 6; i++)
for (auto x : pack1)
{
makeWriteRegPacket(s1, dev_addr, UUDAT, pack1[i]);
makeWriteRegPacket(s1, dev_addr, UUDAT, x);
sendUSBPacket(s1, s1);
}
// Wait about 400 ms
Sleeper::msleep(400);
// Read distance
for (int i = 0; i < 6; i++)
for (auto x: pack2)
{
makeWriteRegPacket(s1, dev_addr, UUDAT, pack2[i]);
makeWriteRegPacket(s1, dev_addr, UUDAT, x);
sendUSBPacket(s1, s1);
}
for (int i = 0; i < 8; i++)
for (auto &x: buf1)
{
do
{
Expand All @@ -739,7 +740,7 @@ uint32_t read_URM04_dist(uint8_t dev_addr, uint8_t urm04_addr)
errcode = decodeReceivedPacket(s2, devaddr, funccode, regaddr, regval);
tmout ++;
} while (((devaddr != dev_addr) || (regaddr != UUDAT)) && (tmout < TIME_OUT));
buf1[i] = regval;
x = regval;
}
crc1 = buf1[0] + buf1[1] + buf1[2] + buf1[3] + buf1[4] + buf1[5] + buf1[6];
if (crc1 != buf1[7])
Expand Down
3 changes: 3 additions & 0 deletions trikKernel/include/trikKernel/deinitializationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License. */

#pragma once
#include <QtGlobal>

namespace trikKernel {

Expand All @@ -21,7 +22,9 @@ namespace trikKernel {
/// shuts down.
class DeinitializationHelper
{
Q_DISABLE_COPY(DeinitializationHelper)
public:
DeinitializationHelper() = default;
/// Here is all the magic - runs zero-time event loop when this object is destroyed.
~DeinitializationHelper();
};
Expand Down
2 changes: 2 additions & 0 deletions trikKernel/include/trikKernel/differentOwnerPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace trikKernel {
template<typename T> class DifferentOwnerPointer
{
public:
~DifferentOwnerPointer() = default;

/// Copy constructor. Preserves ownership semantics of a copied object.
DifferentOwnerPointer(const DifferentOwnerPointer<T> &other)
: mPointer(other.mPointer)
Expand Down
2 changes: 1 addition & 1 deletion trikKernel/include/trikKernel/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

namespace trikKernel {

const QString version = "3.1.4";
const auto version = "3.1.4";

}
2 changes: 1 addition & 1 deletion trikKernel/src/applicationInitHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ApplicationInitHelper::ApplicationInitHelper(QCoreApplication &app)
trikKernel::TranslationsHelper::initLocale(app.arguments().contains("--no-locale")
|| app.arguments().contains("-no-locale"));

QApplication *guiApp = dynamic_cast<QApplication *>(&app);
auto *guiApp = qobject_cast<QApplication *>(&app);
if (guiApp) {
QFont font(guiApp->font());
font.setPixelSize(18);
Expand Down
Loading