File indexing completed on 2024-05-12 05:51:05

0001 /*
0002     SPDX-FileCopyrightText: 2022 Héctor Mesa Jiménez <wmj.py@gmx.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include <QObject>
0009 
0010 class QJsonObject;
0011 class QByteArray;
0012 
0013 namespace dap
0014 {
0015 namespace settings
0016 {
0017 struct BusSettings;
0018 }
0019 
0020 class Bus : public QObject
0021 {
0022     Q_OBJECT
0023 public:
0024     enum class State { None, Running, Closed };
0025 
0026     explicit Bus(QObject *parent = nullptr);
0027     ~Bus() override = default;
0028 
0029     virtual QByteArray read() = 0;
0030     virtual quint16 write(const QByteArray &data) = 0;
0031 
0032     State state() const;
0033 
0034     virtual bool start(const settings::BusSettings &configuration) = 0;
0035     virtual void close() = 0;
0036 
0037 Q_SIGNALS:
0038     void readyRead();
0039 
0040     void stateChanged(State state);
0041 
0042     void running();
0043     void closed();
0044     void error(const QString &errorMessage);
0045     void serverOutput(const QString &message);
0046     void processOutput(const QString &message);
0047 
0048 protected:
0049     void setState(State state);
0050 
0051 private:
0052     State m_state;
0053 };
0054 
0055 }