#ifndef NATIVESTREAMER_H #define NATIVESTREAMER_H #include #include #include #include #include #include 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 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 m_running{false}; std::atomic m_stopping{false}; std::atomic m_fid{-1}; RestartPolicy m_policy; std::function m_guard; QTimer *m_restartTimer = nullptr; }; #endif // NATIVESTREAMER_H