63 lines
1.6 KiB
C++
63 lines
1.6 KiB
C++
#ifndef NATIVESTREAMER_H
|
|
#define NATIVESTREAMER_H
|
|
|
|
#include <QObject>
|
|
#include <QThread>
|
|
#include <QString>
|
|
#include <QTimer>
|
|
#include <atomic>
|
|
#include <functional>
|
|
|
|
class Lib9pClient;
|
|
|
|
/**
|
|
* NativeStreamer - Streaming file reader using native 9P library.
|
|
*
|
|
* Reads from a 9P file in a worker thread, emitting data as it arrives.
|
|
* Replaces QProcess-based streaming with direct library calls.
|
|
*
|
|
* Restart policies:
|
|
* Oneshot — runs once, emits finished on EOF/error
|
|
* Looping — always restarts after EOF/error
|
|
* Guarded — restarts only if guard() returns true
|
|
*/
|
|
class NativeStreamer : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
enum RestartPolicy { Oneshot, Looping, Guarded };
|
|
|
|
explicit NativeStreamer(Lib9pClient *client, RestartPolicy policy, QObject *parent = nullptr);
|
|
~NativeStreamer() override;
|
|
|
|
void start(const QString &path);
|
|
void stop();
|
|
bool isRunning() const;
|
|
|
|
void setGuard(std::function<bool()> guard);
|
|
|
|
signals:
|
|
void dataReady(const QByteArray &data);
|
|
void finished(); // Only emitted when not restarting (Oneshot, or Guarded with false guard)
|
|
void errorOccurred(const QString &error);
|
|
|
|
private slots:
|
|
void onThreadFinished();
|
|
|
|
private:
|
|
void run();
|
|
void scheduleRestart();
|
|
|
|
Lib9pClient *m_client;
|
|
QString m_path;
|
|
QThread *m_thread = nullptr;
|
|
std::atomic<bool> m_running{false};
|
|
std::atomic<bool> m_stopping{false};
|
|
std::atomic<int> m_fid{-1};
|
|
RestartPolicy m_policy;
|
|
std::function<bool()> m_guard;
|
|
QTimer *m_restartTimer = nullptr;
|
|
};
|
|
|
|
#endif // NATIVESTREAMER_H
|