annotate base/FileReadThread.h @ 101:ce1d385f4f89

* Use kill(pid, 0) instead of /proc or sysctl blather for looking up pids * Add OpenProcess call for Win32
author Chris Cannam
date Fri, 05 May 2006 12:34:51 +0000
parents 1aebdc68ec6d
children
rev   line source
Chris@95 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@95 2
Chris@95 3 /*
Chris@95 4 Sonic Visualiser
Chris@95 5 An audio file viewer and annotation editor.
Chris@95 6 Centre for Digital Music, Queen Mary, University of London.
Chris@95 7 This file copyright 2006 Chris Cannam.
Chris@95 8
Chris@95 9 This program is free software; you can redistribute it and/or
Chris@95 10 modify it under the terms of the GNU General Public License as
Chris@95 11 published by the Free Software Foundation; either version 2 of the
Chris@95 12 License, or (at your option) any later version. See the file
Chris@95 13 COPYING included with this distribution for more information.
Chris@95 14 */
Chris@95 15
Chris@95 16 #ifndef _FILE_READ_THREAD_H_
Chris@95 17 #define _FILE_READ_THREAD_H_
Chris@95 18
Chris@96 19 #include "NonRTThread.h"
Chris@96 20
Chris@95 21 #include <QMutex>
Chris@95 22 #include <QWaitCondition>
Chris@95 23
Chris@95 24 #include <map>
Chris@95 25 #include <set>
Chris@95 26
Chris@95 27 #include <stdint.h>
Chris@95 28
Chris@96 29 class FileReadThread : public NonRTThread
Chris@95 30 {
Chris@95 31 Q_OBJECT
Chris@95 32
Chris@95 33 public:
Chris@95 34 FileReadThread();
Chris@95 35
Chris@95 36 virtual void run();
Chris@95 37 virtual void finish();
Chris@95 38
Chris@95 39 struct Request {
Chris@95 40 int fd;
Chris@95 41 QMutex *mutex; // used to synchronise access to fd; may be null
Chris@95 42 off_t start;
Chris@95 43 size_t size;
Chris@95 44 char *data; // caller is responsible for allocating and deallocating
Chris@95 45 };
Chris@95 46
Chris@95 47 virtual int request(const Request &request);
Chris@95 48 virtual void cancel(int token);
Chris@95 49
Chris@95 50 virtual bool isReady(int token);
Chris@95 51 virtual bool isCancelled(int token); // and safe to delete
Chris@95 52 virtual bool getRequest(int token, Request &request);
Chris@95 53 virtual void done(int token);
Chris@95 54
Chris@95 55 signals:
Chris@95 56 void ready(int token, bool successful);
Chris@95 57 void cancelled(int token);
Chris@95 58
Chris@95 59 protected:
Chris@95 60 int m_nextToken;
Chris@95 61 bool m_exiting;
Chris@95 62
Chris@95 63 typedef std::map<int, Request> RequestQueue;
Chris@95 64 RequestQueue m_queue;
Chris@95 65 RequestQueue m_cancelledRequests;
Chris@95 66 RequestQueue m_readyRequests;
Chris@95 67 std::set<int> m_newlyCancelled;
Chris@95 68
Chris@95 69 QMutex m_mutex;
Chris@95 70 QWaitCondition m_condition;
Chris@95 71
Chris@95 72 void process();
Chris@95 73 void notifyCancelled();
Chris@95 74 };
Chris@95 75
Chris@95 76 #endif