LCOV - code coverage report
Current view: top level - src/cli - loggerstopcommand.cpp (source / functions) Hit Total Coverage
Project: Dokit Lines: 15 25 60.0 %
Version: Functions: 3 5 60.0 %

          Line data    Source code
       1             : // SPDX-FileCopyrightText: 2022-2023 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          72 : LoggerStopCommand::LoggerStopCommand(QObject * const parent) : DeviceCommand(parent)
      23             : {
      24             : 
      25          72 : }
      26             : 
      27             : /*!
      28             :  * \copybrief DeviceCommand::getService
      29             :  *
      30             :  * This override returns a pointer to a DataLoggerService object.
      31             :  */
      32           0 : AbstractPokitService * LoggerStopCommand::getService()
      33             : {
      34             :     Q_ASSERT(device);
      35           0 :     if (!service) {
      36           0 :         service = device->dataLogger();
      37             :         Q_ASSERT(service);
      38           0 :         connect(service, &DataLoggerService::settingsWritten,
      39             :         this, &LoggerStopCommand::settingsWritten);
      40             :     }
      41           0 :     return service;
      42             : }
      43             : 
      44             : /*!
      45             :  * \copybrief DeviceCommand::serviceDetailsDiscovered
      46             :  *
      47             :  * This override stops the device's logger.
      48             :  */
      49           0 : void LoggerStopCommand::serviceDetailsDiscovered()
      50             : {
      51           0 :     DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
      52           0 :     qCInfo(lc).noquote() << tr("Stopping logger.");
      53           0 :     service->stopLogger();
      54           0 : }
      55             : 
      56             : /*!
      57             :  * Invoked when the data logger settings have been written.
      58             :  */
      59          54 : void LoggerStopCommand::settingsWritten()
      60             : {
      61          54 :     qCDebug(lc).noquote() << tr("Settings written; data logger has stopped.");
      62          54 :     switch (format) {
      63          18 :     case OutputFormat::Csv:
      64          22 :         std::cout << qUtf8Printable(tr("logger_stop_result\nsuccess\n"));
      65          18 :         break;
      66             :     case OutputFormat::Json:
      67          26 :         std::cout << qUtf8Printable(QLatin1String("true\n"));
      68          18 :         break;
      69          18 :     case OutputFormat::Text:
      70          22 :         std::cout << qUtf8Printable(tr("Done.\n"));
      71          18 :         break;
      72             :     }
      73          54 :     if (device) disconnect(); // Will exit the application once disconnected.
      74          54 : }

Generated by: LCOV version 1.14