Dokit
dev
v0.6.0
v0.5.8
v0.5.7
v0.5.6
v0.5.5
v0.5.4
v0.5.3
v0.5.2
v0.5.1
v0.5.0
v0.4.0
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
User docs
Internal
Coverage
Internal development documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
loggerstopcommand.cpp
1
// SPDX-FileCopyrightText: 2022-2026 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
LoggerStopCommand::LoggerStopCommand
(
QObject
*
const
parent
) :
DeviceCommand
(
parent
)
26
{
27
28
}
29
30
/*!
31
* \copybrief DeviceCommand::getService
32
*
33
* This override returns a pointer to a DataLoggerService object.
34
*/
35
AbstractPokitService
*
LoggerStopCommand::getService
()
36
{
37
Q_ASSERT(
device
);
38
if
(!
service
) {
39
service
=
device
->
dataLogger
();
40
Q_ASSERT(
service
);
41
connect
(
service
, &
DataLoggerService::settingsWritten
,
42
this
, &
LoggerStopCommand::settingsWritten
);
43
}
44
return
service
;
45
}
46
47
/*!
48
* \copybrief DeviceCommand::serviceDetailsDiscovered
49
*
50
* This override stops the device's logger.
51
*/
52
void
LoggerStopCommand::serviceDetailsDiscovered
()
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
*/
62
void
LoggerStopCommand::settingsWritten
()
63
{
64
qCDebug(lc).noquote() <<
tr
(
"Settings written; data logger has stopped."
);
65
switch
(
format
) {
66
case
OutputFormat::Csv
:
67
std::cout << qUtf8Printable(
tr
(
"logger_stop_result\nsuccess\n"
));
68
break
;
69
case
OutputFormat::Json
:
70
std::cout << qUtf8Printable(u
"true\n"
_s);
71
break
;
72
case
OutputFormat::Text
:
73
std::cout << qUtf8Printable(
tr
(
"Done.\n"
));
74
break
;
75
}
76
if
(
device
)
disconnect
();
// Will exit the application once disconnected.
77
}
AbstractCommand::format
OutputFormat format
Selected output format.
Definition
abstractcommand.h:46
AbstractCommand::OutputFormat::Text
@ Text
Plain unstructured text.
Definition
abstractcommand.h:25
AbstractCommand::OutputFormat::Csv
@ Csv
RFC 4180 compliant CSV text.
Definition
abstractcommand.h:23
AbstractCommand::OutputFormat::Json
@ Json
RFC 8259 compliant JSON text.
Definition
abstractcommand.h:24
AbstractPokitService
The AbstractPokitService class provides a common base for Pokit services classes.
Definition
abstractpokitservice.h:27
DataLoggerService::stopLogger
bool stopLogger()
Stop the data logger.
Definition
dataloggerservice.cpp:200
DataLoggerService::settingsWritten
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
DeviceCommand::device
PokitDevice * device
Pokit Bluetooth device (if any) this command interacts with.
Definition
devicecommand.h:27
DeviceCommand::DeviceCommand
DeviceCommand(QObject *const parent=nullptr)
Construct a new DeviceCommand object with parent.
Definition
devicecommand.cpp:21
DeviceCommand::serviceDetailsDiscovered
virtual void serviceDetailsDiscovered()
Handles service detail discovery events.
Definition
devicecommand.cpp:330
DeviceCommand::disconnect
void disconnect(int exitCode=EXIT_SUCCESS)
Disconnects the underlying Pokit device, and sets exitCode to be return to the OS once the disconnect...
Definition
devicecommand.cpp:42
LoggerStopCommand::service
DataLoggerService * service
Bluetooth service this command interacts with.
Definition
loggerstopcommand.h:22
LoggerStopCommand::settingsWritten
void settingsWritten()
Invoked when the data logger settings have been written.
Definition
loggerstopcommand.cpp:62
LoggerStopCommand::getService
AbstractPokitService * getService() override
Returns a Pokit service object for the derived command class.
Definition
loggerstopcommand.cpp:35
LoggerStopCommand::serviceDetailsDiscovered
void serviceDetailsDiscovered() override
Handles service detail discovery events.
Definition
loggerstopcommand.cpp:52
LoggerStopCommand::LoggerStopCommand
LoggerStopCommand(QObject *const parent=nullptr)
Construct a new LoggerStopCommand object with parent.
Definition
loggerstopcommand.cpp:25
PokitDevice::dataLogger
DataLoggerService * dataLogger()
Returns a pointer to a DataLoggerService instance that uses this device's controller for access.
Definition
pokitdevice.cpp:133
pokitdevice.h
Declares the PokitDevice class.
QObject::QObject
QObject(QObject *parent)
QObject::connect
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const const
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
stringliterals_p.h
Declares the DOKIT_USE_STRINGLITERALS macro, and related functions.
DOKIT_USE_STRINGLITERALS
#define DOKIT_USE_STRINGLITERALS
Internal macro for using either official Qt string literals (added in Qt 6.4), or our own equivalent ...
Definition
stringliterals_p.h:71
dokit
dokit
src
cli
loggerstopcommand.cpp
Generated by
1.18.0