LCOV - code coverage report
Current view: top level - src/cli - flashledcommand.cpp (source / functions) Coverage Total Hit
Project: Dokit Lines: 61.1 % 54 33
Version: Functions: 71.4 % 7 5

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2022-2025 Paul Colby <git@colby.id.au>
       2              : // SPDX-License-Identifier: LGPL-3.0-or-later
       3              : 
       4              : #include "flashledcommand.h"
       5              : #include "../stringliterals_p.h"
       6              : 
       7              : #include <qtpokit/pokitdevice.h>
       8              : #include <qtpokit/statusservice.h>
       9              : 
      10              : #include <iostream>
      11              : 
      12              : DOKIT_USE_STRINGLITERALS
      13              : 
      14              : /*!
      15              :  * \class FlashLedCommand
      16              :  *
      17              :  * The FlashLedCommand class implements the `flash-led` CLI command.
      18              :  */
      19              : 
      20              : /*!
      21              :  * Construct a new FlashLedCommand object with \a parent.
      22              :  */
      23          840 : FlashLedCommand::FlashLedCommand(QObject * const parent) : DeviceCommand(parent)
      24          392 : {
      25              : 
      26          952 : }
      27              : 
      28          400 : QStringList FlashLedCommand::requiredOptions(const QCommandLineParser &parser) const
      29          280 : {
      30         1080 :     return DeviceCommand::requiredOptions(parser) + QStringList{
      31          935 :     };
      32          280 : }
      33              : 
      34          160 : QStringList FlashLedCommand::supportedOptions(const QCommandLineParser &parser) const
      35          112 : {
      36          272 :     return DeviceCommand::supportedOptions(parser);
      37          112 : }
      38              : 
      39              : /*!
      40              :  * \copybrief DeviceCommand::processOptions
      41              :  *
      42              :  * This implementation extends DeviceCommand::processOptions to process additional CLI options
      43              :  * supported (or required) by this command.
      44              :  */
      45           80 : QStringList FlashLedCommand::processOptions(const QCommandLineParser &parser)
      46           56 : {
      47          136 :     QStringList errors = DeviceCommand::processOptions(parser);
      48           56 :     if (!errors.isEmpty()) {
      49            0 :         return errors;
      50            0 :     }
      51              : 
      52           56 :     return errors;
      53           56 : }
      54              : 
      55              : /*!
      56              :  * \copybrief DeviceCommand::getService
      57              :  *
      58              :  * This override returns a pointer to a StatusService object.
      59              :  */
      60            0 : AbstractPokitService * FlashLedCommand::getService()
      61            0 : {
      62            0 :     Q_ASSERT(device);
      63            0 :     if (!service) {
      64            0 :         service = device->status();
      65            0 :         Q_ASSERT(service);
      66            0 :         connect(service, &StatusService::deviceLedFlashed,
      67            0 :                 this, &FlashLedCommand::deviceLedFlashed);
      68            0 :     }
      69            0 :     return service;
      70            0 : }
      71              : 
      72              : /*!
      73              :  * \copybrief DeviceCommand::serviceDetailsDiscovered
      74              :  *
      75              :  * This override flashes the device's LED, via the Pokit Status service.
      76              :  */
      77            0 : void FlashLedCommand::serviceDetailsDiscovered()
      78            0 : {
      79            0 :     DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
      80            0 :     qCInfo(lc).noquote() << tr("Flashing Pokit device LED...");
      81            0 :     if (!service->flashLed()) {
      82            0 :         QCoreApplication::exit(EXIT_FAILURE);
      83            0 :     }
      84            0 : }
      85              : 
      86              : /*!
      87              :  * Handles StatusService::deviceLedFlashed events, by outputting the result and exiting.
      88              :  */
      89          240 : void FlashLedCommand::deviceLedFlashed()
      90          168 : {
      91          408 :     switch (format) {
      92          136 :     case OutputFormat::Csv:
      93          148 :         std::cout << qUtf8Printable(tr("flash_led_result\nsuccess\n"));
      94          136 :         break;
      95          136 :     case OutputFormat::Json:
      96          148 :         std::cout << qUtf8Printable(u"true\n"_s);
      97          136 :         break;
      98          136 :     case OutputFormat::Text:
      99          148 :         std::cout << qUtf8Printable(tr("Done.\n"));
     100          136 :         break;
     101          168 :     }
     102          408 :     if (device) disconnect(); // Will exit the application once disconnected.
     103          408 : }
        

Generated by: LCOV version 2.3.1-1