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

          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          76 : LoggerStopCommand::LoggerStopCommand(QObject * const parent) : DeviceCommand(parent)
      23             : {
      24             : 
      25          76 : }
      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           0 :         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          57 : void LoggerStopCommand::settingsWritten()
      60             : {
      61          63 :     qCDebug(lc).noquote() << tr("Settings written; data logger has stopped.");
      62          57 :     switch (format) {
      63          19 :     case OutputFormat::Csv:
      64          24 :         std::cout << qUtf8Printable(tr("logger_stop_result\nsuccess\n"));
      65          19 :         break;
      66             :     case OutputFormat::Json:
      67          29 :         std::cout << qUtf8Printable(QLatin1String("true\n"));
      68          19 :         break;
      69          19 :     case OutputFormat::Text:
      70          24 :         std::cout << qUtf8Printable(tr("Done.\n"));
      71          19 :         break;
      72             :     }
      73          57 :     if (device) disconnect(); // Will exit the application once disconnected.
      74          57 : }

Generated by: LCOV version 1.14