Chris@95: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@95: Chris@95: /* Chris@95: Sonic Visualiser Chris@95: An audio file viewer and annotation editor. Chris@95: Centre for Digital Music, Queen Mary, University of London. Chris@95: This file copyright 2006 Chris Cannam. Chris@95: Chris@95: This program is free software; you can redistribute it and/or Chris@95: modify it under the terms of the GNU General Public License as Chris@95: published by the Free Software Foundation; either version 2 of the Chris@95: License, or (at your option) any later version. See the file Chris@95: COPYING included with this distribution for more information. Chris@95: */ Chris@95: Chris@95: #ifndef _FILE_READ_THREAD_H_ Chris@95: #define _FILE_READ_THREAD_H_ Chris@95: Chris@96: #include "NonRTThread.h" Chris@96: Chris@95: #include Chris@95: #include Chris@95: Chris@95: #include Chris@95: #include Chris@95: Chris@95: #include Chris@95: Chris@96: class FileReadThread : public NonRTThread Chris@95: { Chris@95: Q_OBJECT Chris@95: Chris@95: public: Chris@95: FileReadThread(); Chris@95: Chris@95: virtual void run(); Chris@95: virtual void finish(); Chris@95: Chris@95: struct Request { Chris@95: int fd; Chris@95: QMutex *mutex; // used to synchronise access to fd; may be null Chris@95: off_t start; Chris@95: size_t size; Chris@95: char *data; // caller is responsible for allocating and deallocating Chris@95: }; Chris@95: Chris@95: virtual int request(const Request &request); Chris@95: virtual void cancel(int token); Chris@95: Chris@95: virtual bool isReady(int token); Chris@95: virtual bool isCancelled(int token); // and safe to delete Chris@95: virtual bool getRequest(int token, Request &request); Chris@95: virtual void done(int token); Chris@95: Chris@95: signals: Chris@95: void ready(int token, bool successful); Chris@95: void cancelled(int token); Chris@95: Chris@95: protected: Chris@95: int m_nextToken; Chris@95: bool m_exiting; Chris@95: Chris@95: typedef std::map RequestQueue; Chris@95: RequestQueue m_queue; Chris@95: RequestQueue m_cancelledRequests; Chris@95: RequestQueue m_readyRequests; Chris@95: std::set m_newlyCancelled; Chris@95: Chris@95: QMutex m_mutex; Chris@95: QWaitCondition m_condition; Chris@95: Chris@95: void process(); Chris@95: void notifyCancelled(); Chris@95: }; Chris@95: Chris@95: #endif