1 /***************************************************************************
2  *   SPDX-FileCopyrightText: 2013 Volker Krause <vkrause@kde.org>          *
3  *                                                                         *
4  *   SPDX-License-Identifier: LGPL-2.0-or-later                            *
5  ***************************************************************************/
6 
7 #pragma once
8 
9 #include <QElapsedTimer>
10 #include <QLocalSocket>
11 #include <QObject>
12 
13 class QIODevice;
14 class QSocketNotifier;
15 
16 /** ASAP CLI session. */
17 class Session : public QObject
18 {
19     Q_OBJECT
20 public:
21     explicit Session(const QString &input, QObject *parent = nullptr);
22     ~Session() override;
23 
24     void printStats() const;
25 
26 public Q_SLOTS:
27     void connectToHost();
28 
29 Q_SIGNALS:
30     void disconnected();
31 
32 private Q_SLOTS:
33     void inputAvailable();
34     void serverDisconnected();
35     void serverError(QLocalSocket::LocalSocketError socketError);
36     void serverRead();
37 
38 private:
39     QIODevice *m_input = nullptr;
40     QIODevice *m_session = nullptr;
41     QSocketNotifier *m_notifier = nullptr;
42 
43     QElapsedTimer m_connectionTime;
44     qint64 m_receivedBytes = 0;
45     qint64 m_sentBytes = 0;
46 };
47 
48