Dokit
Internal development documentation
Loading...
Searching...
No Matches
loggerstopcommand.cpp
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
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 */
26
27/*!
28 * \copybrief DeviceCommand::getService
29 *
30 * This override returns a pointer to a DataLoggerService object.
31 */
33{
34 Q_ASSERT(device);
35 if (!service) {
36 service = device->dataLogger();
37 Q_ASSERT(service);
40 }
41 return service;
42}
43
44/*!
45 * \copybrief DeviceCommand::serviceDetailsDiscovered
46 *
47 * This override stops the device's logger.
48 */
50{
51 DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
52 qCInfo(lc).noquote() << tr("Stopping logger.");
53 service->stopLogger();
54}
55
56/*!
57 * Invoked when the data logger settings have been written.
58 */
60{
61 qCDebug(lc).noquote() << tr("Settings written; data logger has stopped.");
62 switch (format) {
64 std::cout << qUtf8Printable(tr("logger_stop_result\nsuccess\n"));
65 break;
67 std::cout << qUtf8Printable(QLatin1String("true\n"));
68 break;
70 std::cout << qUtf8Printable(tr("Done.\n"));
71 break;
72 }
73 if (device) disconnect(); // Will exit the application once disconnected.
74}
OutputFormat format
Selected output format.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
The AbstractPokitService class provides a common base for Pokit services classes.
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
PokitDevice * device
Pokit Bluetooth device (if any) this command interracts with.
DeviceCommand(QObject *const parent=nullptr)
Construct a new DeviceCommand object with parent.
virtual void serviceDetailsDiscovered()
Handles service detail discovery events.
void disconnect(int exitCode=EXIT_SUCCESS)
Disconnects the underlying Pokit device, and sets exitCode to be return to the OS once the disconnect...
DataLoggerService * service
Bluetooth service this command interracts with.
void settingsWritten()
Invoked when the data logger settings have been written.
AbstractPokitService * getService() override
Returns a Pokit service object for the derived command class.
void serviceDetailsDiscovered() override
Handles service detail discovery events.
LoggerStopCommand(QObject *const parent=nullptr)
Construct a new LoggerStopCommand object with parent.
Declares the PokitDevice class.
QObject(QObject *parent)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)