Dokit
Internal development documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
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"
6
8
9#include <QJsonDocument>
10#include <QJsonObject>
11
12#include <iostream>
13
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 */
29
30/*!
31 * \copybrief DeviceCommand::getService
32 *
33 * This override returns a pointer to a DataLoggerService object.
34 */
36{
37 Q_ASSERT(device);
38 if (!service) {
39 service = device->dataLogger();
40 Q_ASSERT(service);
43 }
44 return service;
45}
46
47/*!
48 * \copybrief DeviceCommand::serviceDetailsDiscovered
49 *
50 * This override stops the device's logger.
51 */
53{
54 DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
55 qCInfo(lc).noquote() << tr("Stopping logger.");
56 service->stopLogger();
57}
58
59/*!
60 * Invoked when the data logger settings have been written.
61 */
63{
64 qCDebug(lc).noquote() << tr("Settings written; data logger has stopped.");
65 switch (format) {
67 std::cout << qUtf8Printable(tr("logger_stop_result\nsuccess\n"));
68 break;
70 std::cout << qUtf8Printable(u"true\n"_s);
71 break;
73 std::cout << qUtf8Printable(tr("Done.\n"));
74 break;
75 }
76 if (device) disconnect(); // Will exit the application once disconnected.
77}
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 interacts 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 interacts 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)
Declares the DOKIT_USE_STRINGLITERALS macro, and related functions.
#define DOKIT_USE_STRINGLITERALS
Internal macro for using either official Qt string literals (added in Qt 6.4), or our own equivalent ...