LCOV - code coverage report
Current view: top level - src/app - loggerstopcommand.cpp (source / functions) Hit Total Coverage
Project: QtPokit Lines: 16 26 61.5 %
Version: Functions: 3 5 60.0 %

          Line data    Source code
       1             : // SPDX-FileCopyrightText: 2022 Paul Colby <git@colby.id.au>
       2             : // SPDX-License-Identifier: LGPL-3.0-or-later
       3             : 
       4             : #include "loggerstopcommand.h"
       5             : 
       6             : #include <qtpokit/pokitdevice.h>
       7             : 
       8             : #include <QJsonDocument>
       9             : #include <QJsonObject>
      10             : 
      11             : #include <iostream>
      12             : 
      13             : /*!
      14             :  * \class LoggerStopCommand
      15             :  *
      16             :  * The LoggerStopCommand class implements the `logger stop` CLI command.
      17             :  */
      18             : 
      19             : /*!
      20             :  * Construct a new LoggerStopCommand object with \a parent.
      21             :  */
      22          68 : LoggerStopCommand::LoggerStopCommand(QObject * const parent)
      23          68 :     : DeviceCommand(parent), service(nullptr)
      24             : {
      25             : 
      26          68 : }
      27             : 
      28             : /*!
      29             :  * \copybrief DeviceCommand::getService
      30             :  *
      31             :  * This override returns a pointer to a DataLoggerService object.
      32             :  */
      33           0 : AbstractPokitService * LoggerStopCommand::getService()
      34             : {
      35             :     Q_ASSERT(device);
      36           0 :     if (!service) {
      37           0 :         service = device->dataLogger();
      38             :         Q_ASSERT(service);
      39           0 :         connect(service, &DataLoggerService::settingsWritten,
      40             :         this, &LoggerStopCommand::settingsWritten);
      41             :     }
      42           0 :     return service;
      43             : }
      44             : 
      45             : /*!
      46             :  * \copybrief DeviceCommand::serviceDetailsDiscovered
      47             :  *
      48             :  * This override stops the device's logger.
      49             :  */
      50           0 : void LoggerStopCommand::serviceDetailsDiscovered()
      51             : {
      52           0 :     DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
      53           0 :     qCInfo(lc).noquote() << tr("Stopping logger.");
      54           0 :     service->stopLogger();
      55           0 : }
      56             : 
      57             : /*!
      58             :  * Invoked when the data logger settings have been written.
      59             :  */
      60          51 : void LoggerStopCommand::settingsWritten()
      61             : {
      62          51 :     qCDebug(lc).noquote() << tr("Settings written; data logger has stopped.");
      63          51 :     switch (format) {
      64           6 :     case OutputFormat::Csv:
      65          20 :         std::cout << qUtf8Printable(tr("logger_stop_result\nsuccess\n"));
      66          17 :         break;
      67             :     case OutputFormat::Json:
      68          23 :         std::cout << qUtf8Printable(QLatin1String("true\n"));
      69          17 :         break;
      70           6 :     case OutputFormat::Text:
      71          20 :         std::cout << qUtf8Printable(tr("Done.\n"));
      72          17 :         break;
      73             :     }
      74          51 :     if (device) disconnect(); // Will exit the application once disconnected.
      75          51 : }

Generated by: LCOV version 1.14