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